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.
ShapeBase.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/ShapeBase.H"
30 
31 #define _USE_MATH_DEFINES
32 #include <cmath>
33 
34 #include <array>
35 #include <vector>
36 
37 #include <BRepAlgoAPI_Cut.hxx>
38 #include <BRepBuilderAPI_Sewing.hxx>
39 #include <TopAbs_ShapeEnum.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopoDS_ListOfShape.hxx>
43 #include <TopoDS_Shape.hxx>
44 
45 #include "Geometry/GeoManager.H"
46 
47 namespace NEM {
48 namespace NUCMESH {
49 
50 const std::array<double, 3> &ShapeBase::getCenter() const { return center_; }
51 
52 void ShapeBase::setCenter(const std::array<double, 3> &center) {
53  center_ = center;
54 }
55 
56 ShapeBase::ShapeBase(const std::array<double, 3> &center) : center_(center) {}
57 
58 std::array<double, 3> ShapeBase::getRotatedPoint(
59  const std::array<double, 3> &center,
60  const std::array<double, 2> &rotation) {
61  auto angle = rotation[1] * M_PI / 180.;
62  return {center[0] + rotation[0] * std::cos(angle),
63  center[1] + rotation[0] * std::sin(angle), center[2]};
64 }
65 
67  NEM::GEO::GeoManager &&removeGeo) {
68  auto origCompound = keepGeo.buildCompound();
69  if (origCompound.IsNull()) {
70  keepGeo = std::move(removeGeo);
71  return;
72  } else {
73  auto newCompound = removeGeo.buildCompound();
74  TopoDS_ListOfShape newShapes;
75  static constexpr std::array<TopAbs_ShapeEnum, 4> shapeTypes{
76  TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX};
77  for (auto &shapeType : shapeTypes) {
78  for (TopExp_Explorer explorer{newCompound, shapeType}; explorer.More();
79  explorer.Next()) {
80  auto &oldSubshape = explorer.Current();
81  if (auto old_metadata = removeGeo.get(oldSubshape)) {
82  keepGeo.insert(oldSubshape, std::move(*old_metadata));
83  }
84  }
85  }
86  if (!newCompound.IsNull()) {
87  keepGeo.setDim(std::max(keepGeo.getDim(), removeGeo.getDim()));
88  BRepAlgoAPI_Cut cutter{origCompound, newCompound};
89  if (cutter.HasDeleted() || cutter.HasModified() ||
90  cutter.HasGenerated()) {
91  auto deletedShapes = keepGeo.modify(cutter, {TopAbs_EDGE, TopAbs_FACE});
92  keepGeo.deleteShapes(deletedShapes[0]);
93  }
94  BRepBuilderAPI_Sewing sewer{};
95  std::vector<TopoDS_Shape> sewedShapes;
96  auto compound = keepGeo.buildCompound();
97  for (TopExp_Explorer explorer{compound, TopAbs_FACE}; explorer.More();
98  explorer.Next()) {
99  sewer.Add(explorer.Current());
100  sewedShapes.emplace_back(explorer.Current());
101  }
102  sewer.Perform();
103  auto deletedShapes =
104  keepGeo.modify(sewer, sewedShapes, {TopAbs_EDGE, TopAbs_FACE});
105  keepGeo.deleteShapes(deletedShapes);
106  }
107  }
108 }
109 
110 } // namespace NUCMESH
111 } // namespace NEM
std::pair< MapType::iterator, bool > insert(const TopoDS_Shape &shape, std::shared_ptr< ShapeData > shapeData)
Definition: GeoManager.C:181
Class to manage TopoDS_Shapes along with metadata.
Definition: GeoManager.H:61
void deleteShapes(const TopoDS_Shape &shape)
Remove a shape from the map.
Definition: GeoManager.C:127
int getDim() const
Get dimension of geometry.
Definition: GeoManager.C:50
std::array< double, 3 > center_
Definition: ShapeBase.H:97
static constexpr auto shapeType
Definition: NucMeshJson.H:81
static std::array< double, 3 > getRotatedPoint(const std::array< double, 3 > &center, const std::array< double, 2 > &rotation)
Definition: ShapeBase.C:58
const std::array< double, 3 > & getCenter() const
Definition: ShapeBase.C:50
ShapeBase(const std::array< double, 3 > &center={0, 0, 0})
Definition: ShapeBase.C:56
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 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
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
void setCenter(const std::array< double, 3 > &center)
Definition: ShapeBase.C:52
void setDim(int dim)
Set the dimension.
Definition: GeoManager.C:52