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_HEADERS
15 #include <lagrange/primitive/legacy/generate_rounded_cone.h>
16#endif
17
18#include <lagrange/primitive/api.h>
19
20#include <lagrange/SurfaceMesh.h>
21#include <lagrange/internal/constants.h>
22#include <lagrange/primitive/PrimitiveOptions.h>
23
24namespace lagrange::primitive {
25
28
33{
34 using Scalar = PrimitiveOptions::Scalar;
35 using Index = size_t;
36
38 Scalar radius_top = 0;
39
41 Scalar radius_bottom = 1;
42
44 Scalar height = 1;
45
48 Scalar bevel_radius_top = 0;
49
53
56 Index radial_sections = 32;
57
61
65
67 Index side_segments = 1;
68
70 Index top_segments = 1;
71
73 Index bottom_segments = 1;
74
78
81 Scalar end_sweep_angle = static_cast<Scalar>(2 * lagrange::internal::pi);
82
96 {
97 radius_top = std::max(radius_top, Scalar(0));
98 radius_bottom = std::max(radius_bottom, Scalar(0));
99 height = std::max(height, Scalar(0));
100
101 auto [max_bevel_top, max_bevel_bottom] = get_max_cone_bevel();
102 bevel_radius_top = std::clamp(bevel_radius_top, Scalar(0), max_bevel_top);
103 bevel_radius_bottom = std::clamp(bevel_radius_bottom, Scalar(0), max_bevel_bottom);
104
105 radial_sections = std::max(radial_sections, Index(1));
106 bevel_segments_top = std::max(bevel_segments_top, Index(1));
107 bevel_segments_bottom = std::max(bevel_segments_bottom, Index(1));
108
109 side_segments = std::max(side_segments, Index(1));
110 top_segments = std::max(top_segments, Index(1));
111 bottom_segments = std::max(bottom_segments, Index(1));
112 }
113
128 std::pair<Scalar, Scalar> get_max_cone_bevel() const
129 {
130 // angle between the cone slope and the vertical line (0 for cylinders)
131 Scalar psi = std::atan2((radius_top - radius_bottom), height);
132 Scalar a1 = (Scalar)(lagrange::internal::pi_2 + psi) * .5f;
133 Scalar a2 = (Scalar)(lagrange::internal::pi_2 - psi) * .5f;
134
135 Scalar max_bevel_bottom =
136 radius_bottom * std::tan(a1); // max bevel against radius and slope
137 max_bevel_bottom = std::min(height * .5f, max_bevel_bottom); // also check against height
138 max_bevel_bottom = std::max(max_bevel_bottom, 0.f);
139
140
141 Scalar max_bevel_top =
142 radius_top * std::tan(a2); // max bevel against other radius and inverse slope
143 max_bevel_top = std::min(height * .5f, max_bevel_top); // also check against height
144 max_bevel_top = std::max(max_bevel_top, 0.f);
145
146 return std::pair<Scalar, Scalar>{max_bevel_top, max_bevel_bottom};
147 }
148};
149
177template <typename Scalar, typename Index>
178LA_PRIMITIVE_API SurfaceMesh<Scalar, Index> generate_rounded_cone(RoundedConeOptions setting);
179
181
182} // namespace lagrange::primitive
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
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:33
void project_to_valid_range()
Clamps all parameters to valid ranges.
Definition generate_rounded_cone.h:95
Scalar radius_bottom
Radius of the cone at the bottom.
Definition generate_rounded_cone.h:41
Scalar start_sweep_angle
Starting angle for partial cone generation (in radians).
Definition generate_rounded_cone.h:77
Index bevel_segments_top
Number of segments used to approximate the top rounded edge.
Definition generate_rounded_cone.h:60
Index top_segments
Number of radial segments on the top cap when radius_top > 0.
Definition generate_rounded_cone.h:70
Scalar radius_top
Radius of the cone at the top. Set to 0 for a traditional cone.
Definition generate_rounded_cone.h:38
Scalar height
Height of the cone along the Y-axis.
Definition generate_rounded_cone.h:44
Index bevel_segments_bottom
Number of segments used to approximate the bottom rounded edge.
Definition generate_rounded_cone.h:64
Scalar bevel_radius_top
Radius of the bevel/rounding applied to the top edge.
Definition generate_rounded_cone.h:48
std::pair< Scalar, Scalar > get_max_cone_bevel() const
Computes the maximum allowable bevel radii for the cone geometry.
Definition generate_rounded_cone.h:128
Index side_segments
Number of segments along the cone's side surface (height direction).
Definition generate_rounded_cone.h:67
Scalar bevel_radius_bottom
Radius of the bevel/rounding applied to the bottom edge.
Definition generate_rounded_cone.h:52
Index radial_sections
Number of radial subdivisions around the cone circumference.
Definition generate_rounded_cone.h:56
Index bottom_segments
Number of radial segments on the bottom cap when radius_bottom > 0.
Definition generate_rounded_cone.h:73
Scalar end_sweep_angle
Ending angle for partial cone generation (in radians).
Definition generate_rounded_cone.h:81