Clean opengl rendering.

This commit is contained in:
James Grogan 2022-11-16 09:39:05 +00:00
parent 4849d83fcf
commit 798cb365d7
19 changed files with 483 additions and 274 deletions

View file

@ -16,16 +16,20 @@ void TriMesh::populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces)
mFaces = std::move(faces);
}
std::vector<std::vector<Point> > TriMesh::getFaceVertices() const
std::vector<unsigned> TriMesh::getFaceNodeIds() const
{
std::vector<std::vector<Point> > verts(mFaces.size());
unsigned nodes_per_face = 3;
std::vector<unsigned> ids(nodes_per_face*mFaces.size());
for(std::size_t idx=0; idx<mFaces.size(); idx++)
{
const auto nodeIds = mFaces[idx]->getNodeIds();
verts[idx] = {mNodes[nodeIds[0]]->getPoint(), mNodes[nodeIds[1]]->getPoint(), mNodes[nodeIds[2]]->getPoint()};
for(std::size_t jdx=0; jdx<nodes_per_face; jdx++)
{
ids[nodes_per_face*idx + jdx] = nodeIds[jdx];
}
}
return verts;
return ids;
}
std::vector<std::vector<double> > TriMesh::getFaceVectorAttributes(const std::string& tag)
@ -45,3 +49,34 @@ void TriMesh::addConstantFaceVectorAttribute(const std::string& tag, const std::
face->addVectorAttribute(tag, values);
}
}
void TriMesh::addConstantNodeVectorAttribute(const std::string& tag, const std::vector<double>& values)
{
}
std::vector<std::vector<double> > TriMesh::getNodeVectorAttributes(const std::string& tag)
{
std::vector<std::vector<double> > attribs(mNodes.size());
return attribs;
}
void TriMesh::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
{
mVectorAttributes[tag] = values;
}
bool TriMesh::hasVectorAttribute(const std::string& tag) const
{
return mVectorAttributes.find(tag) != mVectorAttributes.end();
}
std::vector<double> TriMesh::getVectorAttribute(const std::string& tag) const
{
auto iter = mVectorAttributes.find(tag);
if (iter != mVectorAttributes.end())
{
return iter->second;
}
return {};
}

View file

@ -2,11 +2,13 @@
#include "AbstractMesh.h"
#include "Point.h"
#include "Node.h"
#include <vector>
#include <memory>
#include <string>
#include <unordered_map>
class Node;
class Edge;
class TriFace;
@ -27,13 +29,38 @@ public:
void populate(VecNodes& nodes, VecEdges& edges, VecFaces& faces);
std::vector<std::vector<Point> > getFaceVertices() const;
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;
private:
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
VecNodes mNodes;
VecEdges mEdges;
VecFaces mFaces;