Renamed getEdges and getVertices to computeEdges and computeVertices

This commit is contained in:
iasonmanolas 2022-02-18 17:44:33 +02:00
parent ec7160e637
commit bef2ae8860
2 changed files with 57 additions and 47 deletions

View File

@ -78,12 +78,13 @@ double PatternGeometry::getTriangleEdgeSize() const { return triangleEdgeSize; }
PatternGeometry::PatternGeometry() {}
std::vector<vcg::Point3d> PatternGeometry::getVertices() const {
std::vector<VCGEdgeMesh::CoordType> verts(VN());
for (size_t vi = 0; vi < VN(); vi++) {
verts[vi] = vert[vi].cP();
}
return verts;
std::vector<vcg::Point3d> PatternGeometry::computeVertices() const
{
std::vector<VCGEdgeMesh::CoordType> 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<PatternGeometry, PatternGeometry>::MeshCopy(*this, other);
this->vertices = other.getVertices();
baseTriangle = other.getBaseTriangle();
baseTriangleHeight = computeBaseTriangleHeight();
vcg::tri::UpdateTopology<PatternGeometry>::VertexEdge(*this);
vcg::tri::UpdateTopology<PatternGeometry>::EdgeEdge(*this);
void PatternGeometry::updateBaseTriangle()
{
baseTriangle = computeBaseTriangle();
}
PatternGeometry::PatternGeometry(PatternGeometry &other)
{
vcg::tri::Append<PatternGeometry, PatternGeometry>::MeshCopy(*this, other);
this->vertices = other.computeVertices();
baseTriangle = other.getBaseTriangle();
baseTriangleHeight = computeBaseTriangleHeight();
vcg::tri::UpdateTopology<PatternGeometry>::VertexEdge(*this);
vcg::tri::UpdateTopology<PatternGeometry>::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<vcg::Point3d> &vertices) {
this->vertices = vertices;
std::for_each(vertices.begin(), vertices.end(), [&](const vcg::Point3d &p) {
vcg::tri::Allocator<PatternGeometry>::AddVertex(*this, p);
vcg::tri::Allocator<PatternGeometry>::AddVertex(*this, p, DefaultNormal);
});
vcg::tri::UpdateTopology<PatternGeometry>::VertexEdge(*this);
vcg::tri::UpdateTopology<PatternGeometry>::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<PatternGeometry>::VertexEdge(*this);
baseTriangleHeight = computeBaseTriangleHeight();
baseTriangle = computeBaseTriangle();
vcg::tri::UpdateTopology<PatternGeometry>::VertexEdge(*this);
baseTriangleHeight = computeBaseTriangleHeight();
baseTriangle = computeBaseTriangle();
updateEigenEdgeAndVertices();
updateEigenEdgeAndVertices();
}
double PatternGeometry::computeBaseTriangleHeight() const
@ -867,8 +875,8 @@ std::shared_ptr<PatternGeometry> 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> 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> 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> 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> 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> 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<VCGEdgeMesh>::PointerUpdater<VertexPointer> pu_vertices;
@ -987,6 +995,7 @@ std::shared_ptr<PatternGeometry> PatternGeometry::tilePattern(
return sum + v.size();
});
const int en = pTiledPattern->EN();
assert(pTiledPattern->EN() == sumOfEdgeIndices);
tileIntoEdgesToTiledVi.clear();

View File

@ -59,7 +59,7 @@ private:
bool hasDanglingEdges(const std::vector<size_t> &numberOfNodesPerSlot);
bool hasValenceGreaterThan(const std::vector<size_t> &numberOfNodesPerSlot,
const size_t &valenceThreshold);
std::vector<vcg::Point3d> getVertices() const;
std::vector<vcg::Point3d> computeVertices() const;
static PatternGeometry createFan(PatternGeometry &pattern);
static PatternGeometry createTile(PatternGeometry &pattern);
double getTriangleEdgeSize() const;
@ -85,7 +85,7 @@ private:
PatternGeometry(const std::vector<size_t> &numberOfNodesPerSlot,
const std::vector<vcg::Point2i> &edges);
PatternGeometry(const std::string &filename, bool addNormalsIfAbsent = true);
PatternGeometry(const std::filesystem::path &patternFilePath, bool addNormalsIfAbsent = true);
bool createHoneycombAtom();
void copy(PatternGeometry &copyFrom);
@ -129,6 +129,7 @@ private:
void deleteDanglingVertices() override;
void deleteDanglingVertices(
vcg::tri::Allocator<VCGEdgeMesh>::PointerUpdater<VertexPointer> &pu) override;
void updateBaseTriangle();
};
#endif // FLATPATTERNGEOMETRY_HPP