From 0cb175e72efcaef63e202cc8d31fb5c50b2d9cf0 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Fri, 6 May 2022 16:27:00 +0300 Subject: [PATCH] Added functions for changing the geometry and material props of the reduced model --- reducedmodel.cpp | 102 +++++++++++++++++++++++++++++++++++++++-------- reducedmodel.hpp | 8 +++- 2 files changed, 93 insertions(+), 17 deletions(-) diff --git a/reducedmodel.cpp b/reducedmodel.cpp index 3cb1688..e754639 100644 --- a/reducedmodel.cpp +++ b/reducedmodel.cpp @@ -1,24 +1,94 @@ #include "reducedmodel.hpp" -void ReducedModel::constructReducedModelBaseTriangleGeometry() -{ - std::vector vertices{{0, 0, 0}, - {-0.1666666666666666, -0.2886751345948129, 0}, - {-0.3333333333333333, -0.5773502691896257, 0}, - {0, -0.8660254037844387, 0}, - {0.3333333333333333, -0.5773502691896258, 0}, - {0.1666666666666666, -0.288675134594813, 0}, - {0, -0.3333333, 0}}; - std::vector edges{{0, 3}}; - add(vertices, edges); +ReducedModel::ReducedModel() : PatternGeometry({1, 0, 0, 2, 1, 2, 1}, {{0, 3}}) - updateBaseTriangle(); +{ interfaceNodeIndex = 3; - vcg::tri::UpdateTopology::VertexEdge(*this); - vcg::tri::UpdateTopology::EdgeEdge(*this); + label = "ReducedModel"; + // constexpr double initialHexSize = 0.3; + // CoordType movableVertex_barycentric(1 - initialHexSize, initialHexSize / 2, initialHexSize / 2); + // const vcg::Triangle3 &baseTriangle = getBaseTriangle(); + // vert[0].P() = baseTriangle.cP(0) * movableVertex_barycentric[0] + // + baseTriangle.cP(1) * movableVertex_barycentric[1] + // + baseTriangle.cP(2) * movableVertex_barycentric[2]; } -ReducedModel::ReducedModel() +void ReducedModel::updateBaseTriangleGeometry_theta(const double &newTheta_deg) { - constructReducedModelBaseTriangleGeometry(); + const CoordType baseTriangleHexagonVertexPosition = vert[0].cP(); + + const CoordType thetaRotatedHexagonBaseTriangleVertexPosition + = vcg::RotationMatrix(PatternGeometry::DefaultNormal, vcg::math::ToRad(newTheta_deg)) + * baseTriangleHexagonVertexPosition; + vert[0].P() = thetaRotatedHexagonBaseTriangleVertexPosition; + + // constexpr int fanSize = 6; + // for (int rotationCounter = 0; rotationCounter < /*ReducedModelOptimizer::*/ fanSize; + // rotationCounter++) { + // vert[2 * rotationCounter].P() = vcg::RotationMatrix(PatternGeometry::DefaultNormal, + // vcg::math::ToRad(60.0 * rotationCounter)) + // * thetaRotatedHexagonBaseTriangleVertexPosition; + // } + updateEigenEdgeAndVertices(); +} + +void ReducedModel::updateBaseTriangleGeometry_R(const double &newR) +{ + const CoordType barycentricCoordinates_hexagonBaseTriangleVertex(1 - newR, newR / 2, newR / 2); + const vcg::Triangle3 &baseTriangle = getBaseTriangle(); + const CoordType hexagonBaseTriangleVertexPosition + = baseTriangle.cP(0) * barycentricCoordinates_hexagonBaseTriangleVertex[0] + + baseTriangle.cP(1) * barycentricCoordinates_hexagonBaseTriangleVertex[1] + + baseTriangle.cP(2) * barycentricCoordinates_hexagonBaseTriangleVertex[2]; + vert[0].P() = hexagonBaseTriangleVertexPosition; + + // constexpr int fanSize = 6; + // for (int rotationCounter = 0; rotationCounter < /*ReducedModelOptimizer::*/ fanSize; + // rotationCounter++) { + // vert[2 * rotationCounter].P() = vcg::RotationMatrix(PatternGeometry::DefaultNormal, + // vcg::math::ToRad(60.0 * rotationCounter)) + // * hexagonBaseTriangleVertexPosition; + // // std::cout << vert[2 * rotationCounter].P()[0] << " " << vert[2 * rotationCounter].P()[1] + // // << " " << vert[2 * rotationCounter].P()[2] << std::endl; + // } + updateEigenEdgeAndVertices(); +} + +void ReducedModel::updateBaseTriangleGeometry_theta( + const double &newTheta_deg, std::shared_ptr &pReducedModel_edgeMesh) +{ + std::dynamic_pointer_cast(pReducedModel_edgeMesh) + ->updateBaseTriangleGeometry_theta(newTheta_deg); +} + +void ReducedModel::updateBaseTriangleGeometry_R(const double &newR, + std::shared_ptr &pReducedModel_edgeMesh) +{ + std::dynamic_pointer_cast(pReducedModel_edgeMesh) + ->updateBaseTriangleGeometry_R(newR); +} + +void ReducedModel::createFan(const size_t &fanSize) +{ + deleteDanglingVertices(); + PatternGeometry rotatedPattern; + vcg::tri::Append::MeshCopy(rotatedPattern, *this); + for (int rotationCounter = 1; rotationCounter < fanSize; rotationCounter++) { + vcg::Matrix44d R; + auto rotationAxis = PatternGeometry::DefaultNormal; + R.SetRotateDeg(360.0 / fanSize, rotationAxis); + vcg::tri::UpdatePosition::Matrix(rotatedPattern, R); + vcg::tri::Append::Mesh(*this, rotatedPattern); + //For the reduced model we also need to connect to neighbouring base triangles of the fan + if (rotationCounter == fanSize - 1) { + vcg::tri::Allocator::AddEdge(*this, + 0, + this->VN() - rotatedPattern.VN()); + } + vcg::tri::Allocator::AddEdge(*this, + this->VN() - 2 * rotatedPattern.VN(), + this->VN() - rotatedPattern.VN()); + removeDuplicateVertices(); + updateEigenEdgeAndVertices(); + } } diff --git a/reducedmodel.hpp b/reducedmodel.hpp index 5afe241..16996d6 100644 --- a/reducedmodel.hpp +++ b/reducedmodel.hpp @@ -5,10 +5,16 @@ class ReducedModel : public PatternGeometry { - void constructReducedModelBaseTriangleGeometry(); public: ReducedModel(); + void updateBaseTriangleGeometry_theta(const double &newTheta_deg); + void updateBaseTriangleGeometry_R(const double &newR); + static void updateBaseTriangleGeometry_theta( + const double &newTheta_deg, std::shared_ptr &pReducedModel_edgeMesh); + static void updateBaseTriangleGeometry_R(const double &newR, + std::shared_ptr &pReducedModel_edgeMesh); + void createFan(const size_t &fanSize = 6) override; }; #endif // REDUCEDMODEL_HPP