1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::MeshTri2D |
---|
4 | * This is a non-uniform, triangular mesh for 2-dimensional |
---|
5 | * structures. |
---|
6 | * |
---|
7 | * ====================================================================== |
---|
8 | * AUTHOR: Michael McLennan, Purdue University |
---|
9 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | #ifndef RAPPTURE_MESHTRI2D_H |
---|
16 | #define RAPPTURE_MESHTRI2D_H |
---|
17 | |
---|
18 | #include "RpNode.h" |
---|
19 | #include "RpSerializable.h" |
---|
20 | |
---|
21 | namespace Rappture { |
---|
22 | |
---|
23 | class CellTri2D { |
---|
24 | public: |
---|
25 | CellTri2D(); |
---|
26 | CellTri2D(int cellId, Node2D* n1Ptr, Node2D* n2Ptr, Node2D* n3Ptr); |
---|
27 | CellTri2D(const CellTri2D& cell); |
---|
28 | CellTri2D& operator=(const CellTri2D& cell); |
---|
29 | |
---|
30 | int cellId() const; |
---|
31 | int nodeId(int n) const; |
---|
32 | double x(int n) const; |
---|
33 | double y(int n) const; |
---|
34 | |
---|
35 | int isNull() const; |
---|
36 | int isOutside() const; |
---|
37 | void clear(); |
---|
38 | |
---|
39 | void barycentrics(const Node2D& node, double* phi) const; |
---|
40 | |
---|
41 | private: |
---|
42 | int _cellId; |
---|
43 | const Node2D* _nodes[3]; |
---|
44 | }; |
---|
45 | |
---|
46 | class Tri2D { |
---|
47 | public: |
---|
48 | Tri2D(); |
---|
49 | Tri2D(int n1, int n2, int n3); |
---|
50 | |
---|
51 | int nodes[3]; |
---|
52 | int neighbors[3]; |
---|
53 | }; |
---|
54 | |
---|
55 | class MeshTri2D : public Serializable { |
---|
56 | public: |
---|
57 | MeshTri2D(); |
---|
58 | MeshTri2D(const MeshTri2D& mesh); |
---|
59 | MeshTri2D& operator=(const MeshTri2D& mesh); |
---|
60 | virtual ~MeshTri2D(); |
---|
61 | |
---|
62 | virtual Node2D& addNode(const Node2D& node); |
---|
63 | virtual void addCell(int nId1, int nId2, int nId3); |
---|
64 | virtual void addCell(const Node2D& n1, const Node2D& n2, const Node2D& n3); |
---|
65 | virtual MeshTri2D& clear(); |
---|
66 | |
---|
67 | virtual int sizeNodes() const; |
---|
68 | virtual Node2D& atNode(int pos); |
---|
69 | |
---|
70 | virtual int sizeCells() const; |
---|
71 | virtual CellTri2D atCell(int pos); |
---|
72 | |
---|
73 | virtual double rangeMin(Axis which) const; |
---|
74 | virtual double rangeMax(Axis which) const; |
---|
75 | |
---|
76 | virtual CellTri2D locate(const Node2D& node) const; |
---|
77 | |
---|
78 | // required for base class Serializable: |
---|
79 | const char* serializerType() const { return "MeshTri2D"; } |
---|
80 | char serializerVersion() const { return 'A'; } |
---|
81 | |
---|
82 | static Ptr<Serializable> create(); |
---|
83 | void serialize_A(SerialBuffer& buffer) const; |
---|
84 | Outcome deserialize_A(SerialBuffer& buffer); |
---|
85 | |
---|
86 | protected: |
---|
87 | virtual Node2D* _getNodeById(int nodeId); |
---|
88 | virtual void _rebuildNodeIdMap(); |
---|
89 | |
---|
90 | private: |
---|
91 | std::vector<Node2D> _nodelist; // list of all nodes |
---|
92 | int _counter; // auto counter for node IDs |
---|
93 | double _min[2]; // min values for (x,y) |
---|
94 | double _max[2]; // max values for (x,y) |
---|
95 | |
---|
96 | std::vector<Tri2D> _celllist; // list of all triangular cells |
---|
97 | |
---|
98 | // use this structure and map to find neighbors for all triangles |
---|
99 | typedef struct Edge2D { |
---|
100 | int fromNode; // minimum node ID |
---|
101 | int toNode; // maximum node ID |
---|
102 | Edge2D() : fromNode(-1), toNode(-1) {} |
---|
103 | int operator<(const Edge2D& edge) const { |
---|
104 | if (fromNode < edge.fromNode) { |
---|
105 | return 1; |
---|
106 | } else if (fromNode == edge.fromNode && toNode < edge.toNode) { |
---|
107 | return 1; |
---|
108 | } |
---|
109 | return 0; |
---|
110 | } |
---|
111 | } Edge2D; |
---|
112 | typedef struct Neighbor2D { |
---|
113 | int triId; // ID of triangle containing edge |
---|
114 | int index; // index (0/1/2) for point opposite edge |
---|
115 | Neighbor2D() : triId(-1), index(-1) {} |
---|
116 | } Neighbor2D; |
---|
117 | typedef std::map<Edge2D, Neighbor2D> Edge2Neighbor; |
---|
118 | Edge2Neighbor _edge2neighbor; // maps tri edge to tri containing it |
---|
119 | |
---|
120 | int _id2nodeDirty; // non-zero => _id2node needs to be rebuilt |
---|
121 | std::vector<int> _id2node; // maps node Id => index in _nodelist |
---|
122 | |
---|
123 | CellTri2D _lastLocate; // last result from locate() operation |
---|
124 | |
---|
125 | // methods for serializing/deserializing version 'A' |
---|
126 | static SerialConversion versionA; |
---|
127 | }; |
---|
128 | |
---|
129 | } // namespace Rappture |
---|
130 | |
---|
131 | #endif |
---|