43#include <gsPde/gsSurfacePoissonPde.h>
58class gsXml< gsSolid<T> >
63 GSXML_COMMON_FUNCTIONS(gsSolid<T>);
64 static std::string tag () {
return "Solid"; }
65 static std::string type () {
return ""; }
67 static gsSolid<T> * get (gsXmlNode * node)
70 "Something went wrong. Expected Solid tag." );
72 gsSolid<T> * m =
new gsSolid<T>;
74 int n = atoi ( node->first_attribute(
"vertices")->value() ) ;
75 int nVol = atoi ( node->first_attribute(
"volumes")->value() ) ;
77 gsXmlNode * tmp = node->first_node(
"Vertex");
78 std::istringstream str;
79 str.str( tmp->value() );
85 std::vector< std::vector< gsSolidHeVertex<T>* > > vert;
88 for (
int i=0; i<n; ++i)
94 m->addHeVertex(x,y,z);
97 "Number of vertices does not match the Solid tag." );
100 gsXmlNode * toplevel = node->parent();
101 n = atoi ( node->first_attribute(
"faces")->value() ) ;
102 tmp = node->first_node(
"Face");
103 std::istringstream strf;
104 strf.str( tmp->value() );
106 for (
int iface=0; iface<n; iface++)
114 vert.push_back(std::vector< gsSolidHeVertex<T>* >());
117 for (
int ivert=0; ivert<nf; ivert++)
119 gsGetInt(strf, vertID);
120 vert[nLoops-1].push_back(m->vertex[vertID]);
126 gsGetInt(strf, trimID);
127 }
while(trimID <= -2);
129 m->addFace(vert,
getById< gsTrimSurface<T> >( toplevel, trimID ) );
130 else if (trimID==-1 && nLoops == 1)
132 else if (trimID==0 && nLoops == 1)
133 GISMO_ERROR(
"Faces must have unequal 0 as id (last value: increase from 1 or use -1 for all)");
136 gsWarn<<
"\nAutomatic creation of trimmed surfaces is only supported for a single loop\n";
140 gsWarn<<
"\n ID of the trimmed surface trimID=" <<trimID<<
" is invalid (must be >=-1)\n";
145 gsXmlNode * nodeVol = node->first_node(
"Volume");
148 GISMO_ASSERT(nVol == 1,
"More than one volume but faces for volumes not specified");
149 m->addVolume(m->face);
154 std::istringstream strVol;
155 strVol.str( nodeVol->value() );
156 std::vector<gsSolidHalfFace<T> *> volFaces;
157 for(
int i = 0; i < nVol; i++)
161 gsGetInt(strVol, numFaces);
162 for(
int j = 0; j < numFaces; j++)
165 gsGetInt(strVol, faceId);
166 volFaces.push_back(m->face[faceId]);
168 m->addVolume(volFaces);
176 static gsXmlNode * put (
const gsSolid<T> & obj,
180 size_t nVert = obj.vertex.size();
181 gsMatrix<T> vert(nVert, 3);
182 for(
size_t i = 0; i < nVert; i++)
184 vert.row(i) = obj.vertex[i]->coords;
188 size_t nFace = obj.face.size();
189 std::ostringstream strf;
190 std::vector<int> faceVerts;
191 for(
size_t i = 0; i < nFace; i++)
193 size_t nLoops = obj.face[i]->loop.size();
194 for(
size_t loopIdx = 0; loopIdx < nLoops; loopIdx++)
197 gsSolidHalfEdge<T> *eFirst = obj.face[i]->loop[loopIdx];
198 gsSolidHalfEdge<T> *e = eFirst;
201 faceVerts.push_back(e->source->getId());
203 }
while(e != eFirst);
204 size_t nfv = faceVerts.size();
207 for(
size_t j = 0; j < nfv; j++)
209 strf << faceVerts[j] <<
" ";
212 if(loopIdx < nLoops - 1) strf << -2 <<
" ";
219 int nVol = obj.nVolumes();
220 std::ostringstream strVol;
221 for(
int i = 0; i < nVol; i++)
223 size_t nVolF = obj.volume[i]->face.size();
224 strVol << nVolF <<
" ";
225 for(
size_t j = 0; j < nVolF; j++)
227 strVol << obj.volume[i]->face[j]->getId();
228 if(j < nVolF - 1) strVol <<
" ";
236 nodeSolid->append_attribute(
makeAttribute(
"vertices", nVert, data));
237 nodeSolid->append_attribute(
makeAttribute(
"faces", nFace, data));
238 nodeSolid->append_attribute(
makeAttribute(
"volumes", nVol, data));
241 nodeSolid->append_node(nodeVertex);
242 nodeSolid->append_node(nodeFace);
243 nodeSolid->append_node(nodeVolume);
246 for(
size_t i = 0; i < nFace; i++)
248 gsXmlNode* nodeTS = gsXml< gsTrimSurface<T> >::put(*(obj.face[i]->surf), data);
249 data.appendToRoot(nodeTS);
259class gsXml< gsMesh<T> >
264 GSXML_COMMON_FUNCTIONS(gsMesh<T>);
265 static std::string tag () {
return "Mesh"; }
266 static std::string type () {
return "off"; }
268 static gsMesh<T> * get (gsXmlNode * node)
270 assert( ( !strcmp( node->name(),
"Mesh") )
271 && ( !strcmp(node->first_attribute(
"type")->value(),
"off") ) );
273 gsMesh<T> * m =
new gsMesh<T>;
274 std::istringstream str;
275 str.str( node->value() );
277 unsigned n = atoi ( node->first_attribute(
"vertices")->value() ) ;
279 for (
unsigned i=0; i<n; ++i)
287 n = atoi ( node->first_attribute(
"faces")->value() ) ;
289 std::vector<int> face;
290 for (
unsigned i=0; i<n; ++i)
294 for (
unsigned j=0; j<c; ++j)
295 gsGetInt(str, face[j]);
302 static gsXmlNode * put (
const gsMesh<T> &,
312class gsXml< gsMatrix<T> >
316 typedef gsMatrix<T> Object;
319 GSXML_COMMON_FUNCTIONS(Object);
320 static std::string tag () {
return "Matrix"; }
321 static std::string type() {
return ""; }
323 GSXML_GET_POINTER(Object);
325 static void get_into (gsXmlNode * node, Object & obj)
328 "Something went wrong. Expected Matrix tag." );
330 unsigned rows = atoi(node->first_attribute(
"rows")->value());
331 unsigned cols = atoi(node->first_attribute(
"cols")->value());
332 gsXmlAttribute *format = node->first_attribute(
"format");
333 std::string format_flag = format ? format->value() :
"ascii";
334 getMatrixFromXml<T>(node, rows, cols, obj, format_flag);
337 static gsXmlNode * put (
const gsMatrix<T> & obj,
342 mat_data->append_attribute(
344 mat_data->append_attribute(
354class gsXml< gsSparseMatrix<T> >
358 typedef gsSparseMatrix<T> Object;
361 GSXML_COMMON_FUNCTIONS(Object);
362 static std::string tag () {
return "SparseMatrix"; }
363 static std::string type() {
return ""; }
365 GSXML_GET_POINTER(Object);
367 static void get_into (gsXmlNode * node, Object & obj)
370 "Something went wrong. Expected SparseMatrix tag." );
372 const index_t rows = atoi ( node->first_attribute(
"rows")->value() ) ;
373 const index_t cols = atoi ( node->first_attribute(
"cols")->value() ) ;
375 gsSparseEntries<T> entries;
376 getSparseEntriesFromXml<T>(node, entries);
378 obj.resize(rows,cols);
379 obj.setFrom(entries);
382 static gsXmlNode * put (
const gsSparseMatrix<T> & obj,
387 mat_data->append_attribute(
389 mat_data->append_attribute(
402template<
short_t d,
class T>
403class gsXml< gsTensorNurbsBasis<d,T> >
408 GSXML_COMMON_FUNCTIONS(gsTensorNurbsBasis<TMPLA2(d,T)>);
409 static std::string tag () {
return "Basis"; }
410 static std::string type () {
return "TensorNurbsBasis"+
to_string(d); }
412 static gsTensorNurbsBasis<d,T> * get (gsXmlNode * node)
414 return getRationalBasisFromXml< gsTensorNurbsBasis<d,T> >(node);
417 static gsXmlNode * put (
const gsTensorNurbsBasis<d,T> & obj,
420 return putRationalBasisToXml< gsTensorNurbsBasis<d,T> >(obj,data);
427class gsXml< gsNurbs<T> >
432 GSXML_COMMON_FUNCTIONS(gsNurbs<T>);
433 static std::string tag () {
return "Geometry"; }
434 static std::string type () {
return "Nurbs"; }
436 static gsNurbs<T> * get (gsXmlNode * node)
438 return getGeometryFromXml< gsNurbs<T> >(node);
441 static gsXmlNode * put (
const gsNurbs<T> & obj,
449template<
short_t d,
class T>
450class gsXml< gsTensorNurbs<d,T> >
455 GSXML_COMMON_FUNCTIONS(gsTensorNurbs<TMPLA2(d,T)>);
456 static std::string tag () {
return "Geometry"; }
457 static std::string type () {
return "TensorNurbs"+
to_string(d); }
459 static gsTensorNurbs<d,T> * get (gsXmlNode * node)
461 return getGeometryFromXml< gsTensorNurbs<d,T> >( node );
464 static gsXmlNode * put (
const gsTensorNurbs<d,T> & obj,
473class gsXml< gsTrimSurface<T> >
478 GSXML_COMMON_FUNCTIONS(gsTrimSurface<T>);
479 static std::string tag () {
return "TrimSurface"; }
480 static std::string type () {
return ""; }
482 static gsTrimSurface<T> * get (gsXmlNode * node)
484 assert( !strcmp( node->name(),
"TrimSurface") );
486 gsXmlNode * tmp = node->first_node(
"Geometry");
487 gsSurface<T> * geo = gsXml<gsSurface<T> >::get (tmp) ;
489 tmp = node->first_node(
"PlanarDomain");
490 gsPlanarDomain<T> * pd = gsXml<gsPlanarDomain<T> >::get (tmp) ;
492 return new gsTrimSurface<T>( geo, pd );
495 static gsXmlNode * put (
const gsTrimSurface<T> & obj,
499 gsXmlNode* nodeGeom = gsXml< gsGeometry<T> >::put(*(obj.getTP()), data);
500 gsXmlNode* nodeDom = gsXml< gsPlanarDomain<T> >::put(obj.domain(), data);
502 nodeTS->append_node(nodeGeom);
503 nodeTS->append_node(nodeDom);
510class gsXml< gsGeometry<T> >
515 GSXML_COMMON_FUNCTIONS(gsGeometry<T>);
516 static std::string tag () {
return "Geometry"; }
517 static std::string type () {
return ""; }
519 static gsGeometry<T> * get (gsXmlNode * node)
522 "Something went wrong, was waiting for a Geometry tag.\n" );
524 gsXmlAttribute * gtype = node->first_attribute(
"type");
527 gsWarn<<
"Geometry without a type in the xml file\n";
530 std::string s = gtype->value() ;
532 if ( s ==
"BSpline" )
533 return gsXml< gsBSpline<T> >::get(node);
535 return gsXml< gsNurbs<T> >::get(node);
536 if ( s ==
"HBSpline2" )
537 return gsXml< gsHBSpline<2,T> >::get(node);
538 if ( s ==
"HBSpline3" )
539 return gsXml< gsHBSpline<3,T> >::get(node);
540 if ( s ==
"THBSpline1" )
541 return gsXml< gsTHBSpline<1,T> >::get(node);
542 if ( s ==
"THBSpline2" )
543 return gsXml< gsTHBSpline<2,T> >::get(node);
544 if ( s ==
"THBSpline3" )
545 return gsXml< gsTHBSpline<3,T> >::get(node);
548 if ( s ==
"TensorBSpline1" )
549 return gsXml< gsTensorBSpline<1,T> >::get(node);
550 if ( s ==
"TensorBSpline2" )
551 return gsXml< gsTensorBSpline<2,T> >::get(node);
552 if ( s ==
"TensorBSpline3" )
553 return gsXml< gsTensorBSpline<3,T> >::get(node);
554 if ( s ==
"TensorBSpline4" )
555 return gsXml< gsTensorBSpline<4,T> >::get(node);
556 if ( s ==
"TensorNurbs2" )
557 return gsXml< gsTensorNurbs<2,T> >::get(node);
558 if ( s ==
"TensorNurbs3" )
559 return gsXml< gsTensorNurbs<3,T> >::get(node);
560 if ( s ==
"TensorNurbs4" )
561 return gsXml< gsTensorNurbs<4,T> >::get(node);
569 gsWarn<<
"gsXmlUtils: getGeometry: No known geometry \""<<s<<
"\". Error.\n";
574 static gsXmlNode * put (
const gsGeometry<T> & obj,
577 const gsGeometry<T> * ptr = & obj;
579 if (
const gsBSpline<T> * g =
580 dynamic_cast<const gsBSpline<T> *
>( ptr ) )
581 return gsXml< gsBSpline<T> >::put(*g,data);
583 if (
const gsNurbs<T> * g =
584 dynamic_cast<const gsNurbs<T> *
>( ptr ) )
585 return gsXml< gsNurbs<T> >::put(*g,data);
587 if (
const gsTensorBSpline<2,T> * g =
588 dynamic_cast<const gsTensorBSpline<2,T> *
>( ptr ) )
589 return gsXml< gsTensorBSpline<2,T> >::put(*g,data);
591 if (
const gsTensorBSpline<3,T> * g =
592 dynamic_cast<const gsTensorBSpline<3,T> *
>( ptr ) )
593 return gsXml< gsTensorBSpline<3,T> >::put(*g,data);
595 if (
const gsTensorBSpline<4,T> * g =
596 dynamic_cast<const gsTensorBSpline<4,T> *
>( ptr ) )
597 return gsXml< gsTensorBSpline<4,T> >::put(*g,data);
599 if (
const gsTensorNurbs<2,T> * g =
600 dynamic_cast<const gsTensorNurbs<2,T> *
>( ptr ) )
601 return gsXml< gsTensorNurbs<2,T> >::put(*g,data);
603 if (
const gsTensorNurbs<3,T> * g =
604 dynamic_cast<const gsTensorNurbs<3,T> *
>( ptr ) )
605 return gsXml< gsTensorNurbs<3,T> >::put(*g,data);
607 if (
const gsTensorNurbs<4,T> * g =
608 dynamic_cast<const gsTensorNurbs<4,T> *
>( ptr ) )
609 return gsXml< gsTensorNurbs<4,T> >::put(*g,data);
611 if (
const gsTHBSpline<1,T> * g =
612 dynamic_cast<const gsTHBSpline<1,T> *
>( ptr ) )
613 return gsXml< gsTHBSpline<1,T> >::put(*g,data);
615 if (
const gsTHBSpline<2,T> * g =
616 dynamic_cast<const gsTHBSpline<2,T> *
>( ptr ) )
617 return gsXml< gsTHBSpline<2,T> >::put(*g,data);
619 if (
const gsTHBSpline<3,T> * g =
620 dynamic_cast<const gsTHBSpline<3,T> *
>( ptr ) )
621 return gsXml< gsTHBSpline<3,T> >::put(*g,data);
623 if (
const gsTrimSurface<T> * g =
624 dynamic_cast<const gsTrimSurface<T> *
>( ptr ) )
625 return gsXml< gsTrimSurface<T> >::put(*g,data);
627 if (
const gsHBSpline<1,T> * g =
628 dynamic_cast<const gsHBSpline<1,T> *
>( ptr ) )
629 return gsXml< gsHBSpline<1,T> >::put(*g,data);
631 if (
const gsHBSpline<2,T> * g =
632 dynamic_cast<const gsHBSpline<2,T> *
>( ptr ) )
633 return gsXml< gsHBSpline<2,T> >::put(*g,data);
635 if (
const gsHBSpline<3,T> * g =
636 dynamic_cast<const gsHBSpline<3,T> *
>( ptr ) )
637 return gsXml< gsHBSpline<3,T> >::put(*g,data);
643 gsWarn<<
"gsXmlUtils: put Geometry: No known object "<< obj <<
"Error.\n";
652class gsXml< gsCurve<T> >
657 GSXML_COMMON_FUNCTIONS(gsCurve<T>);
658 static std::string tag () {
return "Geometry"; }
659 static std::string type () {
return ""; }
661 static gsCurve<T> * get (gsXmlNode * node)
664 "Something went wrong, was waiting for a Geometry tag.\n" );
666 gsXmlAttribute * gtype = node->first_attribute(
"type");
669 gsWarn<<
"Geometry without a type in the xml file\n";
672 std::string s = gtype->value() ;
674 if ( s ==
"BSpline" )
675 return gsXml< gsBSpline<T> >::get(node);
677 return gsXml< gsNurbs<T> >::get(node);
679 gsWarn<<
"gsXmlUtils: getCurve: No known curve \""<<s<<
"\". Error.\n";
684 static gsXmlNode * put (
const gsCurve<T> & obj,
687 const gsGeometry<T> * ptr = & obj;
689 if (
const gsBSpline<T> * g =
690 dynamic_cast<const gsBSpline<T> *
>( ptr ) )
691 return gsXml< gsBSpline<T> >::put(*g,data);
693 if (
const gsNurbs<T> * g =
694 dynamic_cast<const gsNurbs<T> *
>( ptr ) )
695 return gsXml< gsNurbs<T> >::put(*g,data);
697 if (
const gsHBSpline<1,T> * g =
698 dynamic_cast<const gsHBSpline<1,T> *
>( ptr ) )
699 return gsXml< gsHBSpline<1,T> >::put(*g,data);
701 gsWarn<<
"gsXmlUtils: put Curve: No known object "<< obj <<
"Error.\n";
709class gsXml< gsSurface<T> >
714 GSXML_COMMON_FUNCTIONS(gsSurface<T>);
715 static std::string tag () {
return "Geometry"; }
716 static std::string type () {
return ""; }
718 static gsSurface<T> * get (gsXmlNode * node)
721 "Something went wrong, was waiting for a Geometry tag.\n" );
723 gsXmlAttribute * gtype = node->first_attribute(
"type");
726 gsWarn<<
"Geometry without a type in the xml file\n";
729 std::string s = gtype->value() ;
731 if ( s ==
"HBSpline2" )
732 return gsXml< gsHBSpline<2,T> >::get(node);
733 if ( s ==
"THBSpline2" )
734 return gsXml< gsTHBSpline<2,T> >::get(node);
736 if ( s ==
"TensorBSpline2" )
737 return gsXml< gsTensorBSpline<2,T> >::get(node);
738 if ( s ==
"TensorNurbs2" )
739 return gsXml< gsTensorNurbs<2,T> >::get(node);
741 gsWarn<<
"gsXmlUtils: getSurface: No known surface \""<<s<<
"\". Error.\n";
745 static gsXmlNode * put (
const gsSurface<T> & obj,
748 const gsGeometry<T> * ptr = & obj;
750 if (
const gsTensorBSpline<2,T> * g =
751 dynamic_cast<const gsTensorBSpline<2,T> *
>( ptr ) )
752 return gsXml< gsTensorBSpline<2,T> >::put(*g,data);
754 if (
const gsTensorNurbs<2,T> * g =
755 dynamic_cast<const gsTensorNurbs<2,T> *
>( ptr ) )
756 return gsXml< gsTensorNurbs<2,T> >::put(*g,data);
758 if (
const gsTHBSpline<2,T> * g =
759 dynamic_cast<const gsTHBSpline<2,T> *
>( ptr ) )
760 return gsXml< gsTHBSpline<2,T> >::put(*g,data);
762 if (
const gsHBSpline<2,T> * g =
763 dynamic_cast<const gsHBSpline<2,T> *
>( ptr ) )
764 return gsXml< gsHBSpline<2,T> >::put(*g,data);
766 gsWarn<<
"gsXmlUtils: put Geometry: No known object "<< obj <<
"Error.\n";
773class gsXml< gsBasis<T> >
778 GSXML_COMMON_FUNCTIONS(gsBasis<T>);
779 static std::string tag () {
return "Basis"; }
780 static std::string type () {
return ""; }
782 static gsBasis<T> * get (gsXmlNode * node)
784 GISMO_ASSERT( ( !strcmp( node->name(),
"Basis") ),
"Something went wrong, waiting for a basis." );
786 gsXmlAttribute * btype = node->first_attribute(
"type");
789 gsWarn<<
"Basis without a type in the xml file.\n";
792 std::string s = btype->value() ;
794 if ( s ==
"BSplineBasis" )
795 return gsXml< gsBSplineBasis<T> >::get(node);
796 if ( s ==
"NurbsBasis" )
797 return gsXml< gsNurbsBasis<T> >::get(node);
799 if ( s ==
"HBSplineBasis" )
800 return gsXml< gsHBSplineBasis<1,T> >::get(node);
801 if ( s ==
"HBSplineBasis2" )
802 return gsXml< gsHBSplineBasis<2,T> >::get(node);
803 if ( s ==
"HBSplineBasis3" )
804 return gsXml< gsHBSplineBasis<3,T> >::get(node);
805 if ( s ==
"HBSplineBasis4" )
806 return gsXml< gsHBSplineBasis<4,T> >::get(node);
808 if ( s ==
"THBSplineBasis" )
809 return gsXml< gsTHBSplineBasis<1,T> >::get(node);
810 if ( s ==
"THBSplineBasis2" )
811 return gsXml< gsTHBSplineBasis<2,T> >::get(node);
812 if ( s ==
"THBSplineBasis3" )
813 return gsXml< gsTHBSplineBasis<3,T> >::get(node);
814 if ( s ==
"THBSplineBasis4" )
815 return gsXml< gsTHBSplineBasis<4,T> >::get(node);
820 if ( s ==
"TensorBSplineBasis2" )
821 return gsXml< gsTensorBSplineBasis<2, T> >::get(node);
822 if ( s ==
"TensorBSplineBasis3" )
823 return gsXml< gsTensorBSplineBasis<3, T> >::get(node);
824 if ( s ==
"TensorBSplineBasis4" )
825 return gsXml< gsTensorBSplineBasis<4, T> >::get(node);
827 if ( s ==
"TensorNurbsBasis2" )
828 return gsXml< gsTensorNurbsBasis<2, T> >::get(node);
829 if ( s ==
"TensorNurbsBasis3" )
830 return gsXml< gsTensorNurbsBasis<3, T> >::get(node);
831 if ( s ==
"TensorNurbsBasis4" )
832 return gsXml< gsTensorNurbsBasis<4, T> >::get(node);
834 gsWarn<<
"gsXmlUtils: getBasis: No known basis \""<<s<<
"\". Error.\n";
838 static gsXmlNode * put (
const gsBasis<T> & obj,
841 const gsBasis<T> * ptr = & obj;
843 if (
const gsBSplineBasis<T> * g =
844 dynamic_cast<const gsBSplineBasis<T> *
>( ptr ) )
845 return gsXml< gsBSplineBasis<T> >::put(*g,data);
847 if (
const gsNurbsBasis<T> * g =
848 dynamic_cast<const gsNurbsBasis<T> *
>( ptr ) )
849 return gsXml< gsNurbsBasis<T> >::put(*g,data);
852 if (
const gsTensorBSplineBasis<2, T> * g =
853 dynamic_cast<const gsTensorBSplineBasis<2, T> *
>( ptr ) )
854 return gsXml< gsTensorBSplineBasis<2, T> >::put(*g,data);
856 if (
const gsTensorBSplineBasis<3, T> * g =
857 dynamic_cast<const gsTensorBSplineBasis<3, T> *
>( ptr ) )
858 return gsXml< gsTensorBSplineBasis<3, T> >::put(*g,data);
860 if (
const gsTensorBSplineBasis<4, T> * g =
861 dynamic_cast<const gsTensorBSplineBasis<4, T> *
>( ptr ) )
862 return gsXml< gsTensorBSplineBasis<4, T> >::put(*g,data);
865 if (
const gsTensorNurbsBasis<2, T> * g =
866 dynamic_cast<const gsTensorNurbsBasis<2, T> *
>( ptr ) )
867 return gsXml< gsTensorNurbsBasis<2, T> >::put(*g,data);
869 if (
const gsTensorNurbsBasis<3, T> * g =
870 dynamic_cast<const gsTensorNurbsBasis<3, T> *
>( ptr ) )
871 return gsXml< gsTensorNurbsBasis<3, T> >::put(*g,data);
873 if (
const gsTensorNurbsBasis<4, T> * g =
874 dynamic_cast<const gsTensorNurbsBasis<4, T> *
>( ptr ) )
875 return gsXml< gsTensorNurbsBasis<4, T> >::put(*g,data);
879 if (
const gsHTensorBasis<1,T> * g =
880 dynamic_cast<const gsHTensorBasis<1,T> *
>( ptr ) )
881 return gsXml< gsHTensorBasis<1,T> >::put(*g,data);
883 if (
const gsHTensorBasis<2,T> * g =
884 dynamic_cast<const gsHTensorBasis<2,T> *
>( ptr ) )
885 return gsXml< gsHTensorBasis<2,T> >::put(*g,data);
887 if (
const gsHTensorBasis<3,T> * g =
888 dynamic_cast<const gsHTensorBasis<3,T> *
>( ptr ) )
889 return gsXml< gsHTensorBasis<3,T> >::put(*g,data);
891 if (
const gsHTensorBasis<4,T> * g =
892 dynamic_cast<const gsHTensorBasis<4,T> *
>( ptr ) )
893 return gsXml< gsHTensorBasis<4,T> >::put(*g,data);
895 if (
const gsTHBSplineBasis<3,T> * g =
896 dynamic_cast<const gsTHBSplineBasis<3,T> *
>( ptr ) )
897 return gsXml< gsTHBSplineBasis<3,T> >::put(*g,data);
903 gsWarn<<
"gsXmlUtils put: getBasis: No known basis \""<<obj<<
"\". Error.\n";
910class gsXml< gsPde<T> >
915 GSXML_COMMON_FUNCTIONS(gsPde<T>);
916 static std::string tag () {
return "Pde"; }
917 static std::string type () {
return ""; }
919 static gsPde<T> * get (gsXmlNode * node)
922 "Something went wrong. Expected Pde tag." );
924 std::string s = node->first_attribute(
"type")->value() ;
925 if ( s ==
"PoissonPde" )
926 return gsXml< gsPoissonPde<T> >::get(node);
927 if ( s ==
"SurfacePoissonPde" )
928 return gsXml< gsSurfacePoissonPde<T> >::get(node);
930 gsWarn<<
"gsXmlUtils: getPde: No known Pde \""<<s<<
"\". Error.\n";
934 static gsXmlNode * put (
const gsPde<T> &,
944class gsXml< gsMultiPatch<T> >
948 typedef gsMultiPatch<T> Object;
951 GSXML_COMMON_FUNCTIONS(Object);
952 static std::string tag () {
return "MultiPatch"; }
953 static std::string type () {
return ""; }
955 GSXML_GET_POINTER(Object);
957 static void get_into (gsXmlNode * node, Object & obj)
960 "Something went wrong. Expected Multipatch tag." );
963 gsXmlNode * toplevel = node->parent();
965 const int d = atoi( node->first_attribute(
"parDim")->value() );
967 gsXmlNode * tmp = node->first_node(
"patches");
968 std::istringstream str ;
969 str.str( tmp->value() );
971 std::vector< gsGeometry<T> *> patches;
972 std::map<int,int> ids;
973 if ( ! strcmp( tmp->first_attribute(
"type")->value(),
"id_range") )
976 gsGetInt(str, first);
978 for (
int i = first; i<=last; ++i )
981 "No Geometry with Id "<<i<<
" found in the XML data.");
982 patches.push_back(
getById< gsGeometry<T> >( toplevel, i ) );
983 patches.back()->setId(i);
987 else if ( ! strcmp( tmp->first_attribute(
"type")->value(),
"id_index") )
990 for (
int pindex; gsGetInt(str, pindex);)
993 "No Geometry with Id "<<pindex<<
" found in the XML data.");
994 patches.push_back(
getById< gsGeometry<T> >( toplevel, pindex ) );
995 patches.back()->setId(pindex);
1001 gsWarn<<
"Unknown tag in XML multipatch object.\n";
1011 std::vector< patchSide > boundaries;
1012 for (gsXmlNode * child = node->first_node(
"boundary"); child;
1013 child = child->next_sibling(
"boundary"))
1015 std::vector< patchSide > tmp_boundaries;
1018 getBoundaries(child, ids, tmp_boundaries);
1019 boundaries.insert( boundaries.end(), tmp_boundaries.begin(), tmp_boundaries.end() );
1023 std::sort(boundaries.begin(), boundaries.end());
1024 boundaries.erase(std::unique(boundaries.begin(), boundaries.end()), boundaries.end());
1027 std::vector< boundaryInterface > interfaces;
1028 for (gsXmlNode * child = node->first_node(
"interfaces"); child;
1029 child = child->next_sibling(
"interfaces"))
1031 std::vector< boundaryInterface > tmp_interfaces;
1034 getInterfaces(child, d, ids, tmp_interfaces);
1035 interfaces.insert( interfaces.end(), tmp_interfaces.begin(), tmp_interfaces.end() );
1039 std::sort(interfaces.begin(), interfaces.end());
1040 interfaces.erase(std::unique(interfaces.begin(), interfaces.end()), interfaces.end());
1043 obj = gsMultiPatch<T>(patches, boundaries, interfaces);
1046 static gsXmlNode * put (
const gsMultiPatch<T> & obj,
1050 int max_id = data.maxId();
1052 std::map<index_t, index_t> id_map;
1053 for (
typename gsMultiPatch<T>::const_iterator it = obj.begin();
1054 it != obj.end(); ++it )
1056 tmp = gsXml<gsGeometry<T> >::put(**it,data);
1057 data.appendToRoot(tmp);
1058 id_map[obj.findPatchIndex(*it)] = std::stoi(tmp->first_attribute(
"id")->value());
1061 std::ostringstream str;
1062 str<< max_id+1 <<
" "<< data.maxId();
1065 str.clear(); str.str(
"");
1070 mp_node->append_node(tmp);
1074 if (obj.numBoxProperties()!=0)
1075 gsWarn<<
"Multi-patch object has box properties that are not written to XML\n";
1084class gsXml< gsMultiBasis<T> >
1088 typedef gsMultiBasis<T> Object;
1091 GSXML_COMMON_FUNCTIONS(Object);
1092 GSXML_GET_POINTER(Object);
1093 static std::string tag() {
return "MultiBasis"; }
1094 static std::string type() {
return ""; }
1096 static void get_into(gsXmlNode* node, Object & result)
1099 "Something went wrong. Expected MultiBasis tag." );
1101 gsXmlNode* topLevel = node->parent();
1103 const int d = atoi( node->first_attribute(
"parDim")->value() );
1105 gsXmlNode* patchNode = node->first_node(
"patches");
1106 std::istringstream iss;
1107 iss.str( patchNode->value() );
1109 typename gsMultiBasis<T>::BasisContainer bases;
1110 std::map<int, int> ids;
1111 if ( !strcmp( patchNode->first_attribute(
"type")->value(),
"id_range") )
1114 gsGetInt(iss, first);
1115 gsGetInt(iss, last);
1116 for (
int i = first; i <= last; ++i)
1118 bases.push_back(
getById< gsBasis<T> >( topLevel, i ) );
1122 else if ( !strcmp( patchNode->first_attribute(
"type")->value(),
"id_index") )
1125 for (
int pindex; gsGetInt(iss, pindex); )
1127 bases.push_back(
getById< gsBasis<T> >( topLevel, pindex ) );
1133 gsWarn <<
"unknown tag in XML multipatch object \n";
1137 std::vector< patchSide > boundaries;
1138 gsXmlNode * tmp = node->first_node(
"boundary");
1140 getBoundaries(tmp, ids, boundaries);
1143 std::vector< boundaryInterface > interfaces;
1144 tmp = node->first_node(
"interfaces");
1146 getInterfaces(tmp, d, ids, interfaces);
1148 gsBoxTopology topology( d, bases.size(), boundaries, interfaces);
1150 result = gsMultiBasis<T>(bases, topology);
1154 static gsXmlNode* put(
const gsMultiBasis<T>& obj,
1158 std::map<index_t, index_t> id_map;
1159 int max_id = data.maxId();
1160 for (
typename gsMultiBasis<T>::const_iterator it = obj.begin();
1161 it != obj.end(); ++it )
1163 gsXmlNode* basisXml = gsXml< gsBasis<T> >::put(**it, data);
1164 data.appendToRoot( basisXml );
1165 id_map[obj.findBasisIndex(*it) ] = std::stoi(basisXml->first_attribute(
"id")->value());
1168 std::ostringstream oss;
1169 oss<< max_id+1 <<
" "<< data.maxId();
1177 mbNode->append_node(node);
1189class gsXml< gsPlanarDomain<T> >
1194 GSXML_COMMON_FUNCTIONS(gsPlanarDomain<T>);
1195 static std::string tag () {
return "PlanarDomain"; }
1196 static std::string type () {
return ""; }
1198 static gsPlanarDomain<T> * get (gsXmlNode * node)
1201 "Something went wrong. Expected PlanarDomain tag." );
1203 std::vector<gsCurveLoop<T>*> loops;
1204 for (gsXmlNode * tmp = node->first_node(
"CurveLoop");
1205 tmp; tmp = tmp->next_sibling(
"CurveLoop"))
1206 loops.push_back( gsXml<gsCurveLoop<T> >::get(tmp) ) ;
1208 return new gsPlanarDomain<T>( loops );
1211 static gsXmlNode * put (
const gsPlanarDomain<T> & obj,
1218 int nl = obj.numLoops();
1220 for (
int i=0; i!=nl; ++i)
1222 tmp = internal::gsXml< gsCurveLoop<T> >::put(obj.loop(i), data );
1224 pl->append_node(tmp);
1232class gsXml< gsCurveLoop<T> >
1237 GSXML_COMMON_FUNCTIONS(gsCurveLoop<T>);
1238 static std::string tag () {
return "CurveLoop"; }
1239 static std::string type () {
return ""; }
1241 static gsCurveLoop<T> * get (gsXmlNode * node)
1244 "Something went wrong. Expected CurveLoop tag." );
1246 std::vector<gsCurve<T>* > curves;
1248 for (gsXmlNode * tmp = node->first_node(
"Geometry");
1249 tmp; tmp = tmp->next_sibling(
"Geometry"))
1250 curves.push_back( gsXml<gsCurve<T> >::get(tmp) ) ;
1252 return new gsCurveLoop<T>( curves );
1255 static gsXmlNode * put (
const gsCurveLoop<T> & obj,
1262 int nc = obj.numCurves();
1264 for (
int i=0; i!=nc; ++i)
1266 tmp = internal::gsXml< gsGeometry<T> >::put(obj.curve(i), data );
1268 cl->append_node(tmp);
1277class gsXml< gsCurveFitting<T> >
1282 GSXML_COMMON_FUNCTIONS(gsCurveFitting<T>);
1283 static std::string tag () {
return "CurveFitting"; }
1284 static std::string type() {
return ""; }
1286 static gsCurveFitting<T> * get (gsXmlNode * node)
1289 "Something went wrong. Expected CurveFitting tag." );
1291 bool closed = (atoi(node->first_attribute(
"closed")->value() ) != 0);
1294 gsXmlNode * tmp = node->first_node(
"KnotVector");
1295 gsKnotVector<T> * kv = gsXml< gsKnotVector<T> >::get(tmp);
1298 tmp = node->first_node(
"Matrix");
1299 gsMatrix<T> * parval = gsXml< gsMatrix<T> >::get(tmp);
1302 tmp = tmp->next_sibling(
"Matrix");
1303 gsMatrix<T> * pts = gsXml< gsMatrix<T> >::get(tmp);
1305 gsCurveFitting<T> * cf =
new gsCurveFitting<T>(*parval,*pts,*kv,closed);
1312 static gsXmlNode * put (
const gsCurveFitting<T> &,
1322class gsXml< gsPoissonPde<T> >
1327 GSXML_COMMON_FUNCTIONS(gsPoissonPde<T>);
1328 static std::string tag () {
return "Pde"; }
1329 static std::string type () {
return "PoissonPde"; }
1331 static gsPoissonPde<T> * get (gsXmlNode * node)
1333 assert( ( !strcmp( node->name(),
"Pde") ) &&
1335 strcmp( node->first_attribute(
"type")->value(),
"PoissonPde")
1336 && strcmp( node->first_attribute(
"type")->value(),
"SurfacePoissonPde")
1340 GISMO_ASSERT( node->first_attribute(
"dim"),
"xml reader: No dim found" ) ;
1341 short_t d = atoi( node->first_attribute(
"dim")->value() );
1345 gsXmlAttribute * targetDim = node->first_attribute(
"targetDim");
1348 tDim = atoi( targetDim->value() );
1352 gsXmlNode * tmp = node->first_node(
"rhs");
1353 gsFunctionExpr<T> rhs_fnct;
1354 internal::gsXml<gsFunctionExpr<T> >::get_into(tmp, rhs_fnct);
1356 tmp = node->first_node(
"solution");
1359 gsFunctionExpr<T> msol;
1360 internal::gsXml<gsFunctionExpr<T> >::get_into(tmp, msol);
1362 return new gsPoissonPde<T>(rhs_fnct, d, msol );
1366 return new gsPoissonPde<T>( rhs_fnct, d );
1371 gsXmlNode * tmp = node->first_node(
"rhs");
1372 gsFunctionExpr<T> rhs(tmp->value(), d);
1375 tmp = node->first_node(
"solution");
1378 gsFunctionExpr<T> sol(tmp->value(), d);
1380 return new gsPoissonPde<T>(rhs, d, sol );
1384 return new gsPoissonPde<T>( rhs, d );
1388 static gsXmlNode * put (
const gsPoissonPde<T> &,
1399class gsXml< gsSurfacePoissonPde<T> >
1404 GSXML_COMMON_FUNCTIONS(gsSurfacePoissonPde<T>);
1405 static std::string tag () { return "Pde"; }
1406 static std::string type () { return "SurfacePoissonPde"; }
1408 static gsSurfacePoissonPde<T> * get (gsXmlNode * node)
1410 assert( ( !strcmp( node->name(),"Pde") ) &&
1411 ( !strcmp( node->first_attribute("type")->value(),"SurfacePoissonPde") ) );
1413 // Read the dimension
1414 assert( node->first_attribute("dim") ) ;
1415 unsigned d = atoi( node->first_attribute("dim")->value() );
1417 // Read right hand side function
1418 gsXmlNode * tmp = node->first_node("rhs");
1419 gsFunctionExpr<T> * rhs = new gsFunctionExpr<T>(tmp->value());
1421 // Read exact solution, if one exists in the file
1422 tmp = node->first_node("solution");
1425 gsFunctionExpr<T> * sol = new gsFunctionExpr<T>(tmp->value());
1426 //gsDebugVar (*sol);
1427 return new gsSurfacePoissonPde<T>(rhs, d, sol );
1431 return new gsSurfacePoissonPde<T>( rhs, d );
1435 static gsXmlNode * put (const gsSurfacePoissonPde<T> & obj,
1447class gsXml< gsBVProblem<T> >
1452 GSXML_COMMON_FUNCTIONS(gsBVProblem<T>);
1453 static std::string tag () { return "BVProblem"; }
1454 static std::string type() { return ""; }
1456 static gsBVProblem<T> * get (gsXmlNode * node)
1458 GISMO_ASSERT( !strcmp( node->name(),"BVProblem"),
1459 "Something went wrong. Expected BVProblem tag." );
1461 gsBVProblem<T> * bvp;
1464 gsPde<T> * pde = gsXml< gsPde<T> >::get( node->first_node("Pde") );
1467 int domain = atoi(node->first_attribute("domain")->value() );
1468 gsXmlNode * toplevel = node->parent();// the geometry patches should be siblings of node
1469 std::string dtag; // = getTag(toplevel, domain );
1470 for (gsXmlNode * child = node->first_node();
1471 child; child = child->next_sibling() )
1472 if ( atoi(child->first_attribute("id")->value() ) == domain )
1474 dtag = child->name();
1478 if ( dtag == "Geometry" )
1480 gsGeometry<T> * geo = getById< gsGeometry<T> >(toplevel,domain);
1481 bvp = new gsBVProblem<T>(geo, pde);
1483 else if ( dtag == "MultiPatch" )
1485 // to do: memory to delete?
1486 gsMultiPatch<T> * mp = getById< gsMultiPatch<T> >(toplevel,domain);
1487 bvp = new gsBVProblem<T>(*mp, pde);
1491 GISMO_ERROR("Invalid tag");
1494 // Read in boundary conditions
1495 for (gsXmlNode * child = node->first_node("bc");
1496 child; child = child->next_sibling("bc") )
1498 gsFunctionExpr<T> * ff =
1499 new gsFunctionExpr<T>(child->first_attribute("function")->value() );
1500 std::istringstream str;
1501 str.str( child->value() );
1503 if ( !strcmp(child->first_attribute("type")->value(), "dirichlet") )
1505 for (int side; gsGetInt(str, side);)
1506 bvp->addCondition( static_cast<boxSide>(side),
1507 condition_type::dirichlet, ff);
1509 else if ( !strcmp(child->first_attribute("type")->value(), "neumann") )
1511 for (int side; gsGetInt(str, side);)
1512 bvp->addCondition( static_cast<boxSide>(side),
1513 condition_type::neumann, ff);
1520 static gsXmlNode * put (const gsBVProblem<T> & obj,
Provides declaration of Basis abstract interface.
Provides structs and classes related to interfaces and boundaries.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
Fits a (closed) B-spline curve to some given data.
#define GISMO_ERROR(message)
Definition gsDebug.h:118
#define gsWarn
Definition gsDebug.h:50
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of FunctionExpr class.
Provides declaration of THBSplineBasis class.
This is the main header file that collects wrappers of Eigen for linear algebra.
Provides declaration of the Mesh class.
Provides declaration of MultiBasis class.
Provides declaration of the MultiPatch class.
Represents a NURBS curve/function with one parameter.
Provides declaration of gsPlanarDomain class. The outer boundary (m_loops[0]) is a loop of curves,...
Provides declaration of RationalBasis class.
Provides declaration of gsSolid class, a boundary-represented solid.
Provides declaration of THBSplineBasis class.
Represents a tensor-product NURBS patch.
Provides interface of gsTrimSurface class. Represents a trimmed surface (= spline "master surface" in...
Provides implementation of generic XML functions.
gsXmlNode * putSparseMatrixToXml(gsSparseMatrix< T > const &mat, gsXmlTree &data, std::string name="SparseMatrix")
Helper to insert sparse matrices into XML.
Definition gsXml.hpp:111
void appendBoxTopology(const gsBoxTopology &topology, gsXmlNode *node, std::map< index_t, index_t > id_map, gsXmlTree &data)
Appends a box topology into node, used for gsMultiPatch and gsMultiBasis.
Definition gsXml.cpp:186
gsXmlNode * putGeometryToXml(Object const &obj, gsXmlTree &data)
Helper to put geometries to XML.
Definition gsXmlGenericUtils.hpp:388
gsXmlNode * putMatrixToXml(gsMatrix< T > const &mat, gsXmlTree &data, std::string name="Matrix")
Helper to insert matrices into XML.
Definition gsXml.hpp:103
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition gsXml.cpp:74
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition gsXml.cpp:54
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition gsXml.cpp:37
gsXmlNode * searchId(const int id, gsXmlNode *root, const char *tag_name=NULL, const bool print_warning=true)
Definition gsXml.h:254
Object * getById(gsXmlNode *node, const int &id)
Definition gsXml.h:311
The G+Smo namespace, containing all definitions for the library.
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition gsMemory.h:312