OBBox.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 #ifndef __OBBox_HPP__
25 #define __OBBox_HPP__
26 
27 #include "BaseManipulation.hpp"
28 
29 namespace mimmo{
30 
31 
36 enum class OBBStrategy{
37  OBB = 0 ,
38  AABB = 1 ,
39  MINVOL = 2
40 };
41 
42 
43 
90 class OBBox: public BaseManipulation {
91 
92 protected:
97  std::unordered_map<MimmoSharedPointer<MimmoObject>, int> m_listgeo;
99  bool m_writeInfo;
101 public:
102  OBBox();
103  OBBox(const bitpit::Config::Section & rootXML);
104  virtual ~OBBox();
105 
106  //copy operators/constructors
107  OBBox(const OBBox & other);
108 
109  void buildPorts();
110 
111  //clean structure;
112  void clearOBBox();
113 
114  //internal methods
115  std::vector<MimmoSharedPointer<MimmoObject> > getGeometries();
117  darray3E getSpan();
119  BITPIT_DEPRECATED(
120  bool isForcedAABB());
122 
124  void setGeometries(std::vector<MimmoSharedPointer<MimmoObject> > listgeo);
125  BITPIT_DEPRECATED(
126  void setForceAABB(bool flag));
127  void setOBBStrategy(OBBStrategy strategy);
128  void setOBBStrategyInt(int strategyflag);
129  void setWriteInfo(bool flag);
130 
131  //plotting wrappers
132  void plot(std::string directory, std::string filename, int counter, bool binary);
133 
134  //building method
135  void execute();
136 
137  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name = "");
138  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name= "");
139 
140 
141 protected:
142  virtual void plotOptionalResults();
143  void swap(OBBox & x) noexcept;
144  dmatrix33E transpose(const dmatrix33E & mat);
145  dmatrix33E inverse (const dmatrix33E & mat);
146  void computeOBB(std::vector<MimmoSharedPointer<MimmoObject>> & vector_listgeo, darray3E& origin, darray3E & span, dmatrix33E & axes);
147  void computeAABB(std::vector<MimmoSharedPointer<MimmoObject>> & vector_listgeo, darray3E& origin, darray3E & span, dmatrix33E & axes);
148 
149 private:
150  dmatrix33E evaluatePointsCovarianceMatrix(std::vector<MimmoSharedPointer<MimmoObject> > list);
151  dmatrix33E evaluateElementsCovarianceMatrix(std::vector<MimmoSharedPointer<MimmoObject> > list);
152  dmatrix33E eigenVectors( dmatrix33E &, darray3E & eigenValues);
153  void adjustBasis( dmatrix33E &, darray3E & eigenValues);
154  std::array<long,3> get3RepPoints(long cellID, mimmo::MimmoSharedPointer<MimmoObject> geo);
155 };
156 
157 REGISTER_PORT(M_GEOM, MC_SCALAR, MD_MIMMO_,__OBBox_HPP__)
159 REGISTER_PORT(M_POINT, MC_ARRAY3, MD_FLOAT,__OBBox_HPP__)
160 REGISTER_PORT(M_AXES, MC_ARR3ARR3, MD_FLOAT,__OBBox_HPP__)
161 REGISTER_PORT(M_SPAN, MC_ARRAY3, MD_FLOAT,__OBBox_HPP__)
162 
163 
164 REGISTER(BaseManipulation, OBBox, "mimmo.OBBox")
165 
166 };
167 
168 #endif /* __LATTICE_HPP__ */
void swap(OBBox &x) noexcept
Definition: OBBox.cpp:92
dmatrix33E transpose(const dmatrix33E &mat)
Definition: OBBox.cpp:885
darray3E getOrigin()
Definition: OBBox.cpp:140
bool m_writeInfo
Definition: OBBox.hpp:99
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
Definition: OBBox.cpp:599
dmatrix33E inverse(const dmatrix33E &mat)
Definition: OBBox.cpp:901
void computeAABB(std::vector< MimmoSharedPointer< MimmoObject >> &vector_listgeo, darray3E &origin, darray3E &span, dmatrix33E &axes)
Definition: OBBox.cpp:487
bool isForcedAABB()
Definition: OBBox.cpp:180
#define M_GEOM
#define MC_ARRAY3
#define MD_FLOAT
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
Definition: OBBox.cpp:549
void setGeometry(MimmoSharedPointer< MimmoObject > geo)
Definition: OBBox.cpp:212
#define MC_ARR3ARR3
#define M_POINT
std::vector< MimmoSharedPointer< MimmoObject > > getGeometries()
Definition: OBBox.cpp:168
darray3E m_span
Definition: OBBox.hpp:94
BaseManipulation is the base class of any manipulation object of the library.
void clearOBBox()
Definition: OBBox.cpp:120
void setWriteInfo(bool flag)
Definition: OBBox.cpp:262
OBBStrategy getOBBStrategy()
Definition: OBBox.cpp:188
virtual ~OBBox()
Definition: OBBox.cpp:74
Oriented Bounding Box calculator.
Definition: OBBox.hpp:90
#define MC_SCALAR
void execute()
Definition: OBBox.cpp:329
OBBStrategy
Enum class for engine choice to set up initial points on a 3D surface.
Definition: OBBox.hpp:36
#define REGISTER_PORT(Name, Container, Datatype, ManipBlock)
void setGeometries(std::vector< MimmoSharedPointer< MimmoObject > > listgeo)
Definition: OBBox.cpp:199
std::array< darray3E, 3 > dmatrix33E
#define M_SPAN
void buildPorts()
Definition: OBBox.cpp:106
#define M_AXES
darray3E m_origin
Definition: OBBox.hpp:93
#define MC_VECTOR
darray3E getSpan()
Definition: OBBox.cpp:149
dmatrix33E getAxes()
Definition: OBBox.cpp:159
#define MD_MIMMO_
void setOBBStrategyInt(int strategyflag)
Definition: OBBox.cpp:251
void plot(std::string directory, std::string filename, int counter, bool binary)
Definition: OBBox.cpp:273
dmatrix33E m_axes
Definition: OBBox.hpp:95
std::array< double, 3 > darray3E
void computeOBB(std::vector< MimmoSharedPointer< MimmoObject >> &vector_listgeo, darray3E &origin, darray3E &span, dmatrix33E &axes)
Definition: OBBox.cpp:416
MimmoSharedPointer is a custom implementation of shared pointer.
void setForceAABB(bool flag)
Definition: OBBox.cpp:232
OBBStrategy m_strategy
Definition: OBBox.hpp:98
std::unordered_map< MimmoSharedPointer< MimmoObject >, int > m_listgeo
Definition: OBBox.hpp:97
void setOBBStrategy(OBBStrategy strategy)
Definition: OBBox.cpp:242
#define M_VECGEOM
virtual void plotOptionalResults()
Definition: OBBox.cpp:537
#define REGISTER(Base, Derived, name)
Definition: factory.hpp:206