44 namespace NekMeshUtils
48 "cfi", CADSystemCFI::create,
"Uses CFI as cad engine");
50 bool CADSystemCFI::LoadCAD()
54 cfiHandel.startServer();
57 cout <<
"cfi loaded in mode: ";
58 if (cfiHandel.info.mode == cfi::MODE_STANDALONE)
60 cout <<
"standalone" << endl;
62 else if (cfiHandel.info.mode == cfi::MODE_CLIENT)
64 cout <<
"client" << endl;
66 else if (cfiHandel.info.mode == cfi::MODE_SERVER)
68 cout <<
"server" << endl;
70 else if (cfiHandel.info.mode == cfi::MODE_BOTH)
72 cout <<
"both" << endl;
74 else if (cfiHandel.info.mode == cfi::MODE_PLUGIN)
76 cout <<
"plugin" << endl;
80 cout <<
"unknown" << endl;
83 cout <<
"\tVersion " << cfiHandel.info.version << endl
84 <<
"\tfixno " << cfiHandel.info.fixno << endl
85 <<
"\tubid " << cfiHandel.info.ubid << endl;
88 model = cfiHandel.openModelFile(m_name.c_str());
90 if (
model->getEntityTotal(cfi::TYPE_BODY, cfi::SUBTYPE_ALL) != 1)
96 cout <<
"\tWill extract mesh and have multibodies" << endl;
103 cout <<
"\tHas multibodies and instructions to mesh, this is " 112 vector<cfi::Entity *> *bds =
113 model->getEntityList(cfi::TYPE_BODY, cfi::SUBTYPE_ALL);
117 cfi::Body *b =
static_cast<cfi::Body *
>(i);
126 if (
model->getUnits() == cfi::UNIT_INCHES)
130 cout <<
"\tModel is in inches, scaling accordingly" << endl;
134 else if (
model->getUnits() == cfi::UNIT_MILLIMETERS ||
135 model->getUnits() == cfi::UNIT_MILLIMETRES)
139 cout <<
"\tModel is in mm, scaling accordingly" << endl;
147 map<string, cfi::Point *> mapOfVerts;
148 map<string, cfi::Line *> mapOfEdges;
149 map<string, cfi::Face *> mapOfFaces;
156 for (
int i = 0; i < bodies.size(); i++)
159 if (bodies[i]->getTopoSubtype() == cfi::SUBTYPE_COMBINED)
164 vector<cfi::Oriented<cfi::TopoEntity *>> *faceList =
165 bodies[i]->getChildList();
167 vector<cfi::Oriented<cfi::TopoEntity *>>::iterator it, it2, it3;
168 for (it = faceList->begin(); it != faceList->end(); it++)
170 cfi::Oriented<cfi::TopoEntity *> orientatedFace = *it;
171 cfi::Face *face =
static_cast<cfi::Face *
>(orientatedFace.entity);
175 boost::optional<cfi::Oriented<cfi::Surface *>> surf =
176 face->getTopoEmbedding();
178 catch (std::exception &e)
184 auto it = mapOfFaces.find(face->getName());
185 if (it == mapOfFaces.end())
187 vector<cfi::Oriented<cfi::TopoEntity *>> *edgeList =
188 face->getChildList();
191 vector<cfi::Oriented<cfi::TopoEntity *>> fullEdgeList;
192 for (it2 = edgeList->begin(); it2 != edgeList->end(); it2++)
194 cfi::Line *edge =
static_cast<cfi::Line *
>(it2->entity);
196 if (edge->getTopoSubtype() == cfi::SUBTYPE_COMBINED)
198 vector<cfi::Oriented<cfi::TopoEntity *>> *subEdgeList =
199 edge->getChildList();
201 for (it3 = subEdgeList->begin();
202 it3 != subEdgeList->end(); it3++)
204 fullEdgeList.push_back(*it3);
209 fullEdgeList.push_back(*it2);
213 for (it2 = fullEdgeList.begin(); it2 != fullEdgeList.end(); it2++)
215 cfi::Oriented<cfi::TopoEntity *> orientatedEdge = *it2;
217 static_cast<cfi::Line *
>(orientatedEdge.entity);
218 mapOfEdges[edge->getName()] = edge;
220 vector<cfi::Oriented<cfi::TopoEntity *>> *vertList =
221 edge->getChildList();
222 for (it3 = vertList->begin(); it3 != vertList->end(); it3++)
224 cfi::Oriented<cfi::TopoEntity *> orientatedVert = *it3;
226 static_cast<cfi::Point *
>(orientatedVert.entity);
227 mapOfVerts[vert->getName()] = vert;
228 mapVertToListEdge[vert->getName()].push_back(
233 mapOfFaces[face->getName()] = face;
239 map<string, cfi::Point *>::iterator vit;
241 for (vit = mapOfVerts.begin(); vit != mapOfVerts.end(); vit++, i++)
243 AddVert(i, vit->second);
244 nameToVertId[vit->second->getName()] = i;
248 map<string, cfi::Line *>::iterator eit;
250 for (eit = mapOfEdges.begin(); eit != mapOfEdges.end(); eit++, i++)
252 AddCurve(i, eit->second);
253 nameToCurveId[eit->second->getName()] = i;
257 map<string, cfi::Face *>::iterator fit;
259 for (fit = mapOfFaces.begin(); fit != mapOfFaces.end(); fit++, i++)
261 nameToFaceId[fit->second->getName()] = i;
263 AddSurf(i, fit->second);
269 if (!m_2d && !m_cfiMesh)
271 map<int, CADCurveSharedPtr>::iterator it;
272 for (it = m_curves.begin(); it != m_curves.end(); it++)
274 ASSERTL0(it->second->GetAdjSurf().size() == 2,
275 "curve is not joined to 2 surfaces");
287 void CADSystemCFI::AddVert(
int i, cfi::Point *in)
291 static_pointer_cast<
CADVertCFI>(newVert)->Initialise(i, in, m_scal);
293 m_verts[i] = newVert;
294 m_verts[i]->SetName(in->getName());
297 void CADSystemCFI::AddCurve(
int i, cfi::Line *in)
300 static_pointer_cast<
CADCurveCFI>(newCurve)->Initialise(i, in, m_scal);
302 vector<cfi::Oriented<cfi::TopoEntity *>> *vertList = in->getChildList();
304 ASSERTL0(vertList->size() == 2,
"should be two ends");
306 vector<cfi::Oriented<cfi::TopoEntity *>>::iterator it;
308 for (it = vertList->begin(); it != vertList->end(); it++)
310 cfi::Oriented<cfi::TopoEntity *> orientatedVert = *it;
311 cfi::Point *vert =
static_cast<cfi::Point *
>(orientatedVert.entity);
312 boost::optional<cfi::Projected<double>> pj =
313 in->calcTFromXYZ(vert->getGeometry(), -1);
314 t.push_back(pj.value().parameters);
318 vector<CADVertSharedPtr> vs;
319 vs.push_back(m_verts[nameToVertId[vertList->at(0).entity->getName()]]);
320 vs.push_back(m_verts[nameToVertId[vertList->at(1).entity->getName()]]);
321 m_curves[i] = newCurve;
322 m_curves[i]->SetVert(vs);
323 m_curves[i]->SetName(in->getName());
324 m_verts[nameToVertId[vertList->at(0).entity->getName()]]->AddAdjCurve(
326 m_verts[nameToVertId[vertList->at(1).entity->getName()]]->AddAdjCurve(
330 void CADSystemCFI::AddSurf(
int i, cfi::Face *in)
333 static_pointer_cast<
CADSurfCFI>(newSurf)->Initialise(i, in, m_scal);
335 vector<cfi::Oriented<cfi::TopoEntity *>> *edgeList = in->getChildList();
338 vector<cfi::Oriented<cfi::TopoEntity *>> fullEdgeList;
339 vector<cfi::Oriented<cfi::TopoEntity *>>::iterator it2, it3;
340 for (it2 = edgeList->begin(); it2 != edgeList->end(); it2++)
342 cfi::Line *edge =
static_cast<cfi::Line *
>(it2->entity);
344 if (edge->getTopoSubtype() == cfi::SUBTYPE_COMBINED)
346 vector<cfi::Oriented<cfi::TopoEntity *>> *subEdgeList =
347 edge->getChildList();
349 for (it3 = subEdgeList->begin(); it3 != subEdgeList->end(); it3++)
351 fullEdgeList.push_back(*it3);
354 if (it2->orientation == cfi::ORIENT_NEGATIVE)
356 reverse(fullEdgeList.begin() + fullEdgeList.size() -
363 fullEdgeList.push_back(*it2);
367 vector<EdgeLoopSharedPtr> edgeloops;
369 while (done != fullEdgeList.size())
373 vector<cfi::Oriented<cfi::TopoEntity *>> *vertList =
374 fullEdgeList.at(done).entity->getChildList();
375 if (fullEdgeList.at(done).orientation == cfi::ORIENT_POSITIVE)
377 firstVert = vertList->at(0).entity->getName();
382 firstVert = vertList->at(1).entity->getName();
386 edgeloop->edges.push_back(
387 m_curves[nameToCurveId[fullEdgeList.at(done).entity->getName()]]);
389 for (done++; done < fullEdgeList.size(); done++)
392 vertList = fullEdgeList.at(done).entity->getChildList();
393 if (fullEdgeList.at(done).orientation == cfi::ORIENT_POSITIVE)
395 if (vertList->at(1).entity->getName() == firstVert)
403 if (vertList->at(0).entity->getName() == firstVert)
410 edgeloop->edges.push_back(
411 m_curves[nameToCurveId[fullEdgeList.at(done).entity->getName()]]);
419 edgeloops.push_back(edgeloop);
425 for (
int k = 0; k < edgeloops.size(); k++)
427 tote += edgeloops[k]->edges.size();
430 ASSERTL0(tote != 1,
"cannot handle periodic curves");
432 CADSurf::OrientateEdges(newSurf, edgeloops);
433 newSurf->SetEdges(edgeloops);
436 for (
int k = 0; k < edgeloops.size(); k++)
438 for (
int j = 0; j < edgeloops[k]->edges.size(); j++)
440 edgeloops[k]->edges[j]->SetAdjSurf(
441 make_pair(newSurf, edgeloops[k]->edgeo[j]));
445 m_surfs[i] = newSurf;
446 m_surfs[i]->SetName(in->getName());
451 cfi::BoundingBox
box =
model->calcBoundingBox();
CADCurveFactory & GetCADCurveFactory()
std::shared_ptr< CADSurf > CADSurfSharedPtr
#define ASSERTL0(condition, msg)
std::shared_ptr< EdgeLoop > EdgeLoopSharedPtr
std::shared_ptr< CADVert > CADVertSharedPtr
struct which descibes a collection of cad edges which are a loop on the cad surface ...
CADVertFactory & GetCADVertFactory()
CADSurfFactory & GetCADSurfFactory()
bg::model::box< point > box
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::shared_ptr< CADCurve > CADCurveSharedPtr
EngineFactory & GetEngineFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.