Commit 77875017 authored by Thomas's avatar Thomas

debbug svg

parent cb3d435d
......@@ -19,7 +19,7 @@ namespace Import
bool chechXmlNode(xmlNodePtr node, const std::string& name);
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames);
bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& position, CellMarker& polygons);
......
#include <iostream>
#include "Geometry/bounding_box.h"
namespace CGoGN
{
......@@ -22,7 +23,7 @@ inline bool valueOf(const std::string &s, T &obj)
}
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<std::string>& attrNames)
bool importSVG(typename PFP::MAP& map, const std::string& filename, typename PFP::TVEC3& position, CellMarker& polygons)
{
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
xmlNodePtr map_node = xmlDocGetRootElement(doc);
......@@ -50,12 +51,13 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<
allPoly.push_back(POLYGON());
CGoGNout << "--load a path--"<< CGoGNendl;
xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "d");
CGoGNout << "path "<< prop << CGoGNendl;
// CGoGNout << "path "<< prop << CGoGNendl;
std::string allcoords((reinterpret_cast<const char*>(prop)));
std::stringstream is(allcoords);
bool relative;
bool push_point;
std::string coord;
int mode = -1;
while ( std::getline( is, coord, ' ' ) )
{
......@@ -64,73 +66,44 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<
if(coord[0]=='m' || coord[0]=='l' || coord[0]=='t') //start point, line or quadratic bezier curve
{
mode = 0;
// std::cout << "relative coordinates" << std::endl;
relative=true;
}
else if(coord[0]=='M' || coord[0] == 'L' || coord[0]=='T') //same in absolute coordinates
{
// std::cout << "absolute coordinates" << std::endl;
mode = 1;
relative=false;
}
else if(coord[0]=='h' || coord[0] == 'H') //horizontal line
{
// std::cout << "horizontal line" << std::endl;
mode = 2;
relative=(coord[0]=='h');
std::stringstream streamCoord(coord);
std::string xS;
std::getline(streamCoord, xS, ',' );
valueOf(xS,x);
POLYGON curPoly = allPoly[allPoly.size()-1];
typename PFP::VEC3 previous = (curPoly)[(curPoly).size()-1];
y = previous[1];
push_point=true;
}
else if(coord[0]=='v' || coord[0] == 'V') //vertical line
{
// std::cout << "horizontal line" << std::endl;
// std::cout << "vertical line" << std::endl;
mode = 3;
relative=(coord[0]=='v');
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;
}
else if(coord[0]=='c' || coord[0] == 'C') //bezier curve
{
// std::cout << "bezier line" << std::endl;
mode = 4;
relative=(coord[0]=='c');
std::getline( is, coord, ' ' ); //ignore first control point
std::getline( is, coord, ' ' ); //ignore second control point
}
else if(coord[0]=='s' || coord[0] == 'S' || coord[0]=='q' || coord[0] == 'Q') //bezier curve 2
{
// std::cout << "bezier line 2" << std::endl;
mode = 5;
relative= ((coord[0]=='s') || (coord[0]=='q'));
std::getline( is, coord, ' ' ); //ignore control point
}
else if(coord[0]=='a' || coord[0] == 'A') //elliptic arc
{
// std::cout << "elliptic arc" << std::endl;
mode =6;
relative= (coord[0]=='a');
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
}
else if(coord[0]=='z')
{
......@@ -138,6 +111,59 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<
}
else //coordinates
{
switch(mode)
{
case 0 : //relative
break;
case 1 : //absolute
break;
case 2 : //horizontal
{
std::stringstream streamCoord(coord);
std::string xS;
std::getline(streamCoord, xS, ',' );
valueOf(xS,x);
POLYGON curPoly = allPoly[allPoly.size()-1];
typename PFP::VEC3 previous = (curPoly)[(curPoly).size()-1];
y = previous[1];
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;
}
std::stringstream streamCoord(coord);
std::string xS,yS;
std::getline(streamCoord, xS, ',' );
......@@ -172,6 +198,79 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, std::vector<
xmlFreeDoc(doc);
Geom::BoundingBox<typename PFP::VEC3> bb(*(allPoly.begin()->begin()));
typename std::vector<POLYGON >::iterator it;
for(it = allPoly.begin() ; it != allPoly.end() ; ++it)
{
if(it->size()<3)
{
it = allPoly.erase(it);
}
else
{
Dart d = map.newFace(it->size()-1);
for(typename POLYGON::iterator emb = it->begin() ; emb != it->end() ; emb++)
{
position[d] = *emb;
bb.addPoint(*emb);
d = map.phi1(d);
}
}
}
Dart dBorder = map.newFace(4);
typename PFP::VEC3 bmin = bb.min();
typename PFP::VEC3 bmax = bb.max();
position[dBorder] = bmin-0.1f*bmin;
position[map.phi1(dBorder)] = VEC3(bmax[0],bmin[1],0) + 0.1f*VEC3(bmax[0],-bmin[1],0);
position[map.phi1(map.phi1(dBorder))] = VEC3(bmax[0],bmax[1],0) + 0.1f*bmax;
position[map.phi_1(dBorder)] = VEC3(bmin[0],bmax[1],0) + 0.1f*VEC3(-bmin[0],bmax[1],0);;
DartMarker inside(map);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(map.phi2(d) == d)
{
polygons.mark(d);
inside.mark(d);
}
}
DartMarker close(map);
map.closeMap(close);
CellMarker linked(map,FACE);
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(!linked.isMarked(d) && !inside.isMarked(d))
{
linked.mark(d);
Dart dMin;
float distMin = (bb.max()-bb.min()).norm2();
for(Dart dd = map.begin(); dd != map.end(); map.next(dd))
{
if(!map.sameFace(d,dd))
{
float dist = (position[dd]-position[d]).norm2();
if(dist<distMin)
{
distMin = dist;
dMin = dd;
}
}
}
// map.splitFace(d,d);
// map.splitFace(dMin,dMin);
// map.sewFaces(map.phi_1(d),map.phi_1(dMin));
// map.mergeFaces(map.phi_1(d));
}
}
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