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.
ShapesArray.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #include "NucMesh/ShapesArray.H"
30 
31 #include <memory>
32 
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopoDS_Compound.hxx>
37 
38 namespace NEM {
39 namespace NUCMESH {
40 
41 ShapesArray::ShapesArray(const std::array<double, 3> &center,
42  std::size_t numPatternShapes)
43  : ShapeBase(center), patternShapes_(), pattern_(numPatternShapes) {}
44 
45 std::size_t ShapesArray::getNumPatternShapes() const {
46  return patternShapes_.size();
47 }
48 
49 const ShapeBase *ShapesArray::getPatternShape(std::size_t idx) const {
50  if (idx < patternShapes_.size()) {
51  return patternShapes_.at(idx).get();
52  } else {
53  return nullptr;
54  }
55 }
56 
57 void ShapesArray::setPatternShape(std::size_t idx,
58  const std::shared_ptr<ShapeBase> &shape) {
59  if (idx >= patternShapes_.size()) {
60  patternShapes_.resize(idx + 1);
61  }
62  patternShapes_.at(idx) = shape;
63 }
64 
65 void ShapesArray::fillPattern(std::size_t idx) {
66  for (auto &pattern : pattern_) {
67  pattern = idx;
68  }
69 }
70 
71 std::size_t ShapesArray::getPatternSize() const { return pattern_.size(); }
72 
73 const std::size_t &ShapesArray::getPattern(std::size_t idx) const {
74  return pattern_.at(idx);
75 }
76 
77 void ShapesArray::setPattern(std::size_t idx, std::size_t patternKey) {
78  pattern_.at(idx) = patternKey;
79 }
80 
82  const gp_Trsf &transformation, NEM::GEO::GeoManager &&geoMetadata) {
83  auto compound = geoMetadata.buildCompound();
84  BRepBuilderAPI_Transform transformer{transformation};
85  transformer.Perform(compound);
86  NEM::GEO::GeoManager output(geoMetadata.getDim());
87  static constexpr std::array<TopAbs_ShapeEnum, 4> shapeTypes{
88  TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX};
89  for (auto &shapeType : shapeTypes) {
90  for (TopExp_Explorer explorer{compound, shapeType}; explorer.More();
91  explorer.Next()) {
92  auto &oldSubshape = explorer.Current();
93  if (auto old_metadata = geoMetadata.get(oldSubshape)) {
94  output.insert(transformer.ModifiedShape(oldSubshape),
95  std::move(*old_metadata));
96  }
97  }
98  }
99  return output;
100 }
101 
102 } // namespace NUCMESH
103 } // namespace NEM
std::pair< MapType::iterator, bool > insert(const TopoDS_Shape &shape, std::shared_ptr< ShapeData > shapeData)
Definition: GeoManager.C:181
std::vector< decltype(patternShapes_)::size_type > pattern_
Each entry of pattern_ is an index into patternShapes_; subclasses interpret how to transform each en...
Definition: ShapesArray.H:116
Class to manage TopoDS_Shapes along with metadata.
Definition: GeoManager.H:61
ShapesArray(const std::array< double, 3 > &center, std::size_t numPatternShapes)
Definition: ShapesArray.C:41
std::size_t getNumPatternShapes() const
Definition: ShapesArray.C:45
static constexpr auto shapeType
Definition: NucMeshJson.H:81
void fillPattern(std::size_t idx)
Definition: ShapesArray.C:65
void setPatternShape(std::size_t idx, const std::shared_ptr< ShapeBase > &shape)
Definition: ShapesArray.C:57
std::vector< std::shared_ptr< ShapeBase > > patternShapes_
A set of other ShapeBase objects, referenced by pattern_.
Definition: ShapesArray.H:111
Abstract base class for types that create NEM::GEO::GeoManager.
Definition: ShapeBase.H:52
TopoDS_Compound buildCompound() const
Create a compound from shapes present in the map that have same dimension as the instance.
Definition: GeoManager.C:145
static NEM::GEO::GeoManager basicTransformation(const gp_Trsf &transformation, NEM::GEO::GeoManager &&geoMetadata)
Definition: ShapesArray.C:81
const ShapeBase * getPatternShape(std::size_t idx) const
Definition: ShapesArray.C:49
std::size_t getPatternSize() const
Definition: ShapesArray.C:71
void setPattern(std::size_t idx, std::size_t patternKey)
Definition: ShapesArray.C:77
const std::size_t & getPattern(std::size_t idx) const
Definition: ShapesArray.C:73