Volume Cartographer 2.27.0
Cone.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cmath>
6#include <cstddef>
7
8#include <opencv2/core.hpp>
9
10#include "ShapePrimitive.hpp"
11
12namespace volcart::shapes
13{
32class Cone : public ShapePrimitive
33{
34public:
35 Cone(int radius = 2, int height = 5, int recursion = 5, bool closed = true)
36 {
37 std::vector<cv::Vec3d> circle_list;
38 cv::Vec3d c_point;
39
40 // add beginning 8 points of circle
41 for (double l = 0.0; l < 2 * M_PI; l += (M_PI / 4)) {
42 c_point[0] = radius * cos(l);
43 c_point[1] = radius * sin(l);
44 c_point[2] = height;
45 circle_list.push_back(c_point);
46 }
47
48 int r = 0;
49 while (r != recursion) {
50 std::vector<cv::Vec3d> loop_list;
51 loop_list = circle_list;
52 circle_list.clear();
53 // number of section to calculate angle at each vertex
54 double theta_inc = (2 * M_PI) / ((r + 2) * 8);
55 double theta = 0.0;
56 for (int p_id = 0; p_id < ((r + 2) * 8); p_id++) {
57
58 // x value that will be on circle
59 c_point[0] = radius * cos(theta);
60 // y value that will be on circle
61 c_point[1] = radius * sin(theta);
62 c_point[2] = height;
63 circle_list.push_back(c_point);
64
65 theta += theta_inc;
66 }
67 r++;
68 }
69
70 // generate the starting vertices
71 // cone point
72 addVertex_(0, 0, 0);
73 // mid point of circle
74 if (closed) {
75 addVertex_(0, 0, height);
76 }
77
78 // generate the circle points
79 for (auto& point : circle_list) {
80 addVertex_(point[0], point[1], point[2]);
81 }
82
83 // generate the cells for faces
84 // Our two "center" points are v_id 0 && 1, so start at 2
85 int B;
86 std::size_t v_id = (closed) ? 2 : 1;
87 for (; v_id < points_.size(); ++v_id) {
88
89 // Handle the last point in the circle
90 if (v_id == points_.size() - 1) {
91 B = (closed) ? 2 : 1;
92 } else {
93 B = v_id + 1;
94 }
95
96 addCell_(B, v_id, 0);
97 if (closed) {
98 addCell_(v_id, B, 1);
99 }
100 }
101
102 } // Constructor
103
104}; // Cone
105} // namespace volcart::shapes
Cone shape.
Definition: Cone.hpp:33
Base class for shape generators.
std::vector< SimpleMesh::Vertex > points_
void addVertex_(double x, double y, double z)
Add a new vertex to the shape.
void addCell_(int v1, int v2, int v3)
Add a new triangular face to the mesh from vertex IDs.
Shape and mesh primitives.