Revision 27442 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/vectorizacion/process/PotraceProcess.java
PotraceProcess.java | ||
---|---|---|
26 | 26 |
import org.cresques.cts.ProjectionPool; |
27 | 27 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
28 | 28 |
import org.gvsig.raster.RasterProcess; |
29 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
|
30 |
import org.gvsig.raster.process.RasterTask; |
|
31 |
import org.gvsig.raster.process.RasterTaskQueue; |
|
29 | 32 |
import org.gvsig.raster.util.RasterToolsUtil; |
30 | 33 |
import org.gvsig.raster.vectorization.VectorizationBinding; |
31 | 34 |
import org.gvsig.rastertools.vectorizacion.fmap.BezierPathX; |
32 | 35 |
|
36 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
|
33 | 37 |
import com.hardcode.gdbms.engine.values.Value; |
34 | 38 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
39 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
|
35 | 40 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
36 | 41 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
37 | 42 |
import com.iver.cit.gvsig.fmap.core.FShape; |
... | ... | |
94 | 99 |
*/ |
95 | 100 |
public void process() throws InterruptedException { |
96 | 101 |
try { |
102 |
insertLineLog("Potrace"); |
|
97 | 103 |
generatePotrace(); |
98 |
} catch (Exception e) { |
|
104 |
} catch (VisitorException e) {
|
|
99 | 105 |
RasterToolsUtil.messageBoxError("error_closing_grid", this, e); |
106 |
} catch (InitializeWriterException e) { |
|
107 |
RasterToolsUtil.messageBoxError("error_closing_grid", this, e); |
|
108 |
} catch (RasterDriverException e) { |
|
109 |
RasterToolsUtil.messageBoxError("error_closing_grid", this, e); |
|
100 | 110 |
} finally { |
101 |
if (externalActions != null) |
|
102 |
externalActions.end(fileName); |
|
111 |
if (incrementableTask != null) { |
|
112 |
incrementableTask.processFinalize(); |
|
113 |
incrementableTask = null; |
|
114 |
} |
|
103 | 115 |
} |
116 |
if (externalActions != null) |
|
117 |
externalActions.end(fileName); |
|
104 | 118 |
} |
105 | 119 |
|
106 | 120 |
/** |
... | ... | |
109 | 123 |
* @param lyr |
110 | 124 |
* @param fileOut |
111 | 125 |
* @param bezierPoints |
126 |
* @throws RasterDriverException |
|
127 |
* @throws InterruptedException |
|
128 |
* @throws VisitorException |
|
129 |
* @throws InitializeWriterException |
|
112 | 130 |
* @throws Exception |
113 | 131 |
*/ |
114 |
public void generatePotrace() throws Exception { |
|
132 |
public void generatePotrace() throws InterruptedException, RasterDriverException, VisitorException, InitializeWriterException {
|
|
115 | 133 |
VectorizationBinding binding = new VectorizationBinding(lyr.getBufferFactory()); |
116 | 134 |
binding.setPolicy(policy); |
117 | 135 |
binding.setDespeckle(despeckle); |
... | ... | |
169 | 187 |
writer.postProcess(); |
170 | 188 |
} |
171 | 189 |
|
172 |
public void addShape(FShape shape, Value[] value) throws Exception {
|
|
190 |
public void addShape(FShape shape, Value[] value) throws VisitorException {
|
|
173 | 191 |
if (shape == null) |
174 | 192 |
return; |
175 | 193 |
IGeometry geom = ShapeFactory.createGeometry(shape); |
176 | 194 |
addGeometry(geom, value); |
177 | 195 |
} |
178 | 196 |
|
179 |
public void addGeometry(IGeometry geom, Value[] value) throws Exception { |
|
197 |
public void addGeometry(IGeometry geom, Value[] value) throws VisitorException {
|
|
180 | 198 |
DefaultFeature feat = new DefaultFeature(geom, value, Integer.toString(m_iGeometry)); |
181 | 199 |
IRowEdited editFeat = new DefaultRowEdited(feat, IRowEdited.STATUS_MODIFIED, m_iGeometry); |
182 | 200 |
m_iGeometry++; |
... | ... | |
190 | 208 |
return ptSrc; |
191 | 209 |
} |
192 | 210 |
|
193 |
private void showPotrace(double[] potraceX, int trozos) throws Exception { |
|
211 |
private void showPotrace(double[] potraceX, int trozos) throws InterruptedException, VisitorException { |
|
212 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString()); |
|
194 | 213 |
BezierPathX pathX = new BezierPathX(trozos); |
195 | 214 |
|
215 |
double increment = (100 / (double)potraceX.length); |
|
196 | 216 |
int cont = 1; |
197 | 217 |
while (true) { |
198 | 218 |
if ((cont >= potraceX.length) || (cont >= potraceX[0])) |
... | ... | |
201 | 221 |
case 0: // MoveTo |
202 | 222 |
pathX.moveTo(getTransformPixel(potraceX[cont + 1], potraceX[cont + 2])); |
203 | 223 |
cont += 3; |
224 |
percent += (increment * 3); |
|
204 | 225 |
break; |
205 | 226 |
case 1: // LineTo |
206 | 227 |
pathX.lineTo(getTransformPixel(potraceX[cont + 1], potraceX[cont + 2])); |
207 | 228 |
cont += 3; |
229 |
percent += (increment * 3); |
|
208 | 230 |
break; |
209 | 231 |
case 2: // CurveTo |
210 | 232 |
pathX.curveTo(getTransformPixel(potraceX[cont + 1], potraceX[cont + 2]), getTransformPixel(potraceX[cont + 3], potraceX[cont + 4]), getTransformPixel(potraceX[cont + 5], potraceX[cont + 6])); |
211 | 233 |
cont += 7; |
234 |
percent += (increment * 7); |
|
212 | 235 |
break; |
213 | 236 |
case 3: // closePath |
214 | 237 |
FPolyline2D line = new FPolyline2D(pathX); |
215 | 238 |
addShape(line, values); |
216 | 239 |
pathX = new BezierPathX(trozos); |
217 | 240 |
cont ++; |
241 |
percent += increment; |
|
218 | 242 |
break; |
219 | 243 |
} |
244 |
if(task.getEvent() != null) |
|
245 |
task.manageEvent(task.getEvent()); |
|
220 | 246 |
} |
221 | 247 |
} |
222 | 248 |
|
Also available in: Unified diff