Lagrange
Loading...
Searching...
No Matches
generate_rounded_cone.h
1/*
2 * Copyright 2019 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
15 #include <lagrange/primitive/legacy/generate_rounded_cone.h>
16#endif
17
18#include <lagrange/SurfaceMesh.h>
19#include <lagrange/internal/constants.h>
20#include <lagrange/primitive/PrimitiveOptions.h>
21
22namespace lagrange::primitive {
23
26
31{
32 using Scalar = PrimitiveOptions::Scalar;
33 using Index = size_t;
34
36 Scalar radius_top = 0;
37
39 Scalar radius_bottom = 1;
40
42 Scalar height = 1;
43
46 Scalar bevel_radius_top = 0;
47
51
54 Index radial_sections = 32;
55
59
63
65 Index side_segments = 1;
66
68 Index top_segments = 1;
69
71 Index bottom_segments = 1;
72
76
79 Scalar end_sweep_angle = static_cast<Scalar>(2 * lagrange::internal::pi);
80
94 {
95 radius_top = std::max(radius_top, Scalar(0));
96 radius_bottom = std::max(radius_bottom, Scalar(0));
97 height = std::max(height, Scalar(0));
98
99 auto [max_bevel_top, max_bevel_bottom] = get_max_cone_bevel();
100 bevel_radius_top = std::clamp(bevel_radius_top, Scalar(0), max_bevel_top);
101 bevel_radius_bottom = std::clamp(bevel_radius_bottom, Scalar(0), max_bevel_bottom);
102
103 radial_sections = std::max(radial_sections, Index(1));
104 bevel_segments_top = std::max(bevel_segments_top, Index(1));
105 bevel_segments_bottom = std::max(bevel_segments_bottom, Index(1));
106
107 side_segments = std::max(side_segments, Index(1));
108 top_segments = std::max(top_segments, Index(1));
109 bottom_segments = std::max(bottom_segments, Index(1));
110 }
111
126 std::pair<Scalar, Scalar> get_max_cone_bevel() const
127 {
128 // angle between the cone slope and the vertical line (0 for cylinders)
129 Scalar psi = std::atan2((radius_top - radius_bottom), height);
130 Scalar a1 = (Scalar)(lagrange::internal::pi_2 + psi) * .5f;
131 Scalar a2 = (Scalar)(lagrange::internal::pi_2 - psi) * .5f;
132
133 Scalar max_bevel_bottom =
134 radius_bottom * std::tan(a1); // max bevel against radius and slope
135 max_bevel_bottom = std::min(height * .5f, max_bevel_bottom); // also check against height
136 max_bevel_bottom = std::max(max_bevel_bottom, 0.f);
137
138
139 Scalar max_bevel_top =
140 radius_top * std::tan(a2); // max bevel against other radius and inverse slope
141 max_bevel_top = std::min(height * .5f, max_bevel_top); // also check against height
142 max_bevel_top = std::max(max_bevel_top, 0.f);
143
144 return std::pair<Scalar, Scalar>{max_bevel_top, max_bevel_bottom};
145 }
146};
147
175template <typename Scalar, typename Index>
176SurfaceMesh<Scalar, Index> generate_rounded_cone(RoundedConeOptions setting);
177
179
180} // namespace lagrange::primitive
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
SurfaceMesh< Scalar, Index > generate_rounded_cone(RoundedConeOptions setting)
Generate a rounded cone mesh.
Definition generate_rounded_cone.cpp:149
Common settings shared by all primitives.
Definition PrimitiveOptions.h:28
Options for generating a rounded cone mesh.
Definition generate_rounded_cone.h:31
void project_to_valid_range()
Clamps all parameters to valid ranges.
Definition generate_rounded_cone.h:93
Scalar radius_bottom
Radius of the cone at the bottom.
Definition generate_rounded_cone.h:39
Scalar start_sweep_angle
Starting angle for partial cone generation (in radians).
Definition generate_rounded_cone.h:75
Index bevel_segments_top
Number of segments used to approximate the top rounded edge.
Definition generate_rounded_cone.h:58
Index top_segments
Number of radial segments on the top cap when radius_top > 0.
Definition generate_rounded_cone.h:68
Scalar radius_top
Radius of the cone at the top. Set to 0 for a traditional cone.
Definition generate_rounded_cone.h:36
Scalar height
Height of the cone along the Y-axis.
Definition generate_rounded_cone.h:42
Index bevel_segments_bottom
Number of segments used to approximate the bottom rounded edge.
Definition generate_rounded_cone.h:62
Scalar bevel_radius_top
Radius of the bevel/rounding applied to the top edge.
Definition generate_rounded_cone.h:46
std::pair< Scalar, Scalar > get_max_cone_bevel() const
Computes the maximum allowable bevel radii for the cone geometry.
Definition generate_rounded_cone.h:126
Index side_segments
Number of segments along the cone's side surface (height direction).
Definition generate_rounded_cone.h:65
Scalar bevel_radius_bottom
Radius of the bevel/rounding applied to the bottom edge.
Definition generate_rounded_cone.h:50
Index radial_sections
Number of radial subdivisions around the cone circumference.
Definition generate_rounded_cone.h:54
Index bottom_segments
Number of radial segments on the bottom cap when radius_bottom > 0.
Definition generate_rounded_cone.h:71
Scalar end_sweep_angle
Ending angle for partial cone generation (in radians).
Definition generate_rounded_cone.h:79