manipulators_example_00006.cpp

Example of usage of RBF block to manipulate an input geometry.Using: MimmoGeometry, GenericInput, CreatePointCloud, ProjPatchOnSurface, MRBF, Apply, Chain, Partition(MPI version).

To run : ./manipulators_example_00006
To run (MPI version): mpirun -np X manipulators_example_00006
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_manipulators.hpp"
#include "mimmo_iogeneric.hpp"
#include "mimmo_utils.hpp"
#include <random>
#if MIMMO_ENABLE_MPI
#include "mimmo_parallel.hpp"
#endif
// =================================================================================== //
void test00006() {
/*
Read a sphere from STL. Convert mode is to save the just read geometry in
another file with name manipulators_output_00006.0000.stl
*/
mimmo0->setReadDir("geodata");
mimmo0->setReadFileType(FileType::STL);
mimmo0->setReadFilename("sphere2");
mimmo0->setWriteDir(".");
mimmo0->setWriteFileType(FileType::STL);
mimmo0->setWriteFilename("manipulators_output_00006.0000");
/* write the deformed mesh to file */
mimmo1->setWriteDir(".");
mimmo1->setWriteFileType(FileType::STL);
mimmo1->setWriteFilename("manipulators_output_00006.0001");
#if MIMMO_ENABLE_MPI
/*
Distribute mesh among processes
*/
mimmo::Partition* partition= new mimmo::Partition();
partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
#endif
/*
Creation of a random distribution of 10 points with coordinates between [-0.5, 0.5]
*/
int np = 10;
dvecarr3E rbfNodes(10);
std::minstd_rand rgen;
rgen.seed(160);
double dist = (rgen.max()-rgen.min());
for (int i=0; i<np; i++){
for (int j=0; j<3; j++)
rbfNodes[i][j] = 1.0*( double(rgen() - rgen.min() ) / dist ) - 0.5;
}
/*
Set a Generic input block with the
nodes defined above.
*/
inputn->setInput(rbfNodes);
/*
Creation of a set of displacements of the control nodes of the radial basis functions.
Use a radial displacements from a center point placed in axes origin.
*/
dvecarr3E displ(np, darray3E{0.0, 0.0, 0.0});
darray3E center({0.0, 0.0, 0.0});
for (int i=0; i<np; i++){
displ[i] = rbfNodes[i] - center;
displ[i] /= 2.0*norm2(displ[i]);
}
/*
Set Generic input block with the
displacements defined above.
*/
input->setInput(displ);
/*
Create a Point Cloud that will use the outputs of previous generic inputs.
Nodes and displacements will be stored as a point cloud mesh with a vector
field attached
*/
/*
This block will project the rbf point cloud onto the target surface
*/
proj->setWorkingOnTarget(true);
proj->setPlotInExecution(true);
/*
RBF manipulator, will use RBF point cloud and its vectorfield of displacements
to build up itself.
It requires the definition of RBF function and support radius
*/
mrbf->setFunction(bitpit::RBFBasisFunction::WENDLANDC2);
mrbf->setPlotInExecution(true);
/*
Create applier block.
It applies the deformation displacements to the original input geometry.
*/
mimmo::Apply* applier = new mimmo::Apply();
/* Setup pin connections.
*/
#if MIMMO_ENABLE_MPI
mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
mimmo::pin::addPin(partition, mrbf, M_GEOM, M_GEOM);
#else
mimmo::pin::addPin(mimmo0, mrbf, M_GEOM, M_GEOM);
#endif
mimmo::pin::addPin(mimmo0, proj, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM);
/*
Setup execution chain.
*/
#if MIMMO_ENABLE_MPI
ch0.addObject(partition);
#endif
ch0.addObject(input);
ch0.addObject(inputn);
ch0.addObject(rbfPC);
ch0.addObject(mimmo0);
ch0.addObject(proj);
ch0.addObject(applier);
ch0.addObject(mrbf);
ch0.addObject(mimmo1);
/*
Execute the chain.
* Use debug flag true to print out the execution steps.
*/
ch0.exec(true);
/*
Clean up & exit;
*/
#if MIMMO_ENABLE_MPI
delete partition;
#endif
delete mrbf;
delete proj;
delete applier;
delete input;
delete rbfPC;
delete mimmo0;
delete mimmo1;
return;
}
int main( int argc, char *argv[] ) {
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#if MIMMO_ENABLE_MPI
MPI_Init(&argc, &argv);
#endif
try{
test00006() ;
}
catch(std::exception & e){
std::cout<<"manipulators_example_00006 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if MIMMO_ENABLE_MPI
MPI_Finalize();
#endif
return 0;
}
void exec(bool debug=false)
Definition: Chain.cpp:284
#define M_GDISPLS
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_DISPLS
#define M_GEOM
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
std::vector< darray3E > dvecarr3E
void setSupportRadiusReal(double suppR_)
Definition: MRBF.cpp:436
void setWriteFileType(FileType type)
void setWriteDir(std::string dir)
#define M_GEOM2
void setInput(T *data)
GENERICINPUT////////////////////////////////////////////////////////////////////////////.
void setWriteFilename(std::string filename)
#define M_VECTORFIELD
GenericInput is the class that set the initialization of a generic input data.
void setReadFilename(std::string filename)
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
Executable block class capable of projecting a surface patch, 3DCurve or PointCloud on a 3D surface,...
std::array< double, 3 > darray3E
Radial Basis Function evaluation from clouds of control points.
Definition: MRBF.hpp:146
void setReadFileType(FileType type)
CreatePointCloud manages cloud point data in raw format to create a MimmoObject Point Cloud container...
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
#define M_COORDS
void setFunction(const MRBFBasisFunction &funct, bool isCompact=false)
Definition: MRBF.cpp:594