NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
NEM::GEO::convexContainer Class Reference

An implementation of convex container object for point The class implements methods to generate a convex hull for a point cloud, perform point location, and output to STL format. More...

Detailed Description

Note
Only use for convex objects.

Definition at line 113 of file convexContainer.H.

Public Member Functions

 convexContainer ()
 default constructor More...
 
 convexContainer (std::vector< std::vector< double > > &verts)
 construct from a vector point coordinates More...
 
 convexContainer (std::vector< quickhull::Vector3< double > > &verts)
 
virtual ~convexContainer ()
 
virtual void setVertex (std::vector< std::vector< double > > &verts)
 re-/setting vertice coordinates More...
 
virtual void computeConvexHull ()
 calculating the convex hull More...
 
bool isInConvexPoly (NEM::MTH::Vector const &p)
 check for point containment More...
 
bool isInConvexPoly (const std::vector< double > &p)
 
void toSTL (std::string file_name) const
 generate STL triangulation from the convex hull More...
 

Private Attributes

bool _isReady
 
std::vector< quickhull::Vector3< double > > vrts
 
quickhull::QuickHull< double > * qHull
 
std::vector< Facefv
 

Constructor & Destructor Documentation

◆ convexContainer() [1/3]

NEM::GEO::convexContainer::convexContainer ( )

Definition at line 38 of file convexContainer.C.

38  :
39  _isReady(false)
40 {}

◆ convexContainer() [2/3]

NEM::GEO::convexContainer::convexContainer ( std::vector< std::vector< double > > &  verts)
Parameters
vertsvector of vector of doubles of point coordinats

Definition at line 43 of file convexContainer.C.

References setVertex().

44 {
45  // deep copying
46  setVertex(inVrts);
47 }
virtual void setVertex(std::vector< std::vector< double > > &verts)
re-/setting vertice coordinates

◆ convexContainer() [3/3]

NEM::GEO::convexContainer::convexContainer ( std::vector< quickhull::Vector3< double > > &  verts)

Definition at line 49 of file convexContainer.C.

References vrts.

50 {
51  // deep copying
52  for (auto itr=inVrts.begin(); itr!=inVrts.end(); itr++)
53  vrts.emplace_back(*itr);
54 }
std::vector< quickhull::Vector3< double > > vrts

◆ ~convexContainer()

virtual NEM::GEO::convexContainer::~convexContainer ( )
inlinevirtual

Definition at line 127 of file convexContainer.H.

127 {};

Member Function Documentation

◆ computeConvexHull()

void NEM::GEO::convexContainer::computeConvexHull ( )
virtual

Definition at line 63 of file convexContainer.C.

References _isReady, fv, qHull, NEM::GEO::Face::v, vrts, NEM::MTH::Vector::x, NEM::MTH::Vector::y, and NEM::MTH::Vector::z.

Referenced by isInConvexPoly().

64 {
65  // computes/re-computes convex hull of the verices
66  std::vector<size_t> indxBuf;
67  quickhull::VertexDataSource<double> vrtBuf;
68  qHull = new quickhull::QuickHull<double>();
69  auto hull = qHull->getConvexHull(vrts, false, false, 1.e-14);
70  indxBuf = hull.getIndexBuffer();
71  vrtBuf = hull.getVertexBuffer();
72 
73  // converting to face-vector format
74  //std::cout << "Size of index buffer = "
75  // << indxBuf.size() << std::endl;
76 
77  // saving to vf
78  for (int it=0; it<indxBuf.size(); it+=3)
79  {
80  Face f;
81  for (int idx=0; idx<3; idx++)
82  {
83  NEM::MTH::Vector pnt;
84  pnt.x = (vrtBuf[indxBuf[it+idx]]).x;
85  pnt.y = (vrtBuf[indxBuf[it+idx]]).y;
86  pnt.z = (vrtBuf[indxBuf[it+idx]]).z;
87  f.v.push_back(pnt);
88  }
89  fv.push_back(f);
90  }
91 
92  _isReady = true;
93 
94 }
std::vector< quickhull::Vector3< double > > vrts
std::vector< Face > fv
quickhull::QuickHull< double > * qHull

◆ isInConvexPoly() [1/2]

bool NEM::GEO::convexContainer::isInConvexPoly ( NEM::MTH::Vector const &  p)
Parameters
pvector of coordinates of the point

Definition at line 96 of file convexContainer.C.

References _isReady, computeConvexHull(), NEM::MTH::Vector::dot(), fv, and NEM::MTH::Vector::norm().

Referenced by isInConvexPoly().

96  {
97  // check readiness
98  if (!_isReady)
100 
101  // looping through faces
102  for (Face const& f : fv) {
103  NEM::MTH::Vector p2f = f.v[0] - p; // f.v[0] is an arbitrary point on f
104  double d = p2f.dot(f.normal());
105  d /= p2f.norm(); // for numeric stability
106 
107  constexpr double bound = -1e-15; // use 1e15 to exclude boundaries
108  if (d < bound)
109  return false;
110  }
111  return true;
112 }
double norm() const
double dot(Vector p) const
virtual void computeConvexHull()
calculating the convex hull
std::vector< Face > fv

◆ isInConvexPoly() [2/2]

bool NEM::GEO::convexContainer::isInConvexPoly ( const std::vector< double > &  p)

Definition at line 114 of file convexContainer.C.

References isInConvexPoly(), NEM::MTH::Vector::x, NEM::MTH::Vector::y, and NEM::MTH::Vector::z.

114  {
115  if (p.size() != 3)
116  throw;
117  NEM::MTH::Vector pnt;
118  pnt.x = p[0];
119  pnt.y = p[1];
120  pnt.z = p[2];
121  return(isInConvexPoly(pnt));
122 }
bool isInConvexPoly(NEM::MTH::Vector const &p)
check for point containment

◆ setVertex()

void NEM::GEO::convexContainer::setVertex ( std::vector< std::vector< double > > &  verts)
virtual
Parameters
vertsvector of vector of doubles of point coordinats

Definition at line 56 of file convexContainer.C.

References vrts.

Referenced by convexContainer().

57 {
58  // deep copying
59  for (auto itr=inVrts.begin(); itr!=inVrts.end(); itr++)
60  vrts.emplace_back((*itr)[0], (*itr)[1], (*itr)[2]);
61 }
std::vector< quickhull::Vector3< double > > vrts

◆ toSTL()

void NEM::GEO::convexContainer::toSTL ( std::string  file_name) const
Parameters
file_namefull path to the output STL file

Definition at line 124 of file convexContainer.C.

References fv, NEM::MTH::Vector::x, NEM::MTH::Vector::y, and NEM::MTH::Vector::z.

124  {
125 
126  //ascii file
127  std::ofstream myfile;
128  myfile.open((file_name + ".stl").c_str(), std::ios::out | std::ios::binary);
129  myfile << "solid "
130  << file_name
131  << "\n";
132 
133  //write down every triangle
134  for (auto it = fv.begin(); it!=fv.end(); it++){
135 
136  //normal vector coordinates
137  NEM::MTH::Vector n = it->normal();
138  myfile << "facet normal ";
139  myfile << n.x << " " << n.y << " " << n.z << "\n";
140 
141  myfile << "\touter loop\n";
142  //vertex coordinates
143  for (int iv=0; iv<3; iv++)
144  {
145  myfile << "\t\tvertex "
146  << (it->v[iv]).x << " "
147  << (it->v[iv]).y << " "
148  << (it->v[iv]).z << "\n";
149  }
150  myfile << "\tendloop\n";
151  myfile << "endfacet\n";
152  }
153  myfile << "endsolid " << file_name << "\n";
154  myfile.close();
155 
156 }
std::vector< Face > fv

Member Data Documentation

◆ _isReady

bool NEM::GEO::convexContainer::_isReady
private

Definition at line 153 of file convexContainer.H.

Referenced by computeConvexHull(), and isInConvexPoly().

◆ fv

std::vector<Face> NEM::GEO::convexContainer::fv
private

Definition at line 156 of file convexContainer.H.

Referenced by computeConvexHull(), isInConvexPoly(), and toSTL().

◆ qHull

quickhull::QuickHull<double>* NEM::GEO::convexContainer::qHull
private

Definition at line 155 of file convexContainer.H.

Referenced by computeConvexHull().

◆ vrts

std::vector<quickhull::Vector3<double> > NEM::GEO::convexContainer::vrts
private

Definition at line 154 of file convexContainer.H.

Referenced by computeConvexHull(), convexContainer(), and setVertex().


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