Lagrange
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/raycasting/project_attributes_closest_point.h>
16#include <lagrange/raycasting/project_attributes_directional.h>
17#include <lagrange/raycasting/project_options.h>
18
19namespace lagrange {
20namespace raycasting {
21
50template <
51 typename SourceMeshType,
52 typename TargetMeshType,
53 typename DerivedVector = Eigen::Matrix<ScalarOf<SourceMeshType>, 3, 1>,
54 typename DefaultScalar = typename SourceMeshType::Scalar>
56 const SourceMeshType &source,
57 TargetMeshType &target,
58 const std::vector<std::string> &names,
59 ProjectMode project_mode,
60 const Eigen::MatrixBase<DerivedVector> &direction = DerivedVector(0, 0, 1),
61 CastMode cast_mode = CastMode::BOTH_WAYS,
62 WrapMode wrap_mode = WrapMode::CONSTANT,
63 DefaultScalar default_value = DefaultScalar(0),
64 std::function<void(typename TargetMeshType::Index, bool)> user_callback = nullptr,
65 EmbreeRayCaster<ScalarOf<SourceMeshType>> *ray_caster = nullptr,
66 std::function<bool(IndexOf<TargetMeshType>)> skip_vertex = nullptr)
67{
68 static_assert(MeshTrait<SourceMeshType>::is_mesh(), "Input type is not Mesh");
69 static_assert(MeshTrait<TargetMeshType>::is_mesh(), "Output type is not Mesh");
70 la_runtime_assert(source.get_vertex_per_facet() == 3);
71
72 switch (project_mode) {
74 ::lagrange::bvh::project_attributes_closest_vertex(source, target, names, skip_vertex);
75 break;
77 project_attributes_closest_point(source, target, names, ray_caster, skip_vertex);
78 break;
81 source,
82 target,
83 names,
84 direction,
85 cast_mode,
86 wrap_mode,
87 default_value,
88 user_callback,
89 ray_caster,
90 skip_vertex);
91 break;
92 default: throw std::runtime_error("Not implemented");
93 }
94}
95
96} // namespace raycasting
97} // namespace lagrange
A wrapper for Embree's raycasting API to compute ray intersections with (instances of) meshes.
Definition: EmbreeRayCaster.h:47
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
ProjectMode
Main projection mode.
Definition: project_options.h:21
@ CLOSEST_POINT
Interpolate attribute from the closest point on the source mesh.
@ RAY_CASTING
Copy attribute by projecting along a prescribed direction on the source mesh.
@ CLOSEST_VERTEX
Copy attribute from the closest vertex on the source mesh.
CastMode
Ray-casting mode.
Definition: project_options.h:28
@ BOTH_WAYS
Cast a ray both forward and backward in the prescribed direction.
WrapMode
Wraping mode for vertices without a hit.
Definition: project_options.h:34
@ CONSTANT
Fill with a constant value (defaults to 0).
void project_attributes_directional(const SourceMeshType &source, TargetMeshType &target, const std::vector< std::string > &names, const Eigen::MatrixBase< DerivedVector > &direction, CastMode cast_mode=CastMode::BOTH_WAYS, WrapMode wrap_mode=WrapMode::CONSTANT, DefaultScalar default_value=DefaultScalar(0), std::function< void(typename TargetMeshType::Index, bool)> user_callback=nullptr, EmbreeRayCaster< ScalarOf< SourceMeshType > > *ray_caster=nullptr, std::function< bool(IndexOf< TargetMeshType >)> skip_vertex=nullptr)
Project vertex attributes from one mesh to another, by projecting target vertices along a prescribed ...
Definition: project_attributes_directional.h:74
void project_attributes_closest_point(const SourceMeshType &source, TargetMeshType &target, const std::vector< std::string > &names, EmbreeRayCaster< ScalarOf< SourceMeshType > > *ray_caster=nullptr, std::function< bool(IndexOf< TargetMeshType >)> skip_vertex=nullptr)
Project vertex attributes from one mesh to another, by copying attributes from the closest point on t...
Definition: project_attributes_closest_point.h:49
void project_attributes(const SourceMeshType &source, TargetMeshType &target, const std::vector< std::string > &names, ProjectMode project_mode, const Eigen::MatrixBase< DerivedVector > &direction=DerivedVector(0, 0, 1), CastMode cast_mode=CastMode::BOTH_WAYS, WrapMode wrap_mode=WrapMode::CONSTANT, DefaultScalar default_value=DefaultScalar(0), std::function< void(typename TargetMeshType::Index, bool)> user_callback=nullptr, EmbreeRayCaster< ScalarOf< SourceMeshType > > *ray_caster=nullptr, std::function< bool(IndexOf< TargetMeshType >)> skip_vertex=nullptr)
Project vertex attributes from one mesh to another.
Definition: project_attributes.h:55
Main namespace for Lagrange.
Definition: AABBIGL.h:30
MeshTrait class provide compiler check for different mesh types.
Definition: MeshTrait.h:108