1 #ifndef AIMS_MESH2MESH_RESAMPLE_H 2 #define MESH2MESH_RESAMPLE_H 26 _source(source), _target(target), _sx(sx), _sy(sy), _tx(tx), _ty(ty), _period(period) {checkIntegrity(); buildTriangles();}
43 void checkIntegrity();
44 void buildAlternateRep();
45 void buildTriangles();
46 float _min(
float a,
float b,
float c);
47 float _max(
float a,
float b,
float c);
49 std::vector< AimsVector<std::pair<float, float>, 3> > _triangles;
62 float Mesh2mesh::_min(
float a,
float b,
float c)
72 float Mesh2mesh::_max(
float a,
float b,
float c)
85 void Mesh2mesh::checkIntegrity()
88 int ns=_source.vertex().size();
89 int nt=_target.vertex().size();
91 if ((nsx != nsy) || (nsx != ns) || (nsy !=ns))
93 std::cerr <<
"Mesh2mesh : number of nodes/items faulty for source" << std::endl;
96 else if ((ntx != nty) || (ntx != nt) || (nty !=nt))
98 std::cerr <<
"Mesh2mesh : number of nodes/items faulty for target" << std::endl;
109 void Mesh2mesh::buildAlternateRep()
117 void Mesh2mesh::buildTriangles()
119 AimsVector<uint, 3> tri;
120 std::vector<AimsVector<uint, 3> > poly=_source.polygon();
122 float x1, x2, x3, y1, y2, y3;
130 p1=tri[0]; p2=tri[1]; p3=tri[2];
131 x1=_sx[0].
item(p1); y1=_sy[0].
item(p1);
132 x2=_sx[0].
item(p2); y2=_sy[0].
item(p2);
133 x3=_sx[0].
item(p3); y3=_sy[0].
item(p3);
140 if ((x2 > _period - x2) || (x3 > _period - x3))
143 if (fabs(x2)<eps) x2=_period;
144 if (fabs(x3)<eps) x3=_period;
147 else if (fabs(x2)<eps)
149 if ((x1>_period-x1) || (x3>_period-x3))
152 if (fabs(x3)<eps) x3=_period;
155 else if (fabs(x3)<eps)
157 if ((x1>_period-x1) || (x2>_period-x2))
161 AimsVector<std::pair<float, float>, 3> newTri;
162 newTri[0]=std::pair<float, float>(x1, y1);
163 newTri[1]=std::pair<float, float>(x2, y2);
164 newTri[2]=std::pair<float, float>(x3, y3);
165 _triangles.push_back(newTri);
175 double p1x, p1y, p2x, p2y, p3x, p3y;
176 double vp3, vp2, vp1;
177 AimsVector<std::pair<float, float>, 3> newTri=_triangles[i];
179 p1x=newTri[0].first; p1y=newTri[0].second;
180 p2x=newTri[1].first; p2y=newTri[1].second;
181 p3x=newTri[2].first; p3y=newTri[2].second;
185 vp1=((p3x-p1x)*(py-p1y) - (p3y-p1y)*(px-p1x))
186 *((px-p1x)*(p2y-p1y) - (py-p1y)*(p2x-p1x));
188 vp2=((p3x-p2x)*(py-p2y) - (p3y-p2y)*(px-p2x))
189 *((px-p2x)*(p1y-p2y) - (py-p2y)*(p1x-p2x));
191 vp3=((p1x-p3x)*(py-p3y) - (p1y-p3y)*(px-p3x))
192 *((px-p3x)*(p2y-p3y) - (py-p3y)*(p2x-p3x));
194 if ((vp1>=0) && (vp2>=0) && (vp3>=0))
207 float dist, distMin=10000.0;
209 for (i=0; i<_ns; i++)
211 dist=sqrt((x-_sx[0].item(i))*(x-_sx[0].item(i)) + (y-_sy[0].item(i))*(y-_sy[0].item(i)));
225 std::vector< AimsVector<uint,3> > poly=_source.polygon();
226 uint ntr_s=poly.size();
230 int flag=0, count=0, countZe=0;
231 float x1, x2, x3, y1, y2, y3;
233 if (text[0].nItem() != _ns)
235 std::cerr <<
"Mesh2Mesh::sendTextureTotarget : texture does not have the same nb of items than the source" << std::endl;
239 for (i=0; i<_nt; i++)
245 for (j=0; (j<ntr_s) && (flag==0); j++)
267 AimsVector<std::pair<float, float>, 3> newTri=_triangles[polsrc];
268 x1=newTri[0].first; y1=newTri[0].second;
269 x2=newTri[1].first; y2=newTri[1].second;
270 x3=newTri[2].first; y3=newTri[2].second;
278 z1=text[0].
item(poly[polsrc][0]);
279 z2=text[0].
item(poly[polsrc][1]);
280 z3=text[0].
item(poly[polsrc][2]);
283 t1=(y2-y1)*(z3-z1) - (y3-y1)*(z2-z1);
284 t2=(x3-x1)*(z2-z1) - (x2-x1)*(z3-z1);
285 t3=(x2-x1)*(y3-y1) - (x3-x1)*(y2-y1);
288 result[0].
item(i)=((x1*t1 + y1*t2 + z1*t3 - x*t1 - y*t2)/t3);
319 std::vector<Point3df> vert_s=_source.vertex();
320 std::vector<Point3df> vert_t;
322 std::vector< AimsVector<uint,3> > poly=_target.polygon();
324 for (i=0; i<_ns; i++)
326 x_coord[0].item(i)=vert_s[i][0];
327 y_coord[0].item(i)=vert_s[i][1];
328 z_coord[0].
item(i)=vert_s[i][2];
335 for (i=0; i<_nt; i++)
337 Point3df point(x_rs[0].item(i), y_rs[0].item(i), z_rs[0].item(i));
338 vert_t.push_back(point);
341 newSource.vertex()=vert_t;
342 newSource.polygon()=poly;
343 newSource.updateNormals();
Mesh2mesh(AimsSurfaceTriangle source, AimsSurfaceTriangle target, TimeTexture< float > sx, TimeTexture< float > sy, TimeTexture< float > tx, TimeTexture< float > ty, float period)
TimeTexture< float > sendTextureToTarget(TimeTexture< float > text)
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
AimsSurfaceTriangle remeshSourceToTarget()
int isInTriangle(float x, float y, uint i)
const T & item(int n) const
uint nearestNeighbour(float x, float y)