manipulators_example_00007.cpp

Example of usage of RBF manipulator with variable support radius to deform an input geometry.Using: MimmoGeometry, GenericInput, CreatePointCloud, ProjPatchOnSurface, MRBF, Apply, Chain.

To run : ./manipulators_example_00007
To run (MPI version): mpirun -np X manipulators_example_00007
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>
// =================================================================================== //
void test00007() {
/*
Read a sphere from STL. Convert mode is to save the just read geometry in
another file with name manipulators_output_00007.0000.stl
*/
mimmo0->setReadDir("geodata");
mimmo0->setReadFileType(FileType::STL);
mimmo0->setReadFilename("sphere2");
mimmo0->setWriteDir(".");
mimmo0->setWriteFileType(FileType::STL);
mimmo0->setWriteFilename("manipulators_output_00007.0000");
/* write the deformed mesh to file */
mimmo1->setWriteDir(".");
mimmo1->setWriteFileType(FileType::STL);
mimmo1->setWriteFilename("manipulators_output_00007.0001");
/*
Creation of a random distribution of 10 points with coordinates between [-0.5, 0.5]
and a random distribution of 10 support radii between [0.05, 0.35]
*/
int np = 10;
dvecarr3E rbfNodes(10);
dvector1D supportRadii(10);
std::minstd_rand rgen, sgen;
rgen.seed(160);
sgen.seed(333);
double dist = (rgen.max()-rgen.min());
double dist2 = (sgen.max()-sgen.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;
}
supportRadii[i] = 0.1 * ( double(sgen() - sgen.min() ) / dist2 ) + 0.05;
}
/*
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] /= -20.0*norm2(displ[i]);
}
/*
Set Generic input block with the
nodes defined above.
*/
inputn->setInput(rbfNodes);
/* Set Generic input block with the
* supportRadii defined above.
*/
inputSR->setInput(supportRadii);
/* 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, displacements and supportRadii will be stored as a point cloud mesh with a vector
field/scalar field attached, respectively.
*/
/*
This block will project the rbf point cloud onto the target surface
*/
proj->setWorkingOnTarget(true);
/*
RBF manipulator, will use RBF point cloud, its vectorfield of displacements
and its scalarfield of variable supportRadii to build up itself.
It requires the definition of RBF function.
*/
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.
*/
mimmo::pin::addPin(mimmo0, mrbf, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, proj, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
mimmo::pin::addPin(inputn, pointcloud, M_COORDS, M_COORDS);
mimmo::pin::addPin(input, pointcloud, M_DISPLS, M_DISPLS);
mimmo::pin::addPin(inputSR, pointcloud, M_DATAFIELD, M_DATAFIELD);
mimmo::pin::addPin(pointcloud, proj, M_GEOM, M_GEOM2);
mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM);
/*
Setup execution chain.
*/
ch0.addObject(input);
ch0.addObject(inputn);
ch0.addObject(inputSR);
ch0.addObject(mimmo0);
ch0.addObject(pointcloud);
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;
*/
delete mrbf;
delete proj;
delete pointcloud;
delete applier;
delete input;
delete inputSR;
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{
test00007() ;
}
catch(std::exception & e){
std::cout<<"manipulators_example_00007 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_DATAFIELD
#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 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)
std::vector< double > dvector1D
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,...
#define M_SCALARFIELD
std::array< double, 3 > darray3E
Radial Basis Function evaluation from clouds of control points.
Definition: MRBF.hpp:146
#define M_SCALARFIELD2
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