22 template<
class Object>
23 Object * getTensorBasisFromXml ( gsXmlNode * node)
27 GISMO_ASSERT( !strcmp( node->name(),
"Basis"),
"Invalid tag when \"Basis\" was expected.");
30 std::vector<typename Object::CoordinateBasis* > bb;
33 if ( !strcmp(node->first_attribute(
"type")->value(),
34 gsXml<typename Object::CoordinateBasis>::type().c_str() ) )
36 bb.push_back( gsXml<typename Object::CoordinateBasis>::get(node) );
37 return Object::New( bb );
40 const unsigned d = Object::Dim;
41 gsXmlNode * tmp = node->first_node(
"Basis");
44 for (
unsigned i = 0; i!=d; ++i)
46 bb.push_back( gsXml<typename Object::CoordinateBasis>::get(tmp) );
47 tmp = tmp->next_sibling(
"Basis");
53 bb.push_back( gsXml<typename Object::CoordinateBasis>::get(node) );
57 return Object::New( bb );
60 template<
class Object>
61 gsXmlNode * putTensorBasisToXml ( Object
const & obj, gsXmlTree & data)
64 static const unsigned d = Object::Dim;
66 return gsXml<typename Object::CoordinateBasis>::put(obj.component(0), data);
71 internal::gsXml<Object>::type().c_str(), data) );
73 for (
unsigned i = 0; i!=d; ++i )
76 internal::gsXml< typename Object::CoordinateBasis >::put(obj.component(i), data );
78 tp_node->append_node(tmp);
85 template<
class Object>
86 Object * getRationalBasisFromXml ( gsXmlNode * node)
89 && ( !strcmp(node->first_attribute(
"type")->value(),
90 internal::gsXml<Object>::type().c_str() ) ),
91 "Something is wrong with the XML data: There should be a node with a "
92 <<internal::gsXml<Object>::type().c_str()<<
" Basis.");
95 gsXmlNode * tmp = node->first_node(
"Basis");
96 typename Object::SourceBasis * src = gsXml<typename Object::SourceBasis>::get(tmp) ;
99 tmp = node->first_node(
"weights");
100 gsMatrix<typename Object::Scalar_t> weights;
101 gsXmlAttribute* format = tmp->first_attribute(
"format");
102 std::string format_flag = format ? format->value() :
"ascii";
103 getMatrixFromXml<typename Object::Scalar_t>(tmp, src->size(), 1, weights,
105 return new Object(src,
give(weights));
108 template<
class Object>
109 Object * getHTensorBasisFromXml ( gsXmlNode * node)
112 && ( !strcmp(node->first_attribute(
"type")->value(),
113 internal::gsXml<Object>::type().c_str() ) ),
114 "Something is wrong with the XML data: There should be a node with a "<<
115 internal::gsXml<Object>::type().c_str()<<
" Basis.");
117 typedef typename Object::Scalar_t T;
118 static const int d = Object::Dim;
122 gsXmlNode * tmp = node->first_node(
"Basis");
126 gsTensorBSplineBasis<d,T> * tp =
127 gsXml<gsTensorBSplineBasis<d,T> >::get(tmp);
130 std::istringstream str;
134 std::vector<index_t> all_boxes;
135 for (tmp = node->first_node(
"box");
136 tmp; tmp = tmp->next_sibling(
"box"))
138 all_boxes.push_back(atoi( tmp->first_attribute(
"level")->value() ));
140 str.str( tmp->value() );
141 for(
unsigned i = 0; i < 2*d; i++)
144 all_boxes.push_back(c);
148 gsXmlAttribute * manualLevels = node->first_attribute(
"manualLevels");
149 bool ml = manualLevels && !strcmp(manualLevels->value(),
"true");
150 Object * hbs =
new Object(*tp, ml);
156 const gsXmlAttribute * id_at;
157 for (gsXmlNode * child = node->first_node(
"Basis");
158 child; child = child->next_sibling(
"Basis"))
160 id_at = child->first_attribute(
"level");
161 if (id_at && atoi(id_at->value()) == lvl )
165 internal::gsXml<gsTensorBSplineBasis<d,T> >::
get(child) );
166 hbs->addLevel(
give(*tb) );
171 hbs->refineElements(all_boxes);
175 template<
class Object>
176 gsXmlNode * putHTensorBasisToXml ( Object
const & obj, gsXmlTree & data)
179 const int d = obj.dim();
185 internal::gsXml<Object>::type().c_str(), data) );
190 if (obj.manualLevels())
192 tp_node->append_attribute(
makeAttribute(
"manualLevels",
"true", data) );
193 for (
index_t l = 0; l != obj.numLevels(); l++)
195 tmp = putTensorBasisToXml(obj.tensorLevel(l), data);
197 tp_node->append_node(tmp);
202 tp_node->append_attribute(
makeAttribute(
"manualLevels",
"false", data) );
204 tmp = putTensorBasisToXml(obj.tensorLevel(0), data);
205 tp_node->append_node(tmp);
210 gsMatrix<index_t> box(1,2*d);
212 for(
typename Object::hdomain_type::const_literator lIter =
213 obj.tree().beginLeafIterator(); lIter.good() ; lIter.next() )
215 if ( lIter->level > 0 )
217 box.leftCols(d) = lIter.lowerCorner().transpose();
218 box.rightCols(d) = lIter.upperCorner().transpose();
223 tp_node->append_node(tmp);
247 template<
class Object>
248 gsXmlNode * putRationalBasisToXml ( Object
const & obj, gsXmlTree & data)
253 internal::gsXml< Object >::type().c_str(), data) );
257 internal::gsXml< typename Object::SourceBasis >::put(obj.source(), data );
258 rat_node->append_node(tmp);
262 rat_node->append_node(tmp);
307 template<
class Object>
311 assert ( ( !strcmp( node->name(),
"Geometry") ) &&
312 ( !strcmp(node->first_attribute(
"type")->value(), gsXml<Object>::type().c_str() ) ) );
314 gsXmlNode * tmp = node->first_node(
"Basis");
317 typename Object::Basis::Ptr b( gsXml<typename Object::Basis>::get(tmp) );
321 tmp = node->first_node(
"coefs");
322 GISMO_ASSERT( tmp,
"Did not find any coefficients for "<< gsXml<Object>::type().c_str() );
323 gsXmlAttribute * at_geodim = tmp->first_attribute(
"geoDim");
324 GISMO_ASSERT( at_geodim ,
"geoDim attribute not found in Geometry XML tag");
325 unsigned geoDim = atoi(at_geodim->value() ) ;
331 gsXmlAttribute* format = tmp->first_attribute(
"format");
332 std::string format_flag = format ? format->value() :
"ascii";
333 getMatrixFromXml<typename Object::Scalar_t>(
334 tmp, b->size(), geoDim, coefficient_matrix, format_flag);
337 gsXmlAttribute* coef_order = tmp->first_attribute(
"order");
338 if (
nullptr != coef_order)
339 if (!strcmp(coef_order->value(),
"coordinates")) {
340 coefficient_matrix.transposeInPlace();
341 coefficient_matrix.resize(b->size(), geoDim);
345 tmp = node->first_node(
"transform");
349 for (gsXmlNode * tr = tmp->first_node();
350 tr; tr= tr->next_sibling() )
352 std::string val( tr->name() );
354 if (val ==
"translation")
356 getMatrixFromXml<typename Object::Scalar_t>(tmp, 3, 1 ,a);
359 if (val ==
"rotation" )
361 getMatrixFromXml<typename Object::Scalar_t>(tmp, 4, 1, a);
362 gsEigen::Transform<typename Object::Scalar_t,3,gsEigen::Affine>
363 rot( gsEigen::AngleAxis<typename Object::Scalar_t>
364 ( a(3,0), a.template block<3,1>(0,0).normalized() ) );
365 coefficient_matrix = (coefficient_matrix. rowwise().homogeneous() *
366 rot.matrix().transpose() ).leftCols(3) ;
375 gsWarn<<
"Unidentified transform tag in XML.\n";
380 Object * result =
new Object(*b, coefficient_matrix);
387 template<
class Object>
393 internal::gsXml<Object>::type().c_str(), data) );
397 internal::gsXml< typename Object::Basis >::put(obj.basis(), data);
400 gsWarn<<
"XML Warning: Writing basis failed.\n";
404 bs->append_node(tmp);
408 tmp->append_attribute(
makeAttribute(
"geoDim", obj.geoDim(), data) );
409 bs->append_node(tmp);
414 gsXmlNode * putFunctionExprToXml(
const gsFunctionExpr<T> & obj, gsXmlNode * result, gsXmlTree & data)
416 std::string typeStr = gsXml<gsFunctionExpr<T> >::type();
418 result->append_attribute(type);
421 result->append_attribute(dim);
426 result->value(
makeValue(obj.expression(), data) );
431 for (
short_t c = 0; c!=tdim; ++c)
433 cnode =
makeNode(
"c", obj.expression(c), data);
434 result->append_node(cnode);
441 gsXmlNode * putConstantFunctionToXml(
const gsConstantFunction<T> & obj,gsXmlNode * result, gsXmlTree & data)
443 std::string typeStr =
"FunctionExpr";
445 result->append_attribute(type);
448 result->append_attribute(dim);
451 gsMatrix<T> value = obj.value();
452 result->value(
makeValue( value, data,
true) );
457 gsXmlNode * putFunctionToXml (
const typename gsFunctionSet<T>::Ptr & obj, gsXmlTree & data,
int index)
460 if (
typeid(*obj) ==
typeid(gsFunctionExpr<T> ))
462 gsFunctionExpr<T> * ptr2 =
463 dynamic_cast<gsFunctionExpr<T> *
>(obj.get());
464 result = putFunctionExprToXml(*ptr2, result, data);
466 else if (
typeid(*obj) ==
typeid(gsConstantFunction<T> ))
468 gsConstantFunction<T> * ptr2 =
469 dynamic_cast<gsConstantFunction<T> *
>(obj.get());
470 result = putConstantFunctionToXml(*ptr2, result, data);
474 result->append_attribute(indexNode);
unique_ptr< T > make_unique(T *x)
Definition: gsMemory.h:198
short_t targetDim() const
Dimension of the target space.
Definition: gsFunctionExpr.hpp:474
#define short_t
Definition: gsConfig.h:35
Provides declaration of ConstantFunction class.
S give(S &x)
Definition: gsMemory.h:266
Object * getGeometryFromXml(gsXmlNode *node)
Helper to fetch geometries.
Definition: gsXmlGenericUtils.hpp:308
#define index_t
Definition: gsConfig.h:32
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition: gsMatrix.h:38
#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
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition: gsXml.cpp:74
#define gsWarn
Definition: gsDebug.h:50
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsFunctionExpr.hpp:468
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54
char * makeValue(const std::string &value, gsXmlTree &data)
Helper to allocate XML value.
Definition: gsXml.cpp:32
gsXmlNode * putMatrixToXml(gsMatrix< T > const &mat, gsXmlTree &data, std::string name="Matrix")
Helper to insert matrices into XML.
Definition: gsXml.hpp:103
Class defining a multivariate (real or vector) function given by a string mathematical expression...
Definition: gsFunctionExpr.h:51