Visual Computing Library
Loading...
Searching...
No Matches
axis.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_MESH_CREATE_AXIS_H
24#define VCL_ALGORITHMS_MESH_CREATE_AXIS_H
25
26#include "cone.h"
27#include "sphere.h"
28
29namespace vcl {
30
31namespace detail {
32
33template<FaceMeshConcept MeshType>
34MeshType createAxisCylinder(double unitLength, bool fromOrigin = false)
35{
36 const double cylLength = fromOrigin ? unitLength : unitLength * 2;
37 const double cylRadius = cylLength * 0.0025;
38
39 const double coneRadius = cylRadius * 10;
40 const double coneLength = cylLength * 0.1;
41
42 const double firstSphereRadius = unitLength * 0.02;
43 const double commonSphereRadius = unitLength * 0.008;
44
45 MeshType cylinder = vcl::createCylinder<MeshType>(cylRadius, cylLength);
46
47 if (fromOrigin) {
48 vcl::translate(cylinder, vcl::Point3d(0, unitLength * 0.5, 0));
49 }
50
51 vcl::updatePerVertexNormals(cylinder);
52
53 return cylinder;
54}
55
56template<FaceMeshConcept MeshType>
57MeshType createAxisConeSpheres(double unitLength, bool fromOrigin = false)
58{
59 const double cylLength = fromOrigin ? unitLength : unitLength * 2;
60 const double cylRadius = cylLength * 0.0025;
61
62 const double coneRadius = cylRadius * 10;
63 const double coneLength = cylLength * 0.1;
64
65 const double firstSphereRadius = unitLength * 0.02;
66 const double commonSphereRadius = unitLength * 0.008;
67
68 MeshType coneSpheres = vcl::createCone<MeshType>(coneRadius, 0, coneLength);
69 double transl = unitLength + (coneLength * 0.5);
70 vcl::translate(coneSpheres, vcl::Point3d(0, transl, 0));
71
72 if (!fromOrigin) {
73 vcl::Sphered s(vcl::Point3d(0, -1, 0), firstSphereRadius);
74 MeshType sp = vcl::createSphere<MeshType>(s);
75 coneSpheres.append(sp);
76 }
77
78 for (uint i = 0; i < 9; ++i) {
79 const double step = unitLength * 0.1;
80 const double x = step + i * step;
81 vcl::Sphered s(vcl::Point3d(0, x, 0), commonSphereRadius);
82 MeshType sp = vcl::createSphere<MeshType>(s);
83 coneSpheres.append(sp);
84 if (!fromOrigin) {
85 s.center().y() = -x;
87 coneSpheres.append(sp);
88 }
89 }
90
91 const double rad = fromOrigin ? firstSphereRadius : commonSphereRadius;
92 vcl::Sphered s = vcl::Sphered(vcl::Point3d(0, 0, 0), rad);
93 MeshType sp = vcl::createSphere<MeshType>(s);
94 coneSpheres.append(sp);
95
96 vcl::updatePerVertexNormals(coneSpheres);
97
98 return coneSpheres;
99}
100
101} // namespace detail
102
103template<FaceMeshConcept MeshType>
104std::pair<MeshType, MeshType> createAxisDisjoint(
105 double unitLength = 1,
106 bool fromOrigin = false)
107{
108 return std::make_pair(
109 detail::createAxisCylinder<MeshType>(unitLength, fromOrigin),
110 detail::createAxisConeSpheres<MeshType>(unitLength, fromOrigin));
111}
112
113template<FaceMeshConcept MeshType>
114MeshType createAxis(double unitLength = 1, bool fromOrigin = false)
115{
116 MeshType axis =
117 detail::createAxisCylinder<MeshType>(unitLength, fromOrigin);
118
119 axis.append(
120 detail::createAxisConeSpheres<MeshType>(unitLength, fromOrigin));
121
122 return axis;
123}
124
125} // namespace vcl
126
127#endif // VCL_ALGORITHMS_MESH_CREATE_AXIS_H
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:58
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43