Lagrange
common.h
1/*
2 * Copyright 2016 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/utils/invalid.h>
15
16#include <limits>
17#include <memory>
18
19// clang-format off
20#include <lagrange/utils/warnoff.h>
21#include <Eigen/Core>
22#include <lagrange/utils/warnon.h>
23// clang-format on
24
25namespace lagrange {
26
27using Vertices2D = Eigen::Matrix<double, Eigen::Dynamic, 2, Eigen::RowMajor>;
28using Vertices3D = Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor>;
29using Vertices2Df = Eigen::Matrix<float, Eigen::Dynamic, 2, Eigen::RowMajor>;
30using Vertices3Df = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>;
31using Triangles = Eigen::Matrix<int, Eigen::Dynamic, 3, Eigen::RowMajor>;
32using Quads = Eigen::Matrix<int, Eigen::Dynamic, 4, Eigen::RowMajor>;
33
34template <typename VertexArray, typename FacetArray>
35class Mesh;
36using TriangleMesh3D = Mesh<Vertices3D, Triangles>;
37using TriangleMesh2D = Mesh<Vertices2D, Triangles>;
38using TriangleMesh3Df = Mesh<Vertices3Df, Triangles>;
39using TriangleMesh2Df = Mesh<Vertices2Df, Triangles>;
40using QuadMesh3D = Mesh<Vertices3D, Quads>;
41using QuadMesh2D = Mesh<Vertices2D, Quads>;
42using QuadMesh3Df = Mesh<Vertices3Df, Quads>;
43using QuadMesh2Df = Mesh<Vertices2Df, Quads>;
44
45template <class T>
46using ScalarOf = typename T::Scalar;
47
48template <class T>
49using IndexOf = typename T::Index;
50
51template <class T>
52using VertexArrayOf = typename T::VertexArray;
53
54template <class T>
55using FacetArrayOf = typename T::FacetArray;
56
57template <class T>
58using AttributeArrayOf = typename T::AttributeArray;
59
64template <typename Derived1, typename Derived2>
65void move_data(Eigen::DenseBase<Derived1>& from, Eigen::DenseBase<Derived2>& to)
66{
67#if 0
68 // Uncomment this block of code to assert that the data pointers can be swapped.
69 // Currently, we have a couple of examples/tests that fail to compile if we enable this assert.
70 // Ideally maybe we'd like to have static_warning that produces an informative message at
71 // compilation time...
72 enum {
73 SwapPointers = Eigen::internal::is_same<Derived1, Derived2>::value &&
74 Eigen::MatrixBase<Derived1>::SizeAtCompileTime == Eigen::Dynamic
75 };
76 static_assert(SwapPointers == true, "cannot swap matrix data pointers");
77#endif
78 to.derived() = std::move(from.derived());
79 from.derived().resize(0, Eigen::NoChange);
80}
81
87template <class T>
88std::shared_ptr<T> to_shared_ptr(std::unique_ptr<T>&& ptr)
89{
90 return std::shared_ptr<T>(ptr.release());
91}
92
98template <typename... Args>
100{
101 constexpr static bool False = false;
102 constexpr static bool True = true;
103};
104
105} // namespace lagrange
Main namespace for Lagrange.
Definition: AABBIGL.h:30
std::shared_ptr< T > to_shared_ptr(std::unique_ptr< T > &&ptr)
Helper for automatic type deduction for unique_ptr to shared_ptr conversion.
Definition: common.h:88
void move_data(Eigen::DenseBase< Derived1 > &from, Eigen::DenseBase< Derived2 > &to)
Move data from one Eigen obj to another.
Definition: common.h:65
Definition: project.cpp:27
Compilers might complain about static_assert(false, "").
Definition: common.h:100