bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& polygons, CellMarker<FACE>& polygonsFaces) { typedef typename PFP::VEC3 VEC3; typedef std::vector<VEC3 > POLYGON; xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0); xmlNodePtr map_node = xmlDocGetRootElement(doc); if (!checkXmlNode(map_node,"svg")) { CGoGNerr << "Wrong xml format: Root node != svg"<< CGoGNendl; return false; } std::vector<POLYGON> allPoly; std::vector<POLYGON> allBrokenLines; std::vector<float> allBrokenLinesWidth; bool closedPoly; for (xmlNode* cur_node = map_node->children; cur_node; cur_node = cur_node->next) { // for each layer if (checkXmlNode(cur_node, "g")) { // CGoGNout << "----load layer----"<< CGoGNendl; for (xmlNode* cur_path = cur_node->children ; cur_path; cur_path = cur_path->next) { if (checkXmlNode(cur_path, "path")) { POLYGON curPoly; // CGoGNout << "--load a path--"<< CGoGNendl; xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "d"); std::string allcoords((reinterpret_cast<const char*>(prop))); getPolygonFromSVG(allcoords,curPoly,closedPoly); //check orientation : set in CCW if(curPoly.size()>2) { VEC3 v1(curPoly[1]-curPoly[0]); VEC3 v2(curPoly[2]-curPoly[1]); if((v1^v2)[2]>0) { std::reverse(curPoly.begin(), curPoly.end()); } } if(closedPoly) allPoly.push_back(curPoly); else { allBrokenLines.push_back(curPoly); xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "style"); std::string allstyle((reinterpret_cast<const char*>(prop))); std::stringstream is(allstyle); std::string style; while ( std::getline( is, style, ';' ) ) { if(style.find("stroke-width:")!=std::string::npos) { std::stringstream isSize(style); std::getline( isSize, style, ':' ); float sizeOfLine; isSize >> sizeOfLine; allBrokenLinesWidth.push_back(sizeOfLine); } } } } } }