PeriDyno 1.0.0
Loading...
Searching...
No Matches
TriangleSet.h
Go to the documentation of this file.
1
16#pragma once
17#include "EdgeSet.h"
18
19namespace dyno
20{
21 class TKey
22 {
23 public:
24 DYN_FUNC TKey()
25 {
26 id[0] = EMPTY;
27 id[1] = EMPTY;
28 id[2] = EMPTY;
29 }
30
31 DYN_FUNC TKey(PointType v0, PointType v1, PointType v2)
32 {
33 id[0] = v0;
34 id[1] = v1;
35 id[2] = v2;
36
37 swap(id[0], id[1]);
38 swap(id[0], id[2]);
39 swap(id[1], id[2]);
40 }
41
42 DYN_FUNC inline PointType operator[] (unsigned int i) { return id[i]; }
43 DYN_FUNC inline PointType operator[] (unsigned int i) const { return id[i]; }
44
45 DYN_FUNC inline bool operator>= (const TKey& other) const {
46 if (id[0] >= other.id[0]) return true;
47 if (id[0] == other.id[0] && id[1] >= other.id[1]) return true;
48 if (id[0] == other.id[0] && id[1] == other.id[1] && id[2] >= other.id[2]) return true;
49
50 return false;
51 }
52
53 DYN_FUNC inline bool operator> (const TKey& other) const {
54 if (id[0] > other.id[0]) return true;
55 if (id[0] == other.id[0] && id[1] > other.id[1]) return true;
56 if (id[0] == other.id[0] && id[1] == other.id[1] && id[2] > other.id[2]) return true;
57
58 return false;
59 }
60
61 DYN_FUNC inline bool operator<= (const TKey& other) const {
62 if (id[0] <= other.id[0]) return true;
63 if (id[0] == other.id[0] && id[1] <= other.id[1]) return true;
64 if (id[0] == other.id[0] && id[1] == other.id[1] && id[2] <= other.id[2]) return true;
65
66 return false;
67 }
68
69 DYN_FUNC inline bool operator< (const TKey& other) const {
70 if (id[0] < other.id[0]) return true;
71 if (id[0] == other.id[0] && id[1] < other.id[1]) return true;
72 if (id[0] == other.id[0] && id[1] == other.id[1] && id[2] < other.id[2]) return true;
73
74 return false;
75 }
76
77 DYN_FUNC inline bool operator== (const TKey& other) const {
78 return id[0] == other.id[0] && id[1] == other.id[1] && id[2] == other.id[2];
79 }
80
81 DYN_FUNC inline bool operator!= (const TKey& other) const {
82 return id[0] != other.id[0] || id[1] != other.id[1] || id[2] != other.id[2];
83 }
84
85 private:
86 DYN_FUNC inline void swap(PointType& v0, PointType& v1)
87 {
88 PointType vt = v0;
89 v0 = v0 < v1 ? v0 : v1;
90 v1 = vt < v1 ? v1 : vt;
91 }
92
93 PointType id[3];
94 };
95
96 template<typename TDataType>
97 class TriangleSet : public EdgeSet<TDataType>
98 {
99 public:
100 typedef typename TDataType::Real Real;
101 typedef typename TDataType::Coord Coord;
103
104 TriangleSet();
105 ~TriangleSet() override;
106
107 void setTriangles(std::vector<Triangle>& triangles);
109
115
118
119 void setNormals(DArray<Coord>& normals);
121
126
129
130
131 bool loadObjFile(std::string filename);
132
134
135 std::shared_ptr<TriangleSet<TDataType>>
137
138 bool isEmpty() override;
139
140 void clear() override;
141
142 //If true, normals will be updated automatically as calling update();
144
145 void rotate(const Coord angle) override;
146 void rotate(const Quat<Real> q) override;
147
148 protected:
149 void updateTopology() override;
150
151 void updateEdges() override;
152
153 virtual void updateTriangles() {};
154 virtual void updateVertexNormal();
155
156 private:
157 //A tag used to identify when the normals should be updated automatically
158 bool bAutoUpdateNormal = true;
159
161
162 //Map vertex id to triangle id
164
165 //Map edge id to triangle id
167
168 //Map triangle id to edge id
170
172 };
173}
174
DYN_FUNC TKey()
Definition TriangleSet.h:24
DYN_FUNC bool operator<(const TKey &other) const
Definition TriangleSet.h:69
DYN_FUNC bool operator==(const TKey &other) const
Definition TriangleSet.h:77
DYN_FUNC bool operator>=(const TKey &other) const
Definition TriangleSet.h:45
DYN_FUNC void swap(PointType &v0, PointType &v1)
Definition TriangleSet.h:86
DYN_FUNC bool operator!=(const TKey &other) const
Definition TriangleSet.h:81
DYN_FUNC TKey(PointType v0, PointType v1, PointType v2)
Definition TriangleSet.h:31
DYN_FUNC PointType operator[](unsigned int i)
Definition TriangleSet.h:42
DYN_FUNC bool operator<=(const TKey &other) const
Definition TriangleSet.h:61
DYN_FUNC bool operator>(const TKey &other) const
Definition TriangleSet.h:53
PointType id[3]
Definition TriangleSet.h:93
Vector< PointType, 3 > Triangle
virtual void updateTriangles()
void updateTopology() override
void setTriangles(std::vector< Triangle > &triangles)
void updateAngleWeightedVertexNormal(DArray< Coord > &vertexNormal)
bool loadObjFile(std::string filename)
void setNormals(DArray< Coord > &normals)
void rotate(const Quat< Real > q) override
void updateEdgeNormal(DArray< Coord > &edgeNormal)
DArray< Triangle > mTriangleIndex
std::shared_ptr< TriangleSet< TDataType > > merge(TriangleSet< TDataType > &ts)
~TriangleSet() override
DArray<::dyno::TopologyModule::Tri2Edg > mTri2Edg
void updateTriangle2Edge()
update the index from triangle id to edges ids
void setTriangles(DArray< Triangle > &triangles)
virtual void updateVertexNormal()
TopologyModule::Triangle Triangle
void setAutoUpdateNormals(bool b)
void clear() override
DArray< Coord > & getVertexNormals()
bool isEmpty() override
TDataType::Real Real
DArray<::dyno::TopologyModule::Edg2Tri > mEdg2Tri
DArrayList< int > & getVertex2Triangles()
TDataType::Coord Coord
DArray< Coord > mVertexNormal
void rotate(const Coord angle) override
DArray< TopologyModule::Tri2Edg > & getTriangle2Edge()
void copyFrom(TriangleSet< TDataType > &triangleSet)
DArray< TopologyModule::Edg2Tri > & getEdge2Triangle()
DArray< Triangle > & getTriangles()
return all triangle indices
void updateEdges() override
DArrayList< int > mVer2Tri
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
int PointType
constexpr int EMPTY
ArrayList< ElementType, DeviceType::GPU > DArrayList
Definition ArrayList.inl:83