Commit 89786538 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

ajout fichiers Traversors

parent d27ef426
......@@ -60,7 +60,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = mts.getEmbIdx(index++);
if (em!=prec)
if (em != prec)
{
prec = em;
edgesBuffer.push_back(em);
......@@ -74,21 +74,21 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
nbe = edgesBuffer.size();
if (nbe > 2)
{
Dart d = map.newFace(nbe,false);
Dart d = map.newFace(nbe, false);
for (unsigned int j = 0; j < nbe; ++j)
{
unsigned int em = edgesBuffer[j]; // get embedding
map.setDartEmbedding(VERTEX, d, em); // associate to dart
vecDartsPerVertex[em].push_back(d); // store incident darts for fast phi2 reconstruction
map.embedOrbit(VERTEX, d, em) ;
// map.setDartEmbedding(VERTEX, d, em); // associate to dart
vecDartsPerVertex[em].push_back(d); // store incident darts for fast adjacency reconstruction
d = map.phi1(d);
}
m.markOrbit(FACE, d); // mark on the fly to unmark on second loop
m.markOrbit(ORIENTED_FACE, d); // mark on the fly to unmark on second loop
}
}
unsigned int nbnm = 0;
// reconstruct neighbourhood
unsigned int nbnm = 0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (m.isMarked(d))
......@@ -97,7 +97,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];
unsigned int embd = map.getEmbedding(VERTEX, d);
Dart good_dart=NIL;
Dart good_dart = NIL;
for (typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
{
if (map.getEmbedding(VERTEX, map.phi1(*it)) == embd)
......@@ -108,7 +108,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesSurface<PFP>& mts)
{
if (good_dart == map.phi2(good_dart))
{
map.sewFaces(d, good_dart,false);
map.sewFaces(d, good_dart, false);
m.unmarkOrbit(EDGE, d);
}
}
......
......@@ -117,11 +117,11 @@ protected:
/**
* numbers that defined the subdivision of Polyhedron
*/
int m_nx;
unsigned int m_nx;
int m_ny;
unsigned int m_ny;
int m_nz;
unsigned int m_nz;
bool m_top_closed;
......@@ -170,7 +170,7 @@ public:
/**
* create simple simple polyhedron (not handled by Polyhedron object)
*/
static Dart createPolyhedron(typename PFP::MAP& the_map, int nbFaces);
static Dart createPolyhedron(typename PFP::MAP& the_map, unsigned int nbFaces);
/**
* create simple simple tetrahedron (not handled by Polyhedron object)
......@@ -225,7 +225,7 @@ public:
* @param bottom_closed close the bottom with triangles fan
* @return the dart
*/
Dart cylinder_topo(int n, int z, bool top_closed, bool bottom_closed);
Dart cylinder_topo(unsigned int n, unsigned int z, bool top_closed, bool bottom_closed);
/**
* Create a subdivided (surface) cone (with param 1,3,true create tetrahedron)
......@@ -234,7 +234,7 @@ public:
* @param bottom_closed close the bottom with triangles fan
* @return the dart
*/
Dart cone_topo(int n, int z, bool bottom_closed);
Dart cone_topo(unsigned int n, unsigned int z, bool bottom_closed);
/**
* Create a subdived (surface) cube
......@@ -244,7 +244,7 @@ public:
* @param z nb of quads in z
* @return the dart
*/
Dart cube_topo(int x, int y, int z);
Dart cube_topo(unsigned int x, unsigned int y, unsigned int z);
/**
* Create a subdivided (surface) cylinder
......@@ -254,7 +254,7 @@ public:
* @param bottom_closed close the bottom with triangles fan
* @return the dart
*/
Dart tore_topo(int m, int n);
Dart tore_topo(unsigned int m, unsigned int n);
/**
* embed the topo grid Polyhedron
......@@ -262,7 +262,7 @@ public:
* @param x
* @param y
*/
void embedGrid(float x, float y, float z=0.0f);
void embedGrid(float x, float y, float z = 0.0f);
/**
* embed the topo cylinder Polyhedron
......@@ -317,7 +317,7 @@ public:
* @param maxHeight height to reach
* @param turns number of turn
*/
void embedHelicoid( float radius_min, float radius_max, float maxHeight, float nbTurn, int orient=1);
void embedHelicoid( float radius_min, float radius_max, float maxHeight, float nbTurn, int orient = 1);
/**
* transform the Polyhedron with transformation matrice
......
......@@ -37,26 +37,22 @@ void explodPolyhedron(typename PFP::MAP& map, Dart d, typename PFP::TVEC3 positi
map.unsewVertexUmbrella(d);
unsigned int newFaceDegree = map.closeHole(map.phi1(d));
if(newFaceDegree != 3)
{
//chercher le brin ou demarer
// chercher le brin ou demarrer
std::multimap<Dart, int> edges ;
typename std::multimap<Dart, int>::iterator it ;
Dart d12 = map.phi2(map.phi1(d));
Dart fit = d12;
int i;
unsigned int i;
do
{
i = map.faceDegree(map.phi2(fit));
std::cout << "edge(" << fit << "," << i << ")" << std::endl;
edges.insert(std::make_pair(fit, i));
fit = map.phi1(fit);
}
while(fit != d12);
......@@ -108,8 +104,6 @@ void explodPolyhedron(typename PFP::MAP& map, Dart d, typename PFP::TVEC3 positi
std::cout << "flip cas quad tri" << std::endl;
}
fit = map.phi1(fit);
}
while(map.faceDegree(fit) > 4 && fit != d12);
......@@ -118,13 +112,13 @@ void explodPolyhedron(typename PFP::MAP& map, Dart d, typename PFP::TVEC3 positi
}
template <typename PFP>
Polyhedron<PFP>::Polyhedron(const Polyhedron<PFP>& p1, const Polyhedron<PFP>& p2):
m_map(p1.m_map),
m_dart(p1.m_dart),
m_kind(COMPOSED),
m_nx(-1), m_ny(-1), m_nz(-1),
m_top_closed(false), m_bottom_closed(false),
m_positions(p1.m_positions)
Polyhedron<PFP>::Polyhedron(const Polyhedron<PFP>& p1, const Polyhedron<PFP>& p2) :
m_map(p1.m_map),
m_dart(p1.m_dart),
m_kind(COMPOSED),
m_nx(-1), m_ny(-1), m_nz(-1),
m_top_closed(false), m_bottom_closed(false),
m_positions(p1.m_positions)
{
if (&(p1.map) != &(p2.map))
{
......@@ -135,23 +129,23 @@ m_positions(p1.m_positions)
typename PFP::VEC3 center(0);
for(typename std::vector<Dart>::const_iterator di=p1.m_tableVertDarts.begin(); di!=p1.m_tableVertDarts.end(); ++di)
for(typename std::vector<Dart>::const_iterator di = p1.m_tableVertDarts.begin(); di != p1.m_tableVertDarts.end(); ++di)
{
m_tableVertDarts.push_back(*di);
center += m_positions[*di];
}
// O(n2) pas terrible !!
for(typename std::vector<Dart>::const_iterator di=p2.m_tableVertDarts.begin(); di!=p2.m_tableVertDarts.end(); ++di)
for(typename std::vector<Dart>::const_iterator di = p2.m_tableVertDarts.begin(); di != p2.m_tableVertDarts.end(); ++di)
{
unsigned int em = m_map.getEmbedding(*di,VERTEX);
unsigned int em = m_map.getEmbedding(*di, VERTEX);
typename std::vector<Dart>::const_iterator dj=p1.m_tableVertDarts.begin();
bool found = false;
while ((dj !=p1.m_tableVertDarts.end()) && (!found))
{
unsigned int xm = m_map.getEmbedding(*dj,VERTEX);
if ( xm == em)
unsigned int xm = m_map.getEmbedding(*dj, VERTEX);
if (xm == em)
found = true;
else
++dj;
......@@ -270,7 +264,7 @@ Dart Polyhedron<PFP>::createPrism(typename PFP::MAP& the_map)
}
template <typename PFP>
Dart Polyhedron<PFP>::createPolyhedron(typename PFP::MAP& the_map, int n)
Dart Polyhedron<PFP>::createPolyhedron(typename PFP::MAP& the_map, unsigned int n)
{
Dart d;
switch (n)
......@@ -352,7 +346,7 @@ Dart Polyhedron<PFP>::grid_topo(unsigned int x, unsigned int y)
}
template <typename PFP>
Dart Polyhedron<PFP>::cylinder_topo(int n, int z, bool top_closed, bool bottom_closed)
Dart Polyhedron<PFP>::cylinder_topo(unsigned int n, unsigned int z, bool top_closed, bool bottom_closed)
{
if (m_kind != NONE) return m_dart;
......@@ -360,8 +354,8 @@ Dart Polyhedron<PFP>::cylinder_topo(int n, int z, bool top_closed, bool bottom_c
m_nx = n;
m_nz = z;
m_bottom_closed=bottom_closed;
m_top_closed=top_closed;
m_bottom_closed = bottom_closed;
m_top_closed = top_closed;
int nb = (n)*(z+1);
if (bottom_closed) nb++;
......@@ -371,40 +365,40 @@ Dart Polyhedron<PFP>::cylinder_topo(int n, int z, bool top_closed, bool bottom_c
m_tableVertDarts.reserve(nb);
// creation of quads and storing vertices
for (int i=0;i<z;++i)
for (unsigned int i = 0; i < z; ++i)
{
for (int j=0;j<n;++j)
for (unsigned int j = 0; j < n; ++j)
{
Dart d = m_map.newFace(4,false);
Dart d = m_map.newFace(4, false);
m_tableVertDarts.push_back(d);
}
}
for (int i=0;i<n;++i)
for (unsigned int i = 0; i < n; ++i)
{
m_tableVertDarts.push_back( m_map.phi_1(m_tableVertDarts[(z-1)*n+i]) );
}
//sewing the quads
for (int i=0;i<z;++i)
for (unsigned int i = 0; i < z; ++i)
{
for (int j=0;j<n;++j)
for (unsigned int j = 0; j < n; ++j)
{
if (i>0) // sew with preceeding row
if (i > 0) // sew with preceeding row
{
int pos = i*n+j;
Dart d = m_tableVertDarts[pos];
Dart e = m_tableVertDarts[pos-n];
e = m_map.phi1(m_map.phi1(e));
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
if (j>0) // sew with preceeding column
if (j > 0) // sew with preceeding column
{
int pos = i*n+j;
Dart d = m_tableVertDarts[pos];
d = m_map.phi_1(d);
Dart e = m_tableVertDarts[pos-1];
e = m_map.phi1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
else
{
......@@ -413,7 +407,7 @@ Dart Polyhedron<PFP>::cylinder_topo(int n, int z, bool top_closed, bool bottom_c
d = m_map.phi_1(d);
Dart e = m_tableVertDarts[pos+(n-1)];
e = m_map.phi1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
}
}
......@@ -450,7 +444,7 @@ Dart Polyhedron<PFP>::cylinder_topo(int n, int z, bool top_closed, bool bottom_c
if (top_closed)
{
Dart d = m_map.phi_1(m_tableVertDarts[n*z]);
if(m_map.closeHole(d,true))
if(m_map.closeHole(d, true))
{
d = m_map.phi2(d);
if(m_map.faceDegree(d) > 3)
......@@ -626,7 +620,7 @@ Dart Polyhedron<PFP>::cylinder_topo(int n, int z, bool top_closed, bool bottom_c
// }
template <typename PFP>
Dart Polyhedron<PFP>::cube_topo(int x, int y,int z)
Dart Polyhedron<PFP>::cube_topo(unsigned int x, unsigned int y, unsigned int z)
{
if (m_kind != NONE) return m_dart;
......@@ -646,31 +640,31 @@ Dart Polyhedron<PFP>::cube_topo(int x, int y,int z)
std::vector<Dart>& tableTop = primTop.getVertexDarts();
int index_side = 2*(x+y)*z;
for(int i=0;i<x;++i)
for(unsigned int i = 0; i < x; ++i)
{
Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
Dart e = tableTop[i];
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
for(int i=0;i<y;++i)
for(unsigned int i = 0; i < y; ++i)
{
Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
Dart e = tableTop[x+i*(x+1)];
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
for(int i=0;i<x;++i)
for(unsigned int i = 0; i < x; ++i)
{
Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
Dart e = tableTop[(x+1)*(y+1)-2 - i];
e = m_map.phi_1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
for(int i=0;i<y;++i)
for(unsigned int i = 0; i < y; ++i)
{
Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
Dart e = tableTop[(y-1-i)*(x+1)];
e = m_map.phi_1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
// the bottom
......@@ -679,57 +673,53 @@ Dart Polyhedron<PFP>::cube_topo(int x, int y,int z)
std::vector<Dart>& tableBottom = primBottom.getVertexDarts();
index_side = 3*(x+y)+(x-1);
for(int i=0;i<x;++i)
for(unsigned int i = 0; i < x; ++i)
{
Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
Dart e = tableBottom[i];
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
for(int i=0;i<y;++i)
for(unsigned int i = 0; i < y; ++i)
{
Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
Dart e = tableBottom[x+i*(x+1)];
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
for(int i=0;i<x;++i)
for(unsigned int i = 0; i < x; ++i)
{
Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
Dart e = tableBottom[(x+1)*(y+1)-2 - i];
e = m_map.phi_1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
for(int i=0;i<y;++i)
for(unsigned int i = 0; i < y; ++i)
{
Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
Dart e = tableBottom[(y-1-i)*(x+1)];
e = m_map.phi_1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
// and add new vertex in m_tableVertDarts
//top first
for(int i=1;i<y;++i)
{
for(int j=1;j<x;++j)
for(unsigned int i = 1; i < y; ++i)
{
for(unsigned int j = 1; j < x; ++j)
m_tableVertDarts.push_back(tableTop[i*(x+1)+j]);
}
}
// then bottom
for(int i=1;i<y;++i)
{
for(int j=1;j<x;++j)
for(unsigned int i = 1; i < y; ++i)
{
for(unsigned int j = 1; j < x; ++j)
m_tableVertDarts.push_back(tableBottom[i*(x+1)+j]);
}
}
return m_dart;
}
template <typename PFP>
Dart Polyhedron<PFP>::tore_topo(int m, int n)
Dart Polyhedron<PFP>::tore_topo(unsigned int m, unsigned int n)
{
if (m_kind != NONE) return m_dart;
......@@ -739,12 +729,12 @@ Dart Polyhedron<PFP>::tore_topo(int m, int n)
m_kind = TORE;
// juste finish to sew
for(int i=0; i<n; ++i)
for(unsigned int i = 0; i < n; ++i)
{
Dart d = m_tableVertDarts[i];
Dart e = m_tableVertDarts[(m*n)+i];
e = m_map.phi_1(e);
m_map.sewFaces(d,e,false);
m_map.sewFaces(d, e, false);
}
// remove the last n vertex darts that are no more necessary (sewed with n first)
......@@ -755,7 +745,7 @@ Dart Polyhedron<PFP>::tore_topo(int m, int n)
}
template <typename PFP>
void Polyhedron<PFP>::embedGrid( float x, float y,float z)
void Polyhedron<PFP>::embedGrid(float x, float y, float z)
{
typedef typename PFP::VEC3 VEC3 ;
......@@ -767,24 +757,25 @@ void Polyhedron<PFP>::embedGrid( float x, float y,float z)
float dx = x/float(m_nx);
float dy = y/float(m_ny);
for(int i=0; i<=m_ny; ++i)
for(unsigned int i = 0; i <= m_ny; ++i)
{
for(int j=0; j<=m_nx;++j)
for(unsigned int j = 0; j <= m_nx;++j)
{
VEC3 pos(-x/2 + dx*float(j), -y/2 + dy*float(i), z);
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[i*(m_nx+1)+j];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
}
}
template <typename PFP>
void Polyhedron<PFP>::embedCylinder( float bottom_radius, float top_radius, float height)
void Polyhedron<PFP>::embedCylinder(float bottom_radius, float top_radius, float height)
{
typedef typename PFP::VEC3 VEC3 ;
if (m_kind != CYLINDER) {
if (m_kind != CYLINDER)
{
CGoGNerr << "Warning try to embedCylinder something that is not a cylnder"<<CGoGNendl;
return;
}
......@@ -792,11 +783,11 @@ void Polyhedron<PFP>::embedCylinder( float bottom_radius, float top_radius, floa
float alpha = float(2.0*M_PI/m_nx);
float dz = height/float(m_nz);
for(int i=0; i<=m_nz; ++i)
for(unsigned int i = 0; i <= m_nz; ++i)
{
float a = float(i)/float(m_nz);
float radius = a*top_radius + (1.0f-a)*bottom_radius;
for(int j=0; j<m_nx;++j)
for(unsigned int j = 0; j < m_nx; ++j)
{
float x = radius*cos(alpha*float(j));
......@@ -804,7 +795,7 @@ void Polyhedron<PFP>::embedCylinder( float bottom_radius, float top_radius, floa
VEC3 pos(x, y, -height/2 + dz*float(i));
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[i*(m_nx)+j];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
}
......@@ -814,7 +805,7 @@ void Polyhedron<PFP>::embedCylinder( float bottom_radius, float top_radius, floa
VEC3 pos(0.0f, 0.0f, -height/2 );
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[indexUmbrella++];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
if (m_top_closed)
......@@ -822,16 +813,17 @@ void Polyhedron<PFP>::embedCylinder( float bottom_radius, float top_radius, floa
VEC3 pos(0.0f ,0.0f, height/2 );
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[indexUmbrella];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
}
template <typename PFP>
void Polyhedron<PFP>::embedCone( float radius, float height)
void Polyhedron<PFP>::embedCone(float radius, float height)
{
typedef typename PFP::VEC3 VEC3 ;
if (m_kind != CONE) {
if (m_kind != CONE)
{
CGoGNerr << "Warning try to embedCone something that is not a cone"<<CGoGNendl;
return;
}
......@@ -840,9 +832,9 @@ void Polyhedron<PFP>::embedCone( float radius, float height)
int zcyl = m_nz-1;
float dz = height/float(m_nz);
for(int i=0; i<=zcyl; ++i)
for(unsigned int i = 0; i <= zcyl; ++i)
{
for(int j=0; j<m_nx;++j)
for(unsigned int j = 0; j < m_nx; ++j)
{
float rad = radius * float(m_nz-i)/float(m_nz);
float h = -height/2 + dz*float(i);
......@@ -853,7 +845,7 @@ void Polyhedron<PFP>::embedCone( float radius, float height)
VEC3 pos(x, y, h);
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[i*(m_nx)+j];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
}
......@@ -863,22 +855,23 @@ void Polyhedron<PFP>::embedCone( float radius, float height)
VEC3 pos(0.0f, 0.0f, -height/2 );
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[indexUmbrella++];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
// top always closed in cone
VEC3 pos(0.0f ,0.0f, height/2.0f );
unsigned int em = m_positions.insert(pos);
Dart d = m_tableVertDarts[indexUmbrella];
m_map.embedOrbit(VERTEX,d,em);
m_map.embedOrbit(VERTEX, d, em);
}
template <typename PFP>
void Polyhedron<PFP>::embedSphere( float radius)
void Polyhedron<PFP>::embedSphere(float radius)
{
typedef typename PFP::VEC3 VEC3 ;
if (!((m_kind==CYLINDER)&&(m_top_closed)&&(m_bottom_closed))) {
if (!((m_kind == CYLINDER) && (m_top_closed) && (m_bottom_closed)))
{
CGoGNerr << "Warning try to embedSphere something that is not a sphere (closed cylinder)"<<CGoGNendl;
return;
}
......@@ -886,9 +879,9 @@ void Polyhedron<PFP>::embedSphere( float radius)
float alpha = float(2.0*M_PI/m_nx);
float beta = float(M_PI/(m_nz+2));