Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Nektar::NekMeshUtils::CADSystem Class Reference

Base class for CAD interface system. More...

#include <CADSystem.h>

Collaboration diagram for Nektar::NekMeshUtils::CADSystem:
Collaboration graph
[legend]

Public Member Functions

 CADSystem (const std::string &name)
 Default constructor. More...
 
std::string GetName ()
 Return the name of the CAD system. More...
 
bool LoadCAD ()
 Initialises CAD and makes surface, curve and vertex maps. More...
 
void Report ()
 Reports basic properties to screen. More...
 
Array< OneD, NekDoubleGetBoundingBox ()
 Returns bounding box of the domain. More...
 
int GetNumSurf ()
 Get the number of surfaces. More...
 
int GetNumCurve ()
 Get the number of curves. More...
 
CADCurveSharedPtr GetCurve (int i)
 Gets a curve from the map. More...
 
CADSurfSharedPtr GetSurf (int i)
 Gets a surface from the map. More...
 
std::map< int, CADVertSharedPtrGetVerts ()
 Gets map of all vertices. More...
 
int GetNumVerts ()
 Gets number of vertices. More...
 
bool InsideShape (Array< OneD, NekDouble > loc)
 based on location in space, uses opencascade routines to determin if the point is within the domain. This routine is slow and should be used sparingly, it is smart enough to take and form of geometry More...
 

Private Member Functions

void AddVert (int i, TopoDS_Shape in)
 Function to add curve to CADSystem::m_verts. More...
 
void AddCurve (int i, TopoDS_Shape in, int fv, int lv)
 Function to add curve to CADSystem::m_curves. More...
 
void AddSurf (int i, TopoDS_Shape in, std::vector< EdgeLoop > ein)
 Function to add surface to CADSystem::m_surfs. More...
 

Private Attributes

std::string m_name
 Name of cad file to be opened, including file extension. More...
 
std::map< int, CADCurveSharedPtrm_curves
 Map of curves. More...
 
std::map< int, CADSurfSharedPtrm_surfs
 Map of surfaces. More...
 
std::map< int, CADVertSharedPtrm_verts
 Map of vertices. More...
 
TopoDS_Shape shape
 OCC master object. More...
 

Friends

class MemoryManager< CADSystem >
 

Detailed Description

Base class for CAD interface system.

A class which can load and interact with CAD for Nektar++ using OpenCascade. This class contains maps to subclasses surface and curves.

Definition at line 65 of file CADSystem.h.

Constructor & Destructor Documentation

Nektar::NekMeshUtils::CADSystem::CADSystem ( const std::string &  name)
inline

Default constructor.

Definition at line 73 of file CADSystem.h.

73  : m_name(name)
74  {
75  }
std::string m_name
Name of cad file to be opened, including file extension.
Definition: CADSystem.h:174

Member Function Documentation

void Nektar::NekMeshUtils::CADSystem::AddCurve ( int  i,
TopoDS_Shape  in,
int  fv,
int  lv 
)
private

Function to add curve to CADSystem::m_curves.

Definition at line 358 of file CADSystem.cpp.

359 {
360  CADCurveSharedPtr newCurve =
362 
363  vector<CADVertSharedPtr> vs;
364  vs.push_back(m_verts[fv]);
365  vs.push_back(m_verts[lv]);
366  m_curves[i] = newCurve;
367  m_curves[i]->SetVert(vs);
368 }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition: CADSystem.h:176
std::map< int, CADVertSharedPtr > m_verts
Map of vertices.
Definition: CADSystem.h:180
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:168
void Nektar::NekMeshUtils::CADSystem::AddSurf ( int  i,
TopoDS_Shape  in,
std::vector< EdgeLoop ein 
)
private

Function to add surface to CADSystem::m_surfs.

Definition at line 370 of file CADSystem.cpp.

References ASSERTL0.

371 {
372  CADSurfSharedPtr newSurf =
374  m_surfs[i] = newSurf;
375 
376  if (in.Orientation() == 0)
377  {
378  m_surfs[i]->SetReverseNomral();
379  }
380 
381  int tote = 0;
382  for (int i = 0; i < ein.size(); i++)
383  {
384  tote += ein[i].edges.size();
385  }
386 
387  ASSERTL0(tote != 1, "cannot handle periodic curves");
388 
389  if (tote == 2)
390  {
391  m_surfs[i]->SetTwoC();
392  }
393 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< CADSurf > CADSurfSharedPtr
Definition: CADSurf.h:217
std::map< int, CADSurfSharedPtr > m_surfs
Map of surfaces.
Definition: CADSystem.h:178
void Nektar::NekMeshUtils::CADSystem::AddVert ( int  i,
TopoDS_Shape  in 
)
private

Function to add curve to CADSystem::m_verts.

Definition at line 351 of file CADSystem.cpp.

352 {
354 
355  m_verts[i] = newVert;
356 }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::map< int, CADVertSharedPtr > m_verts
Map of vertices.
Definition: CADSystem.h:180
boost::shared_ptr< CADVert > CADVertSharedPtr
Definition: CADSystem.h:51
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSystem::GetBoundingBox ( )

Returns bounding box of the domain.

Gets the bounding box of the domain by considering the start and end points of each curve in the geometry.

Returns
Array with 6 entries: xmin, xmax, ymin, ymax, zmin and zmax.

Definition at line 64 of file CADSystem.cpp.

65 {
66  Array<OneD, NekDouble> bound(6);
67  bound[0] = numeric_limits<double>::max(); // xmin
68  bound[1] = numeric_limits<double>::min(); // xmax
69  bound[2] = numeric_limits<double>::max(); // ymin
70  bound[3] = numeric_limits<double>::min(); // ymax
71  bound[4] = numeric_limits<double>::max(); // zmin
72  bound[5] = numeric_limits<double>::min(); // zmax
73 
74  for (int i = 1; i <= m_curves.size(); i++)
75  {
76  gp_Pnt start, end;
78  Array<OneD, NekDouble> ends = c->GetMinMax();
79 
80  bound[0] = min(bound[0], min(ends[0], ends[3]));
81  bound[1] = max(bound[1], max(ends[0], ends[3]));
82 
83  bound[2] = min(bound[2], min(ends[1], ends[4]));
84  bound[3] = max(bound[3], max(ends[1], ends[4]));
85 
86  bound[4] = min(bound[4], min(ends[2], ends[5]));
87  bound[5] = max(bound[5], max(ends[2], ends[5]));
88  }
89 
90  return bound;
91 }
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition: CADSystem.h:176
CADCurveSharedPtr GetCurve(int i)
Gets a curve from the map.
Definition: CADSystem.h:123
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:168
CADCurveSharedPtr Nektar::NekMeshUtils::CADSystem::GetCurve ( int  i)
inline

Gets a curve from the map.

Definition at line 123 of file CADSystem.h.

References ASSERTL0, Nektar::iterator, and m_curves.

124  {
126  ASSERTL0(search != m_curves.end(), "curve does not exist");
127 
128  return search->second;
129  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition: CADSystem.h:176
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
string Nektar::NekMeshUtils::CADSystem::GetName ( )

Return the name of the CAD system.

Definition at line 52 of file CADSystem.cpp.

53 {
54  return m_name;
55 }
std::string m_name
Name of cad file to be opened, including file extension.
Definition: CADSystem.h:174
int Nektar::NekMeshUtils::CADSystem::GetNumCurve ( )
inline

Get the number of curves.

Definition at line 115 of file CADSystem.h.

References m_curves.

116  {
117  return m_curves.size();
118  }
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition: CADSystem.h:176
int Nektar::NekMeshUtils::CADSystem::GetNumSurf ( )
inline

Get the number of surfaces.

Definition at line 107 of file CADSystem.h.

References m_surfs.

108  {
109  return m_surfs.size();
110  }
std::map< int, CADSurfSharedPtr > m_surfs
Map of surfaces.
Definition: CADSystem.h:178
int Nektar::NekMeshUtils::CADSystem::GetNumVerts ( )
inline

Gets number of vertices.

Definition at line 153 of file CADSystem.h.

References m_verts.

154  {
155  return m_verts.size();
156  }
std::map< int, CADVertSharedPtr > m_verts
Map of vertices.
Definition: CADSystem.h:180
CADSurfSharedPtr Nektar::NekMeshUtils::CADSystem::GetSurf ( int  i)
inline

Gets a surface from the map.

Definition at line 134 of file CADSystem.h.

References ASSERTL0, Nektar::iterator, and m_surfs.

135  {
137  ASSERTL0(search != m_surfs.end(), "surface does not exist");
138 
139  return search->second;
140  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< int, CADSurfSharedPtr > m_surfs
Map of surfaces.
Definition: CADSystem.h:178
std::map<int, CADVertSharedPtr> Nektar::NekMeshUtils::CADSystem::GetVerts ( )
inline

Gets map of all vertices.

Definition at line 145 of file CADSystem.h.

References m_verts.

146  {
147  return m_verts;
148  }
std::map< int, CADVertSharedPtr > m_verts
Map of vertices.
Definition: CADSystem.h:180
bool Nektar::NekMeshUtils::CADSystem::InsideShape ( Array< OneD, NekDouble loc)

based on location in space, uses opencascade routines to determin if the point is within the domain. This routine is slow and should be used sparingly, it is smart enough to take and form of geometry

Definition at line 395 of file CADSystem.cpp.

396 {
397  gp_Pnt p(loc[0] * 1000.0, loc[1] * 1000.0, loc[2] * 1000.0);
398 
399  BRepClass3d_SolidClassifier test(shape, p, 1E-7);
400  if (test.State() == TopAbs_IN || test.State() == TopAbs_ON)
401  {
402  return true;
403  }
404  else
405  {
406  return false;
407  }
408 }
TopoDS_Shape shape
OCC master object.
Definition: CADSystem.h:182
bool Nektar::NekMeshUtils::CADSystem::LoadCAD ( )

Initialises CAD and makes surface, curve and vertex maps.

Returns
true if completed successfully

TODO fix this test

Definition at line 93 of file CADSystem.cpp.

References ASSERTL0, Nektar::NekMeshUtils::EdgeLoop::center, Nektar::NekMeshUtils::curve, Nektar::NekMeshUtils::EdgeLoop::edgeo, Nektar::NekMeshUtils::EdgeLoop::edges, and Nektar::iterator.

94 {
95  if (!boost::filesystem::exists(m_name.c_str()))
96  {
97  return false;
98  }
99 
100  string ext;
101  size_t pos = m_name.find(".");
102  ext = m_name.substr(pos);
103 
104  if (boost::iequals(ext, ".STEP") || boost::iequals(ext, ".STP"))
105  {
106  // Takes step file and makes OpenCascade shape
107  STEPControl_Reader reader;
108  reader = STEPControl_Reader();
109  reader.ReadFile(m_name.c_str());
110  reader.NbRootsForTransfer();
111  reader.TransferRoots();
112  shape = reader.OneShape();
113  if (shape.IsNull())
114  {
115  return false;
116  }
117  }
118  else if (boost::iequals(ext, ".IGES") || boost::iequals(ext, ".IGS"))
119  {
120  // Takes IGES file and makes OpenCascade shape
121  IGESControl_Reader reader;
122  reader = IGESControl_Reader();
123  reader.ReadFile(m_name.c_str());
124  reader.NbRootsForTransfer();
125  reader.TransferRoots();
126  shape = reader.OneShape();
127  if (shape.IsNull())
128  {
129  return false;
130  }
131  }
132  else
133  {
134  return false;
135  }
136 
137  // faces and verts can be extracted straight from shape
138  TopTools_IndexedMapOfShape mapOfVerts, mapOfFaces;
139  TopExp::MapShapes(shape, TopAbs_VERTEX, mapOfVerts);
140  TopExp::MapShapes(shape, TopAbs_FACE, mapOfFaces);
141 
142  // edges need to be built from loops around faces to elimiate degen and
143  // hanging edges
144  TopTools_IndexedMapOfShape mapOfEdges;
145 
146  // build map of verticies
147  for (int i = 1; i <= mapOfVerts.Extent(); i++)
148  {
149  TopoDS_Shape v = mapOfVerts.FindKey(i);
150  AddVert(i, v);
151  }
152 
153  // For each face of the geometry, get the local edges which bound it. If
154  // they are valid (their type != 7), then add them to an edge map. This
155  // filters out the dummy edges which OCC uses.
156  for (int i = 1; i <= mapOfFaces.Extent(); i++)
157  {
158  TopoDS_Shape face = mapOfFaces.FindKey(i);
159 
160  TopTools_IndexedMapOfShape localEdges;
161  TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
162 
163  for (int j = 1; j <= localEdges.Extent(); j++)
164  {
165  TopoDS_Shape edge = localEdges.FindKey(j);
166  BRepAdaptor_Curve curve = BRepAdaptor_Curve(TopoDS::Edge(edge));
167  if (curve.GetType() != 7)
168  {
169  if (!(mapOfEdges.Contains(edge)))
170  {
171  mapOfEdges.Add(edge);
172  }
173  }
174  }
175  }
176 
177  map<int, vector<int> > adjsurfmap; // from id of curve to list of ids of
178  // surfs
179 
180  // Adds edges to our type and map
181  for (int i = 1; i <= mapOfEdges.Extent(); i++)
182  {
183  TopoDS_Shape edge = mapOfEdges.FindKey(i);
184  TopoDS_Vertex fv =
185  TopExp::FirstVertex(TopoDS::Edge(edge), Standard_True);
186  TopoDS_Vertex lv =
187  TopExp::LastVertex(TopoDS::Edge(edge), Standard_True);
188 
189  if (edge.Orientation() == 0)
190  {
191  AddCurve(i, edge, mapOfVerts.FindIndex(fv),
192  mapOfVerts.FindIndex(lv));
193  }
194  else
195  {
196  AddCurve(i, edge, mapOfVerts.FindIndex(lv),
197  mapOfVerts.FindIndex(fv));
198  }
199  }
200 
201  // For each face, examine all the wires (i.e. bounding loops) and
202  // investigates the loop. Using this information, connectivity is determined
203  // and edges are associated with surfaces.
204  for (int i = 1; i <= mapOfFaces.Extent(); i++)
205  {
206  TopoDS_Shape face = mapOfFaces.FindKey(i);
207 
208  TopTools_IndexedMapOfShape mapOfWires;
209  TopExp::MapShapes(face, TopAbs_WIRE, mapOfWires);
210 
211  // this pice of code does an idiot check on the loops to make sure
212  // they dont cross or touch
213  if (mapOfWires.Extent() > 1)
214  {
215  TopoDS_Wire ow = BRepTools::OuterWire(TopoDS::Face(face));
216 
217  vector<TopoDS_Shape> wirefacecuts;
218  vector<gp_Pnt> centersofcutfaces;
219 
220  for (int j = 1; j <= mapOfWires.Extent(); j++)
221  {
222  TopoDS_Shape wire = mapOfWires.FindKey(j);
223 
224  if (wire != ow)
225  {
226  BRepBuilderAPI_MakeFace build(
227  BRep_Tool::Surface(TopoDS::Face(face)), 1e-7);
228  build.Add(TopoDS::Wire(wire));
229  TopoDS_Shape newface = build.Shape();
230  wirefacecuts.push_back(newface);
231  BRepAdaptor_Surface b =
232  BRepAdaptor_Surface(TopoDS::Face(newface));
233  NekDouble u, v;
234  u = (b.LastUParameter() - b.FirstUParameter()) / 2.0;
235  v = (b.LastVParameter() - b.FirstVParameter()) / 2.0;
236  centersofcutfaces.push_back(b.Value(u, v));
237  }
238  }
239  for (int j = 0; j < wirefacecuts.size(); j++)
240  {
241  for (int k = 0; k < wirefacecuts.size(); k++)
242  {
243  if (j == k)
244  continue;
245 
246  /// TODO fix this test
247  BRepClass_FaceClassifier fc(TopoDS::Face(wirefacecuts[j]),
248  centersofcutfaces[k], 1e-7);
249  // ASSERTL0(fc.State() == 1, "Internal face loops make this
250  // cad impossible to mesh");
251  }
252  }
253  }
254 
255  vector<EdgeLoop> edgeloops;
256 
257  // now we acutally analyse the loops for cad building
258  for (int j = 1; j <= mapOfWires.Extent(); j++)
259  {
260  EdgeLoop edgeloop;
261 
262  TopoDS_Shape wire = mapOfWires.FindKey(j);
263 
264  ShapeAnalysis_Wire wiretest(TopoDS::Wire(wire), TopoDS::Face(face),
265  1E-6);
266 
267  // calculate the center of the wire
268  GProp_GProps massProps;
269  BRepGProp::SurfaceProperties(wire, massProps);
270  gp_Pnt gPt = massProps.CentreOfMass();
271  // alternative locuv methods
272  ShapeAnalysis_Surface sas(BRep_Tool::Surface(TopoDS::Face(face)));
273  sas.SetDomain(
274  BRepAdaptor_Surface(TopoDS::Face(face)).FirstUParameter(),
275  BRepAdaptor_Surface(TopoDS::Face(face)).LastUParameter(),
276  BRepAdaptor_Surface(TopoDS::Face(face)).FirstVParameter(),
277  BRepAdaptor_Surface(TopoDS::Face(face)).LastVParameter());
278  gp_Pnt2d p2 = sas.ValueOfUV(gPt, 1e-7);
279  Array<OneD, NekDouble> cen(2);
280  cen[0] = p2.X();
281  cen[1] = p2.Y();
282  edgeloop.center = cen;
283 
284  BRepTools_WireExplorer exp;
285 
286  exp.Init(TopoDS::Wire(wire));
287 
288  while (exp.More())
289  {
290  TopoDS_Shape edge = exp.Current();
291 
292  if (mapOfEdges.Contains(edge))
293  {
294  int e = mapOfEdges.FindIndex(edge);
295  edgeloop.edges.push_back(m_curves[e]);
296  edgeloop.edgeo.push_back(exp.Orientation());
297  adjsurfmap[e].push_back(i);
298  }
299 
300  exp.Next();
301  }
302 
303  edgeloops.push_back(edgeloop);
304  }
305 
306  AddSurf(i, face, edgeloops);
307  }
308 
309  // attempts to identify properties of the vertex on the degen edge
310  for (int i = 1; i <= mapOfFaces.Extent(); i++)
311  {
312  TopoDS_Shape face = mapOfFaces.FindKey(i);
313 
314  TopTools_IndexedMapOfShape localEdges;
315  TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
316 
317  for (int j = 1; j <= localEdges.Extent(); j++)
318  {
319  TopoDS_Shape edge = localEdges.FindKey(j);
320  if (BRep_Tool::Degenerated(TopoDS::Edge(edge)))
321  {
322  cout << "degen edge on face " << i << endl;
323  gp_Pnt2d p1, p2;
324 
325  BRep_Tool::UVPoints(TopoDS::Edge(edge), TopoDS::Face(face), p1,
326  p2);
327 
328  m_verts[mapOfVerts.FindIndex(TopExp::FirstVertex(
329  TopoDS::Edge(edge), Standard_True))]
330  ->SetDegen(i, m_surfs[i], (p1.X() + p2.X()) / 2.0,
331  (p1.Y() + p2.Y()) / 2.0);
332  }
333  }
334  }
335 
336  // This checks that all edges are bound by two surfaces, sanity check.
337  for (map<int, vector<int> >::iterator it = adjsurfmap.begin();
338  it != adjsurfmap.end(); it++)
339  {
340  ASSERTL0(it->second.size() == 2, "no three curve surfaces");
341  vector<CADSurfSharedPtr> sfs;
342  for (int i = 0; i < it->second.size(); i++)
343  {
344  sfs.push_back(m_surfs[it->second[i]]);
345  }
346  m_curves[it->first]->SetAdjSurf(sfs);
347  }
348  return true;
349 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
TopoDS_Shape shape
OCC master object.
Definition: CADSystem.h:182
void AddVert(int i, TopoDS_Shape in)
Function to add curve to CADSystem::m_verts.
Definition: CADSystem.cpp:351
std::string m_name
Name of cad file to be opened, including file extension.
Definition: CADSystem.h:174
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition: CADSystem.h:176
std::map< int, CADVertSharedPtr > m_verts
Map of vertices.
Definition: CADSystem.h:180
double NekDouble
void AddCurve(int i, TopoDS_Shape in, int fv, int lv)
Function to add curve to CADSystem::m_curves.
Definition: CADSystem.cpp:358
void AddSurf(int i, TopoDS_Shape in, std::vector< EdgeLoop > ein)
Function to add surface to CADSystem::m_surfs.
Definition: CADSystem.cpp:370
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< int, CADSurfSharedPtr > m_surfs
Map of surfaces.
Definition: CADSystem.h:178
void Nektar::NekMeshUtils::CADSystem::Report ( )

Reports basic properties to screen.

Definition at line 57 of file CADSystem.cpp.

58 {
59  cout << endl << "CAD report:" << endl;
60  cout << "\tCAD has: " << m_curves.size() << " curves." << endl;
61  cout << "\tCAD has: " << m_surfs.size() << " surfaces." << endl;
62 }
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition: CADSystem.h:176
std::map< int, CADSurfSharedPtr > m_surfs
Map of surfaces.
Definition: CADSystem.h:178

Friends And Related Function Documentation

friend class MemoryManager< CADSystem >
friend

Definition at line 68 of file CADSystem.h.

Member Data Documentation

std::map<int, CADCurveSharedPtr> Nektar::NekMeshUtils::CADSystem::m_curves
private

Map of curves.

Definition at line 176 of file CADSystem.h.

Referenced by GetCurve(), and GetNumCurve().

std::string Nektar::NekMeshUtils::CADSystem::m_name
private

Name of cad file to be opened, including file extension.

Definition at line 174 of file CADSystem.h.

std::map<int, CADSurfSharedPtr> Nektar::NekMeshUtils::CADSystem::m_surfs
private

Map of surfaces.

Definition at line 178 of file CADSystem.h.

Referenced by GetNumSurf(), and GetSurf().

std::map<int, CADVertSharedPtr> Nektar::NekMeshUtils::CADSystem::m_verts
private

Map of vertices.

Definition at line 180 of file CADSystem.h.

Referenced by GetNumVerts(), and GetVerts().

TopoDS_Shape Nektar::NekMeshUtils::CADSystem::shape
private

OCC master object.

Definition at line 182 of file CADSystem.h.