Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfMeshObj.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_TFMESHOBJ_H_
26#define _MODELS_VERTEX_SOLVER_TFMESHOBJ_H_
27
28#include <tf_platform.h>
29#include <types/tf_types.h>
30
31#include <iostream>
32#include <unordered_set>
33#include <unordered_map>
34#include <vector>
35
36
37namespace TissueForge::models::vertex {
38
39
40 class Mesh;
41 class Vertex;
42 class Surface;
43 class Body;
44
48 enum MeshObjTypeLabel : unsigned int {
49 NONE = 0,
50 VERTEX = 1,
51 SURFACE = 2,
52 BODY = 3
53 };
54
55 #define MESHOBJ_CLASSDEF(oType) \
56 \
57 const int objectId() const { return _objId; } \
58 \
59 \
60 MeshObjTypeLabel objType() const { return oType; } \
61 \
62 \
63 HRESULT destroy(); \
64 \
65 \
66 bool validate(); \
67 \
68 \
69 HRESULT positionChanged();
70
71 #define MESHOBJ_INITOBJ \
72 _objId = -1;
73
74 #define MESHOBJ_DELOBJ
75
76 #define MESHBOJ_DEFINES_DECL(childType) \
77 bool defines(const childType *obj) const; \
78
79 #define MESHBOJ_DEFINES_DEF(parentAccessor) \
80 if(!obj) \
81 return false; \
82 for(auto &p : obj->parentAccessor()) \
83 if(p->objectId() == this->objectId()) \
84 return true; \
85 return false;
86
87 #define MESHOBJ_DEFINEDBY_DECL(parentType) \
88 bool definedBy(const parentType *obj) const;
89
90 #define MESHOBJ_DEFINEDBY_DEF \
91 return obj && obj->defines(this);
92
93
97 struct MeshObjActor {
98
102 virtual std::string name() const { return "MeshObjActor"; }
103
107 static std::string actorName() { return "MeshObjActor"; }
108
116 template <typename T, typename O>
117 static std::vector<T*> get(O *obj) {
118 std::vector<T*> result;
119 if(!obj)
120 return result;
121 for(auto &a : obj->actors)
122 if(strcmp(a->name().c_str(), T::actorName().c_str()) == 0)
123 result.push_back((T*)a);
124 return result;
125 }
126
130 virtual std::string toString();
131
139 virtual FloatP_t energy(const Surface *source, const Vertex *target) { return 0; }
140
148 virtual FVector3 force(const Surface *source, const Vertex *target) { return FVector3(0); }
149
157 virtual FloatP_t energy(const Body *source, const Vertex *target) { return 0; }
158
166 virtual FVector3 force(const Body *source, const Vertex *target) { return FVector3(0); }
167
168 };
169
170
176 struct MeshObjType {
177
179 int id = -1;
180
182 std::vector<MeshObjActor*> actors;
183
187 virtual MeshObjTypeLabel objType() const = 0;
188
192 virtual std::string str() const = 0;
193
194 };
195
196
202
206 virtual std::string name() { return "MeshObjTypePairActor"; }
207
211 static std::string actorName() { return "MeshObjTypePairActor"; }
212
219 HRESULT registerPair(const int &type1, const int &type2);
220
228
236 bool hasPair(const int &type1, const int &type2);
237
245 bool hasPair(MeshObjType *type1, MeshObjType *type2);
246
250 std::unordered_map<int, std::unordered_set<int> > getTypePairs() { return typePairs; };
251
252 protected:
253
254 std::unordered_map<int, std::unordered_set<int> > typePairs;
255
256 };
257
258}
259
260#endif // _MODELS_VERTEX_SOLVER_TFMESHOBJ_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
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
Base definition of how a mesh object acts on another mesh object.
Definition tfMeshObj.h:97
static std::vector< T * > get(O *obj)
Get a list of actors bound to a mesh object.
Definition tfMeshObj.h:117
virtual FloatP_t energy(const Body *source, const Vertex *target)
Calculate the energy of a source object acting on a target object.
Definition tfMeshObj.h:157
virtual std::string name() const
Name of the actor.
Definition tfMeshObj.h:102
virtual FVector3 force(const Surface *source, const Vertex *target)
Calculate the force that a source object exerts on a target object.
Definition tfMeshObj.h:148
virtual std::string toString()
Get a JSON string representation.
virtual FloatP_t energy(const Surface *source, const Vertex *target)
Calculate the energy of a source object acting on a target object.
Definition tfMeshObj.h:139
static std::string actorName()
Unique name of the actor.
Definition tfMeshObj.h:107
virtual FVector3 force(const Body *source, const Vertex *target)
Calculate the force that a source object exerts on a target object.
Definition tfMeshObj.h:166
Base mesh object type definition.
Definition tfMeshObj.h:176
std::vector< MeshObjActor * > actors
Definition tfMeshObj.h:182
virtual std::string str() const =0
Get a summary string.
virtual MeshObjTypeLabel objType() const =0
Get the mesh object type.
Base definition of how a mesh object of a type acts on another mesh object through interactions with ...
Definition tfMeshObj.h:201
virtual std::string name()
Name of the actor.
Definition tfMeshObj.h:206
bool hasPair(MeshObjType *type1, MeshObjType *type2)
Test whether a pair of types is registered with this actor.
HRESULT registerPair(MeshObjType *type1, MeshObjType *type2)
Register a pair of types for this actor.
HRESULT registerPair(const int &type1, const int &type2)
Register a pair of types for this actor.
bool hasPair(const int &type1, const int &type2)
Test whether a pair of types is registered with this actor.
std::unordered_map< int, std::unordered_set< int > > getTypePairs()
Get the type pair data.
Definition tfMeshObj.h:250
static std::string actorName()
Unique name of the actor.
Definition tfMeshObj.h:211
int32_t HRESULT
Definition tf_port.h:255
MeshObjTypeLabel
Mesh object type enum.
Definition tfMeshObj.h:48