Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfMesh.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
25#ifndef _MODELS_VERTEX_SOLVER_TFMESH_H_
26#define _MODELS_VERTEX_SOLVER_TFMESH_H_
27
28#define TFMESHINV_INCR 100
29
30#include "tfVertex.h"
31#include "tfSurface.h"
32#include "tfBody.h"
33#include "tfMeshQuality.h"
34
35#include <mutex>
36#include <set>
37#include <vector>
38#include <unordered_map>
39
40
41namespace TissueForge::models::vertex {
42
43
44 struct MeshRenderer;
45 struct MeshSolver;
46
47
52 class CAPI_EXPORT Mesh {
53
54 std::vector<Vertex> *vertices;
55 size_t nr_vertices;
56 std::vector<Surface> *surfaces;
57 size_t nr_surfaces;
58 std::vector<Body> *bodies;
59 size_t nr_bodies;
60
61 std::set<unsigned int> vertexIdsAvail, surfaceIdsAvail, bodyIdsAvail;
62 std::unordered_map<int, Vertex*> verticesByPID;
63 bool isDirty;
64 MeshSolver *_solver = NULL;
65 MeshQuality *_quality;
66 std::mutex meshLock;
67
68 HRESULT incrementVertices(const size_t &numIncr=TFMESHINV_INCR);
69 HRESULT incrementSurfaces(const size_t &numIncr=TFMESHINV_INCR);
70 HRESULT incrementBodies(const size_t &numIncr=TFMESHINV_INCR);
71 HRESULT allocateVertex(Vertex **obj);
72 HRESULT allocateSurface(Surface **obj);
73 HRESULT allocateBody(Body **obj);
74 HRESULT allocateVertices(Vertex*** objs, const size_t& numObjs);
75 HRESULT allocateSurfaces(Surface*** objs, const size_t& numObjs);
76 HRESULT allocateBodies(Body*** objs, const size_t& numObjs);
77
78 public:
79
80 Mesh();
81
82 ~Mesh();
83
87 std::string str() const;
88
92 std::string toString();
93
99 bool hasQuality() const { return _quality; }
100
105
112
118 bool qualityWorking() const { return hasQuality() && getQuality().working(); }
119
125 HRESULT ensureAvailableVertices(const size_t &numAlloc);
126
132 HRESULT ensureAvailableSurfaces(const size_t &numAlloc);
133
139 HRESULT ensureAvailableBodies(const size_t &numAlloc);
140
147 HRESULT create(Vertex **obj, const unsigned int &pid);
148
155 HRESULT create(Vertex*** objs, const std::vector<unsigned int>& pids);
156
163
170 HRESULT create(Surface*** objs, const size_t& numObjs);
171
178
185 HRESULT create(Body*** objs, const size_t& numObjs);
186
190 static Mesh *get();
191
195 void lock() { this->meshLock.lock(); }
196
200 void unlock() { this->meshLock.unlock(); }
201
209 Vertex *findVertex(const FVector3 &pos, const FloatP_t &tol = 0.0001);
210
216 Vertex *getVertexByPID(const unsigned int &pid) const;
217
223 Vertex *getVertex(const unsigned int &idx);
224
230 Surface *getSurface(const unsigned int &idx);
231
237 Body *getBody(const unsigned int &idx);
238
242 unsigned int numVertices() const { return nr_vertices; }
243
247 unsigned int numSurfaces() const { return nr_surfaces; }
248
252 unsigned int numBodies() const { return nr_bodies; }
253
257 unsigned int sizeVertices() const { return vertices->size(); }
258
262 unsigned int sizeSurfaces() const { return surfaces->size(); }
263
267 unsigned int sizeBodies() const { return bodies->size(); }
268
274 bool validate();
275
280
288 bool connected(const Vertex *v1, const Vertex *v2) const;
289
297 bool connected(const Surface *s1, const Surface *s2) const;
298
306 bool connected(const Body *b1, const Body *b2) const;
307
314
321 HRESULT remove(Vertex** v, const size_t& numObjs);
322
329
336 HRESULT remove(Surface** s, const size_t& numObjs);
337
344
351 HRESULT remove(Body** b, const size_t& numObjs);
352
360 bool is3D() const { return nr_bodies > 0; }
361
362 friend MeshRenderer;
363 friend MeshSolver;
364
365 };
366
367};
368
369#endif // _MODELS_VERTEX_SOLVER_TFMESH_H_
The mesh body is a volume-enclosing object of mesh surfaces.
Definition tfBody.h:59
Contains all Vertex, Surface and Body instances.
Definition tfMesh.h:52
Vertex * getVertexByPID(const unsigned int &pid) const
Get the vertex for a given particle id.
HRESULT remove(Vertex **v, const size_t &numObjs)
Remove vertices from the mesh; all dependent surfaces and bodies are also removed.
unsigned int numBodies() const
Get the number of bodies.
Definition tfMesh.h:252
TissueForge::models::vertex::MeshQuality & getQuality() const
Get the mesh quality instance.
Definition tfMesh.h:104
bool qualityWorking() const
Test whether a mesh quality instance is working on the mesh.
Definition tfMesh.h:118
HRESULT remove(Surface *s)
Remove a surface from the mesh; all dependent bodies are also removed.
HRESULT ensureAvailableBodies(const size_t &numAlloc)
Ensure that there are a given number of allocated bodies.
HRESULT create(Surface **obj)
Create a surface.
bool connected(const Surface *s1, const Surface *s2) const
Check whether two surfaces are connected.
Surface * getSurface(const unsigned int &idx)
Get the surface at a location in the list of surfaces.
HRESULT remove(Body **b, const size_t &numObjs)
Remove bodies from the mesh.
HRESULT create(Vertex **obj, const unsigned int &pid)
Create a vertex.
HRESULT create(Vertex ***objs, const std::vector< unsigned int > &pids)
Create vertices.
bool is3D() const
Test whether the mesh is 3D.
Definition tfMesh.h:360
unsigned int sizeSurfaces() const
Get the size of the list of surfaces.
Definition tfMesh.h:262
Vertex * getVertex(const unsigned int &idx)
Get the vertex at a location in the list of vertices.
HRESULT remove(Body *b)
Remove a body from the mesh.
bool connected(const Vertex *v1, const Vertex *v2) const
Check whether two vertices are connected.
HRESULT remove(Vertex *v)
Remove a vertex from the mesh; all dependent surfaces and bodies are also removed.
std::string toString()
Get a JSON string representation.
static Mesh * get()
Get the mesh.
unsigned int sizeBodies() const
Get the size of the list of bodies.
Definition tfMesh.h:267
bool validate()
Validate state of the mesh.
HRESULT makeDirty()
Manually notify that the mesh has been changed.
Vertex * findVertex(const FVector3 &pos, const FloatP_t &tol=0.0001)
Find a vertex in this mesh.
void unlock()
Unlocks the mesh for thread-safe operations.
Definition tfMesh.h:200
unsigned int sizeVertices() const
Get the size of the list of vertices.
Definition tfMesh.h:257
HRESULT create(Body **obj)
Create a body.
Body * getBody(const unsigned int &idx)
Get the body at a location in the list of bodies.
HRESULT create(Body ***objs, const size_t &numObjs)
Create bodies.
HRESULT create(Surface ***objs, const size_t &numObjs)
Create surfaces.
bool connected(const Body *b1, const Body *b2) const
Check whether two bodies are connected.
bool hasQuality() const
Test whether this mesh has a mesh quality instance.
Definition tfMesh.h:99
void lock()
Locks the mesh for thread-safe operations.
Definition tfMesh.h:195
HRESULT ensureAvailableSurfaces(const size_t &numAlloc)
Ensure that there are a given number of allocated surfaces.
HRESULT ensureAvailableVertices(const size_t &numAlloc)
Ensure that there are a given number of allocated vertices.
unsigned int numSurfaces() const
Get the number of surfaces.
Definition tfMesh.h:247
HRESULT remove(Surface **s, const size_t &numObjs)
Remove surfaces from the mesh; all dependent bodies are also removed.
std::string str() const
Get a summary string.
unsigned int numVertices() const
Get the number of vertices.
Definition tfMesh.h:242
HRESULT setQuality(TissueForge::models::vertex::MeshQuality *quality)
Set the mesh quality instance.
An object that schedules topological operations on a mesh to maintain its quality.
Definition tfMeshQuality.h:205
The mesh surface is an area-enclosed object of implicit mesh edges defined by mesh vertices.
Definition tfSurface.h:65
The mesh vertex is a volume of a mesh centered at a point in a space.
Definition tfVertex.h:71
Definition tfMeshRenderer.h:35
Vertex model mesh solver.
Definition tfMeshSolver.h:148
int32_t HRESULT
Definition tf_port.h:255