MoCSI API Reference
Loading...
Searching...
No Matches
ShapeBase.h
Go to the documentation of this file.
1#ifndef SHAPE_BASE_H
2#define SHAPE_BASE_H
3
4#include <memory>
5#include <string>
6#include <utility>
7#include <valarray>
8#include <vector>
9
14template <typename T>
16{
17 protected:
18 std::vector<std::vector<T>> m_vertex_list{}; // List of vertex coordinates (n x 3)
19 std::vector<std::vector<int>>
20 m_face_list; // List of faces, returning their corresponding vertices (n x X), X
21 // depending on face type (tris: X = 3, quads: X = 4...)
22 std::vector<std::vector<T>> m_face_normals{}; // List of face normals (n x 3)
23 std::vector<T> m_face_areas{}; // List of areas of the faces
24
25 public:
26 const std::vector<std::vector<T>>& getVertices() const { return m_vertex_list; }
27 const std::vector<std::vector<int>>& getFaces() const { return m_face_list; }
28 const std::vector<std::vector<T>>& getNormals() const { return m_face_normals; }
29 const std::vector<T>& getAreas() const { return m_face_areas; }
30 int getNumberOfFacets() const { return m_face_areas.size(); }
31
32 void setVertices(const std::vector<std::vector<T>> vertex_list)
33 {
35 }
36 void setFaces(const std::vector<std::vector<int>>& face_list) { m_face_list = face_list; }
37 void setNormals(const std::vector<std::vector<T>> face_normals)
38 {
40 }
41 void setAreas(const std::vector<T> face_areas) { m_face_areas = face_areas; }
42
43 void validityCheck();
44
45 ShapeBase();
46 ShapeBase(std::vector<std::vector<T>> vertex_list, std::vector<std::vector<int>> face_list,
47 std::vector<std::vector<T>> face_normals, std::vector<T> face_areas);
48 ~ShapeBase() = default;
49};
50
54template <typename T>
58
67template <typename T>
68ShapeBase<T>::ShapeBase(std::vector<std::vector<T>> vertex_list,
69 std::vector<std::vector<int>> face_list,
70 std::vector<std::vector<T>> face_normals, std::vector<T> face_areas)
71 : m_vertex_list{vertex_list},
72 m_face_list{std::move(face_list)},
73 m_face_normals{face_normals},
74 m_face_areas{face_areas}
75{
76}
77
82template <typename T>
84{
85 // Check if the three vectors that are required to have identical length do infact have
86 // identical length
87 bool equal_size{m_face_list.size() == m_face_normals.size()
88 && m_face_normals.size() == m_face_areas.size()
89 and m_face_areas.size() == m_face_list.size()};
90 // Check if the mesh consists of at least one facet (at least one "Tri")
91 bool valid_length{m_vertex_list.size() > 3 && !m_face_list.empty()};
92 if (!equal_size && !valid_length)
93 {
94 std::string error_msg{
95 "The supplied lists for the normals, faces and areas of lengths "
96 + std::to_string(m_face_normals.size()) + ", " + std::to_string(m_face_list.size())
97 + ", " + std::to_string(m_face_areas.size())
98 + " are not matching in length and the mesh does not contain a valid facet!\n"};
99 throw std::runtime_error(error_msg.c_str());
100 }
101 if (!equal_size)
102 {
103 std::string error_msg{
104 "The supplied lists for the normals, faces and areas of lengths "
105 + std::to_string(m_face_normals.size()) + ", " + std::to_string(m_face_list.size())
106 + ", " + std::to_string(m_face_areas.size()) + " are not matching in length!\n"};
107 throw std::runtime_error(error_msg.c_str());
108 }
109 else if (!valid_length)
110 {
111 throw std::runtime_error("The mesh does not contain a valid facet!\n");
112 };
113}
114
115#endif
Error class to throw when a module chain has circular or missing dependencies. Inherits from std::exc...
Definition ChainManager.h:28
Managing class for all types of meshes. Provides the interface to all the needed data when working wi...
Definition ShapeBase.h:16
const std::vector< std::vector< T > > & getVertices() const
Definition ShapeBase.h:26
const std::vector< std::vector< T > > & getNormals() const
Definition ShapeBase.h:28
std::vector< T > m_face_areas
Definition ShapeBase.h:23
const std::vector< std::vector< int > > & getFaces() const
Definition ShapeBase.h:27
std::vector< std::vector< T > > m_vertex_list
Definition ShapeBase.h:18
void setFaces(const std::vector< std::vector< int > > &face_list)
Definition ShapeBase.h:36
void setAreas(const std::vector< T > face_areas)
Definition ShapeBase.h:41
std::vector< std::vector< T > > m_face_normals
Definition ShapeBase.h:22
ShapeBase()
Constructor for an empty ShapeBase object.
Definition ShapeBase.h:55
~ShapeBase()=default
const std::vector< T > & getAreas() const
Definition ShapeBase.h:29
std::vector< std::vector< int > > m_face_list
Definition ShapeBase.h:20
void setVertices(const std::vector< std::vector< T > > vertex_list)
Definition ShapeBase.h:32
int getNumberOfFacets() const
Definition ShapeBase.h:30
void validityCheck()
Checks whether the mesh has at least one valid facet and whether all vectors of expected equal length...
Definition ShapeBase.h:83
void setNormals(const std::vector< std::vector< T > > face_normals)
Definition ShapeBase.h:37