Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfVertex.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_TFVERTEX_H_
26#define _MODELS_VERTEX_SOLVER_TFVERTEX_H_
27
28#include <tf_port.h>
29
30#include <tfParticle.h>
31#include <rendering/tfStyle.h>
32
33#include "tfMeshObj.h"
34#include "tfMesh.h"
35
36#include <io/tfThreeDFVertexData.h>
37
38#include <vector>
39
40
41namespace TissueForge::models::vertex {
42
43
44 class Surface;
45 struct SurfaceHandle;
46 class Body;
47 struct BodyHandle;
48 class Mesh;
49
50 struct VertexHandle;
51
52
53 struct CAPI_EXPORT MeshParticleType : ParticleType {
54
55 MeshParticleType() : ParticleType(true) {
56 std::memcpy(this->name, "MeshParticleType", sizeof("MeshParticleType"));
57 style->setVisible(false);
58 dynamics = PARTICLE_OVERDAMPED;
60 };
61
62 };
63
64 CAPI_FUNC(MeshParticleType*) MeshParticleType_get();
65
66
71 class CAPI_EXPORT Vertex {
72
74 int _objId;
75
77 int pid;
78
80 std::vector<Surface*> surfaces;
81
83 FloatP_t _particleMass;
84
86 FVector3 _particlePosition;
87
89 FVector3 _particleVelocity;
90
92 std::vector<Vertex*> _connectedVertices;
93
94 public:
95
96 Vertex();
97 ~Vertex();
98
104 static VertexHandle create(const unsigned int &_pid);
105
111 static VertexHandle create(const FVector3 &position);
112
118 static VertexHandle create(TissueForge::io::ThreeDFVertexData *vdata);
119
125 static std::vector<VertexHandle> create(const std::vector<unsigned int>& _pids);
126
132 static std::vector<VertexHandle> create(const std::vector<FVector3>& positions);
133
139 static std::vector<VertexHandle> create(const std::vector<TissueForge::io::ThreeDFVertexData*>& vdata);
140
141 MESHBOJ_DEFINES_DECL(Surface);
142 MESHBOJ_DEFINES_DECL(Body);
143 MESHOBJ_CLASSDEF(MeshObjTypeLabel::VERTEX)
144
145
148 std::string str() const;
149
153 std::string toString();
154
160 HRESULT add(Surface *s);
161
168 HRESULT insert(Surface *s, const int &idx);
169
176 HRESULT insert(Surface *s, Surface *before);
177
183 HRESULT remove(Surface *s);
184
191 HRESULT replace(Surface *toInsert, const int &idx);
192
199 HRESULT replace(Surface *toInsert, Surface *toRemove);
200
206 static HRESULT destroy(const std::vector<Vertex*>& toDestroy);
207
211 const int getPartId() const { return pid; }
212
216 std::vector<Body*> getBodies() const;
217
221 const std::vector<Surface*>& getSurfaces() const { return surfaces; }
222
228 Surface *findSurface(const FVector3 &dir) const;
229
235 Body *findBody(const FVector3 &dir) const;
236
241
247 const std::vector<Vertex*>& connectedVertices() const { return _connectedVertices; }
248
254 std::vector<Surface*> sharedSurfaces(const Vertex *other) const;
255
259 FloatP_t getArea() const;
260
264 FloatP_t getVolume() const;
265
269 FloatP_t getMass() const;
270
275
280
284 const FVector3& getPosition() const { return _particlePosition; }
285
292 HRESULT setPosition(const FVector3 &pos, const bool &updateChildren=true);
293
297 const FVector3& getVelocity() const { return _particleVelocity; }
298
302 const FloatP_t& getCachedParticleMass() const { return _particleMass; }
303
309 HRESULT transferBondsTo(Vertex *other);
310
316 static HRESULT transferBondsTo(const std::vector<std::pair<Vertex*, Vertex*> >& targets);
317
323 HRESULT replace(Surface *toReplace);
324
332 static Vertex *replace(const FVector3 &position, Surface *toReplace);
333
341 static VertexHandle replace(const FVector3 &position, SurfaceHandle &toReplace);
342
348 HRESULT replace(Body *toReplace);
349
357 static Vertex *replace(const FVector3 &position, Body *toReplace);
358
366 static VertexHandle replace(const FVector3 &position, BodyHandle &toReplace);
367
376 HRESULT merge(Vertex *toRemove, const FloatP_t &lenCf=0.5f);
377
386 static HRESULT merge(const std::vector<std::vector<Vertex*> >& toMerge, const FloatP_t &lenCf=0.5f);
387
394 HRESULT insert(Vertex *v1, Vertex *v2);
395
404 static Vertex *insert(const FVector3 &position, Vertex *v1, Vertex *v2);
405
414 static VertexHandle insert(const FVector3 &position, const VertexHandle &v1, const VertexHandle &v2);
415
422 HRESULT insert(Vertex *vf, std::vector<Vertex*> nbs);
423
432 static Vertex *insert(const FVector3 &position, Vertex *vf, std::vector<Vertex*> nbs);
433
442 static VertexHandle insert(const FVector3 &position, const VertexHandle &vf, const std::vector<VertexHandle> &nbs);
443
451 HRESULT splitPlan(const FVector3 &sep, std::vector<Vertex*> &verts_v, std::vector<Vertex*> &verts_new_v);
452
460 Vertex *splitExecute(const FVector3 &sep, const std::vector<Vertex*> &verts_v, const std::vector<Vertex*> &verts_new_v);
461
474 Vertex *split(const FVector3 &sep);
475
476
477 friend VertexHandle;
478 friend Surface;
479 friend Body;
480 friend Mesh;
481
482 };
483
484
493 struct CAPI_EXPORT VertexHandle {
494
495 int id;
496
497 VertexHandle(const int &_id=-1);
498
502 Vertex *vertex() const;
503
510 bool defines(const SurfaceHandle &s) const;
511
518 bool defines(const BodyHandle &b) const;
519
523 MeshObjTypeLabel objType() const { return MeshObjTypeLabel::VERTEX; }
524
529
533 bool validate();
534
539
543 std::string str() const;
544
548 std::string toString() const;
549
555 static VertexHandle fromString(const std::string &s);
556
562 HRESULT add(const SurfaceHandle &s) const;
563
570 HRESULT insert(const SurfaceHandle &s, const int &idx) const;
571
578 HRESULT insert(const SurfaceHandle &s, const SurfaceHandle &before) const;
579
585 HRESULT remove(const SurfaceHandle &s) const;
586
593 HRESULT replace(const SurfaceHandle &toInsert, const int &idx) const;
594
601 HRESULT replace(const SurfaceHandle &toInsert, const SurfaceHandle &toRemove) const;
602
606 const int getPartId() const;
607
611 std::vector<BodyHandle> getBodies() const;
612
616 std::vector<SurfaceHandle> getSurfaces() const;
617
623 SurfaceHandle findSurface(const FVector3 &dir) const;
624
630 BodyHandle findBody(const FVector3 &dir) const;
631
636
642 std::vector<VertexHandle> connectedVertices() const;
643
649 std::vector<SurfaceHandle> sharedSurfaces(const VertexHandle &other) const;
650
654 FloatP_t getArea() const;
655
659 FloatP_t getVolume() const;
660
664 FloatP_t getMass() const;
665
670
675
679 FVector3 getPosition() const;
680
687 HRESULT setPosition(const FVector3 &pos, const bool &updateChildren=true);
688
692 FVector3 getVelocity() const;
693
699 HRESULT transferBondsTo(const VertexHandle &other) const;
700
706 HRESULT replace(SurfaceHandle &toReplace) const;
707
714
723 HRESULT merge(VertexHandle &toRemove, const FloatP_t &lenCf=0.5f);
724
731 HRESULT insert(const VertexHandle &v1, const VertexHandle &v2);
732
739 HRESULT insert(const VertexHandle &vf, const std::vector<VertexHandle> &nbs);
740
748 HRESULT splitPlan(const FVector3 &sep, const std::vector<VertexHandle> &verts_v, const std::vector<VertexHandle> &verts_new_v);
749
757 VertexHandle splitExecute(const FVector3 &sep, const std::vector<VertexHandle> &verts_v, const std::vector<VertexHandle> &verts_new_v);
758
771 VertexHandle split(const FVector3 &sep);
772
773 operator bool() const { return id >= 0; }
774 };
775
776
777 inline bool operator< (const TissueForge::models::vertex::Vertex& lhs, const TissueForge::models::vertex::Vertex& rhs) { return lhs.objectId() < rhs.objectId(); }
778 inline bool operator> (const TissueForge::models::vertex::Vertex& lhs, const TissueForge::models::vertex::Vertex& rhs) { return rhs < lhs; }
779 inline bool operator<=(const TissueForge::models::vertex::Vertex& lhs, const TissueForge::models::vertex::Vertex& rhs) { return !(lhs > rhs); }
780 inline bool operator>=(const TissueForge::models::vertex::Vertex& lhs, const TissueForge::models::vertex::Vertex& rhs) { return !(lhs < rhs); }
781 inline bool operator==(const TissueForge::models::vertex::Vertex& lhs, const TissueForge::models::vertex::Vertex& rhs) { return lhs.objectId() == rhs.objectId(); }
782 inline bool operator!=(const TissueForge::models::vertex::Vertex& lhs, const TissueForge::models::vertex::Vertex& rhs) { return !(lhs == rhs); }
783
784 inline bool operator< (const TissueForge::models::vertex::VertexHandle& lhs, const TissueForge::models::vertex::VertexHandle& rhs) { return lhs.id < rhs.id; }
785 inline bool operator> (const TissueForge::models::vertex::VertexHandle& lhs, const TissueForge::models::vertex::VertexHandle& rhs) { return rhs < lhs; }
786 inline bool operator<=(const TissueForge::models::vertex::VertexHandle& lhs, const TissueForge::models::vertex::VertexHandle& rhs) { return !(lhs > rhs); }
787 inline bool operator>=(const TissueForge::models::vertex::VertexHandle& lhs, const TissueForge::models::vertex::VertexHandle& rhs) { return !(lhs < rhs); }
788 inline bool operator==(const TissueForge::models::vertex::VertexHandle& lhs, const TissueForge::models::vertex::VertexHandle& rhs) { return lhs.id == rhs.id; }
789 inline bool operator!=(const TissueForge::models::vertex::VertexHandle& lhs, const TissueForge::models::vertex::VertexHandle& rhs) { return !(lhs == rhs); }
790
791}
792
793
794inline std::ostream &operator<<(std::ostream& os, const TissueForge::models::vertex::Vertex &o)
795{
796 os << o.str().c_str();
797 return os;
798}
799
800namespace std {
801
802 template <>
803 struct hash<TissueForge::models::vertex::VertexHandle> {
804 size_t operator() (const TissueForge::models::vertex::VertexHandle& h) const {
805 return hash<int>()(h.id);
806 }
807 };
808}
809
810#endif // _MODELS_VERTEX_SOLVER_TFVERTEX_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
static std::vector< VertexHandle > create(const std::vector< unsigned int > &_pids)
Create vertices.
HRESULT insert(Surface *s, const int &idx)
Insert a surface at a location in the list of surfaces.
HRESULT replace(Body *toReplace)
Replace a body.
HRESULT remove(Surface *s)
Remove a surface.
const std::vector< Surface * > & getSurfaces() const
Get the surfaces defined by the vertex.
Definition tfVertex.h:221
Vertex * splitExecute(const FVector3 &sep, const std::vector< Vertex * > &verts_v, const std::vector< Vertex * > &verts_new_v)
Implement a pre-calculated vertex split, as determined by splitPlan.
static VertexHandle insert(const FVector3 &position, const VertexHandle &vf, const std::vector< VertexHandle > &nbs)
Create a vertex and insert it between a vertex and each of a set of vertices.
std::vector< Surface * > sharedSurfaces(const Vertex *other) const
Get the surfaces that this vertex and another vertex both define.
std::string toString()
Get a JSON string representation.
static std::vector< VertexHandle > create(const std::vector< TissueForge::io::ThreeDFVertexData * > &vdata)
Create vertices.
static Vertex * replace(const FVector3 &position, Body *toReplace)
Create a vertex and replace a body with it.
HRESULT insert(Vertex *v1, Vertex *v2)
Inserts a vertex between two vertices.
static VertexHandle create(const FVector3 &position)
Create a vertex.
void updateConnectedVertices()
Update internal connected vertex data.
FloatP_t getVolume() const
Get the current volume.
static HRESULT transferBondsTo(const std::vector< std::pair< Vertex *, Vertex * > > &targets)
Transfer all bonds to other vertices.
static VertexHandle replace(const FVector3 &position, BodyHandle &toReplace)
Create a vertex and replace a body with it.
const int getPartId() const
Get the id of the underlying particle.
Definition tfVertex.h:211
HRESULT add(Surface *s)
Add a surface.
ParticleHandle * particle() const
Get a handle to the underlying particle, if any.
static Vertex * replace(const FVector3 &position, Surface *toReplace)
Create a vertex and replace a surface with it.
Body * findBody(const FVector3 &dir) const
Find a body defined by this vertex.
FloatP_t getArea() const
Get the current area.
FloatP_t getMass() const
Get the current mass.
static VertexHandle create(TissueForge::io::ThreeDFVertexData *vdata)
Create a vertex.
Vertex * split(const FVector3 &sep)
Split a vertex into an edge.
std::string str() const
Get a summary string.
HRESULT replace(Surface *toInsert, const int &idx)
Replace a surface at a location in the list of surfaces.
HRESULT replace(Surface *toReplace)
Replace a surface.
std::vector< Body * > getBodies() const
Get the bodies defined by the vertex.
const FloatP_t & getCachedParticleMass() const
Get the cached particle mass from the most recent update.
Definition tfVertex.h:302
static HRESULT merge(const std::vector< std::vector< Vertex * > > &toMerge, const FloatP_t &lenCf=0.5f)
Merge sets of vertices.
const std::vector< Vertex * > & connectedVertices() const
Get the connected vertices.
Definition tfVertex.h:247
HRESULT splitPlan(const FVector3 &sep, std::vector< Vertex * > &verts_v, std::vector< Vertex * > &verts_new_v)
Calculate the topology of a vertex split without implementing the split.
static VertexHandle replace(const FVector3 &position, SurfaceHandle &toReplace)
Create a vertex and replace a surface with it.
static Vertex * insert(const FVector3 &position, Vertex *vf, std::vector< Vertex * > nbs)
Create a vertex and insert it between a vertex and each of a set of vertices.
static VertexHandle insert(const FVector3 &position, const VertexHandle &v1, const VertexHandle &v2)
Create a vertex and inserts it between two vertices.
HRESULT transferBondsTo(Vertex *other)
Transfer all bonds to another vertex.
const FVector3 & getVelocity() const
Get the current velocity.
Definition tfVertex.h:297
static VertexHandle create(const unsigned int &_pid)
Create a vertex.
static std::vector< VertexHandle > create(const std::vector< FVector3 > &positions)
Create vertices.
const FVector3 & getPosition() const
Get the current position.
Definition tfVertex.h:284
HRESULT setPosition(const FVector3 &pos, const bool &updateChildren=true)
Set the current position.
HRESULT insert(Vertex *vf, std::vector< Vertex * > nbs)
Insert a vertex between a vertex and each of a set of vertices.
HRESULT updateProperties()
Update the properties of the underlying particle.
HRESULT merge(Vertex *toRemove, const FloatP_t &lenCf=0.5f)
Merge with a vertex.
static Vertex * insert(const FVector3 &position, Vertex *v1, Vertex *v2)
Create a vertex and inserts it between two vertices.
Surface * findSurface(const FVector3 &dir) const
Find a surface defined by this vertex.
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
A handle to a particle.
Definition tfParticle.h:313
virtual HRESULT registerType()
Registers a type with the engine.
rendering::Style * style
style pointer, optional.
Definition tfParticle.h:854
char name[MAX_NAME]
Name of this particle type.
Definition tfParticle.h:837
unsigned char dynamics
Default dynamics of particles of this type.
Definition tfParticle.h:832
3D data file vertex data
Definition tfThreeDFVertexData.h:41
A handle to a Body.
Definition tfBody.h:345
A handle to a Surface.
Definition tfSurface.h:630
A handle to a Vertex.
Definition tfVertex.h:493
bool defines(const BodyHandle &b) const
Test whether defines a body.
const int getPartId() const
Get the id of the underlying particle.
HRESULT insert(const SurfaceHandle &s, const SurfaceHandle &before) const
Insert a surface before another surface.
HRESULT splitPlan(const FVector3 &sep, const std::vector< VertexHandle > &verts_v, const std::vector< VertexHandle > &verts_new_v)
Calculate the topology of a vertex split without implementing the split.
void updateConnectedVertices() const
Update internal connected vertex data.
std::vector< SurfaceHandle > getSurfaces() const
Get the surfaces defined by the vertex.
HRESULT positionChanged()
Update internal data due to a change in position.
VertexHandle splitExecute(const FVector3 &sep, const std::vector< VertexHandle > &verts_v, const std::vector< VertexHandle > &verts_new_v)
Implement a pre-calculated vertex split, as determined by splitPlan.
HRESULT destroy()
Destroy the vertex.
HRESULT merge(VertexHandle &toRemove, const FloatP_t &lenCf=0.5f)
Merge with a vertex.
HRESULT remove(const SurfaceHandle &s) const
Remove a surface.
std::vector< SurfaceHandle > sharedSurfaces(const VertexHandle &other) const
Get the surfaces that this vertex and another vertex both define.
HRESULT insert(const SurfaceHandle &s, const int &idx) const
Insert a surface at a location in the list of surfaces.
HRESULT replace(const SurfaceHandle &toInsert, const int &idx) const
Replace a surface at a location in the list of surfaces.
FloatP_t getMass() const
Get the current mass.
std::string toString() const
Get a JSON string representation.
std::vector< BodyHandle > getBodies() const
Get the bodies defined by the vertex.
BodyHandle findBody(const FVector3 &dir) const
Find a body defined by this vertex.
HRESULT add(const SurfaceHandle &s) const
Add a surface.
HRESULT transferBondsTo(const VertexHandle &other) const
Transfer all bonds to another vertex.
MeshObjTypeLabel objType() const
Get the mesh object type.
Definition tfVertex.h:523
SurfaceHandle findSurface(const FVector3 &dir) const
Find a surface defined by this vertex.
HRESULT setPosition(const FVector3 &pos, const bool &updateChildren=true)
Set the current position.
FVector3 getVelocity() const
Get the current velocity.
HRESULT replace(BodyHandle &toReplace)
Replace a body.
std::string str() const
Get a summary string.
VertexHandle split(const FVector3 &sep)
Split a vertex into an edge.
HRESULT replace(const SurfaceHandle &toInsert, const SurfaceHandle &toRemove) const
Replace a surface with another surface.
ParticleHandle * particle() const
Get a handle to the underlying particle, if any.
HRESULT insert(const VertexHandle &v1, const VertexHandle &v2)
Inserts a vertex between two vertices.
HRESULT replace(SurfaceHandle &toReplace) const
Replace a surface.
HRESULT insert(const VertexHandle &vf, const std::vector< VertexHandle > &nbs)
Insert a vertex between a vertex and each of a set of vertices.
FloatP_t getArea() const
Get the current area.
bool validate()
Validate the vertex.
std::vector< VertexHandle > connectedVertices() const
Get the connected vertices.
HRESULT updateProperties() const
Update the properties of the underlying particle.
FVector3 getPosition() const
Get the current position.
static VertexHandle fromString(const std::string &s)
Create an instance from a JSON string representation.
bool defines(const SurfaceHandle &s) const
Test whether defines a surface.
Vertex * vertex() const
Get the underlying object, if any.
FloatP_t getVolume() const
Get the current volume.
int32_t HRESULT
Definition tf_port.h:255
MeshObjTypeLabel
Mesh object type enum.
Definition tfMeshObj.h:48