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.
PolarArray.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/PolarArray.H"
30 
31 #define _USE_MATH_DEFINES
32 #include <cmath>
33 
34 #include <gp_Ax1.hxx>
35 #include <gp_Trsf.hxx>
36 
37 namespace NEM {
38 namespace NUCMESH {
39 
40 namespace {
41 
42 double fixEndAngle(double startAngle, double endAngle) {
43  auto mapped = std::fmod(endAngle, 360.);
44  return mapped > startAngle ? mapped : mapped + 360;
45 }
46 
47 } // namespace
48 
49 PolarArray::PolarArray(std::size_t numSubshapes, double startAngle,
50  double endAngle, double radius, bool rotateWithArray,
51  const std::array<double, 3> &center)
52  : ShapesArray(center, numSubshapes),
53  numShapesInArr_(numSubshapes),
54  radius_(radius),
55  start_(startAngle),
56  end_(endAngle),
57  rotateWithArray_(rotateWithArray) {}
58 
60  const auto start = std::fmod(start_, 360.);
61  const auto end = fixEndAngle(start, end_);
62  const auto increment = (end - start) / numShapesInArr_;
63  double angle = start;
64  return this->createGeoImpl([this, increment,
65  &angle](NEM::GEO::GeoManager *const inp) {
66  if (inp) {
67  const auto destCenter =
68  getRotatedPoint(this->getCenter(), {this->radius_, angle});
69  gp_Trsf transformation{};
70  transformation.SetTranslation(
71  gp_Vec{destCenter[0], destCenter[1], destCenter[2]});
72  if (this->rotateWithArray_) {
73  gp_Trsf rotation{};
74  gp_Ax1 axisOfRotation{}; // Z-axis by default
75  rotation.SetRotation(axisOfRotation, angle * M_PI / 180.);
76  transformation *= rotation;
77  }
78  *inp = ShapesArray::basicTransformation(transformation, std::move(*inp));
79  }
80  angle += increment;
81  });
82 }
83 
84 } // namespace NUCMESH
85 } // namespace NEM
Class to manage TopoDS_Shapes along with metadata.
Definition: GeoManager.H:61
static std::array< double, 3 > getRotatedPoint(const std::array< double, 3 > &center, const std::array< double, 2 > &rotation)
Definition: ShapeBase.C:58
PolarArray(std::size_t numSubshapes, double startAngle, double endAngle, double radius, bool rotateWithArray=false, const std::array< double, 3 > &center={0, 0, 0})
Definition: PolarArray.C:49
std::size_t numShapesInArr_
Definition: PolarArray.H:74
const std::array< double, 3 > & getCenter() const
Definition: ShapeBase.C:50
NEM::GEO::GeoManager createGeoImpl(Modifier &&modifier) const
Definition: ShapesArray.H:87
static NEM::GEO::GeoManager basicTransformation(const gp_Trsf &transformation, NEM::GEO::GeoManager &&geoMetadata)
Definition: ShapesArray.C:81
Abstract base class representing a set of other ShapeBase objects, with a transformation applied to e...
Definition: ShapesArray.H:52
NEM::GEO::GeoManager createGeo() const override
Construct a NEM::GEO::GeoManager.
Definition: PolarArray.C:59