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
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ GMDS_ADD_COMPONENT(
OFF # must be covered
)

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



#==============================================================================
set (GMDS_INCLUDE_DIRS APPEND)
Expand Down
6 changes: 4 additions & 2 deletions math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(GMDS_INC
inc/gmds/math/Vector.h
inc/gmds/math/VectorDyn.h
inc/gmds/math/StreamComputation.h
inc/gmds/math/BezierSurface.h
)
set(GMDS_SRC
src/AxisAngleRotation.cpp
Expand Down Expand Up @@ -67,10 +68,11 @@ set(GMDS_SRC
src/VectorDyn.cpp
src/Orientation.cpp
src/Vector.cpp
src/TransfiniteInterpolation.cpp inc/gmds/math/BezierSurface.h src/BezierSurface.cpp)
src/TransfiniteInterpolation.cpp
src/BezierSurface.cpp)
#==============================================================================
find_package(Eigen3 3.3 REQUIRED)
#==============================================================================
#==============================================================================k
add_library(${GMDS_LIB} ${GMDS_INC} ${GMDS_SRC})
#==============================================================================
include(GenerateExportHeader)
Expand Down
60 changes: 60 additions & 0 deletions morphMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#==============================================================================
# LIBRARY DEFINTION (SOURCE FILES)
#==============================================================================
# Nommer tout en GMDS_MODULE_NAME, GMDS_SRC, ... dans les composants
set(GMDS_LIB ${LIB_GMDS_MORPHMESH})
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
inc/gmds/morphMesh/EllipticMorph.h
)
set(GMDS_SRC
src/FastLocalize.cpp
src/MorphMesh.cpp
src/EllipticMorph.cpp
)
#==============================================================================
add_library(${GMDS_LIB} ${GMDS_INC} ${GMDS_SRC})
#==============================================================================
include(GenerateExportHeader)
generate_export_header(${GMDS_LIB}
EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exports/${GMDS_LIB}_export.h
EXPORT_MACRO_NAME ${GMDS_LIB}_API)
#==============================================================================
# TARGET DEFINITION
#==============================================================================
include(GNUInstallDirs)

#LIBRARY TO INSTALL
target_link_libraries(${GMDS_LIB} PUBLIC
${LIB_GMDS_IG}
${LIB_GMDS_IG_ALGO}
${LIB_GMDS_IO} ANN)

target_compile_features(${GMDS_LIB} PUBLIC cxx_std_14)

# INCLUDE TO INSTALL
target_include_directories(${GMDS_LIB} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>
)
set_target_properties(${GMDS_LIB} PROPERTIES PUBLIC_HEADER "${GMDS_INC}")

install(TARGETS ${GMDS_LIB}
EXPORT GMDS_SUITE
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${GMDS_LIB_PREFIX}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
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)
install(TARGETS morphing)
3 changes: 3 additions & 0 deletions morphMesh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#morphMesh module

This module propose algorithm to morph mesh using deformation function.
55 changes: 55 additions & 0 deletions morphMesh/inc/gmds/morphMesh/EllipticMorph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

#ifndef GMDS_ELLIPTICMORPH_H
#define GMDS_ELLIPTICMORPH_H

/*----------------------------------------------------------------------------*/
#include "LIB_GMDS_MORPHMESH_export.h"
#include "gmds/ig/Mesh.h"
/*----------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------*/
namespace morphmesh {
/*----------------------------------------------------------------------------*/
class LIB_GMDS_MORPHMESH_API EllipticMorph
{

public:
/*------------------------------------------------------------------------*/
/** @brief Constructor.
*/
EllipticMorph(Mesh* AMesh);

/*------------------------------------------------------------------------*/
/** @brief Destructor.
*/
~EllipticMorph();

/*------------------------------------------------------------------------*/
/** @brief Constructor.
*/
void execute(const std::vector<std::vector<double>>& AEllipses);

private:

/*Surement a retirer plus tard*/
void markLockedCells();


private:

/* Locked nodes */
int m_locked;
/* Nodes on the surface of the mesh */
std::vector<TCellID> m_surfNodes;
std::vector<TCellID> m_locked_faces;


/* The mesh to deform */
Mesh* m_mesh;
};
/*----------------------------------------------------------------------------*/
}// namespace morphmesh
/*----------------------------------------------------------------------------*/
}// namespace gmds
/*----------------------------------------------------------------------------*/
#endif // GMDS_ELLIPTICMORPH_H
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(const std::vector<Node> &ANodes);
/*-------------------------------------------------------------------*/
/** @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
*/
TCellID find(const math::Point& APoint);
/*-------------------------------------------------------------------*/

private:
void buildANNTree();
private:
/** mesh we work on */
std::vector<Node> m_nodes;
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
/*----------------------------------------------------------------------------*/
66 changes: 66 additions & 0 deletions morphMesh/inc/gmds/morphMesh/MorphMesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*----------------------------------------------------------------------------*/
#ifndef GMDS_MORPHMESH_H
#define GMDS_MORPHMESH_H

/*----------------------------------------------------------------------------*/
#include "LIB_GMDS_MORPHMESH_export.h"
#include "gmds/ig/Mesh.h"
/*----------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------*/
namespace morphmesh {
/*----------------------------------------------------------------------------*/
class LIB_GMDS_MORPHMESH_API MorphMesh
{

public:
/*------------------------------------------------------------------------*/
/** @brief Constructor.
*/
MorphMesh(Mesh* AMesh, const std::vector<math::Point> &APoints, double ARadius);

/*------------------------------------------------------------------------*/
/** @brief Destructor.
*/
~MorphMesh();

/*------------------------------------------------------------------------*/
/** @brief Constructor.
*/
void execute();

private:

/*Surement a retirer plus tard*/
void markLockedCells();

bool computeLocalOrigin(const math::Point& AP, math::Point& AResult);
bool computeLocalOriginZ(const math::Point& AP, math::Point& AResult);

double findHomothetyRatio(const math::Point& AP, const Node& ANode);

private:

/* Locked nodes */
int m_locked;
Variable<int>* locked_faces;
/* List of "homothetic points" that will define the mesh deformation */
std::vector<math::Point> m_targets;
/* The radius of an area that will be modified by a homothetic point*/
double m_radius;
/* Nodes on the surface of the mesh */
std::vector<TCellID> m_surfNodes;
std::vector<TCellID> m_locked_faces;
//std::map<TCellID,bool> is_locked_node;
//std::map<TCellID,math::Point> nodes_origins;


/* The mesh to deform */
Mesh* m_mesh;
};
/*----------------------------------------------------------------------------*/
}// namespace morphmesh
/*----------------------------------------------------------------------------*/
}// namespace gmds
/*----------------------------------------------------------------------------*/
#endif // GMDS_MORPHMESH_H
Loading