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_HEADERS
15 #include <lagrange/primitive/legacy/generate_rounded_plane.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
32{
33 using Scalar = PrimitiveOptions::Scalar;
34 using Index = size_t;
35
38 Scalar width = 1;
39
42 Scalar height = 1;
43
47 Scalar bevel_radius = 0;
48
51 Index width_segments = 1;
52
55 Index height_segments = 1;
56
61 Index bevel_segments = 8;
62
64 std::array<Scalar, 3> normal = {0, 0, 1};
65
76 {
77 width = std::max(width, static_cast<Scalar>(0));
78 height = std::max(height, static_cast<Scalar>(0));
79 bevel_radius = std::min(
80 std::max(bevel_radius, static_cast<Scalar>(0)),
81 (std::min(width, height)) / static_cast<Scalar>(2));
82
83 width_segments = std::max(width_segments, static_cast<Index>(1));
84 height_segments = std::max(height_segments, static_cast<Index>(1));
85
86 if (bevel_radius > this->epsilon) {
87 bevel_segments = std::max(bevel_segments, static_cast<Index>(1));
88 } else {
90 }
91
92 const Scalar l =
93 std::sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]);
94 if (l > this->epsilon) {
95 normal[0] /= l;
96 normal[1] /= l;
97 normal[2] /= l;
98 } else {
99 // Degenerate normal, reset to default
100 normal = {0, 0, 1};
101 }
102 }
103};
104
125template <typename Scalar, typename Index>
126LA_PRIMITIVE_API SurfaceMesh<Scalar, Index> generate_rounded_plane(RoundedPlaneOptions settings);
127
129
130} // namespace lagrange::primitive
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
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:32
void project_to_valid_range()
Clamps all parameters to valid ranges.
Definition generate_rounded_plane.h:75
Index width_segments
Number of subdivisions along the width (X-axis).
Definition generate_rounded_plane.h:51
Index height_segments
Number of subdivisions along the height (Z-axis).
Definition generate_rounded_plane.h:55
Scalar height
Height of the plane along the Z-axis.
Definition generate_rounded_plane.h:42
Scalar width
Width of the plane along the X-axis.
Definition generate_rounded_plane.h:38
Scalar bevel_radius
Radius of the bevel/rounding applied to the plane corners.
Definition generate_rounded_plane.h:47
std::array< Scalar, 3 > normal
Unit normal vector for the plane.
Definition generate_rounded_plane.h:64
Index bevel_segments
Number of subdivisions for the bevel/rounded corners.
Definition generate_rounded_plane.h:61