Chombo + EB  3.2
STLExplorer.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _STLEXPLORER_H_
12 #define _STLEXPLORER_H_
13 
14 #include "ProblemDomain.H"
15 #include "RealVect.H"
16 #include "IntVect.H"
17 #include "Box.H"
18 #include "MayDay.H"
19 #include "RefCountedPtr.H"
20 
21 #include "STLMesh.H"
22 #include "STLBox.H"
23 #include "CellEdge.H"
24 
25 #include "KDTree.H"
26 
27 #include "NamespaceHeader.H"
28 
29 /*
30  * Class to explore an STL mesh
31  * has member functions that
32  * 1) build a K-D tree of the vertices
33  * 2) search for nearest triangles given
34  * a) a point (return 1 triangle)
35  * b) a cell/volume (return all triangles with some part inside the volume)
36  * 3) find intersection of a triangle with a single edge
37  * 4) find intersection(s) of the whole mesh and an edge
38  */
39 
41 {
42 public:
43 
44  /// Constructor - just need a mesh
46 
47  /*
48  /// Copy constructor
49  STLExplorer(const STLExplorer& a_inputExplorer);
50  */
51 
52  /// Destructor
53  ~STLExplorer();
54 
55  /// builds cellToTriangles - connectivity between box and stlmesh
56  void Explore(RefCountedPtr<STLBox> a_sb);
57 
58  void Explore(const Box& a_region,
59  const ProblemDomain& a_domain,
60  const RealVect& a_origin,
61  const RealVect& a_dx);
62 
63 
64  /// return the point of intersection between a cellEdge and the mesh
65  /// and whether the two nodes are inside or outside
66  /// a_intersectPt is bogus if both nodes are inside or both outside
67  void GetCellEdgeIntersection(const CellEdge& a_celledge,
68  RealVect& a_intersectPt,
69  bool& a_isNode0Inside,
70  bool& a_isNode1Inside);
71 
72  /// return whether or not a point is inside or outside the domain
73  void GetPointInOut(const IntVect& a_point,
74  bool& a_inout);
75 
76  // get methods for temporary variables
77  void GetVertMap(Vector<IntVect>** a_vertmap);
78  void GetTriMap(Vector<Vector<IntVect> >** a_trimap);
79  void GetSTLBox(RefCountedPtr<STLBox>& a_sb);
80 
81 protected:
82 
83  // actual data (shared)
84  RefCountedPtr<STLMesh> m_msh; // pointer to mesh
85  RefCountedPtr<STLBox> m_sb; // pointer to mesh<->box data
86  KDTree* m_ptree; // pointer to the KDTree of nodes
87 
88  bool m_freestlbox; // true if STLExplorer should free the stlbox when destroyed
89  bool m_printdebug; // if true, will print (lots of) debug info
90 
91  // (temporary data holder) vertex index -> cell (cell that a vertex is in)
92  // only used in FindCellsOnEdges (to fill in cells between vertices of mesh)
93  // NOTE: this structure may contain IntVects that are invalid (outside of m_box)
95 
96  // (temporary data holder) triangle index -> cell (Vector of cells in a given triangle)
97  // only used in FindCellsInTriangles (to fill in intervening cells within triangles)
98  // NOTE: this structure may contain IntVects that are invalid (outside of m_box)
100 
101  // overall function to explore a box
102  void DoExplore();
103 
104  // sets map<IntVect,TriInCell> cellmap (adds on cells as we find them)
105  // and Vector<Intvect> vertmap
106  void FindCellsOnVertices();
107 
108  // goes along triangle edges and finds cells (sets left & right triangles)
109  // sets cellmap (inserts cells) and trimap
110  void FindCellsOnEdges();
111 
112  // fills in any cells completely contained by the triangle
113  // sets cellmap (inserts cells) and trimap
114  void FindCellsInTriangles();
115 
116  // removes all cells that lie outside of the Box from consideration
117  // modifies cellmap, trimap, vertmap (call before setting edgemap and nodemap)
119 
120  // stores the set of cell edges on the boundary
121  // builds edgemap and nodemap
122  void FindCellEdgesOnBondary();
123 
124  // builds a KDTree of the nodes that we know are inside/outside
125  void BuildKDTree();
126 
127  // returns whether node0 or node1 of the cell edge is inside the domain
128  bool WhichNodeIsInside(const CellEdge& celledge,
129  const int& triangle);
130 
131  // returns whether node0 and node1
132  void FindEdgeInOut(const CellEdge& celledge,
133  bool& isNode0Inside,
134  bool& isNode1Inside);
135 
136  // same as above, but uses a KDTree instead of exhaustive search
137  void FindEdgeInOutWithKDTree(const CellEdge& celledge,
138  bool& isNode0Inside,
139  bool& isNode1Inside);
140 
141  // given a triangle and an edge, find the intersection
143  const int& triangle);
144 
145  // return true if point lies within the triangle (up to the tolerance mesh.tol??)
146  bool IsPointInTriangle(const RealVect& point,
147  const int& triangle);
148 
149  // return true if the point lies on the edge (up to the tolerance mesh.tol)
150  bool IsPointOnCellEdge(const RealVect& point,
151  const CellEdge& celledge);
152 
153  // note, i is an input and is incremented in FillInCellLine
154  void FillInCellLine(vector<IntVect>& cells,
155  int& i,
156  const int& itri,
157  const int& idir0,
158  const int& idir1);
159 
160 protected:
161  void RecursiveKDTreeInsert(vector<pair<RealVect,pair<IntVect,bool>*> > &allNodes,
162  const int &nstart,
163  const int &nend,
164  const int &depth);
165 
166 private:
168  {
169  MayDay::Abort("STLExplorer uses strong construction");
170  }
171 
172  void operator=(const STLExplorer& a_inputReader)
173  {
174  MayDay::Abort("STLExplorer doesn't allow assignment");
175  }
176 };
177 
178 #include "NamespaceFooter.H"
179 #endif
180 
KDTree * m_ptree
Definition: STLExplorer.H:86
bool m_freestlbox
Definition: STLExplorer.H:88
bool m_printdebug
Definition: STLExplorer.H:89
void FindCellsOnEdges()
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
void RecursiveKDTreeInsert(vector< pair< RealVect, pair< IntVect, bool > * > > &allNodes, const int &nstart, const int &nend, const int &depth)
RefCountedPtr< STLBox > m_sb
Definition: STLExplorer.H:85
void operator=(const STLExplorer &a_inputReader)
Definition: STLExplorer.H:172
void GetTriMap(Vector< Vector< IntVect > > **a_trimap)
void GetVertMap(Vector< IntVect > **a_vertmap)
Vector< Vector< IntVect > > m_trimap
Definition: STLExplorer.H:99
STLExplorer()
Definition: STLExplorer.H:167
void GetSTLBox(RefCountedPtr< STLBox > &a_sb)
void BuildKDTree()
void FindCellsInTriangles()
void FillInCellLine(vector< IntVect > &cells, int &i, const int &itri, const int &idir0, const int &idir1)
void Explore(RefCountedPtr< STLBox > a_sb)
builds cellToTriangles - connectivity between box and stlmesh
void FindEdgeInOut(const CellEdge &celledge, bool &isNode0Inside, bool &isNode1Inside)
Vector< IntVect > m_vertmap
Definition: STLExplorer.H:94
Definition: STLExplorer.H:40
Definition: KDStruct.H:98
bool IsPointInTriangle(const RealVect &point, const int &triangle)
Definition: CellEdge.H:21
void GetPointInOut(const IntVect &a_point, bool &a_inout)
return whether or not a point is inside or outside the domain
RealVect FindPlaneLineIntersection(const CellEdge &celledge, const int &triangle)
bool WhichNodeIsInside(const CellEdge &celledge, const int &triangle)
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
RefCountedPtr< STLMesh > m_msh
Definition: STLExplorer.H:84
void DoExplore()
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
~STLExplorer()
Destructor.
void FindCellEdgesOnBondary()
void GetCellEdgeIntersection(const CellEdge &a_celledge, RealVect &a_intersectPt, bool &a_isNode0Inside, bool &a_isNode1Inside)
void FindEdgeInOutWithKDTree(const CellEdge &celledge, bool &isNode0Inside, bool &isNode1Inside)
bool IsPointOnCellEdge(const RealVect &point, const CellEdge &celledge)
void FindCellsOnVertices()
void RemoveCellsOutsideDomain()
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).