MySources/trianglepatterngeometry.hpp

129 lines
5.4 KiB
C++
Raw Normal View History

2020-11-27 11:47:21 +01:00
#ifndef FLATPATTERNGEOMETRY_HPP
#define FLATPATTERNGEOMETRY_HPP
#include "edgemesh.hpp"
#include <string>
#include <unordered_map>
#include <unordered_set>
2021-03-15 18:04:29 +01:00
#include "vcgtrimesh.hpp"
#include "polymesh.hpp"
2020-11-27 11:47:21 +01:00
2021-04-30 12:13:58 +02:00
class PatternGeometry;
using ConstPatternGeometry = PatternGeometry;
class PatternGeometry : public VCGEdgeMesh
{
2020-11-27 11:47:21 +01:00
private:
size_t
computeTiledValence(const size_t &nodeIndex,
const std::vector<size_t> &numberOfNodesPerSlot) const;
size_t getNodeValence(const size_t &nodeIndex) const;
size_t getNodeSlot(const size_t &nodeIndex) const;
2021-03-15 18:04:29 +01:00
void addNormals();
double baseTriangleHeight;
double computeBaseTriangleHeight() const;
2021-04-30 12:13:58 +02:00
inline static size_t fanSize{6};
2020-11-27 11:47:21 +01:00
std::vector<VCGEdgeMesh::CoordType> vertices;
const double triangleEdgeSize{1}; // radius edge
2021-04-30 12:13:58 +02:00
std::unordered_map<size_t, size_t> nodeToSlotMap;
2020-11-27 11:47:21 +01:00
std::unordered_map<size_t, size_t> correspondingNode;
std::unordered_map<size_t, size_t> nodeTiledValence;
2021-04-30 12:13:58 +02:00
vcg::Triangle3<double> baseTriangle;
2020-11-27 11:47:21 +01:00
void
2021-04-30 12:13:58 +02:00
constructCorrespondingNodeMap(const std::vector<size_t> &numberOfNodesPerSlot);
void constructNodeToTiledValenceMap(const std::vector<size_t> &numberOfNodesPerSlot);
2020-11-27 11:47:21 +01:00
2021-04-30 12:13:58 +02:00
std::vector<VectorType> getEdgeVectorsWithVertexAsOrigin(std::vector<EdgePointer> &edgePointers,
const int &vi);
2020-11-27 11:47:21 +01:00
2021-04-30 12:13:58 +02:00
public:
2021-03-15 18:04:29 +01:00
PatternGeometry();
2020-11-27 11:47:21 +01:00
/*The following function should be a copy constructor with
* a const argument but this is impossible due to the
* vcglib interface.
* */
2021-03-15 18:04:29 +01:00
PatternGeometry(PatternGeometry &other);
2021-04-30 12:13:58 +02:00
bool load(const std::string &plyFilename) override;
2020-11-27 11:47:21 +01:00
void add(const std::vector<vcg::Point3d> &vertices);
void add(const std::vector<vcg::Point2i> &edges);
void add(const std::vector<vcg::Point3d> &vertices,
const std::vector<vcg::Point2i> &edges);
void add(const std::vector<size_t> &numberOfNodesPerSlot,
const std::vector<vcg::Point2i> &edges);
static std::vector<vcg::Point3d>
constructVertexVector(const std::vector<size_t> &numberOfNodesPerSlot,
const size_t &fanSize, const double &triangleEdgeSize);
bool hasDanglingEdges(const std::vector<size_t> &numberOfNodesPerSlot);
2021-04-30 12:13:58 +02:00
bool hasValenceGreaterThan(const std::vector<size_t> &numberOfNodesPerSlot,
const size_t &valenceThreshold);
2020-11-27 11:47:21 +01:00
std::vector<vcg::Point3d> getVertices() const;
2021-03-15 18:04:29 +01:00
static PatternGeometry createFan(PatternGeometry &pattern);
static PatternGeometry createTile(PatternGeometry &pattern);
2020-11-27 11:47:21 +01:00
double getTriangleEdgeSize() const;
bool hasUntiledDanglingEdges();
std::unordered_map<size_t, std::unordered_set<size_t>>
getIntersectingEdges(size_t &numberOfIntersectingEdgePairs) const;
static size_t binomialCoefficient(size_t n, size_t m) {
assert(n >= m);
return tgamma(n + 1) / (tgamma(m + 1) * tgamma(n - m + 1));
}
bool isFullyConnectedWhenTiled();
bool hasIntersectingEdges(
const std::string &patternBinaryRepresentation,
const std::unordered_map<size_t, std::unordered_set<size_t>>
&intersectingEdges);
bool isPatternValid();
size_t getFanSize() const;
2021-03-15 18:04:29 +01:00
void add(const std::vector<vcg::Point2d> &vertices,
const std::vector<vcg::Point2i> &edges);
PatternGeometry(const std::vector<size_t> &numberOfNodesPerSlot,
const std::vector<vcg::Point2i> &edges);
PatternGeometry(const std::string &filename, bool addNormalsIfAbsent = true);
bool createHoneycombAtom();
void copy(PatternGeometry &copyFrom);
2021-04-08 20:03:23 +02:00
void tilePattern(VCGEdgeMesh &pattern,
VCGPolyMesh &tileInto,
const int &interfaceNodeIndex,
2021-03-15 18:04:29 +01:00
const bool &shouldDeleteDanglingEdges);
2021-04-08 20:03:23 +02:00
void scale(const double &desiredBaseTriangleCentralEdgeSize, const int &interfaceNodeIndex);
2021-03-15 18:04:29 +01:00
double getBaseTriangleHeight() const;
2021-04-30 12:13:58 +02:00
vcg::Triangle3<double> computeBaseTriangle() const;
2021-03-15 18:04:29 +01:00
2021-04-08 20:03:23 +02:00
PatternGeometry(const std::vector<vcg::Point2d> &vertices, const std::vector<vcg::Point2i> &edges);
2021-04-30 12:13:58 +02:00
// static std::shared_ptr<PatternGeometry> tilePattern(
// std::vector<PatternGeometry> &pattern,
// const std::vector<int> &connectToNeighborsVi,
// const VCGPolyMesh &tileInto,
// std::vector<int> &tileIntoEdgesToTiledVi,
// std::vector<std::vector<size_t>> &perPatternEdges);
void createFan(const std::vector<int> &connectToNeighborsVi = std::vector<int>(),
const size_t &fanSize = 6);
int interfaceNodeIndex{3}; //TODO: Fix this. This should be automatically computed
bool hasAngleSmallerThanThreshold(const std::vector<size_t> &numberOfNodesPerSlot,
const double &angleThreshold_degrees);
vcg::Triangle3<double> getBaseTriangle() const;
2021-04-08 20:03:23 +02:00
static std::shared_ptr<PatternGeometry> tilePattern(PatternGeometry &pattern,
const std::vector<int> &connectToNeighborsVi,
2021-04-30 12:13:58 +02:00
const VCGPolyMesh &tileInto,
std::vector<int> &tileIntoEdgesToTiledVi);
static std::shared_ptr<PatternGeometry> tilePattern(
std::vector<ConstPatternGeometry> &patterns,
const std::vector<int> &connectToNeighborsVi,
const VCGPolyMesh &tileInto,
const std::vector<int> &perSurfaceFacePatternIndices,
2021-05-24 13:43:32 +02:00
std::vector<size_t> &tileIntoEdgesToTiledVi,
2021-04-30 12:13:58 +02:00
std::vector<std::vector<size_t>> &perPatternIndexTiledPatternEdgeIndex);
2020-11-27 11:47:21 +01:00
};
2021-04-08 20:03:23 +02:00
2020-11-27 11:47:21 +01:00
#endif // FLATPATTERNGEOMETRY_HPP