40 #include <boost/algorithm/string.hpp>
41 #include <boost/filesystem.hpp>
48 namespace LibUtilities {
53 string CADSystem::GetName()
61 void CADSystem::Report()
63 cout << endl <<
"CAD report:" << endl;
64 cout <<
"\tCAD has: " << m_curves.size() <<
" curves." << endl;
65 cout <<
"\tCAD has: " << m_surfs.size() <<
" surfaces." << endl;
66 cout <<
"\tCAD Euler-Poincaré characteristic: " << m_epc << endl;
80 bound[0] = numeric_limits<double>::max();
81 bound[1] = numeric_limits<double>::min();
82 bound[2] = numeric_limits<double>::max();
83 bound[3] = numeric_limits<double>::min();
84 bound[4] = numeric_limits<double>::max();
85 bound[5] = numeric_limits<double>::min();
87 for(
int i = 1; i <= m_curves.size(); i++)
93 bound[0] = min(bound[0], min(ends[0],ends[3]));
94 bound[1] = max(bound[1], max(ends[0],ends[3]));
96 bound[2] = min(bound[2], min(ends[1],ends[4]));
97 bound[3] = max(bound[3], max(ends[1],ends[4]));
99 bound[4] = min(bound[4], min(ends[2],ends[5]));
100 bound[5] = max(bound[5], max(ends[2],ends[5]));
111 bool CADSystem::LoadCAD()
113 if (!boost::filesystem::exists(m_name.c_str()))
119 size_t pos = m_name.find(
".");
120 ext = m_name.substr(pos);
124 if (boost::iequals(ext,
".STEP") || boost::iequals(ext,
".STP"))
127 STEPControl_Reader reader;
128 reader = STEPControl_Reader();
129 reader.ReadFile(m_name.c_str());
130 reader.NbRootsForTransfer();
131 reader.TransferRoots();
132 shape = reader.OneShape();
138 else if(boost::iequals(ext,
".IGES") || boost::iequals(ext,
".IGS"))
141 IGESControl_Reader reader;
142 reader = IGESControl_Reader();
143 reader.ReadFile(m_name.c_str());
144 reader.NbRootsForTransfer();
145 reader.TransferRoots();
146 shape = reader.OneShape();
158 TopTools_IndexedMapOfShape fc, vc, ec;
159 TopExp::MapShapes(shape, TopAbs_FACE, fc);
160 TopExp::MapShapes(shape, TopAbs_EDGE, ec);
161 TopExp::MapShapes(shape, TopAbs_VERTEX, vc);
163 m_epc = vc.Extent() - ec.Extent() + fc.Extent();
165 TopTools_IndexedMapOfShape mapOfFaces;
166 TopTools_IndexedMapOfShape mapOfEdges;
167 TopExp::MapShapes(shape, TopAbs_FACE, mapOfFaces);
172 for(
int i = 1; i <= mapOfFaces.Extent(); i++)
174 TopoDS_Shape face= mapOfFaces.FindKey(i);
176 TopTools_IndexedMapOfShape localEdges;
177 TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
179 for(
int j = 1; j <= localEdges.Extent(); j++)
181 TopoDS_Shape edge = localEdges.FindKey(j);
182 BRepAdaptor_Curve curve = BRepAdaptor_Curve(TopoDS::Edge(edge));
183 if(curve.GetType() != 7)
185 if(!(mapOfEdges.Contains(edge)))
187 mapOfEdges.Add(edge);
193 map<int, vector<int> > adjsurfmap;
196 for(
int i = 1; i <= mapOfEdges.Extent(); i++)
198 TopoDS_Shape edge = mapOfEdges.FindKey(i);
205 for(
int i = 1; i <= mapOfFaces.Extent(); i++)
207 vector<vector<pair<int,int> > > edges;
209 TopoDS_Shape face = mapOfFaces.FindKey(i);
211 TopTools_IndexedMapOfShape mapOfWires;
212 TopExp::MapShapes(face, TopAbs_WIRE, mapOfWires);
214 for(
int j = 1; j <= mapOfWires.Extent(); j++)
216 vector<pair<int,int> > edgeloop;
218 TopoDS_Shape wire = mapOfWires.FindKey(j);
220 ShapeAnalysis_Wire wiretest(TopoDS::Wire(wire),
224 BRepTools_WireExplorer exp;
226 exp.Init(TopoDS::Wire(wire));
230 TopoDS_Shape edge = exp.Current();
232 if(mapOfEdges.Contains(edge))
235 e.first = mapOfEdges.FindIndex(edge);
236 adjsurfmap[e.first].push_back(i);
237 e.second = exp.Orientation();
238 edgeloop.push_back(e);
244 edges.push_back(edgeloop);
247 AddSurf(i, face, edges);
251 for(map<
int,vector<int> >::
iterator it = adjsurfmap.begin();
252 it != adjsurfmap.end(); it++)
254 ASSERTL0(it->second.size() == 2,
"no three curve surfaces");
255 m_curves[it->first]->SetAdjSurf(it->second);
261 void CADSystem::AddCurve(
int i, TopoDS_Shape in)
265 m_curves[i] = newCurve;
268 void CADSystem::AddSurf(
int i, TopoDS_Shape in,
269 std::vector<std::vector<std::pair<int,int> > > ein)
273 m_surfs[i] = newSurf;
#define ASSERTL0(condition, msg)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
boost::shared_ptr< CADCurve > CADCurveSharedPtr
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< CADSurf > CADSurfSharedPtr