Lagrange
Loading...
Searching...
No Matches
generate_rounded_plane.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_plane.h>
16#endif
17
18#include <lagrange/SurfaceMesh.h>
19#include <lagrange/primitive/PrimitiveOptions.h>
20
21namespace lagrange::primitive {
22
25
30{
31 using Scalar = PrimitiveOptions::Scalar;
32 using Index = size_t;
33
36 Scalar width = 1;
37
40 Scalar height = 1;
41
45 Scalar bevel_radius = 0;
46
49 Index width_segments = 1;
50
53 Index height_segments = 1;
54
59 Index bevel_segments = 8;
60
62 std::array<Scalar, 3> normal = {0, 0, 1};
63
74 {
75 width = std::max(width, static_cast<Scalar>(0));
76 height = std::max(height, static_cast<Scalar>(0));
77 bevel_radius = std::min(
78 std::max(bevel_radius, static_cast<Scalar>(0)),
79 (std::min(width, height)) / static_cast<Scalar>(2));
80
81 width_segments = std::max(width_segments, static_cast<Index>(1));
82 height_segments = std::max(height_segments, static_cast<Index>(1));
83
84 if (bevel_radius > this->epsilon) {
85 bevel_segments = std::max(bevel_segments, static_cast<Index>(1));
86 } else {
88 }
89
90 const Scalar l =
91 std::sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]);
92 if (l > this->epsilon) {
93 normal[0] /= l;
94 normal[1] /= l;
95 normal[2] /= l;
96 } else {
97 // Degenerate normal, reset to default
98 normal = {0, 0, 1};
99 }
100 }
101};
102
123template <typename Scalar, typename Index>
124SurfaceMesh<Scalar, Index> generate_rounded_plane(RoundedPlaneOptions settings);
125
127
128} // namespace lagrange::primitive
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
SurfaceMesh< Scalar, Index > generate_rounded_plane(RoundedPlaneOptions settings)
Generate a rounded plane mesh.
Definition generate_rounded_plane.cpp:126
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 plane mesh.
Definition generate_rounded_plane.h:30
void project_to_valid_range()
Clamps all parameters to valid ranges.
Definition generate_rounded_plane.h:73
Index width_segments
Number of subdivisions along the width (X-axis).
Definition generate_rounded_plane.h:49
Index height_segments
Number of subdivisions along the height (Z-axis).
Definition generate_rounded_plane.h:53
Scalar height
Height of the plane along the Z-axis.
Definition generate_rounded_plane.h:40
Scalar width
Width of the plane along the X-axis.
Definition generate_rounded_plane.h:36
Scalar bevel_radius
Radius of the bevel/rounding applied to the plane corners.
Definition generate_rounded_plane.h:45
std::array< Scalar, 3 > normal
Unit normal vector for the plane.
Definition generate_rounded_plane.h:62
Index bevel_segments
Number of subdivisions for the bevel/rounded corners.
Definition generate_rounded_plane.h:59