Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfBody.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_TFBODY_H_
26#define _MODELS_VERTEX_SOLVER_TFBODY_H_
27
28#include <tf_port.h>
29
30#include <state/tfStateVector.h>
31
32#include "tf_mesh.h"
33
34#include <io/tfThreeDFMeshData.h>
35
36
37namespace TissueForge::models::vertex {
38
39
40 class Vertex;
41 struct VertexHandle;
42 class Surface;
43 struct SurfaceHandle;
44 class Mesh;
45
46 struct BodyHandle;
47 struct BodyType;
48 struct SurfaceType;
49
59 class CAPI_EXPORT Body {
60
62 int _objId;
63
64 public:
65
67 int typeId;
68
69 private:
70
72 std::vector<Surface*> surfaces;
73
75 FVector3 centroid;
76
78 FloatP_t area;
79
81 FloatP_t volume;
82
84 FloatP_t density;
85
86 public:
87
89 std::vector<MeshObjActor*> actors;
90
93
94 Body();
95 ~Body();
96
98 static BodyHandle create(const std::vector<SurfaceHandle> &_surfaces);
99
102
103 MESHOBJ_DEFINEDBY_DECL(Vertex);
104 MESHOBJ_DEFINEDBY_DECL(Surface);
105 MESHOBJ_CLASSDEF(MeshObjTypeLabel::BODY)
106
107
110 std::string str() const;
111
115 std::string toString();
116
120 void updateInternals();
121
128
134 HRESULT remove(Surface *s);
135
142 HRESULT replace(Surface *toInsert, Surface *toRemove);
143
151 static HRESULT destroy(Body *target);
152
161 static HRESULT destroy(BodyHandle &target);
162
171 static HRESULT destroy(const std::vector<Body*>& toRemove);
172
176 BodyType *type() const;
177
183 HRESULT become(BodyType *btype);
184
188 const std::vector<Surface*>& getSurfaces() const { return surfaces; }
189
193 std::vector<Vertex*> getVertices() const;
194
200 Vertex *findVertex(const FVector3 &dir) const;
201
207 Surface *findSurface(const FVector3 &dir) const;
208
214 std::vector<Body*> connectedBodies() const;
215
221 std::vector<Body*> adjacentBodies() const;
222
230 std::vector<Surface*> neighborSurfaces(const Surface *s) const;
231
235 const FloatP_t& getDensity() const { return density; }
236
242 void setDensity(const FloatP_t &_density) { density = _density; }
243
247 const FVector3& getCentroid() const { return centroid; }
248
253
257 const FloatP_t& getArea() const { return area; }
258
262 const FloatP_t& getVolume() const { return volume; }
263
267 FloatP_t getMass() const { return volume * density; }
268
274 FloatP_t getVertexArea(const Vertex *v) const;
275
281 FloatP_t getVertexVolume(const Vertex *v) const;
282
288 FloatP_t getVertexMass(const Vertex *v) const { return getVertexVolume(v) * density; }
289
295 std::vector<Surface*> findInterface(const Body *b) const;
296
302 FloatP_t contactArea(const Body *other) const;
303
309 std::vector<Vertex*> sharedVertices(const Body *other) const;
310
317 bool isOutside(const FVector3 &pos) const;
318
326 Body *split(const FVector3 &cp_pos, const FVector3 &cp_norm, SurfaceType *stype=NULL);
327
328
329 friend BodyHandle;
330 friend Vertex;
331 friend Mesh;
332 friend BodyType;
333
334 };
335
336
345 struct CAPI_EXPORT BodyHandle {
346
347 int id;
348
349 BodyHandle(const int &_id=-1);
350
354 Body *body() const;
355
362 bool definedBy(const VertexHandle &v) const;
363
370 bool definedBy(const SurfaceHandle &s) const;
371
375 MeshObjTypeLabel objType() const { return MeshObjTypeLabel::BODY; }
376
381
385 bool validate();
386
391
395 std::string str() const;
396
400 std::string toString();
401
407 static BodyHandle fromString(const std::string &s);
408
415
422
429 HRESULT replace(const SurfaceHandle &toInsert, const SurfaceHandle &toRemove);
430
434 BodyType *type() const;
435
442
446 std::vector<SurfaceHandle> getSurfaces() const;
447
451 std::vector<VertexHandle> getVertices() const;
452
459
466
472 std::vector<BodyHandle> connectedBodies() const;
473
479 std::vector<BodyHandle> adjacentBodies() const;
480
488 std::vector<SurfaceHandle> neighborSurfaces(const SurfaceHandle &s) const;
489
493 FloatP_t getDensity() const;
494
500 void setDensity(const FloatP_t &_density);
501
506
511
515 FloatP_t getArea() const;
516
520 FloatP_t getVolume() const;
521
525 FloatP_t getMass() const;
526
532 FloatP_t getVertexArea(const VertexHandle &v) const;
533
539 FloatP_t getVertexVolume(const VertexHandle &v) const;
540
546 FloatP_t getVertexMass(const VertexHandle &v) const;
547
552
559
565 std::vector<SurfaceHandle> findInterface(const BodyHandle &b) const;
566
572 FloatP_t contactArea(const BodyHandle &other) const;
573
579 std::vector<VertexHandle> sharedVertices(const BodyHandle &other) const;
580
587 bool isOutside(const FVector3 &pos) const;
588
596 BodyHandle split(const FVector3 &cp_pos, const FVector3 &cp_norm, SurfaceType *stype=NULL);
597
598 operator bool() const { return id >= 0; }
599 };
600
601
608 struct CAPI_EXPORT BodyType : MeshObjType {
609
611 std::string name;
612
614 FloatP_t density;
615
616 BodyType(const bool &noReg=false);
617
621 MeshObjTypeLabel objType() const override { return MeshObjTypeLabel::BODY; }
622
626 virtual std::string str() const override;
627
631 std::string toString();
632
640 static BodyType *fromString(const std::string &str);
641
643 static BodyType *findFromName(const std::string &_name);
644
651
655 virtual void on_register() {}
656
663
667 virtual BodyType *get();
668
675
682
688 HRESULT remove(const std::vector<BodyHandle>& i);
689
693 std::vector<BodyHandle> getInstances();
694
698 std::vector<int> getInstanceIds() { return _instanceIds; }
699
703 unsigned int getNumInstances();
704
708 BodyHandle operator() (const std::vector<SurfaceHandle> &surfaces);
709
714
721 BodyHandle extend(const SurfaceHandle &base, const FVector3 &pos);
722
731 BodyHandle extrude(const SurfaceHandle &base, const FloatP_t &normLen);
732
733 private:
734
735 std::vector<int> _instanceIds;
736
737 };
738
739 inline bool operator< (const TissueForge::models::vertex::Body& lhs, const TissueForge::models::vertex::Body& rhs) { return lhs.objectId() < rhs.objectId(); }
740 inline bool operator> (const TissueForge::models::vertex::Body& lhs, const TissueForge::models::vertex::Body& rhs) { return rhs < lhs; }
741 inline bool operator<=(const TissueForge::models::vertex::Body& lhs, const TissueForge::models::vertex::Body& rhs) { return !(lhs > rhs); }
742 inline bool operator>=(const TissueForge::models::vertex::Body& lhs, const TissueForge::models::vertex::Body& rhs) { return !(lhs < rhs); }
743 inline bool operator==(const TissueForge::models::vertex::Body& lhs, const TissueForge::models::vertex::Body& rhs) { return lhs.objectId() == rhs.objectId(); }
744 inline bool operator!=(const TissueForge::models::vertex::Body& lhs, const TissueForge::models::vertex::Body& rhs) { return !(lhs == rhs); }
745
746 inline bool operator< (const TissueForge::models::vertex::BodyHandle& lhs, const TissueForge::models::vertex::BodyHandle& rhs) { return lhs.id < rhs.id; }
747 inline bool operator> (const TissueForge::models::vertex::BodyHandle& lhs, const TissueForge::models::vertex::BodyHandle& rhs) { return rhs < lhs; }
748 inline bool operator<=(const TissueForge::models::vertex::BodyHandle& lhs, const TissueForge::models::vertex::BodyHandle& rhs) { return !(lhs > rhs); }
749 inline bool operator>=(const TissueForge::models::vertex::BodyHandle& lhs, const TissueForge::models::vertex::BodyHandle& rhs) { return !(lhs < rhs); }
750 inline bool operator==(const TissueForge::models::vertex::BodyHandle& lhs, const TissueForge::models::vertex::BodyHandle& rhs) { return lhs.id == rhs.id; }
751 inline bool operator!=(const TissueForge::models::vertex::BodyHandle& lhs, const TissueForge::models::vertex::BodyHandle& rhs) { return !(lhs == rhs); }
752
753 inline bool operator< (const TissueForge::models::vertex::BodyType& lhs, const TissueForge::models::vertex::BodyType& rhs) { return lhs.id < rhs.id; }
754 inline bool operator> (const TissueForge::models::vertex::BodyType& lhs, const TissueForge::models::vertex::BodyType& rhs) { return rhs < lhs; }
755 inline bool operator<=(const TissueForge::models::vertex::BodyType& lhs, const TissueForge::models::vertex::BodyType& rhs) { return !(lhs > rhs); }
756 inline bool operator>=(const TissueForge::models::vertex::BodyType& lhs, const TissueForge::models::vertex::BodyType& rhs) { return !(lhs < rhs); }
757 inline bool operator==(const TissueForge::models::vertex::BodyType& lhs, const TissueForge::models::vertex::BodyType& rhs) { return lhs.id == rhs.id; }
758 inline bool operator!=(const TissueForge::models::vertex::BodyType& lhs, const TissueForge::models::vertex::BodyType& rhs) { return !(lhs == rhs); }
759
760}
761
762
763inline std::ostream &operator<<(std::ostream& os, const TissueForge::models::vertex::Body &o)
764{
765 os << o.str().c_str();
766 return os;
767}
768
769inline std::ostream &operator<<(std::ostream& os, const TissueForge::models::vertex::BodyType &o)
770{
771 os << o.str().c_str();
772 return os;
773}
774
775namespace std {
776
777 template <>
778 struct hash<TissueForge::models::vertex::BodyHandle> {
779 size_t operator() (const TissueForge::models::vertex::BodyHandle& h) const {
780 return hash<int>()(h.id);
781 }
782 };
783}
784
785#endif // _MODELS_VERTEX_SOLVER_TFBODY_H_
The mesh body is a volume-enclosing object of mesh surfaces.
Definition tfBody.h:59
const FloatP_t & getVolume() const
Get the volume.
Definition tfBody.h:262
bool isOutside(const FVector3 &pos) const
Test whether a point is outside. Test is performed using the nearest surface.
FloatP_t getVertexMass(const Vertex *v) const
Get the mass contribution of a vertex to this body.
Definition tfBody.h:288
const FloatP_t & getDensity() const
Get the mass density.
Definition tfBody.h:235
std::vector< Body * > adjacentBodies() const
Get the adjacent bodies.
Surface * findSurface(const FVector3 &dir) const
Find a surface that defines this body.
std::vector< MeshObjActor * > actors
Definition tfBody.h:89
std::vector< Surface * > neighborSurfaces(const Surface *s) const
Get the neighboring surfaces of a surface on this body.
std::vector< Body * > connectedBodies() const
Get the connected bodies.
state::StateVector * species
Definition tfBody.h:92
static BodyHandle create(const std::vector< SurfaceHandle > &_surfaces)
const FloatP_t & getArea() const
Get the surface area.
Definition tfBody.h:257
FloatP_t getVertexArea(const Vertex *v) const
Get the surface area contribution of a vertex to this body.
std::vector< Surface * > findInterface(const Body *b) const
Get the surfaces that define the interface between this body and another body.
std::string str() const
Get a summary string.
static BodyHandle create(TissueForge::io::ThreeDFMeshData *ioMesh)
FloatP_t getVertexVolume(const Vertex *v) const
Get the volume contribution of a vertex to this body.
FloatP_t getMass() const
Get the mass.
Definition tfBody.h:267
const FVector3 & getCentroid() const
Get the centroid.
Definition tfBody.h:247
int typeId
Definition tfBody.h:67
std::vector< Vertex * > getVertices() const
Get the vertices that define the body.
Vertex * findVertex(const FVector3 &dir) const
Find a vertex that defines this body.
void setDensity(const FloatP_t &_density)
Set the mass density.
Definition tfBody.h:242
std::vector< Vertex * > sharedVertices(const Body *other) const
Get the vertices that define both this body and another body.
FloatP_t contactArea(const Body *other) const
Get the contacting surface area of this body with another body.
Body * split(const FVector3 &cp_pos, const FVector3 &cp_norm, SurfaceType *stype=NULL)
Split into two bodies. The split is defined by a cut plane.
FVector3 getVelocity() const
Get the velocity, calculated as the velocity of the centroid.
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
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
3D data file mesh data
Definition tfThreeDFMeshData.h:43
A handle to a Body.
Definition tfBody.h:345
bool definedBy(const VertexHandle &v) const
Test whether defined by a vertex.
std::string toString()
Get a JSON string representation.
BodyHandle split(const FVector3 &cp_pos, const FVector3 &cp_norm, SurfaceType *stype=NULL)
Split into two bodies. The split is defined by a cut plane.
VertexHandle findVertex(const FVector3 &dir) const
Find a vertex that defines this body.
BodyType * type() const
Get the body type.
HRESULT add(const SurfaceHandle &s)
Add a surface.
FVector3 getVelocity() const
Get the velocity, calculated as the velocity of the centroid.
FloatP_t getVertexVolume(const VertexHandle &v) const
Get the volume contribution of a vertex to this body.
MeshObjTypeLabel objType() const
Get the mesh object type.
Definition tfBody.h:375
FloatP_t getDensity() const
Get the mass density.
std::vector< SurfaceHandle > getSurfaces() const
Get the surfaces that define the body.
std::vector< BodyHandle > connectedBodies() const
Get the connected bodies.
std::vector< BodyHandle > adjacentBodies() const
Get the adjacent bodies.
FVector3 getCentroid() const
Get the centroid.
std::vector< SurfaceHandle > neighborSurfaces(const SurfaceHandle &s) const
Get the neighboring surfaces of a surface on this body.
std::string str() const
Get a summary string.
FloatP_t getVertexArea(const VertexHandle &v) const
Get the surface area contribution of a vertex to this body.
std::vector< VertexHandle > sharedVertices(const BodyHandle &other) const
Get the vertices that define both this body and another body.
HRESULT positionChanged()
Update internal data due to a change in position.
state::StateVector * getSpecies() const
Get the amount of species in the enclosed volume, if any.
HRESULT become(BodyType *btype)
Become a different type.
bool validate()
Validate the body.
std::vector< VertexHandle > getVertices() const
Get the vertices that define the body.
FloatP_t getMass() const
Get the mass.
FloatP_t getVolume() const
Get the volume.
bool isOutside(const FVector3 &pos) const
Test whether a point is outside. Test is performed using the nearest surface.
std::vector< SurfaceHandle > findInterface(const BodyHandle &b) const
Get the surfaces that define the interface between this body and another body.
static BodyHandle fromString(const std::string &s)
Create an instance from a JSON string representation.
HRESULT destroy()
Destroy the body.
void setDensity(const FloatP_t &_density)
Set the mass density.
HRESULT replace(const SurfaceHandle &toInsert, const SurfaceHandle &toRemove)
Replace a surface with a surface.
HRESULT setSpecies(state::StateVector *s) const
Set the amount of species in the enclosed volume.
FloatP_t contactArea(const BodyHandle &other) const
Get the contacting surface area of this body with another body.
HRESULT remove(const SurfaceHandle &s)
Remove a surface.
bool definedBy(const SurfaceHandle &s) const
Test whether defined by a surface.
FloatP_t getArea() const
Get the surface area.
SurfaceHandle findSurface(const FVector3 &dir) const
Find a surface that defines this body.
Body * body() const
Get the underlying object, if any.
FloatP_t getVertexMass(const VertexHandle &v) const
Get the mass contribution of a vertex to this body.
Mesh body type.
Definition tfBody.h:608
std::vector< int > getInstanceIds()
list of instances ids that belong to this type
Definition tfBody.h:698
std::vector< BodyHandle > getInstances()
list of instances that belong to this type
BodyHandle extrude(const SurfaceHandle &base, const FloatP_t &normLen)
Create a body from a surface in a mesh by extruding along the outward-facing normal of the surface.
virtual BodyType * get()
Get the type engine instance.
bool isRegistered()
Tests whether this type is registered.
unsigned int getNumInstances()
number of instances that belong to this type
virtual std::string str() const override
Get a summary string.
HRESULT remove(const BodyHandle &i)
Remove an instance.
std::string name
Definition tfBody.h:611
static BodyType * findFromName(const std::string &_name)
static BodyType * fromString(const std::string &str)
Create from a JSON string representation.
virtual void on_register()
A callback for when a type is registered.
Definition tfBody.h:655
HRESULT remove(const std::vector< BodyHandle > &i)
Remove instances.
std::string toString()
Get a JSON string representation.
FloatP_t density
Definition tfBody.h:614
MeshObjTypeLabel objType() const override
Get the mesh object type.
Definition tfBody.h:621
virtual HRESULT registerType()
Registers a type with the engine.
HRESULT add(const BodyHandle &i)
Add an instance.
BodyHandle extend(const SurfaceHandle &base, const FVector3 &pos)
Create a body from a surface in the mesh and a position.
Base mesh object type definition.
Definition tfMeshObj.h:176
int id
Definition tfMeshObj.h:179
A handle to a Surface.
Definition tfSurface.h:630
Mesh surface type.
Definition tfSurface.h:1099
A handle to a Vertex.
Definition tfVertex.h:493
A state vector of an object.
Definition tfStateVector.h:50
int32_t HRESULT
Definition tf_port.h:255
MeshObjTypeLabel
Mesh object type enum.
Definition tfMeshObj.h:48