stuff-from-scratch/src/mesh/TriMesh.h
2022-11-16 15:06:08 +00:00

72 lines
1.9 KiB
C++

#pragma once
#include "AbstractMesh.h"
#include "Point.h"
#include "Node.h"
#include <vector>
#include <memory>
#include <string>
#include <unordered_map>
class Edge;
class TriFace;
using NodePtr = std::unique_ptr<Node>;
using EdgePtr = std::unique_ptr<Edge>;
using TriFacePtr = std::unique_ptr<TriFace>;
using VecNodes = std::vector<NodePtr>;
using VecEdges = std::vector<EdgePtr>;
using VecFaces = std::vector<TriFacePtr>;
class TriMesh : public AbstractMesh
{
public:
TriMesh() = default;
~TriMesh();
void populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces);
template<typename T>
std::vector<T> getVerticesFlat(T scaleX = 1.0, T scaleY = 1.0, T scaleZ = 1.0) const
{
std::vector<T> ret(3*mNodes.size());
for(std::size_t idx = 0; idx<mNodes.size(); idx++)
{
auto node = mNodes[idx].get();
ret[3*idx] = node->getPoint().getX()/scaleX;
ret[3*idx + 1] = node->getPoint().getY()/scaleY;
ret[3*idx + 2] = node->getPoint().getZ()/scaleZ;
}
return ret;
}
std::vector<unsigned> getFaceNodeIds() const;
void addConstantFaceVectorAttribute(const std::string& tag, const std::vector<double>& values);
void addConstantNodeVectorAttribute(const std::string& tag, const std::vector<double>& values);
std::vector<std::vector<double> > getFaceVectorAttributes(const std::string& tag);
std::vector<std::vector<double> > getNodeVectorAttributes(const std::string& tag);
void addVectorAttribute(const std::string& tag, const std::vector<double>& values);
bool hasVectorAttribute(const std::string& tag) const;
std::vector<double> getVectorAttribute(const std::string& tag) const;
MeshType getType() const
{
return MeshType::TRI;
}
private:
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
VecNodes mNodes;
VecEdges mEdges;
VecFaces mFaces;
};