utils_example_00004.cpp
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 #include "mimmo_utils.hpp"
26 #include "FFDLattice.hpp"
27 #if MIMMO_ENABLE_MPI
28  #include "Partition.hpp"
29 #endif
30 
31 // =================================================================================== //
47 void test00004() {
48 
49  /*
50  Read a target bunny geometry from file. CONVERT option will let the block to write
51  the just read file in another file, immediately after the reading.
52  */
54  mimmo0->setName("StanfordBunnyReader");
55  mimmo0->setReadDir("geodata");
56  mimmo0->setReadFileType(FileType::STL);
57  mimmo0->setReadFilename("stanfordBunny2");
58  mimmo0->setWriteDir(".");
59  mimmo0->setWriteFileType(FileType::SURFVTU);
60  mimmo0->setWriteFilename("utils_mesh_00004.0000");
61 
62 #if MIMMO_ENABLE_MPI
63  /* Distribute bunny among processes.
64  */
65  mimmo::Partition * mimmo0part = new mimmo::Partition();
66  mimmo0part->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
67  mimmo0part->setName("StanfordBunnyPartitioner");
68  mimmo0part->setPlotInExecution(true);
69 #endif
70 
71  /*
72  Calculate the OBB the original StanfordBunny
73  */
74  mimmo::OBBox * obb_original = new mimmo::OBBox();
75  obb_original->setName("OBBOriginal");
76  obb_original->setWriteInfo(true);
77  obb_original->setPlotInExecution(true);
78 
79  /*
80  Calculate the OBB the deformed StanfordBunny
81  */
82  mimmo::OBBox * obb_deformed = new mimmo::OBBox();
83  obb_deformed->setName("OBBDeformed");
84  obb_deformed->setWriteInfo(true);
85  obb_deformed->setPlotInExecution(true);
86 
87  /*
88  Translate point. This is meant as the new origin of the FFDLattice for deformation
89  */
91  translp->setName("TranslationOriginLattice");
92  translp->setOrigin({{0.0,0.0,0.0}});
93  translp->setDirection({{-0.714,0.0,1.0}});
94  translp->setTranslation(0.9);
95 
96  /*
97  Rotate axes reference system. This is meant as the new sdr axes of the FFDLattice for deformation
98  */
99  mimmo::RotationAxes * rot_axes = new mimmo::RotationAxes();
100  rot_axes->setName("SDRAxesLattice");
101  rot_axes->setOrigin({{0.0,0.0,0.0}});
102  rot_axes->setDirection({{0.0,0.0,1.0}});
103  rot_axes->setRotation(-30.0*BITPIT_PI/180.0);
104  rot_axes->setAxes({{1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0}});
105  rot_axes->setAxesOrigin({{0.0,0.0,0.0}});
106 
107  /*
108  Create a box shaped FFD Lattice to deform the head of the rabbit.
109  Axes and Origin of the cube are provided by rot_axes and translp
110  through ports.
111  */
112  mimmo::FFDLattice * latt = new mimmo::FFDLattice();
113  latt->setName("FFDLattice");
115  latt->setSpan({{0.7,1.2,0.62}});
116  latt->setDimension(iarray3E({{2,2,2}}));
117  latt->setDegrees(iarray3E({{1,1,1}}));
118  dvecarr3E displs(8,{{0.0,0.0,0.0}});
119  displs[1][0] = -0.5;
120  displs[3][0] = -0.5;
121  latt->setDisplacements(displs);
122  latt->setApply(true);
123  latt->setPlotInExecution(true);
124 
125  // create connections
126  // original geoemetry passed to obb and lattice
127 #if MIMMO_ENABLE_MPI
128  mimmo::pin::addPin(mimmo0, mimmo0part, M_GEOM, M_GEOM);
129  mimmo::pin::addPin(mimmo0part, obb_original, M_GEOM, M_GEOM);
130  mimmo::pin::addPin(mimmo0part, latt, M_GEOM, M_GEOM);
131 #else
132  mimmo::pin::addPin(mimmo0, obb_original, M_GEOM, M_GEOM);
133  mimmo::pin::addPin(mimmo0, latt, M_GEOM, M_GEOM);
134 #endif
135 
136  // origin, axes passed to lattice
137  mimmo::pin::addPin(translp, latt, M_POINT, M_POINT);
138  mimmo::pin::addPin(rot_axes, latt, M_AXES, M_AXES);
139 
140  // pass deformed geoemetry to obb_deformed
141  mimmo::pin::addPin(latt, obb_deformed, M_GEOM, M_GEOM);
142 
143  /* Setup execution chain.
144  */
145  mimmo::Chain ch0,ch1;
146  ch0.addObject(mimmo0);
147  ch0.addObject(obb_original);
148 #if MIMMO_ENABLE_MPI
149  ch0.addObject(mimmo0part);
150 #endif
151 
152  ch1.addObject(translp);
153  ch1.addObject(rot_axes);
154  ch1.addObject(latt);
155  ch1.addObject(obb_deformed);
156 
157  /* Execute the chain.
158  * Use debug flag false to avoid to print out the execution steps on console.
159  */
160  ch0.exec(true);
161  ch1.exec(true);
162 
163 
164  /*
165  Write deformed geometry;
166  */
167  mimmo0->getGeometry()->getPatch()->write("utils_mesh_00004.0001");
168 
169  /* Clean up & exit;
170  */
171  delete mimmo0;
172  delete translp;
173  delete rot_axes;
174  delete obb_original;
175  delete obb_deformed;
176  delete latt;
177 #if MIMMO_ENABLE_MPI
178  delete mimmo0part;
179 #endif
180  return;
181 }
182 
183 
184 int main(int argc, char *argv[]) {
185 
186  BITPIT_UNUSED(argc);
187  BITPIT_UNUSED(argv);
188 
189 #if MIMMO_ENABLE_MPI==1
190  MPI_Init(&argc, &argv);
191 
192  {
193 #endif
194 
196  try{
197  test00004() ;
198  }
199  catch(std::exception & e){
200  std::cout<<"utils_example_00004 exited with an error of type : "<<e.what()<<std::endl;
201  return 1;
202  }
203 
204 #if MIMMO_ENABLE_MPI==1
205  }
206 
207  MPI_Finalize();
208 #endif
209 
210  return 0;
211 }
void exec(bool debug=false)
Definition: Chain.cpp:284
std::array< int, 3 > iarray3E
void setDimension(ivector1D dim)
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_GEOM
void setOrigin(darray3E origin)
void setAxes(dmatrix33E axes)
std::vector< darray3E > dvecarr3E
void setDisplacements(dvecarr3E displacements)
Definition: FFDLattice.cpp:284
void setAxesOrigin(darray3E axes_origin)
void setWriteFileType(FileType type)
void setName(std::string name)
void setRotation(double alpha)
void setTranslation(double alpha)
void setWriteDir(std::string dir)
void setDegrees(iarray3E curveDegrees)
Definition: FFDLattice.cpp:273
#define M_POINT
RotationAxes is the class that applies a rotation to a given reference system.
void setShape(ShapeType type=ShapeType::CUBE)
TranslationPoint is the class that applies the a translation to a point.
void setWriteFilename(std::string filename)
void setDirection(darray3E direction)
void setWriteInfo(bool flag)
Definition: OBBox.cpp:262
Oriented Bounding Box calculator.
Definition: OBBox.hpp:90
void setReadFilename(std::string filename)
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
#define M_AXES
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
void setDirection(darray3E direction)
void setOrigin(darray3E origin)
void setSpan(double, double, double)
void setReadFileType(FileType type)
MimmoSharedPointer< MimmoObject > getGeometry()
void setApply(bool flag=true)
Free Form Deformation of a 3D surface and point clouds, with structured lattice.
Definition: FFDLattice.hpp:133
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170