Lagrange
Loading...
Searching...
No Matches
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_HEADERS
16 #include <lagrange/subdivision/legacy/mesh_subdivision.h>
17#endif
18
19#include <lagrange/subdivision/api.h>
20
21#include <lagrange/SurfaceMesh.h>
22
23#include <optional>
24
25namespace lagrange::subdivision {
26
29
31enum class SchemeType {
32 Bilinear,
36};
37
59
77
81enum class RefinementType {
84
85 // TODO: Implement these. This involves creating a Far::PatchTable, extracting the subdivided
86 // facets, and welding T-junctions...
89 // CurvatureAdaptive,
90
94};
95
106{
107public:
111 enum class SelectionType { All, None, Selected };
112
113public:
119 static InterpolatedAttributes all() { return {SelectionType::All, {}, {}}; }
120
126 static InterpolatedAttributes none() { return {SelectionType::None, {}, {}}; }
127
138 std::vector<AttributeId> smooth,
139 std::vector<AttributeId> linear = {})
140 {
141 return {SelectionType::Selected, std::move(smooth), std::move(linear)};
142 }
143
147 void set_all() { *this = all(); }
148
152 void set_none() { *this = none(); }
153
160 void set_selected(std::vector<AttributeId> smooth, std::vector<AttributeId> linear = {})
161 {
162 selection_type = SelectionType::Selected;
163 smooth_attributes = std::move(smooth);
164 linear_attributes = std::move(linear);
165 }
166
167 // Has to be kept public to use aggregate initialization...
168public:
170 SelectionType selection_type = SelectionType::All;
171
176 std::vector<AttributeId> smooth_attributes;
177
180 std::vector<AttributeId> linear_attributes;
181};
182
185{
189
192 std::optional<SchemeType> scheme;
193
195 unsigned num_levels = 1;
196
199
203
210 std::optional<float> max_edge_length;
211
225 std::optional<float> max_chordal_deviation;
226
230
234
237
239 bool use_limit_surface = false;
240
244
252
253 // TODO: Add face-uniform attributes (i.e. per-facet attributes), e.g. material_id.
254
258
261 std::optional<AttributeId> edge_sharpness_attr;
262
265 std::optional<AttributeId> vertex_sharpness_attr;
266
269 std::optional<AttributeId> face_hole_attr;
270
274
281
290 std::string_view output_limit_normals;
291
300 std::string_view output_limit_tangents;
301
310 std::string_view output_limit_bitangents;
311
315
320 bool validate_topology = false;
321
323};
324
336template <typename Scalar, typename Index>
337LA_SUBDIVISION_API SurfaceMesh<Scalar, Index> subdivide_mesh(
338 const SurfaceMesh<Scalar, Index>& mesh,
339 const SubdivisionOptions& options = {});
340
342
343} // namespace lagrange::subdivision
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
Helper class to select which attributes to interpolate.
Definition mesh_subdivision.h:106
void set_none()
Sets selection to none.
Definition mesh_subdivision.h:152
std::vector< AttributeId > smooth_attributes
List of per-vertex or indexed attributes ids to smoothly interpolate (in OpenSubdiv terms,...
Definition mesh_subdivision.h:176
void set_all()
Sets selection to all.
Definition mesh_subdivision.h:147
std::vector< AttributeId > linear_attributes
List of per-vertex attributes ids to linearly interpolate (in OpenSubdiv terms, this corresponds to "...
Definition mesh_subdivision.h:180
static InterpolatedAttributes selected(std::vector< AttributeId > smooth, std::vector< AttributeId > linear={})
Only interpolate the specified attributes.
Definition mesh_subdivision.h:137
static InterpolatedAttributes all()
Interpolate all compatible attribute.
Definition mesh_subdivision.h:119
SelectionType selection_type
Selection type.
Definition mesh_subdivision.h:170
SelectionType
Selection tag.
Definition mesh_subdivision.h:111
static InterpolatedAttributes none()
Do not interpolate any attribute.
Definition mesh_subdivision.h:126
void set_selected(std::vector< AttributeId > smooth, std::vector< AttributeId > linear={})
Set selection to a specific list of attribute ids.
Definition mesh_subdivision.h:160
FaceVaryingInterpolation
Face-varying Interpolation Rules.
Definition mesh_subdivision.h:69
VertexBoundaryInterpolation
Boundary Interpolation Rules.
Definition mesh_subdivision.h:44
SchemeType
Subdivision scheme.
Definition mesh_subdivision.h:31
RefinementType
Topology refinement method.
Definition mesh_subdivision.h:81
@ CornersPlus2
CornersPlus2 + sharpening of darts and concave corners.
Definition mesh_subdivision.h:73
@ CornersOnly
Linearly interpolate (sharpen or pin) corners only.
Definition mesh_subdivision.h:71
@ None
Smooth everywhere the mesh is smooth.
Definition mesh_subdivision.h:70
@ CornersPlus1
CornersOnly + sharpening of junctions of 3 or more regions.
Definition mesh_subdivision.h:72
@ Boundaries
Linear interpolation along all boundary edges and corners.
Definition mesh_subdivision.h:74
@ All
Linear interpolation everywhere (boundaries and interior)
Definition mesh_subdivision.h:75
@ EdgeOnly
A sequence of boundary vertices defines a smooth curve to which the limit surface along boundary face...
Definition mesh_subdivision.h:53
@ None
No boundary edge interpolation is applied by default; boundary faces are tagged as holes so that the ...
Definition mesh_subdivision.h:49
@ EdgeAndCorner
Similar to edge-only but the smooth curve resulting on the boundary is made to interpolate corner ver...
Definition mesh_subdivision.h:57
@ CatmullClark
Bilinear subdivision scheme.
Definition mesh_subdivision.h:34
@ Loop
Loop is preferred for (and requires) purely triangulated meshes.
Definition mesh_subdivision.h:35
@ EdgeAdaptive
Each facet is subdivided adaptively according to the mesh curvature.
Definition mesh_subdivision.h:93
@ Uniform
Each facet is subdivided a fixed number of time.
Definition mesh_subdivision.h:83
Subdivision surfaces.
Definition compute_sharpness.h:21
Mesh subdivision options.
Definition mesh_subdivision.h:185
std::string_view output_limit_normals
A newly computed per-vertex attribute containing the normals to the limit surface.
Definition mesh_subdivision.h:290
bool preserve_shared_indices
[Adaptive subdivision only] Whether to preserve shared indices when interpolating indexed attributes.
Definition mesh_subdivision.h:280
std::optional< AttributeId > face_hole_attr
Per-face integer attribute denoting face holes.
Definition mesh_subdivision.h:269
std::optional< AttributeId > edge_sharpness_attr
Per-edge scalar attribute denoting edge sharpness.
Definition mesh_subdivision.h:261
unsigned num_levels
Number of subdivision level requested.
Definition mesh_subdivision.h:195
bool validate_topology
Validate topology of the subdivision surface.
Definition mesh_subdivision.h:320
std::optional< float > max_edge_length
Maximum edge length for adaptive tessellation.
Definition mesh_subdivision.h:210
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:310
std::optional< SchemeType > scheme
Subvision scheme.
Definition mesh_subdivision.h:192
VertexBoundaryInterpolation vertex_boundary_interpolation
Vertex boundary interpolation rule.
Definition mesh_subdivision.h:232
std::optional< AttributeId > vertex_sharpness_attr
Per-vertex scalar attribute denoting vertex sharpness (e.g.
Definition mesh_subdivision.h:265
InterpolatedAttributes interpolated_attributes
List of attributes to interpolate.
Definition mesh_subdivision.h:251
RefinementType refinement
How to refine the mesh topology.
Definition mesh_subdivision.h:198
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:300
std::optional< float > max_chordal_deviation
Maximum chordal deviation for adaptive tessellation.
Definition mesh_subdivision.h:225
bool use_limit_surface
Interpolate all data to the limit surface.
Definition mesh_subdivision.h:239
FaceVaryingInterpolation face_varying_interpolation
Face-varying interpolation rule.
Definition mesh_subdivision.h:236