MoCSI API Reference
Loading...
Searching...
No Matches
ShapeFactory.h
Go to the documentation of this file.
1#ifndef SHAPE_FACTORY_H
2#define SHAPE_FACTORY_H
3
4#include "CoreEnums.h"
5#include "ShapeBase.h"
7
8#if VTK_PRESENT
9#include "VtkRayCasting.h"
10#endif
11
12#include <cmath>
13#include <memory>
14#include <string>
15#include <vector>
16
21template <typename T>
23{
24 private:
25 bool m_shape_file;
26 Dimension m_dimension;
27 std::shared_ptr<ShapeBase<T>> m_simulation_shape{std::make_shared<ShapeBase<T>>()};
28 std::string m_shape_file_path;
29
30 void oneDSingleFacetGenerator();
31 void loadShapeFile();
32 void create();
33
34 public:
35 ShapeFactory(SimulationClassBase<T>* sim, bool shape_file, const std::string& dimension);
36
37 std::shared_ptr<ShapeBase<T>> getShapePtr() { return m_simulation_shape; }
38};
39
48template <typename T>
50 const std::string& dimension)
51 : m_shape_file{shape_file}, m_dimension(setDimension(dimension))
52{
53 std::cout << "[ShapeFactory]: " << shape_file << " " << dimension << "\n";
54 if (m_shape_file)
55 {
56 m_shape_file_path = sim->m_simulation_config.getStringParameters("shape_model_path");
57 }
58 create();
59 sim->m_simulation_config.forceValueOverwrite(
60 "number_of_facets", std::to_string(m_simulation_shape->getNumberOfFacets()));
61}
62
68template <typename T>
70{
71 switch (m_dimension)
72 {
73 case Dimension::OneD:
74 if (!m_shape_file)
75 {
76 oneDSingleFacetGenerator();
77 }
78 else
79 {
80 loadShapeFile();
81 }
82 break;
83 // TwoD and ThreeD always need loadShapeFile
84 default:
85 loadShapeFile();
86 break;
87 }
88}
89
94template <typename T>
96{
97 // Will be replaced with an implementation that allows for arbitraty rotation of the facet.
98 std::vector<std::vector<T>> vertices(
99 {{-0.5, -0.5, 0.0}, {0.5, -0.5, 0.0}, {0.5, 0.5, 0.0}, {-0.5, 0.5, 0.0}});
100 std::vector<std::vector<int>> faces({{0, 1, 2, 3}});
101 std::vector<std::vector<T>> normals({{0.0, 0.0, 1.0}});
102 std::vector<T> areas({1.0});
103
104 m_simulation_shape->setVertices(vertices);
105 m_simulation_shape->setFaces(faces);
106 m_simulation_shape->setNormals(normals);
107 m_simulation_shape->setAreas(areas);
108
109 try
110 {
111 m_simulation_shape->validityCheck();
112 }
113 catch (const std::runtime_error& e)
114 {
115 std::cerr << "[ShapeFactory]: Failed creating the ShapeBase object!\n[ShapeFactory]: "
116 << e.what() << '\n';
117 throw std::runtime_error(
118 static_cast<std::string>(
119 "[ShapeFactory]: Failed creating the ShapeBase object!\n[ShapeFactory]: ")
120 + static_cast<std::string>(e.what()));
121 }
122}
123
128template <typename T>
130{
131// Currently only VTK loading supported
132#ifdef VTK_PRESENT
133 VtkRayCasting vtk_shape_loader(m_shape_file_path.c_str(), false);
134
135 m_simulation_shape->setVertices(vtk_shape_loader.getVertices());
136 m_simulation_shape->setFaces(vtk_shape_loader.getFaces());
137 m_simulation_shape->setNormals(vtk_shape_loader.getNormals());
138 m_simulation_shape->setAreas(vtk_shape_loader.getAreas());
139
140 m_simulation_shape->validityCheck();
141 return;
142#endif
143 {
144 std::cerr
145 << "[ShapeFactory]: Selected shape model is not supported. Check the options and if "
146 "you are certain it "
147 "should be available, check that third party libraries are linked correctly.\n";
148 throw std::runtime_error(static_cast<std::string>(
149 "[ShapeFactory]: Selected shape model is not supported. Check the options and if you "
150 "are certain it "
151 "should be available, check that third party libraries are linked correctly."));
152 }
153}
154
155#endif
Dimension
Definition CoreEnums.h:8
constexpr Dimension setDimension(const std::string &dimension)
Definition CoreEnums.h:14
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:37
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:94
Class that manages the creation of the ShapeBase object, which is used by GridFactory....
Definition ShapeFactory.h:23
ShapeFactory(SimulationClassBase< T > *sim, bool shape_file, const std::string &dimension)
Creator of a ShapeFactory. Invokes creation routine.
Definition ShapeFactory.h:49
std::shared_ptr< ShapeBase< T > > getShapePtr()
Definition ShapeFactory.h:37