Lagrange
Loading...
Searching...
No Matches
smoothing_utils.h
1/*
2 * Copyright 2025 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#include <lagrange/SurfaceMesh.h>
15
16#include <lagrange/solver/DirectSolver.h>
17
18// Include before any ShapeGradientDomain header to override their threadpool implementation.
19#include "ThreadPool.h"
20#define MULTI_THREADING_INCLUDED
21using namespace lagrange::filtering::threadpool;
22
23// clang-format off
24#include <lagrange/utils/warnoff.h>
25#include <Include/PreProcessor.h>
26#include <Include/GradientDomain.h>
27#include <Include/CurvatureMetric.h>
28#include <Misha/Geometry.h>
29#include <Misha/Miscellany.h>
30#include <lagrange/utils/warnon.h>
31// clang-format on
32
33#include <string_view>
34#include <vector>
35
36namespace lagrange::filtering {
37
38namespace {
39
40using namespace MishaK;
41
42// Using `Point` directly leads to ambiguity with Apple Accelerate types.
43template <typename T, unsigned N>
44using Vector = MishaK::Point<T, N>;
45
46// The dimension of the manifold.
47static const unsigned int K = 2;
48
49// The dimension of the space into which the manifold is embedded.
50static const unsigned int Dim = 3;
51
52using Real = double;
53
54using Solver = lagrange::solver::SolverLDLT<Eigen::SparseMatrix<Real>>;
55
56} // namespace
57
61namespace smoothing_utils {
62
71template <typename Scalar, typename Index>
72void get_triangles(
73 const SurfaceMesh<Scalar, Index>& t_mesh,
74 std::vector<SimplexIndex<K, int>>& triangles);
75
86template <typename Scalar, typename Index>
88 const SurfaceMesh<Scalar, Index>& t_mesh,
89 std::vector<Vector<Real, Dim>>& vertices,
90 std::vector<Vector<Real, Dim>>& normals,
91 AttributeId normal_id);
92
101template <typename Scalar, typename Index>
102void set_vertices(SurfaceMesh<Scalar, Index>& mesh, const std::vector<Vector<Real, Dim>>& vertices);
103
125template <typename Scalar, typename Index>
126std::unique_ptr<FEM::RiemannianMesh<Real>> setup_for_smoothing(
127 SurfaceMesh<Scalar, Index>& mesh,
128 SurfaceMesh<Scalar, Index>& _mesh,
129 std::vector<SimplexIndex<K, int>>& triangles,
130 std::vector<Vector<Real, Dim>>& vertices,
131 std::vector<Vector<Real, Dim>>& normals,
132 Solver& solver,
133 Real& original_area);
134
147 FEM::RiemannianMesh<Real>& r_mesh,
148 const std::vector<Vector<Real, Dim>>& vertices,
149 const std::vector<Vector<Real, Dim>>& normals,
150 Real original_area,
151 double curvature_weight,
152 double normal_smoothing_weight,
153 Solver& solver);
154
155} // namespace smoothing_utils
156
157} // namespace lagrange::filtering
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Type alias for one-dimensional column Eigen vectors.
Definition views.h:79
Common utility functions for mesh and attribute smoothing.
Definition smoothing_utils.cpp:41
void get_triangles(const SurfaceMesh< Scalar, Index > &t_mesh, std::vector< SimplexIndex< K, int > > &triangles)
Extract triangles from a mesh.
Definition smoothing_utils.cpp:44
void adjust_metric_for_curvature(FEM::RiemannianMesh< Real > &r_mesh, const std::vector< Vector< Real, Dim > > &vertices, const std::vector< Vector< Real, Dim > > &normals, Real original_area, double curvature_weight, double normal_smoothing_weight, Solver &solver)
Adjust the metric based on curvature.
Definition smoothing_utils.cpp:178
void set_vertices(SurfaceMesh< Scalar, Index > &mesh, const std::vector< Vector< Real, Dim > > &vertices)
Set vertices in a mesh.
Definition smoothing_utils.cpp:94
void get_vertices_and_normals(const SurfaceMesh< Scalar, Index > &t_mesh, std::vector< Vector< Real, Dim > > &vertices, std::vector< Vector< Real, Dim > > &normals, AttributeId normal_id)
Extract vertices and normals from a mesh.
Definition smoothing_utils.cpp:58
std::unique_ptr< FEM::RiemannianMesh< Real > > setup_for_smoothing(SurfaceMesh< Scalar, Index > &mesh, SurfaceMesh< Scalar, Index > &_mesh, std::vector< SimplexIndex< K, int > > &triangles, std::vector< Vector< Real, Dim > > &vertices, std::vector< Vector< Real, Dim > > &normals, Solver &solver, Real &original_area)
Setup a mesh for smoothing operations.
Definition smoothing_utils.cpp:111