40 bestTriangulation=NULL;
46 delete[] bestTriangulation;
47 bestTriangulation=NULL;
54 if(vertices.size()==3)
57 triangles[0].idx[0]=0;
58 triangles[0].idx[1]=1;
59 triangles[0].idx[2]=2;
62 else if(vertices.size()==4)
70 tIndex[0][0].
idx[0]=0;
71 tIndex[0][0].
idx[1]=1;
72 tIndex[0][0].
idx[2]=2;
73 tIndex[0][1].
idx[0]=2;
74 tIndex[0][1].
idx[1]=3;
75 tIndex[0][1].
idx[2]=0;
77 tIndex[1][0].
idx[0]=0;
78 tIndex[1][0].
idx[1]=1;
79 tIndex[1][0].
idx[2]=3;
80 tIndex[1][1].
idx[0]=3;
81 tIndex[1][1].
idx[1]=1;
82 tIndex[1][1].
idx[2]=2;
88 p1=vertices[tIndex[i][j].
idx[1]]-vertices[tIndex[i][j].
idx[0]];
89 p2=vertices[tIndex[i][j].
idx[2]]-vertices[tIndex[i][j].
idx[0]];
95 triangles[0]=tIndex[1][0];
96 triangles[1]=tIndex[1][1];
100 triangles[0]=tIndex[0][0];
101 triangles[1]=tIndex[0][1];
105 delete[] bestTriangulation;
107 bestTriangulation=NULL;
109 std::size_t eCount=vertices.size();
110 bestTriangulation=
new Real[eCount*eCount];
111 midPoint=
new int[eCount*eCount];
112 for(std::size_t i=0;i<eCount*eCount;i++)
113 bestTriangulation[i]=-1;
114 memset(midPoint,-1,
sizeof(
int)*eCount*eCount);
115 GetArea(0,1,vertices);
117 GetTriangulation(0,1,vertices,triangles);
119 template <
class Real>
122 delete[] bestTriangulation;
124 bestTriangulation=NULL;
126 int eCount=vertices.size();
127 bestTriangulation=
new double[eCount*eCount];
128 midPoint=
new int[eCount*eCount];
129 for(
int i=0;i<eCount*eCount;i++)
130 bestTriangulation[i]=-1;
131 memset(midPoint,-1,
sizeof(
int)*eCount*eCount);
132 return GetArea(0,1,vertices);
138 std::size_t eCount=vertices.size();
144 ii=midPoint[i*eCount+j];
147 tIndex.
idx[0] = int( i );
148 tIndex.
idx[1] = int( j );
149 tIndex.
idx[2] = int( ii );
150 triangles.push_back(tIndex);
151 GetTriangulation(i,ii,vertices,triangles);
152 GetTriangulation(ii,j,vertices,triangles);
157 Real MinimalAreaTriangulation<Real>::GetArea(
const std::size_t& i,
const std::size_t& j,
const std::vector<Point3D<Real> >& vertices)
160 std::size_t eCount=vertices.size();
161 std::size_t idx=i*eCount+j;
167 bestTriangulation[idx]=0;
170 if(midPoint[idx]!=-1)
171 return bestTriangulation[idx];
173 for(std::size_t r=j+1;r<ii;r++)
175 std::size_t rr=r%eCount;
176 std::size_t idx1=i*eCount+rr,idx2=rr*eCount+j;
177 Point3D<Real> p,p1,p2;
178 p1=vertices[i]-vertices[rr];
179 p2=vertices[j]-vertices[rr];
182 if(bestTriangulation[idx1]>=0)
184 temp+=bestTriangulation[idx1];
187 if(bestTriangulation[idx2]>0)
188 temp+=bestTriangulation[idx2];
190 temp+=GetArea(rr,j,vertices);
194 if(bestTriangulation[idx2]>=0)
195 temp+=bestTriangulation[idx2];
197 temp+=GetArea(rr,j,vertices);
200 temp+=GetArea(i,rr,vertices);
209 bestTriangulation[idx]=a;
MinimalAreaTriangulation(void)
~MinimalAreaTriangulation(void)
void CrossProduct(const Point3D< Real > &p1, const Point3D< Real > &p2, Point3D< Real > &p)
double Length(const Point3D< Real > &p)