Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 265 mesh deformation #323

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -270,16 +270,26 @@ GMDS_ADD_COMPONENT(
ON # must be covered
)

GMDS_ADD_COMPONENT(
RLBLOCKING # cmake variable
rlBlocking # src subdirectory name
GMDSRlBlocking # name of the generated library
" " # description
OFF # is activated
OFF # must be covered
)

GMDS_ADD_COMPONENT(
MORPHMESH
morphMesh
GMDSmorphMesh
"morphing the mesh"
ON
OFF
OFF # must be covered
)



#==============================================================================
set (GMDS_INCLUDE_DIRS APPEND)
#==============================================================================
7 changes: 6 additions & 1 deletion morphMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -7,11 +7,12 @@ set(GMDS_LIB_PREFIX gmds/morphMesh)

set(GMDS_INC
${CMAKE_BINARY_DIR}/exports/${GMDS_LIB}_export.h
inc/gmds/morphMesh/FastLocalize.h
inc/gmds/morphMesh/MorphMesh.h
)
set(GMDS_SRC
src/FastLocalize.cpp
src/MorphMesh.cpp
src/main.cpp
)
#==============================================================================
add_library(${GMDS_LIB} ${GMDS_INC} ${GMDS_SRC})
@@ -47,6 +48,10 @@ install(TARGETS ${GMDS_LIB}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
#==============================================================================
if(WITH_TEST)
add_subdirectory(tst)
endif(WITH_TEST)
#==============================================================================
add_executable(morphing src/main.cpp)
target_link_libraries(morphing PRIVATE ${GMDS_LIB})
target_compile_features(morphing PUBLIC cxx_std_14)
52 changes: 52 additions & 0 deletions morphMesh/inc/gmds/morphMesh/FastLocalize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*----------------------------------------------------------------------------*/
#ifndef GMDS_MORPHMESH_FASTLOCALIZE_H
#define GMDS_MORPHMESH_FASTLOCALIZE_H
/*----------------------------------------------------------------------------*/
#include "LIB_GMDS_MORPHMESH_export.h"
# include <gmds/ig/Mesh.h>
/*----------------------------------------------------------------------------*/
#include <map>
#include <ANN/ANN.h>
/*----------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------*/
class LIB_GMDS_MORPHMESH_API FastLocalize {
public:

/*-------------------------------------------------------------------*/
/** @brief Constructor.
* @param AMesh the mesh where we work on
*/
FastLocalize(Mesh *AMesh);
/*-------------------------------------------------------------------*/
/** @brief Destructor.
*/
virtual ~FastLocalize();

/*-------------------------------------------------------------------*/
/** @brief Given an input point \p APoint return the cell data that
* indicate what is the closest cell of \APoint (it can be a node or
* a face)
* @param APoint point to localize
* @return the cell data indicating where \p APoint is in this->m_mesh
*/
Cell::Data find(const math::Point& APoint);
/*-------------------------------------------------------------------*/

private:
void buildANNTree();
private:
/** mesh we work on */
Mesh *m_mesh;
std::map<int,TCellID > m_ann2gmds_id;
ANNkd_tree* m_kdTree;
ANNidxArray m_nnIdx; // near neighbor indices
ANNdistArray m_dists; // near neighbor distances
ANNpoint m_queryPt; // query point
ANNpointArray m_dataPts; // data points
};
/*----------------------------------------------------------------------------*/
} // namespace gmds
/*----------------------------------------------------------------------------*/
#endif // GMDS_MORPHMESH_FASTLOCALIZE_H
/*----------------------------------------------------------------------------*/
70 changes: 70 additions & 0 deletions morphMesh/src/FastLocalize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*------------------------------------------------------------------------*/
#include "gmds/morphMesh/FastLocalize.h"
//#include <gmds/claire/Utils.h>
/*------------------------------------------------------------------------*/
using namespace gmds;
/*------------------------------------------------------------------------*/
FastLocalize::FastLocalize(Mesh *AMesh): m_mesh(AMesh) {
int nb_pnts = m_mesh->getNbNodes();
int k = 20; // max number of nearest neighbors
int dim = 3; // dimension
int maxPts = nb_pnts; // maximum number of data points

int nPts; // actual number of data points

m_queryPt = annAllocPt(3);
m_dataPts = annAllocPts(maxPts, dim); // allocate data points
m_nnIdx = new ANNidx[k]; // allocate near neigh indices
m_dists = new ANNdist[k]; // allocate near neighbor dists

//========================================================
// (1) Fill in the ANN structure for storing points
//
// Important: Points in APnts and dataPnts are stored with
// same index.
//========================================================
nPts = 0;
for(auto n_id: m_mesh->nodes()){
math::Point p = m_mesh->get<Node>(n_id).point();
m_dataPts[nPts][0] = p.X();
m_dataPts[nPts][1] = p.Y();
m_dataPts[nPts][2] = p.Z();
m_ann2gmds_id[nPts]=n_id;
nPts++;
};

//========================================================
// (2) Build the search structure
//========================================================
m_kdTree = new ANNkd_tree(m_dataPts, // the data points
nPts, // number of points
dim); // dimension of space
}
/*------------------------------------------------------------------------*/
FastLocalize::~FastLocalize(){
delete [] m_nnIdx; // clean things up
delete [] m_dists;
delete m_kdTree;
annDeallocPt(m_queryPt);
annDeallocPts(m_dataPts);
annClose(); // done with ANN

}
/*------------------------------------------------------------------------*/
Cell::Data
FastLocalize::find(const math::Point &APoint)
{
int k = 5; // max number of nearest neighbors
m_queryPt[0]=APoint.X();
m_queryPt[1]=APoint.Y();
m_queryPt[2]=APoint.Z();

m_kdTree->annkSearch( // search
m_queryPt,// query point
k,
m_nnIdx,
m_dists,
0.01);
return Cell::Data(0,m_ann2gmds_id[m_nnIdx[0]]);
}
/*------------------------------------------------------------------------*/
13 changes: 13 additions & 0 deletions morphMesh/tst/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_executable(GMDS_MORPHMESH_TEST
FastLocalizeTestSuite.h
main_test.cpp
)
#==============================================================================
target_link_libraries(GMDS_MORPHMESH_TEST PUBLIC
${GMDS_LIB}
${LIB_GMDS_IO}
GTest::gtest)
#==============================================================================
gtest_discover_tests(GMDS_MORPHMESH_TEST
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
#==============================================================================
87 changes: 87 additions & 0 deletions morphMesh/tst/FastLocalizeTestSuite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <gmds/morphMesh/FastLocalize.h>
#include <gmds/ig/Mesh.h>
#include <gmds/ig/MeshDoctor.h>
#include <gmds/io/IGMeshIOService.h>
#include <gmds/io/VTKReader.h>
#include <gtest/gtest.h>
#include <iostream>
#include <unit_test_config.h>
/*----------------------------------------------------------------------------*/
/* TESTS UNITAIRES */
/*----------------------------------------------------------------------------*/

TEST(MorphMesh_FastLocalizeTestSuite, test_FastLocalize_2D)
{
// WE READ
gmds::Mesh m(gmds::MeshModel(gmds::DIM3 | gmds::N | gmds::F | gmds::F2N));

std::string dir(TEST_SAMPLES_DIR);
std::string vtk_file = dir + "/Aero/2D/C1_2D_0.1.vtk";

gmds::IGMeshIOService ioService(&m);
gmds::VTKReader vtkReader(&ioService);
vtkReader.setCellOptions(gmds::N | gmds::F);
vtkReader.read(vtk_file);

// fastlocalize works on a point cloud, no need for the faces
for(auto i: m.faces()) {
m.deleteFace(i);
}

gmds::FastLocalize fl(&m);

gmds::Cell::Data data = fl.find(gmds::math::Point({-0.0338,0.74,0}));
ASSERT_EQ(data.dim, 0);
ASSERT_EQ(data.id, 734);

data = fl.find(gmds::math::Point({-0.2,0.46,0}));
ASSERT_EQ(data.dim, 0);
ASSERT_EQ(data.id, 11);
}


TEST(MorphMesh_FastLocalizeTestSuite, test_FastLocalize_3D)
{
// WE READ
gmds::Mesh m(gmds::MeshModel(gmds::DIM3 | gmds::N | gmds::F | gmds::F2N));

std::string dir(TEST_SAMPLES_DIR);
std::string vtk_file = dir + "/Aero/3D/C1_3D_0.1.vtk";

gmds::IGMeshIOService ioService(&m);
gmds::VTKReader vtkReader(&ioService);
vtkReader.setCellOptions(gmds::N | gmds::F);
vtkReader.read(vtk_file);

// fastlocalize works on a point cloud, no need for the faces
for(auto i: m.faces()) {
m.deleteFace(i);
}

gmds::FastLocalize fl(&m);

gmds::Cell::Data data = fl.find(gmds::math::Point({-1.0,0.0,0}));
ASSERT_EQ(data.dim, 0);
ASSERT_EQ(data.id, 14322);

data = fl.find(gmds::math::Point({-1.33,0.678,-1.89}));
ASSERT_EQ(data.dim, 0);
ASSERT_EQ(data.id, 4048);
}


TEST(MorphMesh_FastLocalizeTestSuite, test_FastLocalize_nodes)
{
// WE READ
gmds::Mesh m(gmds::MeshModel(gmds::DIM3 | gmds::N | gmds::F | gmds::F2N));

for(int i=0; i<50; i++) {
m.newNode(i,1,1);
}

gmds::FastLocalize fl(&m);

gmds::Cell::Data data = fl.find(gmds::math::Point({1.9,0.0,0}));
ASSERT_EQ(data.dim, 0);
ASSERT_EQ(data.id, 2);
}
13 changes: 13 additions & 0 deletions morphMesh/tst/main_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*----------------------------------------------------------------------------*/
#include <gtest/gtest.h>
/*----------------------------------------------------------------------------*/
// Files containing the different test suites to launch

#include "FastLocalizeTestSuite.h"
/*----------------------------------------------------------------------------*/
int main(int argc, char ** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
/*----------------------------------------------------------------------------*/