Lagrange
Loading...
Searching...
No Matches
project_attributes.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#pragma once
13
14#include <lagrange/bvh/project_attributes_closest_vertex.h>
15#include <lagrange/legacy/inline.h>
16#include <lagrange/raycasting/Options.h>
17#include <lagrange/raycasting/legacy/project_attributes_closest_point.h>
18#include <lagrange/raycasting/legacy/project_attributes_directional.h>
19
20namespace lagrange {
21namespace raycasting {
22LAGRANGE_LEGACY_INLINE
23namespace legacy {
24
53template <
54 typename SourceMeshType,
55 typename TargetMeshType,
56 typename DerivedVector = Eigen::Matrix<ScalarOf<SourceMeshType>, 3, 1>,
57 typename DefaultScalar = typename SourceMeshType::Scalar>
58void project_attributes(
59 const SourceMeshType& source,
60 TargetMeshType& target,
61 const std::vector<std::string>& names,
62 ProjectMode project_mode,
63 const Eigen::MatrixBase<DerivedVector>& direction = DerivedVector(0, 0, 1),
64 CastMode cast_mode = CastMode::BothWays,
66 DefaultScalar default_value = DefaultScalar(0),
67 std::function<void(typename TargetMeshType::Index, bool)> user_callback = nullptr,
68 EmbreeRayCaster<ScalarOf<SourceMeshType>>* ray_caster = nullptr,
69 std::function<bool(IndexOf<TargetMeshType>)> skip_vertex = nullptr)
70{
71 static_assert(MeshTrait<SourceMeshType>::is_mesh(), "Input type is not Mesh");
72 static_assert(MeshTrait<TargetMeshType>::is_mesh(), "Output type is not Mesh");
73 la_runtime_assert(source.get_vertex_per_facet() == 3);
74
75 switch (project_mode) {
77 ::lagrange::bvh::project_attributes_closest_vertex(source, target, names, skip_vertex);
78 break;
80 project_attributes_closest_point(source, target, names, ray_caster, skip_vertex);
81 break;
83 project_attributes_directional(
84 source,
85 target,
86 names,
87 direction,
88 cast_mode,
89 wrap_mode,
90 default_value,
91 user_callback,
92 ray_caster,
93 skip_vertex);
94 break;
95 default: throw std::runtime_error("Not implemented");
96 }
97}
98
99} // namespace legacy
100} // namespace raycasting
101} // namespace lagrange
A wrapper for Embree's raycasting API to compute ray intersections with (instances of) meshes.
Definition EmbreeRayCaster.h:59
#define la_runtime_assert(...)
Runtime assertion check.
Definition assert.h:174
Raycasting operations.
Definition ClosestPointResult.h:22
ProjectMode
Main projection mode.
Definition Options.h:30
@ RayCasting
Copy attribute by projecting along a prescribed direction on the source mesh.
Definition Options.h:36
@ ClosestPoint
Interpolate attribute from the closest point on the source mesh.
Definition Options.h:35
@ ClosestVertex
Copy attribute from the closest vertex on the source mesh.
Definition Options.h:34
FallbackMode
Fallback mode for vertices without a hit.
Definition Options.h:49
@ Constant
Fill with a constant value (defaults to 0).
Definition Options.h:53
CastMode
Ray-casting mode.
Definition Options.h:41
@ BothWays
Cast a ray both forward and backward in the prescribed direction.
Definition Options.h:45
Main namespace for Lagrange.