Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "CSGTransformationHelper.h" 11 : 12 : namespace CSG 13 : { 14 : 15 : void 16 118 : CSGTransformationHelper::addTransformation(TransformationType type, 17 : const std::tuple<Real, Real, Real> & values) 18 : { 19 118 : if (!isValidTransformationValue(type, values)) 20 2 : mooseError("Invalid transformation values provided for transformation type " + 21 6 : getTransformationTypeString(type)); 22 116 : _transformations.emplace_back(type, values); 23 116 : } 24 : 25 : bool 26 120 : CSGTransformationHelper::isValidTransformationValue(TransformationType type, 27 : const std::tuple<Real, Real, Real> & values) 28 : { 29 : // Additional validation specific to each transformation type could be added here 30 120 : switch (type) 31 : { 32 32 : case TransformationType::TRANSLATION: 33 : // All translation values are inherently valid 34 32 : return true; 35 : 36 70 : case TransformationType::ROTATION: 37 : // Rotation uses euler notation; values are angles in degrees (phi, theta, psi) 38 : // For consistency with TransformGenerator, there are no restrictions on the angles 39 : // phi: rotation around Z-axis 40 : // theta: rotation around new X-axis 41 : // psi: rotation around new Z-axis 42 70 : return true; 43 : 44 18 : case TransformationType::SCALE: 45 : // Scaling factors should be non-zero 46 18 : if (std::get<0>(values) == 0.0 || std::get<1>(values) == 0.0 || std::get<2>(values) == 0.0) 47 4 : return false; 48 14 : return true; 49 : 50 0 : default: 51 0 : mooseError("Unknown transformation type"); 52 : } 53 : } 54 : 55 : std::string 56 24 : CSGTransformationHelper::getTransformationTypeString(TransformationType type) 57 : { 58 : // Set the enum to the value and convert it to string 59 24 : MooseEnum enum_copy = transformation_type_enum; 60 24 : enum_copy = static_cast<int>(type); 61 48 : return std::string(enum_copy); 62 24 : } 63 : 64 : std::vector<std::pair<std::string, std::tuple<Real, Real, Real>>> 65 16 : CSGTransformationHelper::getTransformationsAsStrings() const 66 : { 67 16 : std::vector<std::pair<std::string, std::tuple<Real, Real, Real>>> result; 68 32 : for (const auto & transform_pair : _transformations) 69 16 : result.emplace_back(getTransformationTypeString(transform_pair.first), transform_pair.second); 70 16 : return result; 71 0 : } 72 : 73 : Point 74 14 : CSGTransformationHelper::applyReverseTransformsToPoint(Point p) const 75 : { 76 : // iterate list of transformations in reverse and apply the inverse operation 77 30 : for (auto it = _transformations.rbegin(); it != _transformations.rend(); ++it) 78 : { 79 16 : auto trans_type = it->first; 80 16 : auto val = it->second; 81 : 82 16 : if (trans_type == TransformationType::TRANSLATION) 83 : { 84 6 : Point offset(std::get<0>(val), std::get<1>(val), std::get<2>(val)); 85 6 : p -= offset; 86 : } 87 10 : else if (trans_type == TransformationType::SCALE) 88 : { 89 4 : Point scale(std::get<0>(val), std::get<1>(val), std::get<2>(val)); 90 16 : for (int i = 0; i < 3; ++i) 91 12 : p(i) /= scale(i); 92 : } 93 6 : else if (trans_type == TransformationType::ROTATION) 94 : { 95 : // get the transpose of the original rotation matrix and apply to point p 96 : const auto rot_matrix = RealTensorValue::intrinsic_rotation_matrix( 97 6 : std::get<0>(val), std::get<1>(val), std::get<2>(val)); 98 6 : const auto rot_transpose = rot_matrix.transpose(); 99 6 : p = rot_transpose * p; 100 6 : } 101 : else 102 0 : mooseError("Transformation type is not recognized."); 103 : } 104 14 : return p; 105 : } 106 : 107 : } // namespace CSG