Added functions for changing the geometry and material props of the reduced model

This commit is contained in:
iasonmanolas 2022-05-06 16:27:00 +03:00
parent a7fdf431dd
commit 0cb175e72e
2 changed files with 93 additions and 17 deletions

View File

@ -1,24 +1,94 @@
#include "reducedmodel.hpp"
void ReducedModel::constructReducedModelBaseTriangleGeometry()
{
std::vector<vcg::Point3d> 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<vcg::Point2i> edges{{0, 3}};
add(vertices, edges);
ReducedModel::ReducedModel() : PatternGeometry({1, 0, 0, 2, 1, 2, 1}, {{0, 3}})
updateBaseTriangle();
{
interfaceNodeIndex = 3;
vcg::tri::UpdateTopology<PatternGeometry>::VertexEdge(*this);
vcg::tri::UpdateTopology<PatternGeometry>::EdgeEdge(*this);
label = "ReducedModel";
// constexpr double initialHexSize = 0.3;
// CoordType movableVertex_barycentric(1 - initialHexSize, initialHexSize / 2, initialHexSize / 2);
// const vcg::Triangle3<double> &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<double> &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<VCGEdgeMesh> &pReducedModel_edgeMesh)
{
std::dynamic_pointer_cast<ReducedModel>(pReducedModel_edgeMesh)
->updateBaseTriangleGeometry_theta(newTheta_deg);
}
void ReducedModel::updateBaseTriangleGeometry_R(const double &newR,
std::shared_ptr<VCGEdgeMesh> &pReducedModel_edgeMesh)
{
std::dynamic_pointer_cast<ReducedModel>(pReducedModel_edgeMesh)
->updateBaseTriangleGeometry_R(newR);
}
void ReducedModel::createFan(const size_t &fanSize)
{
deleteDanglingVertices();
PatternGeometry rotatedPattern;
vcg::tri::Append<PatternGeometry, PatternGeometry>::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<PatternGeometry>::Matrix(rotatedPattern, R);
vcg::tri::Append<PatternGeometry, PatternGeometry>::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<PatternGeometry>::AddEdge(*this,
0,
this->VN() - rotatedPattern.VN());
}
vcg::tri::Allocator<PatternGeometry>::AddEdge(*this,
this->VN() - 2 * rotatedPattern.VN(),
this->VN() - rotatedPattern.VN());
removeDuplicateVertices();
updateEigenEdgeAndVertices();
}
}

View File

@ -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<VCGEdgeMesh> &pReducedModel_edgeMesh);
static void updateBaseTriangleGeometry_R(const double &newR,
std::shared_ptr<VCGEdgeMesh> &pReducedModel_edgeMesh);
void createFan(const size_t &fanSize = 6) override;
};
#endif // REDUCEDMODEL_HPP