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_HEADERS
15 #include <lagrange/primitive/legacy/generate_rounded_cube.h>
16#endif
17
18#include <lagrange/primitive/api.h>
19
20#include <lagrange/SurfaceMesh.h>
21#include <lagrange/primitive/PrimitiveOptions.h>
22
23namespace lagrange::primitive {
24
27
37{
38 using Scalar = PrimitiveOptions::Scalar;
39 using Index = size_t;
40
42 Scalar width = 1;
43
45 Scalar height = 1;
46
48 Scalar depth = 1;
49
51 Index width_segments = 1;
52
54 Index height_segments = 1;
55
57 Index depth_segments = 1;
58
61 Scalar bevel_radius = 0;
62
65 Index bevel_segments = 8;
66
77 {
78 width = std::max(width, Scalar(0));
79 height = std::max(height, Scalar(0));
80 depth = std::max(depth, Scalar(0));
81
82 width_segments = std::max(width_segments, Index(1));
83 height_segments = std::max(height_segments, Index(1));
84 depth_segments = std::max(depth_segments, Index(1));
85
86 bevel_radius = std::max(bevel_radius, Scalar(0));
87 Scalar max_acceptable_radius = (std::min(std::min(width, height), depth)) / 2;
88 bevel_radius = std::min(bevel_radius, max_acceptable_radius);
89
90 if (bevel_radius > this->epsilon) {
91 bevel_segments = std::max(bevel_segments, Index(1));
92 } else {
94 }
95 }
96};
97
119template <typename Scalar, typename Index>
120LA_PRIMITIVE_API SurfaceMesh<Scalar, Index> generate_rounded_cube(RoundedCubeOptions setting);
121
123
124} // namespace lagrange::primitive
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
SurfaceMesh< Scalar, Index > generate_rounded_cube(RoundedCubeOptions setting)
Generate a rounded cube mesh.
Definition generate_rounded_cube.cpp:1071
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:37
void project_to_valid_range()
Clamps all parameters to valid ranges.
Definition generate_rounded_cube.h:76
Index width_segments
Number of segments along the width (X-axis)
Definition generate_rounded_cube.h:51
Index depth_segments
Number of segments along the depth (Z-axis)
Definition generate_rounded_cube.h:57
Index height_segments
Number of segments along the height (Y-axis)
Definition generate_rounded_cube.h:54
Scalar height
Height of the cube along the Y-axis.
Definition generate_rounded_cube.h:45
Scalar width
Width of the cube along the X-axis.
Definition generate_rounded_cube.h:42
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:61
Scalar depth
Depth of the cube along the Z-axis.
Definition generate_rounded_cube.h:48
Index bevel_segments
Number of segments used to approximate each rounded edge Higher values create smoother rounded edges ...
Definition generate_rounded_cube.h:65