84 lines
3.3 KiB
C++
Executable File
84 lines
3.3 KiB
C++
Executable File
#include "generators/geometry_generator.h"
|
|
#include <string>
|
|
#include "simulation/errors.h"
|
|
namespace generator {
|
|
|
|
std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
|
|
const json_path& path_to_geometry) {
|
|
if (parameter.jsonObjectFromBase(
|
|
json_path_append(path_to_geometry, {"Cylinder"}))) {
|
|
#ifdef debug_level2
|
|
DEBUG_LEVEL_2("Creating geometry: cylinder.");
|
|
#endif
|
|
double radius =
|
|
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
path_to_geometry, {"Cylinder", "Radius"})),
|
|
"m");
|
|
double height =
|
|
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
path_to_geometry, {"Cylinder", "Height"})),
|
|
"m");
|
|
#ifdef debug_level3
|
|
DEBUG_LEVEL_3("with radius: " + std::to_string(radius) + " m");
|
|
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
|
|
#endif
|
|
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
|
|
} else if(parameter.jsonObjectFromBase(
|
|
json_path_append(path_to_geometry, {"HalfCylinderWithCone"}))) {
|
|
|
|
#ifdef debug
|
|
DEBUG("Creating geometry: half cylinder with cone.");
|
|
#endif
|
|
double radius =
|
|
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
path_to_geometry, {"HalfCylinderWithCone", "Radius"})),
|
|
"m");
|
|
double heightcylinder =
|
|
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
path_to_geometry, {"HalfCylinderWithCone", "HeightCylinder"})),
|
|
"m");
|
|
double heightcone =
|
|
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
path_to_geometry, {"HalfCylinderWithCone", "HeightCone"})),
|
|
"m");
|
|
double z_frustum =
|
|
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
path_to_geometry, {"HalfCylinderWithCone", "FrustumStartZ"})),
|
|
"m");
|
|
|
|
#ifdef debug
|
|
std::stringstream out;
|
|
out << "height cyl: " << heightcylinder << ", height cone: " << heightcone << ", radius: " << radius << ", zfrustum: " << z_frustum << "\n";
|
|
DEBUG(out.str());
|
|
#endif
|
|
return std::shared_ptr<Geometry>(
|
|
new HalfCylinderWithCone(radius, heightcylinder, heightcone, z_frustum));
|
|
} else {
|
|
ERROR("This geometry is not implemented.");
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<Geometry> buildGeometryIncludingRedirection(
|
|
Parameter& parameter, const json_path& path_to_geometry) {
|
|
if (parameter.jsonObjectFromBase(
|
|
json_path_append(path_to_geometry, {"CreateSameAs"}))) {
|
|
#ifdef debug_level2
|
|
DEBUG_LEVEL_2("Creating geometry: CreateSameAs.");
|
|
#endif
|
|
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
|
json_path_append(path_to_geometry, {"CreateSameAs"})));
|
|
std::stringstream path;
|
|
for (auto& p : path_to_same) {
|
|
path << p << " ";
|
|
}
|
|
#ifdef debug_level3
|
|
DEBUG_LEVEL_3("From path: " + path.str());
|
|
#endif
|
|
return buildGeometryIncludingRedirection(parameter, path_to_same);
|
|
} else {
|
|
return buildGeometry(parameter, path_to_geometry);
|
|
}
|
|
}
|
|
|
|
}; // namespace generator
|