diff --git a/trianglepatterngeometry.cpp b/trianglepatterngeometry.cpp index f8aa2e3..163c2fb 100755 --- a/trianglepatterngeometry.cpp +++ b/trianglepatterngeometry.cpp @@ -78,12 +78,13 @@ double PatternGeometry::getTriangleEdgeSize() const { return triangleEdgeSize; } PatternGeometry::PatternGeometry() {} -std::vector PatternGeometry::getVertices() const { - std::vector verts(VN()); - for (size_t vi = 0; vi < VN(); vi++) { - verts[vi] = vert[vi].cP(); - } - return verts; +std::vector PatternGeometry::computeVertices() const +{ + std::vector verts(VN()); + for (size_t vi = 0; vi < VN(); vi++) { + verts[vi] = vert[vi].cP(); + } + return verts; } PatternGeometry PatternGeometry::createTile(PatternGeometry &pattern) @@ -140,13 +141,19 @@ PatternGeometry PatternGeometry::createFan(PatternGeometry &pattern) { return fan; } -PatternGeometry::PatternGeometry(PatternGeometry &other) { - vcg::tri::Append::MeshCopy(*this, other); - this->vertices = other.getVertices(); - baseTriangle = other.getBaseTriangle(); - baseTriangleHeight = computeBaseTriangleHeight(); - vcg::tri::UpdateTopology::VertexEdge(*this); - vcg::tri::UpdateTopology::EdgeEdge(*this); +void PatternGeometry::updateBaseTriangle() +{ + baseTriangle = computeBaseTriangle(); +} + +PatternGeometry::PatternGeometry(PatternGeometry &other) +{ + vcg::tri::Append::MeshCopy(*this, other); + this->vertices = other.computeVertices(); + baseTriangle = other.getBaseTriangle(); + baseTriangleHeight = computeBaseTriangleHeight(); + vcg::tri::UpdateTopology::VertexEdge(*this); + vcg::tri::UpdateTopology::EdgeEdge(*this); } bool PatternGeometry::load(const std::filesystem::__cxx11::path &meshFilePath) @@ -166,7 +173,7 @@ bool PatternGeometry::load(const std::filesystem::__cxx11::path &meshFilePath) void PatternGeometry::add(const std::vector &vertices) { this->vertices = vertices; std::for_each(vertices.begin(), vertices.end(), [&](const vcg::Point3d &p) { - vcg::tri::Allocator::AddVertex(*this, p); + vcg::tri::Allocator::AddVertex(*this, p, DefaultNormal); }); vcg::tri::UpdateTopology::VertexEdge(*this); vcg::tri::UpdateTopology::EdgeEdge(*this); @@ -754,27 +761,28 @@ PatternGeometry::getIntersectingEdges( return intersectingEdges; } -PatternGeometry::PatternGeometry(const std::string &filename, - bool addNormalsIfAbsent) { - if (!std::filesystem::exists(std::filesystem::path(filename))) { - assert(false); - std::cerr << "No flat pattern with name " << filename << std::endl; - return; - } - if (!load(filename)) { - assert(false); - std::cerr << "File could not be loaded " << filename << std::endl; - return; - } - if (addNormalsIfAbsent) { - addNormals(); - } +PatternGeometry::PatternGeometry(const std::filesystem::path &patternFilePath, + bool addNormalsIfAbsent) +{ + if (!std::filesystem::exists(std::filesystem::path(patternFilePath))) { + assert(false); + std::cerr << "No flat pattern with name " << patternFilePath << std::endl; + return; + } + if (!load(patternFilePath)) { + assert(false); + std::cerr << "File could not be loaded " << patternFilePath << std::endl; + return; + } + if (addNormalsIfAbsent) { + addNormals(); + } - vcg::tri::UpdateTopology::VertexEdge(*this); - baseTriangleHeight = computeBaseTriangleHeight(); - baseTriangle = computeBaseTriangle(); + vcg::tri::UpdateTopology::VertexEdge(*this); + baseTriangleHeight = computeBaseTriangleHeight(); + baseTriangle = computeBaseTriangle(); - updateEigenEdgeAndVertices(); + updateEigenEdgeAndVertices(); } double PatternGeometry::computeBaseTriangleHeight() const @@ -867,8 +875,8 @@ std::shared_ptr PatternGeometry::tilePattern( assert(vcg::tri::HasFEAdjacency(tileInto)); assert(vcg::tri::HasFVAdjacency(tileInto)); for (const VCGPolyMesh::FaceType &f : tileInto.face) { - const int facePatternIndex = perSurfaceFacePatternIndices[tileInto.getIndex(f)]; - if (facePatternIndex == -1) { + const int patternIndex = perSurfaceFacePatternIndices[tileInto.getIndex(f)]; + if (patternIndex == -1) { continue; } CoordType centerOfFace(0, 0, 0); @@ -884,7 +892,7 @@ std::shared_ptr PatternGeometry::tilePattern( for (int &vi : firstInFanConnectToNeighbor_vi) { vi += pTiledPattern->VN(); } - ConstPatternGeometry &pattern = patterns[facePatternIndex]; + ConstPatternGeometry &pattern = patterns[patternIndex]; for (size_t vi = 0; vi < f.VN(); vi++) { auto ep = f.FEp(vi); @@ -909,9 +917,9 @@ std::shared_ptr PatternGeometry::tilePattern( //Transform the base triangle nodes to the mesh triangle using barycentric coords for (int vi = 0; vi < transformedPattern.VN(); vi++) { transformedPattern.vert[vi].P() = CoordType( - meshTrianglePoints[0] * barycentricCoordinates[facePatternIndex][vi][0] - + meshTrianglePoints[1] * barycentricCoordinates[facePatternIndex][vi][1] - + meshTrianglePoints[2] * barycentricCoordinates[facePatternIndex][vi][2]); + meshTrianglePoints[0] * barycentricCoordinates[patternIndex][vi][0] + + meshTrianglePoints[1] * barycentricCoordinates[patternIndex][vi][1] + + meshTrianglePoints[2] * barycentricCoordinates[patternIndex][vi][2]); } for (VertexType &v : transformedPattern.vert) { @@ -923,7 +931,7 @@ std::shared_ptr PatternGeometry::tilePattern( transformedPattern, remap); for (size_t ei = 0; ei < pattern.EN(); ei++) { - perPatternIndexToTiledPatternEdgeIndex[facePatternIndex].push_back(remap.edge[ei]); + perPatternIndexToTiledPatternEdgeIndex[patternIndex].push_back(remap.edge[ei]); } const size_t ei = tileInto.getIndex(ep); tileIntoEdgeToInterfaceVi[ei].push_back(remap.vert[pattern.interfaceNodeIndex]); @@ -938,7 +946,7 @@ std::shared_ptr PatternGeometry::tilePattern( firstInFanConnectToNeighbor_vi[connectToNeighborIndex], pTiledPattern->VN() - pattern.VN() + connectToNeighborsVi[connectToNeighborIndex]); - perPatternIndexToTiledPatternEdgeIndex[facePatternIndex].push_back( + perPatternIndexToTiledPatternEdgeIndex[patternIndex].push_back( pTiledPattern->getIndex(*eIt)); } } @@ -952,15 +960,15 @@ std::shared_ptr PatternGeometry::tilePattern( + connectToNeighborsVi[connectToNeighborIndex], pTiledPattern->VN() - pattern.VN() + connectToNeighborsVi[connectToNeighborIndex]); - perPatternIndexToTiledPatternEdgeIndex[facePatternIndex].push_back( + perPatternIndexToTiledPatternEdgeIndex[patternIndex].push_back( pTiledPattern->getIndex(*eIt)); } } } - // tiledPattern.updateEigenEdgeAndVertices(); - // tiledPattern.registerForDrawing(); + // pTiledPattern->updateEigenEdgeAndVertices(); + // pTiledPattern->registerForDrawing(); - // polyscope::show(); + // polyscope::show(); } } vcg::tri::Allocator::PointerUpdater pu_vertices; @@ -987,6 +995,7 @@ std::shared_ptr PatternGeometry::tilePattern( return sum + v.size(); }); + const int en = pTiledPattern->EN(); assert(pTiledPattern->EN() == sumOfEdgeIndices); tileIntoEdgesToTiledVi.clear(); diff --git a/trianglepatterngeometry.hpp b/trianglepatterngeometry.hpp index 3309446..249af04 100755 --- a/trianglepatterngeometry.hpp +++ b/trianglepatterngeometry.hpp @@ -59,7 +59,7 @@ private: bool hasDanglingEdges(const std::vector &numberOfNodesPerSlot); bool hasValenceGreaterThan(const std::vector &numberOfNodesPerSlot, const size_t &valenceThreshold); - std::vector getVertices() const; + std::vector computeVertices() const; static PatternGeometry createFan(PatternGeometry &pattern); static PatternGeometry createTile(PatternGeometry &pattern); double getTriangleEdgeSize() const; @@ -85,7 +85,7 @@ private: PatternGeometry(const std::vector &numberOfNodesPerSlot, const std::vector &edges); - PatternGeometry(const std::string &filename, bool addNormalsIfAbsent = true); + PatternGeometry(const std::filesystem::path &patternFilePath, bool addNormalsIfAbsent = true); bool createHoneycombAtom(); void copy(PatternGeometry ©From); @@ -129,6 +129,7 @@ private: void deleteDanglingVertices() override; void deleteDanglingVertices( vcg::tri::Allocator::PointerUpdater &pu) override; + void updateBaseTriangle(); }; #endif // FLATPATTERNGEOMETRY_HPP