Lagrange
Loading...
Searching...
No Matches
generate_rounded_cube.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_cube.h>
16#endif
17
18#include <lagrange/SurfaceMesh.h>
19#include <lagrange/primitive/PrimitiveOptions.h>
20
21namespace lagrange::primitive {
22
25
35{
36 using Scalar = PrimitiveOptions::Scalar;
37 using Index = size_t;
38
40 Scalar width = 1;
41
43 Scalar height = 1;
44
46 Scalar depth = 1;
47
49 Index width_segments = 1;
50
52 Index height_segments = 1;
53
55 Index depth_segments = 1;
56
59 Scalar bevel_radius = 0;
60
63 Index bevel_segments = 8;
64
75 {
76 width = std::max(width, Scalar(0));
77 height = std::max(height, Scalar(0));
78 depth = std::max(depth, Scalar(0));
79
80 width_segments = std::max(width_segments, Index(1));
81 height_segments = std::max(height_segments, Index(1));
82 depth_segments = std::max(depth_segments, Index(1));
83
84 bevel_radius = std::max(bevel_radius, Scalar(0));
85 Scalar max_acceptable_radius = (std::min(std::min(width, height), depth)) / 2;
86 bevel_radius = std::min(bevel_radius, max_acceptable_radius);
87
88 if (bevel_radius > this->epsilon) {
89 bevel_segments = std::max(bevel_segments, Index(1));
90 } else {
92 }
93 }
94};
95
117template <typename Scalar, typename Index>
118SurfaceMesh<Scalar, Index> generate_rounded_cube(RoundedCubeOptions setting);
119
121
122} // namespace lagrange::primitive
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
SurfaceMesh< Scalar, Index > generate_rounded_cube(RoundedCubeOptions setting)
Generate a rounded cube mesh.
Definition generate_rounded_cube.cpp:1070
Common settings shared by all primitives.
Definition PrimitiveOptions.h:28
Scalar epsilon
Numerical tolerance used for comparing Scalar values.
Definition PrimitiveOptions.h:76
Options for generating a rounded cube mesh.
Definition generate_rounded_cube.h:35
void project_to_valid_range()
Clamps all parameters to valid ranges.
Definition generate_rounded_cube.h:74
Index width_segments
Number of segments along the width (X-axis)
Definition generate_rounded_cube.h:49
Index depth_segments
Number of segments along the depth (Z-axis)
Definition generate_rounded_cube.h:55
Index height_segments
Number of segments along the height (Y-axis)
Definition generate_rounded_cube.h:52
Scalar height
Height of the cube along the Y-axis.
Definition generate_rounded_cube.h:43
Scalar width
Width of the cube along the X-axis.
Definition generate_rounded_cube.h:40
Scalar bevel_radius
Radius of the bevel/rounding applied to cube edges A value of 0 creates a regular cube with sharp edg...
Definition generate_rounded_cube.h:59
Scalar depth
Depth of the cube along the Z-axis.
Definition generate_rounded_cube.h:46
Index bevel_segments
Number of segments used to approximate each rounded edge Higher values create smoother rounded edges ...
Definition generate_rounded_cube.h:63