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::NUCMESH::NucMeshGeo Class Reference

Detailed Description

Definition at line 44 of file NucMeshGeo.H.

Public Types

using MapType = std::unordered_map< TopoDS_Shape, std::shared_ptr< ShapeData >, ShapeMapHasher_Hash, ShapeMapHasher_KeyEqual >
 

Public Member Functions

std::unique_ptr< SMESH_Mesh > computeMesh (SMESH_Gen &generator)
 Construct a mesh using the shapes in the map and their ShapeData. More...
 
int getDim () const
 Get dimension of geometry. More...
 
void setDim (int dim)
 Set the dimension. More...
 
std::vector< TopoDS_Shape > modify (BRepBuilderAPI_MakeShape &op, const std::vector< TopoDS_Shape > &shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse={ TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID})
 Modify this geoMetadata after a BRepBuilderAPI_MakeShape operation. More...
 
std::vector< TopoDS_Shape > modify (BRepBuilderAPI_MakeShape &op, const TopTools_ListOfShape &shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse={ TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID})
 
std::array< std::vector< TopoDS_Shape >, 2 > modify (BRepAlgoAPI_BooleanOperation &op, const std::vector< TopAbs_ShapeEnum > &typesToTraverse={ TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID})
 
std::vector< TopoDS_Shape > modify (BRepBuilderAPI_Sewing &op, const std::vector< TopoDS_Shape > &shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse={ TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID})
 
void deleteShapes (const TopoDS_Shape &shape)
 Remove a shape from the map. More...
 
void deleteShapes (const std::vector< TopoDS_Shape > &shapes)
 Delete a set of shapes. More...
 
TopoDS_Compound buildCompound () const
 Create a compound from shapes present in the map that have same dimension as the instance. More...
 
std::shared_ptr< ShapeData > * get (const TopoDS_Shape &shape)
 Get the data from the map. More...
 
const std::shared_ptr< ShapeData > * get (const TopoDS_Shape &shape) const
 Get the data from the map. More...
 
std::pair< MapType::iterator, bool > insert (const TopoDS_Shape &shape, std::shared_ptr< ShapeData > shapeData)
 
template<typename T >
std::pair< MapType::iterator, bool > insertForward (const TopoDS_Shape &shape, T &&shapeData)
 Helper to insert a shape and data into the map. More...
 
template<typename T , typename... Args>
std::pair< MapType::iterator, bool > insertConstruct (const TopoDS_Shape &shape, Args &&...args)
 Helper to insert a shape and construct data. More...
 
MapTypegetMap ()
 
const MapTypegetMap () const
 Get the shapes and data. More...
 

Protected Member Functions

bool isChild (const TopoDS_Shape &shape) const
 
void modifyImpl (BRepBuilderAPI_MakeShape &op, const TopoDS_Shape &shape, std::vector< TopoDS_Shape > &shapesToRemove)
 

Protected Attributes

MapType map_
 
int dim_
 

Inherits NEM::GEO::GeoManager.

Member Typedef Documentation

◆ MapType

using NEM::GEO::GeoManager::MapType = std::unordered_map<TopoDS_Shape, std::shared_ptr<ShapeData>, ShapeMapHasher_Hash, ShapeMapHasher_KeyEqual>
inherited

Definition at line 85 of file GeoManager.H.

Member Function Documentation

◆ buildCompound()

TopoDS_Compound NEM::GEO::GeoManager::buildCompound ( ) const
inherited
Returns
compound of shapes

Definition at line 145 of file GeoManager.C.

References NEM::GEO::GeoManager::isChild(), and NEM::GEO::GeoManager::map_.

Referenced by NEM::NUCMESH::ShapesArray::basicTransformation(), computeMesh(), and NEM::NUCMESH::ShapeBase::mergeGeo().

145  {
146  BRep_Builder builder;
147  TopoDS_Compound compound;
148  // If no top-dimension shapes, then return a null compound
149  bool addedShapes = false;
150  for (auto &shape : map_) {
151  if (!isChild(shape.first)) {
152  if (!addedShapes) {
153  builder.MakeCompound(compound);
154  addedShapes = true;
155  }
156  builder.Add(compound, shape.first);
157  }
158  }
159  return compound;
160 }
bool isChild(const TopoDS_Shape &shape) const
Definition: GeoManager.C:190

◆ computeMesh()

std::unique_ptr< SMESH_Mesh > NEM::NUCMESH::NucMeshGeo::computeMesh ( SMESH_Gen &  generator)

Note there is a default edge hypothesis (StdMeshers_AutomaticLength), edge algorithm (StdMeshers_Regular_1D), and face algorithm (StdMeshers_MEFISTO_2D). Geometry and mesh regenerated on each call.

Returns
Generated mesh

Definition at line 48 of file NucMeshGeo.C.

References NEM::GEO::GeoManager::buildCompound(), NEM::GEO::GeoManager::isChild(), NEM::GEO::GeoManager::map_, mesh, and NEM::DRV::JSON::shapeType.

Referenced by NEM::SRV::NucMeshSrv::FillOutputPortInformation().

48  {
49  std::unique_ptr<SMESH_Mesh> mesh{generator.CreateMesh(false)};
50  std::vector<std::unique_ptr<SMESH_Hypothesis>> hypotheses;
51  auto compound = this->buildCompound();
52  mesh->ShapeToMesh(compound);
53  {
54  auto edgeAlgId = generator.GetANewId();
55  hypotheses.emplace_back(new StdMeshers_Regular_1D{edgeAlgId, &generator});
56  mesh->AddHypothesis(compound, edgeAlgId);
57  auto edgeHypId = generator.GetANewId();
58  hypotheses.emplace_back(
59  new StdMeshers_Adaptive1D{edgeHypId, &generator});
60  mesh->AddHypothesis(compound, edgeHypId);
61  }
62  {
63  auto faceAlgId = generator.GetANewId();
64  hypotheses.emplace_back(new StdMeshers_MEFISTO_2D{faceAlgId, &generator});
65  mesh->AddHypothesis(compound, faceAlgId);
66  }
67  std::unordered_set<TopoDS_Shape, ShapeMapHasher_Hash, ShapeMapHasher_KeyEqual>
68  generated_shapes;
69  for (auto &shape : map_) {
70  if (!isChild(shape.first)) {
71  static constexpr std::array<TopAbs_ShapeEnum, 4> shapeTypes{
72  TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID};
73  for (auto &shapeType : shapeTypes) {
74  for (TopExp_Explorer explorer{shape.first, shapeType}; explorer.More();
75  explorer.Next()) {
76  auto &subShape = explorer.Current();
77  auto findIter = map_.find(subShape);
78  if (findIter != map_.end() &&
79  generated_shapes.find(subShape) == generated_shapes.end()) {
80  if (auto nmData =
81  dynamic_cast<NucMeshShapeData *>(findIter->second.get())) {
82  nmData->setupAlgos(explorer.Current(), generator, *mesh,
83  hypotheses);
84  }
85  generated_shapes.emplace(subShape);
86  }
87  }
88  }
89  }
90  }
91  generator.Compute(*mesh, compound);
92  return mesh;
93 }
static constexpr auto shapeType
Definition: NucMeshJson.H:81
bool isChild(const TopoDS_Shape &shape) const
Definition: GeoManager.C:190
std::shared_ptr< meshBase > mesh
TopoDS_Compound buildCompound() const
Create a compound from shapes present in the map that have same dimension as the instance.
Definition: GeoManager.C:145

◆ deleteShapes() [1/2]

void NEM::GEO::GeoManager::deleteShapes ( const TopoDS_Shape &  shape)
inherited

Note there is no effect if shape's dimension is less than the instance dimension (to avoid removing shapes that are still referenced by other shapes).

Parameters
shapeShape to remove, if present

Definition at line 127 of file GeoManager.C.

References NEM::GEO::GeoManager::isChild(), and NEM::GEO::GeoManager::map_.

Referenced by NEM::GEO::GeoManager::deleteShapes(), and NEM::NUCMESH::ShapeBase::mergeGeo().

127  {
128  if (!isChild(shape)) {
129  auto findIter = map_.find(shape);
130  if (findIter != map_.end()) {
131  if (findIter->second) {
132  findIter->second->updateDeleted(shape, *this);
133  }
134  map_.erase(findIter);
135  }
136  }
137 }
bool isChild(const TopoDS_Shape &shape) const
Definition: GeoManager.C:190

◆ deleteShapes() [2/2]

void NEM::GEO::GeoManager::deleteShapes ( const std::vector< TopoDS_Shape > &  shapes)
inherited
Parameters
shapesShapes to remove, if present

Definition at line 139 of file GeoManager.C.

References NEM::GEO::GeoManager::deleteShapes().

139  {
140  for (auto &shape : shapes) {
141  this->deleteShapes(shape);
142  }
143 }
void deleteShapes(const TopoDS_Shape &shape)
Remove a shape from the map.
Definition: GeoManager.C:127

◆ get() [1/2]

std::shared_ptr< ShapeData > * NEM::GEO::GeoManager::get ( const TopoDS_Shape &  shape)
inherited

Definition at line 162 of file GeoManager.C.

References NEM::GEO::GeoManager::map_.

162  {
163  auto findIter = map_.find(shape);
164  if (findIter != map_.end()) {
165  return &findIter->second;
166  } else {
167  return nullptr;
168  }
169 }

◆ get() [2/2]

const std::shared_ptr< ShapeData > * NEM::GEO::GeoManager::get ( const TopoDS_Shape &  shape) const
inherited
Parameters
shapeShape to query
Returns
Pointer to data in the map, or nullptr if shape not in map. If a pointer to a nullptr, then shape is in map, but data in map is null.

Definition at line 171 of file GeoManager.C.

References NEM::GEO::GeoManager::map_.

172  {
173  auto findIter = map_.find(shape);
174  if (findIter != map_.end()) {
175  return &findIter->second;
176  } else {
177  return nullptr;
178  }
179 }

◆ getDim()

int NEM::GEO::GeoManager::getDim ( ) const
inherited
Returns
dimension

Definition at line 50 of file GeoManager.C.

References NEM::GEO::GeoManager::dim_.

Referenced by NEM::NUCMESH::ShapeBase::mergeGeo().

50 { return dim_; }

◆ getMap() [1/2]

GeoManager::MapType & NEM::GEO::GeoManager::getMap ( )
inherited

◆ getMap() [2/2]

const GeoManager::MapType & NEM::GEO::GeoManager::getMap ( ) const
inherited
Returns
Map from shapes to data

Definition at line 188 of file GeoManager.C.

References NEM::GEO::GeoManager::map_.

188 { return map_; }

◆ insert()

std::pair< GeoManager::MapType::iterator, bool > NEM::GEO::GeoManager::insert ( const TopoDS_Shape &  shape,
std::shared_ptr< ShapeData shapeData 
)
inherited

Definition at line 181 of file GeoManager.C.

References NEM::GEO::GeoManager::map_.

Referenced by NEM::NUCMESH::ShapesArray::basicTransformation(), and NEM::NUCMESH::ShapeBase::mergeGeo().

182  {
183  return map_.emplace(shape, std::move(shapeData));
184 }

◆ insertConstruct()

template<typename T , typename... Args>
std::pair<MapType::iterator, bool> NEM::GEO::GeoManager::insertConstruct ( const TopoDS_Shape &  shape,
Args &&...  args 
)
inlineinherited
Template Parameters
TShapeData type
ArgsTypes of T constructor
Parameters
shapeShape to insert
argsArguments of T constructor for data to associate with shape
Returns
iterator to inserted or already existing element, and whether or not there was an insertion

Definition at line 218 of file GeoManager.H.

219  {
220  auto emplaceIter = getMap().emplace(shape, std::shared_ptr<ShapeData>{});
221  if (emplaceIter.second) {
222  emplaceIter.first->second.reset(new T(std::forward<Args>(args)...));
223  }
224  return emplaceIter;
225  }
MapType & getMap()
Definition: GeoManager.C:186

◆ insertForward()

template<typename T >
std::pair<MapType::iterator, bool> NEM::GEO::GeoManager::insertForward ( const TopoDS_Shape &  shape,
T &&  shapeData 
)
inlineinherited
Template Parameters
TShapeData type
Parameters
shapeShape to insert
shapeDataData to associate to with
Returns
iterator to inserted or already existing element, and whether or not there was an insertion

Definition at line 197 of file GeoManager.H.

198  {
199  auto emplaceIter = getMap().emplace(shape, std::shared_ptr<ShapeData>{});
200  if (emplaceIter.second) {
201  emplaceIter.first->second.reset(
202  new typename std::decay<T>::type(std::forward<T>(shapeData)));
203  }
204  return emplaceIter;
205  }
MapType & getMap()
Definition: GeoManager.C:186

◆ isChild()

bool NEM::GEO::GeoManager::isChild ( const TopoDS_Shape &  shape) const
protectedinherited

Definition at line 190 of file GeoManager.C.

References NEM::GEO::GeoManager::dim_.

Referenced by NEM::GEO::GeoManager::buildCompound(), computeMesh(), and NEM::GEO::GeoManager::deleteShapes().

190  {
191  int shapeDim;
192  switch (shape.ShapeType()) {
193  case TopAbs_COMPSOLID:
194  case TopAbs_SOLID: shapeDim = 3; break;
195  case TopAbs_SHELL:
196  case TopAbs_FACE: shapeDim = 2; break;
197  case TopAbs_WIRE:
198  case TopAbs_EDGE: shapeDim = 1; break;
199  case TopAbs_VERTEX: shapeDim = 0; break;
200  case TopAbs_COMPOUND:
201  case TopAbs_SHAPE:
202  default: return false;
203  }
204  return shapeDim < dim_;
205 }

◆ modify() [1/4]

std::vector< TopoDS_Shape > NEM::GEO::GeoManager::modify ( BRepBuilderAPI_MakeShape &  op,
const std::vector< TopoDS_Shape > &  shapes,
const std::vector< TopAbs_ShapeEnum > &  typesToTraverse = { TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID} 
)
inherited
Parameters
opModification of geometry
shapesGeometry objects assumed to be inputs of op. The corresponding values in the map dictate the behavior of the resulting metadata.
typesToTraverseTraverse the subshapes of shapes with these types. An empty list means only shapes will be examined.
Returns
Shapes that are no longer present in the output of op

Definition at line 74 of file GeoManager.C.

References NEM::GEO::GeoManager::modifyImpl(), and NEM::GEO::modifyTempl().

Referenced by NEM::NUCMESH::ShapeBase::mergeGeo(), and NEM::GEO::GeoManager::modify().

76  {
77  return modifyTempl(op, shapes, typesToTraverse,
78  [this, &op](const TopoDS_Shape &shape,
79  std::vector<TopoDS_Shape> &shapesToRemove) {
80  this->modifyImpl(op, shape, shapesToRemove);
81  });
82 }
std::vector< TopoDS_Shape > modifyTempl(Op &&op, T &&shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse, F &&modifyFunc)
Definition: GeoManager.C:55
void modifyImpl(BRepBuilderAPI_MakeShape &op, const TopoDS_Shape &shape, std::vector< TopoDS_Shape > &shapesToRemove)
Definition: GeoManager.C:207

◆ modify() [2/4]

std::vector< TopoDS_Shape > NEM::GEO::GeoManager::modify ( BRepBuilderAPI_MakeShape &  op,
const TopTools_ListOfShape shapes,
const std::vector< TopAbs_ShapeEnum > &  typesToTraverse = { TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID} 
)
inherited

Definition at line 84 of file GeoManager.C.

References NEM::GEO::GeoManager::modifyImpl(), and NEM::GEO::modifyTempl().

86  {
87  return modifyTempl(op, shapes, typesToTraverse,
88  [this, &op](const TopoDS_Shape &shape,
89  std::vector<TopoDS_Shape> &shapesToRemove) {
90  this->modifyImpl(op, shape, shapesToRemove);
91  });
92 }
std::vector< TopoDS_Shape > modifyTempl(Op &&op, T &&shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse, F &&modifyFunc)
Definition: GeoManager.C:55
void modifyImpl(BRepBuilderAPI_MakeShape &op, const TopoDS_Shape &shape, std::vector< TopoDS_Shape > &shapesToRemove)
Definition: GeoManager.C:207

◆ modify() [3/4]

std::array< std::vector< TopoDS_Shape >, 2 > NEM::GEO::GeoManager::modify ( BRepAlgoAPI_BooleanOperation &  op,
const std::vector< TopAbs_ShapeEnum > &  typesToTraverse = { TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID} 
)
inherited

shapes are inferred from

Definition at line 94 of file GeoManager.C.

References NEM::GEO::GeoManager::modify().

96  {
97  return {this->modify(op, op.Arguments(), typesToTraverse),
98  this->modify(op, op.Tools(), typesToTraverse)};
99 }
std::vector< TopoDS_Shape > modify(BRepBuilderAPI_MakeShape &op, const std::vector< TopoDS_Shape > &shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse={ TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID})
Modify this geoMetadata after a BRepBuilderAPI_MakeShape operation.
Definition: GeoManager.C:74

◆ modify() [4/4]

std::vector< TopoDS_Shape > NEM::GEO::GeoManager::modify ( BRepBuilderAPI_Sewing &  op,
const std::vector< TopoDS_Shape > &  shapes,
const std::vector< TopAbs_ShapeEnum > &  typesToTraverse = { TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID} 
)
inherited

Definition at line 101 of file GeoManager.C.

References NEM::GEO::GeoManager::map_, NEM::GEO::modifyTempl(), and NEM::DRV::JSON::shapeType.

103  {
104  return modifyTempl(
105  op, shapes, typesToTraverse,
106  [this, &op](const TopoDS_Shape &shape,
107  std::vector<TopoDS_Shape> &shapesToRemove) {
108  auto findIter = map_.find(shape);
109  if (findIter != map_.end()) {
110  auto shapeType = shape.ShapeType();
111  auto modified =
112  (shapeType == TopAbs_FACE || shapeType == TopAbs_SHELL)
113  ? op.Modified(shape)
114  : op.ModifiedSubShape(shape);
115  if (!modified.IsSame(shape)) {
116  TopTools_ListOfShape modShapes;
117  modShapes.Append(modified);
118  if (findIter->second) {
119  findIter->second->updateModified(shape, modShapes, *this);
120  }
121  shapesToRemove.emplace_back(shape);
122  }
123  }
124  });
125 }
std::vector< TopoDS_Shape > modifyTempl(Op &&op, T &&shapes, const std::vector< TopAbs_ShapeEnum > &typesToTraverse, F &&modifyFunc)
Definition: GeoManager.C:55
static constexpr auto shapeType
Definition: NucMeshJson.H:81

◆ modifyImpl()

void NEM::GEO::GeoManager::modifyImpl ( BRepBuilderAPI_MakeShape &  op,
const TopoDS_Shape &  shape,
std::vector< TopoDS_Shape > &  shapesToRemove 
)
protectedinherited

Definition at line 207 of file GeoManager.C.

References NEM::GEO::GeoManager::map_.

Referenced by NEM::GEO::GeoManager::modify().

209  {
210  if (op.IsDeleted(shape)) {
211  shapesToRemove.emplace_back(shape);
212  } else {
213  auto findIter = map_.find(shape);
214  if (findIter != map_.end()) {
215  auto &generated = op.Generated(shape);
216  if (!generated.IsEmpty()) {
217  if (findIter->second) {
218  findIter->second->updateGenerated(shape, generated, *this);
219  }
220  }
221  auto &modified = op.Modified(shape);
222  if (!modified.IsEmpty()) {
223  if (findIter->second) {
224  findIter->second->updateModified(shape, modified, *this);
225  }
226  shapesToRemove.emplace_back(shape);
227  }
228  }
229  }
230 }

◆ setDim()

void NEM::GEO::GeoManager::setDim ( int  dim)
inherited
Parameters
dimdimension (between 1 and 3)

Definition at line 52 of file GeoManager.C.

References NEM::GEO::GeoManager::dim_.

Referenced by NEM::NUCMESH::ShapeBase::mergeGeo().

52 { dim_ = dim; }

Member Data Documentation

◆ dim_

int NEM::GEO::GeoManager::dim_
protectedinherited

◆ map_


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