24 #include <rapidxml/rapidxml.hpp>
25 #include <rapidxml/rapidxml_print.hpp>
27 #ifdef gsOpennurbs_ENABLED
31 #ifdef gsOpenCascade_ENABLED
35 #ifdef GISMO_WITH_PSOLID // Extension files
40 #include <gzstream/gzstream.h>
46 gsFileData<T>::gsFileData()
57 this->read(fn, recursive);
68 template<
class T>
void
85 template<
class T>
void
90 template<
class T>
void
94 data->prepend_node(comment);
97 template<
class T>
void
102 data->prepend_node(comment);
104 gsXmlNode * declNode = data->allocate_node(rapidxml::node_type::node_declaration);
105 declNode->append_attribute(data->allocate_attribute(
"version",
"1.0"));
106 declNode->append_attribute(data->allocate_attribute(
"encoding",
"UTF-8"));
107 data->prepend_node(declNode);
111 saveCompressed(fname);
117 tmp = fname +
".xml";
123 std::ofstream fn( tmp.c_str() );
127 data->remove_node( data->first_node() );
130 template<
class T>
void
137 tmp = fname +
".xml.gz";
146 ogzstream fn( tmp.c_str() );
147 fn <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
153 template<
class T>
void
156 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
157 <<
": IO error near line "<<lineNumber<<std::endl;
158 throw std::runtime_error(str +
" failed");
165 if ( m_lastPath.empty() )
167 gsWarn<<
"gsFileData: Problem with file "<<fn<<
": File not found.\n";
176 return readXmlFile(m_lastPath, recursive);
178 return readXmlGzFile(m_lastPath, recursive);
179 else if (ext==
"txt")
180 return readGeompFile(m_lastPath);
182 return readGoToolsFile(m_lastPath);
183 else if (ext==
"axl")
184 return readAxelFile(m_lastPath);
185 else if (ext==
"off")
186 return readOffFile(m_lastPath);
187 #ifdef gsOpennurbs_ENABLED
188 else if (ext==
"3dm")
189 return read3dmFile(m_lastPath);
191 #ifdef gsOpenCascade_ENABLED
192 else if (ext==
"brep")
193 return readBrepFile(m_lastPath);
199 #ifdef GISMO_WITH_PSOLID
200 else if (ext==
"xmt_txt")
201 return readParasolidFile(m_lastPath);
202 else if (ext==
"x_t")
203 return readParasolidFile(m_lastPath);
204 else if (ext==
"xmt_bin")
205 return readParasolidFile(m_lastPath);
207 else if (ext==
"obj")
208 return readObjFile(m_lastPath);
209 else if (ext==
"stl")
210 return readStlFile(m_lastPath);
211 else if (ext==
"igs" || ext==
"iges")
212 return readIgesFile(m_lastPath);
216 return readX3dFile(m_lastPath);
218 return readCsvFile(m_lastPath);
221 gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Unknown extension \"."<<ext<<
"\".\n";
232 std::ifstream file(fn.c_str(), std::ios::in);
234 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
236 return readGismoXmlStream(file, recursive);
243 igzstream file(fn.c_str(), std::ios::in);
245 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
247 return readGismoXmlStream(file, recursive);
254 m_buffer.emplace_back();
255 std::vector<char> & buffer = m_buffer.back();
256 buffer.assign( std::istreambuf_iterator<char>(is.rdbuf() ),
257 std::istreambuf_iterator<char>() );
258 buffer.push_back(
'\0');
260 data->parse<0>(&buffer[0],
true);
262 gsXmlNode * ln = data->last_node(
"xml");
265 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
266 <<
": Invalid XML file, no root tag <xml> found.\n";
272 std::list<std::string> ifn;
273 for (gsXmlNode * child = ln->first_node(
"xmlfile") ;
274 child; child = child->next_sibling(
"xmlfile") )
276 ifn.push_back( child->value() );
283 readXmlFile(cfn + f);
287 gsXmlNode * root = data->getRoot();
288 root->merge_sibling(ln);
289 data->remove_node(ln);
297 const index_t &
id,
const std::string & label)
299 GISMO_ASSERT( filename!=
"",
"No filename provided for include!");
303 data->appendToRoot(node,
id, label);
311 GISMO_ENSURE(( (
id!=-1) ^ (time!=-1.) ^ (label!=
"") ) &&
312 !(
id!=-1 && time!=-1. && label!=
""),
313 "gsFileData::getInclude("<<
id<<
","<<time<<
","<<label<<
"), too many arguments provided!");
314 std::string attr_name, attr_string;
325 attr_string = cast<real_t,double>( time );
333 gsXmlNode * root = getXmlRoot();
343 GISMO_ERROR(
"Include with " << attr_name <<
"=" << attr_string <<
" does not exist!");
352 std::ifstream file(fn.c_str(), std::ios::in);
354 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
356 std::vector<char> buffer(
357 std::istreambuf_iterator<char>(file.rdbuf() ),
358 std::istreambuf_iterator<char>() );
359 buffer.push_back(
'\0');
363 axldata.parse<0>(&buffer[0]);
366 gsXmlNode * node = axldata.first_node(
"axl");
370 for (gsXmlNode * child = node->first_node(); child; child = child->next_sibling())
374 { readAxelCurve(child); }
375 if ( s ==
"surface" )
376 { readAxelSurface(child); }
378 { readAxelMesh(child); }
389 std::stringstream str;
395 data->appendToRoot(g);
396 gsXmlNode * parent= g;
398 gsXmlNode* tmp = node->first_node(
"dimension");
399 String geoDim = tmp->value();
403 parent->append_node(b);
406 tmp= node->first_node(
"order");
407 str.str( tmp->value() );
410 tmp = node->first_node(
"knots");
416 tmp = node->first_node(
"points");
419 parent->append_node(g);
425 bool gsFileData<T>::readAxelSurface(gsXmlNode * node )
427 std::stringstream str;
431 data->appendToRoot(g);
432 gsXmlNode * parent = g;
437 gsXmlNode * tmp = node->first_node(
"order");
439 str.str( tmp->value() );
447 parent->append_node(tb);
453 tmp = node->first_node(
"knots");
462 tmp = tmp->next_sibling(
"knots");
468 tmp = node->first_node(
"points");
471 parent->append_node(g);
477 bool gsFileData<T>::readAxelMesh(gsXmlNode * node )
479 std::ostringstream str;
480 gsXmlNode * tmp = node->first_node(
"points");
483 tmp = node->first_node(
"faces");
489 tmp = node->first_node(
"count");
491 std::istringstream iss(tmp->value());
497 internal::gsXmlNode* parent = data->first_node(
"xml") ;
498 parent->append_node(g);
500 tmp = node->first_node(
"edges");
502 gsWarn <<
"Skipping edges in axl file.\n";
514 std::ifstream file(fn.c_str(),std::ios::in);
516 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
518 std::istringstream lnstream;
519 lnstream.unsetf(std::ios_base::skipws);
530 int ncp, deg, c, parDim(0), geoDim;
543 while (!file.eof() && getline(file, line))
545 while (!file.eof() && line ==
"") getline(file, line);
550 if ( !(lnstream >> std::ws >> ncp ) )
continue;
551 if ( !(lnstream >> std::ws >> c ) || c > 1 )
continue;
552 if ( !(lnstream >> std::ws >> c ) || c >9 )
continue;
553 if ( !(lnstream >> std::ws >> c ) || c >9 )
continue;
567 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
568 <<
": Reading GoTools trimmed surface (ClassType="<<ncp<<
") not implemented.\n";
571 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
572 <<
": Reading GoTools CurveOnSurface (ClassType="<<ncp<<
") not implemented.\n";
576 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
577 <<
": Reading GoTools Line (ClassType="<<ncp<<
") not implemented.\n";
581 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
582 <<
": Reading GoTools Circle (ClassType="<<ncp<<
") not implemented.\n";
586 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
587 <<
": Reading GoTools Ellipse (ClassType="<<ncp<<
") not implemented.\n";
591 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
592 <<
": Reading GoTools BoundedCurve (ClassType="<<ncp<<
") not implemented.\n";
596 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
597 <<
": Reading GoTools Hyperbola (ClassType="<<ncp<<
") not implemented.\n";
601 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
602 <<
": Reading GoTools Parabola (ClassType="<<ncp<<
") not implemented.\n";
606 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
607 <<
": Reading GoTools SurfaceOnVolume (ClassType="<<ncp<<
") not implemented.\n";
611 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
612 <<
": Reading GoTools GoBaryPolSurface (ClassType="<<ncp<<
") not implemented.\n";
616 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
617 <<
": Reading GoTools GoHBSplineParamSurface (ClassType="<<ncp<<
") not implemented.\n";
621 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
622 <<
": Reading GoTools CompositeSurface (ClassType="<<ncp<<
") not implemented.\n";
626 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
627 <<
": Reading GoTools Plane (ClassType="<<ncp<<
") not implemented.\n";
631 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
632 <<
": Reading GoTools Cylinder (ClassType="<<ncp<<
") not implemented.\n";
636 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
637 <<
": Reading GoTools Sphere (ClassType="<<ncp<<
") not implemented.\n";
641 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
642 <<
": Reading GoTools Sphere (ClassType="<<ncp<<
") not implemented.\n";
646 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
647 <<
": Reading GoTools Torus (ClassType="<<ncp<<
") not implemented.\n";
651 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
652 <<
": Reading GoTools SurfaceOfRevolution (ClassType="<<ncp<<
") not implemented.\n";
656 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
657 <<
": Reading GoTools Disc (ClassType="<<ncp<<
") not implemented.\n";
661 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
662 <<
": Reading GoTools LRSplineSurface (ClassType="<<ncp<<
") not implemented.\n";
666 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
667 <<
": Reading GoTools TSplineSurface (ClassType="<<ncp<<
") not implemented.\n";
671 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
672 <<
": Reading GoTools Go3dsObject (ClassType="<<ncp<<
") not implemented.\n";
676 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
677 <<
": Reading GoTools GoHeTriang (ClassType="<<ncp<<
") not implemented.\n";
681 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
682 <<
": Reading GoTools GoSdTriang (ClassType="<<ncp<<
") not implemented.\n";
686 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
687 <<
": Reading GoTools GoQuadMesh (ClassType="<<ncp<<
") not implemented.\n";
691 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
692 <<
": Reading GoTools GoHybridMesh (ClassType="<<ncp<<
") not implemented.\n";
696 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
697 <<
": Reading GoTools GoHybridMesh (ClassType="<<ncp<<
") not implemented.\n";
701 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
702 <<
": Reading GoTools GoVrmlGeometry (ClassType="<<ncp<<
") not implemented.\n";
706 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
707 <<
": Reading GoTools PointCloud (ClassType="<<ncp<<
") not implemented.\n";
711 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
712 <<
": Reading GoTools LineCloud (ClassType="<<ncp<<
") not implemented.\n";
716 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
717 <<
": Reading GoTools GoTriangleSets (ClassType="<<ncp<<
") not implemented.\n";
721 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
722 <<
": Reading GoTools RectGrid (ClassType="<<ncp<<
") not implemented.\n";
726 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
727 <<
": Reading GoTools BoundedVolume (ClassType="<<ncp<<
") not implemented.\n";
731 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
732 <<
": Reading GoTools Parallelepiped (ClassType="<<ncp<<
") not implemented.\n";
736 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
737 <<
": Reading GoTools SphereVolume (ClassType="<<ncp<<
") not implemented.\n";
741 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
742 <<
": Reading GoTools CylinderVolume (ClassType="<<ncp<<
") not implemented.\n";
746 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
747 <<
": Reading GoTools ConeVolume (ClassType="<<ncp<<
") not implemented.\n";
751 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
752 <<
": Reading GoTools TorusVolume (ClassType="<<ncp<<
") not implemented.\n";
756 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
757 <<
": Reading GoTools LRSplineVolume (ClassType="<<ncp<<
") not implemented.\n";
761 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
762 <<
": Unknown GoTools entity (ClassType="<<ncp<<
").\n";
769 while (!file.eof() && line ==
"") getline(file, line);
772 lnstream >> std::ws >> geoDim >> std::ws >> rational >> std::ws ;
778 (rational ?
"Nurbs" :
"BSpline"), *data) );
786 data->appendToRoot(g);
794 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
795 <<
": RATIONAL GoTools input is not supported/tested/working.\n";
800 rtb->append_node(src);
809 for (
int i=0; i<parDim; ++i)
813 while (!file.eof() && line ==
"") getline(file, line);
817 lnstream >> std::ws >> c >> std::ws >> deg >> std::ws ;
823 while (!file.eof() && line ==
"") getline(file, line);
847 std::ostringstream coefstream;
849 for (
int i = 0; i < ncp; i++)
851 if ( getline(file, line) )
853 while (!file.eof() && line ==
"") getline(file, line);
854 coefstream << line.substr(0,line.size()) << std::endl;
858 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
859 <<
": Failed to read coefficients.\n";
885 std::ifstream file(fn.c_str(),std::ios::in);
887 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
889 std::istringstream lnstream;
890 lnstream.unsetf(std::ios_base::skipws);
892 std::stringstream str;
897 int N,Np,Ni(0),Ns(0);
898 std::vector<gsKnotVector<T> *> knots;
902 while (!file.eof() && getline(file, line))
904 if (line[0] !=
'#')
break;
908 gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Reached end of file.\n";
918 lnstream >> std::ws >> N >> std::ws >> Np >> std::ws ;
920 lnstream >> std::ws >> Ni >> std::ws >> Ns >> std::ws ;
933 while ( !file.eof() )
935 while (!file.eof() && getline(file, line))
936 if ( line[0] !=
'#' )
break;
943 std::transform(line.begin(),line.end(),line.begin(),::tolower);
986 else if ( ( line.find(
"patch")!=String::npos ) || patch==
true )
992 if ( ! isdigit(line[0]) )
993 while (!file.eof() && getline(file, line))
994 if (line[0] !=
'#')
break;
997 for (
int i=0;i<N;++i)
998 lnstream >> std::ws >> p[i] ;
1002 while (!file.eof() && getline(file, line))
1003 if (line[0] !=
'#')
break;
1006 for (
int i=0;i<N;++i)
1007 lnstream >> std::ws >> ncp[i] ;
1008 unsigned sz= ncp.prod() ;
1013 data->appendToRoot(g);
1018 g->append_node(rtb);
1022 rtb->append_node(src);
1027 while (!file.eof() && getline(file, line))
1028 if (line[0] !=
'#')
break;
1033 src->append_node(k);
1039 for (
int i=0;i<N;++i)
1041 while (!file.eof() && getline(file, line))
1042 if (line[0] !=
'#')
break;
1048 src->append_node(b);
1060 for (
int i=0;i<N;++i)
1062 while (!file.eof() && getline(file, line))
1063 if (line[0] !=
'#')
break;
1066 for (
unsigned k=0;k< sz;++k)
1068 lnstream >> std::ws >> tmp ;
1077 while (!file.eof() && getline(file, line))
1078 if (line[0] !=
'#')
break;
1081 for (
unsigned k=0;k< sz;++k)
1083 lnstream >> std::ws >> tmp ;
1084 weights(k,0) = tmp ;
1085 coefs.row(k) /= tmp;
1093 rtb->append_node(c);
1278 std::ifstream file(fn.c_str(),std::ios::in);
1280 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
1284 data->appendToRoot(g);
1287 std::istringstream lnstream;
1288 lnstream.unsetf(std::ios_base::skipws);
1289 std::ostringstream tmp;
1291 getline(file, line);
1292 if ( line.compare(0,3,
"OFF") != 0)
1295 getline(file, line);
1296 int nverts, nfaces, nedges(0);
1298 lnstream >> std::ws >> nverts >>
1299 std::ws >> nfaces >>
1306 for (
int i = 0; i < nverts; i++)
1307 if ( getline(file, line) )
1308 tmp << line.substr(0,line.size()) << std::endl;
1312 for (
int i = 0; i < nfaces; i++)
1313 if ( getline(file, line) )
1314 tmp << line.substr(0,line.size()) << std::endl;
1329 bool solid(
false),facet(
false),loop(
false);
1331 std::ifstream file(fn.c_str(),std::ios::in);
1333 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
1337 data->appendToRoot(g);
1339 std::ostringstream triangles;
1340 triangles.unsetf(std::ios_base::skipws);
1341 std::ostringstream vertices;
1342 vertices.unsetf(std::ios_base::skipws);
1343 unsigned nvert(0), nfaces(0), tmp(0);
1345 unsigned lineNumber(0);
1348 while( !file.eof() && getline(file, str) )
1350 std::transform(str.begin(),str.end(),str.begin(),::tolower);
1351 if(str.find(
"solid")!=String::npos && str.find(
"endsolid")==String::npos)
1353 if(solid) ioError(lineNumber,
"startSolid");
1356 else if(str.find(
"endsolid")!=String::npos)
1358 if(!solid || facet || loop) ioError(lineNumber,
"endSolid");
1361 else if(str.find(
"facet")!=String::npos && str.find(
"endfacet")==String::npos)
1363 if(!solid || facet || loop) ioError(lineNumber,
"startFacet");
1366 else if(str.find(
"endfacet")!=String::npos)
1368 if(!solid || !facet || loop) ioError(lineNumber,
"endFacet");
1371 else if(str.find(
"outer")!=String::npos)
1373 if(!solid || !facet || loop) ioError(lineNumber,
"startLoop");
1376 else if(str.find(
"endloop")!=String::npos)
1378 if(!solid || !facet || !loop )
1379 ioError(lineNumber,
"endLoop");
1381 for (
unsigned i= nvert-tmp; i!=nvert; ++i)
1388 else if(str.find(
"vertex")!=String::npos)
1390 if(!solid || !facet || !loop )
1391 ioError(lineNumber,
"vertex");
1394 size_t pos=str.rfind(
"vertex")+7;
1395 assert(pos!=String::npos);
1396 vertices << str.substr(pos, str.size()-pos) <<
"\n";
1402 vertices << triangles.str() ;
1416 std::ifstream file(fn.c_str(),std::ios::in);
1418 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Cannot open file stream.\n";
return false; }
1449 std::istringstream lnstream;
1450 lnstream.unsetf(std::ios_base::skipws);
1452 String token(
" "), bdr, ifc;
1455 while (!file.eof() && getline(file, line))
1459 lnstream >> std::ws;
1462 else if (lnstream.peek() ==
'#')
1472 while (lnstream && !lnstream.eof())
1474 lnstream >> std::ws >> x >> std::ws ;
1477 points.push_back(v);
1480 else if (token ==
"vp")
1484 while (lnstream && !lnstream.eof())
1486 lnstream >> std::ws >> x >> std::ws ;
1489 points2d.push_back(v);
1491 else if (token ==
"cstype")
1493 lnstream >>std::ws >> cstype >> std::ws;
1495 while (lnstream && !lnstream.eof())
1497 lnstream >> std::ws >> t >> std::ws ;
1502 else if (token ==
"deg")
1504 lnstream >> std::ws >> du >> std::ws >> dv>> std::ws;
1505 gsDebug<<
"du, dv: "<<du<<
", "<<dv <<std::endl;
1507 else if (token ==
"curv")
1511 gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Ignore curv.\n";
1515 else if (token ==
"curv2")
1522 while (lnstream && !lnstream.eof())
1524 lnstream >> std::ws >> cp ;
1526 c2->control_points.push_back(cp-1);
1532 else if (token ==
"surf")
1537 lnstream >> std::ws >> start_u >> std::ws >> end_u;
1538 lnstream >> std::ws >> start_v >> std::ws >> end_v;
1539 while (lnstream && !lnstream.eof())
1541 lnstream >> std::ws >> cp ;
1543 control_points.push_back(cp-1);
1546 else if (token ==
"parm")
1550 lnstream >> std::ws >> c >> std::ws;
1552 while (lnstream && !lnstream.eof())
1554 lnstream >> std::ws >> val >> std::ws;
1556 if (type ==
"curv2")
1557 c2->knots.push_back(val);
1559 knots[var[c]].push_back(val);
1563 else if (token ==
"trim")
1569 while (lnstream && !lnstream.eof())
1571 lnstream >> std::ws >> u >> std::ws >> v >> std::ws >> cv >> std::ws;
1575 gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Ignore trim loop.\n";
1577 else if (token ==
"end")
1579 gsDebug<<
"End reading "<< cstype <<
" "<<type<<std::endl;
1581 if (cstype==
"bspline" && type==
"surf")
1583 curves.push_back(c2);
1588 axl<<
"<surface type=\"trimmed\" number =\"1\">\n";
1591 if (cstype==
"bspline" && type==
"surf")
1593 axl<<
"<surface type=\"bspline\" name=\"bs_"<<surf_count<<
"\">\n";
1594 axl<<
"<dimension>3</dimension>\n";
1595 axl<<
"<number>"<<knots[0].size()-du-1 <<
" "<<knots[1].size()-dv-1<<
"</number>\n";
1596 axl<<
"<order>"<<du+1<<
" "<<dv+1<<
"</order>\n";
1598 for (
int i=0; i<knots[0].size(); i++ )
1599 axl<< knots[0][i]<<
" ";
1602 for (
int i=0; i<knots[1].size(); i++ )
1603 axl<< knots[1][i]<<
" ";
1606 for (
int i=0; i<control_points.size(); i++ )
1608 for (
int j=0; j<points[control_points[i]].size(); j++ )
1609 axl<< points[control_points[i]][j] <<
" ";
1613 axl<<
"</surface>\n";
1614 gsDebug<<
"Got "<< cstype <<
" "<<type<<
" "<<surf_count<<std::endl;
1616 else if (cstype==
"rat_bspline" && type==
"surf")
1618 axl<<
"<surface type=\"bspline\" rational=\"1\" name=\"bs_"<<surf_count<<
"\">\n";
1619 axl<<
"<dimension>3</dimension>\n";
1620 axl<<
"<number>"<<knots[0].size()-du-1 <<
" "<<knots[1].size()-dv-1<<
"</number>\n";
1621 axl<<
"<order>"<<du+1<<
" "<<dv+1<<
"</order>\n";
1623 for (
int i=0; i<knots[0].size(); i++ )
1624 axl<< knots[0][i]<<
" ";
1627 for (
int i=0; i<knots[1].size(); i++ )
1628 axl<< knots[1][i]<<
" ";
1631 for (
int i=0; i<control_points.size(); i++ )
1634 for (
int j=0; j<points[control_points[i]].size()-1; j++ )
1637 axl<< points[control_points[i]][j] <<
" ";
1646 for (
int i=0; i<trims.size(); i++ )
1648 axl<<
"<curveloop>\n";
1649 for (
int j=0; j<trims[i].size(); j++ )
1653 axl<<
"</curveloop>\n";
1657 axl<<
"</surface>\n";
1659 gsDebug<<
"Got "<< cstype <<
" "<<type<<
" "<<surf_count<<std::endl;
1661 else if (cstype==
"bspline" && type==
"curv2")
1665 else if (cstype!=
"")
1667 gsWarn<<
"gsFileData: Problem with file "<<fn<<
": Ignoring "<< cstype<<
" "<<type <<std::endl;
1672 knots.push_back(Vertex());
1673 knots.push_back(Vertex());
1674 control_points.clear();
1681 std::string message =
"ignoring line ‘" + line +
"’";
1696 #ifdef gsOpenCascade_ENABLED
1697 return extensions::gsReadBrep( fn.c_str(), *data);
1707 #define MAXENTITY 1000
1717 int read_iges_line(FILE *f,
char *s)
1722 for (i=0; i < 80; i++)
1725 if (c == EOF)
return -1;
1731 case '\x0D': i--;
break;
1732 case '\x0A': i--;
break;
1739 void copy_field(
char *s1,
int poz,
int x,
char *s2)
1751 void format_number(
char *n_s)
1754 int n_len = strlen(n_s);
1756 for (
int i=0; i < n_len; i++)
1758 if(n_s[i] ==
'E' || n_s[i] ==
'e' || n_s[i] ==
'D' || n_s[i] ==
'd')
1766 if(n_s[n_len - 1] ==
'0')
1768 for (
int i=n_len-1; i >= 0; i--)
1780 default :
goto endfor_fn;
1789 void parse_d_entry(
int entity[MAXENTITY][4],
int & emark,
int & entity_sum,
char *ret1,
char *ret2)
1793 int kod, pd_ptr, pd_count, layer, form;
1799 copy_field(ret1,0,8,fld); kod= atoi(fld);
1800 copy_field(ret2,32,8,fld); form= atoi(fld);
1801 copy_field(ret1,8,8,fld); pd_ptr= atoi(fld);
1802 copy_field(ret2,24,8,fld); pd_count=atoi(fld);
1803 copy_field(ret1,32,8,fld); layer= atoi(fld);
1840 entity[emark][E_TYPE]=kod;
1841 entity[emark][PD_PTR]=pd_ptr;
1842 entity[emark][PD_CNT]=pd_count;
1843 entity[emark][ELAYER]=layer;
1849 entity[emark][E_TYPE]=kod;
1850 entity[emark][PD_PTR]=pd_ptr;
1851 entity[emark][PD_CNT]=pd_count;
1852 entity[emark][ELAYER]=layer;
1859 void read_iges_pd128(
char *s,
int begin, std::stringstream & ss)
1862 static char t[FIELD_L+1];
1865 static int c, endknot;
1866 static int q[5],b[4];
1878 for (i=0; i <= 64; i++)
1917 if (0!=j) q[j-5]= atoi(t);
1918 if (7==j) ss<<q[0]<<
",";
1929 endknot = b[0]+b[2]+2+b[1]+b[3]+2;
1935 if (s[i] ==
' ')
return;
1936 else if (s[i] ==
',' || s[i] ==
';')
1943 if (c == 3*(b[0]+1)*(b[1]+1))
1956 if (s[i] ==
' ')
return;
1957 else if (s[i] ==
',')
1964 if (c == b[0]+b[2]+2) ss<<
","<<b[2]<<
",";
1980 if (s[i] ==
' ')
return;
1981 else if (s[i] ==
',')
1995 if (c == (b[0]+1)*(b[1]+1))
2006 void read_iges_pd126(
char *s,
int begin, std::stringstream & ss)
2009 static char t[FIELD_L+1];
2012 static int c, endknot;
2023 for (i=0; i <= 64; i++)
2066 endknot = b[0]+b[1]+2;
2072 if (s[i] ==
' ')
return;
2073 else if (s[i] ==
',' || s[i] ==
';')
2080 if (c == 3*(b[0]+1))
2093 if (s[i] ==
' ')
return;
2094 else if (s[i] ==
',')
2116 if (s[i] ==
' ')
return;
2117 else if (s[i] ==
',')
2152 FILE * fr = fopen(fn.c_str(),
"rb");
2154 int entity[MAXENTITY][4];
2160 gsWarn<<
"gsFileData: Problem with input "<<fn<<
": Cannot open file.\n";
2166 char pd_seq_s[8]; pd_seq_s[7]=
'\0';
2170 if (read_iges_line(fr, line) == -1)
2171 {
gsWarn<<
"IGES file empty.\n";
return false; }
2172 if (line[72] ==
'F')
2173 {
gsWarn<<
"IGES file is not ASCII file (binary mode is not supported).\n";
return false; }
2180 while (line[72] !=
'D')
2182 err_code=read_iges_line(fr, line);
2183 if (err_code == -1) {
gsWarn<<
"IGES file empty.\n";
return false; }
2185 err_code=read_iges_line(fr, pairline);
2186 if (err_code == -1) {
gsWarn<<
"IGES file empty.\n";
return false; }
2187 parse_d_entry(entity,emark,entity_sum,line, pairline);
2190 while (line[72] ==
'D')
2192 err_code=read_iges_line(fr, line);
2193 if (err_code == -1) {
gsWarn<<
"IGES file empty.\n";
return false; }
2194 if (line[72] ==
'D')
2196 err_code=read_iges_line(fr, pairline);
2197 if (err_code == -1) {
gsWarn<<
"IGES file empty.\n";
return false; }
2198 parse_d_entry(entity,emark,entity_sum,line, pairline);
2199 if (entity_sum >= MAXENTITY) {
gsWarn<<
"Too many entities (more than "<<MAXENTITY<<
" in the file.\n";
return false; }
2206 copy_field(line,73,7,pd_seq_s);
2207 pd_seq = atoi(pd_seq_s);
2208 for (emark=0; emark < entity_sum; emark++)
2210 while (pd_seq != entity[emark][PD_PTR])
2212 read_iges_line(fr, line);
2213 copy_field(line,73,7,pd_seq_s);
2214 pd_seq=atoi(pd_seq_s);
2217 std::stringstream ss;
2220 switch (entity[emark][E_TYPE])
2252 for (
int i=1; i <= entity[emark][PD_CNT]; i++)
2254 read_iges_pd126(line, i, ss);
2255 read_iges_line(fr, line);
2256 copy_field(line,73,7,pd_seq_s);
2257 pd_seq=atoi(pd_seq_s);
2261 for (
int i=1; i <= entity[emark][PD_CNT]; i++)
2263 read_iges_pd128(line, i, ss);
2264 read_iges_line(fr, line);
2265 copy_field(line,73,7,pd_seq_s);
2266 pd_seq=atoi(pd_seq_s);
2272 std::getline(ss, token,
',');
2273 bool rat = (token!=
"0");
2276 (rat?
"TensorNurbs2":
"TensorBSpline2"), *data) );
2277 data->appendToRoot(g);
2278 gsXmlNode* rtb(
nullptr), * src;
2284 g->append_node(rtb);
2285 rtb->append_node(src);
2288 g->append_node(src);
2293 src->append_node(b);
2294 std::getline(ss, token,
',');
2296 std::getline(ss, token,
',');
2302 src->append_node(b);
2303 std::getline(ss, token,
',');
2305 std::getline(ss, token,
',');
2308 std::getline(ss, token,
',');
2312 rtb->append_node(k);
2314 std::getline(ss, token,
',');
2322 const bool fc = ( 0==fclose(fr) );
2323 if (fc)
gsWarn<<
"File closing didn't succeeded!\n";
2343 std::istringstream str;
2345 for (gsXmlNode * node = shape->first_node(
"NurbsPatchSurface");
2346 node; node = node->next_sibling(
"NurbsPatchSurface") )
2351 "TensorBSplineBasis2", *data) );
2357 p = atoi(node->first_attribute(
"uOrder")->value()) -1 ;
2358 gsXmlAttribute * kv_attr = node->first_attribute(
"uKnot");
2361 ch = node->first_attribute(
"uKnot")->value() ;
2365 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
2366 <<
": Setting knots to [0..1] by default not implemented";
2373 bs_node->append_node(kv_node);
2374 tp_node->append_node(bs_node);
2376 p = atoi(node->first_attribute(
"vOrder")->value()) -1 ;
2377 kv_attr = node->first_attribute(
"vKnot");
2379 ch = kv_attr->value() ;
2383 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
2384 <<
": Setting knots to [0..1] by default not implemented";
2391 bs_node->append_node(kv_node);
2392 tp_node->append_node(bs_node);
2395 gsXmlAttribute * rat_weights = node->first_attribute(
"weight");
2399 ch = rat_weights->value();
2401 "TensorNurbs2", *data));
2405 "TensorNurbsBasis2", *data) );
2406 nurbs_node->append_node(tp_node);
2408 nurbs_node->append_node(weights_node);
2409 patch->append_node(nurbs_node);
2415 "TensorBSpline2", *data));
2416 patch->append_node( tp_node);
2420 ch = node->first_node(
"Coordinate")->first_attribute(
"point")->value();
2423 patch->append_node( cp_node);
2426 data->appendToRoot(patch);
2431 void gsFileData<T>::addX3dTransform(gsXmlNode * trans)
2434 gsXmlAttribute * attr = trans->first_attribute(
"translation");
2436 gsDebug<<
"Translate "<< attr->value() <<
"\n";
2439 attr = trans->first_attribute(
"rotation");
2441 gsDebug<<
"Rotate "<< attr->value() <<
"\n";
2444 attr = trans->first_attribute(
"scale");
2446 gsDebug<<
"Scale "<< attr->value() <<
"\n";
2464 std::ifstream file(fn.c_str(), std::ios::in);
2466 {
gsWarn<<
"gsFileData: Problem with file "<<fn<<
": cannot open file stream.\n";
return false;}
2468 std::vector<char> buffer(
2469 std::istreambuf_iterator<char>(file.rdbuf() ),
2470 std::istreambuf_iterator<char>() );
2471 buffer.push_back(
'\0');
2475 x3ddata.parse<0>(&buffer[0]);
2478 gsXmlNode * x3d = x3ddata.first_node(
"X3D");
2481 for (gsXmlNode * scene = x3d->first_node(
"Scene");
2482 scene; scene = scene->next_sibling(
"Scene") )
2484 for (gsXmlNode * shape = scene->first_node(
"Shape");
2485 shape; shape = shape->next_sibling(
"Shape") )
2486 addX3dShape( shape );
2488 for (gsXmlNode * trans = scene->first_node(
"Transform");
2489 trans; trans = trans->next_sibling(
"Transform") )
2492 gsXmlNode * trans_rec = trans;
2495 addX3dTransform( trans_rec );
2496 gsXmlNode * tmp = trans_rec->first_node(
"Transform");
2503 for (gsXmlNode * shape = trans_rec->first_node(
"Shape");
2504 shape; shape = shape->next_sibling(
"Shape") )
2506 addX3dShape( shape );
2509 for (gsXmlNode * coll = trans->first_node(
"Collision");
2510 coll; coll = trans->next_sibling(
"Collision") )
2512 gsDebug<<
"Reach collision tag.\n";
2513 for (gsXmlNode * shape = coll->first_node(
"Shape");
2514 shape; shape = shape->next_sibling(
"Shape") )
2516 gsDebug<<
"Reach shape in tag.\n";
2517 addX3dShape( shape );
2529 #ifdef gsOpennurbs_ENABLED
2530 return extensions::gsReadOpenNurbs( fn.c_str(), *data);
2544 #ifdef GISMO_WITH_PSOLID
2545 return extensions::gsReadParasolid( fn.c_str(), *data);
2555 std::ifstream indata;
2556 indata.open(fn.c_str());
2557 std::string cell, line, mstr;
2559 std::istringstream lnstream;
2560 lnstream.unsetf(std::ios_base::skipws);
2561 while (std::getline(indata, line))
2565 while (std::getline(lnstream, cell,
','))
2577 data->appendToRoot(nd);
2585 std::ostringstream os;
2588 for (gsXmlNode * child = data->first_node(
"xml")->first_node();
2589 child; child = child->next_sibling() )
2591 os << i++ <<
". " << child->name() ;
2592 for (gsXmlAttribute * attr = child->first_attribute();
2593 attr; attr = attr->next_attribute() )
2594 os <<
", "<< attr->name() <<
"="<< attr->value();
2601 template<
class T>
inline
2605 for (gsXmlNode * child = data->first_node(
"xml")->first_node() ;
2606 child; child = child->next_sibling() )
2611 template<
class T>
inline
2612 typename gsFileData<T>::gsXmlNode *
2615 return data->getRoot();
2618 template<
class T>
inline
2619 void gsFileData<T>::deleteXmlSubtree(gsXmlNode * node)
2621 node->parent()->remove_node(node);
2626 template<
class T>
inline
2627 typename gsFileData<T>::gsXmlNode *
2628 gsFileData<T>::getFirstNode(
const std::string & name,
const std::string & type)
const
2630 gsXmlNode * root = data->first_node(
"xml");
2633 gsWarn<<
"gsFileData: Problem with file "<<m_lastPath
2634 <<
": Invalid XML file, no root tag <xml> found.\n";
2639 return root->first_node( name.c_str() );
2642 for (gsXmlNode * child = root->first_node( name.c_str() ) ;
2643 child; child = child->next_sibling( name.c_str() ) )
2644 if ( !strcmp( child->first_attribute(
"type")->value(), type.c_str() ) )
2650 template<
class T>
inline
2651 typename gsFileData<T>::gsXmlNode *
2652 gsFileData<T>::getAnyFirstNode(
const std::string & name,
const std::string & type)
const
2654 gsXmlNode * root = data->first_node(
"xml");
2658 for (gsXmlNode * child = root->first_node() ;
2659 child; child = child->next_sibling() )
2661 if (!strcmp( child->name(), name.c_str() ) )
2664 for (gsXmlNode * child2 = child->first_node() ;
2665 child2; child2 = child2->next_sibling() )
2667 if ( !strcmp( child2->name(), name.c_str() ) )
2670 for (gsXmlNode * child3 = child2->first_node() ;
2671 child3; child3 = child3->next_sibling() )
2672 if ( !strcmp( child3->name(), name.c_str() ) )
2678 for (gsXmlNode * child = root->first_node() ;
2679 child; child = child->next_sibling() )
2681 if (!strcmp( child->name(), name.c_str() ) &&
2682 !strcmp( child->first_attribute(
"type")->value(), type.c_str() ) )
2685 for (gsXmlNode * child2 = child->first_node() ;
2686 child2; child2 = child2->next_sibling() )
2688 if ( !strcmp( child2->name(), name.c_str() ) &&
2689 !strcmp( child2->first_attribute(
"type")->value(), type.c_str() ))
2692 for (gsXmlNode * child3 = child2->first_node() ;
2693 child3; child3 = child3->next_sibling() )
2694 if ( !strcmp( child3->name(), name.c_str() ) &&
2695 !strcmp( child3->first_attribute(
"type")->value(), type.c_str()))
2702 template<
class T>
inline
2703 typename gsFileData<T>::gsXmlNode *
2704 gsFileData<T>::getNextSibling(gsXmlNode*
const & node,
const std::string & name,
2705 const std::string & type)
2708 return node->next_sibling( name.c_str() );
2711 for (gsXmlNode * next = node->next_sibling( name.c_str() );
2712 next; next = next->next_sibling( name.c_str() ) )
2713 if ( !strcmp( next->first_attribute(
"type")->value(), type.c_str() ) )
Knot vector for B-splines.
bool readStlFile(String const &fn)
Reads STL mesh file.
Definition: gsFileData.hpp:1327
static std::string find(std::string fn)
Find a file.
Definition: gsFileManager.cpp:283
#define gsDebug
Definition: gsDebug.h:61
bool readParasolidFile(String const &fn)
Reads parasolid files.
Definition: gsFileData.hpp:2539
void saveCompressed(String const &fname="dump") const
Save file contents to compressed xml file.
Definition: gsFileData.hpp:131
static std::string getExtension(std::string const &fn)
Returns the extension of the filename fn.
Definition: gsFileManager.cpp:568
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
Provides declaration of gsReadParasolid functions.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
int numTags() const
Counts the number of Objects/tags in the filedata.
Definition: gsFileData.hpp:2602
bool readXmlGzFile(String const &fn, bool recursive=false)
Reads a file with xml.gz extension.
Definition: gsFileData.hpp:240
gsXmlNode * searchNode(gsXmlNode *root, const std::string &attr_name, const std::string &value, const char *tag_name=NULL)
Definition: gsXml.h:231
bool readOffFile(String const &fn)
Reads Off mesh file.
Definition: gsFileData.hpp:1259
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition: gsXml.cpp:74
bool readGismoXmlStream(std::istream &is, bool recursive=false)
Reads Gismo's native XML file.
Definition: gsFileData.hpp:252
#define gsWarn
Definition: gsDebug.h:50
gsXmlNode * makeComment(const std::string &comment, gsXmlTree &data)
Helper to create an XML comment node.
Definition: gsXml.cpp:68
EIGEN_STRONG_INLINE onormal_expr< T > nv(const gsGeometryMap< T > &u)
The (outer pointing) boundary normal of a geometry map.
Definition: gsExpressions.h:4508
String contents() const
Lists the contents of the filedata.
Definition: gsFileData.hpp:2583
bool readObjFile(String const &fn)
Reads Wavefront OBJ file.
Definition: gsFileData.hpp:1410
bool read(String const &fn, bool recursive=false)
Definition: gsFileData.hpp:162
void addInclude(const std::string &filename, const real_t &time=-1., const index_t &id=-1, const std::string &label="")
Add a reference ( <xmlfile> tag ) to another Gismo .xml file to the xml tree.
Definition: gsFileData.hpp:296
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
bool readIgesFile(String const &fn)
Reads Iges file.
Definition: gsFileData.hpp:2149
#define GISMO_VERSION
Definition: gsConfig.h:20
Declaration of function for data input from the Rhinoceros 3DM file format.
bool readAxelFile(String const &fn)
Reads Axel file.
Definition: gsFileData.hpp:349
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54
void dump(String const &fname="dump") const
Dump file contents to an xml file.
Definition: gsFileData.hpp:86
static std::string getPath(std::string const &fn, bool resolve=false)
Definition: gsFileManager.cpp:608
char * makeValue(const std::string &value, gsXmlTree &data)
Helper to allocate XML value.
Definition: gsXml.cpp:32
bool readGeompFile(String const &fn)
Reads GeoPDEs txt file.
Definition: gsFileData.hpp:882
void clear()
Clear all data.
Definition: gsFileData.hpp:69
bool read3dmFile(String const &fn)
Reads 3DM file.
Definition: gsFileData.hpp:2527
bool readX3dFile(String const &fn)
Reads X3D file.
Definition: gsFileData.hpp:2460
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
Utility class for finding files and handling paths.
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
Reading OpenCascade .brep and others via OCCT.
bool readGoToolsFile(String const &fn)
Reads GoTools file.
Definition: gsFileData.hpp:511
This class represents an XML data tree which can be read from or written to a (file) stream...
Definition: gsFileData.h:33
bool ends_with(const std::string &haystack, const std::string &needle)
Checks if a string haystack ends with the string needle.
Definition: gsUtils.h:79
void save(String const &fname="dump", bool compress=false) const
Save file contents to an xml file.
Definition: gsFileData.hpp:98
bool readBrepFile(String const &fn)
Reads OpenCascade brep file.
Definition: gsFileData.hpp:1694
bool readXmlFile(String const &fn, bool recursive=false)
Reads a file with xml extension.
Definition: gsFileData.hpp:229
std::ostream & print(std::ostream &os) const
Prints the XML data as a string.
Definition: gsFileData.hpp:77
static std::string getSearchPaths()
Get the defined search paths.
Definition: gsFileManager.cpp:271