44 #include <gsPde/gsSurfacePoissonPde.h>
59 class gsXml< gsSolid<T> >
64 GSXML_COMMON_FUNCTIONS(gsSolid<T>);
65 static std::string tag () {
return "Solid"; }
66 static std::string type () {
return ""; }
68 static gsSolid<T> *
get (gsXmlNode * node)
71 "Something went wrong. Expected Solid tag." );
73 gsSolid<T> * m =
new gsSolid<T>;
75 int n = atoi ( node->first_attribute(
"vertices")->value() ) ;
76 int nVol = atoi ( node->first_attribute(
"volumes")->value() ) ;
78 gsXmlNode * tmp = node->first_node(
"Vertex");
79 std::istringstream str;
80 str.str( tmp->value() );
86 std::vector< std::vector< gsSolidHeVertex<T>* > > vert;
89 for (
int i=0; i<n; ++i)
95 m->addHeVertex(x,y,z);
98 "Number of vertices does not match the Solid tag." );
101 gsXmlNode * toplevel = node->parent();
102 n = atoi ( node->first_attribute(
"faces")->value() ) ;
103 tmp = node->first_node(
"Face");
104 std::istringstream strf;
105 strf.str( tmp->value() );
107 for (
int iface=0; iface<n; iface++)
115 vert.push_back(std::vector< gsSolidHeVertex<T>* >());
118 for (
int ivert=0; ivert<nf; ivert++)
120 gsGetInt(strf, vertID);
121 vert[nLoops-1].push_back(m->vertex[vertID]);
127 gsGetInt(strf, trimID);
128 }
while(trimID <= -2);
130 m->addFace(vert,
getById< gsTrimSurface<T> >( toplevel, trimID ) );
131 else if (trimID==-1 && nLoops == 1)
133 else if (trimID==0 && nLoops == 1)
134 GISMO_ERROR(
"Faces must have unequal 0 as id (last value: increase from 1 or use -1 for all)");
137 gsWarn<<
"\nAutomatic creation of trimmed surfaces is only supported for a single loop\n";
141 gsWarn<<
"\n ID of the trimmed surface trimID=" <<trimID<<
" is invalid (must be >=-1)\n";
146 gsXmlNode * nodeVol = node->first_node(
"Volume");
149 GISMO_ASSERT(nVol == 1,
"More than one volume but faces for volumes not specified");
150 m->addVolume(m->face);
155 std::istringstream strVol;
156 strVol.str( nodeVol->value() );
157 std::vector<gsSolidHalfFace<T> *> volFaces;
158 for(
int i = 0; i < nVol; i++)
162 gsGetInt(strVol, numFaces);
163 for(
int j = 0; j < numFaces; j++)
166 gsGetInt(strVol, faceId);
167 volFaces.push_back(m->face[faceId]);
169 m->addVolume(volFaces);
177 static gsXmlNode * put (
const gsSolid<T> & obj,
181 size_t nVert = obj.vertex.size();
182 gsMatrix<T> vert(nVert, 3);
183 for(
size_t i = 0; i < nVert; i++)
185 vert.row(i) = obj.vertex[i]->coords;
189 size_t nFace = obj.face.size();
190 std::ostringstream strf;
191 std::vector<int> faceVerts;
192 for(
size_t i = 0; i < nFace; i++)
194 size_t nLoops = obj.face[i]->loop.size();
195 for(
size_t loopIdx = 0; loopIdx < nLoops; loopIdx++)
198 gsSolidHalfEdge<T> *eFirst = obj.face[i]->loop[loopIdx];
199 gsSolidHalfEdge<T> *e = eFirst;
202 faceVerts.push_back(e->source->getId());
204 }
while(e != eFirst);
205 size_t nfv = faceVerts.size();
208 for(
size_t j = 0; j < nfv; j++)
210 strf << faceVerts[j] <<
" ";
213 if(loopIdx < nLoops - 1) strf << -2 <<
" ";
220 int nVol = obj.nVolumes();
221 std::ostringstream strVol;
222 for(
int i = 0; i < nVol; i++)
224 size_t nVolF = obj.volume[i]->face.size();
225 strVol << nVolF <<
" ";
226 for(
size_t j = 0; j < nVolF; j++)
228 strVol << obj.volume[i]->face[j]->getId();
229 if(j < nVolF - 1) strVol <<
" ";
237 nodeSolid->append_attribute(
makeAttribute(
"vertices", nVert, data));
238 nodeSolid->append_attribute(
makeAttribute(
"faces", nFace, data));
239 nodeSolid->append_attribute(
makeAttribute(
"volumes", nVol, data));
242 nodeSolid->append_node(nodeVertex);
243 nodeSolid->append_node(nodeFace);
244 nodeSolid->append_node(nodeVolume);
247 for(
size_t i = 0; i < nFace; i++)
249 gsXmlNode* nodeTS = gsXml< gsTrimSurface<T> >::put(*(obj.face[i]->surf), data);
250 data.appendToRoot(nodeTS);
260 class gsXml< gsMesh<T> >
265 GSXML_COMMON_FUNCTIONS(gsMesh<T>);
266 static std::string tag () {
return "Mesh"; }
267 static std::string type () {
return "off"; }
269 static gsMesh<T> *
get (gsXmlNode * node)
271 assert( ( !strcmp( node->name(),
"Mesh") )
272 && ( !strcmp(node->first_attribute(
"type")->value(),
"off") ) );
274 gsMesh<T> * m =
new gsMesh<T>;
275 std::istringstream str;
276 str.str( node->value() );
278 unsigned n = atoi ( node->first_attribute(
"vertices")->value() ) ;
280 for (
unsigned i=0; i<n; ++i)
288 n = atoi ( node->first_attribute(
"faces")->value() ) ;
290 std::vector<int> face;
291 for (
unsigned i=0; i<n; ++i)
295 for (
unsigned j=0; j<c; ++j)
296 gsGetInt(str, face[j]);
303 static gsXmlNode * put (
const gsMesh<T> &,
313 class gsXml< gsMatrix<T> >
317 typedef gsMatrix<T> Object;
320 GSXML_COMMON_FUNCTIONS(Object);
321 static std::string tag () {
return "Matrix"; }
322 static std::string type() {
return ""; }
324 GSXML_GET_POINTER(Object);
326 static void get_into (gsXmlNode * node, Object & obj)
329 "Something went wrong. Expected Matrix tag." );
331 unsigned rows = atoi(node->first_attribute(
"rows")->value());
332 unsigned cols = atoi(node->first_attribute(
"cols")->value());
333 gsXmlAttribute *format = node->first_attribute(
"format");
334 std::string format_flag = format ? format->value() :
"ascii";
335 getMatrixFromXml<T>(node, rows, cols, obj, format_flag);
338 static gsXmlNode * put (
const gsMatrix<T> & obj,
343 mat_data->append_attribute(
345 mat_data->append_attribute(
355 class gsXml< gsSparseMatrix<T> >
359 typedef gsSparseMatrix<T> Object;
362 GSXML_COMMON_FUNCTIONS(Object);
363 static std::string tag () {
return "SparseMatrix"; }
364 static std::string type() {
return ""; }
366 GSXML_GET_POINTER(Object);
368 static void get_into (gsXmlNode * node, Object & obj)
371 "Something went wrong. Expected SparseMatrix tag." );
373 const index_t rows = atoi ( node->first_attribute(
"rows")->value() ) ;
374 const index_t cols = atoi ( node->first_attribute(
"cols")->value() ) ;
376 gsSparseEntries<T> entries;
377 getSparseEntriesFromXml<T>(node, entries);
379 obj.resize(rows,cols);
380 obj.setFrom(entries);
383 static gsXmlNode * put (
const gsSparseMatrix<T> & obj,
388 mat_data->append_attribute(
390 mat_data->append_attribute(
403 class gsXml< gsNurbsBasis<T> >
408 GSXML_COMMON_FUNCTIONS(gsNurbsBasis<T>);
409 static std::string tag () {
return "Basis"; }
410 static std::string type () {
return "NurbsBasis"; }
412 static gsNurbsBasis<T> *
get (gsXmlNode * node)
414 return getRationalBasisFromXml<gsNurbsBasis<T> >(node);
417 static gsXmlNode * put (
const gsNurbsBasis<T> & obj,
420 return putRationalBasisToXml(obj,data);
426 template<
short_t d,
class T>
427 class gsXml< gsTensorNurbsBasis<d,T> >
432 GSXML_COMMON_FUNCTIONS(gsTensorNurbsBasis<TMPLA2(d,T)>);
433 static std::string tag () {
return "Basis"; }
434 static std::string type () {
return "TensorNurbsBasis"+
to_string(d); }
436 static gsTensorNurbsBasis<d,T> *
get (gsXmlNode * node)
438 return getRationalBasisFromXml< gsTensorNurbsBasis<d,T> >(node);
441 static gsXmlNode * put (
const gsTensorNurbsBasis<d,T> & obj,
444 return putRationalBasisToXml< gsTensorNurbsBasis<d,T> >(obj,data);
451 class gsXml< gsNurbs<T> >
456 GSXML_COMMON_FUNCTIONS(gsNurbs<T>);
457 static std::string tag () {
return "Geometry"; }
458 static std::string type () {
return "Nurbs"; }
460 static gsNurbs<T> *
get (gsXmlNode * node)
462 return getGeometryFromXml< gsNurbs<T> >(node);
465 static gsXmlNode * put (
const gsNurbs<T> & obj,
473 template<
short_t d,
class T>
474 class gsXml< gsTensorNurbs<d,T> >
479 GSXML_COMMON_FUNCTIONS(gsTensorNurbs<TMPLA2(d,T)>);
480 static std::string tag () {
return "Geometry"; }
481 static std::string type () {
return "TensorNurbs"+
to_string(d); }
483 static gsTensorNurbs<d,T> *
get (gsXmlNode * node)
485 return getGeometryFromXml< gsTensorNurbs<d,T> >( node );
488 static gsXmlNode * put (
const gsTensorNurbs<d,T> & obj,
497 class gsXml< gsTrimSurface<T> >
502 GSXML_COMMON_FUNCTIONS(gsTrimSurface<T>);
503 static std::string tag () {
return "TrimSurface"; }
504 static std::string type () {
return ""; }
506 static gsTrimSurface<T> *
get (gsXmlNode * node)
508 assert( !strcmp( node->name(),
"TrimSurface") );
510 gsXmlNode * tmp = node->first_node(
"Geometry");
511 gsSurface<T> * geo = gsXml<gsSurface<T> >::get (tmp) ;
513 tmp = node->first_node(
"PlanarDomain");
514 gsPlanarDomain<T> * pd = gsXml<gsPlanarDomain<T> >::get (tmp) ;
516 return new gsTrimSurface<T>( geo, pd );
519 static gsXmlNode * put (
const gsTrimSurface<T> & obj,
523 gsXmlNode* nodeGeom = gsXml< gsGeometry<T> >::put(*(obj.getTP()), data);
524 gsXmlNode* nodeDom = gsXml< gsPlanarDomain<T> >::put(obj.domain(), data);
526 nodeTS->append_node(nodeGeom);
527 nodeTS->append_node(nodeDom);
534 class gsXml< gsGeometry<T> >
539 GSXML_COMMON_FUNCTIONS(gsGeometry<T>);
540 static std::string tag () {
return "Geometry"; }
541 static std::string type () {
return ""; }
543 static gsGeometry<T> *
get (gsXmlNode * node)
546 "Something went wrong, was waiting for a Geometry tag.\n" );
548 gsXmlAttribute * gtype = node->first_attribute(
"type");
551 gsWarn<<
"Geometry without a type in the xml file\n";
554 std::string s = gtype->value() ;
556 if ( s ==
"BSpline" )
557 return gsXml< gsBSpline<T> >::get(node);
559 return gsXml< gsNurbs<T> >::get(node);
560 if ( s ==
"HBSpline2" )
561 return gsXml< gsHBSpline<2,T> >::get(node);
562 if ( s ==
"HBSpline3" )
563 return gsXml< gsHBSpline<3,T> >::get(node);
564 if ( s ==
"THBSpline1" )
565 return gsXml< gsTHBSpline<1,T> >::get(node);
566 if ( s ==
"THBSpline2" )
567 return gsXml< gsTHBSpline<2,T> >::get(node);
568 if ( s ==
"THBSpline3" )
569 return gsXml< gsTHBSpline<3,T> >::get(node);
572 if ( s ==
"TensorBSpline1" )
573 return gsXml< gsTensorBSpline<1,T> >::get(node);
574 if ( s ==
"TensorBSpline2" )
575 return gsXml< gsTensorBSpline<2,T> >::get(node);
576 if ( s ==
"TensorBSpline3" )
577 return gsXml< gsTensorBSpline<3,T> >::get(node);
578 if ( s ==
"TensorBSpline4" )
579 return gsXml< gsTensorBSpline<4,T> >::get(node);
580 if ( s ==
"TensorNurbs2" )
581 return gsXml< gsTensorNurbs<2,T> >::get(node);
582 if ( s ==
"TensorNurbs3" )
583 return gsXml< gsTensorNurbs<3,T> >::get(node);
584 if ( s ==
"TensorNurbs4" )
585 return gsXml< gsTensorNurbs<4,T> >::get(node);
593 gsWarn<<
"gsXmlUtils: getGeometry: No known geometry \""<<s<<
"\". Error.\n";
598 static gsXmlNode * put (
const gsGeometry<T> & obj,
601 const gsGeometry<T> * ptr = & obj;
603 if (
const gsBSpline<T> * g =
604 dynamic_cast<const gsBSpline<T> *
>( ptr ) )
605 return gsXml< gsBSpline<T> >::put(*g,data);
607 if (
const gsNurbs<T> * g =
608 dynamic_cast<const gsNurbs<T> *
>( ptr ) )
609 return gsXml< gsNurbs<T> >::put(*g,data);
611 if (
const gsTensorBSpline<2,T> * g =
612 dynamic_cast<const gsTensorBSpline<2,T> *
>( ptr ) )
613 return gsXml< gsTensorBSpline<2,T> >::put(*g,data);
615 if (
const gsTensorBSpline<3,T> * g =
616 dynamic_cast<const gsTensorBSpline<3,T> *
>( ptr ) )
617 return gsXml< gsTensorBSpline<3,T> >::put(*g,data);
619 if (
const gsTensorBSpline<4,T> * g =
620 dynamic_cast<const gsTensorBSpline<4,T> *
>( ptr ) )
621 return gsXml< gsTensorBSpline<4,T> >::put(*g,data);
623 if (
const gsTensorNurbs<2,T> * g =
624 dynamic_cast<const gsTensorNurbs<2,T> *
>( ptr ) )
625 return gsXml< gsTensorNurbs<2,T> >::put(*g,data);
627 if (
const gsTensorNurbs<3,T> * g =
628 dynamic_cast<const gsTensorNurbs<3,T> *
>( ptr ) )
629 return gsXml< gsTensorNurbs<3,T> >::put(*g,data);
631 if (
const gsTensorNurbs<4,T> * g =
632 dynamic_cast<const gsTensorNurbs<4,T> *
>( ptr ) )
633 return gsXml< gsTensorNurbs<4,T> >::put(*g,data);
635 if (
const gsTHBSpline<1,T> * g =
636 dynamic_cast<const gsTHBSpline<1,T> *
>( ptr ) )
637 return gsXml< gsTHBSpline<1,T> >::put(*g,data);
639 if (
const gsTHBSpline<2,T> * g =
640 dynamic_cast<const gsTHBSpline<2,T> *
>( ptr ) )
641 return gsXml< gsTHBSpline<2,T> >::put(*g,data);
643 if (
const gsTHBSpline<3,T> * g =
644 dynamic_cast<const gsTHBSpline<3,T> *
>( ptr ) )
645 return gsXml< gsTHBSpline<3,T> >::put(*g,data);
647 if (
const gsTrimSurface<T> * g =
648 dynamic_cast<const gsTrimSurface<T> *
>( ptr ) )
649 return gsXml< gsTrimSurface<T> >::put(*g,data);
651 if (
const gsHBSpline<1,T> * g =
652 dynamic_cast<const gsHBSpline<1,T> *
>( ptr ) )
653 return gsXml< gsHBSpline<1,T> >::put(*g,data);
655 if (
const gsHBSpline<2,T> * g =
656 dynamic_cast<const gsHBSpline<2,T> *
>( ptr ) )
657 return gsXml< gsHBSpline<2,T> >::put(*g,data);
659 if (
const gsHBSpline<3,T> * g =
660 dynamic_cast<const gsHBSpline<3,T> *
>( ptr ) )
661 return gsXml< gsHBSpline<3,T> >::put(*g,data);
667 gsWarn<<
"gsXmlUtils: put Geometry: No known object "<< obj <<
"Error.\n";
676 class gsXml< gsCurve<T> >
681 GSXML_COMMON_FUNCTIONS(gsCurve<T>);
682 static std::string tag () {
return "Geometry"; }
683 static std::string type () {
return ""; }
685 static gsCurve<T> *
get (gsXmlNode * node)
688 "Something went wrong, was waiting for a Geometry tag.\n" );
690 gsXmlAttribute * gtype = node->first_attribute(
"type");
693 gsWarn<<
"Geometry without a type in the xml file\n";
696 std::string s = gtype->value() ;
698 if ( s ==
"BSpline" )
699 return gsXml< gsBSpline<T> >::get(node);
701 return gsXml< gsNurbs<T> >::get(node);
703 gsWarn<<
"gsXmlUtils: getCurve: No known curve \""<<s<<
"\". Error.\n";
708 static gsXmlNode * put (
const gsCurve<T> & obj,
711 const gsGeometry<T> * ptr = & obj;
713 if (
const gsBSpline<T> * g =
714 dynamic_cast<const gsBSpline<T> *
>( ptr ) )
715 return gsXml< gsBSpline<T> >::put(*g,data);
717 if (
const gsNurbs<T> * g =
718 dynamic_cast<const gsNurbs<T> *
>( ptr ) )
719 return gsXml< gsNurbs<T> >::put(*g,data);
721 if (
const gsHBSpline<1,T> * g =
722 dynamic_cast<const gsHBSpline<1,T> *
>( ptr ) )
723 return gsXml< gsHBSpline<1,T> >::put(*g,data);
725 gsWarn<<
"gsXmlUtils: put Curve: No known object "<< obj <<
"Error.\n";
733 class gsXml< gsSurface<T> >
738 GSXML_COMMON_FUNCTIONS(gsSurface<T>);
739 static std::string tag () {
return "Geometry"; }
740 static std::string type () {
return ""; }
742 static gsSurface<T> *
get (gsXmlNode * node)
745 "Something went wrong, was waiting for a Geometry tag.\n" );
747 gsXmlAttribute * gtype = node->first_attribute(
"type");
750 gsWarn<<
"Geometry without a type in the xml file\n";
753 std::string s = gtype->value() ;
755 if ( s ==
"HBSpline2" )
756 return gsXml< gsHBSpline<2,T> >::get(node);
757 if ( s ==
"THBSpline2" )
758 return gsXml< gsTHBSpline<2,T> >::get(node);
760 if ( s ==
"TensorBSpline2" )
761 return gsXml< gsTensorBSpline<2,T> >::get(node);
762 if ( s ==
"TensorNurbs2" )
763 return gsXml< gsTensorNurbs<2,T> >::get(node);
765 gsWarn<<
"gsXmlUtils: getSurface: No known surface \""<<s<<
"\". Error.\n";
769 static gsXmlNode * put (
const gsSurface<T> & obj,
772 const gsGeometry<T> * ptr = & obj;
774 if (
const gsTensorBSpline<2,T> * g =
775 dynamic_cast<const gsTensorBSpline<2,T> *
>( ptr ) )
776 return gsXml< gsTensorBSpline<2,T> >::put(*g,data);
778 if (
const gsTensorNurbs<2,T> * g =
779 dynamic_cast<const gsTensorNurbs<2,T> *
>( ptr ) )
780 return gsXml< gsTensorNurbs<2,T> >::put(*g,data);
782 if (
const gsTHBSpline<2,T> * g =
783 dynamic_cast<const gsTHBSpline<2,T> *
>( ptr ) )
784 return gsXml< gsTHBSpline<2,T> >::put(*g,data);
786 if (
const gsHBSpline<2,T> * g =
787 dynamic_cast<const gsHBSpline<2,T> *
>( ptr ) )
788 return gsXml< gsHBSpline<2,T> >::put(*g,data);
790 gsWarn<<
"gsXmlUtils: put Geometry: No known object "<< obj <<
"Error.\n";
797 class gsXml< gsBasis<T> >
802 GSXML_COMMON_FUNCTIONS(gsBasis<T>);
803 static std::string tag () {
return "Basis"; }
804 static std::string type () {
return ""; }
806 static gsBasis<T> *
get (gsXmlNode * node)
808 GISMO_ASSERT( ( !strcmp( node->name(),
"Basis") ),
"Something went wrong, waiting for a basis." );
810 gsXmlAttribute * btype = node->first_attribute(
"type");
813 gsWarn<<
"Basis without a type in the xml file.\n";
816 std::string s = btype->value() ;
818 if ( s ==
"BSplineBasis" )
819 return gsXml< gsBSplineBasis<T> >::get(node);
820 if ( s ==
"NurbsBasis" )
821 return gsXml< gsNurbsBasis<T> >::get(node);
823 if ( s ==
"HBSplineBasis" )
824 return gsXml< gsHBSplineBasis<1,T> >::get(node);
825 if ( s ==
"HBSplineBasis2" )
826 return gsXml< gsHBSplineBasis<2,T> >::get(node);
827 if ( s ==
"HBSplineBasis3" )
828 return gsXml< gsHBSplineBasis<3,T> >::get(node);
829 if ( s ==
"HBSplineBasis4" )
830 return gsXml< gsHBSplineBasis<4,T> >::get(node);
832 if ( s ==
"THBSplineBasis" )
833 return gsXml< gsTHBSplineBasis<1,T> >::get(node);
834 if ( s ==
"THBSplineBasis2" )
835 return gsXml< gsTHBSplineBasis<2,T> >::get(node);
836 if ( s ==
"THBSplineBasis3" )
837 return gsXml< gsTHBSplineBasis<3,T> >::get(node);
838 if ( s ==
"THBSplineBasis4" )
839 return gsXml< gsTHBSplineBasis<4,T> >::get(node);
844 if ( s ==
"TensorBSplineBasis2" )
845 return gsXml< gsTensorBSplineBasis<2, T> >::get(node);
846 if ( s ==
"TensorBSplineBasis3" )
847 return gsXml< gsTensorBSplineBasis<3, T> >::get(node);
848 if ( s ==
"TensorBSplineBasis4" )
849 return gsXml< gsTensorBSplineBasis<4, T> >::get(node);
851 if ( s ==
"TensorNurbsBasis2" )
852 return gsXml< gsTensorNurbsBasis<2, T> >::get(node);
853 if ( s ==
"TensorNurbsBasis3" )
854 return gsXml< gsTensorNurbsBasis<3, T> >::get(node);
855 if ( s ==
"TensorNurbsBasis4" )
856 return gsXml< gsTensorNurbsBasis<4, T> >::get(node);
858 gsWarn<<
"gsXmlUtils: getBasis: No known basis \""<<s<<
"\". Error.\n";
862 static gsXmlNode * put (
const gsBasis<T> & obj,
865 const gsBasis<T> * ptr = & obj;
867 if (
const gsBSplineBasis<T> * g =
868 dynamic_cast<const gsBSplineBasis<T> *
>( ptr ) )
869 return gsXml< gsBSplineBasis<T> >::put(*g,data);
871 if (
const gsNurbsBasis<T> * g =
872 dynamic_cast<const gsNurbsBasis<T> *
>( ptr ) )
873 return gsXml< gsNurbsBasis<T> >::put(*g,data);
876 if (
const gsTensorBSplineBasis<2, T> * g =
877 dynamic_cast<const gsTensorBSplineBasis<2, T> *
>( ptr ) )
878 return gsXml< gsTensorBSplineBasis<2, T> >::put(*g,data);
880 if (
const gsTensorBSplineBasis<3, T> * g =
881 dynamic_cast<const gsTensorBSplineBasis<3, T> *
>( ptr ) )
882 return gsXml< gsTensorBSplineBasis<3, T> >::put(*g,data);
884 if (
const gsTensorBSplineBasis<4, T> * g =
885 dynamic_cast<const gsTensorBSplineBasis<4, T> *
>( ptr ) )
886 return gsXml< gsTensorBSplineBasis<4, T> >::put(*g,data);
889 if (
const gsTensorNurbsBasis<2, T> * g =
890 dynamic_cast<const gsTensorNurbsBasis<2, T> *
>( ptr ) )
891 return gsXml< gsTensorNurbsBasis<2, T> >::put(*g,data);
893 if (
const gsTensorNurbsBasis<3, T> * g =
894 dynamic_cast<const gsTensorNurbsBasis<3, T> *
>( ptr ) )
895 return gsXml< gsTensorNurbsBasis<3, T> >::put(*g,data);
897 if (
const gsTensorNurbsBasis<4, T> * g =
898 dynamic_cast<const gsTensorNurbsBasis<4, T> *
>( ptr ) )
899 return gsXml< gsTensorNurbsBasis<4, T> >::put(*g,data);
903 if (
const gsHTensorBasis<1,T> * g =
904 dynamic_cast<const gsHTensorBasis<1,T> *
>( ptr ) )
905 return gsXml< gsHTensorBasis<1,T> >::put(*g,data);
907 if (
const gsHTensorBasis<2,T> * g =
908 dynamic_cast<const gsHTensorBasis<2,T> *
>( ptr ) )
909 return gsXml< gsHTensorBasis<2,T> >::put(*g,data);
911 if (
const gsHTensorBasis<3,T> * g =
912 dynamic_cast<const gsHTensorBasis<3,T> *
>( ptr ) )
913 return gsXml< gsHTensorBasis<3,T> >::put(*g,data);
915 if (
const gsHTensorBasis<4,T> * g =
916 dynamic_cast<const gsHTensorBasis<4,T> *
>( ptr ) )
917 return gsXml< gsHTensorBasis<4,T> >::put(*g,data);
919 if (
const gsTHBSplineBasis<3,T> * g =
920 dynamic_cast<const gsTHBSplineBasis<3,T> *
>( ptr ) )
921 return gsXml< gsTHBSplineBasis<3,T> >::put(*g,data);
927 gsWarn<<
"gsXmlUtils put: getBasis: No known basis \""<<obj<<
"\". Error.\n";
934 class gsXml< gsPde<T> >
939 GSXML_COMMON_FUNCTIONS(gsPde<T>);
940 static std::string tag () {
return "Pde"; }
941 static std::string type () {
return ""; }
943 static gsPde<T> *
get (gsXmlNode * node)
946 "Something went wrong. Expected Pde tag." );
948 std::string s = node->first_attribute(
"type")->value() ;
949 if ( s ==
"PoissonPde" )
950 return gsXml< gsPoissonPde<T> >::get(node);
951 if ( s ==
"SurfacePoissonPde" )
952 return gsXml< gsSurfacePoissonPde<T> >::get(node);
954 gsWarn<<
"gsXmlUtils: getPde: No known Pde \""<<s<<
"\". Error.\n";
958 static gsXmlNode * put (
const gsPde<T> &,
968 class gsXml< gsMultiPatch<T> >
972 typedef gsMultiPatch<T> Object;
975 GSXML_COMMON_FUNCTIONS(Object);
976 static std::string tag () {
return "MultiPatch"; }
977 static std::string type () {
return ""; }
979 GSXML_GET_POINTER(Object);
981 static void get_into (gsXmlNode * node, Object & obj)
984 "Something went wrong. Expected Multipatch tag." );
987 gsXmlNode * toplevel = node->parent();
989 const int d = atoi( node->first_attribute(
"parDim")->value() );
991 gsXmlNode * tmp = node->first_node(
"patches");
992 std::istringstream str ;
993 str.str( tmp->value() );
995 std::vector< gsGeometry<T> *> patches;
996 std::map<int,int> ids;
997 if ( ! strcmp( tmp->first_attribute(
"type")->value(),
"id_range") )
1000 gsGetInt(str, first);
1001 gsGetInt(str, last);
1002 for (
int i = first; i<=last; ++i )
1005 "No Geometry with Id "<<i<<
" found in the XML data.");
1006 patches.push_back(
getById< gsGeometry<T> >( toplevel, i ) );
1007 patches.back()->setId(i);
1011 else if ( ! strcmp( tmp->first_attribute(
"type")->value(),
"id_index") )
1014 for (
int pindex; gsGetInt(str, pindex);)
1017 "No Geometry with Id "<<pindex<<
" found in the XML data.");
1018 patches.push_back(
getById< gsGeometry<T> >( toplevel, pindex ) );
1019 patches.back()->setId(pindex);
1025 gsWarn<<
"Unknown tag in XML multipatch object.\n";
1035 std::vector< patchSide > boundaries;
1036 for (gsXmlNode * child = node->first_node(
"boundary"); child;
1037 child = child->next_sibling(
"boundary"))
1039 std::vector< patchSide > tmp_boundaries;
1042 getBoundaries(child, ids, tmp_boundaries);
1043 boundaries.insert( boundaries.end(), tmp_boundaries.begin(), tmp_boundaries.end() );
1047 std::sort(boundaries.begin(), boundaries.end());
1048 boundaries.erase(std::unique(boundaries.begin(), boundaries.end()), boundaries.end());
1051 std::vector< boundaryInterface > interfaces;
1052 for (gsXmlNode * child = node->first_node(
"interfaces"); child;
1053 child = child->next_sibling(
"interfaces"))
1055 std::vector< boundaryInterface > tmp_interfaces;
1058 getInterfaces(child, d, ids, tmp_interfaces);
1059 interfaces.insert( interfaces.end(), tmp_interfaces.begin(), tmp_interfaces.end() );
1063 std::sort(interfaces.begin(), interfaces.end());
1064 interfaces.erase(std::unique(interfaces.begin(), interfaces.end()), interfaces.end());
1067 obj = gsMultiPatch<T>(patches, boundaries, interfaces);
1070 static gsXmlNode * put (
const gsMultiPatch<T> & obj,
1074 int max_id = data.maxId();
1076 for (
typename gsMultiPatch<T>::const_iterator it = obj.begin();
1077 it != obj.end(); ++it )
1079 tmp = gsXml<gsGeometry<T> >::put(**it,data);
1080 data.appendToRoot(tmp);
1083 std::ostringstream str;
1084 str<< max_id+1 <<
" "<< data.maxId();
1087 str.clear(); str.str(
"");
1092 mp_node->append_node(tmp);
1096 if (obj.numBoxProperties()!=0)
1097 gsWarn<<
"Multi-patch object has box properties that are not written to XML\n";
1106 class gsXml< gsMultiBasis<T> >
1110 typedef gsMultiBasis<T> Object;
1113 GSXML_COMMON_FUNCTIONS(Object);
1114 GSXML_GET_POINTER(Object);
1115 static std::string tag() {
return "MultiBasis"; }
1116 static std::string type() {
return ""; }
1118 static void get_into(gsXmlNode* node, Object & result)
1121 "Something went wrong. Expected MultiBasis tag." );
1123 gsXmlNode* topLevel = node->parent();
1125 const int d = atoi( node->first_attribute(
"parDim")->value() );
1127 gsXmlNode* patchNode = node->first_node(
"patches");
1128 std::istringstream iss;
1129 iss.str( patchNode->value() );
1131 typename gsMultiBasis<T>::BasisContainer bases;
1132 std::map<int, int> ids;
1133 if ( !strcmp( patchNode->first_attribute(
"type")->value(),
"id_range") )
1136 gsGetInt(iss, first);
1137 gsGetInt(iss, last);
1138 for (
int i = first; i <= last; ++i)
1140 bases.push_back(
getById< gsBasis<T> >( topLevel, i ) );
1144 else if ( !strcmp( patchNode->first_attribute(
"type")->value(),
"id_index") )
1147 for (
int pindex; gsGetInt(iss, pindex); )
1149 bases.push_back(
getById< gsBasis<T> >( topLevel, pindex ) );
1155 gsWarn <<
"unknown tag in XML multipatch object \n";
1159 std::vector< patchSide > boundaries;
1160 gsXmlNode * tmp = node->first_node(
"boundary");
1162 getBoundaries(tmp, ids, boundaries);
1165 std::vector< boundaryInterface > interfaces;
1166 tmp = node->first_node(
"interfaces");
1168 getInterfaces(tmp, d, ids, interfaces);
1170 gsBoxTopology topology( d, bases.size(), boundaries, interfaces);
1172 result = gsMultiBasis<T>(bases, topology);
1176 static gsXmlNode* put(
const gsMultiBasis<T>& obj,
1180 int max_id = data.maxId();
1181 for (
typename gsMultiBasis<T>::const_iterator it = obj.begin();
1182 it != obj.end(); ++it )
1184 gsXmlNode* basisXml = gsXml< gsBasis<T> >::put(**it, data);
1185 data.appendToRoot( basisXml );
1188 std::ostringstream oss;
1189 oss<< max_id+1 <<
" "<< data.maxId();
1197 mbNode->append_node(node);
1209 class gsXml< gsPlanarDomain<T> >
1214 GSXML_COMMON_FUNCTIONS(gsPlanarDomain<T>);
1215 static std::string tag () {
return "PlanarDomain"; }
1216 static std::string type () {
return ""; }
1218 static gsPlanarDomain<T> *
get (gsXmlNode * node)
1221 "Something went wrong. Expected PlanarDomain tag." );
1223 std::vector<gsCurveLoop<T>*> loops;
1224 for (gsXmlNode * tmp = node->first_node(
"CurveLoop");
1225 tmp; tmp = tmp->next_sibling(
"CurveLoop"))
1226 loops.push_back( gsXml<gsCurveLoop<T> >::
get(tmp) ) ;
1228 return new gsPlanarDomain<T>( loops );
1231 static gsXmlNode * put (
const gsPlanarDomain<T> & obj,
1238 int nl = obj.numLoops();
1240 for (
int i=0; i!=nl; ++i)
1242 tmp = internal::gsXml< gsCurveLoop<T> >::put(obj.loop(i), data );
1244 pl->append_node(tmp);
1252 class gsXml< gsCurveLoop<T> >
1257 GSXML_COMMON_FUNCTIONS(gsCurveLoop<T>);
1258 static std::string tag () {
return "CurveLoop"; }
1259 static std::string type () {
return ""; }
1261 static gsCurveLoop<T> *
get (gsXmlNode * node)
1264 "Something went wrong. Expected CurveLoop tag." );
1266 std::vector<gsCurve<T>* > curves;
1268 for (gsXmlNode * tmp = node->first_node(
"Geometry");
1269 tmp; tmp = tmp->next_sibling(
"Geometry"))
1270 curves.push_back( gsXml<gsCurve<T> >::
get(tmp) ) ;
1272 return new gsCurveLoop<T>( curves );
1275 static gsXmlNode * put (
const gsCurveLoop<T> & obj,
1282 int nc = obj.numCurves();
1284 for (
int i=0; i!=nc; ++i)
1286 tmp = internal::gsXml< gsGeometry<T> >::put(obj.curve(i), data );
1288 cl->append_node(tmp);
1297 class gsXml< gsCurveFitting<T> >
1302 GSXML_COMMON_FUNCTIONS(gsCurveFitting<T>);
1303 static std::string tag () {
return "CurveFitting"; }
1304 static std::string type() {
return ""; }
1306 static gsCurveFitting<T> *
get (gsXmlNode * node)
1309 "Something went wrong. Expected CurveFitting tag." );
1311 bool closed = (atoi(node->first_attribute(
"closed")->value() ) != 0);
1314 gsXmlNode * tmp = node->first_node(
"KnotVector");
1315 gsKnotVector<T> * kv = gsXml< gsKnotVector<T> >::get(tmp);
1318 tmp = node->first_node(
"Matrix");
1319 gsMatrix<T> * parval = gsXml< gsMatrix<T> >::get(tmp);
1322 tmp = tmp->next_sibling(
"Matrix");
1323 gsMatrix<T> * pts = gsXml< gsMatrix<T> >::get(tmp);
1325 gsCurveFitting<T> * cf =
new gsCurveFitting<T>(*parval,*pts,*kv,closed);
1332 static gsXmlNode * put (
const gsCurveFitting<T> &,
1342 class gsXml< gsPoissonPde<T> >
1347 GSXML_COMMON_FUNCTIONS(gsPoissonPde<T>);
1348 static std::string tag () {
return "Pde"; }
1349 static std::string type () {
return "PoissonPde"; }
1351 static gsPoissonPde<T> *
get (gsXmlNode * node)
1353 assert( ( !strcmp( node->name(),
"Pde") ) &&
1355 strcmp( node->first_attribute(
"type")->value(),
"PoissonPde")
1356 && strcmp( node->first_attribute(
"type")->value(),
"SurfacePoissonPde")
1360 GISMO_ASSERT( node->first_attribute(
"dim"),
"xml reader: No dim found" ) ;
1361 short_t d = atoi( node->first_attribute(
"dim")->value() );
1365 gsXmlAttribute * targetDim = node->first_attribute(
"targetDim");
1368 tDim = atoi( targetDim->value() );
1372 gsXmlNode * tmp = node->first_node(
"rhs");
1373 gsFunctionExpr<T> rhs_fnct;
1374 internal::gsXml<gsFunctionExpr<T> >::get_into(tmp, rhs_fnct);
1376 tmp = node->first_node(
"solution");
1379 gsFunctionExpr<T> msol;
1380 internal::gsXml<gsFunctionExpr<T> >::get_into(tmp, msol);
1382 return new gsPoissonPde<T>(rhs_fnct, d, msol );
1386 return new gsPoissonPde<T>( rhs_fnct, d );
1391 gsXmlNode * tmp = node->first_node(
"rhs");
1392 gsFunctionExpr<T> rhs(tmp->value(), d);
1395 tmp = node->first_node(
"solution");
1398 gsFunctionExpr<T> sol(tmp->value(), d);
1400 return new gsPoissonPde<T>(rhs, d, sol );
1404 return new gsPoissonPde<T>( rhs, d );
1408 static gsXmlNode * put (
const gsPoissonPde<T> &,
Represents a NURBS basis with one parameter.
Provides declaration of FunctionExpr class.
Represents a NURBS curve/function with one parameter.
#define short_t
Definition: gsConfig.h:35
Provides structs and classes related to interfaces and boundaries.
Object * getById(gsXmlNode *node, const int &id)
Definition: gsXml.h:291
Provides declaration of MultiBasis class.
Provides interface of gsTrimSurface class. Represents a trimmed surface (= spline "master surface" in...
Provides declaration of THBSplineBasis class.
Provides declaration of Basis abstract interface.
#define index_t
Definition: gsConfig.h:32
Represents a tensor-product NURBS patch.
gsXmlNode * searchId(const int id, gsXmlNode *root, const char *tag_name=NULL, const bool print_warning=true)
Definition: gsXml.h:254
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
gsXmlNode * putGeometryToXml(Object const &obj, gsXmlTree &data)
Helper to put geometries to XML.
Definition: gsXmlGenericUtils.hpp:388
Provides implementation of generic XML functions.
Provides declaration of THBSplineBasis class.
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition: gsXml.cpp:74
#define gsWarn
Definition: gsDebug.h:50
gsXmlNode * putSparseMatrixToXml(gsSparseMatrix< T > const &mat, gsXmlTree &data, std::string name="SparseMatrix")
Helper to insert sparse matrices into XML.
Definition: gsXml.hpp:111
Provides declaration of the MultiPatch class.
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
Fits a (closed) B-spline curve to some given data.
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54
Provides declaration of the Mesh class.
gsXmlNode * putMatrixToXml(gsMatrix< T > const &mat, gsXmlTree &data, std::string name="Matrix")
Helper to insert matrices into XML.
Definition: gsXml.hpp:103
Provides declaration of RationalBasis class.
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
This is the main header file that collects wrappers of Eigen for linear algebra.
void appendBoxTopology(const gsBoxTopology &topology, gsXmlNode *node, gsXmlTree &data)
Appends a box topology into node, used for gsMultiPatch and gsMultiBasis.
Definition: gsXml.cpp:186
Provides declaration of gsPlanarDomain class. The outer boundary (m_loops[0]) is a loop of curves...
Provides declaration of gsSolid class, a boundary-represented solid.