Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfMeshQuality.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego and Tien Comlekoglu
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
24
25#ifndef _MODELS_VERTEX_SOLVER_TFMESHQUALITY_H_
26#define _MODELS_VERTEX_SOLVER_TFMESHQUALITY_H_
27
28
29#include "tfMeshObj.h"
30
31#include <tf_port.h>
32
33#include <mutex>
34#include <set>
35#include <unordered_set>
36#include <vector>
37
38
39namespace TissueForge::models::vertex {
40
41
42 class Mesh;
43
44
48 struct MeshQualityOperation {
49
50 enum Flag : unsigned int {
51 None = 0,
52 Active = 1 << 0,
53 Custom = 1 << 1
54 };
55
56 unsigned int flags;
57
63 std::vector<int> targets;
64
66 std::set<MeshQualityOperation*> prev;
67
69 std::set<MeshQualityOperation*> next;
70
72 std::mutex lock;
73
74 MeshQualityOperation(Mesh *_mesh);
75
76 virtual ~MeshQualityOperation() {};
77
86 HRESULT appendNext(MeshQualityOperation *_next);
87
93 HRESULT removeNext(MeshQualityOperation *_next);
94
98 std::set<MeshQualityOperation*> upstreams() const;
99
103 std::set<MeshQualityOperation*> downstreams() const;
104
108 std::set<MeshQualityOperation*> headOperations() const;
109
113 virtual HRESULT validate() { return S_OK; }
114
120 virtual bool check() { return !(flags & Flag::None); };
121
125 virtual void prep() {}
126
130 virtual size_t numNewVertices() const { return 0; };
131
135 virtual size_t numNewSurfaces() const { return 0; };
136
140 virtual size_t numNewBodies() const { return 0; };
141
147 virtual std::vector<int> implement() { return {}; }
148
149 protected:
150
151 Mesh *mesh;
152 };
153
154
160 struct CAPI_EXPORT CustomQualityOperation : MeshQualityOperation {
161
162 typedef bool (*OperationCheck)();
163 typedef void (*OperationPrep)();
164 typedef std::vector<int> (*OperationFunction)(std::vector<int>);
165
166 OperationCheck *opCheck;
167 OperationPrep *opPrep;
168 OperationFunction *opFunc;
169
170 CustomQualityOperation(Mesh *_mesh, OperationFunction *_opFunc, OperationCheck *_opCheck=NULL, OperationPrep *_opPrep=NULL) :
171 MeshQualityOperation(_mesh),
172 opFunc{_opFunc},
173 opCheck{_opCheck},
174 opPrep{_opPrep}
175 {
176 flags = Flag::Active | Flag::Custom;
177 };
178
179 virtual ~CustomQualityOperation() {
180 if(opCheck) {
181 delete opCheck;
182 opCheck = 0;
183 }
184 delete opFunc;
185 opFunc = 0;
186 };
187
188 bool check() override {
189 if(opCheck) return (*opCheck)();
190 return true;
191 }
192
193 void prep() override {
194 if(opPrep) (*opPrep)();
195 }
196
197 std::vector<int> implement() override { return (*opFunc)(targets); }
198 };
199
200
205 class CAPI_EXPORT MeshQuality {
206
212 FloatP_t vertexMergeDist;
213
219 FloatP_t surfaceDemoteArea;
220
226 FloatP_t bodyDemoteVolume;
227
231 FloatP_t edgeSplitDist;
232
236 bool collision2D;
237
239 bool _working;
240
241 std::unordered_set<unsigned int> excludedVertices;
242
243 std::unordered_set<unsigned int> excludedSurfaces;
244
245 std::unordered_set<unsigned int> excludedBodies;
246
247 public:
248
249 MeshQuality(
250 const FloatP_t &vertexMergeDistCf=0.0001,
251 const FloatP_t &surfaceDemoteAreaCf=0.0001,
252 const FloatP_t &bodyDemoteVolumeCf=0.0001,
253 const FloatP_t &_edgeSplitDistCf=2.0
254 );
255
259 std::string str() const;
260
264 std::string toString();
265
271 static MeshQuality fromString(const std::string &s);
272
277
283 const bool working() const { return _working; }
284
288 FloatP_t getVertexMergeDistance() const { return vertexMergeDist; };
289
295 HRESULT setVertexMergeDistance(const FloatP_t &_val);
296
300 FloatP_t getSurfaceDemoteArea() const { return surfaceDemoteArea; };
301
307 HRESULT setSurfaceDemoteArea(const FloatP_t &_val);
308
312 FloatP_t getBodyDemoteVolume() const { return bodyDemoteVolume; }
313
319 HRESULT setBodyDemoteVolume(const FloatP_t &_val);
320
324 FloatP_t getEdgeSplitDist() const { return edgeSplitDist; };
325
331 HRESULT setEdgeSplitDist(const FloatP_t &_val);
332
338 bool getCollision2D() const { return collision2D; }
339
345 HRESULT setCollision2D(const bool &_collision2D);
346
352 HRESULT excludeVertex(const unsigned int &id);
353
359 HRESULT excludeSurface(const unsigned int &id);
360
366 HRESULT excludeBody(const unsigned int &id);
367
375 HRESULT includeVertex(const unsigned int &id);
376
384 HRESULT includeSurface(const unsigned int &id);
385
393 HRESULT includeBody(const unsigned int &id);
394
398 std::unordered_set<unsigned int> getExcludedVertices() const { return excludedVertices; }
399
403 std::unordered_set<unsigned int> getExcludedSurfaces() const { return excludedSurfaces; }
404
408 std::unordered_set<unsigned int> getExcludedBodies() const { return excludedBodies; }
409 };
410}
411
412
413#endif // _MODELS_VERTEX_SOLVER_TFMESHQUALITY_H_
Contains all Vertex, Surface and Body instances.
Definition tfMesh.h:52
HRESULT excludeBody(const unsigned int &id)
Exclude a body from quality operations.
HRESULT setBodyDemoteVolume(const FloatP_t &_val)
Set the volume below which a body is scheduled to become a vertex.
HRESULT excludeVertex(const unsigned int &id)
Exclude a vertex from quality operations.
static MeshQuality fromString(const std::string &s)
Create an instance from a JSON string representation.
const bool working() const
Test whether quality operations are being done.
Definition tfMeshQuality.h:283
FloatP_t getBodyDemoteVolume() const
Get the volume below which a body is scheduled to become a vertex.
Definition tfMeshQuality.h:312
HRESULT includeVertex(const unsigned int &id)
Include a vertex from quality operations.
std::unordered_set< unsigned int > getExcludedVertices() const
Get the current set of excluded vertices.
Definition tfMeshQuality.h:398
FloatP_t getEdgeSplitDist() const
Get the distance at which two vertices are seperated when a vertex is split.
Definition tfMeshQuality.h:324
std::unordered_set< unsigned int > getExcludedBodies() const
Get the current set of excluded bodies.
Definition tfMeshQuality.h:408
HRESULT setVertexMergeDistance(const FloatP_t &_val)
Set the distance below which two vertices are scheduled for merging.
HRESULT doQuality()
Perform quality operations work.
HRESULT excludeSurface(const unsigned int &id)
Exclude a surface from quality operations.
HRESULT includeSurface(const unsigned int &id)
Include a surface from quality operations.
std::unordered_set< unsigned int > getExcludedSurfaces() const
Get the current set of excluded surfaces.
Definition tfMeshQuality.h:403
FloatP_t getVertexMergeDistance() const
Get the distance below which two vertices are scheduled for merging.
Definition tfMeshQuality.h:288
HRESULT setCollision2D(const bool &_collision2D)
Set whether 2D collisions are implemented.
std::string toString()
Get a JSON string representation.
HRESULT setEdgeSplitDist(const FloatP_t &_val)
Set the distance at which two vertices are seperated when a vertex is split.
std::string str() const
Get a summary string.
FloatP_t getSurfaceDemoteArea() const
Get the area below which a surface is scheduled to become a vertex.
Definition tfMeshQuality.h:300
HRESULT setSurfaceDemoteArea(const FloatP_t &_val)
Set the area below which a surface is scheduled to become a vertex.
HRESULT includeBody(const unsigned int &id)
Include a body from quality operations.
bool getCollision2D() const
Get whether 2D collisions are implemented.
Definition tfMeshQuality.h:338
std::vector< int > implement() override
Implement this operation.
Definition tfMeshQuality.h:197
bool check() override
Check whether this operation is still valid.
Definition tfMeshQuality.h:188
void prep() override
Do all prep, checks and planning for this operation.
Definition tfMeshQuality.h:193
std::set< MeshQualityOperation * > upstreams() const
Compute all upstream operations.
virtual void prep()
Do all prep, checks and planning for this operation.
Definition tfMeshQuality.h:125
std::set< MeshQualityOperation * > headOperations() const
Compute all upstream operations that have no dependencies.
virtual size_t numNewSurfaces() const
Returns how many surfaces will be created by this operation.
Definition tfMeshQuality.h:135
virtual HRESULT validate()
Validate this operation.
Definition tfMeshQuality.h:113
std::set< MeshQualityOperation * > next
Definition tfMeshQuality.h:69
virtual std::vector< int > implement()
Implement this operation.
Definition tfMeshQuality.h:147
std::mutex lock
Definition tfMeshQuality.h:72
virtual size_t numNewBodies() const
Returns how many bodies will be created by this operation.
Definition tfMeshQuality.h:140
virtual size_t numNewVertices() const
Returns how many vertices will be created by this operation.
Definition tfMeshQuality.h:130
virtual bool check()
Check whether this operation is still valid.
Definition tfMeshQuality.h:120
std::set< MeshQualityOperation * > prev
Definition tfMeshQuality.h:66
std::set< MeshQualityOperation * > downstreams() const
Compute all downstream operations.
HRESULT appendNext(MeshQualityOperation *_next)
Add an operation to the list of next operations.
HRESULT removeNext(MeshQualityOperation *_next)
Remove an operation to the list of next operations.
std::vector< int > targets
Target mesh objects.
Definition tfMeshQuality.h:63
int32_t HRESULT
Definition tf_port.h:255