Skip to content

Commit 63602bb

Browse files
404 tristan 2nd part internship (#427)
* Two new executables added (cross field and quantization). Moved circumcenter functions from medialaxis module to math module. * Two new executables added (block decomposition and quantization). Class NonConformalHalfEdge added. Class QuantizationGraphBuilder added. Class QuantizationGraph added. * Implemented class QuantizationSolver. * Some comments modified. Last version of the internship. --------- Co-authored-by: chenyt <tristan.cheny@cea.fr>
1 parent 34e543c commit 63602bb

22 files changed

+3239
-164
lines changed

math/inc/gmds/math/Tetrahedron.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class Triangle;
110110
*/
111111
const Point getCenter() const;
112112

113+
/*------------------------------------------------------------------------*/
114+
/** \brief Compute the center of the circumcircle of the tetrahedron
115+
*
116+
* \return a point
117+
*/
118+
const Point getCircumcenter() const;
119+
113120
/*------------------------------------------------------------------------*/
114121
/** \brief Compute the signed volume of the tetrahedron
115122
*

math/inc/gmds/math/Triangle.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ class Plane;
117117
*/
118118
Point getCenter() const;
119119

120+
/*------------------------------------------------------------------------*/
121+
/** \brief Computes the center of the circumcircle triangle
122+
*
123+
* \return the center of the circumcircle of the triangle
124+
*/
125+
Point getCircumcenter() const;
126+
120127
/*------------------------------------------------------------------------*/
121128
/** \brief Compute the scaled jacobian of the quadrilateral
122129
*

math/src/Tetrahedron.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,49 @@ const Point& Tetrahedron::getPoint(const TInt& AIndex) const
8585

8686
return Point(coordX,coordY,coordZ);
8787
}
88+
/*----------------------------------------------------------------------------*/
89+
const Point Tetrahedron::getCircumcenter() const
90+
{
91+
// Get the tetra vertices
92+
math::Point A = m_pnts[0];
93+
math::Point B = m_pnts[1];
94+
math::Point C = m_pnts[2];
95+
math::Point D = m_pnts[3];
96+
// Get the coordinates
97+
double xA = A.X();
98+
double yA = A.Y();
99+
double zA = A.Z();
100+
double xB = B.X();
101+
double yB = B.Y();
102+
double zB = B.Z();
103+
double xC = C.X();
104+
double yC = C.Y();
105+
double zC = C.Z();
106+
double xD = D.X();
107+
double yD = D.Y();
108+
double zD = D.Z();
109+
math::Matrix33 M;
110+
M(0,0) = xB-xA;
111+
M(0,1) = yB-yA;
112+
M(0,2) = zB-zA;
113+
M(1,0) = xC-xB;
114+
M(1,1) = yC-yB;
115+
M(1,2) = zC-zB;
116+
M(2,0) = xD-xA;
117+
M(2,1) = yD-yA
118+
;
119+
M(2,2) = zD-zA;
120+
double xV = (xB-xA)*(1./2.)*(xA+xB)+(yB-yA)*(1./2.)*(yA+yB)+(zB-zA)*(1./2.)*(zA+zB);
121+
double yV = (xC-xB)*(1./2.)*(xB+xC)+(yC-yB)*(1./2.)*(yB+yC)+(zC-zB)*(1./2.)*(zB+zC);
122+
double zV = (xD-xA)*(1./2.)*(xA+xD)+(yD-yA)*(1./2.)*(yA+yD)+(zD-zA)*(1./2.)*(zA+zD);
123+
math::Vector3d V;
124+
V.set(0, xV);
125+
V.set(1, yV);
126+
V.set(2, zV);
127+
math::Vector3d X = M.solve(V);
128+
math::Point Ctr(X.X(), X.Y(), X.Z());
129+
return Ctr;
130+
}
88131
/*----------------------------------------------------------------------------*/
89132
TCoord Tetrahedron::getVolume() const
90133
{

math/src/Triangle.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ Triangle::getCenter() const {
9494
return pt;
9595
}
9696
/*----------------------------------------------------------------------------*/
97+
Point Triangle::getCircumcenter() const
98+
{
99+
math::Point A = m_pnts[0];
100+
math::Point B = m_pnts[1];
101+
math::Point C = m_pnts[2];
102+
double xA = A.X();
103+
double yA = A.Y();
104+
double xB = B.X();
105+
double yB = B.Y();
106+
double xC = C.X();
107+
double yC = C.Y();
108+
double S = area();
109+
double xO = ((xA*xA+yA*yA)*(yB-yC)-(xB*xB+yB*yB)*(yA-yC)+(xC*xC+yC*yC)*(yA-yB))*(1./(4.*S));
110+
double yO = -((xA*xA+yA*yA)*(xB-xC)-(xB*xB+yB*yB)*(xA-xC)+(xC*xC+yC*yC)*(xA-xB))*(1./(4.*S));
111+
math::Point Ctr(xO, yO, 0.);
112+
return Ctr;
113+
}
114+
/*----------------------------------------------------------------------------*/
97115
double
98116
Triangle::computeScaledJacobian2D() const
99117
{

medialaxis/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ set(GMDS_SRC
2121
src/MedialAxis3D.cpp
2222
src/MedialAxis3DBuilder.cpp
2323
src/CrossField.cpp
24+
src/NonConformalHalfEdge.cpp
25+
inc/gmds/medialaxis/NonConformalHalfEdge.h
26+
src/QuantizationSolver.cpp
27+
inc/gmds/medialaxis/QuantizationSolver.h
28+
src/QuantizationGraph.cpp
29+
inc/gmds/medialaxis/QuantizationGraph.h
2430
)
2531
#==============================================================================
2632
add_library(${GMDS_LIB} ${GMDS_INC} ${GMDS_SRC})
@@ -64,7 +70,22 @@ endif(WITH_TEST)
6470
#==============================================================================
6571
# EXECUTABLE
6672
#==============================================================================
67-
add_executable(medialaxis_exec src/main.cpp)
73+
add_executable(medialaxis_exec src/main_medax_build.cpp)
6874
target_link_libraries(medialaxis_exec PRIVATE ${GMDS_LIB})
6975
target_compile_features(medialaxis_exec PUBLIC cxx_std_14)
70-
install(TARGETS medialaxis_exec)
76+
install(TARGETS medialaxis_exec)
77+
78+
add_executable(medialaxis_crossfield_exec src/main_crossfield.cpp)
79+
target_link_libraries(medialaxis_crossfield_exec PRIVATE ${GMDS_LIB})
80+
target_compile_features(medialaxis_crossfield_exec PUBLIC cxx_std_14)
81+
install(TARGETS medialaxis_crossfield_exec)
82+
83+
add_executable(medialaxis_block_decomp_exec src/main_block_decomp.cpp)
84+
target_link_libraries(medialaxis_block_decomp_exec PRIVATE ${GMDS_LIB})
85+
target_compile_features(medialaxis_block_decomp_exec PUBLIC cxx_std_14)
86+
install(TARGETS medialaxis_block_decomp_exec)
87+
88+
add_executable(quantization_exec src/main_quantization.cpp)
89+
target_link_libraries(quantization_exec PRIVATE ${GMDS_LIB})
90+
target_compile_features(quantization_exec PUBLIC cxx_std_14)
91+
install(TARGETS quantization_exec)

medialaxis/inc/gmds/medialaxis/MedialAxis2D.h

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ class LIB_GMDS_MEDIALAXIS_API MedialAxis2D
130130
*/
131131
void setMedialPointType();
132132

133+
/*-------------------------------------------------------------------------*/
134+
/** \brief Get the medial point type
135+
* @param AId medial point id
136+
*/
137+
int getMedialPointType(TCellID AId);
138+
133139
/*-------------------------------------------------------------------------*/
134140
/** \brief Set the medial edge type
135141
* @param
@@ -228,6 +234,13 @@ class LIB_GMDS_MEDIALAXIS_API MedialAxis2D
228234
*/
229235
void checkSingularities(const double& AOrthogonalityDefaultTol);
230236

237+
/*-------------------------------------------------------------------------*/
238+
/** \brief Check if singularities are close to an intersection point up to ANbPoints points. If it is the case,
239+
* move the singularity to the IP.
240+
* @param ANbPoints a number of points
241+
*/
242+
void moveSingularitiesToIPs(const double& ANbPoints);
243+
231244
/*-------------------------------------------------------------------------*/
232245
/** \brief Get a point's adjacent point with respect to one of its edges
233246
* @param A medial point id and a medial edge id.
@@ -348,6 +361,125 @@ class LIB_GMDS_MEDIALAXIS_API MedialAxis2D
348361
*/
349362
Eigen::MatrixXd constraintMatrix();
350363

364+
/*-------------------------------------------------------------------------*/
365+
/** \brief Return the given node's neighbouring node of the topological representation with respect to the given edge
366+
* @param AN, AE a node and an edge which contains the node
367+
*/
368+
Node getNextSingularNode(Node &AN, Edge &AE);
369+
370+
/*-------------------------------------------------------------------------*/
371+
/** \brief Return the given edge's neighbouring edge of the topological representation with respect to the given node
372+
* @param AE, AN an edge and a node contained by th edge
373+
*/
374+
Edge getNextMedialSection(Edge &AE, Node &AN);
375+
376+
/*-------------------------------------------------------------------------*/
377+
/** \brief Wander around the medial axis topological representation
378+
* @param
379+
*/
380+
void browseTopoRep();
381+
382+
/*-------------------------------------------------------------------------*/
383+
/** \brief Build the degrees of freedom graph nodes
384+
* @param
385+
*/
386+
void buildDofGraphNodes();
387+
388+
/*-------------------------------------------------------------------------*/
389+
/** \brief Build the degrees of freedom edge corresponding to the two given sections of type 0 and 0,
390+
* oriented by the two given sides (0 = left, 1 = right)
391+
* @param ASection1, ASection2, ASide1, ASide2
392+
*/
393+
void dofEdge00(Edge &ASection1, Edge &ASection2, int ASide1, int ASide2);
394+
395+
/*-------------------------------------------------------------------------*/
396+
/** \brief Build the degrees of freedom edges corresponding to the two given sections of type 1 and 1,
397+
* oriented by the two given sides (0 = left, 1 = right)
398+
* @param ASection1, ASection2, ASide1, ASide2
399+
*/
400+
void dofEdges11(Edge &ASection1, Edge &ASection2, int ASide1, int ASide2);
401+
402+
/*-------------------------------------------------------------------------*/
403+
/** \brief Build the degrees of freedom edges corresponding to the two given sections of type 0 and 1,
404+
* oriented by the two given sides (0 = left, 1 = right)
405+
* @param ASection1, ASection2, ASide1, ASide2
406+
*/
407+
void dofEdges01(Edge &ASection1, Edge &ASection2, int ASide1, int ASide2);
408+
409+
/*-------------------------------------------------------------------------*/
410+
/** \brief Build the degrees of freedom edges corresponding to the two given sections of type 1 and 0,
411+
* oriented by the two given sides (0 = left, 1 = right)
412+
* @param ASection1, ASection2, ASide1, ASide2
413+
*/
414+
void dofEdges10(Edge &ASection1, Edge &ASection2, int ASide1, int ASide2);
415+
416+
/*-------------------------------------------------------------------------*/
417+
/** \brief Build the degrees of freedom edges corresponding to the right side of the path formed by the two given edges
418+
* @param ASection1, ASection2
419+
*/
420+
void dofEdges(Edge &ASection1, Edge &ASection2);
421+
422+
/*-------------------------------------------------------------------------*/
423+
/** \brief Build the degrees of freedom graph edges
424+
* @param
425+
*/
426+
void buildDofGraphEdges();
427+
428+
/*-------------------------------------------------------------------------*/
429+
/** \brief Set the connectivity of the quantization degrees of freedom graph
430+
* @param
431+
*/
432+
void setDofGraphConnectivity();
433+
434+
/*-------------------------------------------------------------------------*/
435+
/** \brief Build a solution to the quantization problem in the case without cycle
436+
* @param
437+
*/
438+
void buildQuantizationWithoutCycleSolution();
439+
440+
/*-------------------------------------------------------------------------*/
441+
/** \brief Build the nodes of the medial axis based block decomposition
442+
* @param
443+
*/
444+
void buildBlockDecompMedialAndBoundaryNodes();
445+
446+
/*-------------------------------------------------------------------------*/
447+
/** \brief Write the block decomposition
448+
* @param
449+
*/
450+
void writeBlockDecomp(std::basic_string<char> AFileName);
451+
452+
/*-------------------------------------------------------------------------*/
453+
/** \brief Build blocks
454+
* @param
455+
*/
456+
void buildSection2MedialAndBoundaryNodesAdjacency();
457+
458+
/*-------------------------------------------------------------------------*/
459+
/** \brief Build middle nodes
460+
* @param
461+
*/
462+
void buildMiddleNodes();
463+
464+
/*-------------------------------------------------------------------------*/
465+
/** \brief Build blocks
466+
* @param
467+
*/
468+
void buildBlocks();
469+
470+
/*-------------------------------------------------------------------------*/
471+
/** \brief Sort adjacent edges with respect to their angle with the x-axis.
472+
* @param AN a node
473+
*/
474+
std::vector<Edge> sortedAdjacentEdges(Node &AN);
475+
476+
/*-------------------------------------------------------------------------*/
477+
/** \brief Take an edge and a node belonging to the edge. Return the edges closest to
478+
* the given edge in the list of sorted edges of n.
479+
* @param AE, AN an edge and a node
480+
*/
481+
std::vector<Edge> neighbouringEdges(Edge &AE, Node &AN);
482+
351483
private:
352484

353485
// Geometrical representation of the medial axis
@@ -357,8 +489,12 @@ class LIB_GMDS_MEDIALAXIS_API MedialAxis2D
357489
std::vector<Node> m_singular_nodes;
358490
std::vector<double> m_singularity_indexes;
359491

360-
// Topological representation of the medial axis (used for quantisation)
492+
// Topological representation of the medial axis (used for quantization)
361493
Mesh* m_topological_representation;
494+
// Quantization degrees of freedom graph
495+
Mesh* m_dof_graph;
496+
// Topology of a medial axis based block decomposition
497+
Mesh* m_ma_block_decomposition;
362498
};
363499
/*----------------------------------------------------------------------------*/
364500
} // end namespace medialaxis

medialaxis/inc/gmds/medialaxis/MedialAxis2DBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class LIB_GMDS_MEDIALAXIS_API MedialAxis2DBuilder{
3838
/** @brief Constructor.
3939
* @param
4040
*/
41+
4142
explicit MedialAxis2DBuilder(Mesh &AMesh);
4243

4344
public:

medialaxis/inc/gmds/medialaxis/MedialAxisMath.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,35 @@
1010
#include <gmds/math/Tetrahedron.h>
1111
#include <gmds/math/Matrix.h>
1212
#include <gmds/math/Vector.h>
13+
#include <gmds/ig/Mesh.h>
1314
using namespace gmds;
1415

15-
// Computes the circumcenter of a triangle
16-
math::Point circumcenter(const math::Triangle& ATri);
17-
18-
// Computes the circumcenter of a tetrahedron
19-
math::Point circumcenterTetra(const math::Tetrahedron& ATetra);
20-
2116
// Computes the maximum distance to a sphere 1 of a point of a sphere 2 which doesn't belong to the sphere 1
2217
double maxRange(const math::Point& ACenter1, const double& ARadius1, const math::Point& ACenter2, const double& ARadius2);
2318

19+
// Compute the oriented angle between two 2D vectors, the result is in [-pi,pi[;
20+
double oriented_angle(const math::Vector &AV1, const math::Vector &AV2);
21+
22+
// Return the vector corresponding to the given edge with first node the given node
23+
math::Vector edge2vec(const gmds::Edge &AE, const gmds::Node &AN);
24+
25+
// Return the common node, if it exists, of twe edges
26+
Node getCommonNode(const Edge &AE1, const Edge &AE2);
27+
28+
// Takes a node and a list of edges containing this node. Return a list of the sorted edges, minimizing the
29+
// rotation between two consecutive edges
30+
std::vector<Edge> sortEdges(Node &AN, std::vector<Edge> &AV);
31+
32+
// Useful functions for oriented graphs represented by a mesh
33+
std::vector<Node> getNextNodes(Node &AN);
34+
void propagateValue(Node &AN, Variable<double> &AVar);
35+
bool isASource(Node &AN);
36+
bool isAWell(Node &AN);
37+
int NbWells(Mesh* AMesh);
38+
39+
// Orientate edges of a face in the direct sense
40+
std::vector<Edge> orientateEdges(Face &AF);
41+
42+
// Regroup aligned conformal edges of a face
43+
std::vector<std::vector<Edge>> groupsOfAlignedEdges(Face &AF);
2444
#endif // GMDS_MEDIALAXISMATH_H

0 commit comments

Comments
 (0)