utils_example_00004.cpp

Comparison of Oriented Bounding Boxes between a deformed and undeformed geometry.Using: MimmoGeometry, OBBox, TranslationPoint, RotationAxes, FFDLattice, Chain, Partition(MPI version)

To run : ./utils_example_00004
To run (MPI version): mpirun -np X utils_example_00004
visit: mimmo website

/*---------------------------------------------------------------------------*\
*
* mimmo
*
* Copyright (C) 2015-2021 OPTIMAD engineering Srl
*
* -------------------------------------------------------------------------
* License
* This file is part of mimmo.
*
* mimmo is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License v3 (LGPL)
* as published by the Free Software Foundation.
*
* mimmo is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mimmo. If not, see <http://www.gnu.org/licenses/>.
*
\ *---------------------------------------------------------------------------*/
#include "mimmo_utils.hpp"
#include "FFDLattice.hpp"
#if MIMMO_ENABLE_MPI
#include "Partition.hpp"
#endif
// =================================================================================== //
void test00004() {
/*
Read a target bunny geometry from file. CONVERT option will let the block to write
the just read file in another file, immediately after the reading.
*/
mimmo0->setName("StanfordBunnyReader");
mimmo0->setReadDir("geodata");
mimmo0->setReadFileType(FileType::STL);
mimmo0->setReadFilename("stanfordBunny2");
mimmo0->setWriteDir(".");
mimmo0->setWriteFileType(FileType::SURFVTU);
mimmo0->setWriteFilename("utils_mesh_00004.0000");
#if MIMMO_ENABLE_MPI
/* Distribute bunny among processes.
*/
mimmo::Partition * mimmo0part = new mimmo::Partition();
mimmo0part->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
mimmo0part->setName("StanfordBunnyPartitioner");
mimmo0part->setPlotInExecution(true);
#endif
/*
Calculate the OBB the original StanfordBunny
*/
mimmo::OBBox * obb_original = new mimmo::OBBox();
obb_original->setName("OBBOriginal");
obb_original->setWriteInfo(true);
obb_original->setPlotInExecution(true);
/*
Calculate the OBB the deformed StanfordBunny
*/
mimmo::OBBox * obb_deformed = new mimmo::OBBox();
obb_deformed->setName("OBBDeformed");
obb_deformed->setWriteInfo(true);
obb_deformed->setPlotInExecution(true);
/*
Translate point. This is meant as the new origin of the FFDLattice for deformation
*/
translp->setName("TranslationOriginLattice");
translp->setOrigin({{0.0,0.0,0.0}});
translp->setDirection({{-0.714,0.0,1.0}});
translp->setTranslation(0.9);
/*
Rotate axes reference system. This is meant as the new sdr axes of the FFDLattice for deformation
*/
rot_axes->setName("SDRAxesLattice");
rot_axes->setOrigin({{0.0,0.0,0.0}});
rot_axes->setDirection({{0.0,0.0,1.0}});
rot_axes->setRotation(-30.0*BITPIT_PI/180.0);
rot_axes->setAxes({{1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0}});
rot_axes->setAxesOrigin({{0.0,0.0,0.0}});
/*
Create a box shaped FFD Lattice to deform the head of the rabbit.
Axes and Origin of the cube are provided by rot_axes and translp
through ports.
*/
latt->setName("FFDLattice");
latt->setSpan({{0.7,1.2,0.62}});
latt->setDimension(iarray3E({{2,2,2}}));
latt->setDegrees(iarray3E({{1,1,1}}));
dvecarr3E displs(8,{{0.0,0.0,0.0}});
displs[1][0] = -0.5;
displs[3][0] = -0.5;
latt->setDisplacements(displs);
latt->setApply(true);
latt->setPlotInExecution(true);
// create connections
// original geoemetry passed to obb and lattice
#if MIMMO_ENABLE_MPI
mimmo::pin::addPin(mimmo0, mimmo0part, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0part, obb_original, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0part, latt, M_GEOM, M_GEOM);
#else
mimmo::pin::addPin(mimmo0, obb_original, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, latt, M_GEOM, M_GEOM);
#endif
// origin, axes passed to lattice
mimmo::pin::addPin(rot_axes, latt, M_AXES, M_AXES);
// pass deformed geoemetry to obb_deformed
mimmo::pin::addPin(latt, obb_deformed, M_GEOM, M_GEOM);
/* Setup execution chain.
*/
mimmo::Chain ch0,ch1;
ch0.addObject(mimmo0);
ch0.addObject(obb_original);
#if MIMMO_ENABLE_MPI
ch0.addObject(mimmo0part);
#endif
ch1.addObject(translp);
ch1.addObject(rot_axes);
ch1.addObject(latt);
ch1.addObject(obb_deformed);
/* Execute the chain.
* Use debug flag false to avoid to print out the execution steps on console.
*/
ch0.exec(true);
ch1.exec(true);
/*
Write deformed geometry;
*/
mimmo0->getGeometry()->getPatch()->write("utils_mesh_00004.0001");
/* Clean up & exit;
*/
delete mimmo0;
delete translp;
delete rot_axes;
delete obb_original;
delete obb_deformed;
delete latt;
#if MIMMO_ENABLE_MPI
delete mimmo0part;
#endif
return;
}
int main(int argc, char *argv[]) {
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#if MIMMO_ENABLE_MPI==1
MPI_Init(&argc, &argv);
{
#endif
try{
test00004() ;
}
catch(std::exception & e){
std::cout<<"utils_example_00004 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if MIMMO_ENABLE_MPI==1
}
MPI_Finalize();
#endif
return 0;
}
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