xmsgrid  1.0
XmUGrid.h
Go to the documentation of this file.
1 #pragma once
2 //------------------------------------------------------------------------------
8 //------------------------------------------------------------------------------
9 
10 //----- Included files ---------------------------------------------------------
11 
12 // 3. Standard library headers
13 #include <memory>
14 
15 // 4. External library headers
16 
17 // 5. Shared code headers
18 #include <xmscore/stl/vector.h>
19 
20 //----- Forward declarations ---------------------------------------------------
21 
22 //----- Namespace declaration --------------------------------------------------
23 
25 namespace xms
26 {
27 //----- Forward declarations ---------------------------------------------------
28 class XmEdge;
29 
30 //----- Constants / Enumerations -----------------------------------------------
31 
34  XMU_INVALID_CELL_TYPE = -1,
35 
36  // Linear cells
37  XMU_EMPTY_CELL = 0,
38  XMU_VERTEX = 1,
39  XMU_POLY_VERTEX = 2,
40  XMU_LINE = 3,
41  XMU_POLY_LINE = 4,
42  XMU_TRIANGLE = 5,
43  XMU_TRIANGLE_STRIP = 6,
44  XMU_POLYGON = 7,
45  XMU_PIXEL = 8,
46  XMU_QUAD = 9,
47  XMU_TETRA = 10,
48  XMU_VOXEL = 11,
49  XMU_HEXAHEDRON = 12,
50  XMU_WEDGE = 13,
51  XMU_PYRAMID = 14,
52  XMU_PENTAGONAL_PRISM = 15,
53  XMU_HEXAGONAL_PRISM = 16,
54 
55  // Quadratic, isoparametric cells
56  XMU_QUADRATIC_EDGE = 21,
57  XMU_QUADRATIC_TRIANGLE = 22,
58  XMU_QUADRATIC_QUAD = 23,
59  XMU_QUADRATIC_POLYGON = 36,
60  XMU_QUADRATIC_TETRA = 24,
61  XMU_QUADRATIC_HEXAHEDRON = 25,
62  XMU_QUADRATIC_WEDGE = 26,
63  XMU_QUADRATIC_PYRAMID = 27,
64  XMU_BIQUADRATIC_QUAD = 28,
65  XMU_TRIQUADRATIC_HEXAHEDRON = 29,
66  XMU_QUADRATIC_LINEAR_QUAD = 30,
67  XMU_QUADRATIC_LINEAR_WEDGE = 31,
68  XMU_BIQUADRATIC_QUADRATIC_WEDGE = 32,
69  XMU_BIQUADRATIC_QUADRATIC_HEXAHEDRON = 33,
70  XMU_BIQUADRATIC_TRIANGLE = 34,
71 
72  // Cubic, isoparametric cell
73  XMU_CUBIC_LINE = 35,
74 
75  // Special class of cells formed by convex group of points
76  XMU_CONVEX_POINT_SET = 41,
77 
78  // Polyhedron cell (consisting of polygonal faces)
79  XMU_POLYHEDRON = 42,
80 
81  // Higher order cells in parametric form
82  XMU_PARAMETRIC_CURVE = 51,
83  XMU_PARAMETRIC_SURFACE = 52,
84  XMU_PARAMETRIC_TRI_SURFACE = 53,
85  XMU_PARAMETRIC_QUAD_SURFACE = 54,
86  XMU_PARAMETRIC_TETRA_REGION = 55,
87  XMU_PARAMETRIC_HEX_REGION = 56,
88 
89  // Higher order cells
90  XMU_HIGHER_ORDER_EDGE = 60,
91  XMU_HIGHER_ORDER_TRIANGLE = 61,
92  XMU_HIGHER_ORDER_QUAD = 62,
93  XMU_HIGHER_ORDER_POLYGON = 63,
94  XMU_HIGHER_ORDER_TETRAHEDRON = 64,
95  XMU_HIGHER_ORDER_WEDGE = 65,
96  XMU_HIGHER_ORDER_PYRAMID = 66,
97  XMU_HIGHER_ORDER_HEXAHEDRON = 67,
98 
99  XMU_NUMBER_OF_CELL_TYPES
100 
101 };
102 
105  XMU_ORIENTATION_UNKNOWN = -1,
106  XMU_ORIENTATION_SIDE = 0,
107  XMU_ORIENTATION_TOP = 1,
108  XMU_ORIENTATION_BOTTOM = 2,
109  XMU_ORIENTATION_NUMBER
110 };
111 
112 //----- Structs / Classes ------------------------------------------------------
113 
115 class XmUGrid
116 {
117 public:
118  static std::shared_ptr<XmUGrid> New(const VecPt3d& a_locations, const VecInt& a_cellstream);
119  static std::shared_ptr<XmUGrid> New();
120  XmUGrid();
121  XmUGrid(const XmUGrid& a_xmUGrid);
122  XmUGrid(XmUGrid&& a_xmUGrid);
123  ~XmUGrid();
124 
125  XmUGrid& operator=(XmUGrid a_xmUGrid);
126  void Swap(XmUGrid& a_xmUGrid);
127 
128  // Misc
129  bool GetModified() const;
130  void SetUnmodified();
131  void SetUseCache(bool a_useCache);
132  static bool IsValidCellstream(const VecInt& a_cellstream);
133 
134  // Points
135  int GetPointCount() const;
136  const VecPt3d& GetLocations() const;
137  void SetLocations(const VecPt3d& a_locations);
138  Pt3d GetPointLocation(int a_pointIdx) const;
139  bool SetPointLocation(int a_pointIdx, const Pt3d& a_location);
140  Pt3d GetPointXy0(int a_pointIdx) const;
141  VecPt3d GetPointsLocations(const VecInt& a_points) const;
142  void GetExtents(Pt3d& a_min, Pt3d& a_max) const;
143  int GetPointAdjacentCellCount(int a_pointIdx) const;
144  VecInt GetPointAdjacentCells(int a_pointIdx) const;
145  void GetPointAdjacentCells(int a_pointIdx, VecInt& a_adjacentCells) const;
146  VecInt GetPointsAdjacentCells(const VecInt& a_points) const;
147  void GetPointsAdjacentCells(const VecInt& a_pointIdxs, VecInt& a_adjacentCellIdxs) const;
148  void GetPointsAdjacentCells(int a_pointIdx1, int a_pointIdx2, VecInt& a_adjacentCellIdxs) const;
149  bool IsValidPointChange(int a_changedPtIdx, const Pt3d& a_newPosition) const;
150 
151  // Cells
152  int GetCellCount() const;
153  int GetCellPointCount(int a_cellIdx) const;
154  VecInt GetCellPoints(int a_cellIdx) const;
155  bool GetCellPoints(int a_cellIdx, VecInt& a_cellPoints) const;
156  void GetCellLocations(int a_cellIdx, VecPt3d& a_cellLocations) const;
157  XmUGridCellType GetCellType(int a_cellIdx) const;
158  std::vector<int> GetDimensionCounts() const;
159  int GetCellDimension(int a_cellIdx) const;
160  void GetCellExtents(int a_cellIdx, Pt3d& a_min, Pt3d& a_max) const;
161  const VecInt& GetCellstream() const;
162  bool SetCellstream(const VecInt& a_cellstream);
163  bool GetCellCellstream(int a_cellIdx, VecInt& a_cellstream) const;
164  VecInt GetCellAdjacentCells(int a_cellIdx) const;
165  void GetCellAdjacentCells(int a_cellIdx, VecInt& a_cellNeighbors) const;
166  bool GetCellPlanViewPolygon(int a_cellIdx, VecPt3d& a_polygon) const;
167  bool GetCellCentroid(int a_cellIdx, Pt3d& a_centroid) const;
168  int GetCellEdgeCount(int a_cellIdx) const;
169  XmEdge GetCellEdge(int a_cellIdx, int a_edgeIdx) const;
170  VecInt GetCellEdgeAdjacentCells(int a_cellIdx, int a_edgeIdx) const;
171  void GetCellEdgeAdjacentCells(int a_cellIdx, int a_edgeIdx, VecInt& a_adjacentCellIdxs) const;
172  int GetCell2dEdgeAdjacentCell(int a_cellIdx, int a_edgeIdx) const;
173  void GetEdgeAdjacentCells(const XmEdge& a_edge, VecInt& a_adjacentCellIdxs) const;
174  VecInt GetEdgeAdjacentCells(const XmEdge& a_edge) const;
175  std::vector<XmEdge> GetCellEdges(int a_cellIdx) const;
176  void GetCellEdges(int a_cellIdx, std::vector<XmEdge>& a_edges) const;
177  void GetPointAdjacentPoints(int a_pointIdx, VecInt& a_edgePoints) const;
178  void GetPointAdjacentLocations(int a_pointIdx, VecPt3d& a_edgePoints) const;
179 
180  // Faces
181  int GetCell3dFaceCount(int a_cellIdx) const;
182  int GetCell3dFacePointCount(int a_cellIdx, int a_faceIdx) const;
183  VecInt GetCell3dFacePoints(int a_cellIdx, int a_faceIdx) const;
184  void GetCell3dFacePoints(int a_cellIdx, int a_faceIdx, VecInt& a_facePtIdxs) const;
185  VecInt2d GetCell3dFacesPoints(int a_cellIdx) const;
186  int GetCell3dFaceAdjacentCell(int a_cellIdx, int a_faceIdx) const;
187  bool GetCell3dFaceAdjacentCell(int a_cellIdx,
188  int a_faceIdx,
189  int& a_neighborCell,
190  int& a_neighborFace) const;
191  XmUGridFaceOrientation GetCell3dFaceOrientation(int a_cellIdx, int a_faceIdx) const;
192 
193 private:
194  class Impl;
195  std::unique_ptr<Impl> m_impl;
196 };
197 
198 //----- Function prototypes ----------------------------------------------------
199 std::shared_ptr<XmUGrid> TEST_XmUGrid1Left90Tri();
200 std::shared_ptr<XmUGrid> TEST_XmUGridSimpleQuad();
201 std::shared_ptr<XmUGrid> TEST_XmUGrid2dLinear();
202 std::shared_ptr<XmUGrid> TEST_XmUGrid3dLinear();
203 std::shared_ptr<XmUGrid> TEST_XmUGridHexagonalPolyhedron();
204 std::shared_ptr<XmUGrid> TEST_XmUBuildQuadUGrid(int a_rows, int a_cols);
205 std::shared_ptr<XmUGrid> TEST_XmUBuildQuadUGrid(int a_rows, int a_cols, const xms::Pt3d& a_origin);
206 std::shared_ptr<XmUGrid> TEST_XmUBuildHexahedronUgrid(int a_rows, int a_cols, int a_lays);
207 std::shared_ptr<XmUGrid> TEST_XmUBuildHexahedronUgrid(int a_rows,
208  int a_cols,
209  int a_lays,
210  const xms::Pt3d& a_origin);
211 std::shared_ptr<XmUGrid> TEST_XmUBuildPolyhedronUgrid(int a_rows, int a_cols, int a_lays);
212 std::shared_ptr<XmUGrid> TEST_XmUBuildPolyhedronUgrid(int a_rows,
213  int a_cols,
214  int a_lays,
215  const xms::Pt3d& a_origin);
216 std::shared_ptr<XmUGrid> TEST_XmUBuild3DChevronUgrid();
217 
218 } // namespace xms
std::shared_ptr< XmUGrid > TEST_XmUGrid1Left90Tri()
Builds a 1 cell (left 90 degree triangle) 2D XmUGrid for testing.
Definition: XmUGrid.cpp:3639
VecInt GetCellEdgeAdjacentCells(int a_cellIdx, int a_edgeIdx) const
Get the index of the adjacent cells (that shares the same cell edge)
Definition: XmUGrid.cpp:3444
std::shared_ptr< XmUGrid > TEST_XmUGrid3dLinear()
Builds an XmUGrid with supported 3D linear cells for testing.
Definition: XmUGrid.cpp:3705
VecInt GetCellAdjacentCells(int a_cellIdx) const
Get the cells neighboring a cell (cells associated with any of it&#39;s points)
Definition: XmUGrid.cpp:3379
bool SetCellstream(const VecInt &a_cellstream)
Set the ugrid cells for the entire UGrid using a cell stream.
Definition: XmUGrid.cpp:3357
bool GetCellCentroid(int a_cellIdx, Pt3d &a_centroid) const
Get the centroid location of a cell.
Definition: XmUGrid.cpp:3412
std::shared_ptr< xms::XmUGrid > TEST_XmUBuildHexahedronUgrid(int a_rows, int a_cols, int a_lays)
Builds a UGrid of Quads at 1 spacing for rows & cols specified.
Definition: XmUGrid.cpp:3817
Implementation for XmUGrid.
Definition: XmUGrid.cpp:50
std::vector< int > VecInt
XmUGrid & operator=(XmUGrid a_xmUGrid)
Assignment operator.
Definition: XmUGrid.cpp:2928
int GetCellEdgeCount(int a_cellIdx) const
Get the number of edges for a cell.
Definition: XmUGrid.cpp:3422
Pt3d GetPointXy0(int a_pointIdx) const
Get the X, Y location of a point.
Definition: XmUGrid.cpp:3141
std::shared_ptr< xms::XmUGrid > TEST_XmUBuildPolyhedronUgrid(int a_rows, int a_cols, int a_lays)
Builds a UGrid of Quads at 1 spacing for rows & cols specified.
Definition: XmUGrid.cpp:3883
XmUGridCellType
Matches cell types from VTK (see vtkCellType.h)
Definition: XmUGrid.h:33
std::shared_ptr< XmUGrid > TEST_XmUGridSimpleQuad()
Builds a 2 cell (Quad) 2D XmUGrid for testing.
Definition: XmUGrid.cpp:3662
VecInt GetPointsAdjacentCells(const VecInt &a_points) const
Gets the common cells from a vector of points.
Definition: XmUGrid.cpp:3202
bool IsValidPointChange(int a_changedPtIdx, const Pt3d &a_newPosition) const
Determine whether adjacent cells are valid after a point is moved.
Definition: XmUGrid.cpp:3239
Pt3d GetPointLocation(int a_pointIdx) const
Get the point.
Definition: XmUGrid.cpp:3120
const VecPt3d & GetLocations() const
Get vector of UGrid points.
Definition: XmUGrid.cpp:3101
int GetCellDimension(int a_cellIdx) const
Get the dimension of the specified cell.
Definition: XmUGrid.cpp:3319
std::shared_ptr< XmUGrid > TEST_XmUGrid2dLinear()
Builds an XmUGrid with supported 1D and 2D linear cells for testing.
Definition: XmUGrid.cpp:3679
std::unique_ptr< Impl > m_impl
implementation
Definition: XmUGrid.h:194
void SetUseCache(bool a_useCache)
Turn on or off use of caching to speed up some operations.
Definition: XmUGrid.cpp:3081
void Swap(XmUGrid &a_xmUGrid)
Swap data between two XmUGrids.
Definition: XmUGrid.cpp:2937
int GetCellCount() const
Get the number of cells.
Definition: XmUGrid.cpp:3248
int GetCell3dFaceCount(int a_cellIdx) const
Get the number of cell faces for given cell.
Definition: XmUGrid.cpp:3541
std::vector< VecInt > VecInt2d
void SetUnmodified()
Resets the modified flag to false.
Definition: XmUGrid.cpp:3072
std::vector< int > GetDimensionCounts() const
Count all number of the cells with each dimenion (0, 1, 2, 3)
Definition: XmUGrid.cpp:3308
std::shared_ptr< XmUGrid > TEST_XmUGridHexagonalPolyhedron()
Builds a 1 cell hexagon with cell type polyhedron.
Definition: XmUGrid.cpp:3740
void GetCellExtents(int a_cellIdx, Pt3d &a_min, Pt3d &a_max) const
Get the extents of the given cell.
Definition: XmUGrid.cpp:3330
int GetCellPointCount(int a_cellIdx) const
Get the number of cell points (including polyhedron).
Definition: XmUGrid.cpp:3258
VecInt GetPointAdjacentCells(int a_pointIdx) const
Get the cells that are associated with the specified point.
Definition: XmUGrid.cpp:3181
bool GetModified() const
Returns the modified flag. Gets set when points or cells get changed.
Definition: XmUGrid.cpp:3064
void GetCellLocations(int a_cellIdx, VecPt3d &a_cellLocations) const
Get locations of cell points.
Definition: XmUGrid.cpp:3289
XmEdge GetCellEdge(int a_cellIdx, int a_edgeIdx) const
Get the points of a cell.
Definition: XmUGrid.cpp:3433
std::shared_ptr< xms::XmUGrid > TEST_XmUBuildQuadUGrid(int a_rows, int a_cols)
Builds a UGrid of Quads at 1 spacing for rows & cols specified.
Definition: XmUGrid.cpp:3769
Two integer values representing an edge of an XmUGrid. By default has a direction. Can be sorted to have minimum index first.
Definition: XmEdge.h:33
Geometry for an unstructured grid. An XmUGrid is defined as a vector of 3d points and a stream of cel...
Definition: XmUGrid.h:115
XmUGridFaceOrientation
The orientation of a 3D face must be one of these.
Definition: XmUGrid.h:104
std::shared_ptr< xms::XmUGrid > TEST_XmUBuild3DChevronUgrid()
Builds a UGrid with one 3D Chevron polyhedron.
Definition: XmUGrid.cpp:3980
void GetExtents(Pt3d &a_min, Pt3d &a_max) const
Get extents of all points in UGrid.
Definition: XmUGrid.cpp:3161
void SetLocations(const VecPt3d &a_locations)
Set UGrid points.
Definition: XmUGrid.cpp:3110
XMS Namespace.
Definition: geoms.cpp:34
bool GetCellPlanViewPolygon(int a_cellIdx, VecPt3d &a_polygon) const
Get a plan view polygon of a specified cell.
Definition: XmUGrid.cpp:3401
static bool IsValidCellstream(const VecInt &a_cellstream)
Check a cell stream to make sure it&#39;s valid. Compares cell type against expected number of points...
Definition: XmUGrid.cpp:2947
int GetPointAdjacentCellCount(int a_pointIdx) const
Get the number of cells that use a point.
Definition: XmUGrid.cpp:3171
const VecInt & GetCellstream() const
Get cell stream vector for the entire UGrid. A cellstream is defined as follows: Polyhedrons: Cell ty...
Definition: XmUGrid.cpp:3346
VecInt GetCellPoints(int a_cellIdx) const
Get the points of a cell (including polyhedron)
Definition: XmUGrid.cpp:3268
XmUGrid()
Constructor.
Definition: XmUGrid.cpp:2895
VecInt GetCell3dFacePoints(int a_cellIdx, int a_faceIdx) const
Get the cell face for given cell and face index.
Definition: XmUGrid.cpp:3562
~XmUGrid()
Destructor.
Definition: XmUGrid.cpp:2920
int GetCell2dEdgeAdjacentCell(int a_cellIdx, int a_edgeIdx) const
Get the index of the adjacent cells (that shares the same cell edge)
Definition: XmUGrid.cpp:3469
void GetEdgeAdjacentCells(const XmEdge &a_edge, VecInt &a_adjacentCellIdxs) const
Get the indices of the adjacent cells (that shares the same cell edge)
Definition: XmUGrid.cpp:3479
XmUGridFaceOrientation GetCell3dFaceOrientation(int a_cellIdx, int a_faceIdx) const
Get the orientation of the face of a vertically prismatic cell.
Definition: XmUGrid.cpp:3623
void GetPointAdjacentLocations(int a_pointIdx, VecPt3d &a_edgePoints) const
Given a point gets point locations attached to the point by an edge.
Definition: XmUGrid.cpp:3529
VecInt2d GetCell3dFacesPoints(int a_cellIdx) const
Get the faces of a cell.
Definition: XmUGrid.cpp:3584
int GetCell3dFaceAdjacentCell(int a_cellIdx, int a_faceIdx) const
Get the cell face neighbors for given cell and face index.
Definition: XmUGrid.cpp:3595
XmUGridCellType GetCellType(int a_cellIdx) const
Get the number of cells.
Definition: XmUGrid.cpp:3299
int GetPointCount() const
Get the number of points.
Definition: XmUGrid.cpp:3092
static std::shared_ptr< XmUGrid > New()
Create a new XmUGrid.
Definition: XmUGrid.cpp:2874
VecPt3d GetPointsLocations(const VecInt &a_points) const
Convert a vector of point indices into a vector of point 3d.
Definition: XmUGrid.cpp:3151
void GetPointAdjacentPoints(int a_pointIdx, VecInt &a_edgePoints) const
Given a point gets point indices attached to the point by an edge.
Definition: XmUGrid.cpp:3519
bool SetPointLocation(int a_pointIdx, const Pt3d &a_location)
Set the point.
Definition: XmUGrid.cpp:3131
std::vector< XmEdge > GetCellEdges(int a_cellIdx) const
Get the Edges of a cell.
Definition: XmUGrid.cpp:3499
int GetCell3dFacePointCount(int a_cellIdx, int a_faceIdx) const
Get the number of face points for a given cell and face.
Definition: XmUGrid.cpp:3551
bool GetCellCellstream(int a_cellIdx, VecInt &a_cellstream) const
Get cell stream vector for a single cell.
Definition: XmUGrid.cpp:3369
std::vector< Pt3d > VecPt3d