GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmTriSurfaceDiscontinuity.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2023 by Carlos Augusto Teixeira Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_TRISURFACE_DISCONTINUITY_H_
25#define _GEMA_TRISURFACE_DISCONTINUITY_H_
26
27#include "gmDiscontinuity.h"
28#include "gmBVHAcceleration.h"
29#include "gmCellMesh.h"
30
33{
34public:
35 enum class CellIntersectionType {
36 COMPLETE,
37 PARTIAL,
38 EXTENDED,
39 AMBIGUOUS,
40 EMPTY,
41 };
42
43 const char* ciTypeToStr(const CellIntersectionType t) const {
44 switch (t) {
45 case CellIntersectionType::EMPTY:
46 return "empty";
47 case CellIntersectionType::COMPLETE:
48 return "complete";
49 case CellIntersectionType::PARTIAL:
50 return "partial";
51 case CellIntersectionType::EXTENDED:
52 return "extended";
53 case CellIntersectionType::AMBIGUOUS:
54 return "ambiguous";
55 default:
56 return "unknow";
57 }
58 }
59
63
65
66 // See comments on the base class
67 virtual int numElements() const { return _numTriangles; };
68
69 // See comments on the base class
70 virtual int numIntersections() const { return _intPoint.size(); }
71
72 virtual bool extendGeometry(GmCellMesh* sMesh, double size, const GmLogCategory& logger);
73
75 virtual int numPoints() const { return _numPoints; }
76
78 const double* pointCoordinates() const { return _pointCoord; }
79
81 int numTriangles() const { return _numTriangles; }
82
83 int numOriginalTriangles() const { return _originalNumTriangles; }
84
86 const int* triangleIncidences() const { return _triList; }
87
88 const QHash<int, CellIntersection>& intersectionEdgeList() const { return _cellIntersection; }
89 const QHash<int, CellIntersectionType>& intersectionTypeList() const { return _cellIntersectionType; }
90 const QVector<bool>& validIntersectionPointList() const { return _validIntPoint; }
91 const QSet<int>& extendedCellSet() const { return _extendedCell; }
92 const QVector<RayIntersection>& intersectionPointList() const { return _intPoint; }
93
94 virtual void clearGeometry();
95
96 virtual void printGeometry(const GmLogCategory& logger, GmLogLevel level) const;
97
98 // See comments on the base class
99 virtual size_t usedGeometryMemory() const { return _numPoints * 3 * sizeof(double) + _numTriangles * 3 * sizeof(int); }
100
101 virtual size_t usedIntersectionMemory() const {
102
103 return _intPoint.size() * sizeof(RayIntersection) +
104 std::accumulate(_cellIntersection.begin(),
105 _cellIntersection.end(),
106 (size_t)_cellIntersection.size() * sizeof(CellIntersection),
107 [](size_t v, CellIntersection c) {
108 return v + c.size() * sizeof(EdgeId);
109 }
110 );
111 }
112
113 virtual bool findIntersections(const GmLogCategory& logger);
114 virtual void printIntersections(const GmLogCategory& logger, GmLogLevel level) const;
115
116 const BoolMat& getOrBuildEEMatrix(const GmCellType type);
117 const BoolMat& getOrBuildFEMatrix(const GmCellType type);
118
119private:
121 GmTriSurfaceDiscontinuity(const GmDiscontinuitySet* ds, int index, QString id, int groupIndex, const QVector<int>& psIndex)
122 : GmDiscontinuity(ds, index, id, groupIndex, psIndex), _numPoints(0), _numTriangles(0), _pointCoord(NULL), _triList(NULL), _invalidCellCount(0), _validCellCount(0), _originalNumTriangles(0) {}
123
128 virtual void setGeometry(double* dvec, int nd, int* ivec, int ni)
129 {
130 assert(dvec && ivec);
131 _numPoints = nd;
132 _originalNumTriangles = _numTriangles = ni;
133 _pointCoord = dvec;
134 _triList = ivec;
135
136 }
137 virtual bool loadGeometryFromTable(LuaTable& tab, const GmLogCategory& logger);
138
139 friend class GmDiscontinuitySet;
140
143 double* _pointCoord;
144 int* _triList;
145
146 //Extended surface data
147 int _originalNumTriangles;
148
149 //Map storing <cellId, vector<edgeGlobalId, edgeLocalId>>
150
151 QHash<int, CellIntersection> _cellIntersection;
152 QHash<int, CellIntersectionType> _cellIntersectionType;
153 QSet<int> _extendedCell;
154
155 //Map storing <edgeGlobalId, RayIntersection>
156 QVector<RayIntersection> _intPoint;
157 QVector<bool> _validIntPoint;
158 QSet<int> _ambiguousCells;
159 int _invalidCellCount;
160 int _validCellCount;
161
162 int markAmbiguousEdges();
163
168 CellIntersectionType reorderIntersections(CellIntersection& ci, const GmCellType type, bool removeInvalid = true);
169
170 CellIntersection correctOrientation(CellIntersection& ci);
171
172 QVector<EdgeId> popEdgesOnFace(QVector<EdgeId>& edges, const QVector<bool>& FELine);
173
174
175 //Edge-Edge index
177 //Edge-Face index
179 //Node-Node -> edgeId index
181 //Given an faceEdge map, build a matrix[edge1][edge2] = true
182 // if the edge1 and edge2 have a face in common
183 BoolMat buildEEMatrix(const QVector<QVector<int>>& faceEdge, int nedges);
184 //Given an edgeFace map, build a matrix[edge][face] = true
185 // if the face contais edge
186 BoolMat buildFEMatrix(const QVector<QVector<int>>& edgeFace, int nface);
187
188 //Checks wether valid cells are globally consistenty with no holes on a face.
189 bool checkConsistency();
190
191 void clearIntersections() {
192 _cellIntersection.clear();
193 _cellIntersectionType.clear();
194 _intPoint.clear();
195 _validIntPoint.clear();
196 _ambiguousCells.clear();
197 _extendedCell.clear();
198 _invalidCellCount = 0;
199 _validCellCount = 0;
200 }
201
203 friend QDataStream& operator<<(QDataStream&, const GmDiscontinuitySet&);
204 friend QDataStream& operator>>(QDataStream&, GmDiscontinuitySet&);
205
206 //To be removed after validation
207 void DebugCell(int cellId, GmMatrix& points, CellIntersection& ci);
208 void DebugSurface();
209 bool checkCoherence();
210};
211
212
213#endif // _GEMA_TRISURFACE_DISCONTINUITY_H_
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
The geometric representation for a single discontinuity from the Discontinuity set....
Definition gmDiscontinuity.h:38
int index() const
Returns this discontinuity index in the father set.
Definition gmDiscontinuity.h:44
QString id() const
Returns the discontinuity id (name)
Definition gmDiscontinuity.h:47
Base interface for providing discontinuity geometry information for spatial indices.
Definition gmDiscontinuitySet.h:59
Definition gmDiscontinuitySet.h:357
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Surface 3D representation for a discontinuity.
Definition gmTriSurfaceDiscontinuity.h:33
virtual void printGeometry(const GmLogCategory &logger, GmLogLevel level) const
Prints the discontinuity geometry information.
Definition gmTriSurfaceDiscontinuity.cpp:65
virtual size_t usedGeometryMemory() const
Returns an estimative of the memory used by the discontinuity geometry in bytes.
Definition gmTriSurfaceDiscontinuity.h:99
int * _triList
The list with triangle incidences. Size == _numTriangles * 3.
Definition gmTriSurfaceDiscontinuity.h:144
CellIntersectionType reorderIntersections(CellIntersection &ci, const GmCellType type, bool removeInvalid=true)
For each cellIntersection[i] reorder its edges indexes to form a polygon with the intersection points...
Definition gmTriSurfaceDiscontinuity.cpp:542
virtual ~GmTriSurfaceDiscontinuity()
Destructor.
Definition gmTriSurfaceDiscontinuity.cpp:45
double * _pointCoord
The coordinate vector. Size == _numPoints * 3.
Definition gmTriSurfaceDiscontinuity.h:143
virtual void setGeometry(double *dvec, int nd, int *ivec, int ni)
Sets the geometry. dvec should be a vector with coordinates (size nd * 3), nd the number of coordinat...
Definition gmTriSurfaceDiscontinuity.h:128
virtual int numPoints() const
Returns the number of surface points.
Definition gmTriSurfaceDiscontinuity.h:75
const int * triangleIncidences() const
Returns the incidence vector, organized as p11, p12, p13, p21, p22, p23, .... Size equal to numTriang...
Definition gmTriSurfaceDiscontinuity.h:86
virtual void clearGeometry()
Clears the original discontinuity geometry information, releasing memory.
Definition gmTriSurfaceDiscontinuity.cpp:54
virtual int numElements() const
A generic interface to return the original discontinuity data number of geometric elements....
Definition gmTriSurfaceDiscontinuity.h:67
virtual int numIntersections() const
A generic interface to return the number of intersections between the mesh and the user given geometr...
Definition gmTriSurfaceDiscontinuity.h:70
const double * pointCoordinates() const
Returns the surface coordinates vector, organized as x1, y1, z1, x2, y2, z2, .... Size equal to numPo...
Definition gmTriSurfaceDiscontinuity.h:78
virtual bool extendGeometry(GmCellMesh *sMesh, double size, const GmLogCategory &logger)
Definition gmTriSurfaceDiscontinuity.cpp:772
virtual size_t usedIntersectionMemory() const
Returns an estimative of the memory used by the intersection data in bytes.
Definition gmTriSurfaceDiscontinuity.h:101
virtual void printIntersections(const GmLogCategory &logger, GmLogLevel level) const
Prints the discontinuity-mesh intersection information.
Definition gmTriSurfaceDiscontinuity.cpp:674
virtual bool findIntersections(const GmLogCategory &logger)
Builds the element intersection list for this discontinuity.
Definition gmTriSurfaceDiscontinuity.cpp:84
int _numTriangles
The number of triangles in the surface.
Definition gmTriSurfaceDiscontinuity.h:142
int _numPoints
The number of points in the surface.
Definition gmTriSurfaceDiscontinuity.h:141
GmTriSurfaceDiscontinuity(const GmDiscontinuitySet *ds, int index, QString id, int groupIndex, const QVector< int > &psIndex)
Constructor.
Definition gmTriSurfaceDiscontinuity.h:121
int numTriangles() const
Returns the number of surface triangles.
Definition gmTriSurfaceDiscontinuity.h:81
Declaration of the gmBVHAcceleration class using https://github.com/madmann91/bvh/ header-only implem...
Declaration of the GmCellMesh interface class.
GmCellType
Mesh Cell types. Don't change type orders or add types without reading comments below.
Definition gmCellType.h:31
Declaration of the GmDiscontinuity class.
GmLogLevel
Available log levels list.
Definition gmLog.h:36
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
void clear()
void clear()
void clear()
int size() const const
Definition gmBVHAcceleration.h:36