36 #include <boost/algorithm/string.hpp> 
   37 #include <boost/filesystem.hpp> 
   49 namespace NekMeshUtils
 
   52 string CADSystem::GetName()
 
   57 void CADSystem::Report()
 
   59     cout << endl << 
"CAD report:" << endl;
 
   60     cout << 
"\tCAD has: " << m_curves.size() << 
" curves." << endl;
 
   61     cout << 
"\tCAD has: " << m_surfs.size() << 
" surfaces." << endl;
 
   67     bound[0] = numeric_limits<double>::max(); 
 
   68     bound[1] = numeric_limits<double>::min(); 
 
   69     bound[2] = numeric_limits<double>::max(); 
 
   70     bound[3] = numeric_limits<double>::min(); 
 
   71     bound[4] = numeric_limits<double>::max(); 
 
   72     bound[5] = numeric_limits<double>::min(); 
 
   74     for (
int i = 1; i <= m_curves.size(); i++)
 
   80         bound[0] = min(bound[0], min(ends[0], ends[3]));
 
   81         bound[1] = max(bound[1], max(ends[0], ends[3]));
 
   83         bound[2] = min(bound[2], min(ends[1], ends[4]));
 
   84         bound[3] = max(bound[3], max(ends[1], ends[4]));
 
   86         bound[4] = min(bound[4], min(ends[2], ends[5]));
 
   87         bound[5] = max(bound[5], max(ends[2], ends[5]));
 
   93 bool CADSystem::LoadCAD()
 
   95     if (!boost::filesystem::exists(m_name.c_str()))
 
  101     size_t pos = m_name.find(
".");
 
  102     ext        = m_name.substr(pos);
 
  104     if (boost::iequals(ext, 
".STEP") || boost::iequals(ext, 
".STP"))
 
  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();
 
  118     else if (boost::iequals(ext, 
".IGES") || boost::iequals(ext, 
".IGS"))
 
  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();
 
  138     TopTools_IndexedMapOfShape mapOfVerts, mapOfFaces;
 
  139     TopExp::MapShapes(shape, TopAbs_VERTEX, mapOfVerts);
 
  140     TopExp::MapShapes(shape, TopAbs_FACE, mapOfFaces);
 
  144     TopTools_IndexedMapOfShape mapOfEdges;
 
  147     for (
int i = 1; i <= mapOfVerts.Extent(); i++)
 
  149         TopoDS_Shape v = mapOfVerts.FindKey(i);
 
  156     for (
int i = 1; i <= mapOfFaces.Extent(); i++)
 
  158         TopoDS_Shape face = mapOfFaces.FindKey(i);
 
  160         TopTools_IndexedMapOfShape localEdges;
 
  161         TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
 
  163         for (
int j = 1; j <= localEdges.Extent(); j++)
 
  165             TopoDS_Shape edge       = localEdges.FindKey(j);
 
  166             BRepAdaptor_Curve 
curve = BRepAdaptor_Curve(TopoDS::Edge(edge));
 
  167             if (curve.GetType() != 7)
 
  169                 if (!(mapOfEdges.Contains(edge)))
 
  171                     mapOfEdges.Add(edge);
 
  177     map<int, vector<int> > adjsurfmap; 
 
  181     for (
int i = 1; i <= mapOfEdges.Extent(); i++)
 
  183         TopoDS_Shape edge = mapOfEdges.FindKey(i);
 
  185             TopExp::FirstVertex(TopoDS::Edge(edge), Standard_True);
 
  187             TopExp::LastVertex(TopoDS::Edge(edge), Standard_True);
 
  189         if (edge.Orientation() == 0)
 
  191             AddCurve(i, edge, mapOfVerts.FindIndex(fv),
 
  192                      mapOfVerts.FindIndex(lv));
 
  196             AddCurve(i, edge, mapOfVerts.FindIndex(lv),
 
  197                      mapOfVerts.FindIndex(fv));
 
  204     for (
int i = 1; i <= mapOfFaces.Extent(); i++)
 
  206         TopoDS_Shape face = mapOfFaces.FindKey(i);
 
  208         TopTools_IndexedMapOfShape mapOfWires;
 
  209         TopExp::MapShapes(face, TopAbs_WIRE, mapOfWires);
 
  213         if (mapOfWires.Extent() > 1)
 
  215             TopoDS_Wire ow = BRepTools::OuterWire(TopoDS::Face(face));
 
  217             vector<TopoDS_Shape> wirefacecuts;
 
  218             vector<gp_Pnt> centersofcutfaces;
 
  220             for (
int j = 1; j <= mapOfWires.Extent(); j++)
 
  222                 TopoDS_Shape wire = mapOfWires.FindKey(j);
 
  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));
 
  234                     u = (b.LastUParameter() - b.FirstUParameter()) / 2.0;
 
  235                     v = (b.LastVParameter() - b.FirstVParameter()) / 2.0;
 
  236                     centersofcutfaces.push_back(b.Value(u, v));
 
  239             for (
int j = 0; j < wirefacecuts.size(); j++)
 
  241                 for (
int k = 0; k < wirefacecuts.size(); k++)
 
  247                     BRepClass_FaceClassifier fc(TopoDS::Face(wirefacecuts[j]),
 
  248                                                 centersofcutfaces[k], 1e-7);
 
  255         vector<EdgeLoop> edgeloops;
 
  258         for (
int j = 1; j <= mapOfWires.Extent(); j++)
 
  262             TopoDS_Shape wire = mapOfWires.FindKey(j);
 
  264             ShapeAnalysis_Wire wiretest(TopoDS::Wire(wire), TopoDS::Face(face),
 
  268             GProp_GProps massProps;
 
  269             BRepGProp::SurfaceProperties(wire, massProps);
 
  270             gp_Pnt gPt = massProps.CentreOfMass();
 
  272             ShapeAnalysis_Surface sas(BRep_Tool::Surface(TopoDS::Face(face)));
 
  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);
 
  284             BRepTools_WireExplorer exp;
 
  286             exp.Init(TopoDS::Wire(wire));
 
  290                 TopoDS_Shape edge = exp.Current();
 
  292                 if (mapOfEdges.Contains(edge))
 
  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);
 
  303             edgeloops.push_back(edgeloop);
 
  306         AddSurf(i, face, edgeloops);
 
  310     for (
int i = 1; i <= mapOfFaces.Extent(); i++)
 
  312         TopoDS_Shape face = mapOfFaces.FindKey(i);
 
  314         TopTools_IndexedMapOfShape localEdges;
 
  315         TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
 
  317         for (
int j = 1; j <= localEdges.Extent(); j++)
 
  319             TopoDS_Shape edge = localEdges.FindKey(j);
 
  320             if (BRep_Tool::Degenerated(TopoDS::Edge(edge)))
 
  322                 cout << 
"degen edge on face " << i << endl;
 
  325                 BRep_Tool::UVPoints(TopoDS::Edge(edge), TopoDS::Face(face), p1,
 
  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);
 
  337     for (map<
int, vector<int> >::
iterator it = adjsurfmap.begin();
 
  338          it != adjsurfmap.end(); it++)
 
  340         ASSERTL0(it->second.size() == 2, 
"no three curve surfaces");
 
  341         vector<CADSurfSharedPtr> sfs;
 
  342         for (
int i = 0; i < it->second.size(); i++)
 
  344             sfs.push_back(m_surfs[it->second[i]]);
 
  346         m_curves[it->first]->SetAdjSurf(sfs);
 
  351 void CADSystem::AddVert(
int i, TopoDS_Shape in)
 
  355     m_verts[i] = newVert;
 
  358 void CADSystem::AddCurve(
int i, TopoDS_Shape in, 
int fv, 
int lv)
 
  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);
 
  370 void CADSystem::AddSurf(
int i, TopoDS_Shape in, vector<EdgeLoop> ein)
 
  374     m_surfs[i] = newSurf;
 
  376     if (in.Orientation() == 0)
 
  378         m_surfs[i]->SetReverseNomral();
 
  382     for (
int i = 0; i < ein.size(); i++)
 
  384         tote += ein[i].edges.size();
 
  387     ASSERTL0(tote != 1, 
"cannot handle periodic curves");
 
  391         m_surfs[i]->SetTwoC();
 
  397     gp_Pnt p(loc[0] * 1000.0, loc[1] * 1000.0, loc[2] * 1000.0);
 
  399     BRepClass3d_SolidClassifier test(shape, p, 1E-7);
 
  400     if (test.State() == TopAbs_IN || test.State() == TopAbs_ON)
 
#define ASSERTL0(condition, msg)
 
Array< OneD, NekDouble > center
 
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
 
struct which descibes a collection of cad edges which for a loop on the cad surface ...
 
std::vector< CADCurveSharedPtr > edges
 
boost::shared_ptr< CADSurf > CADSurfSharedPtr
 
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
 
boost::shared_ptr< CADVert > CADVertSharedPtr
 
boost::shared_ptr< CADCurve > CADCurveSharedPtr