8#include <kernel/geometry/atlas/chart.hpp>
10#include <kernel/geometry/atlas/bezier.hpp>
11#include <kernel/geometry/atlas/circle.hpp>
19 template<
typename SubChart_>
32 template<
typename Mesh_,
typename SubChart_>
34 public ChartCRTP<Extrude<Mesh_, SubChart_>, Mesh_, ExtrudeTraits<SubChart_>>
46 typedef typename SubChart_::WorldPoint SubWorldPoint;
47 typedef typename SubChart_::ParamPoint SubParamPoint;
70 explicit Extrude(std::unique_ptr<SubChart_> sub_chart) :
100 void set_sub_chart(std::unique_ptr<SubChart_> sub_chart)
141 void transform_3d_to_2d(
const WorldPoint& p, SubWorldPoint& q)
const
144 transform_3d_to_2d(p, q, z);
150 Tiny::Matrix<CoordType, 3, 3> rotation;
151 rotation.set_rotation_3d(angles[0], angles[1], angles[2]);
179 Tiny::Matrix<CoordType, 3, 3> old_rot(
_rotation);
188 SubWorldPoint sub_point;
190 transform_3d_to_2d(point, sub_point, z);
194 transform_2d_to_3d(point, sub_point, z);
197 void project_meshpart(Mesh_& mesh,
const MeshPart<Mesh_>& meshpart)
const
199 auto& vtx = mesh.get_vertex_set();
200 const auto& target_vtx = meshpart.template get_target_set<0>();
201 for(
Index i(0); i < meshpart.get_num_entities(0); ++i)
203 project_point(
reinterpret_cast<WorldPoint&
>(vtx[target_vtx[i]]));
210 SubParamPoint sub_param;
211 sub_param[0] = param[0];
212 SubWorldPoint sub_point;
215 transform_2d_to_3d(point, sub_point, param[1]);
222 SubWorldPoint sub_point;
223 transform_3d_to_2d(point, sub_point);
231 SubWorldPoint sub_point;
233 transform_3d_to_2d(point, sub_point, z);
235 SubWorldPoint sub_grad_dist;
242 transform_2d_to_3d(grad_dist, sub_grad_dist, z);
251 SubWorldPoint sub_point;
252 transform_3d_to_2d(point, sub_point);
253 return _sub_chart->compute_signed_dist(sub_point);
260 SubWorldPoint sub_point;
262 transform_3d_to_2d(point, sub_point, z);
264 SubWorldPoint sub_grad_dist;
269 transform_2d_to_3d(grad_dist, sub_grad_dist, z);
279 virtual void write(std::ostream& os,
const String& sindent)
const override
287 os << sindent <<
"<Extrude";
298 const CoordType pi = Math::pi<CoordType>();
320 else if(ap <= -pi_2 + tol)
335 os <<
" angles=\"" << (mult*ay) <<
" " << (mult*ap) <<
" " << (mult*ar) <<
"\"";
340 os << sindent <<
"</Extrude>\n";
344 template<
typename Mesh_,
bool enable_ = (Mesh_::shape_dim > 2)>
351 XABORTM(
"Thou shall not arrive here");
355 template<
typename Mesh_>
361 std::unique_ptr<ChartBase<Mesh_>>& _chart;
362 CoordType _ori_x, _ori_y;
363 CoordType _off_x, _off_y, _off_z;
364 CoordType _yaw, _pitch, _roll;
369 _ori_x(CoordType(0)),
370 _ori_y(CoordType(0)),
371 _off_x(CoordType(0)),
372 _off_y(CoordType(0)),
373 _off_z(CoordType(0)),
375 _pitch(CoordType(0)),
380 virtual bool attribs(std::map<String,bool>& attrs)
const override
383 attrs.emplace(
"origin",
false);
384 attrs.emplace(
"offset",
false);
385 attrs.emplace(
"angles",
false);
393 const std::map<String, String>& attrs,
398 auto it = attrs.find(
"origin");
399 if(it != attrs.end())
401 std::deque<String> sori = it->second.split_by_whitespaces();
402 if(sori.size() != std::size_t(2))
404 if(!sori.front().parse(_ori_x) || !sori.back().parse(_ori_y))
405 throw Xml::GrammarError(iline, sline,
"Failed to parse extrude origin attribute");
412 auto it = attrs.find(
"offset");
413 if(it != attrs.end())
415 std::deque<String> soff = it->second.split_by_whitespaces();
416 if(soff.size() != std::size_t(3))
418 if(!soff.at(0).parse(_off_x) || !soff.at(1).parse(_off_y) || !soff.at(2).parse(_off_z))
419 throw Xml::GrammarError(iline, sline,
"Failed to parse extrude offset attribute");
426 auto it = attrs.find(
"angles");
427 if(it != attrs.end())
429 std::deque<String> sang = it->second.split_by_whitespaces();
430 if(sang.size() != std::size_t(3))
432 if(!sang.at(0).parse(_yaw) || !sang.at(1).parse(_pitch) || !sang.at(2).parse(_roll))
433 throw Xml::GrammarError(iline, sline,
"Failed to parse extrude angles attribute");
436 const CoordType mult = CoordType(2) * Math::pi<CoordType>();
457 typedef typename Mesh_::ShapeType ShapeType;
465 ext->set_origin(_ori_x, _ori_y);
466 ext->set_offset(_off_x, _off_y, _off_z);
467 ext->set_angles(_yaw, _pitch, _roll);
468 std::unique_ptr<Circle<SubMeshType>>& sub_chart = ext->_sub_chart;
469 _chart = std::move(ext);
470 return std::make_shared<Atlas::CircleChartParser<SubMeshType, Circle<SubMeshType>>>(sub_chart);
475 ext->set_origin(_ori_x, _ori_y);
476 ext->set_offset(_off_x, _off_y, _off_z);
477 ext->set_angles(_yaw, _pitch, _roll);
478 std::unique_ptr<Bezier<SubMeshType>>& sub_chart = ext->_sub_chart;
479 _chart = std::move(ext);
480 return std::make_shared<Atlas::BezierChartParser<SubMeshType, Bezier<SubMeshType>>>(sub_chart);
#define ASSERT(expr)
Debug-Assertion macro definition.
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Bezier chart class template.
VertexSetType::CoordType CoordType
out coordinate type
Chart CRTP base-class template.
BaseClass::WorldPoint WorldPoint
our world point type
VertexSetType::CoordType CoordType
coordinate type
Circle chart class template.
virtual bool attribs(std::map< String, bool > &attrs) const override
Specifies the mandatory and optional attributes.
virtual bool content(int, const String &) override
Called to process a content line.
virtual void create(int iline, const String &sline, const String &, const std::map< String, String > &attrs, bool) override
Creates this markup parser node.
virtual std::shared_ptr< Xml::MarkupParser > markup(int, const String &, const String &name) override
Called to process a child markup node.
virtual void close(int iline, const String &sline) override
Closes this markup parser node.
BaseClass::ParamPoint ParamPoint
Vector type for parametrization points, aka domain points.
CoordType compute_dist(const WorldPoint &point) const
Computes the distance of a point to this chart.
Tiny::Vector< CoordType, 3 > _offset
the offset point
Tiny::Matrix< CoordType, 3, 3 > _rotation
the rotation matrix
Tiny::Vector< CoordType, 2 > _origin
the origin point
CoordType compute_dist(const WorldPoint &point, WorldPoint &grad_dist) const
Computes the distance of a point to this chart.
CoordType compute_signed_dist(const WorldPoint &point, WorldPoint &grad_dist) const
Computes the signed distance of a point to this chart.
CoordType compute_signed_dist(const WorldPoint &point) const
Computes the signed distance of a point to this chart.
std::unique_ptr< SubChart_ > _sub_chart
our sub-chart object
ChartCRTP< Extrude< Mesh_, SubChart_ >, Mesh_, ExtrudeTraits< SubChart_ > > BaseClass
The CRTP base class.
BaseClass::WorldPoint WorldPoint
Vector type for world points, aka image points.
virtual String get_type() const override
Writes the type as String.
virtual void write(std::ostream &os, const String &sindent) const override
Writes the Chart into a stream in XML format.
virtual bool can_implicit() const override
BaseClass::CoordType CoordType
Floating point type.
virtual bool can_explicit() const override
String class implementation.
Tiny Matrix class template.
CUDA_HOST_DEVICE Matrix & set_mat_mat_mult(const Matrix< T_, m_, la_, sma_, sna_ > &a, const Matrix< T_, lb_, n_, smb_, snb_ > &b)
Sets this matrix to the algebraic matrix-product of two other matrices.
CUDA_HOST_DEVICE DataType norm_sub_id_frobenius() const
Returns the Frobenius norm of the difference of this matrix and the identity matrix.
CUDA_HOST_DEVICE Matrix & set_rotation_3d(T_ yaw, T_ pitch, T_ roll)
Sets this matrix to a 3D yaw-pitch-roll rotation matrix.
CUDA_HOST_DEVICE Matrix & set_identity()
Sets this matrix to the identity matrix.
Tiny Vector class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the vector.
CUDA_HOST_DEVICE DataType norm_euclid_sqr() const
Computes the squared euclid norm of this vector.
CUDA_HOST_DEVICE Vector & set_mat_vec_mult(const Matrix< T_, n_, m_, sma_, sna_ > &a, const Vector< T_, m_, sx_ > &x)
Sets this vector to the result of a matrix-vector product.
Dummy XML markup parser class.
XML Markup Parser interface.
T_ sqrt(T_ x)
Returns the square-root of a value.
T_ atan2(T_ y, T_ x)
Returns the arctangent of y/x.
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
T_ sqr(T_ x)
Returns the square of a value.
std::uint64_t Index
Index data type.
static constexpr int world_dim
this is a 3D object
static constexpr bool is_implicit
we support implicit projection
static constexpr int param_dim
we have 2D parameters
static constexpr bool is_explicit
we support explicit map
Face traits tag struct template.