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 m_simulation_shape->validityCheck();
110}
111
116template <typename T>
118{
119// Currently only VTK loading supported
120#ifdef VTK_PRESENT
121 VtkRayCasting vtk_shape_loader(m_shape_file_path.c_str(), false);
122
123 m_simulation_shape->setVertices(vtk_shape_loader.getVertices());
124 m_simulation_shape->setFaces(vtk_shape_loader.getFaces());
125 m_simulation_shape->setNormals(vtk_shape_loader.getNormals());
126 m_simulation_shape->setAreas(vtk_shape_loader.getAreas());
127
128 m_simulation_shape->validityCheck();
129 return;
130#endif
131 {
132 throw std::runtime_error(
133 "Selected shape model is not supported. Check the options and if you are certain it "
134 "should be available, check that third party libraries are linked correctly.");
135 }
136}
137
138#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:35
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:92
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