BasicShapes.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23  \ *---------------------------------------------------------------------------*/
24 
25 #ifndef __MIMMOBASICSHAPES_HH
26 #define __MIMMOBASICSHAPES_HH
27 
28 #include "MimmoObject.hpp"
29 #include <mimmo_binary_stream.hpp>
30 #include <unordered_set>
31 
32 namespace mimmo{
33 
38 enum class ShapeType{
39  CUBE =0,
40  CYLINDER=1,
41  SPHERE =3,
42  WEDGE =4
43 };
44 
49 enum class CoordType{
50 
51  UNCLAMPED =0,
52  CLAMPED =1,
53  PERIODIC =2,
54  SYMMETRIC =3
55 };
56 
57 }
62 //Binary stream occurring to Classes memebers for port exchange
65 
72  namespace mimmo{
73 
91 class BasicShape {
92 
93 protected:
102  std::array<CoordType,3> m_typeCoord;
104  dvecarr3E m_bbox; //temporary not copied build with get bounding box !!!
105 
106 public:
107 
108  //Costructors, Destructor
109  BasicShape();
110  virtual ~BasicShape();
111 
112  //set-get methods
113  void setOrigin(darray3E);
114  void setSpan(double, double, double);
115  void setSpan(darray3E);
116  void setInfLimits(double val, int dir);
117  void setInfLimits(darray3E val);
119  void setRefSystem(int, darray3E);
120  void setRefSystem(dmatrix33E axes);
121  void setCoordinateType(CoordType, int dir);
122 
124  darray3E getSpan();
127  CoordType getCoordinateType(int dir);
129  ShapeType getShapeType() const;
130 
133 
134 
135  //functionalities
138 
139  livector1D includeGeometry(bitpit::PatchKernel * );
140  livector1D excludeGeometry(bitpit::PatchKernel * );
141 
144 
145  livector1D includeCloudPoints(bitpit::PatchKernel * );
146  livector1D excludeCloudPoints(bitpit::PatchKernel * );
147 
150 
151  bool isSimplexIncluded(const dvecarr3E &);
152  bool isSimplexIncluded(bitpit::PatchKernel * , const long int &indexT);
153  bool isPointIncluded(const darray3E &);
154  bool isPointIncluded(bitpit::PatchKernel * , const long int &indexV);
155 
161  virtual bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax)=0;
162 
163 
169  virtual darray3E toWorldCoord(const darray3E & point)=0;
170 
177  virtual darray3E toLocalCoord(const darray3E & point)=0;
178 
183  virtual darray3E getLocalOrigin()=0;
184 
185 protected:
186  uint32_t intersectShapePlane(int level, const darray3E & target);
187  darray3E checkNearestPointToAABBox(const darray3E &point, const darray3E &bMin, const darray3E &bMax);
188  void swap(BasicShape & ) noexcept;
189  static dmatrix33E transpose(const dmatrix33E & mat);
190  static dmatrix33E inverse(const dmatrix33E & mat);
191  static darray3E matmul(const darray3E & vec, const dmatrix33E & mat);
192  static darray3E matmul(const dmatrix33E & mat,const darray3E & vec);
193 
194 private:
200  virtual darray3E basicToLocal(const darray3E &point)=0;
201 
207  virtual darray3E localToBasic(const darray3E &point)=0;
208 
216  virtual void checkSpan(double &s0, double &s1, double &s2)=0;
217 
225  virtual bool checkInfLimits(double & orig, int &dir)=0;
226 
233  virtual void setScaling(const double &s0, const double &s1, const double &s2)=0;
234 
235  void searchKdTreeMatches(bitpit::KdTree<3,bitpit::Vertex,long> & tree, livector1D & result, bool squeeze = true);
236  void searchBvTreeMatches(bitpit::PatchSkdTree & tree, bitpit::PatchKernel * geo, livector1D & result, bool squeeze = true);
237 
242  virtual void getTempBBox()=0;
243 };
244 
253 class Cube: public BasicShape {
254 
255 public:
256 
257  //Costructors, Destructor, Copy/Assignment operators
258  Cube();
259  Cube(const darray3E &origin, const darray3E &span);
260  ~Cube();
261 
262  Cube(const Cube &);
263 
264  //reimplementing pure virtuals
265 
266  darray3E toWorldCoord(const darray3E &point);
267  darray3E toLocalCoord(const darray3E &point);
269  bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax);
270 
271 private:
272  darray3E basicToLocal(const darray3E &point);
273  darray3E localToBasic(const darray3E &point);
274  void checkSpan(double &, double &, double &);
275  bool checkInfLimits(double &, int & dir);
276  void setScaling(const double &, const double &, const double &);
277  void getTempBBox();
278 };
279 
288 class Cylinder: public BasicShape {
289 
290 public:
291  //Costructors, Destructor, Copy/Assignment operators
292  Cylinder();
293  Cylinder(const darray3E &origin, const darray3E &span);
294  ~Cylinder();
295 
296  Cylinder(const Cylinder &);
297 
298  //reimplementing pure virtuals
299  darray3E toWorldCoord(const darray3E &point);
300  darray3E toLocalCoord(const darray3E &point);
302  bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax);
303 
304 private:
305  darray3E basicToLocal(const darray3E &point);
306  darray3E localToBasic(const darray3E &point);
307  void checkSpan(double &, double &, double &);
308  bool checkInfLimits( double &, int &);
309  void setScaling(const double &, const double &, const double &);
310  void getTempBBox();
311 };
312 
313 
322 class Sphere: public BasicShape {
323 
324 public:
325  //Costructors, Destructor, Copy/Assignment operators
326  Sphere();
327  Sphere(const darray3E &origin, const darray3E &span);
328  ~Sphere();
329 
330  Sphere(const Sphere &);
331 
332  //reimplementing pure virtuals
333  darray3E toWorldCoord(const darray3E &point);
334  darray3E toLocalCoord(const darray3E &point);
336  bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax);
337 
338 private:
339  darray3E basicToLocal(const darray3E &point);
340  darray3E localToBasic(const darray3E &point);
341  void checkSpan(double &, double &, double &);
342  bool checkInfLimits(double &, int &);
343  void setScaling(const double &, const double &, const double &);
344  void getTempBBox();
345 };
346 
357 class Wedge: public BasicShape {
358 
359 public:
360 
361  //Costructors, Destructor, Copy/Assignment operators
362  Wedge();
363  Wedge(const darray3E &origin, const darray3E &span);
364  ~Wedge();
365 
366  Wedge(const Wedge &);
367 
368  //reimplementing pure virtuals
369  darray3E toWorldCoord(const darray3E &point);
370  darray3E toLocalCoord(const darray3E &point);
372  bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax);
373 
374 private:
375  darray3E basicToLocal(const darray3E &point);
376  darray3E localToBasic(const darray3E &point);
377  void checkSpan( double &, double &, double &);
378  bool checkInfLimits(double &, int &);
379  void setScaling(const double &, const double &, const double &);
380  void getTempBBox();
381 
382 };
383 
384 
385 
386 }
387 
388 #endif // __MIMMOBASICSHAPES_HH
darray3E getInfLimits()
livector1D includeGeometry(MimmoSharedPointer< MimmoObject >)
void setOrigin(darray3E)
Abstract Interface class for Elementary Shape Representation.
Definition: BasicShapes.hpp:91
void setInfLimits(double val, int dir)
bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax)
darray3E m_infLimits
Definition: BasicShapes.hpp:97
static dmatrix33E inverse(const dmatrix33E &mat)
virtual darray3E toWorldCoord(const darray3E &point)=0
darray3E getLocalOrigin()
CoordType
Specify type of conditions to distribute NURBS nodes in a given coordinate of the shape.
Definition: BasicShapes.hpp:49
bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax)
Elementary Shape Representation of a Prism with triangular basis.
darray3E getLocalSpan()
bool isSimplexIncluded(const dvecarr3E &)
std::vector< darray3E > dvecarr3E
std::vector< long > livector1D
mimmo custom derivation of bitpit OBinaryStream (see relative doc)
virtual bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax)=0
std::array< CoordType, 3 > m_typeCoord
bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax)
ShapeType getShapeType()
mimmo::IBinaryStream & operator>>(mimmo::IBinaryStream &buf, mimmo::CoordType &element)
Definition: BasicShapes.cpp:77
Elementary Shape Representation of a Sphere or portion of it.
darray3E toLocalCoord(const darray3E &point)
virtual darray3E toLocalCoord(const darray3E &point)=0
darray3E toWorldCoord(const darray3E &point)
Elementary Shape Representation of a Cylinder or portion of it.
darray3E toWorldCoord(const darray3E &point)
dmatrix33E m_sdr
Definition: BasicShapes.hpp:98
static darray3E matmul(const darray3E &vec, const dmatrix33E &mat)
static dmatrix33E transpose(const dmatrix33E &mat)
darray3E getLocalOrigin()
livector1D includeCloudPoints(const dvecarr3E &)
darray3E checkNearestPointToAABBox(const darray3E &point, const darray3E &bMin, const darray3E &bMax)
mimmo::OBinaryStream & operator<<(mimmo::OBinaryStream &buf, const mimmo::CoordType &element)
Definition: BasicShapes.cpp:64
darray3E toLocalCoord(const darray3E &point)
virtual ~BasicShape()
void setRefSystem(darray3E, darray3E, darray3E)
void swap(BasicShape &) noexcept
Elementary Shape Representation of a Cube.
std::array< darray3E, 3 > dmatrix33E
bool isPointIncluded(const darray3E &)
darray3E getOrigin()
uint32_t intersectShapePlane(int level, const darray3E &target)
bool intersectShapeAABBox(const darray3E &bMin, const darray3E &bMax)
ShapeType
Identifies the type of elemental shape supported by BasicShape class.
Definition: BasicShapes.hpp:38
darray3E toWorldCoord(const darray3E &point)
livector1D excludeGeometry(MimmoSharedPointer< MimmoObject >)
darray3E getLocalOrigin()
darray3E getSpan()
mimmo custom derivation of bitpit IBinaryStream (see relative doc)
darray3E getScaling()
std::array< double, 3 > darray3E
dmatrix33E m_sdr_inverse
Definition: BasicShapes.hpp:99
dmatrix33E getRefSystem()
void setSpan(double, double, double)
MimmoSharedPointer is a custom implementation of shared pointer.
livector1D excludeCloudPoints(const dvecarr3E &)
virtual darray3E getLocalOrigin()=0
void setCoordinateType(CoordType, int dir)
darray3E getLocalOrigin()
darray3E toLocalCoord(const darray3E &point)
darray3E toWorldCoord(const darray3E &point)
CoordType getCoordinateType(int dir)
darray3E toLocalCoord(const darray3E &point)