Start adding grid
This commit is contained in:
parent
9301769d58
commit
f04d86e0ad
37 changed files with 709 additions and 211 deletions
22
src/mesh/AbstractFace.cpp
Normal file
22
src/mesh/AbstractFace.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "AbstractFace.h"
|
||||
|
||||
AbstractFace::AbstractFace(unsigned id)
|
||||
: mId(id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AbstractFace::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
mVectorAttributes[tag] = values;
|
||||
}
|
||||
|
||||
std::vector<double> AbstractFace::getVectorAttribute(const std::string& tag) const
|
||||
{
|
||||
auto iter = mVectorAttributes.find(tag);
|
||||
if (iter != mVectorAttributes.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return {};
|
||||
}
|
24
src/mesh/AbstractFace.h
Normal file
24
src/mesh/AbstractFace.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
class AbstractFace
|
||||
{
|
||||
public:
|
||||
AbstractFace(unsigned id=0);
|
||||
|
||||
virtual ~AbstractFace() = default;
|
||||
|
||||
virtual std::vector<unsigned> getNodeIds() const = 0;
|
||||
|
||||
void addVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
std::vector<double> getVectorAttribute(const std::string& tag) const;
|
||||
|
||||
protected:
|
||||
unsigned mId{0};
|
||||
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
#include "AbstractMesh.h"
|
||||
|
||||
void AbstractMesh::addConstantNodeVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::vector<double> > AbstractMesh::getNodeVectorAttributes(const std::string& tag)
|
||||
{
|
||||
std::vector<std::vector<double> > attribs(mNodes.size());
|
||||
return attribs;
|
||||
}
|
||||
|
||||
void AbstractMesh::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
mVectorAttributes[tag] = values;
|
||||
}
|
||||
|
||||
bool AbstractMesh::hasVectorAttribute(const std::string& tag) const
|
||||
{
|
||||
return mVectorAttributes.find(tag) != mVectorAttributes.end();
|
||||
}
|
||||
|
||||
std::vector<double> AbstractMesh::getVectorAttribute(const std::string& tag) const
|
||||
{
|
||||
auto iter = mVectorAttributes.find(tag);
|
||||
if (iter != mVectorAttributes.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void AbstractMesh::scale(double scaleX, double scaleY)
|
||||
{
|
||||
for (auto& node : mNodes)
|
||||
{
|
||||
node->scale(scaleX, scaleY);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "Point.h"
|
||||
#include "Node.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using NodePtr = std::unique_ptr<Node>;
|
||||
using VecNodes = std::vector<NodePtr>;
|
||||
|
||||
class AbstractMesh
|
||||
{
|
||||
public:
|
||||
|
||||
enum class MeshType
|
||||
{
|
||||
LINE,
|
||||
|
@ -13,5 +21,35 @@ public:
|
|||
|
||||
virtual ~AbstractMesh() = default;
|
||||
|
||||
void addVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
void addConstantNodeVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
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<std::vector<double> > getNodeVectorAttributes(const std::string& tag);
|
||||
|
||||
std::vector<double> getVectorAttribute(const std::string& tag) const;
|
||||
|
||||
virtual MeshType getType() const = 0;
|
||||
|
||||
bool hasVectorAttribute(const std::string& tag) const;
|
||||
|
||||
void scale(double scaleX, double scaleY);
|
||||
|
||||
protected:
|
||||
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
|
||||
VecNodes mNodes;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
list(APPEND mesh_LIB_INCLUDES
|
||||
AbstractMesh.cpp
|
||||
Edge.cpp
|
||||
Face.cpp
|
||||
AbstractFace.cpp
|
||||
QuadFace.cpp
|
||||
TriFace.cpp
|
||||
Node.cpp
|
||||
QuadMesh.cpp
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
#include "MeshPrimitives.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::unique_ptr<TriMesh> MeshPrimitives::build(const Rectangle& rectangle)
|
||||
{
|
||||
const auto bottom_left = rectangle.getLocation();
|
||||
const auto width = rectangle.getWidth();
|
||||
const auto height = rectangle.getHeight();
|
||||
|
||||
VecPoints locations = {
|
||||
bottom_left,
|
||||
Point(bottom_left, width, 0),
|
||||
Point(bottom_left, width, height),
|
||||
Point(bottom_left, 0, height)
|
||||
};
|
||||
|
||||
EdgeIds edge_ids = {
|
||||
{0, 1},
|
||||
{1, 2},
|
||||
{2, 0},
|
||||
{2, 3},
|
||||
{3, 0}
|
||||
};
|
||||
|
||||
FaceIds face_ids = {
|
||||
{0, 1, 2},
|
||||
{2, 3, 4}
|
||||
};
|
||||
|
||||
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
|
||||
}
|
||||
|
||||
std::unique_ptr<TriMesh> MeshPrimitives::buildExplodedGrid(unsigned numX, unsigned numY)
|
||||
{
|
||||
double delta_x = 1.0/double(numX);
|
||||
double delta_y = 1.0/double(numY);
|
||||
|
||||
VecPoints locations (4 * numX * numY);
|
||||
double offset_x = delta_x;
|
||||
double offset_y = delta_y;
|
||||
for (unsigned idx=0; idx<numY; idx++)
|
||||
{
|
||||
for(unsigned jdx=0; jdx<numX; jdx++)
|
||||
{
|
||||
auto locX0 = offset_x - delta_x/2.0;
|
||||
auto locX1 = offset_x + delta_x/2.0;
|
||||
auto locY0 = offset_y - delta_y/2.0;
|
||||
auto locY1 = offset_y + delta_y/2.0;
|
||||
|
||||
auto id_offset = 4* (jdx + numX*idx);
|
||||
locations[id_offset] = Point(locX0, locY0);
|
||||
locations[id_offset + 1] = Point(locX1, locY0);
|
||||
locations[id_offset + 2] = Point(locX1, locY1);
|
||||
locations[id_offset + 3] = Point(locX0, locY1);
|
||||
offset_x += delta_x;
|
||||
}
|
||||
offset_x = delta_x;
|
||||
offset_y += delta_y;
|
||||
}
|
||||
|
||||
EdgeIds edge_ids(5 * numX * numY);
|
||||
for (unsigned idx=0; idx<numY; idx++)
|
||||
{
|
||||
for(unsigned jdx=0; jdx<numX; jdx++)
|
||||
{
|
||||
unsigned node_offset = 4 * (jdx + numX * idx);
|
||||
auto id_offset = 5* (jdx + numX*idx);
|
||||
edge_ids[id_offset] = {node_offset, node_offset + 1};
|
||||
edge_ids[id_offset + 1] = {node_offset + 1, node_offset + 2};
|
||||
edge_ids[id_offset + 2] = {node_offset + 2, node_offset + 3};
|
||||
edge_ids[id_offset + 3] = {node_offset + 3, node_offset};
|
||||
edge_ids[id_offset + 4] = {node_offset + 2, node_offset};
|
||||
}
|
||||
}
|
||||
|
||||
FaceIds face_ids(2 *numX * numY);
|
||||
for (unsigned idx=0; idx<numY; idx++)
|
||||
{
|
||||
for(unsigned jdx=0; jdx<numX; jdx++)
|
||||
{
|
||||
unsigned edge_offset = 5 * (jdx + numX * idx);
|
||||
unsigned face_offset = 2 * (jdx + numX * idx);
|
||||
face_ids[face_offset] = {edge_offset, edge_offset + 1, edge_offset + 4};
|
||||
face_ids[face_offset + 1] = {edge_offset + 4, edge_offset + 2, edge_offset + 3};
|
||||
}
|
||||
}
|
||||
|
||||
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "Node.h"
|
||||
#include "Edge.h"
|
||||
#include "Face.h"
|
||||
|
||||
#include "MeshBuilder.h"
|
||||
#include "AbstractGeometricItem.h"
|
||||
|
@ -16,32 +15,7 @@ class MeshPrimitives
|
|||
{
|
||||
public:
|
||||
|
||||
static std::unique_ptr<TriMesh> build(const Rectangle& rectangle)
|
||||
{
|
||||
const auto bottom_left = rectangle.getLocation();
|
||||
const auto width = rectangle.getWidth();
|
||||
const auto height = rectangle.getHeight();
|
||||
static std::unique_ptr<TriMesh> build(const Rectangle& rectangle);
|
||||
|
||||
VecPoints locations = {
|
||||
bottom_left,
|
||||
Point(bottom_left, width, 0),
|
||||
Point(bottom_left, width, height),
|
||||
Point(bottom_left, 0, height)
|
||||
};
|
||||
|
||||
EdgeIds edge_ids = {
|
||||
{0, 1},
|
||||
{1, 2},
|
||||
{2, 0},
|
||||
{2, 3},
|
||||
{3, 0}
|
||||
};
|
||||
|
||||
FaceIds face_ids = {
|
||||
{0, 1, 2},
|
||||
{2, 3, 4}
|
||||
};
|
||||
|
||||
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
|
||||
}
|
||||
static std::unique_ptr<TriMesh> buildExplodedGrid(unsigned numX, unsigned numY);
|
||||
};
|
||||
|
|
|
@ -27,4 +27,19 @@ void Node::updateIndex(unsigned index)
|
|||
mIndex = index;
|
||||
}
|
||||
|
||||
void Node::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
mVectorAttributes[tag] = values;
|
||||
}
|
||||
|
||||
std::vector<double> Node::getVectorAttribute(const std::string& tag) const
|
||||
{
|
||||
auto iter = mVectorAttributes.find(tag);
|
||||
if (iter != mVectorAttributes.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
#include "Point.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
|
@ -20,7 +25,17 @@ public:
|
|||
return mPoint;
|
||||
}
|
||||
|
||||
void addVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
std::vector<double> getVectorAttribute(const std::string& tag) const;
|
||||
|
||||
void scale(double x, double y)
|
||||
{
|
||||
mPoint.scale(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
|
||||
unsigned mIndex{0};
|
||||
Point mPoint;
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class Edge;
|
||||
|
||||
class Face
|
||||
class QuadFace
|
||||
{
|
||||
|
||||
};
|
|
@ -3,10 +3,10 @@
|
|||
#include "Edge.h"
|
||||
|
||||
TriFace::TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id)
|
||||
: mEdge0(edge0),
|
||||
mEdge1(edge1),
|
||||
mEdge2(edge2),
|
||||
mId(id)
|
||||
: AbstractFace(id),
|
||||
mEdge0(edge0),
|
||||
mEdge1(edge1),
|
||||
mEdge2(edge2)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -25,18 +25,3 @@ std::vector<unsigned> TriFace::getNodeIds() const
|
|||
{
|
||||
return {mEdge0->getNode0Id(), mEdge0->getNode1Id(), mEdge1->getNode1Id()};
|
||||
}
|
||||
|
||||
void TriFace::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
|
||||
{
|
||||
mVectorAttributes[tag] = values;
|
||||
}
|
||||
|
||||
std::vector<double> TriFace::getVectorAttribute(const std::string& tag) const
|
||||
{
|
||||
auto iter = mVectorAttributes.find(tag);
|
||||
if (iter != mVectorAttributes.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -1,29 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include "AbstractFace.h"
|
||||
|
||||
class Edge;
|
||||
|
||||
class TriFace
|
||||
class TriFace : public AbstractFace
|
||||
{
|
||||
public:
|
||||
TriFace(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0);
|
||||
|
||||
~TriFace();
|
||||
|
||||
std::vector<unsigned> getNodeIds() const override;
|
||||
|
||||
static std::unique_ptr<TriFace> Create(Edge* edge0, Edge* edge1, Edge* edge2, unsigned id=0);
|
||||
|
||||
std::vector<unsigned> getNodeIds() const;
|
||||
|
||||
void addVectorAttribute(const std::string& tag, const std::vector<double>& values);
|
||||
|
||||
std::vector<double> getVectorAttribute(const std::string& tag) const;
|
||||
|
||||
private:
|
||||
unsigned mId{0};
|
||||
std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
|
||||
|
||||
Edge* mEdge0{nullptr};
|
||||
Edge* mEdge1{nullptr};
|
||||
Edge* mEdge2{nullptr};
|
||||
|
|
|
@ -49,34 +49,3 @@ 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 {};
|
||||
}
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
#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>;
|
||||
|
||||
|
@ -29,44 +23,18 @@ public:
|
|||
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue