Lagrange
mesh_subdivision.h
1/*
2 * Copyright 2020 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
13#pragma once
14
15#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
16 #include <lagrange/subdivision/legacy/mesh_subdivision.h>
17#endif
18
19#include <lagrange/SurfaceMesh.h>
20
21#include <optional>
22
23namespace lagrange::subdivision {
24
27
29enum class SchemeType {
30 Bilinear,
33 Loop,
34};
35
47 None,
48
52
56};
57
68 None,
73 All,
74};
75
79enum class RefinementType {
81 Uniform,
82
83 // TODO: Implement these. This involves creating a Far::PatchTable, extracting the subdivided
84 // facets, and welding T-junctions...
87 // CurvatureAdaptive,
88
92};
93
104{
105public:
109 enum class SelectionType { All, None, Selected };
110
111public:
117 static InterpolatedAttributes all() { return {SelectionType::All, {}, {}}; }
118
124 static InterpolatedAttributes none() { return {SelectionType::None, {}, {}}; }
125
136 std::vector<AttributeId> smooth,
137 std::vector<AttributeId> linear = {})
138 {
139 return {SelectionType::Selected, std::move(smooth), std::move(linear)};
140 }
141
145 void set_all() { *this = all(); }
146
150 void set_none() { *this = none(); }
151
158 void set_selected(std::vector<AttributeId> smooth, std::vector<AttributeId> linear = {})
159 {
160 selection_type = SelectionType::Selected;
161 smooth_attributes = std::move(smooth);
162 linear_attributes = std::move(linear);
163 }
164
165 // Has to be kept public to use aggregate initialization...
166public:
168 SelectionType selection_type = SelectionType::All;
169
174 std::vector<AttributeId> smooth_attributes;
175
178 std::vector<AttributeId> linear_attributes;
179};
180
183{
187
190 std::optional<SchemeType> scheme;
191
193 unsigned num_levels = 1;
194
197
201
204 std::optional<float> max_edge_length;
205
209
213
216
218 bool use_limit_surface = false;
219
223
231
232 // TODO: Add face-uniform attributes (i.e. per-facet attributes), e.g. material_id.
233
237
240 std::optional<AttributeId> edge_sharpness_attr;
241
244 std::optional<AttributeId> vertex_sharpness_attr;
245
248 std::optional<AttributeId> face_hole_attr;
249
253
260
269 std::string_view output_limit_normals;
270
279 std::string_view output_limit_tangents;
280
289 std::string_view output_limit_bitangents;
290
294
299 bool validate_topology = false;
300
302};
303
315template <typename Scalar, typename Index>
316SurfaceMesh<Scalar, Index> subdivide_mesh(
317 const SurfaceMesh<Scalar, Index>& mesh,
318 const SubdivisionOptions& options = {});
319
321
322} // namespace lagrange::subdivision
Helper class to select which attributes to interpolate.
Definition: mesh_subdivision.h:104
void set_none()
Sets selection to none.
Definition: mesh_subdivision.h:150
std::vector< AttributeId > smooth_attributes
List of per-vertex or indexed attributes ids to smoothly interpolate (in OpenSubdiv terms,...
Definition: mesh_subdivision.h:174
void set_all()
Sets selection to all.
Definition: mesh_subdivision.h:145
std::vector< AttributeId > linear_attributes
List of per-vertex attributes ids to linearly interpolate (in OpenSubdiv terms, this corresponds to "...
Definition: mesh_subdivision.h:178
static InterpolatedAttributes selected(std::vector< AttributeId > smooth, std::vector< AttributeId > linear={})
Only interpolate the specified attributes.
Definition: mesh_subdivision.h:135
static InterpolatedAttributes all()
Interpolate all compatible attribute.
Definition: mesh_subdivision.h:117
SelectionType selection_type
Selection type.
Definition: mesh_subdivision.h:168
SelectionType
Selection tag.
Definition: mesh_subdivision.h:109
static InterpolatedAttributes none()
Do not interpolate any attribute.
Definition: mesh_subdivision.h:124
void set_selected(std::vector< AttributeId > smooth, std::vector< AttributeId > linear={})
Set selection to a specific list of attribte ids.
Definition: mesh_subdivision.h:158
@ Uniform
Incident face normals have uniform influence on vertex normal.
FaceVaryingInterpolation
Face-varying Interpolation Rules.
Definition: mesh_subdivision.h:67
VertexBoundaryInterpolation
Boundary Interpolation Rules.
Definition: mesh_subdivision.h:42
SchemeType
Subdivision scheme.
Definition: mesh_subdivision.h:29
RefinementType
Topology refinement method.
Definition: mesh_subdivision.h:79
@ CornersPlus2
CornersPlus2 + sharpening of darts and concave corners.
@ CornersOnly
Linearly interpolate (sharpen or pin) corners only.
@ None
Smooth everywhere the mesh is smooth.
@ CornersPlus1
CornersOnly + sharpening of junctions of 3 or more regions.
@ Boundaries
Linear interpolation along all boundary edges and corners.
@ All
Linear interpolation everywhere (boundaries and interior)
@ EdgeOnly
A sequence of boundary vertices defines a smooth curve to which the limit surface along boundary face...
@ EdgeAndCorner
Similar to edge-only but the smooth curve resulting on the boundary is made to interpolate corner ver...
@ CatmullClark
Bilinear subdivision scheme.
@ Loop
Loop is preferred for (and requires) purely triangulated meshes.
@ EdgeAdaptive
Each facet is subdivided adaptively according to the mesh curvature.
@ Uniform
Each facet is subdivided a fixed number of time.
Subdivision surfaces.
Definition: mesh_subdivision.h:32
@ None
Do not reorder mesh vertices/facets.
Mesh subdivision options.
Definition: mesh_subdivision.h:183
std::string_view output_limit_normals
A newly computed per-vertex attribute containing the normals to the limit surface.
Definition: mesh_subdivision.h:269
bool preserve_shared_indices
[Adaptive subdivision only] Whether to preserve shared indices when interpolating indexed attributes.
Definition: mesh_subdivision.h:259
std::optional< AttributeId > face_hole_attr
Per-face integer attribute denoting face holes.
Definition: mesh_subdivision.h:248
std::optional< AttributeId > edge_sharpness_attr
Per-edge scalar attribute denoting edge sharpness.
Definition: mesh_subdivision.h:240
unsigned num_levels
Number of subdivision level requested.
Definition: mesh_subdivision.h:193
bool validate_topology
Validate topology of the subdivision surface.
Definition: mesh_subdivision.h:299
std::optional< float > max_edge_length
Maximum edge length for adaptive tessellation.
Definition: mesh_subdivision.h:204
std::string_view output_limit_bitangents
A newly computed per-vertex attribute containing the bitangents (second derivative) to the limit surf...
Definition: mesh_subdivision.h:289
std::optional< SchemeType > scheme
Subvision scheme.
Definition: mesh_subdivision.h:190
VertexBoundaryInterpolation vertex_boundary_interpolation
Vertex boundary interpolation rule.
Definition: mesh_subdivision.h:211
std::optional< AttributeId > vertex_sharpness_attr
Per-vertex scalar attribute denoting vertex sharpness (e.g.
Definition: mesh_subdivision.h:244
InterpolatedAttributes interpolated_attributes
List of attributes to interpolate.
Definition: mesh_subdivision.h:230
RefinementType refinement
How to refine the mesh topology.
Definition: mesh_subdivision.h:196
std::string_view output_limit_tangents
A newly computed per-vertex attribute containing the tangents (first derivatives) to the limit surfac...
Definition: mesh_subdivision.h:279
bool use_limit_surface
Interpolate all data to the limit surface.
Definition: mesh_subdivision.h:218
FaceVaryingInterpolation face_varying_interpolation
Face-varying interpolation rule.
Definition: mesh_subdivision.h:215