Memosa-FVM  0.2
AABB Class Reference

#include <AABB.h>

Classes

struct  MySegmentPrimitive
 
struct  MyTriangle
 
struct  MyTrianglePrimitive
 

Public Types

typedef Vector< double, 3 > Vec3D
 

Public Member Functions

 AABB (const Mesh &mesh)
 
bool hasIntersectionWithSegment (Vec3D a, Vec3D b)
 
bool hasIntersectionWithTriangle (Vec3D a, Vec3D b, Vec3D c)
 
int meshIntersections (const Mesh &mesh)
 
int findOrientedSide (Vec3D p)
 

Private Types

typedef CGAL::Simple_cartesian
< double > 
K
 
typedef K::Point_3 Point
 
typedef K::Point_2 Point2D
 
typedef K::Triangle_3 Triangle
 
typedef K::Plane_3 Plane
 
typedef K::Line_2 Line2D
 
typedef std::vector
< MyTriangle * >
::const_iterator 
MyTriangleIterator
 
typedef CGAL::AABB_traits< K,
MyTrianglePrimitive
My_AABB_traits
 
typedef CGAL::AABB_tree
< My_AABB_traits
CGAL_Tree
 
typedef CGAL::AABB_traits< K,
MySegmentPrimitive
My_AABB_traits_2D
 
typedef CGAL::AABB_tree
< My_AABB_traits_2D
CGAL_Tree_2D
 

Private Attributes

bool _is2D
 
std::vector< MyTriangle * > _triangles
 
boost::shared_ptr< CGAL_Tree_tree
 
boost::shared_ptr< CGAL_Tree_2D_tree_2D
 

Detailed Description

A wrapper for CGAL's axis aligned bounding box concept. We use this to compute intersections of the fluid mesh with the boundary mesh representing the solid. The tree is constructed with the faces of the latter and then we go through all the faces of the fluid mesh to find the ones that have intersections with any of the tree faces.

Definition at line 29 of file AABB.h.

Member Typedef Documentation

typedef CGAL::AABB_tree<My_AABB_traits> AABB::CGAL_Tree
private

Definition at line 255 of file AABB.h.

typedef CGAL::AABB_tree<My_AABB_traits_2D> AABB::CGAL_Tree_2D
private

Definition at line 258 of file AABB.h.

typedef CGAL::Simple_cartesian<double> AABB::K
private

Definition at line 67 of file AABB.h.

typedef K::Line_2 AABB::Line2D
private

Definition at line 73 of file AABB.h.

typedef CGAL::AABB_traits<K, MyTrianglePrimitive> AABB::My_AABB_traits
private

Definition at line 254 of file AABB.h.

typedef CGAL::AABB_traits<K, MySegmentPrimitive> AABB::My_AABB_traits_2D
private

Definition at line 257 of file AABB.h.

typedef std::vector<MyTriangle*>::const_iterator AABB::MyTriangleIterator
private

Definition at line 161 of file AABB.h.

typedef K::Plane_3 AABB::Plane
private

Definition at line 72 of file AABB.h.

typedef K::Point_3 AABB::Point
private

Definition at line 68 of file AABB.h.

typedef K::Point_2 AABB::Point2D
private

Definition at line 69 of file AABB.h.

typedef K::Triangle_3 AABB::Triangle
private

Definition at line 71 of file AABB.h.

typedef Vector<double,3> AABB::Vec3D

Definition at line 32 of file AABB.h.

Constructor & Destructor Documentation

AABB::AABB ( const Mesh mesh)

Definition at line 10 of file AABB.cpp.

References _is2D, _tree, _tree_2D, _triangles, Mesh::getBoundaryFaceGroups(), StorageSite::getCount(), CRConnectivity::getCount(), Mesh::getDimension(), Mesh::getFaceNodes(), Mesh::getNodeCoordinates(), and FaceGroup::site.

11 {
12  _is2D = mesh.getDimension() == 2;
13 
14  const Array<Vector<double,3> >& meshCoords = mesh.getNodeCoordinates();
15 
16 
17  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
18  {
19  const FaceGroup& fg = *fgPtr;
20  const StorageSite& faces = fg.site;
21  const CRConnectivity& faceNodes = mesh.getFaceNodes(faces);
22 
23  const int nFaces = faces.getCount();
24 
25  for(int f=0; f<nFaces; f++)
26  {
27  if (_is2D)
28  {
29  _triangles.push_back(new MyTriangle(f,meshCoords,
30  faceNodes(f,0),
31  faceNodes(f,1)));
32  }
33  else
34  {
35  _triangles.push_back(new MyTriangle(f,0,meshCoords,
36  faceNodes(f,0),
37  faceNodes(f,1),
38  faceNodes(f,2)));
39  if (faceNodes.getCount(f) == 4)
40  {
41 
42  _triangles.push_back(new MyTriangle(f,1,meshCoords,
43  faceNodes(f,2),
44  faceNodes(f,3),
45  faceNodes(f,0)));
46  }
47  }
48  }
49  }
50 
51  if (_is2D)
52  _tree_2D = boost::shared_ptr<CGAL_Tree_2D>(new CGAL_Tree_2D(_triangles.begin(),
53  _triangles.end()));
54  else
55  {
56  _tree = boost::shared_ptr<CGAL_Tree>(new CGAL_Tree(_triangles.begin(),
57  _triangles.end()));
58 
59  // _bbox = _tree->bbox();
60  }
61 }
const FaceGroupList & getBoundaryFaceGroups() const
Definition: Mesh.h:187
int getCount(const int i) const
shared_ptr< FaceGroup > FaceGroupPtr
Definition: Mesh.h:46
std::vector< MyTriangle * > _triangles
Definition: AABB.h:261
Definition: Mesh.h:28
const CRConnectivity & getFaceNodes(const StorageSite &site) const
Definition: Mesh.cpp:402
const Array< VecD3 > & getNodeCoordinates() const
Definition: Mesh.h:218
bool _is2D
Definition: AABB.h:260
CGAL::AABB_tree< My_AABB_traits_2D > CGAL_Tree_2D
Definition: AABB.h:258
Definition: Array.h:14
int getCount() const
Definition: StorageSite.h:39
boost::shared_ptr< CGAL_Tree > _tree
Definition: AABB.h:262
boost::shared_ptr< CGAL_Tree_2D > _tree_2D
Definition: AABB.h:263
int getDimension() const
Definition: Mesh.h:105
CGAL::AABB_tree< My_AABB_traits > CGAL_Tree
Definition: AABB.h:255
StorageSite site
Definition: Mesh.h:40

Member Function Documentation

int AABB::findOrientedSide ( AABB::Vec3D  p)

locate the side on which a given point lies. returns 0 if the point is on one of the faces of the tree, -1 if it's inside and 1 if it is outside. This check is only meaningful if the faces of the tree form a closed surface.

Definition at line 156 of file AABB.cpp.

References _is2D, _triangles, AABB::MyTriangle::getLine2D(), AABB::MyTriangle::getPlane(), AABB::MyTriangle::getSegment2D(), and AABB::MyTriangle::getTriangle().

157 {
158  if (_is2D)
159  {
160  K::Point_2 query(p[0], p[1]);
161  foreach(const MyTriangle* myt, _triangles)
162  {
163  Line2D line = myt->getLine2D();
164  CGAL::Oriented_side orientation = line.oriented_side(query);
165  if (orientation == CGAL::ON_POSITIVE_SIDE)
166  return 1;
167  else if (orientation == CGAL::ON_ORIENTED_BOUNDARY)
168  {
169  K::Segment_2 segment = myt->getSegment2D();
170  if (segment.has_on(query))
171  return 0;
172  }
173  }
174  return -1;
175  }
176  else
177  {
178  K::Point_3 query(p[0], p[1], p[2]);
179  foreach(const MyTriangle* myt, _triangles)
180  {
181  Plane plane = myt->getPlane();
182  CGAL::Oriented_side orientation = plane.oriented_side(query);
183  if (orientation == CGAL::ON_POSITIVE_SIDE)
184  return 1;
185  else if (orientation == CGAL::ON_ORIENTED_BOUNDARY)
186  {
187  Triangle triangle = myt->getTriangle();
188  if (triangle.has_on(query))
189  return 0;
190  }
191  }
192  return -1;
193  }
194 }
std::vector< MyTriangle * > _triangles
Definition: AABB.h:261
K::Triangle_3 Triangle
Definition: AABB.h:71
K::Plane_3 Plane
Definition: AABB.h:72
bool _is2D
Definition: AABB.h:260
K::Line_2 Line2D
Definition: AABB.h:73
bool AABB::hasIntersectionWithSegment ( AABB::Vec3D  a,
AABB::Vec3D  b 
)

check whether a segment defined by the two points a and b has any intersections with the faces of the tree

Definition at line 64 of file AABB.cpp.

References _is2D, and _tree.

65 {
66  if (_is2D)
67  {
68  // can't do this check sine we are using 3d segments
69  return false;
70  }
71  else
72  {
73  K::Segment_3 query(K::Point_3(a[0], a[1], a[2]),
74  K::Point_3(b[0], b[1], b[2]));
75  return _tree->do_intersect(query);
76  }
77 }
bool _is2D
Definition: AABB.h:260
boost::shared_ptr< CGAL_Tree > _tree
Definition: AABB.h:262
bool AABB::hasIntersectionWithTriangle ( AABB::Vec3D  a,
AABB::Vec3D  b,
AABB::Vec3D  c 
)

check whether a triangle defined by the three points a, b and c has any intersections with the faces of the tree

Definition at line 81 of file AABB.cpp.

References _is2D, _tree, and _tree_2D.

Referenced by IBManager::markIntersections(), and meshIntersections().

82 {
83  K::Triangle_3 query(K::Point_3(a[0], a[1], a[2]),
84  K::Point_3(b[0], b[1], b[2]),
85  K::Point_3(c[0], c[1], c[2])
86  );
87  if (_is2D)
88  return _tree_2D->do_intersect(query);
89  else
90  return _tree->do_intersect(query);
91 }
bool _is2D
Definition: AABB.h:260
boost::shared_ptr< CGAL_Tree > _tree
Definition: AABB.h:262
boost::shared_ptr< CGAL_Tree_2D > _tree_2D
Definition: AABB.h:263
int AABB::meshIntersections ( const Mesh mesh)

Definition at line 94 of file AABB.cpp.

References _is2D, Mesh::getAllFaceNodes(), Mesh::getCellNodes(), Mesh::getCells(), StorageSite::getCount(), CRConnectivity::getCount(), Mesh::getFaces(), Mesh::getNodeCoordinates(), StorageSite::getSelfCount(), and hasIntersectionWithTriangle().

95 {
96  const Array<Vector<double,3> >& meshCoords = mesh.getNodeCoordinates();
97  int nIntersections = 0;
98 
99  if (_is2D)
100  {
101  const StorageSite& cells = mesh.getCells();
102  const CRConnectivity& cellNodes = mesh.getCellNodes();
103 
104  const int nCells = cells.getSelfCount();
105  for(int n=0; n<nCells; n++)
106  {
107  const Vec3D& a = meshCoords[cellNodes(n,0)];
108  const Vec3D& b = meshCoords[cellNodes(n,1)];
109  const Vec3D& c = meshCoords[cellNodes(n,2)];
110 
111  if (hasIntersectionWithTriangle(a,b,c))
112  {
113  nIntersections++;
114  }
115  else if (cellNodes.getCount(n) == 4)
116  {
117 
118  const Vec3D& d = meshCoords[cellNodes(n,3)];
119  if (hasIntersectionWithTriangle(c,d,a))
120  {
121  nIntersections++;
122  }
123  }
124  }
125  }
126  else
127  {
128  const StorageSite& faces = mesh.getFaces();
129  const CRConnectivity& faceNodes = mesh.getAllFaceNodes();
130 
131  const int nFaces = faces.getCount();
132  for(int n=0; n<nFaces; n++)
133  {
134  const Vec3D& a = meshCoords[faceNodes(n,0)];
135  const Vec3D& b = meshCoords[faceNodes(n,1)];
136  const Vec3D& c = meshCoords[faceNodes(n,2)];
137 
138  if (hasIntersectionWithTriangle(a,b,c))
139  {
140  nIntersections++;
141  }
142  else if (faceNodes.getCount(n) == 4)
143  {
144 
145  const Vec3D& d = meshCoords[faceNodes(n,3)];
146  if (hasIntersectionWithTriangle(c,d,a))
147  {
148  nIntersections++;
149  }
150  }
151  }
152  }
153  return nIntersections;
154 }
const CRConnectivity & getAllFaceNodes() const
Definition: Mesh.cpp:368
int getCount(const int i) const
int getSelfCount() const
Definition: StorageSite.h:40
bool hasIntersectionWithTriangle(Vec3D a, Vec3D b, Vec3D c)
Definition: AABB.cpp:81
const Array< VecD3 > & getNodeCoordinates() const
Definition: Mesh.h:218
bool _is2D
Definition: AABB.h:260
const StorageSite & getFaces() const
Definition: Mesh.h:108
const StorageSite & getCells() const
Definition: Mesh.h:109
Definition: Array.h:14
int getCount() const
Definition: StorageSite.h:39
Vector< double, 3 > Vec3D
Definition: AABB.h:32
const CRConnectivity & getCellNodes() const
Definition: Mesh.cpp:426

Member Data Documentation

bool AABB::_is2D
private
boost::shared_ptr<CGAL_Tree> AABB::_tree
private

Definition at line 262 of file AABB.h.

Referenced by AABB(), hasIntersectionWithSegment(), and hasIntersectionWithTriangle().

boost::shared_ptr<CGAL_Tree_2D> AABB::_tree_2D
private

Definition at line 263 of file AABB.h.

Referenced by AABB(), and hasIntersectionWithTriangle().

std::vector<MyTriangle*> AABB::_triangles
private

Definition at line 261 of file AABB.h.

Referenced by AABB(), and findOrientedSide().


The documentation for this class was generated from the following files: