Commit 2c3d4e33 authored by Thomas's avatar Thomas
Browse files

ajout fction linkVertices

parent 77875017
...@@ -23,8 +23,11 @@ inline bool valueOf(const std::string &s, T &obj) ...@@ -23,8 +23,11 @@ inline bool valueOf(const std::string &s, T &obj)
} }
template <typename PFP> template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& position, CellMarker& polygons) bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& position, CellMarker& polygons, CellMarker& polygonsFaces)
{ {
typedef typename PFP::VEC3 VEC3;
typedef std::vector<VEC3 > POLYGON;
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0); xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
xmlNodePtr map_node = xmlDocGetRootElement(doc); xmlNodePtr map_node = xmlDocGetRootElement(doc);
...@@ -34,7 +37,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -34,7 +37,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
return false; return false;
} }
typedef std::vector<typename PFP::VEC3 > POLYGON;
std::vector<POLYGON> allPoly; std::vector<POLYGON> allPoly;
for (xmlNode* cur_node = map_node->children; cur_node; cur_node = cur_node->next) for (xmlNode* cur_node = map_node->children; cur_node; cur_node = cur_node->next)
...@@ -54,7 +57,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -54,7 +57,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
// CGoGNout << "path "<< prop << CGoGNendl; // CGoGNout << "path "<< prop << CGoGNendl;
std::string allcoords((reinterpret_cast<const char*>(prop))); std::string allcoords((reinterpret_cast<const char*>(prop)));
std::stringstream is(allcoords); std::stringstream is(allcoords);
bool relative; bool relative=false;
bool push_point; bool push_point;
std::string coord; std::string coord;
int mode = -1; int mode = -1;
...@@ -113,57 +116,61 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -113,57 +116,61 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
{ {
switch(mode) switch(mode)
{ {
case 0 : //relative case 0 : //relative
break; break;
case 1 : //absolute case 1 : //absolute
break; break;
case 2 : //horizontal case 2 : //horizontal
{ {
std::stringstream streamCoord(coord); std::stringstream streamCoord(coord);
std::string xS; std::string xS;
std::getline(streamCoord, xS, ',' ); std::getline(streamCoord, xS, ',' );
valueOf(xS,x); valueOf(xS,x);
POLYGON curPoly = allPoly[allPoly.size()-1]; POLYGON curPoly = allPoly[allPoly.size()-1];
typename PFP::VEC3 previous = (curPoly)[(curPoly).size()-1]; VEC3 previous = (curPoly)[(curPoly).size()-1];
y = previous[1]; y = previous[1];
push_point=true; push_point=true;
}
break;
case 3 : //vertical
{
std::stringstream streamCoord(coord);
std::string yS;
std::getline(streamCoord, yS, ',' );
valueOf(yS,y);
POLYGON curPoly = allPoly[allPoly.size()-1];
typename PFP::VEC3 previous = (curPoly)[(curPoly).size()-1];
x = previous[0];
push_point=true;
}
break;
case 4 : //bezier
{
std::getline( is, coord, ' ' ); //ignore first control point
std::getline( is, coord, ' ' ); //ignore second control point
}
break;
case 5 : //bezier 2
{
std::getline( is, coord, ' ' ); //ignore control point
}
break;
case 6 : //elliptic
std::getline( is, coord, ' ' ); //ignore rx
std::getline( is, coord, ' ' ); //ignore ry
std::getline( is, coord, ' ' ); //ignore x-rotation
std::getline( is, coord, ' ' ); //ignore large arc flag
std::getline( is, coord, ' ' ); //ignore sweep flag
break;
} }
break;
case 3 : //vertical
{
std::stringstream streamCoord(coord);
std::string yS;
std::getline(streamCoord, yS, ',' );
valueOf(yS,y);
POLYGON curPoly = allPoly[allPoly.size()-1];
typename PFP::VEC3 previous = (curPoly)[(curPoly).size()-1];
x = previous[0];
push_point=true;
}
break;
case 4 : //bezier
{
std::getline( is, coord, ' ' ); //ignore first control point
std::getline( is, coord, ' ' ); //ignore second control point
}
break;
case 5 : //bezier 2
std::getline( is, coord, ' ' ); //ignore control point
break;
case 6 : //elliptic
std::getline( is, coord, ' ' ); //ignore rx
std::getline( is, coord, ' ' ); //ignore ry
std::getline( is, coord, ' ' ); //ignore x-rotation
std::getline( is, coord, ' ' ); //ignore large arc flag
std::getline( is, coord, ' ' ); //ignore sweep flag
break;
}
std::stringstream streamCoord(coord); std::stringstream streamCoord(coord);
std::string xS,yS; std::string xS,yS;
std::getline(streamCoord, xS, ',' ); std::getline(streamCoord, xS, ',' );
...@@ -182,15 +189,29 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -182,15 +189,29 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
if(relative && curPoly.size()>0) if(relative && curPoly.size()>0)
{ {
typename PFP::VEC3 previous = (curPoly)[(curPoly).size()-1]; VEC3 previous = (curPoly)[(curPoly).size()-1];
x += previous[0]; x += previous[0];
y += previous[1]; y += previous[1];
} }
// std::cout << "coord " << x << " " << y << std::endl; std::cout << "coord " << x << " " << y << std::endl;
curPoly.push_back(typename PFP::VEC3(x,y,0)); curPoly.push_back(VEC3(x,y,0));
} }
} }
//check orientation : set in CCW
POLYGON& curPoly = allPoly[allPoly.size()-1];
if(curPoly.size()>2)
{
VEC3 v1(curPoly[1]-curPoly[0]);
VEC3 v2(curPoly[2]-curPoly[1]);
if((v1^v2)[2]<0)
{
std::cout << "reverse !" << std::endl;
std::reverse(curPoly.begin(), curPoly.end());
}
}
} }
} }
} }
...@@ -204,13 +225,15 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -204,13 +225,15 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
for(it = allPoly.begin() ; it != allPoly.end() ; ++it) for(it = allPoly.begin() ; it != allPoly.end() ; ++it)
{ {
if(it->size()<3) if(it->size()<4)
{ {
it = allPoly.erase(it); it = allPoly.erase(it);
} }
else else
{ {
Dart d = map.newFace(it->size()-1); Dart d = map.newFace(it->size()-1);
std::cout << "newFace " << it->size()-1 << std::endl;
polygonsFaces.mark(d);
for(typename POLYGON::iterator emb = it->begin() ; emb != it->end() ; emb++) for(typename POLYGON::iterator emb = it->begin() ; emb != it->end() ; emb++)
{ {
position[d] = *emb; position[d] = *emb;
...@@ -242,19 +265,32 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -242,19 +265,32 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
DartMarker close(map); DartMarker close(map);
map.closeMap(close); map.closeMap(close);
CellMarker linked(map,FACE); float maxDistSq=40.0f*40.0f;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = map.begin(); d != map.end(); map.next(d))
{
VEC3 p1 =position[d];
VEC3 p2 =position[map.phi1(d)];
if((p1-p2).norm2()>maxDistSq)
{
VEC3 p3 = (p1+p2)/2.0f;
map.cutEdge(d);
position[map.phi1(d)] = p3;
}
}
CellMarker linked(map,VERTEX);
for(Dart d = map.begin();d != map.end(); map.next(d))
{ {
if(!linked.isMarked(d) && !inside.isMarked(d)) if(!linked.isMarked(d) && !inside.isMarked(d))
{ {
linked.mark(d); linked.mark(d);
Dart dMin; Dart dMin=map.end();
float distMin = (bb.max()-bb.min()).norm2(); float distMin = 1.0f/0.0f;
for(Dart dd = map.begin(); dd != map.end(); map.next(dd)) for(Dart dd = map.begin(); dd != map.end(); map.next(dd))
{ {
if(!map.sameFace(d,dd)) if(!inside.isMarked(dd) && !map.sameFace(d,dd))
{ {
float dist = (position[dd]-position[d]).norm2(); float dist = (position[dd]-position[d]).norm();
if(dist<distMin) if(dist<distMin)
{ {
distMin = dist; distMin = dist;
...@@ -263,11 +299,23 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP ...@@ -263,11 +299,23 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP
} }
} }
// map.splitFace(d,d); if(dMin!=map.end())
// map.splitFace(dMin,dMin); {
Dart dChoose = d;
Dart dStart = d;
do {
float dist = (position[dMin]-position[d]).norm();
if(dist<distMin)
{
distMin = dist;
dChoose = d;
}
d = map.phi1(d);
} while(d!= dStart);
// map.sewFaces(map.phi_1(d),map.phi_1(dMin)); map.linkVertices(dMin,dChoose);
// map.mergeFaces(map.phi_1(d)); }
} }
} }
......
...@@ -107,6 +107,12 @@ public: ...@@ -107,6 +107,12 @@ public:
*/ */
virtual void splitFace(Dart d, Dart e) ; virtual void splitFace(Dart d, Dart e) ;
/**
* No attribute is attached to the new edge
* The attributes attached to the face of dart d are kept on the resulting face
*/
virtual void linkVertices(Dart d, Dart e) ;
/** /**
* The attributes attached to the face of dart d are kept on the resulting face * The attributes attached to the face of dart d are kept on the resulting face
*/ */
......
...@@ -319,6 +319,25 @@ void EmbeddedMap2<MAP2>::splitFace(Dart d, Dart e) ...@@ -319,6 +319,25 @@ void EmbeddedMap2<MAP2>::splitFace(Dart d, Dart e)
} }
} }
template <typename MAP2>
void EmbeddedMap2<MAP2>::linkVertices(Dart d, Dart e)
{
Dart dNext = MAP2::phi1(d) ;
MAP2::linkVertices(d,e);
if (MAP2::isOrbitEmbedded(VERTEX))
{
MAP2::copyDartEmbedding(VERTEX, MAP2::phi_1(e), d) ;
MAP2::copyDartEmbedding(VERTEX, MAP2::phi_1(d), e) ;
}
if (MAP2::isOrbitEmbedded(FACE))
{
MAP2::embedOrbit(FACE, dNext, MAP2::getEmbedding(FACE, dNext)) ;
}
}
template <typename MAP2> template <typename MAP2>
bool EmbeddedMap2<MAP2>::mergeFaces(Dart d) bool EmbeddedMap2<MAP2>::mergeFaces(Dart d)
{ {
......
...@@ -145,6 +145,13 @@ public: ...@@ -145,6 +145,13 @@ public:
*/ */
void splitFace(Dart d, Dart e); void splitFace(Dart d, Dart e);
//! Link two vertices belonging to distinct faces (add an edge between the two vertices)
/*! \pre Dart d and e MUST be different and belong to distinct face
* @param d first dart in the face
* @param e second dart in the face
*/
void linkVertices(Dart d, Dart e);
//! Merge the two faces of d and e, darts d & e disappear //! Merge the two faces of d and e, darts d & e disappear
/*! \pre Dart d and e MUST belong to distinct faces /*! \pre Dart d and e MUST belong to distinct faces
* \warning Darts d and e no longer exist after the call * \warning Darts d and e no longer exist after the call
......
...@@ -157,6 +157,14 @@ inline void Map1::splitFace(Dart d, Dart e) ...@@ -157,6 +157,14 @@ inline void Map1::splitFace(Dart d, Dart e)
phi1sew(phi_1(d), phi_1(e)) ; // phi1sew between the 2 new inserted darts phi1sew(phi_1(d), phi_1(e)) ; // phi1sew between the 2 new inserted darts
} }
inline void Map1::linkVertices(Dart d, Dart e)
{
assert(d != e && !sameOrientedFace(d, e)) ;
Map1::cutEdge(phi_1(d)); // cut the edge before d (insert a new dart before d)
Map1::cutEdge(phi_1(e)); // cut the edge before e (insert a new dart before e)
phi1sew(phi_1(d), phi_1(e)) ; // phi1sew between the 2 new inserted darts
}
inline void Map1::mergeFaces(Dart d, Dart e) inline void Map1::mergeFaces(Dart d, Dart e)
{ {
assert(!sameOrientedFace(d, e)) ; assert(!sameOrientedFace(d, e)) ;
......
...@@ -190,6 +190,13 @@ public: ...@@ -190,6 +190,13 @@ public:
*/ */
virtual void splitFace(Dart d, Dart e); virtual void splitFace(Dart d, Dart e);
//! Link two vertices belonging to distinct faces (add an edge between the two vertices)
/*! \pre Dart d and e MUST be different and belong to distinct face
* @param d first dart in the face
* @param e second dart in the face
*/
virtual void linkVertices(Dart d, Dart e);
//! Merge the two faces incident to the edge of d. //! Merge the two faces incident to the edge of d.
/*! Works only for non-border edges. /*! Works only for non-border edges.
* \warning Darts d & phi2(d) no longer exist after the call * \warning Darts d & phi2(d) no longer exist after the call
......
...@@ -226,6 +226,12 @@ void Map2::splitFace(Dart d, Dart e) ...@@ -226,6 +226,12 @@ void Map2::splitFace(Dart d, Dart e)
phi2sew(phi_1(d), phi_1(e)); // Sew the two resulting faces along the new edge phi2sew(phi_1(d), phi_1(e)); // Sew the two resulting faces along the new edge
} }
void Map2::linkVertices(Dart d, Dart e)
{
Map1::linkVertices(d, e); // Split the face
phi2sew(phi_1(d), phi_1(e)); // Sew the two resulting faces along the new edge
}
bool Map2::mergeFaces(Dart d) bool Map2::mergeFaces(Dart d)
{ {
Dart e = phi2(d) ; Dart e = phi2(d) ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment