Commit f2cdf37d authored by David Cazier's avatar David Cazier
Browse files

Import improved!

parent e300c9f4
......@@ -256,10 +256,10 @@ void readCoordAndStyle(xmlNode* cur_path,
}
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& polygons, CellMarker<FACE>& polygonsFaces)
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& obstacleMark, CellMarker<FACE>& buildingMark)
{
typedef typename PFP::VEC3 VEC3;
typedef std::vector<VEC3 > POLYGON;
typedef std::vector<VEC3> POLYGON;
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
xmlNodePtr map_node = xmlDocGetRootElement(doc);
......@@ -289,17 +289,6 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
xmlFreeDoc(doc);
Geom::BoundingBox<typename PFP::VEC3> * bb;
if(allBrokenLines.size()>0)
bb = new Geom::BoundingBox<typename PFP::VEC3>(*(allBrokenLines.begin()->begin()));
else if(allPoly.size()>0)
bb = new Geom::BoundingBox<typename PFP::VEC3>(*(allPoly.begin()->begin()));
else
{
std::cerr << " no usable data in svg file " << std::endl;
return false;
}
std::cout << "importSVG : XML read." << std::endl;
CellMarker<EDGE> brokenMark(map);
......@@ -331,7 +320,6 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
edgeWidth[d] = *itW;
if (*itW == 0)
std::cout << "importSVG : null path width" << std::endl ;
bb->addPoint(*emb);
position[d] = *emb;
d = map.phi1(d);
}
......@@ -355,50 +343,52 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
else
{
Dart d = map.newFace(it->size());
polygonsFaces.mark(d);
buildingMark.mark(d);
buildingMark.mark(map.phi2(d));
for(typename POLYGON::iterator emb = it->begin(); emb != it->end() ; emb++)
{
bb->addPoint(*emb);
position[d] = *emb;
obstacleMark.mark(d);
d = map.phi1(d);
}
}
}
Geom::BoundingBox<typename PFP::VEC3> bb ;
bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleM = std::max<float>(tailleX, tailleY) / 20 ;
std::cout << "bounding box = " << tailleX << " X " << tailleY << std::endl;
for(Dart d = map.begin();d != map.end(); map.next(d))
{
if(position[d][0] == position[map.phi1(d)][0] && position[d][1] == position[map.phi1(d)][1])
std::cout << "prob d " << d << std::endl;
}
DartMarker inside(map);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
polygons.mark(d);
inside.mark(d);
}
std::cout << "importSVG : Polygons generated." << std::endl;
/////////////////////////////////////////////////////////////////////////////////////////////
//cut the edges to have a more regular sampling
float maxDist = 40.0f ;
CellMarker<EDGE> treated(map) ;
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
TraversorE<typename PFP::MAP> edges(map) ;
unsigned int count = 0 ;
for (Dart d = edges.begin() ; d != edges.end() ; d = edges.next())
{
if (!polygons.isMarked(d) && !treated.isMarked(d))
if (!buildingMark.isMarked(d))
{
treated.mark(d) ;
VEC3 p1 = position[d] ;
VEC3 p2 = position[map.phi1(d)] ;
VEC3 v = p2 - p1 ;
float length = v.norm() ;
if (v.norm() > maxDist)
if (length > tailleM)
{
unsigned int nbSeg = (unsigned int)(v.norm() / maxDist) ;
unsigned int nbSeg = (unsigned int)(length / tailleM) ;
v /= nbSeg ;
count += nbSeg ;
for (unsigned int i = 0 ; i < nbSeg - 1 ; ++i)
map.cutEdge(d) ;
......@@ -417,26 +407,27 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
}
}
}
std::cout << "importSVG : Subdivision of long edges." << std::endl;
std::cout << "importSVG : Subdivision of long edges : " << count << " morceaux."<< std::endl;
/////////////////////////////////////////////////////////////////////////////////////////////
//simplify the edges to have a more regular sampling
float minDist = 30.0f ;
count = 0 ;
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
{
if(!polygons.isMarked(d))
if(!buildingMark.isMarked(d))
{
bool canSimplify = true ;
while ( canSimplify && ((position[map.phi1(d)] - position[d]).norm() < minDist) )
while ( canSimplify && ((position[map.phi1(d)] - position[d]).norm() < edgeWidth[d]) )
{
if (map.vertexDegree(map.phi1(d)) == 2) {
map.uncutEdge(d) ;
count++;
}
else canSimplify = false ;
}
}
}
std::cout << "importSVG : Downsampling of vertices." << std::endl;
std::cout << "importSVG : Downsampling of vertices : " << count << " sommets supprimés." << std::endl;
/////////////////////////////////////////////////////////////////////////////////////////////
//process broken lines
......@@ -464,8 +455,6 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
ortho.normalize() ;
v.normalize() ;
//if the valence of one of the vertex is equal to one
//cut the edge to insert the quadrangular face
if(map.vertexDegree(d1)==2)
......@@ -474,7 +463,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
brokenL.mark(map.phi1(d2)) ;
eMTreated.mark(map.phi1(d2)) ;
map.sewFaces(map.phi_1(d1), map.phi1(dN)) ;
obstacleMark.mark(map.phi_1(d1)) ;
position[map.phi_1(d1)] = p1 ;
edgePlanes[map.phi_1(d1)] = Geom::Plane3D<typename PFP::REAL>(v, p1) ;
}
......@@ -484,26 +473,24 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
map.cutEdge(d1) ;
brokenL.mark(map.phi1(d1)) ;
eMTreated.mark(map.phi1(d1)) ;
map.sewFaces(map.phi_1(d2), map.phi_1(dN)) ;
obstacleMark.mark(map.phi_1(d2)) ;
position[map.phi_1(d2)] = p2 ;
edgePlanes[map.phi_1(d2)] = Geom::Plane3D<typename PFP::REAL>(-1.0f * v, p2) ;
}
map.sewFaces(d1, dN) ;
map.sewFaces(d2, map.phi1(map.phi1(dN))) ;
obstacleMark.mark(d1) ;
edgePlanes[d1] = Geom::Plane3D<typename PFP::REAL>(ortho, p1 - (width * ortho)) ;
map.sewFaces(d2, map.phi1(map.phi1(dN))) ;
obstacleMark.mark(d2) ;
edgePlanes[d2] = Geom::Plane3D<typename PFP::REAL>(-1.0f * ortho, p2 + (width * ortho)) ;
}
}
//close the intersections
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
{
if (d == map.phi2(d)) map.closeHole(d) ;
}
map.closeMap() ;
//embed the path
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
......@@ -517,9 +504,6 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
pl = edgePlanes[d] ;
pl.project(pos) ;
// pl = edgePlanes[map.phi_1(d)] ;
// pl.project(pos) ;
position[d] = pos ;
pos = position[map.phi1(d)] ;
......@@ -527,122 +511,6 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
position[map.phi1(d)] = pos ;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
//process polygons
// std::vector<std::pair<VEC3,Dart> > toConnect;
// CellMarker connected(map,VERTEX);
// for(Dart d = map.begin(); d != map.end(); map.next(d))
// {
// if( ((!boundingBox.isMarked(d) && !inside.isMarked(d)) || (boundingBox.isMarked(d) && inside.isMarked(d)))
// && !connected.isMarked(d)
// )
// {
// connected.mark(d);
// toConnect.push_back(std::make_pair(position[d],d));
// }
// }
//
// std::sort(toConnect.begin(), toConnect.end(),posSort<VEC3>);
//
// for(typename std::vector<std::pair<VEC3 ,Dart > >::iterator it = toConnect.begin(); it != toConnect.end() ; ++it)
// {
// Dart d = it->second;
// typename std::vector<std::pair<VEC3,Dart> >::iterator it2 = it+1;
// if(it2!= toConnect.end())
// {
// Dart dd = it2->second;
// if(!map.sameFace(map.phi2(d),map.phi2(dd)))
// {
// if(!map.sameFace(dd,d)) {
// std::cout << "link" << std::endl;
// map.linkVertices(dd,d);
// }
// else
// {
// map.splitFace(dd,d);
// std::cout << "split" << std::endl;
// }
// }
// }
//
// }
//
// CellMarker connected(map,VERTEX);
// unsigned int i=0;
// for(Dart d = map.begin();d != map.end(); map.next(d))
// {
// if(!connected.isMarked(d) && !boundingBox.isMarked(d) && !inside.isMarked(d))
// {
// i++;
// Dart dMin=map.end();
// float distMin = std::numeric_limits<float>::max();
// for(Dart dd = map.begin(); dd != map.end(); map.next(dd))
// {
// if( (
// (boundingBox.isMarked(dd) && inside.isMarked(dd))
// || (!boundingBox.isMarked(dd) && !inside.isMarked(dd))
// )
// && !map.sameFace(map.phi2(d),map.phi2(dd)))
// {
// if(Geom::testOrientation2D(position[dd], position[d], position[map.phi1(d)]) == Geom::LEFT
// && Geom::testOrientation2D(position[dd], position[d], position[map.phi_1(d)]) == Geom::RIGHT)
// {
// float dist = (position[dd]-position[d]).norm();
// if(dist<distMin)
// {
// distMin = dist;
// dMin = dd;
// }
// }
// }
// }
//
// if(dMin!=map.end())
// {
// bool noIntersect=true;
// CellMarker edgeM(map,EDGE);
// edgeM.mark(d);
// edgeM.mark(dMin);
//// edgeM.mark(map.phi1(d));
//// edgeM.mark(map.phi_1(d));
//// edgeM.mark(map.phi1(dMin));
//// edgeM.mark(map.phi_1(dMin));
// for(Dart dd = map.begin();noIntersect && dd != map.end(); map.next(dd))
// {
// if(!edgeM.isMarked(dd))
// {
// edgeM.mark(dd);
// VEC3 inter;
// Geom::Intersection eeI = Geom::intersection2DSegmentSegment(position[dd],position[map.phi1(dd)],position[dMin],position[d],inter);
// if(eeI ==Geom::EDGE_INTERSECTION)
// {
// noIntersect=false;
//// std::cout << "dd " << dd << " d " << d << " dMin " << dMin << std::endl;
// std::cout << " pos " << position[dd] << " ; " << position[map.phi1(dd)] << std::endl;
// }
// }
// }
//
// if(noIntersect)
// {
// if(!map.sameFace(dMin,d)) {
// connected.mark(d);
// connected.mark(dMin);
// map.linkVertices(dMin,d);
// }
// else
// {
// map.splitFace(dMin,d);
// connected.mark(d);
// connected.mark(dMin);
// }
// }
// }
// }
// }
return true ;
}
......
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