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::GEO::GeoManager Class Reference

Class to manage TopoDS_Shapes along with metadata. More...

Detailed Description

Handles results of BRepBuilderAPI_MakeShape (in particular, boolean operations) by delegating to the arguments' metadata. Also see NEM::GEO::ShapeData

Definition at line 61 of file GeoManager.H.

Classes

struct  ShapeMapHasher_Hash
 Hasher based on TopTools_ShapeMapHasher, which relies on TopoDS_Shape::IsSame, which is not TopoDS_Shape::operator==. More...
 
struct  ShapeMapHasher_KeyEqual
 Equality operator based on TopTools_ShapeMapHasher, which relies on TopoDS_Shape::IsSame, which is not TopoDS_Shape::operator==. More...
 

Public Types

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

Public Member Functions

 GeoManager (int dim)
 Create an empty geometry manager. 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_
 

Inherited by NEM::NUCMESH::NucMeshGeo.

Member Typedef Documentation

◆ MapType

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

Definition at line 85 of file GeoManager.H.

Constructor & Destructor Documentation

◆ GeoManager()

NEM::GEO::GeoManager::GeoManager ( int  dim)
explicit
Parameters
dimShapes of this dimension (clipped to be between 1 and 3, inclusive) are treated as first-class citizens, with lower-dimensional shapes assumed to be subshapes.

Definition at line 46 of file GeoManager.C.

47  : map_(),
48  dim_(std::min(3, std::max(1, dim))) {}

Member Function Documentation

◆ buildCompound()

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

Definition at line 145 of file GeoManager.C.

References isChild(), and map_.

Referenced by NEM::NUCMESH::ShapesArray::basicTransformation(), NEM::NUCMESH::NucMeshGeo::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

◆ deleteShapes() [1/2]

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

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 isChild(), and map_.

Referenced by 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)

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
shapesShapes to remove, if present

Definition at line 139 of file GeoManager.C.

References 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)
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 162 of file GeoManager.C.

References 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
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 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
Returns
dimension

Definition at line 50 of file GeoManager.C.

References dim_.

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

50 { return dim_; }

◆ getMap() [1/2]

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

Definition at line 186 of file GeoManager.C.

References map_.

Referenced by NEM::NUCMESH::CopyOverrideShapeData< QuadMeshSurface, GroupData >::updateModified().

186 { return map_; }

◆ getMap() [2/2]

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

Definition at line 188 of file GeoManager.C.

References map_.

188 { return map_; }

◆ insert()

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

Definition at line 181 of file GeoManager.C.

References 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 
)
inline
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 
)
inline
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
protected

Definition at line 190 of file GeoManager.C.

References dim_.

Referenced by buildCompound(), NEM::NUCMESH::NucMeshGeo::computeMesh(), and 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} 
)
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 modifyImpl(), and NEM::GEO::modifyTempl().

Referenced by NEM::NUCMESH::ShapeBase::mergeGeo(), and 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} 
)

Definition at line 84 of file GeoManager.C.

References 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} 
)

shapes are inferred from

Definition at line 94 of file GeoManager.C.

References 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} 
)

Definition at line 101 of file GeoManager.C.

References 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 
)
protected

Definition at line 207 of file GeoManager.C.

References map_.

Referenced by 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)
Parameters
dimdimension (between 1 and 3)

Definition at line 52 of file GeoManager.C.

References dim_.

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

52 { dim_ = dim; }

Member Data Documentation

◆ dim_

int NEM::GEO::GeoManager::dim_
protected

Definition at line 240 of file GeoManager.H.

Referenced by getDim(), isChild(), and setDim().

◆ map_

MapType NEM::GEO::GeoManager::map_
protected

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