37 Node(
const Vec3& p) : flags(0), pos(p) {}
44 Triangle() : flags(0) { c[0] = c[1] = c[2] = 0; }
45 Triangle(
int n0,
int n1,
int n2) : flags(0) { c[0]=n0; c[1]=n1; c[2]=n2; }
53 Corner() : tri(-1), node(-1), opposite(-1), next(-1), prev(-1) {};
54 Corner(
int t,
int n) : tri(t), node(n), opposite(-1), next(-1), prev(-1) {}
66 virtual void resize(
int num) = 0;
67 virtual int size() = 0;
70 virtual void addInterpol(
int a,
int b, Real alpha) = 0;
71 virtual void mergeWith(
int node,
int delnode, Real alpha) = 0;
72 virtual void renumber(
const std::vector<int>& newIndex,
int newsize) = 0;
80 void resize(
int num) { data.resize(num); }
81 virtual int size() {
return data.size(); }
82 virtual void renumber(
const std::vector<int>& newIndex,
int newsize);
92 virtual void resize(
int num) = 0;
94 virtual int size() = 0;
96 virtual void addNew() = 0;
97 virtual void addSplit(
int from, Real alpha) = 0;
98 virtual void remove(
int tri) = 0;
106 void resize(
int num) { data.resize(num); }
107 void remove(
int tri) {
if (tri!=(
int)data.size()-1) data[tri] = *data.rbegin(); data.pop_back(); }
108 virtual int size() {
return data.size(); }
110 virtual void addSplit(
int from, Real alpha) { data.push_back(data[from]); }
111 virtual void addNew() { data.push_back(T()); }
125 PYTHON
class Mesh :
public PbClass {
130 virtual Mesh* clone();
132 enum NodeFlags { NfNone = 0, NfFixed = 1, NfMarked = 2, NfKillme = 4, NfCollide = 8 };
133 enum FaceFlags { FfNone = 0, FfDoubled = 1, FfMarked = 2 };
134 enum MeshType { TypeNormal = 0, TypeVortexSheet };
136 virtual MeshType getType() {
return TypeNormal; }
138 Real computeCenterOfMass(
Vec3& cm)
const;
139 void computeVertexNormals();
142 PYTHON()
void clear();
143 PYTHON()
void load (std::string name,
bool append =
false);
144 PYTHON()
void fromShape (
Shape& shape,
bool append =
false);
145 PYTHON()
void save (std::string name);
146 PYTHON()
void advectInGrid(
FlagGrid& flags,
MACGrid& vel,
int integrationMode);
147 PYTHON()
void scale(
Vec3 s);
148 PYTHON()
void offset(
Vec3 o);
150 PYTHON()
void computeLevelset(
LevelsetGrid& levelset, Real sigma, Real cutoff=-1.);
152 PYTHON()
void applyMeshToGrid(
GridBase* grid,
FlagGrid* respectFlags=0, Real cutoff=-1.);
158 inline int numTris()
const {
return mTris.size(); }
159 inline int numNodes()
const {
return mNodes.size(); }
160 inline int numTriChannels()
const {
return mTriChannels.size(); }
161 inline int numNodeChannels()
const {
return mNodeChannels.size(); }
163 inline Triangle& tris(
int i) {
return mTris[i]; }
164 inline Node& nodes(
int i) {
return mNodes[i]; }
165 inline Corner& corners(
int tri,
int c) {
return mCorners[tri*3+c]; }
166 inline Corner& corners(
int c) {
return mCorners[c]; }
167 inline NodeChannel* nodeChannel(
int i) {
return mNodeChannels[i]; }
168 inline TriChannel* triChannel(
int i) {
return mTriChannels[i]; }
171 void resizeTris(
int numTris);
172 void resizeNodes(
int numNodes);
174 inline bool isNodeFixed(
int n) {
return mNodes[n].flags & NfFixed; }
175 inline bool isTriangleFixed(
int t) {
return (mNodes[mTris[t].c[0]].flags & NfFixed) || (mNodes[mTris[t].c[1]].flags & NfFixed) || (mNodes[mTris[t].c[2]].flags & NfFixed); }
177 inline const Vec3 getNode(
int tri,
int c)
const {
return mNodes[mTris[tri].c[c]].pos; }
178 inline Vec3& getNode(
int tri,
int c) {
return mNodes[mTris[tri].c[c]].pos; }
179 inline const Vec3 getEdge(
int tri,
int e)
const {
return getNode(tri,(e+1)%3) - getNode(tri,e); }
180 inline OneRing& get1Ring(
int node) {
return m1RingLookup[node]; }
181 inline Real getFaceArea(
int t) {
Vec3 c0 = mNodes[mTris[t].c[0]].pos;
return 0.5*norm(cross(mNodes[mTris[t].c[1]].pos - c0, mNodes[mTris[t].c[2]].pos - c0)); }
182 inline Vec3 getFaceNormal(
int t) {
Vec3 c0 = mNodes[mTris[t].c[0]].pos;
return getNormalized(cross(mNodes[mTris[t].c[1]].pos - c0, mNodes[mTris[t].c[2]].pos - c0)); }
183 inline Vec3 getFaceCenter(
int t) {
return (mNodes[mTris[t].c[0]].pos + mNodes[mTris[t].c[1]].pos + mNodes[mTris[t].c[2]].pos) / 3.0; }
184 inline std::vector<Node>& getNodeData() {
return mNodes; }
186 void mergeNode(
int node,
int delnode);
190 void removeTri(
int tri);
191 void removeTriFromLookup(
int tri);
192 void removeNodes(
const std::vector<int>& deletedNodes);
193 void rebuildCorners(
int from=0,
int to=-1);
194 void rebuildLookup(
int from=0,
int to=-1);
195 void rebuildQuickCheck();
196 void fastNodeLookupRebuild(
int corner);
197 void sanityCheck(
bool strict=
true, std::vector<int>* deletedNodes=0, std::map<int,bool>* taintedTris=0);
199 void addTriChannel(
TriChannel* c) { mTriChannels.push_back(c); rebuildChannels(); }
200 void addNodeChannel(
NodeChannel* c) { mNodeChannels.push_back(c); rebuildChannels(); }
203 void rebuildChannels();
205 std::vector<Node> mNodes;
206 std::vector<Triangle> mTris;
207 std::vector<Corner> mCorners;
208 std::vector<NodeChannel*> mNodeChannels;
209 std::vector<TriChannel*> mTriChannels;
210 std::vector<OneRing> m1RingLookup;
221 for(
size_t i=0; i<newIndex.size(); i++) {
223 data[newIndex[i]] = data[newsize+i];
225 data.resize(newsize);
Definition: commonkernels.h:22
For fast access to nodes and neighboring triangles.
Definition: mesh.h:52
Base class for mesh data channels (texture coords, vorticity, ...)
Definition: mesh.h:90
Basic inlined vector class.
Definition: vectorbase.h:71
Node channel using only a vector.
Definition: mesh.h:77
static const Vector3D< S > Zero
zero element
Definition: vectorbase.h:212
Node position and flags.
Definition: mesh.h:35
Carries indices of its nodes.
Definition: mesh.h:43
Triangle mesh class.
Definition: mesh.h:126
Definition: levelset.h:25
Base class for mesh data channels (texture coords, vorticity, ...)
Definition: mesh.h:64
Tri channel using only a vector.
Definition: mesh.h:103
Definition: fluidsolver.h:28