otherfns.cpp
Go to the documentation of this file.
00001 /**************************************************************************************************
00002  Software License Agreement (BSD License)
00003 
00004  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
00005  All rights reserved.
00006 
00007  Redistribution and use in source and binary forms, with or without modification, are permitted
00008  provided that the following conditions are met:
00009 
00010   *Redistributions of source code must retain the above copyright notice, this list of
00011    conditions and the following disclaimer.
00012   *Redistributions in binary form must reproduce the above copyright notice, this list of
00013    conditions and the following disclaimer in the documentation and/or other materials provided
00014    with the distribution.
00015   *Neither the name of the University of Aveiro nor the names of its contributors may be used to
00016    endorse or promote products derived from this software without specific prior written permission.
00017  
00018  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
00019  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00020  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00021  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00024  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00025  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 ***************************************************************************************************/
00033 /*CISC 829 Final Project
00034 CISC829 Final project: Image reconstruction using Data-Dependent triangulation (DDT)
00035 Spring 2008
00036 
00037 The following is an implementation of the DDT algorithm presented in 
00038 "Image Reconstruction Using Data-Dependent Triangulation,", Xiaohua Yu, Bryan S. Morse, Thomas W. Sederberg, IEEE Computer Graphics and Applications, vol. 21,  no. 3,  pp. 62-68,  May/Jun,  2001
00039 
00040 Gowri Somanath
00041 Feng Li
00042 CIS
00043 University of Delaware.
00044 */
00045 
00046 
00047 #define PFLN {printf("DEBUG PRINT FILE %s LINE %d\n",__FILE__,__LINE__);}
00048 #include<math.h>
00049 #include "preh.h"
00050 Delaunay dttmp;
00051 bool getPlaneEqn(int x0,int y0,int z0,int x1,int y1,int z1,int x2,int y2,int z2,double *a,double *b)
00052 {
00053         /*double A = y1*(z2 - z3) + y2*(z3 - z1) + y3*(z1 - z2);
00054         double B = z1*(x2 - x3) + z2*(x3 - x1) + z3*(x1 - x2);
00055         double C = x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2);
00056 if 
00057         *a=-A/C;
00058         *b=-B/C;*/
00059         if(x0==x1)
00060         {
00061                 if(x0==x2)
00062                 {
00063                         *a=99999;
00064                         *b=99999;
00065                         return false;
00066                 }
00067         }
00068         if(y0==y1)
00069         {
00070                 if(y0==y2)
00071                 {
00072                         *a=99999;
00073                         *b=99999;
00074                         return false;
00075                 }
00076         }
00077 double d0[3],d1[3],n[3],s,c,d,a1,b1;
00078         d0[0] = x1 - x0;
00079         d0[1] = y1 - y0;
00080         d0[2] = z1 - z0;
00081         d1[0] = x2 - x0;
00082         d1[1] = y2 - y0;
00083         d1[2] = z2 - z0;
00084         n[0] = d1[1] * d0[2] - d1[2] * d0[1];
00085         n[1] = d1[2] * d0[0] - d1[0] * d0[2];
00086         n[2] = d1[0] * d0[1] - d1[1] * d0[0];
00087         if((n[0] * n[0] + n[1] * n[1] + n[2] * n[2] )==0) //collinear traingles
00088         {
00089                 *a=99999;
00090                 *b=99999;
00091                 return false;
00092         }
00093         s = 1.0f / sqrt( n[0] * n[0] + n[1] * n[1] + n[2] * n[2] );
00094         a1 = n[0] * s;
00095         b1 = n[1] * s;
00096         c = n[2] * s;
00097         //d = -( a * x0 + b * y0 + c * z0 );
00098         *a=-a1/c;
00099         *b=-b1/c;
00100         return true;
00101 }
00102 
00103 double getCost(double a1,double b1,double a2,double b2)
00104 {
00105         double cost=sqrt(a1*a1+b1*b1)*sqrt(a2*a2+b2*b2)-(a1*a2+b1*b2);
00106         return cost;
00107 }
00108 
00109 
00110 
00111 bool checkConvex(Point v1,Point v2,Point v3,Point v4)
00112 {
00113         GPoint pts[]={GPoint(v1.x(),v1.y()),GPoint(v2.x(),v2.y()),GPoint(v3.x(),v3.y()),GPoint(v4.x(),v4.y())};
00114                 Polygon_2 pgn(pts, pts+4);
00115                 return pgn.is_convex();
00116 }
00117 
00118 bool processForCost(Face_handle f1,int i,Point_value_map values,Delaunay *dt)
00119 {
00120         double z1,z2,z3,z4,za,zb,zc,zd,a1,a2,b1,b2,aa,ba,ab,bb,ac,bc,ad,bd;
00121         //Point pi,pccwi,pcwi,p0,p1,p2;
00122         double c1,c2,c3,c4,c5;
00123         double s1,s2,s3,s4,s5,s6;
00124 
00125         
00126         Vertex_handle vih=f1->vertex(i);
00127         Point pi=vih->point();
00128         
00129         Point pccwi=f1->vertex(f1->ccw(i))->point(); //shared by neighbor
00130         
00131         Point pcwi=f1->vertex(f1->cw(i))->point();      //shared by neighbor
00132         
00133         z1=values[pi];
00134         z2=values[pccwi];
00135         z3=values[pcwi];
00136                 //int x=pi.x();
00137                                                 //void getPlaneEqn(int x1,int y1,int z1,int x2,int y2,int z2,int x3,int y3,int z3,double *a,double *b);
00138         //f1
00139         if(!getPlaneEqn(pi.x(),pi.y(),z1,pccwi.x(),pccwi.y(),z2,pcwi.x(),pcwi.y(),z3,&a1,&b1))
00140                 return false;
00141                 
00142 
00143         
00144         Face_handle f2=f1->neighbor(i);
00145         if (!f1->has_neighbor(f2))
00146                 return false;
00147 
00148         
00149         
00150         
00151         int vihn=f2->index(f1->vertex(f1->ccw(i))); //vertex index of ccw(i) in neighbor f2
00152         Vertex_handle vin=f2->vertex(f2->ccw(vihn));
00153         Point pin=f2->vertex(f2->ccw(vihn))->point(); //vertex opposite edge e in neighbor f2
00154         z4=values[pin];
00155         
00156         //f2
00157         if(!getPlaneEqn(pin.x(),pin.y(),z4,pcwi.x(),pcwi.y(),z3,pccwi.x(),pccwi.y(),z2,&a2,&b2))
00158                 return false;
00159                                 //double getCost(double a1,double b1,double a2,double b2);
00160         
00161         
00162         //f1-f2
00163         c1=getCost(a1,b1,a2,b2); 
00164         
00165         
00166         
00167 
00169         Point a,b,c,d;
00170         Point pd1,pd2;
00171         c2=0;
00172         Face_handle fd=f1->neighbor(f1->ccw(i));
00173         Face_handle fd1,fd2;
00174         
00175         int id,id1,id2;
00176         
00177         if(f1->has_neighbor(fd))
00178         {
00179                 
00180                 id=fd->index(vih);  //i in fd
00181                 
00182                  d=fd->vertex(fd->cw(id))->point(); 
00183                 
00184                 if(!checkConvex(pi,pccwi,pcwi,d)) return false;
00185                 zd=values[d];           
00186                 
00187                 //fd
00188                 if(!getPlaneEqn(pi.x(),pi.y(),z1,pcwi.x(),pcwi.y(),z3,d.x(),d.y(),zd,&ad,&bd))
00189                         return false;
00190                 c2=getCost(a1,b1,ad,bd);
00191 
00192                 
00193                 fd1=fd->neighbor(fd->ccw(id));
00194                 
00195                 fd2=fd->neighbor(id);
00196                 
00197                  id1= fd1->index(vih);//i in fd1
00198                 
00199                 pd1=fd1->vertex(fd1->cw(id1))->point();
00200                 
00201 
00202                  id2= fd2->index(fd->vertex(fd->cw(id)));//d in fd2
00203                 
00204                 pd2=fd2->vertex(fd2->cw(id2))->point();
00205                 
00206 
00207         }
00208         else return false;
00209 
00210                 
00211         c3=0;
00212                 
00213         Face_handle fa=f1->neighbor(f1->cw(i));
00214                 
00215         Face_handle fa1,fa2;
00216                 
00217         Point pa1,pa2;
00218         int ia,ia1,ia2;
00219         if(f1->has_neighbor(fa))
00220         {
00221                 
00222                 ia=fa->index(vih); //i in fa
00223                 
00224                 a=fa->vertex(fa->ccw(ia))->point(); 
00225                 
00226                 if(!checkConvex(pi,a,pccwi,pcwi)) return false;
00227                 
00228                 za=values[a];           
00229                 //fa
00230                 if(!getPlaneEqn(pi.x(),pi.y(),z1,a.x(),a.y(),za,pccwi.x(),pccwi.y(),z2,&aa,&ba))
00231                         return false;
00232                 c3=getCost(a1,b1,aa,ba);
00233 
00234                 
00235                 fa2=fa->neighbor(ia);
00236                 fa1=fa->neighbor(fa->cw(ia));
00237                 
00238                  ia1=fa1->index(fa->vertex(fa->ccw(ia))); //a in fa1
00239                 pa1=fa1->vertex(fa1->cw(ia1))->point();
00240 
00241                  ia2=fa2->index(fa->vertex(fa->ccw(ia))); //a in fa2
00242                 pa2=fa2->vertex(fa2->ccw(ia2))->point();
00243 
00244         }
00245         else return false;
00246 
00247                 
00248         c4=0;
00249                 
00250         Face_handle fc=f2->neighbor(vihn);
00251                 
00252         Face_handle fc1,fc2;
00253                 
00254         Point pc1,pc2;
00255         int ic,ic1,ic2;
00256         if(f2->has_neighbor(fc))
00257         {
00258                 ic=fc->index(vin);  //pin in fc
00259                 c=fc->vertex(fc->ccw(ic))->point(); 
00260                 if(!checkConvex(pccwi,pcwi,c,pin)) return false;
00261                 zc=values[c];   
00262                 //fc
00263                 if(!getPlaneEqn(pin.x(),pin.y(),z4,c.x(),c.y(),zc,pcwi.x(),pcwi.y(),z3,&ac,&bc))
00264                         return false;
00265                 c4=getCost(a2,b2,ac,bc);
00266 
00267                 fc1=fc->neighbor(ic);
00268                 fc2=fc->neighbor(fc->cw(ic));
00269 
00270                  ic1=fc1->index(fc->vertex(fc->ccw(ic)));//c in fc1
00271                 pc1=fc1->vertex(fc1->ccw(ic1))->point();
00272 
00273                  ic2=fc2->index(fc->vertex(fc->ccw(ic))); //c in fc2
00274                 pc2=fc2->vertex(fc2->cw(ic2))->point();
00275         }
00276         else return false;
00277         
00278                 
00279         c5=0;
00280         Face_handle fb=f2->neighbor(f2->cw(vihn));
00281         Face_handle fb1,fb2;
00282         Point pb1,pb2;
00283         int ib,ib1,ib2;
00284         if(f2->has_neighbor(fb))
00285         {
00286                  ib=fb->index(vin);  //pin in fb
00287                  b=fb->vertex(fb->cw(ib))->point(); 
00288                  if(!checkConvex(pccwi,pcwi,pin,b)) return false;
00289                 zb=values[b];   
00290                 //fb
00291                 if(!getPlaneEqn(pin.x(),pin.y(),z4,pccwi.x(),pccwi.y(),z2,b.x(),b.y(),zb,&ab,&bb))
00292                         return false;
00293                 c5=getCost(a2,b2,ab,bb);
00294 
00295                 fb1=fb->neighbor(ib);
00296                 fb2=fb->neighbor(fb->ccw(ib));
00297 
00298                  ib1=fb1->index(fb->vertex(fb->cw(ib))); //b in fb1
00299                 pb1=fb1->vertex(fb1->cw(ib1))->point();
00300                  ib2=fb2->index(fb->vertex(fb->cw(ib))); //b in fb2
00301                 pb2=fb2->vertex(fb2->ccw(ib2))->point();
00302 
00303         }
00304         else return false;
00305         //s1- cost of triangulan as is
00306         s1=c1+c2+c3+c4+c5;
00307 
00308 //**************************************************************
00309         //setting 2. edge f1-f2 flipped
00310 
00311                 
00312         if(!f1->has_neighbor(fd)) return false;
00313         if(!f1->has_neighbor(fa)) return false;
00314         if(!f2->has_neighbor(fb)) return false;
00315         if(!f2->has_neighbor(fc)) return false;
00316         
00317                 
00318         if(!checkConvex(pi,pccwi,pin,pcwi)) return false;
00319         //if e is flipped then the 2 new faces r made of pi,pin,pcwi and pi,pccwi,pin
00320         
00321         //if setting 2 flip is not allowed then no look ahead can happen
00322         if(!getPlaneEqn(pi.x(),pi.y(),z1,pin.x(),pin.y(),z4,pcwi.x(),pcwi.y(),z3,&a1,&b1))
00323                 return false;
00324         if(!getPlaneEqn(pi.x(),pi.y(),z1,pccwi.x(),pccwi.y(),z2,pin.x(),pin.y(),z4,&a2,&b2))
00325                 return false;
00326 
00327         c1=getCost(a1,b1,a2,b2);
00328         
00329 
00330         c2=0;
00331         c2=getCost(a1,b1,ad,bd);
00332         
00333         c3=0;
00334         c3=getCost(a2,b2,aa,ba);
00335         
00336         c4=0;
00337         c4=getCost(a1,b1,ac,bc);
00338         
00339         c5=0;
00340         c5=getCost(a2,b2,ab,bb);
00341         
00342 
00343         s2=c1+c2+c3+c4+c5;
00344         
00345         
00346                 
00347         if(s2<s1)
00348         {
00349                 dttmp=*dt;
00350                 dttmp.flip(f1,i);
00351                 
00352                 if(dttmp.is_valid())
00353                 {
00354                 
00355                                 //dt->flip(f1,i);
00356 
00357                 
00358                         return true;
00359                 }
00360                 
00361                 //else return false;
00362         }
00363 
00364                 
00365 //return false;
00366 
00367         //******************************************************************************************
00368         //******************************************************************************************
00369         //******************************************************************************************
00371 
00372                 
00373         //from here on all 13 edges r required
00374 if(!fd->has_neighbor(fd1)) return false;
00375 if(!checkConvex(pi,pcwi,d,pd1)) return false;
00376 if(!fd->has_neighbor(fd2)) return false;
00377 if(!checkConvex(pi,d,pd2,pcwi)) return false;
00378 
00379 if(!fa->has_neighbor(fa1)) return false;
00380 if(!checkConvex(pi,pa1,a,pccwi)) return false;
00381 if(!fa->has_neighbor(fa2)) return false;
00382 if(!checkConvex(pi,a,pa2,pccwi)) return false;
00383 
00384 if(!fb->has_neighbor(fb1)) return false;
00385 if(!checkConvex(pccwi,pb1,b,pin)) return false;
00386 if(!fb->has_neighbor(fb2)) return false;
00387 if(!checkConvex(pccwi,b,pb2,pin)) return false;
00388 
00389 if(!fc->has_neighbor(fc1)) return false;
00390 if(!checkConvex(pin,c,pc1,pcwi)) return false;
00391 if(!fc->has_neighbor(fc2)) return false;
00392 if(!checkConvex(pin,pc2,c,pcwi)) return false;
00393 
00394 
00395                 
00396 
00397         double c6,c7,c8,c9,c10,c11,c12,c13;
00398         double aa1,ba1,aa2,ba2,ab1,bb1,ab2,bb2,ac1,bc1,ac2,bc2,ad1,bd1,ad2,bd2;
00399         double za1=values[pa1];
00400         double za2=values[pa2];
00401         
00402         double zb1=values[pb1];
00403         double zb2=values[pb2];
00404 
00405         double zc1=values[pc1];
00406         double zc2=values[pc2];
00407 
00408         double zd1=values[pd1];
00409         double zd2=values[pd2];
00410 
00411         if(!getPlaneEqn(pa1.x(),pa1.y(),za1,a.x(),a.y(),za,pi.x(),pi.y(),z1,&aa1,&ba1)) return false;
00412         if(!getPlaneEqn(pi.x(),pi.y(),z4,a.x(),a.y(),za,pccwi.x(),pccwi.y(),z2,&aa2,&ba2)) return false;
00413         
00414         if(!getPlaneEqn(pccwi.x(),pccwi.y(),z2,pb1.x(),pb1.y(),zb1,b.x(),b.y(),zb,&ab1,&bb1)) return false;
00415         if(!getPlaneEqn(b.x(),b.y(),zb,pb2.x(),pb2.y(),zb2,pin.x(),pin.y(),z4,&ab2,&bb2)) return false;
00416 
00417 
00418         if(!getPlaneEqn(pin.x(),pin.y(),z4,pc2.x(),pc2.y(),zc2,c.x(),c.y(),zc,&ac1,&bc1)) return false;
00419         if(!getPlaneEqn(c.x(),c.y(),zc,pc1.x(),pc1.y(),zc1,pcwi.x(),pcwi.y(),z3,&ac2,&bc2)) return false;
00420         
00421         if(!getPlaneEqn(pd1.x(),pd1.y(),zd1,pi.x(),pi.y(),z1,d.x(),d.y(),zd,&ad1,&bd1)) return false;
00422         if(!getPlaneEqn(d.x(),d.y(),zd,pcwi.x(),pcwi.y(),z3,pd2.x(),pd2.y(),zd2,&ad2,&bd2)) return false;
00423         
00424 int tryset;
00425 //**************************************************************
00426         //setting 3     
00427 //c3 c5 same - surely calculated
00428         
00429         tryset=1;
00430         c2=0;
00431         c1=0;
00432         c13=0;
00433         c12=0;
00434         c4=0;
00435         double at1,bt1,at2,bt2;
00436         if(!checkConvex(pi,pin,pcwi,d)) tryset=0;
00437         //if(fd->has_neighbor(f1))
00438         {
00439                 if(!getPlaneEqn(pi.x(),pi.y(),z1,pin.x(),pin.y(),z4,d.x(),d.y(),zd,&at1,&bt1)) 
00440                 {
00441                         tryset=0;
00442                         //break;
00443                 }
00444                 c2=getCost(a2,b2,at1,bt1);
00445                 c13=getCost(ad1,bd1,at1,bt1);
00446 
00447                 if(!getPlaneEqn(pin.x(),pin.y(),z4,pcwi.x(),pcwi.y(),z3,d.x(),d.y(),zd,&at2,&bt2)) 
00448                 {
00449                         tryset=0;
00450                         //break;
00451                 }
00452                 c1=getCost(at2,bt2,at1,bt1);
00453         //      if(fd->has_neighbor(fd2))
00454                         c12=getCost(at2,bt2,ad2,bd2);
00455                 
00456         //      if(f2->has_neighbor(fc))
00457                         c4=getCost(at2,bt2,ac,bc);
00458 
00459         }
00460         
00461         c6=0;
00462         //if(fa->has_neighbor(fa1))
00463         c6=getCost(aa,ba,aa1,ba1);
00464         
00465         c7=0;
00466         //if(fa->has_neighbor(fa2))
00467                 c7=getCost(aa,ba,aa2,ba2);
00468         
00469         c8=0;
00470         //if(fb->has_neighbor(fb1))
00471                 c8=getCost(ab,bb,ab1,bb1);
00472         c9=0;
00473 //      if(fb->has_neighbor(fb2))
00474                 c9=getCost(ab,bb,ab2,bb2);
00475         
00476 
00477         c10=0;
00478 //      if(fc->has_neighbor(fc2))
00479                 c10=getCost(ac,bc,ac2,bc2);
00480         c11=0;
00481 //      if(fc->has_neighbor(fc1))
00482                 c11=getCost(ac,bc,ac1,bc1);
00483         if(tryset)
00484         {
00485                 s3=c1+c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13;
00486                 if(s3<s2)
00487                 {
00488                         //dttmp=*dt;
00489                         //dttmp.flip(f1,i);
00490                         //dttmp.flip(fd,fd->index(fd->vertex(fd->cw(id)) )     );
00491                         //if(dttmp.is_valid()) 
00492                         {dt->flip(f1,i);
00493                         dt->flip(fd,fd->index(fd->vertex(fd->cw(id)) )     );
00494                         return true;
00495                         }
00496                 }
00497         }
00498 //**************************************************************
00499         //setting 4
00500         //c3 c5 c6 c7 c8 c9 reused - surely calc b4
00501         tryset=1;
00502         c1=0;
00503         c2=0;
00504         c4=0;
00505         c10=0;
00506         c11=0;
00507         c12=0;
00508         c13=0;
00509         if(!checkConvex(pi,pin,c,pcwi)) tryset=0;
00510         //if(f2->has_neighbor(fc))
00511         {
00512                 if(!getPlaneEqn(pi.x(),pi.y(),z1,pin.x(),pin.y(),z4,c.x(),c.y(),zc,&at1,&bt1)) 
00513                 {
00514                         tryset=0;
00515                         //break;
00516                 }
00517                 if(!getPlaneEqn(pi.x(),pi.y(),z1,c.x(),c.y(),zc,pcwi.x(),pcwi.y(),z3,&at2,&bt2)) 
00518                 {
00519                         tryset=0;
00520                         //break;
00521                 }
00522                 c1=getCost(at1,bt1,at2,bt2);
00523                 c2=getCost(at1,bt1,a2,b2);
00524         //      if(fc->has_neighbor(fc2))
00525                         c4=getCost(at1,bt1,ac2,bc2);
00526         //      if(fc->has_neighbor(fc1))
00527                         c10=getCost(at2,bt2,ac1,bc1);
00528         //      if(f1->has_neighbor(fd))
00529                 {
00530                         c11=getCost(at2,bt2,ad,bd);
00531         //              if(fd->has_neighbor(fd1))
00532                                 c13=getCost(ad,bd,ad1,bd1);
00533         //              if(fd->has_neighbor(fd2))
00534                                 c12=getCost(ad,bd,ad2,bd2);
00535                 }
00536 
00537         }
00538         if(tryset)
00539         {
00540                 s4=c1+c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13;
00541                 if(s4<s2)
00542                 {
00543                         //dttmp=*dt;
00544                         //dttmp.flip(f1,i);
00545                         //dttmp.flip(fc,fc->index(fc->vertex(fc->ccw(ic) )) );
00546                         //if(dttmp.is_valid())
00547                         {dt->flip(f1,i);
00548                         dt->flip(fc,fc->index(fc->vertex(fc->ccw(ic) )) );
00549                         return true;
00550                         }
00551                 }
00552         }
00553 //**************************************************************
00555         tryset=1;
00556         c5=0;c6=0;c10=0;c11=0;c12=0;c13=0;
00557         if(!checkConvex(pi,a,pccwi,pin)) tryset=0;
00558         //if(f2->has_neighbor(fa))
00559         {
00560                 if(!getPlaneEqn(a.x(),a.y(),za,pin.x(),pin.y(),z4,pi.x(),pi.y(),z1,&at1,&bt1))
00561                 {
00562                         tryset=0;
00563                         //break;
00564                 }
00565                 if(!getPlaneEqn(a.x(),a.y(),za,pccwi.x(),pccwi.y(),z2,pin.x(),pin.y(),z4,&at2,&bt2))
00566                 {
00567                         tryset=0;
00568                         //break;
00569                 }
00570                 c5=getCost(aa1,ba1,at1,bt1);
00571                 c6=getCost(aa2,ba2,at2,bt2);
00572                 c9=getCost(a1,b1,at1,bt1);
00573                 c10=getCost(at1,bt1,at2,bt2);
00574                 c11=getCost(ab,bb,at2,bt2);
00575                 c12=getCost(ab1,bb1,ab,bb);
00576                 c13=getCost(ab2,bb2,ab,bb);
00577 
00578 
00579         }
00580                 c1=0;
00581                 c7=0;
00582                 c2=0;
00583         //      if(f1->has_neighbor(fd))
00584                 {
00585                         c7=getCost(ad,bd,a1,b1);
00586 //                      if(fd->has_neighbor(fd1))
00587                                 c1=getCost(ad,bd,ad1,bd1);
00588 //                      if(fd->has_neighbor(fd2))
00589                                 c2=getCost(ad,bd,ad2,bd2);
00590 
00591                 }
00592                 c4=0;c3=0;c8=0;
00593         //      if(f2->has_neighbor(fc))
00594                 {
00595                         c8=getCost(a1,b1,ac,bc);
00596 //                      if(fc->has_neighbor(fc1))
00597                                 c3=getCost(ac,bc,ac1,bc1);
00598 //                      if(fc->has_neighbor(fc2))
00599                                 c4=getCost(ac,bc,ac2,bc2);
00600                 }
00601         if(tryset)
00602         {
00603                 s5=c1+c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13;
00604                 if(s5<s2)
00605                 {
00606                         //dttmp=*dt;
00607                         
00608                         //dttmp.flip(f1,i);
00609                         //dttmp.flip(fa,fa->index(fa->vertex(fa->ccw(ia) )) );
00610                         //if(dttmp.is_valid())
00611                         {
00612                                 dt->flip(f1,i);
00613                                 dt->flip(fa,fa->index(fa->vertex(fa->ccw(ia) )) );
00614                         
00615                         return true;
00616                         }
00617                 }
00618 
00619         }
00620 
00621 
00622 
00623 
00624 
00625 //*****************************************************************************
00626         //last possible setting
00627         //setting 6
00628         if(!checkConvex(pi,pccwi,b,pin)) return false;;
00629         if(!getPlaneEqn(pi.x(),pi.y(),z1,b.x(),b.y(),zb,pin.x(),pin.y(),z4,&at1,&bt1))
00630                 return false;
00631         
00632         if(!getPlaneEqn(pi.x(),pi.y(),z1,pccwi.x(),pccwi.y(),z2,b.x(),b.y(),zb,&at2,&bt2))
00633                 return false;
00634 
00635         c11=getCost(a1,b1,at1,bt1);
00636         c12=getCost(at1,bt1,at2,bt2);
00637         c5=getCost(at1,bt1,ab2,bb2);
00638         c6=getCost(at2,bt2,ab1,bb1);
00639         c9=getCost(at2,bt2,aa,ba);
00640         c10=getCost(aa1,ba1,aa,ba);
00641         c13=getCost(aa,ba,aa2,ba2);
00642         s6=c1+c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13;
00643         if(s6<s2)
00644         {
00645                 //dttmp=*dt;
00646                 
00647                 //dttmp.flip(f1,i);
00648                 //dttmp.flip(fb,fb->index(fb->vertex(fb->cw(ib) )) );
00649                 //if(dttmp.is_valid())
00650                 {dt->flip(f1,i);
00651                 dt->flip(fb,fb->index(fb->vertex(fb->cw(ib) )) );
00652                 return true;
00653                 }
00654         }
00655         return false;
00656 }


polygon_primitives_extraction
Author(s): Miguel Oliveira
autogenerated on Thu Nov 20 2014 11:35:55