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.H
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 #ifndef NEMOSYS_SHAPESARRAY_H_
30 #define NEMOSYS_SHAPESARRAY_H_
31 
32 #include "nemosys_export.h"
33 #include "NucMesh/ShapeBase.H"
34 
35 #include <map>
36 #include <memory>
37 #include <type_traits>
38 #include <utility>
39 #include <vector>
40 
41 #include "Geometry/GeoManager.H"
42 
43 class gp_Trsf;
44 
45 namespace NEM {
46 namespace NUCMESH {
47 
48 /**
49  * Abstract base class representing a set of other @c ShapeBase objects, with a
50  * transformation applied to each.
51  */
52 class NEMOSYS_EXPORT ShapesArray : public ShapeBase {
53  public:
54  std::size_t getNumPatternShapes() const;
55 
56  const ShapeBase *getPatternShape(std::size_t idx) const;
57 
58  void setPatternShape(std::size_t idx,
59  const std::shared_ptr<ShapeBase> &shape);
60 
61  template <typename Shape>
62  void insertPatternShape(std::size_t idx, Shape &&shape) {
63  this->setPatternShape(idx,
64  std::make_shared<typename std::decay<Shape>::type>(
65  std::forward<Shape>(shape)));
66  }
67 
68  template <typename Shape, typename... Args>
69  void makePatternShape(std::size_t idx, Args &&...args) {
70  this->setPatternShape(idx,
71  std::make_shared<Shape>(std::forward<Args>(args)...));
72  }
73 
74  void fillPattern(std::size_t idx);
75 
76  protected:
77  ShapesArray(const std::array<double, 3> &center,
78  std::size_t numPatternShapes);
79 
80  std::size_t getPatternSize() const;
81 
82  const std::size_t &getPattern(std::size_t idx) const;
83 
84  void setPattern(std::size_t idx, std::size_t patternKey);
85 
86  template <typename Modifier>
87  NEM::GEO::GeoManager createGeoImpl(Modifier &&modifier) const {
88  NEM::GEO::GeoManager output(0);
89  for (auto &patternId : pattern_) {
90  auto shape = patternId < patternShapes_.size()
91  ? patternShapes_.at(patternId).get()
92  : nullptr;
93  if (shape) {
94  auto subShapeOut = shape->createGeo();
95  modifier(&subShapeOut);
96  ShapeBase::mergeGeo(output, std::move(subShapeOut));
97  } else {
98  modifier(nullptr);
99  }
100  }
101  return output;
102  }
103 
104  static NEM::GEO::GeoManager basicTransformation(
105  const gp_Trsf &transformation, NEM::GEO::GeoManager &&geoMetadata);
106 
107  private:
108  /**
109  * A set of other @c ShapeBase objects, referenced by @c pattern_
110  */
111  std::vector<std::shared_ptr<ShapeBase>> patternShapes_;
112  /**
113  * Each entry of @c pattern_ is an index into @c patternShapes_; subclasses
114  * interpret how to transform each entry
115  */
116  std::vector<decltype(patternShapes_)::size_type> pattern_;
117 };
118 
119 } // namespace NUCMESH
120 } // namespace NEM
121 
122 #endif // NEMOSYS_SHAPESARRAY_H_
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
void insertPatternShape(std::size_t idx, Shape &&shape)
Definition: ShapesArray.H:62
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
NEM::GEO::GeoManager createGeoImpl(Modifier &&modifier) const
Definition: ShapesArray.H:87
static void mergeGeo(NEM::GEO::GeoManager &keepGeo, NEM::GEO::GeoManager &&removeGeo)
Merge two 2d NEM::GEO::GeoManager objects by cutting shapes in removeGeo from shapes in keepGeo and s...
Definition: ShapeBase.C:66
void makePatternShape(std::size_t idx, Args &&...args)
Definition: ShapesArray.H:69
Abstract base class representing a set of other ShapeBase objects, with a transformation applied to e...
Definition: ShapesArray.H:52