38 #include "monoTriangulation.h"
43 void reflexChain::outputFan(Real v[2],
Backend* backend)
56 backend->tmeshvert(v[0], v[1]);
59 for(i=0; i<index_queue; i++)
66 backend->tmeshvert(queue[i][0], queue[i][1]);
70 for(i=index_queue-1; i>=0; i--)
77 backend->tmeshvert(queue[i][0], queue[i][1]);
83 void reflexChain::processNewVertex(Real v[2],
Backend* backend)
100 isReflex = (area(queue[i-1], queue[i], v) <= 0.0);
103 isReflex = (area(v, queue[i], queue[i-1]) <= 0.0);
123 backend->tmeshvert(v[0], v[1]);
133 backend->tmeshvert(queue[k][0], queue[k][1]);
144 backend->tmeshvert(queue[k][0], queue[k][1]);
159 void monoTriangulationRec(Real* topVertex, Real* botVertex,
164 assert( inc_chain != NULL && dec_chain != NULL);
165 assert( ! (inc_current>=inc_chain->getNumElements() &&
166 dec_current>=dec_chain->getNumElements()));
172 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
174 if(inc_current>=inc_chain->getNumElements())
177 dec_array = dec_chain->getArray();
178 dec_nVertices = dec_chain->getNumElements();
181 rChain.processNewVertex(topVertex, backend);
183 for(i=dec_current; i<dec_nVertices; i++){
184 rChain.processNewVertex(dec_array[i], backend);
187 rChain.processNewVertex(botVertex, backend);
190 else if(dec_current>= dec_chain->getNumElements())
192 inc_array = inc_chain->getArray();
193 inc_nVertices= inc_chain->getNumElements();
196 rChain.processNewVertex(topVertex, backend);
198 for(i=inc_current; i<inc_nVertices; i++){
199 rChain.processNewVertex(inc_array[i], backend);
202 rChain.processNewVertex(botVertex, backend);
206 inc_array = inc_chain -> getArray();
207 dec_array = dec_chain -> getArray();
208 inc_nVertices= inc_chain->getNumElements();
209 dec_nVertices= dec_chain->getNumElements();
213 if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0)
217 rChain.processNewVertex(topVertex, backend);
218 for(i=dec_current; i<dec_nVertices; i++)
220 if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0)
221 rChain.processNewVertex(dec_array[i], backend);
225 rChain.outputFan(inc_array[inc_current], backend);
226 monoTriangulationRec(dec_array[i-1], botVertex,
227 inc_chain, inc_current,
235 rChain.processNewVertex(topVertex, backend);
236 for(i=inc_current; i<inc_nVertices; i++)
238 if(compV2InY(inc_array[i], dec_array[dec_current]) >0)
239 rChain.processNewVertex(inc_array[i], backend);
243 rChain.outputFan(dec_array[dec_current], backend);
244 monoTriangulationRec(inc_array[i-1], botVertex,
246 dec_chain, dec_current,
253 void monoTriangulationFunBackend(Arc_ptr loop, Int (*compFun)(Real*, Real*),
Backend* backend)
263 for(tempV = loop->next; tempV != loop; tempV = tempV->next)
265 if(compFun(topV->tail(), tempV->tail())<0) {
268 if(compFun(botV->tail(), tempV->tail())>0) {
275 for(i=1; i<=topV->pwlArc->npts-2; i++) {
276 inc_chain.appendVertex(topV->pwlArc->pts[i].param);
278 for(tempV = topV->next; tempV != botV; tempV = tempV->next)
280 for(i=0; i<=tempV->pwlArc->npts-2; i++){
281 inc_chain.appendVertex(tempV->pwlArc->pts[i].param);
286 for(tempV = topV->prev; tempV != botV; tempV = tempV->prev)
288 for(i=tempV->pwlArc->npts-2; i>=0; i--){
289 dec_chain.appendVertex(tempV->pwlArc->pts[i].param);
292 for(i=botV->pwlArc->npts-2; i>=1; i--){
293 dec_chain.appendVertex(tempV->pwlArc->pts[i].param);
296 monoTriangulationRecFunBackend(topV->tail(), botV->tail(), &inc_chain, 0, &dec_chain, 0, compFun, backend);
303 void monoTriangulationRecFunBackend(Real* topVertex, Real* botVertex,
306 Int (*compFun)(Real*, Real*),
309 assert( inc_chain != NULL && dec_chain != NULL);
310 assert( ! (inc_current>=inc_chain->getNumElements() &&
311 dec_current>=dec_chain->getNumElements()));
317 assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
319 if(inc_current>=inc_chain->getNumElements())
322 dec_array = dec_chain->getArray();
323 dec_nVertices = dec_chain->getNumElements();
326 rChain.processNewVertex(topVertex, backend);
328 for(i=dec_current; i<dec_nVertices; i++){
329 rChain.processNewVertex(dec_array[i], backend);
332 rChain.processNewVertex(botVertex, backend);
335 else if(dec_current>= dec_chain->getNumElements())
337 inc_array = inc_chain->getArray();
338 inc_nVertices= inc_chain->getNumElements();
341 rChain.processNewVertex(topVertex, backend);
343 for(i=inc_current; i<inc_nVertices; i++){
344 rChain.processNewVertex(inc_array[i], backend);
347 rChain.processNewVertex(botVertex, backend);
351 inc_array = inc_chain -> getArray();
352 dec_array = dec_chain -> getArray();
353 inc_nVertices= inc_chain->getNumElements();
354 dec_nVertices= dec_chain->getNumElements();
358 if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0)
362 rChain.processNewVertex(topVertex, backend);
363 for(i=dec_current; i<dec_nVertices; i++)
365 if(compFun(inc_array[inc_current], dec_array[i]) <= 0)
366 rChain.processNewVertex(dec_array[i], backend);
370 rChain.outputFan(inc_array[inc_current], backend);
371 monoTriangulationRecFunBackend(dec_array[i-1], botVertex,
372 inc_chain, inc_current,
381 rChain.processNewVertex(topVertex, backend);
382 for(i=inc_current; i<inc_nVertices; i++)
384 if(compFun(inc_array[i], dec_array[dec_current]) >0)
385 rChain.processNewVertex(inc_array[i], backend);
389 rChain.outputFan(dec_array[dec_current], backend);
390 monoTriangulationRecFunBackend(inc_array[i-1], botVertex,
392 dec_chain, dec_current,