diff --git a/vendor/libigl/include/igl/ARAPEnergyType.h b/vendor/libigl/include/igl/ARAPEnergyType.h new file mode 100644 index 0000000000000000000000000000000000000000..68be24f5d7041363c116a15e03564edfafcf1cd7 --- /dev/null +++ b/vendor/libigl/include/igl/ARAPEnergyType.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ARAPENERGYTYPE_H +#define IGL_ARAPENERGYTYPE_H +namespace igl +{ + // ARAP_ENERGY_TYPE_SPOKES "As-rigid-as-possible Surface Modeling" by [Sorkine and + // Alexa 2007], rotations defined at vertices affecting incident edges, + // default + // ARAP_ENERGY_TYPE_SPOKES-AND-RIMS Adapted version of "As-rigid-as-possible Surface + // Modeling" by [Sorkine and Alexa 2007] presented in section 4.2 of or + // "A simple geometric model for elastic deformation" by [Chao et al. + // 2010], rotations defined at vertices affecting incident edges and + // opposite edges + // ARAP_ENERGY_TYPE_ELEMENTS "A local-global approach to mesh parameterization" by + // [Liu et al. 2010] or "A simple geometric model for elastic + // deformation" by [Chao et al. 2010], rotations defined at elements + // (triangles or tets) + // ARAP_ENERGY_TYPE_DEFAULT Choose one automatically: spokes and rims + // for surfaces, elements for planar meshes and tets (not fully + // supported) + enum ARAPEnergyType + { + ARAP_ENERGY_TYPE_SPOKES = 0, + ARAP_ENERGY_TYPE_SPOKES_AND_RIMS = 1, + ARAP_ENERGY_TYPE_ELEMENTS = 2, + ARAP_ENERGY_TYPE_DEFAULT = 3, + NUM_ARAP_ENERGY_TYPES = 4 + }; +} +#endif diff --git a/vendor/libigl/include/igl/AtA_cached.h b/vendor/libigl/include/igl/AtA_cached.h new file mode 100644 index 0000000000000000000000000000000000000000..7768254111db46f7b704314b9f490e47e8c54773 --- /dev/null +++ b/vendor/libigl/include/igl/AtA_cached.h @@ -0,0 +1,70 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ATA_CACHED_H +#define IGL_ATA_CACHED_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +namespace igl +{ + struct AtA_cached_data + { + // Weights + Eigen::VectorXd W; + + // Flatten composition rules + std::vector I_row; + std::vector I_col; + std::vector I_w; + + // For each entry of AtA, points to the beginning + // of the composition rules + std::vector I_outer; + }; + + // Computes At * W * A, where A is sparse and W is diagonal. Divides the + // construction in two phases, one + // for fixing the sparsity pattern, and one to populate it with values. Compared to + // evaluating it directly, this version is slower for the first time (since it requires a + // precomputation), but faster to the subsequent evaluations. + // + // Input: + // A m x n sparse matrix + // data stores the precomputed sparsity pattern, data.W contains the optional diagonal weights (stored as a dense vector). If W is not provided, it is replaced by the identity. + // Outputs: + // AtA m by m matrix computed as AtA * W * A + // + // Example: + // AtA_data = igl::AtA_cached_data(); + // AtA_data.W = W; + // if (s.AtA.rows() == 0) + // igl::AtA_cached_precompute(s.A,s.AtA_data,s.AtA); + // else + // igl::AtA_cached(s.A,s.AtA_data,s.AtA); + template + IGL_INLINE void AtA_cached_precompute( + const Eigen::SparseMatrix& A, + AtA_cached_data& data, + Eigen::SparseMatrix& AtA + ); + + template + IGL_INLINE void AtA_cached( + const Eigen::SparseMatrix& A, + const AtA_cached_data& data, + Eigen::SparseMatrix& AtA + ); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "AtA_cached.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/C_STR.h b/vendor/libigl/include/igl/C_STR.h new file mode 100644 index 0000000000000000000000000000000000000000..9844b35a5126caa7a8512f7c9334dd1084f2caad --- /dev/null +++ b/vendor/libigl/include/igl/C_STR.h @@ -0,0 +1,18 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_C_STR_H +#define IGL_C_STR_H +// http://stackoverflow.com/a/2433143/148668 +// Suppose you have a function: +// void func(const char * c); +// Then you can write: +// func(C_STR("foo"<<1<<"bar")); +#include +#include +#define C_STR(X) static_cast(std::ostringstream().flush() << X).str().c_str() +#endif diff --git a/vendor/libigl/include/igl/EPS.cpp b/vendor/libigl/include/igl/EPS.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc592cc2a62956c9e896cff44cb7ccc30db53e2b --- /dev/null +++ b/vendor/libigl/include/igl/EPS.cpp @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "EPS.h" + +template <> IGL_INLINE float igl::EPS() +{ + return igl::FLOAT_EPS; +} +template <> IGL_INLINE double igl::EPS() +{ + return igl::DOUBLE_EPS; +} + +template <> IGL_INLINE float igl::EPS_SQ() +{ + return igl::FLOAT_EPS_SQ; +} +template <> IGL_INLINE double igl::EPS_SQ() +{ + return igl::DOUBLE_EPS_SQ; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/EPS.h b/vendor/libigl/include/igl/EPS.h new file mode 100644 index 0000000000000000000000000000000000000000..d65007a6498f5e9f7f46e12d2e1a0942f6c3bb09 --- /dev/null +++ b/vendor/libigl/include/igl/EPS.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EPS_H +#define IGL_EPS_H +#include "igl_inline.h" +namespace igl +{ + // Define a standard value for double epsilon + const double DOUBLE_EPS = 1.0e-14; + const double DOUBLE_EPS_SQ = 1.0e-28; + const float FLOAT_EPS = 1.0e-7f; + const float FLOAT_EPS_SQ = 1.0e-14f; + // Function returning EPS for corresponding type + template IGL_INLINE S_type EPS(); + template IGL_INLINE S_type EPS_SQ(); + // Template specializations for float and double + template <> IGL_INLINE float EPS(); + template <> IGL_INLINE double EPS(); + template <> IGL_INLINE float EPS_SQ(); + template <> IGL_INLINE double EPS_SQ(); +} + +#ifndef IGL_STATIC_LIBRARY +# include "EPS.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/FastWindingNumberForSoups.h b/vendor/libigl/include/igl/FastWindingNumberForSoups.h new file mode 100644 index 0000000000000000000000000000000000000000..1aab23212e22d5b8c529665c825543c016ec8e8c --- /dev/null +++ b/vendor/libigl/include/igl/FastWindingNumberForSoups.h @@ -0,0 +1,7806 @@ +// This header created by issuing: `echo "// This header created by issuing: \`$BASH_COMMAND\` $(echo "" | cat - LICENSE README.md | sed -e "s#^..*#\/\/ &#") $(echo "" | cat - SYS_Types.h SYS_Math.h VM_SSEFunc.h VM_SIMDFunc.h VM_SIMD.h UT_Array.h UT_ArrayImpl.h UT_SmallArray.h UT_FixedVector.h UT_ParallelUtil.h UT_BVH.h UT_BVHImpl.h UT_SolidAngle.h UT_Array.cpp UT_SolidAngle.cpp | sed -e "s/^#.*include *\".*$//g")" > ~/Repos/libigl/include/igl/FastWindingNumberForSoups.h` +// MIT License + +// Copyright (c) 2018 Side Effects Software Inc. + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// # Fast Winding Numbers for Soups + +// https://github.com/alecjacobson/WindingNumber + +// Implementation of the _ACM SIGGRAPH_ 2018 paper, + +// "Fast Winding Numbers for Soups and Clouds" + +// Gavin Barill¹, Neil Dickson², Ryan Schmidt³, David I.W. Levin¹, Alec Jacobson¹ + +// ¹University of Toronto, ²SideFX, ³Gradient Space + + +// _Note: this implementation is for triangle soups only, not point clouds._ + +// This version does _not_ depend on Intel TBB. Instead it depends on +// [libigl](https://github.com/libigl/libigl)'s simpler `igl::parallel_for` (which +// uses `std::thread`) + +// This code, as written, depends on Intel's Threading Building Blocks (TBB) library for parallelism, but it should be fairly easy to change it to use any other means of threading, since it only uses parallel for loops with simple partitioning. + +// The main class of interest is UT_SolidAngle and its init and computeSolidAngle functions, which you can use by including UT_SolidAngle.h, and whose implementation is mostly in UT_SolidAngle.cpp, using a 4-way bounding volume hierarchy (BVH) implemented in the UT_BVH.h and UT_BVHImpl.h headers. The rest of the files are mostly various supporting code. UT_SubtendedAngle, for computing angles subtended by 2D curves, can also be found in UT_SolidAngle.h and UT_SolidAngle.cpp . + +// An example of very similar code and how to use it to create a geometry operator (SOP) in Houdini can be found in the HDK examples (toolkit/samples/SOP/SOP_WindingNumber) for Houdini 16.5.121 and later. Query points go in the first input and the mesh geometry goes in the second input. + + +// Create a single header using: + +// echo "// This header created by issuing: \`$BASH_COMMAND\` $(echo "" | cat - LICENSE README.md | sed -e "s#^..*#\/\/ &#") $(echo "" | cat - SYS_Types.h SYS_Math.h VM_SSEFunc.h VM_SIMD.h UT_Array.h UT_ArrayImpl.h UT_SmallArray.h UT_FixedVector.h UT_ParallelUtil.h UT_BVH.h UT_BVHImpl.h UT_SolidAngle.h UT_Array.cpp UT_SolidAngle.cpp | sed -e "s/^#.*include *\".*$//g")" +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Common type definitions. + */ + +#pragma once + +#ifndef __SYS_Types__ +#define __SYS_Types__ + +/* Include system types */ +#include +#include +#include +#include + +namespace igl { namespace FastWindingNumber { + +/* + * Integer types + */ +typedef signed char int8; +typedef unsigned char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned int uint32; + +#ifndef MBSD +typedef unsigned int uint; +#endif + +/* + * Avoid using uint64. + * The extra bit of precision is NOT worth the cost in pain and suffering + * induced by use of unsigned. + */ +#if defined(_WIN32) + typedef __int64 int64; + typedef unsigned __int64 uint64; +#elif defined(MBSD) + // On MBSD, int64/uint64 are also defined in the system headers so we must + // declare these in the same way or else we get conflicts. + typedef int64_t int64; + typedef uint64_t uint64; +#elif defined(AMD64) + typedef long int64; + typedef unsigned long uint64; +#else + typedef long long int64; + typedef unsigned long long uint64; +#endif + +/// The problem with int64 is that it implies that it is a fixed 64-bit quantity +/// that is saved to disk. Therefore, we need another integral type for +/// indexing our arrays. +typedef int64 exint; + +/// Mark function to be inlined. If this is done, taking the address of such +/// a function is not allowed. +#if defined(__GNUC__) || defined(__clang__) +#define SYS_FORCE_INLINE __attribute__ ((always_inline)) inline +#elif defined(_MSC_VER) +#define SYS_FORCE_INLINE __forceinline +#else +#define SYS_FORCE_INLINE inline +#endif + +/// Floating Point Types +typedef float fpreal32; +typedef double fpreal64; + +/// SYS_FPRealUnionT for type-safe casting with integral types +template +union SYS_FPRealUnionT; + +template <> +union SYS_FPRealUnionT +{ + typedef int32 int_type; + typedef uint32 uint_type; + typedef fpreal32 fpreal_type; + + enum { + EXPONENT_BITS = 8, + MANTISSA_BITS = 23, + EXPONENT_BIAS = 127 }; + + int_type ival; + uint_type uval; + fpreal_type fval; + + struct + { + uint_type mantissa_val: 23; + uint_type exponent_val: 8; + uint_type sign_val: 1; + }; +}; + +template <> +union SYS_FPRealUnionT +{ + typedef int64 int_type; + typedef uint64 uint_type; + typedef fpreal64 fpreal_type; + + enum { + EXPONENT_BITS = 11, + MANTISSA_BITS = 52, + EXPONENT_BIAS = 1023 }; + + int_type ival; + uint_type uval; + fpreal_type fval; + + struct + { + uint_type mantissa_val: 52; + uint_type exponent_val: 11; + uint_type sign_val: 1; + }; +}; + +typedef union SYS_FPRealUnionT SYS_FPRealUnionF; +typedef union SYS_FPRealUnionT SYS_FPRealUnionD; + +/// Asserts are disabled +/// @{ +#define UT_ASSERT_P(ZZ) ((void)0) +#define UT_ASSERT(ZZ) ((void)0) +#define UT_ASSERT_MSG_P(ZZ, MM) ((void)0) +#define UT_ASSERT_MSG(ZZ, MM) ((void)0) +/// @} +}} + +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Miscellaneous math functions. + */ + +#pragma once + +#ifndef __SYS_Math__ +#define __SYS_Math__ + + + +#include +#include +#include + +namespace igl { namespace FastWindingNumber { + +// NOTE: +// These have been carefully written so that in the case of equality +// we always return the first parameter. This is so that NANs in +// in the second parameter are suppressed. +#define h_min(a, b) (((a) > (b)) ? (b) : (a)) +#define h_max(a, b) (((a) < (b)) ? (b) : (a)) +// DO NOT CHANGE THE ABOVE WITHOUT READING THE COMMENT +#define h_abs(a) (((a) > 0) ? (a) : -(a)) + +static constexpr inline int16 SYSmin(int16 a, int16 b) { return h_min(a,b); } +static constexpr inline int16 SYSmax(int16 a, int16 b) { return h_max(a,b); } +static constexpr inline int16 SYSabs(int16 a) { return h_abs(a); } +static constexpr inline int32 SYSmin(int32 a, int32 b) { return h_min(a,b); } +static constexpr inline int32 SYSmax(int32 a, int32 b) { return h_max(a,b); } +static constexpr inline int32 SYSabs(int32 a) { return h_abs(a); } +static constexpr inline int64 SYSmin(int64 a, int64 b) { return h_min(a,b); } +static constexpr inline int64 SYSmax(int64 a, int64 b) { return h_max(a,b); } +static constexpr inline int64 SYSmin(int32 a, int64 b) { return h_min(a,b); } +static constexpr inline int64 SYSmax(int32 a, int64 b) { return h_max(a,b); } +static constexpr inline int64 SYSmin(int64 a, int32 b) { return h_min(a,b); } +static constexpr inline int64 SYSmax(int64 a, int32 b) { return h_max(a,b); } +static constexpr inline int64 SYSabs(int64 a) { return h_abs(a); } +static constexpr inline uint16 SYSmin(uint16 a, uint16 b) { return h_min(a,b); } +static constexpr inline uint16 SYSmax(uint16 a, uint16 b) { return h_max(a,b); } +static constexpr inline uint32 SYSmin(uint32 a, uint32 b) { return h_min(a,b); } +static constexpr inline uint32 SYSmax(uint32 a, uint32 b) { return h_max(a,b); } +static constexpr inline uint64 SYSmin(uint64 a, uint64 b) { return h_min(a,b); } +static constexpr inline uint64 SYSmax(uint64 a, uint64 b) { return h_max(a,b); } +static constexpr inline fpreal32 SYSmin(fpreal32 a, fpreal32 b) { return h_min(a,b); } +static constexpr inline fpreal32 SYSmax(fpreal32 a, fpreal32 b) { return h_max(a,b); } +static constexpr inline fpreal64 SYSmin(fpreal64 a, fpreal64 b) { return h_min(a,b); } +static constexpr inline fpreal64 SYSmax(fpreal64 a, fpreal64 b) { return h_max(a,b); } + +// Some systems have size_t as a seperate type from uint. Some don't. +#if (defined(LINUX) && defined(IA64)) || defined(MBSD) +static constexpr inline size_t SYSmin(size_t a, size_t b) { return h_min(a,b); } +static constexpr inline size_t SYSmax(size_t a, size_t b) { return h_max(a,b); } +#endif + +#undef h_min +#undef h_max +#undef h_abs + +#define h_clamp(val, min, max, tol) \ + ((val <= min+tol) ? min : ((val >= max-tol) ? max : val)) + + static constexpr inline int + SYSclamp(int v, int min, int max) + { return h_clamp(v, min, max, 0); } + + static constexpr inline uint + SYSclamp(uint v, uint min, uint max) + { return h_clamp(v, min, max, 0); } + + static constexpr inline int64 + SYSclamp(int64 v, int64 min, int64 max) + { return h_clamp(v, min, max, int64(0)); } + + static constexpr inline uint64 + SYSclamp(uint64 v, uint64 min, uint64 max) + { return h_clamp(v, min, max, uint64(0)); } + + static constexpr inline fpreal32 + SYSclamp(fpreal32 v, fpreal32 min, fpreal32 max, fpreal32 tol=(fpreal32)0) + { return h_clamp(v, min, max, tol); } + + static constexpr inline fpreal64 + SYSclamp(fpreal64 v, fpreal64 min, fpreal64 max, fpreal64 tol=(fpreal64)0) + { return h_clamp(v, min, max, tol); } + +#undef h_clamp + +static inline fpreal64 SYSsqrt(fpreal64 arg) +{ return ::sqrt(arg); } +static inline fpreal32 SYSsqrt(fpreal32 arg) +{ return ::sqrtf(arg); } +static inline fpreal64 SYSatan2(fpreal64 a, fpreal64 b) +{ return ::atan2(a, b); } +static inline fpreal32 SYSatan2(fpreal32 a, fpreal32 b) +{ return ::atan2(a, b); } + +static inline fpreal32 SYSabs(fpreal32 a) { return ::fabsf(a); } +static inline fpreal64 SYSabs(fpreal64 a) { return ::fabs(a); } + +}} + +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * SIMD wrapper functions for SSE instructions + */ + +#pragma once +#ifdef __SSE__ + +#ifndef __VM_SSEFunc__ +#define __VM_SSEFunc__ + + + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable:4799) +#endif + +#define CPU_HAS_SIMD_INSTR 1 +#define VM_SSE_STYLE 1 + +#include + +#if defined(__SSE4_1__) +#define VM_SSE41_STYLE 1 +#include +#endif + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif + +namespace igl { namespace FastWindingNumber { + +typedef __m128 v4sf; +typedef __m128i v4si; + +// Plain casting (no conversion) +// MSVC has problems casting between __m128 and __m128i, so we implement a +// custom casting routine specifically for windows. + +#if defined(_MSC_VER) + +static SYS_FORCE_INLINE v4sf +vm_v4sf(const v4si &a) +{ + union { + v4si ival; + v4sf fval; + }; + ival = a; + return fval; +} + +static SYS_FORCE_INLINE v4si +vm_v4si(const v4sf &a) +{ + union { + v4si ival; + v4sf fval; + }; + fval = a; + return ival; +} + +#define V4SF(A) vm_v4sf(A) +#define V4SI(A) vm_v4si(A) + +#else + +#define V4SF(A) (v4sf)A +#define V4SI(A) (v4si)A + +#endif + +#define VM_SHUFFLE_MASK(a0,a1, b0,b1) ((b1)<<6|(b0)<<4 | (a1)<<2|(a0)) + +template +static SYS_FORCE_INLINE v4sf +vm_shuffle(const v4sf &a, const v4sf &b) +{ + return _mm_shuffle_ps(a, b, mask); +} + +template +static SYS_FORCE_INLINE v4si +vm_shuffle(const v4si &a, const v4si &b) +{ + return V4SI(_mm_shuffle_ps(V4SF(a), V4SF(b), mask)); +} + +template +static SYS_FORCE_INLINE T +vm_shuffle(const T &a, const T &b) +{ + return vm_shuffle(a, b); +} + +template +static SYS_FORCE_INLINE T +vm_shuffle(const T &a) +{ + return vm_shuffle(a, a); +} + +template +static SYS_FORCE_INLINE T +vm_shuffle(const T &a) +{ + return vm_shuffle(a, a); +} + +#if defined(VM_SSE41_STYLE) + +static SYS_FORCE_INLINE v4si +vm_insert(const v4si v, int32 a, int n) +{ + switch (n) + { + case 0: return _mm_insert_epi32(v, a, 0); + case 1: return _mm_insert_epi32(v, a, 1); + case 2: return _mm_insert_epi32(v, a, 2); + case 3: return _mm_insert_epi32(v, a, 3); + } + return v; +} + +static SYS_FORCE_INLINE v4sf +vm_insert(const v4sf v, float a, int n) +{ + switch (n) + { + case 0: return _mm_insert_ps(v, _mm_set_ss(a), _MM_MK_INSERTPS_NDX(0,0,0)); + case 1: return _mm_insert_ps(v, _mm_set_ss(a), _MM_MK_INSERTPS_NDX(0,1,0)); + case 2: return _mm_insert_ps(v, _mm_set_ss(a), _MM_MK_INSERTPS_NDX(0,2,0)); + case 3: return _mm_insert_ps(v, _mm_set_ss(a), _MM_MK_INSERTPS_NDX(0,3,0)); + } + return v; +} + +static SYS_FORCE_INLINE int +vm_extract(const v4si v, int n) +{ + switch (n) + { + case 0: return _mm_extract_epi32(v, 0); + case 1: return _mm_extract_epi32(v, 1); + case 2: return _mm_extract_epi32(v, 2); + case 3: return _mm_extract_epi32(v, 3); + } + return 0; +} + +static SYS_FORCE_INLINE float +vm_extract(const v4sf v, int n) +{ + SYS_FPRealUnionF tmp; + switch (n) + { + case 0: tmp.ival = _mm_extract_ps(v, 0); break; + case 1: tmp.ival = _mm_extract_ps(v, 1); break; + case 2: tmp.ival = _mm_extract_ps(v, 2); break; + case 3: tmp.ival = _mm_extract_ps(v, 3); break; + } + return tmp.fval; +} + +#else + +static SYS_FORCE_INLINE v4si +vm_insert(const v4si v, int32 a, int n) +{ + union { v4si vector; int32 comp[4]; }; + vector = v; + comp[n] = a; + return vector; +} + +static SYS_FORCE_INLINE v4sf +vm_insert(const v4sf v, float a, int n) +{ + union { v4sf vector; float comp[4]; }; + vector = v; + comp[n] = a; + return vector; +} + +static SYS_FORCE_INLINE int +vm_extract(const v4si v, int n) +{ + union { v4si vector; int32 comp[4]; }; + vector = v; + return comp[n]; +} + +static SYS_FORCE_INLINE float +vm_extract(const v4sf v, int n) +{ + union { v4sf vector; float comp[4]; }; + vector = v; + return comp[n]; +} + +#endif + +static SYS_FORCE_INLINE v4sf +vm_splats(float a) +{ + return _mm_set1_ps(a); +} + +static SYS_FORCE_INLINE v4si +vm_splats(uint32 a) +{ + SYS_FPRealUnionF tmp; + tmp.uval = a; + return V4SI(vm_splats(tmp.fval)); +} + +static SYS_FORCE_INLINE v4si +vm_splats(int32 a) +{ + SYS_FPRealUnionF tmp; + tmp.ival = a; + return V4SI(vm_splats(tmp.fval)); +} + +static SYS_FORCE_INLINE v4sf +vm_splats(float a, float b, float c, float d) +{ + return vm_shuffle<0,2,0,2>( + vm_shuffle<0>(_mm_set_ss(a), _mm_set_ss(b)), + vm_shuffle<0>(_mm_set_ss(c), _mm_set_ss(d))); +} + +static SYS_FORCE_INLINE v4si +vm_splats(uint32 a, uint32 b, uint32 c, uint32 d) +{ + SYS_FPRealUnionF af, bf, cf, df; + af.uval = a; + bf.uval = b; + cf.uval = c; + df.uval = d; + return V4SI(vm_splats(af.fval, bf.fval, cf.fval, df.fval)); +} + +static SYS_FORCE_INLINE v4si +vm_splats(int32 a, int32 b, int32 c, int32 d) +{ + SYS_FPRealUnionF af, bf, cf, df; + af.ival = a; + bf.ival = b; + cf.ival = c; + df.ival = d; + return V4SI(vm_splats(af.fval, bf.fval, cf.fval, df.fval)); +} + +static SYS_FORCE_INLINE v4si +vm_load(const int32 v[4]) +{ + return V4SI(_mm_loadu_ps((const float *)v)); +} + +static SYS_FORCE_INLINE v4sf +vm_load(const float v[4]) +{ + return _mm_loadu_ps(v); +} + +static SYS_FORCE_INLINE void +vm_store(float dst[4], v4sf value) +{ + _mm_storeu_ps(dst, value); +} + +static SYS_FORCE_INLINE v4sf +vm_negate(v4sf a) +{ + return _mm_sub_ps(_mm_setzero_ps(), a); +} + +static SYS_FORCE_INLINE v4sf +vm_abs(v4sf a) +{ + return _mm_max_ps(a, vm_negate(a)); +} + +static SYS_FORCE_INLINE v4sf +vm_fdiv(v4sf a, v4sf b) +{ + return _mm_mul_ps(a, _mm_rcp_ps(b)); +} + +static SYS_FORCE_INLINE v4sf +vm_fsqrt(v4sf a) +{ + return _mm_rcp_ps(_mm_rsqrt_ps(a)); +} + +static SYS_FORCE_INLINE v4sf +vm_madd(v4sf a, v4sf b, v4sf c) +{ + return _mm_add_ps(_mm_mul_ps(a, b), c); +} + +static const v4si theSSETrue = vm_splats(0xFFFFFFFF); + +static SYS_FORCE_INLINE bool +vm_allbits(const v4si &a) +{ + return _mm_movemask_ps(V4SF(_mm_cmpeq_epi32(a, theSSETrue))) == 0xF; +} + + +#define VM_EXTRACT vm_extract +#define VM_INSERT vm_insert +#define VM_SPLATS vm_splats +#define VM_LOAD vm_load +#define VM_STORE vm_store + +#define VM_CMPLT(A,B) V4SI(_mm_cmplt_ps(A,B)) +#define VM_CMPLE(A,B) V4SI(_mm_cmple_ps(A,B)) +#define VM_CMPGT(A,B) V4SI(_mm_cmpgt_ps(A,B)) +#define VM_CMPGE(A,B) V4SI(_mm_cmpge_ps(A,B)) +#define VM_CMPEQ(A,B) V4SI(_mm_cmpeq_ps(A,B)) +#define VM_CMPNE(A,B) V4SI(_mm_cmpneq_ps(A,B)) + +#define VM_ICMPLT _mm_cmplt_epi32 +#define VM_ICMPGT _mm_cmpgt_epi32 +#define VM_ICMPEQ _mm_cmpeq_epi32 + +#define VM_IADD _mm_add_epi32 +#define VM_ISUB _mm_sub_epi32 + +#define VM_ADD _mm_add_ps +#define VM_SUB _mm_sub_ps +#define VM_MUL _mm_mul_ps +#define VM_DIV _mm_div_ps +#define VM_SQRT _mm_sqrt_ps +#define VM_ISQRT _mm_rsqrt_ps +#define VM_INVERT _mm_rcp_ps +#define VM_ABS vm_abs + +#define VM_FDIV vm_fdiv +#define VM_NEG vm_negate +#define VM_FSQRT vm_fsqrt +#define VM_MADD vm_madd + +#define VM_MIN _mm_min_ps +#define VM_MAX _mm_max_ps + +#define VM_AND _mm_and_si128 +#define VM_ANDNOT _mm_andnot_si128 +#define VM_OR _mm_or_si128 +#define VM_XOR _mm_xor_si128 + +#define VM_ALLBITS vm_allbits + +#define VM_SHUFFLE vm_shuffle + +// Integer to float conversions +#define VM_SSE_ROUND_MASK 0x6000 +#define VM_SSE_ROUND_ZERO 0x6000 +#define VM_SSE_ROUND_UP 0x4000 +#define VM_SSE_ROUND_DOWN 0x2000 +#define VM_SSE_ROUND_NEAR 0x0000 + +#define GETROUND() (_mm_getcsr()&VM_SSE_ROUND_MASK) +#define SETROUND(x) (_mm_setcsr(x|(_mm_getcsr()&~VM_SSE_ROUND_MASK))) + +// The P functions must be invoked before FLOOR, the E functions invoked +// afterwards to reset the state. + +#define VM_P_FLOOR() uint rounding = GETROUND(); \ + SETROUND(VM_SSE_ROUND_DOWN); +#define VM_FLOOR _mm_cvtps_epi32 +#define VM_INT _mm_cvttps_epi32 +#define VM_E_FLOOR() SETROUND(rounding); + +// Float to integer conversion +#define VM_IFLOAT _mm_cvtepi32_ps +}} + +#endif +#endif +#pragma once +#ifndef __SSE__ +#ifndef __VM_SIMDFunc__ +#define __VM_SIMDFunc__ + + + +#include + +namespace igl { namespace FastWindingNumber { + +struct v4si { + int32 v[4]; +}; + +struct v4sf { + float v[4]; +}; + +static SYS_FORCE_INLINE v4sf V4SF(const v4si &v) { + static_assert(sizeof(v4si) == sizeof(v4sf) && alignof(v4si) == alignof(v4sf), "v4si and v4sf must be compatible"); + return *(const v4sf*)&v; +} + +static SYS_FORCE_INLINE v4si V4SI(const v4sf &v) { + static_assert(sizeof(v4si) == sizeof(v4sf) && alignof(v4si) == alignof(v4sf), "v4si and v4sf must be compatible"); + return *(const v4si*)&v; +} + +static SYS_FORCE_INLINE int32 conditionMask(bool c) { + return c ? int32(0xFFFFFFFF) : 0; +} + +static SYS_FORCE_INLINE v4sf +VM_SPLATS(float f) { + return v4sf{{f, f, f, f}}; +} + +static SYS_FORCE_INLINE v4si +VM_SPLATS(uint32 i) { + return v4si{{int32(i), int32(i), int32(i), int32(i)}}; +} + +static SYS_FORCE_INLINE v4si +VM_SPLATS(int32 i) { + return v4si{{i, i, i, i}}; +} + +static SYS_FORCE_INLINE v4sf +VM_SPLATS(float a, float b, float c, float d) { + return v4sf{{a, b, c, d}}; +} + +static SYS_FORCE_INLINE v4si +VM_SPLATS(uint32 a, uint32 b, uint32 c, uint32 d) { + return v4si{{int32(a), int32(b), int32(c), int32(d)}}; +} + +static SYS_FORCE_INLINE v4si +VM_SPLATS(int32 a, int32 b, int32 c, int32 d) { + return v4si{{a, b, c, d}}; +} + +static SYS_FORCE_INLINE v4si +VM_LOAD(const int32 v[4]) { + return v4si{{v[0], v[1], v[2], v[3]}}; +} + +static SYS_FORCE_INLINE v4sf +VM_LOAD(const float v[4]) { + return v4sf{{v[0], v[1], v[2], v[3]}}; +} + + +static inline v4si VM_ICMPEQ(v4si a, v4si b) { + return v4si{{ + conditionMask(a.v[0] == b.v[0]), + conditionMask(a.v[1] == b.v[1]), + conditionMask(a.v[2] == b.v[2]), + conditionMask(a.v[3] == b.v[3]) + }}; +} + +static inline v4si VM_ICMPGT(v4si a, v4si b) { + return v4si{{ + conditionMask(a.v[0] > b.v[0]), + conditionMask(a.v[1] > b.v[1]), + conditionMask(a.v[2] > b.v[2]), + conditionMask(a.v[3] > b.v[3]) + }}; +} + +static inline v4si VM_ICMPLT(v4si a, v4si b) { + return v4si{{ + conditionMask(a.v[0] < b.v[0]), + conditionMask(a.v[1] < b.v[1]), + conditionMask(a.v[2] < b.v[2]), + conditionMask(a.v[3] < b.v[3]) + }}; +} + +static inline v4si VM_IADD(v4si a, v4si b) { + return v4si{{ + (a.v[0] + b.v[0]), + (a.v[1] + b.v[1]), + (a.v[2] + b.v[2]), + (a.v[3] + b.v[3]) + }}; +} + +static inline v4si VM_ISUB(v4si a, v4si b) { + return v4si{{ + (a.v[0] - b.v[0]), + (a.v[1] - b.v[1]), + (a.v[2] - b.v[2]), + (a.v[3] - b.v[3]) + }}; +} + +static inline v4si VM_OR(v4si a, v4si b) { + return v4si{{ + (a.v[0] | b.v[0]), + (a.v[1] | b.v[1]), + (a.v[2] | b.v[2]), + (a.v[3] | b.v[3]) + }}; +} + +static inline v4si VM_AND(v4si a, v4si b) { + return v4si{{ + (a.v[0] & b.v[0]), + (a.v[1] & b.v[1]), + (a.v[2] & b.v[2]), + (a.v[3] & b.v[3]) + }}; +} + +static inline v4si VM_ANDNOT(v4si a, v4si b) { + return v4si{{ + ((~a.v[0]) & b.v[0]), + ((~a.v[1]) & b.v[1]), + ((~a.v[2]) & b.v[2]), + ((~a.v[3]) & b.v[3]) + }}; +} + +static inline v4si VM_XOR(v4si a, v4si b) { + return v4si{{ + (a.v[0] ^ b.v[0]), + (a.v[1] ^ b.v[1]), + (a.v[2] ^ b.v[2]), + (a.v[3] ^ b.v[3]) + }}; +} + +static SYS_FORCE_INLINE int +VM_EXTRACT(const v4si v, int index) { + return v.v[index]; +} + +static SYS_FORCE_INLINE float +VM_EXTRACT(const v4sf v, int index) { + return v.v[index]; +} + +static SYS_FORCE_INLINE v4si +VM_INSERT(v4si v, int32 value, int index) { + v.v[index] = value; + return v; +} + +static SYS_FORCE_INLINE v4sf +VM_INSERT(v4sf v, float value, int index) { + v.v[index] = value; + return v; +} + +static inline v4si VM_CMPEQ(v4sf a, v4sf b) { + return v4si{{ + conditionMask(a.v[0] == b.v[0]), + conditionMask(a.v[1] == b.v[1]), + conditionMask(a.v[2] == b.v[2]), + conditionMask(a.v[3] == b.v[3]) + }}; +} + +static inline v4si VM_CMPNE(v4sf a, v4sf b) { + return v4si{{ + conditionMask(a.v[0] != b.v[0]), + conditionMask(a.v[1] != b.v[1]), + conditionMask(a.v[2] != b.v[2]), + conditionMask(a.v[3] != b.v[3]) + }}; +} + +static inline v4si VM_CMPGT(v4sf a, v4sf b) { + return v4si{{ + conditionMask(a.v[0] > b.v[0]), + conditionMask(a.v[1] > b.v[1]), + conditionMask(a.v[2] > b.v[2]), + conditionMask(a.v[3] > b.v[3]) + }}; +} + +static inline v4si VM_CMPLT(v4sf a, v4sf b) { + return v4si{{ + conditionMask(a.v[0] < b.v[0]), + conditionMask(a.v[1] < b.v[1]), + conditionMask(a.v[2] < b.v[2]), + conditionMask(a.v[3] < b.v[3]) + }}; +} + +static inline v4si VM_CMPGE(v4sf a, v4sf b) { + return v4si{{ + conditionMask(a.v[0] >= b.v[0]), + conditionMask(a.v[1] >= b.v[1]), + conditionMask(a.v[2] >= b.v[2]), + conditionMask(a.v[3] >= b.v[3]) + }}; +} + +static inline v4si VM_CMPLE(v4sf a, v4sf b) { + return v4si{{ + conditionMask(a.v[0] <= b.v[0]), + conditionMask(a.v[1] <= b.v[1]), + conditionMask(a.v[2] <= b.v[2]), + conditionMask(a.v[3] <= b.v[3]) + }}; +} + +static inline v4sf VM_ADD(v4sf a, v4sf b) { + return v4sf{{ + (a.v[0] + b.v[0]), + (a.v[1] + b.v[1]), + (a.v[2] + b.v[2]), + (a.v[3] + b.v[3]) + }}; +} + +static inline v4sf VM_SUB(v4sf a, v4sf b) { + return v4sf{{ + (a.v[0] - b.v[0]), + (a.v[1] - b.v[1]), + (a.v[2] - b.v[2]), + (a.v[3] - b.v[3]) + }}; +} + +static inline v4sf VM_NEG(v4sf a) { + return v4sf{{ + (-a.v[0]), + (-a.v[1]), + (-a.v[2]), + (-a.v[3]) + }}; +} + +static inline v4sf VM_MUL(v4sf a, v4sf b) { + return v4sf{{ + (a.v[0] * b.v[0]), + (a.v[1] * b.v[1]), + (a.v[2] * b.v[2]), + (a.v[3] * b.v[3]) + }}; +} + +static inline v4sf VM_DIV(v4sf a, v4sf b) { + return v4sf{{ + (a.v[0] / b.v[0]), + (a.v[1] / b.v[1]), + (a.v[2] / b.v[2]), + (a.v[3] / b.v[3]) + }}; +} + +static inline v4sf VM_MADD(v4sf a, v4sf b, v4sf c) { + return v4sf{{ + (a.v[0] * b.v[0]) + c.v[0], + (a.v[1] * b.v[1]) + c.v[1], + (a.v[2] * b.v[2]) + c.v[2], + (a.v[3] * b.v[3]) + c.v[3] + }}; +} + +static inline v4sf VM_ABS(v4sf a) { + return v4sf{{ + (a.v[0] < 0) ? -a.v[0] : a.v[0], + (a.v[1] < 0) ? -a.v[1] : a.v[1], + (a.v[2] < 0) ? -a.v[2] : a.v[2], + (a.v[3] < 0) ? -a.v[3] : a.v[3] + }}; +} + +static inline v4sf VM_MAX(v4sf a, v4sf b) { + return v4sf{{ + (a.v[0] < b.v[0]) ? b.v[0] : a.v[0], + (a.v[1] < b.v[1]) ? b.v[1] : a.v[1], + (a.v[2] < b.v[2]) ? b.v[2] : a.v[2], + (a.v[3] < b.v[3]) ? b.v[3] : a.v[3] + }}; +} + +static inline v4sf VM_MIN(v4sf a, v4sf b) { + return v4sf{{ + (a.v[0] > b.v[0]) ? b.v[0] : a.v[0], + (a.v[1] > b.v[1]) ? b.v[1] : a.v[1], + (a.v[2] > b.v[2]) ? b.v[2] : a.v[2], + (a.v[3] > b.v[3]) ? b.v[3] : a.v[3] + }}; +} + +static inline v4sf VM_INVERT(v4sf a) { + return v4sf{{ + (1.0f/a.v[0]), + (1.0f/a.v[1]), + (1.0f/a.v[2]), + (1.0f/a.v[3]) + }}; +} + +static inline v4sf VM_SQRT(v4sf a) { + return v4sf{{ + std::sqrt(a.v[0]), + std::sqrt(a.v[1]), + std::sqrt(a.v[2]), + std::sqrt(a.v[3]) + }}; +} + +static inline v4si VM_INT(v4sf a) { + return v4si{{ + int32(a.v[0]), + int32(a.v[1]), + int32(a.v[2]), + int32(a.v[3]) + }}; +} + +static inline v4sf VM_IFLOAT(v4si a) { + return v4sf{{ + float(a.v[0]), + float(a.v[1]), + float(a.v[2]), + float(a.v[3]) + }}; +} + +static SYS_FORCE_INLINE void VM_P_FLOOR() {} + +static SYS_FORCE_INLINE int32 singleIntFloor(float f) { + // Casting to int32 usually truncates toward zero, instead of rounding down, + // so subtract one if the result is above f. + int32 i = int32(f); + i -= (float(i) > f); + return i; +} +static inline v4si VM_FLOOR(v4sf a) { + return v4si{{ + singleIntFloor(a.v[0]), + singleIntFloor(a.v[1]), + singleIntFloor(a.v[2]), + singleIntFloor(a.v[3]) + }}; +} + +static SYS_FORCE_INLINE void VM_E_FLOOR() {} + +static SYS_FORCE_INLINE bool vm_allbits(v4si a) { + return ( + (a.v[0] == -1) && + (a.v[1] == -1) && + (a.v[2] == -1) && + (a.v[3] == -1) + ); +} + +int SYS_FORCE_INLINE _mm_movemask_ps(const v4si& v) { + return ( + int(v.v[0] < 0) | + (int(v.v[1] < 0)<<1) | + (int(v.v[2] < 0)<<2) | + (int(v.v[3] < 0)<<3) + ); +} + +int SYS_FORCE_INLINE _mm_movemask_ps(const v4sf& v) { + // Use std::signbit just in case it needs to distinguish between +0 and -0 + // or between positive and negative NaN values (e.g. these could really + // be integers instead of floats). + return ( + int(std::signbit(v.v[0])) | + (int(std::signbit(v.v[1]))<<1) | + (int(std::signbit(v.v[2]))<<2) | + (int(std::signbit(v.v[3]))<<3) + ); +} +}} +#endif +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * SIMD wrapper classes for 4 floats or 4 ints + */ + +#pragma once + +#ifndef __HDK_VM_SIMD__ +#define __HDK_VM_SIMD__ + + +#include + +//#define FORCE_NON_SIMD + + + + +namespace igl { namespace FastWindingNumber { + +class v4uf; + +class v4uu { +public: + SYS_FORCE_INLINE v4uu() {} + SYS_FORCE_INLINE v4uu(const v4si &v) : vector(v) {} + SYS_FORCE_INLINE v4uu(const v4uu &v) : vector(v.vector) {} + explicit SYS_FORCE_INLINE v4uu(int32 v) { vector = VM_SPLATS(v); } + explicit SYS_FORCE_INLINE v4uu(const int32 v[4]) + { vector = VM_LOAD(v); } + SYS_FORCE_INLINE v4uu(int32 a, int32 b, int32 c, int32 d) + { vector = VM_SPLATS(a, b, c, d); } + + // Assignment + SYS_FORCE_INLINE v4uu operator=(int32 v) + { vector = v4uu(v).vector; return *this; } + SYS_FORCE_INLINE v4uu operator=(v4si v) + { vector = v; return *this; } + SYS_FORCE_INLINE v4uu operator=(const v4uu &v) + { vector = v.vector; return *this; } + + SYS_FORCE_INLINE void condAssign(const v4uu &val, const v4uu &c) + { *this = (c & val) | ((!c) & *this); } + + // Comparison + SYS_FORCE_INLINE v4uu operator == (const v4uu &v) const + { return v4uu(VM_ICMPEQ(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator != (const v4uu &v) const + { return ~(*this == v); } + SYS_FORCE_INLINE v4uu operator > (const v4uu &v) const + { return v4uu(VM_ICMPGT(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator < (const v4uu &v) const + { return v4uu(VM_ICMPLT(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator >= (const v4uu &v) const + { return ~(*this < v); } + SYS_FORCE_INLINE v4uu operator <= (const v4uu &v) const + { return ~(*this > v); } + + SYS_FORCE_INLINE v4uu operator == (int32 v) const { return *this == v4uu(v); } + SYS_FORCE_INLINE v4uu operator != (int32 v) const { return *this != v4uu(v); } + SYS_FORCE_INLINE v4uu operator > (int32 v) const { return *this > v4uu(v); } + SYS_FORCE_INLINE v4uu operator < (int32 v) const { return *this < v4uu(v); } + SYS_FORCE_INLINE v4uu operator >= (int32 v) const { return *this >= v4uu(v); } + SYS_FORCE_INLINE v4uu operator <= (int32 v) const { return *this <= v4uu(v); } + + // Basic math + SYS_FORCE_INLINE v4uu operator+(const v4uu &r) const + { return v4uu(VM_IADD(vector, r.vector)); } + SYS_FORCE_INLINE v4uu operator-(const v4uu &r) const + { return v4uu(VM_ISUB(vector, r.vector)); } + SYS_FORCE_INLINE v4uu operator+=(const v4uu &r) { return (*this = *this + r); } + SYS_FORCE_INLINE v4uu operator-=(const v4uu &r) { return (*this = *this - r); } + SYS_FORCE_INLINE v4uu operator+(int32 r) const { return *this + v4uu(r); } + SYS_FORCE_INLINE v4uu operator-(int32 r) const { return *this - v4uu(r); } + SYS_FORCE_INLINE v4uu operator+=(int32 r) { return (*this = *this + r); } + SYS_FORCE_INLINE v4uu operator-=(int32 r) { return (*this = *this - r); } + + // logical/bitwise + + SYS_FORCE_INLINE v4uu operator||(const v4uu &r) const + { return v4uu(VM_OR(vector, r.vector)); } + SYS_FORCE_INLINE v4uu operator&&(const v4uu &r) const + { return v4uu(VM_AND(vector, r.vector)); } + SYS_FORCE_INLINE v4uu operator^(const v4uu &r) const + { return v4uu(VM_XOR(vector, r.vector)); } + SYS_FORCE_INLINE v4uu operator!() const + { return *this == v4uu(0); } + + SYS_FORCE_INLINE v4uu operator|(const v4uu &r) const { return *this || r; } + SYS_FORCE_INLINE v4uu operator&(const v4uu &r) const { return *this && r; } + SYS_FORCE_INLINE v4uu operator~() const + { return *this ^ v4uu(0xFFFFFFFF); } + + // component + SYS_FORCE_INLINE int32 operator[](int idx) const { return VM_EXTRACT(vector, idx); } + SYS_FORCE_INLINE void setComp(int idx, int32 v) { vector = VM_INSERT(vector, v, idx); } + + v4uf toFloat() const; + +public: + v4si vector; +}; + +class v4uf { +public: + SYS_FORCE_INLINE v4uf() {} + SYS_FORCE_INLINE v4uf(const v4sf &v) : vector(v) {} + SYS_FORCE_INLINE v4uf(const v4uf &v) : vector(v.vector) {} + explicit SYS_FORCE_INLINE v4uf(float v) { vector = VM_SPLATS(v); } + explicit SYS_FORCE_INLINE v4uf(const float v[4]) + { vector = VM_LOAD(v); } + SYS_FORCE_INLINE v4uf(float a, float b, float c, float d) + { vector = VM_SPLATS(a, b, c, d); } + + // Assignment + SYS_FORCE_INLINE v4uf operator=(float v) + { vector = v4uf(v).vector; return *this; } + SYS_FORCE_INLINE v4uf operator=(v4sf v) + { vector = v; return *this; } + SYS_FORCE_INLINE v4uf operator=(const v4uf &v) + { vector = v.vector; return *this; } + + SYS_FORCE_INLINE void condAssign(const v4uf &val, const v4uu &c) + { *this = (val & c) | (*this & ~c); } + + // Comparison + SYS_FORCE_INLINE v4uu operator == (const v4uf &v) const + { return v4uu(VM_CMPEQ(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator != (const v4uf &v) const + { return v4uu(VM_CMPNE(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator > (const v4uf &v) const + { return v4uu(VM_CMPGT(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator < (const v4uf &v) const + { return v4uu(VM_CMPLT(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator >= (const v4uf &v) const + { return v4uu(VM_CMPGE(vector, v.vector)); } + SYS_FORCE_INLINE v4uu operator <= (const v4uf &v) const + { return v4uu(VM_CMPLE(vector, v.vector)); } + + SYS_FORCE_INLINE v4uu operator == (float v) const { return *this == v4uf(v); } + SYS_FORCE_INLINE v4uu operator != (float v) const { return *this != v4uf(v); } + SYS_FORCE_INLINE v4uu operator > (float v) const { return *this > v4uf(v); } + SYS_FORCE_INLINE v4uu operator < (float v) const { return *this < v4uf(v); } + SYS_FORCE_INLINE v4uu operator >= (float v) const { return *this >= v4uf(v); } + SYS_FORCE_INLINE v4uu operator <= (float v) const { return *this <= v4uf(v); } + + + // Basic math + SYS_FORCE_INLINE v4uf operator+(const v4uf &r) const + { return v4uf(VM_ADD(vector, r.vector)); } + SYS_FORCE_INLINE v4uf operator-(const v4uf &r) const + { return v4uf(VM_SUB(vector, r.vector)); } + SYS_FORCE_INLINE v4uf operator-() const + { return v4uf(VM_NEG(vector)); } + SYS_FORCE_INLINE v4uf operator*(const v4uf &r) const + { return v4uf(VM_MUL(vector, r.vector)); } + SYS_FORCE_INLINE v4uf operator/(const v4uf &r) const + { return v4uf(VM_DIV(vector, r.vector)); } + + SYS_FORCE_INLINE v4uf operator+=(const v4uf &r) { return (*this = *this + r); } + SYS_FORCE_INLINE v4uf operator-=(const v4uf &r) { return (*this = *this - r); } + SYS_FORCE_INLINE v4uf operator*=(const v4uf &r) { return (*this = *this * r); } + SYS_FORCE_INLINE v4uf operator/=(const v4uf &r) { return (*this = *this / r); } + + SYS_FORCE_INLINE v4uf operator+(float r) const { return *this + v4uf(r); } + SYS_FORCE_INLINE v4uf operator-(float r) const { return *this - v4uf(r); } + SYS_FORCE_INLINE v4uf operator*(float r) const { return *this * v4uf(r); } + SYS_FORCE_INLINE v4uf operator/(float r) const { return *this / v4uf(r); } + SYS_FORCE_INLINE v4uf operator+=(float r) { return (*this = *this + r); } + SYS_FORCE_INLINE v4uf operator-=(float r) { return (*this = *this - r); } + SYS_FORCE_INLINE v4uf operator*=(float r) { return (*this = *this * r); } + SYS_FORCE_INLINE v4uf operator/=(float r) { return (*this = *this / r); } + + // logical/bitwise + + SYS_FORCE_INLINE v4uf operator||(const v4uu &r) const + { return v4uf(V4SF(VM_OR(V4SI(vector), r.vector))); } + SYS_FORCE_INLINE v4uf operator&&(const v4uu &r) const + { return v4uf(V4SF(VM_AND(V4SI(vector), r.vector))); } + SYS_FORCE_INLINE v4uf operator^(const v4uu &r) const + { return v4uf(V4SF(VM_XOR(V4SI(vector), r.vector))); } + SYS_FORCE_INLINE v4uf operator!() const + { return v4uf(V4SF((*this == v4uf(0.0F)).vector)); } + + SYS_FORCE_INLINE v4uf operator||(const v4uf &r) const + { return v4uf(V4SF(VM_OR(V4SI(vector), V4SI(r.vector)))); } + SYS_FORCE_INLINE v4uf operator&&(const v4uf &r) const + { return v4uf(V4SF(VM_AND(V4SI(vector), V4SI(r.vector)))); } + SYS_FORCE_INLINE v4uf operator^(const v4uf &r) const + { return v4uf(V4SF(VM_XOR(V4SI(vector), V4SI(r.vector)))); } + + SYS_FORCE_INLINE v4uf operator|(const v4uu &r) const { return *this || r; } + SYS_FORCE_INLINE v4uf operator&(const v4uu &r) const { return *this && r; } + SYS_FORCE_INLINE v4uf operator~() const + { return *this ^ v4uu(0xFFFFFFFF); } + + SYS_FORCE_INLINE v4uf operator|(const v4uf &r) const { return *this || r; } + SYS_FORCE_INLINE v4uf operator&(const v4uf &r) const { return *this && r; } + + // component + SYS_FORCE_INLINE float operator[](int idx) const { return VM_EXTRACT(vector, idx); } + SYS_FORCE_INLINE void setComp(int idx, float v) { vector = VM_INSERT(vector, v, idx); } + + // more math + SYS_FORCE_INLINE v4uf abs() const { return v4uf(VM_ABS(vector)); } + SYS_FORCE_INLINE v4uf clamp(const v4uf &low, const v4uf &high) const + { return v4uf( + VM_MIN(VM_MAX(vector, low.vector), high.vector)); } + SYS_FORCE_INLINE v4uf clamp(float low, float high) const + { return v4uf(VM_MIN(VM_MAX(vector, + v4uf(low).vector), v4uf(high).vector)); } + SYS_FORCE_INLINE v4uf recip() const { return v4uf(VM_INVERT(vector)); } + + /// This is a lie, it is a signed int. + SYS_FORCE_INLINE v4uu toUnsignedInt() const { return VM_INT(vector); } + SYS_FORCE_INLINE v4uu toSignedInt() const { return VM_INT(vector); } + + v4uu floor() const + { + VM_P_FLOOR(); + v4uu result = VM_FLOOR(vector); + VM_E_FLOOR(); + return result; + } + + /// Returns the integer part of this float, this becomes the + /// 0..1 fractional component. + v4uu splitFloat() + { + v4uu base = toSignedInt(); + *this -= base.toFloat(); + return base; + } + +#ifdef __SSE__ + template + SYS_FORCE_INLINE v4uf swizzle() const + { + return VM_SHUFFLE(vector); + } +#endif + + SYS_FORCE_INLINE v4uu isFinite() const + { + // If the exponent is the maximum value, it's either infinite or NaN. + const v4si mask = VM_SPLATS(0x7F800000); + return ~v4uu(VM_ICMPEQ(VM_AND(V4SI(vector), mask), mask)); + } + +public: + v4sf vector; +}; + +SYS_FORCE_INLINE v4uf +v4uu::toFloat() const +{ + return v4uf(VM_IFLOAT(vector)); +} + +// +// Custom vector operations +// + +static SYS_FORCE_INLINE v4uf +sqrt(const v4uf &a) +{ + return v4uf(VM_SQRT(a.vector)); +} + +static SYS_FORCE_INLINE v4uf +fabs(const v4uf &a) +{ + return a.abs(); +} + +// Use this operation to mask disabled values to 0 +// rval = !a ? b : 0; + +static SYS_FORCE_INLINE v4uf +andn(const v4uu &a, const v4uf &b) +{ + return v4uf(V4SF(VM_ANDNOT(a.vector, V4SI(b.vector)))); +} + +static SYS_FORCE_INLINE v4uu +andn(const v4uu &a, const v4uu &b) +{ + return v4uu(VM_ANDNOT(a.vector, b.vector)); +} + +// rval = a ? b : c; +static SYS_FORCE_INLINE v4uf +ternary(const v4uu &a, const v4uf &b, const v4uf &c) +{ + return (b & a) | andn(a, c); +} + +static SYS_FORCE_INLINE v4uu +ternary(const v4uu &a, const v4uu &b, const v4uu &c) +{ + return (b & a) | andn(a, c); +} + +// rval = !(a && b) +static SYS_FORCE_INLINE v4uu +nand(const v4uu &a, const v4uu &b) +{ + return !v4uu(VM_AND(a.vector, b.vector)); +} + +static SYS_FORCE_INLINE v4uf +vmin(const v4uf &a, const v4uf &b) +{ + return v4uf(VM_MIN(a.vector, b.vector)); +} + +static SYS_FORCE_INLINE v4uf +vmax(const v4uf &a, const v4uf &b) +{ + return v4uf(VM_MAX(a.vector, b.vector)); +} + +static SYS_FORCE_INLINE v4uf +clamp(const v4uf &a, const v4uf &b, const v4uf &c) +{ + return vmax(vmin(a, c), b); +} + +static SYS_FORCE_INLINE v4uf +clamp(const v4uf &a, float b, float c) +{ + return vmax(vmin(a, v4uf(c)), v4uf(b)); +} + +static SYS_FORCE_INLINE bool +allbits(const v4uu &a) +{ + return vm_allbits(a.vector); +} + +static SYS_FORCE_INLINE bool +anybits(const v4uu &a) +{ + return !allbits(~a); +} + +static SYS_FORCE_INLINE v4uf +madd(const v4uf &v, const v4uf &f, const v4uf &a) +{ + return v4uf(VM_MADD(v.vector, f.vector, a.vector)); +} + +static SYS_FORCE_INLINE v4uf +madd(const v4uf &v, float f, float a) +{ + return v4uf(VM_MADD(v.vector, v4uf(f).vector, v4uf(a).vector)); +} + +static SYS_FORCE_INLINE v4uf +madd(const v4uf &v, float f, const v4uf &a) +{ + return v4uf(VM_MADD(v.vector, v4uf(f).vector, a.vector)); +} + +static SYS_FORCE_INLINE v4uf +msub(const v4uf &v, const v4uf &f, const v4uf &s) +{ + return madd(v, f, -s); +} + +static SYS_FORCE_INLINE v4uf +msub(const v4uf &v, float f, float s) +{ + return madd(v, f, -s); +} + +static SYS_FORCE_INLINE v4uf +lerp(const v4uf &a, const v4uf &b, const v4uf &w) +{ + v4uf w1 = v4uf(1.0F) - w; + return madd(a, w1, b*w); +} + +static SYS_FORCE_INLINE v4uf +luminance(const v4uf &r, const v4uf &g, const v4uf &b, + float rw, float gw, float bw) +{ + return v4uf(madd(r, v4uf(rw), madd(g, v4uf(gw), b * bw))); +} + +static SYS_FORCE_INLINE float +dot3(const v4uf &a, const v4uf &b) +{ + v4uf res = a*b; + return res[0] + res[1] + res[2]; +} + +static SYS_FORCE_INLINE float +dot4(const v4uf &a, const v4uf &b) +{ + v4uf res = a*b; + return res[0] + res[1] + res[2] + res[3]; +} + +static SYS_FORCE_INLINE float +length(const v4uf &a) +{ + return SYSsqrt(dot3(a, a)); +} + +static SYS_FORCE_INLINE v4uf +normalize(const v4uf &a) +{ + return a / length(a); +} + +static SYS_FORCE_INLINE v4uf +cross(const v4uf &a, const v4uf &b) +{ + return v4uf(a[1]*b[2] - a[2]*b[1], + a[2]*b[0] - a[0]*b[2], + a[0]*b[1] - a[1]*b[0], 0); +} + +// Currently there is no specific support for signed integers +typedef v4uu v4ui; + +// Assuming that ptr is an array of elements of type STYPE, this operation +// will return the index of the first element that is aligned to (1< +#include +#include +#include + +namespace igl { namespace FastWindingNumber { + + /// This routine describes how to change the size of an array. + /// It must increase the current_size by at least one! + /// + /// Current expected sequence of small sizes: + /// 4, 8, 16, 32, 48, 64, 80, 96, 112, + /// 128, 256, 384, 512, 640, 768, 896, 1024, + /// (increases by approx factor of 1.125 each time after this) +template +static inline T +UTbumpAlloc(T current_size) +{ + // NOTE: These must be powers of two. See below. + constexpr T SMALL_ALLOC(16); + constexpr T BIG_ALLOC(128); + + // For small values, we increment by fixed amounts. For + // large values, we increment by one eighth of the current size. + // This prevents n^2 behaviour with allocation one element at a time. + // A factor of 1/8 will waste 1/16 the memory on average, and will + // double the size of the array in approximately 6 reallocations. + if (current_size < T(8)) + { + return (current_size < T(4)) ? T(4) : T(8); + } + if (current_size < T(BIG_ALLOC)) + { + // Snap up to next multiple of SMALL_ALLOC (must be power of 2) + return (current_size + T(SMALL_ALLOC)) & ~T(SMALL_ALLOC-1); + } + if (current_size < T(BIG_ALLOC * 8)) + { + // Snap up to next multiple of BIG_ALLOC (must be power of 2) + return (current_size + T(BIG_ALLOC)) & ~T(BIG_ALLOC-1); + } + + T bump = current_size >> 3; // Divided by 8. + current_size += bump; + return current_size; +} + +template +class UT_Array +{ +public: + typedef T value_type; + + typedef int (*Comparator)(const T *, const T *); + + /// Copy constructor. It duplicates the data. + /// It's marked explicit so that it's not accidentally passed by value. + /// You can always pass by reference and then copy it, if needed. + /// If you have a line like: + /// UT_Array a = otherarray; + /// and it really does need to copy instead of referencing, + /// you can rewrite it as: + /// UT_Array a(otherarray); + inline explicit UT_Array(const UT_Array &a); + + /// Move constructor. Steals the working data from the original. + inline UT_Array(UT_Array &&a) noexcept; + + /// Construct based on given capacity and size + UT_Array(exint capacity, exint size) + { + myData = capacity ? allocateCapacity(capacity) : NULL; + if (capacity < size) + size = capacity; + mySize = size; + myCapacity = capacity; + trivialConstructRange(myData, mySize); + } + + /// Construct based on given capacity with a size of 0 + explicit UT_Array(exint capacity = 0) : myCapacity(capacity), mySize(0) + { + myData = capacity ? allocateCapacity(capacity) : NULL; + } + + /// Construct with the contents of an initializer list + inline explicit UT_Array(std::initializer_list init); + + inline ~UT_Array(); + + inline void swap(UT_Array &other); + + /// Append an element to the current elements and return its index in the + /// array, or insert the element at a specified position; if necessary, + /// insert() grows the array to accommodate the element. The insert + /// methods use the assignment operator '=' to place the element into the + /// right spot; be aware that '=' works differently on objects and pointers. + /// The test for duplicates uses the logical equal operator '=='; as with + /// '=', the behaviour of the equality operator on pointers versus objects + /// is not the same. + /// Use the subscript operators instead of insert() if you are appending + /// to the array, or if you don't mind overwriting the element already + /// inserted at the given index. + exint append(void) { return insert(mySize); } + exint append(const T &t) { return appendImpl(t); } + exint append(T &&t) { return appendImpl(std::move(t)); } + inline void append(const T *pt, exint count); + inline void appendMultiple(const T &t, exint count); + inline exint insert(exint index); + exint insert(const T &t, exint i) + { return insertImpl(t, i); } + exint insert(T &&t, exint i) + { return insertImpl(std::move(t), i); } + + /// Adds a new element to the array (resizing if necessary) and forwards + /// the given arguments to T's constructor. + /// NOTE: Unlike append(), the arguments cannot reference any existing + /// elements in the array. Checking for and handling such cases would + /// remove most of the performance gain versus append(T(...)). Debug builds + /// will assert that the arguments are valid. + template + inline exint emplace_back(S&&... s); + + /// Takes another T array and concatenate it onto my end + inline exint concat(const UT_Array &a); + + /// Insert an element "count" times at the given index. Return the index. + inline exint multipleInsert(exint index, exint count); + + /// An alias for unique element insertion at a certain index. Also used by + /// the other insertion methods. + exint insertAt(const T &t, exint index) + { return insertImpl(t, index); } + + /// Return true if given index is valid. + bool isValidIndex(exint index) const + { return (index >= 0 && index < mySize); } + + /// Remove one element from the array given its + /// position in the list, and fill the gap by shifting the elements down + /// by one position. Return the index of the element removed or -1 if + /// the index was out of bounds. + exint removeIndex(exint index) + { + return isValidIndex(index) ? removeAt(index) : -1; + } + void removeLast() + { + if (mySize) removeAt(mySize-1); + } + + /// Remove the range [begin_i,end_i) of elements from the array. + inline void removeRange(exint begin_i, exint end_i); + + /// Remove the range [begin_i, end_i) of elements from this array and place + /// them in the dest array, shrinking/growing the dest array as necessary. + inline void extractRange(exint begin_i, exint end_i, + UT_Array& dest); + + /// Removes all matching elements from the list, shuffling down and changing + /// the size appropriately. + /// Returns the number of elements left. + template + inline exint removeIf(IsEqual is_equal); + + /// Remove all matching elements. Also sets the capacity of the array. + template + void collapseIf(IsEqual is_equal) + { + removeIf(is_equal); + setCapacity(size()); + } + + /// Move howMany objects starting at index srcIndex to destIndex; + /// This method will remove the elements at [srcIdx, srcIdx+howMany) and + /// then insert them at destIdx. This method can be used in place of + /// the old shift() operation. + inline void move(exint srcIdx, exint destIdx, exint howMany); + + /// Cyclically shifts the entire array by howMany + inline void cycle(exint howMany); + + /// Quickly set the array to a single value. + inline void constant(const T &v); + /// Zeros the array if a POD type, else trivial constructs if a class type. + inline void zero(); + + /// The fastest search possible, which does pointer arithmetic to find the + /// index of the element. WARNING: index() does no out-of-bounds checking. + exint index(const T &t) const { return &t - myData; } + exint safeIndex(const T &t) const + { + return (&t >= myData && &t < (myData + mySize)) + ? &t - myData : -1; + } + + /// Set the capacity of the array, i.e. grow it or shrink it. The + /// function copies the data after reallocating space for the array. + inline void setCapacity(exint newcapacity); + void setCapacityIfNeeded(exint mincapacity) + { + if (capacity() < mincapacity) + setCapacity(mincapacity); + } + /// If the capacity is smaller than mincapacity, expand the array + /// to at least mincapacity and to at least a constant factor of the + /// array's previous capacity, to avoid having a linear number of + /// reallocations in a linear number of calls to bumpCapacity. + void bumpCapacity(exint mincapacity) + { + if (capacity() >= mincapacity) + return; + // The following 4 lines are just + // SYSmax(mincapacity, UTbumpAlloc(capacity())), avoiding SYSmax + exint bumped = UTbumpAlloc(capacity()); + exint newcapacity = mincapacity; + if (bumped > mincapacity) + newcapacity = bumped; + setCapacity(newcapacity); + } + + /// First bumpCapacity to ensure that there's space for newsize, + /// expanding either not at all or by at least a constant factor + /// of the array's previous capacity, + /// then set the size to newsize. + void bumpSize(exint newsize) + { + bumpCapacity(newsize); + setSize(newsize); + } + /// NOTE: bumpEntries() will be deprecated in favour of bumpSize() in a + /// future version. + void bumpEntries(exint newsize) + { + bumpSize(newsize); + } + + /// Query the capacity, i.e. the allocated length of the array. + /// NOTE: capacity() >= size(). + exint capacity() const { return myCapacity; } + /// Query the size, i.e. the number of occupied elements in the array. + /// NOTE: capacity() >= size(). + exint size() const { return mySize; } + /// Alias of size(). size() is preferred. + exint entries() const { return mySize; } + /// Returns true iff there are no occupied elements in the array. + bool isEmpty() const { return mySize==0; } + + /// Set the size, the number of occupied elements in the array. + /// NOTE: This will not do bumpCapacity, so if you call this + /// n times to increase the size, it may take + /// n^2 time. + void setSize(exint newsize) + { + if (newsize < 0) + newsize = 0; + if (newsize == mySize) + return; + setCapacityIfNeeded(newsize); + if (mySize > newsize) + trivialDestructRange(myData + newsize, mySize - newsize); + else // newsize > mySize + trivialConstructRange(myData + mySize, newsize - mySize); + mySize = newsize; + } + /// Alias of setSize(). setSize() is preferred. + void entries(exint newsize) + { + setSize(newsize); + } + /// Set the size, but unlike setSize(newsize), this function + /// will not initialize new POD elements to zero. Non-POD data types + /// will still have their constructors called. + /// This function is faster than setSize(ne) if you intend to fill in + /// data for all elements. + void setSizeNoInit(exint newsize) + { + if (newsize < 0) + newsize = 0; + if (newsize == mySize) + return; + setCapacityIfNeeded(newsize); + if (mySize > newsize) + trivialDestructRange(myData + newsize, mySize - newsize); + else if (!isPOD()) // newsize > mySize + trivialConstructRange(myData + mySize, newsize - mySize); + mySize = newsize; + } + + /// Decreases, but never expands, to the given maxsize. + void truncate(exint maxsize) + { + if (maxsize >= 0 && size() > maxsize) + setSize(maxsize); + } + /// Resets list to an empty list. + void clear() { + // Don't call setSize(0) since that would require a valid default + // constructor. + trivialDestructRange(myData, mySize); + mySize = 0; + } + + /// Assign array a to this array by copying each of a's elements with + /// memcpy for POD types, and with copy construction for class types. + inline UT_Array & operator=(const UT_Array &a); + + /// Replace the contents with those from the initializer_list ilist + inline UT_Array & operator=(std::initializer_list ilist); + + /// Move the contents of array a to this array. + inline UT_Array & operator=(UT_Array &&a); + + /// Compare two array and return true if they are equal and false otherwise. + /// Two elements are checked against each other using operator '==' or + /// compare() respectively. + /// NOTE: The capacities of the arrays are not checked when + /// determining whether they are equal. + inline bool operator==(const UT_Array &a) const; + inline bool operator!=(const UT_Array &a) const; + + /// Subscript operator + /// NOTE: This does NOT do any bounds checking unless paranoid + /// asserts are enabled. + T & operator()(exint i) + { + UT_ASSERT_P(i >= 0 && i < mySize); + return myData[i]; + } + /// Const subscript operator + /// NOTE: This does NOT do any bounds checking unless paranoid + /// asserts are enabled. + const T & operator()(exint i) const + { + UT_ASSERT_P(i >= 0 && i < mySize); + return myData[i]; + } + + /// Subscript operator + /// NOTE: This does NOT do any bounds checking unless paranoid + /// asserts are enabled. + T & operator[](exint i) + { + UT_ASSERT_P(i >= 0 && i < mySize); + return myData[i]; + } + /// Const subscript operator + /// NOTE: This does NOT do any bounds checking unless paranoid + /// asserts are enabled. + const T & operator[](exint i) const + { + UT_ASSERT_P(i >= 0 && i < mySize); + return myData[i]; + } + + /// forcedRef(exint) will grow the array if necessary, initializing any + /// new elements to zero for POD types and default constructing for + /// class types. + T & forcedRef(exint i) + { + UT_ASSERT_P(i >= 0); + if (i >= mySize) + bumpSize(i+1); + return myData[i]; + } + + /// forcedGet(exint) does NOT grow the array, and will return default + /// objects for out of bound array indices. + T forcedGet(exint i) const + { + return (i >= 0 && i < mySize) ? myData[i] : T(); + } + + T & last() + { + UT_ASSERT_P(mySize); + return myData[mySize-1]; + } + const T & last() const + { + UT_ASSERT_P(mySize); + return myData[mySize-1]; + } + + T * getArray() const { return myData; } + const T * getRawArray() const { return myData; } + + T * array() { return myData; } + const T * array() const { return myData; } + + T * data() { return myData; } + const T * data() const { return myData; } + + /// This method allows you to swap in a new raw T array, which must be + /// the same size as myCapacity. Use caution with this method. + T * aliasArray(T *newdata) + { T *data = myData; myData = newdata; return data; } + + template + class base_iterator : + public std::iterator + { + public: + typedef IT& reference; + typedef IT* pointer; + + // Note: When we drop gcc 4.4 support and allow range-based for + // loops, we should also drop atEnd(), which means we can drop + // myEnd here. + base_iterator() : myCurrent(NULL), myEnd(NULL) {} + + // Allow iterator to const_iterator conversion + template + base_iterator(const base_iterator &src) + : myCurrent(src.myCurrent), myEnd(src.myEnd) {} + + pointer operator->() const + { return FORWARD ? myCurrent : myCurrent - 1; } + + reference operator*() const + { return FORWARD ? *myCurrent : myCurrent[-1]; } + + reference item() const + { return FORWARD ? *myCurrent : myCurrent[-1]; } + + reference operator[](exint n) const + { return FORWARD ? myCurrent[n] : myCurrent[-n - 1]; } + + /// Pre-increment operator + base_iterator &operator++() + { + if (FORWARD) ++myCurrent; else --myCurrent; + return *this; + } + /// Post-increment operator + base_iterator operator++(int) + { + base_iterator tmp = *this; + if (FORWARD) ++myCurrent; else --myCurrent; + return tmp; + } + /// Pre-decrement operator + base_iterator &operator--() + { + if (FORWARD) --myCurrent; else ++myCurrent; + return *this; + } + /// Post-decrement operator + base_iterator operator--(int) + { + base_iterator tmp = *this; + if (FORWARD) --myCurrent; else ++myCurrent; + return tmp; + } + + base_iterator &operator+=(exint n) + { + if (FORWARD) + myCurrent += n; + else + myCurrent -= n; + return *this; + } + base_iterator operator+(exint n) const + { + if (FORWARD) + return base_iterator(myCurrent + n, myEnd); + else + return base_iterator(myCurrent - n, myEnd); + } + + base_iterator &operator-=(exint n) + { return (*this) += (-n); } + base_iterator operator-(exint n) const + { return (*this) + (-n); } + + bool atEnd() const { return myCurrent == myEnd; } + void advance() { this->operator++(); } + + // Comparators + template + bool operator==(const base_iterator &r) const + { return myCurrent == r.myCurrent; } + + template + bool operator!=(const base_iterator &r) const + { return myCurrent != r.myCurrent; } + + template + bool operator<(const base_iterator &r) const + { + if (FORWARD) + return myCurrent < r.myCurrent; + else + return r.myCurrent < myCurrent; + } + + template + bool operator>(const base_iterator &r) const + { + if (FORWARD) + return myCurrent > r.myCurrent; + else + return r.myCurrent > myCurrent; + } + + template + bool operator<=(const base_iterator &r) const + { + if (FORWARD) + return myCurrent <= r.myCurrent; + else + return r.myCurrent <= myCurrent; + } + + template + bool operator>=(const base_iterator &r) const + { + if (FORWARD) + return myCurrent >= r.myCurrent; + else + return r.myCurrent >= myCurrent; + } + + // Difference operator for std::distance + template + exint operator-(const base_iterator &r) const + { + if (FORWARD) + return exint(myCurrent - r.myCurrent); + else + return exint(r.myCurrent - myCurrent); + } + + + protected: + friend class UT_Array; + base_iterator(IT *c, IT *e) : myCurrent(c), myEnd(e) {} + private: + + IT *myCurrent; + IT *myEnd; + }; + + typedef base_iterator iterator; + typedef base_iterator const_iterator; + typedef base_iterator reverse_iterator; + typedef base_iterator const_reverse_iterator; + typedef const_iterator traverser; // For backward compatibility + + /// Begin iterating over the array. The contents of the array may be + /// modified during the traversal. + iterator begin() + { + return iterator(myData, myData + mySize); + } + /// End iterator. + iterator end() + { + return iterator(myData + mySize, + myData + mySize); + } + + /// Begin iterating over the array. The array may not be modified during + /// the traversal. + const_iterator begin() const + { + return const_iterator(myData, myData + mySize); + } + /// End const iterator. Consider using it.atEnd() instead. + const_iterator end() const + { + return const_iterator(myData + mySize, + myData + mySize); + } + + /// Begin iterating over the array in reverse. + reverse_iterator rbegin() + { + return reverse_iterator(myData + mySize, + myData); + } + /// End reverse iterator. + reverse_iterator rend() + { + return reverse_iterator(myData, myData); + } + /// Begin iterating over the array in reverse. + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(myData + mySize, + myData); + } + /// End reverse iterator. Consider using it.atEnd() instead. + const_reverse_iterator rend() const + { + return const_reverse_iterator(myData, myData); + } + + /// Remove item specified by the reverse_iterator. + void removeItem(const reverse_iterator &it) + { + removeAt(&it.item() - myData); + } + + + /// Very dangerous methods to share arrays. + /// The array is not aware of the sharing, so ensure you clear + /// out the array prior a destructor or setCapacity operation. + void unsafeShareData(UT_Array &src) + { + myData = src.myData; + myCapacity = src.myCapacity; + mySize = src.mySize; + } + void unsafeShareData(T *src, exint srcsize) + { + myData = src; + myCapacity = srcsize; + mySize = srcsize; + } + void unsafeShareData(T *src, exint size, exint capacity) + { + myData = src; + mySize = size; + myCapacity = capacity; + } + void unsafeClearData() + { + myData = NULL; + myCapacity = 0; + mySize = 0; + } + + /// Returns true if the data used by the array was allocated on the heap. + inline bool isHeapBuffer() const + { + return (myData != (T *)(((char*)this) + sizeof(*this))); + } + inline bool isHeapBuffer(T* data) const + { + return (data != (T *)(((char*)this) + sizeof(*this))); + } + +protected: + // Check whether T may have a constructor, destructor, or copy + // constructor. This test is conservative in that some POD types will + // not be recognized as POD by this function. To mark your type as POD, + // use the SYS_DECLARE_IS_POD() macro in SYS_TypeDecorate.h. + static constexpr SYS_FORCE_INLINE bool isPOD() + { + return std::is_pod::value; + } + + /// Implements both append(const T &) and append(T &&) via perfect + /// forwarding. Unlike the variadic emplace_back(), its argument may be a + /// reference to another element in the array. + template + inline exint appendImpl(S &&s); + + /// Similar to appendImpl() but for insertion. + template + inline exint insertImpl(S &&s, exint index); + + // Construct the given type + template + static void construct(T &dst, S&&... s) + { + new (&dst) T(std::forward(s)...); + } + + // Copy construct the given type + static void copyConstruct(T &dst, const T &src) + { + if (isPOD()) + dst = src; + else + new (&dst) T(src); + } + static void copyConstructRange(T *dst, const T *src, exint n) + { + if (isPOD()) + { + if (n > 0) + { + ::memcpy((void *)dst, (const void *)src, + n * sizeof(T)); + } + } + else + { + for (exint i = 0; i < n; i++) + new (&dst[i]) T(src[i]); + } + } + + /// Element Constructor + static void trivialConstruct(T &dst) + { + if (!isPOD()) + new (&dst) T(); + else + memset((void *)&dst, 0, sizeof(T)); + } + static void trivialConstructRange(T *dst, exint n) + { + if (!isPOD()) + { + for (exint i = 0; i < n; i++) + new (&dst[i]) T(); + } + else if (n == 1) + { + // Special case for n == 1. If the size parameter + // passed to memset is known at compile time, this + // function call will be inlined. This results in + // much faster performance than a real memset + // function call which is required in the case + // below, where n is not known until runtime. + // This makes calls to append() much faster. + memset((void *)dst, 0, sizeof(T)); + } + else + memset((void *)dst, 0, sizeof(T) * n); + } + + /// Element Destructor + static void trivialDestruct(T &dst) + { + if (!isPOD()) + dst.~T(); + } + static void trivialDestructRange(T *dst, exint n) + { + if (!isPOD()) + { + for (exint i = 0; i < n; i++) + dst[i].~T(); + } + } + +private: + /// Pointer to the array of elements of type T + T *myData; + + /// The number of elements for which we have allocated memory + exint myCapacity; + + /// The actual number of valid elements in the array + exint mySize; + + // The guts of the remove() methods. + inline exint removeAt(exint index); + + inline T * allocateCapacity(exint num_items); +}; +}} + + + +#endif // __UT_ARRAY_H_INCLUDED__ +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * This is meant to be included by UT_Array.h and includes + * the template implementations needed by external code. + */ + +#pragma once + +#ifndef __UT_ARRAYIMPL_H_INCLUDED__ +#define __UT_ARRAYIMPL_H_INCLUDED__ + + + + +#include +#include +#include +#include + +namespace igl { namespace FastWindingNumber { + +// Implemented in UT_Array.C +extern void ut_ArrayImplFree(void *p); + + +template +inline UT_Array::UT_Array(const UT_Array &a) + : myCapacity(a.size()), mySize(a.size()) +{ + if (myCapacity) + { + myData = allocateCapacity(myCapacity); + copyConstructRange(myData, a.array(), mySize); + } + else + { + myData = nullptr; + } +} + +template +inline UT_Array::UT_Array(std::initializer_list init) + : myCapacity(init.size()), mySize(init.size()) +{ + if (myCapacity) + { + myData = allocateCapacity(myCapacity); + copyConstructRange(myData, init.begin(), mySize); + } + else + { + myData = nullptr; + } +} + +template +inline UT_Array::UT_Array(UT_Array &&a) noexcept +{ + if (!a.isHeapBuffer()) + { + myData = nullptr; + myCapacity = 0; + mySize = 0; + operator=(std::move(a)); + return; + } + + myCapacity = a.myCapacity; + mySize = a.mySize; + myData = a.myData; + a.myCapacity = a.mySize = 0; + a.myData = nullptr; +} + + +template +inline UT_Array::~UT_Array() +{ + // NOTE: We call setCapacity to ensure that we call trivialDestructRange, + // then call free on myData. + setCapacity(0); +} + +template +inline T * +UT_Array::allocateCapacity(exint capacity) +{ + T *data = (T *)malloc(capacity * sizeof(T)); + // Avoid degenerate case if we happen to be aliased the wrong way + if (!isHeapBuffer(data)) + { + T *prev = data; + data = (T *)malloc(capacity * sizeof(T)); + ut_ArrayImplFree(prev); + } + return data; +} + +template +inline void +UT_Array::swap( UT_Array &other ) +{ + std::swap( myData, other.myData ); + std::swap( myCapacity, other.myCapacity ); + std::swap( mySize, other.mySize ); +} + + +template +inline exint +UT_Array::insert(exint index) +{ + if (index >= mySize) + { + bumpCapacity(index + 1); + + trivialConstructRange(myData + mySize, index - mySize + 1); + + mySize = index+1; + return index; + } + bumpCapacity(mySize + 1); + + UT_ASSERT_P(index >= 0); + ::memmove((void *)&myData[index+1], (void *)&myData[index], + ((mySize-index)*sizeof(T))); + + trivialConstruct(myData[index]); + + mySize++; + return index; +} + +template +template +inline exint +UT_Array::appendImpl(S &&s) +{ + if (mySize == myCapacity) + { + exint idx = safeIndex(s); + + // NOTE: UTbumpAlloc always returns a strictly larger value. + setCapacity(UTbumpAlloc(myCapacity)); + if (idx >= 0) + construct(myData[mySize], std::forward(myData[idx])); + else + construct(myData[mySize], std::forward(s)); + } + else + { + construct(myData[mySize], std::forward(s)); + } + return mySize++; +} + +template +template +inline exint +UT_Array::emplace_back(S&&... s) +{ + if (mySize == myCapacity) + setCapacity(UTbumpAlloc(myCapacity)); + + construct(myData[mySize], std::forward(s)...); + return mySize++; +} + +template +inline void +UT_Array::append(const T *pt, exint count) +{ + bumpCapacity(mySize + count); + copyConstructRange(myData + mySize, pt, count); + mySize += count; +} + +template +inline void +UT_Array::appendMultiple(const T &t, exint count) +{ + UT_ASSERT_P(count >= 0); + if (count <= 0) + return; + if (mySize + count >= myCapacity) + { + exint tidx = safeIndex(t); + + bumpCapacity(mySize + count); + + for (exint i = 0; i < count; i++) + copyConstruct(myData[mySize+i], tidx >= 0 ? myData[tidx] : t); + } + else + { + for (exint i = 0; i < count; i++) + copyConstruct(myData[mySize+i], t); + } + mySize += count; +} + +template +inline exint +UT_Array::concat(const UT_Array &a) +{ + bumpCapacity(mySize + a.mySize); + copyConstructRange(myData + mySize, a.myData, a.mySize); + mySize += a.mySize; + + return mySize; +} + +template +inline exint +UT_Array::multipleInsert(exint beg_index, exint count) +{ + exint end_index = beg_index + count; + + if (beg_index >= mySize) + { + bumpCapacity(end_index); + + trivialConstructRange(myData + mySize, end_index - mySize); + + mySize = end_index; + return beg_index; + } + bumpCapacity(mySize+count); + + ::memmove((void *)&myData[end_index], (void *)&myData[beg_index], + ((mySize-beg_index)*sizeof(T))); + mySize += count; + + trivialConstructRange(myData + beg_index, count); + + return beg_index; +} + +template +template +inline exint +UT_Array::insertImpl(S &&s, exint index) +{ + if (index == mySize) + { + // This case avoids an extraneous call to trivialConstructRange() + // which the compiler may not optimize out. + (void) appendImpl(std::forward(s)); + } + else if (index > mySize) + { + exint src_i = safeIndex(s); + + bumpCapacity(index + 1); + + trivialConstructRange(myData + mySize, index - mySize); + + if (src_i >= 0) + construct(myData[index], std::forward(myData[src_i])); + else + construct(myData[index], std::forward(s)); + + mySize = index + 1; + } + else // (index < mySize) + { + exint src_i = safeIndex(s); + + bumpCapacity(mySize + 1); + + ::memmove((void *)&myData[index+1], (void *)&myData[index], + ((mySize-index)*sizeof(T))); + + if (src_i >= index) + ++src_i; + + if (src_i >= 0) + construct(myData[index], std::forward(myData[src_i])); + else + construct(myData[index], std::forward(s)); + + ++mySize; + } + + return index; +} + +template +inline exint +UT_Array::removeAt(exint idx) +{ + trivialDestruct(myData[idx]); + if (idx != --mySize) + { + ::memmove((void *)&myData[idx], (void *)&myData[idx+1], + ((mySize-idx)*sizeof(T))); + } + + return idx; +} + +template +inline void +UT_Array::removeRange(exint begin_i, exint end_i) +{ + UT_ASSERT(begin_i <= end_i); + UT_ASSERT(end_i <= size()); + if (end_i < size()) + { + trivialDestructRange(myData + begin_i, end_i - begin_i); + ::memmove((void *)&myData[begin_i], (void *)&myData[end_i], + (mySize - end_i)*sizeof(T)); + } + setSize(mySize - (end_i - begin_i)); +} + +template +inline void +UT_Array::extractRange(exint begin_i, exint end_i, UT_Array& dest) +{ + UT_ASSERT_P(begin_i >= 0); + UT_ASSERT_P(begin_i <= end_i); + UT_ASSERT_P(end_i <= size()); + UT_ASSERT(this != &dest); + + exint nelements = end_i - begin_i; + + // grow the raw array if necessary. + dest.setCapacityIfNeeded(nelements); + + ::memmove((void*)dest.myData, (void*)&myData[begin_i], + nelements * sizeof(T)); + dest.mySize = nelements; + + // we just asserted this was true, but just in case + if (this != &dest) + { + if (end_i < size()) + { + ::memmove((void*)&myData[begin_i], (void*)&myData[end_i], + (mySize - end_i) * sizeof(T)); + } + setSize(mySize - nelements); + } +} + +template +inline void +UT_Array::move(exint srcIdx, exint destIdx, exint howMany) +{ + // Make sure all the parameters are valid. + if( srcIdx < 0 ) + srcIdx = 0; + if( destIdx < 0 ) + destIdx = 0; + // If we are told to move a set of elements that would extend beyond the + // end of the current array, trim the group. + if( srcIdx + howMany > size() ) + howMany = size() - srcIdx; + // If the destIdx would have us move the source beyond the end of the + // current array, move the destIdx back. + if( destIdx + howMany > size() ) + destIdx = size() - howMany; + if( srcIdx != destIdx && howMany > 0 ) + { + void **tmp = 0; + exint savelen; + + savelen = SYSabs(srcIdx - destIdx); + tmp = (void **)::malloc(savelen*sizeof(T)); + if( srcIdx > destIdx && howMany > 0 ) + { + // We're moving the group backwards. Save all the stuff that + // we would overwrite, plus everything beyond that to the + // start of the source group. Then move the source group, then + // tack the saved data onto the end of the moved group. + ::memcpy(tmp, (void *)&myData[destIdx], (savelen*sizeof(T))); + ::memmove((void *)&myData[destIdx], (void *)&myData[srcIdx], + (howMany*sizeof(T))); + ::memcpy((void *)&myData[destIdx+howMany], tmp, (savelen*sizeof(T))); + } + if( srcIdx < destIdx && howMany > 0 ) + { + // We're moving the group forwards. Save from the end of the + // group being moved to the end of the where the destination + // group will end up. Then copy the source to the destination. + // Then move back up to the original source location and drop + // in our saved data. + ::memcpy(tmp, (void *)&myData[srcIdx+howMany], (savelen*sizeof(T))); + ::memmove((void *)&myData[destIdx], (void *)&myData[srcIdx], + (howMany*sizeof(T))); + ::memcpy((void *)&myData[srcIdx], tmp, (savelen*sizeof(T))); + } + ::free(tmp); + } +} + +template +template +inline exint +UT_Array::removeIf(IsEqual is_equal) +{ + // Move dst to the first element to remove. + exint dst; + for (dst = 0; dst < mySize; dst++) + { + if (is_equal(myData[dst])) + break; + } + // Now start looking at all the elements past the first one to remove. + for (exint idx = dst+1; idx < mySize; idx++) + { + if (!is_equal(myData[idx])) + { + UT_ASSERT(idx != dst); + myData[dst] = myData[idx]; + dst++; + } + // On match, ignore. + } + // New size + mySize = dst; + return mySize; +} + +template +inline void +UT_Array::cycle(exint howMany) +{ + char *tempPtr; + exint numShift; // The number of items we shift + exint remaining; // mySize - numShift + + if (howMany == 0 || mySize < 1) return; + + numShift = howMany % (exint)mySize; + if (numShift < 0) numShift += mySize; + remaining = mySize - numShift; + tempPtr = new char[numShift*sizeof(T)]; + + ::memmove(tempPtr, (void *)&myData[remaining], (numShift * sizeof(T))); + ::memmove((void *)&myData[numShift], (void *)&myData[0], (remaining * sizeof(T))); + ::memmove((void *)&myData[0], tempPtr, (numShift * sizeof(T))); + + delete [] tempPtr; +} + +template +inline void +UT_Array::constant(const T &value) +{ + for (exint i = 0; i < mySize; i++) + { + myData[i] = value; + } +} + +template +inline void +UT_Array::zero() +{ + if (isPOD()) + ::memset((void *)myData, 0, mySize*sizeof(T)); + else + trivialConstructRange(myData, mySize); +} + +template +inline void +UT_Array::setCapacity(exint capacity) +{ + // Do nothing when new capacity is the same as the current + if (capacity == myCapacity) + return; + + // Special case for non-heap buffers + if (!isHeapBuffer()) + { + if (capacity < mySize) + { + // Destroy the extra elements without changing myCapacity + trivialDestructRange(myData + capacity, mySize - capacity); + mySize = capacity; + } + else if (capacity > myCapacity) + { + T *prev = myData; + myData = (T *)malloc(sizeof(T) * capacity); + // myData is safe because we're already a stack buffer + UT_ASSERT_P(isHeapBuffer()); + if (mySize > 0) + memcpy((void *)myData, (void *)prev, sizeof(T) * mySize); + myCapacity = capacity; + } + else + { + // Keep myCapacity unchanged in this case + UT_ASSERT_P(capacity >= mySize && capacity <= myCapacity); + } + return; + } + + if (capacity == 0) + { + if (myData) + { + trivialDestructRange(myData, mySize); + free(myData); + } + myData = 0; + myCapacity = 0; + mySize = 0; + return; + } + + if (capacity < mySize) + { + trivialDestructRange(myData + capacity, mySize - capacity); + mySize = capacity; + } + + if (myData) + myData = (T *)realloc(myData, capacity*sizeof(T)); + else + myData = (T *)malloc(sizeof(T) * capacity); + + // Avoid degenerate case if we happen to be aliased the wrong way + if (!isHeapBuffer()) + { + T *prev = myData; + myData = (T *)malloc(sizeof(T) * capacity); + if (mySize > 0) + memcpy((void *)myData, (void *)prev, sizeof(T) * mySize); + ut_ArrayImplFree(prev); + } + + myCapacity = capacity; + UT_ASSERT(myData); +} + +template +inline UT_Array & +UT_Array::operator=(const UT_Array &a) +{ + if (this == &a) + return *this; + + // Grow the raw array if necessary. + setCapacityIfNeeded(a.size()); + + // Make sure destructors and constructors are called on all elements + // being removed/added. + trivialDestructRange(myData, mySize); + copyConstructRange(myData, a.myData, a.size()); + + mySize = a.size(); + + return *this; +} + +template +inline UT_Array & +UT_Array::operator=(std::initializer_list a) +{ + const exint new_size = a.size(); + + // Grow the raw array if necessary. + setCapacityIfNeeded(new_size); + + // Make sure destructors and constructors are called on all elements + // being removed/added. + trivialDestructRange(myData, mySize); + + copyConstructRange(myData, a.begin(), new_size); + + mySize = new_size; + + return *this; +} + +template +inline UT_Array & +UT_Array::operator=(UT_Array &&a) +{ + if (!a.isHeapBuffer()) + { + // Cannot steal from non-heap buffers + clear(); + const exint n = a.size(); + setCapacityIfNeeded(n); + if (isPOD()) + { + if (n > 0) + memcpy(myData, a.myData, n * sizeof(T)); + } + else + { + for (exint i = 0; i < n; ++i) + new (&myData[i]) T(std::move(a.myData[i])); + } + mySize = a.mySize; + a.mySize = 0; + return *this; + } + // else, just steal even if we're a small buffer + + // Destroy all the elements we're currently holding. + if (myData) + { + trivialDestructRange(myData, mySize); + if (isHeapBuffer()) + ::free(myData); + } + + // Move the contents of the other array to us and empty the other container + // so that it destructs cleanly. + myCapacity = a.myCapacity; + mySize = a.mySize; + myData = a.myData; + a.myCapacity = a.mySize = 0; + a.myData = nullptr; + + return *this; +} + + +template +inline bool +UT_Array::operator==(const UT_Array &a) const +{ + if (this == &a) return true; + if (mySize != a.size()) return false; + for (exint i = 0; i < mySize; i++) + if (!(myData[i] == a(i))) return false; + return true; +} + +template +inline bool +UT_Array::operator!=(const UT_Array &a) const +{ + return (!operator==(a)); +} + +}} + +#endif // __UT_ARRAYIMPL_H_INCLUDED__ +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Special case for arrays that are usually small, + * to avoid a heap allocation when the array really is small. + */ + +#pragma once + +#ifndef __UT_SMALLARRAY_H_INCLUDED__ +#define __UT_SMALLARRAY_H_INCLUDED__ + + + +#include +#include +namespace igl { namespace FastWindingNumber { + +/// An array class with the small buffer optimization, making it ideal for +/// cases when you know it will only contain a few elements at the expense of +/// increasing the object size by MAX_BYTES (subject to alignment). +template +class UT_SmallArray : public UT_Array +{ + // As many elements that fit into MAX_BYTES with 1 item minimum + enum { MAX_ELEMS = MAX_BYTES/sizeof(T) < 1 ? 1 : MAX_BYTES/sizeof(T) }; + +public: + +// gcc falsely warns about our use of offsetof() on non-POD types. We can't +// easily suppress this because it has to be done in the caller at +// instantiation time. Instead, punt to a runtime check instead. +#if defined(__clang__) || defined(_MSC_VER) + #define UT_SMALL_ARRAY_SIZE_ASSERT() \ + using ThisT = UT_SmallArray; \ + static_assert(offsetof(ThisT, myBuffer) == sizeof(UT_Array), \ + "In order for UT_Array's checks for whether it needs to free the buffer to work, " \ + "the buffer must be exactly following the base class memory.") +#else + #define UT_SMALL_ARRAY_SIZE_ASSERT() \ + UT_ASSERT_P(!UT_Array::isHeapBuffer()); +#endif + + /// Default construction + UT_SmallArray() + : UT_Array(/*capacity*/0) + { + UT_Array::unsafeShareData((T*)myBuffer, 0, MAX_ELEMS); + UT_SMALL_ARRAY_SIZE_ASSERT(); + } + + /// Copy constructor + /// @{ + explicit UT_SmallArray(const UT_Array ©) + : UT_Array(/*capacity*/0) + { + UT_Array::unsafeShareData((T*)myBuffer, 0, MAX_ELEMS); + UT_SMALL_ARRAY_SIZE_ASSERT(); + UT_Array::operator=(copy); + } + explicit UT_SmallArray(const UT_SmallArray ©) + : UT_Array(/*capacity*/0) + { + UT_Array::unsafeShareData((T*)myBuffer, 0, MAX_ELEMS); + UT_SMALL_ARRAY_SIZE_ASSERT(); + UT_Array::operator=(copy); + } + /// @} + + /// Move constructor + /// @{ + UT_SmallArray(UT_Array &&movable) noexcept + { + UT_Array::unsafeShareData((T*)myBuffer, 0, MAX_ELEMS); + UT_SMALL_ARRAY_SIZE_ASSERT(); + UT_Array::operator=(std::move(movable)); + } + UT_SmallArray(UT_SmallArray &&movable) noexcept + { + UT_Array::unsafeShareData((T*)myBuffer, 0, MAX_ELEMS); + UT_SMALL_ARRAY_SIZE_ASSERT(); + UT_Array::operator=(std::move(movable)); + } + /// @} + + /// Initializer list constructor + explicit UT_SmallArray(std::initializer_list init) + { + UT_Array::unsafeShareData((T*)myBuffer, 0, MAX_ELEMS); + UT_SMALL_ARRAY_SIZE_ASSERT(); + UT_Array::operator=(init); + } + +#undef UT_SMALL_ARRAY_SIZE_ASSERT + + /// Assignment operator + /// @{ + UT_SmallArray & + operator=(const UT_SmallArray ©) + { + UT_Array::operator=(copy); + return *this; + } + UT_SmallArray & + operator=(const UT_Array ©) + { + UT_Array::operator=(copy); + return *this; + } + /// @} + + /// Move operator + /// @{ + UT_SmallArray & + operator=(UT_SmallArray &&movable) + { + UT_Array::operator=(std::move(movable)); + return *this; + } + UT_SmallArray & + operator=(UT_Array &&movable) + { + UT_Array::operator=(std::move(movable)); + return *this; + } + /// @} + + UT_SmallArray & + operator=(std::initializer_list src) + { + UT_Array::operator=(src); + return *this; + } +private: + alignas(T) char myBuffer[MAX_ELEMS*sizeof(T)]; +}; +}} + +#endif // __UT_SMALLARRAY_H_INCLUDED__ +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * A vector class templated on its size and data type. + */ + +#pragma once + +#ifndef __UT_FixedVector__ +#define __UT_FixedVector__ + + + + +namespace igl { namespace FastWindingNumber { + +template +class UT_FixedVector +{ +public: + typedef UT_FixedVector ThisType; + typedef T value_type; + typedef T theType; + static const exint theSize = SIZE; + + T vec[SIZE]; + + SYS_FORCE_INLINE UT_FixedVector() = default; + + /// Initializes every component to the same value + SYS_FORCE_INLINE explicit UT_FixedVector(T that) noexcept + { + for (exint i = 0; i < SIZE; ++i) + vec[i] = that; + } + + SYS_FORCE_INLINE UT_FixedVector(const ThisType &that) = default; + SYS_FORCE_INLINE UT_FixedVector(ThisType &&that) = default; + + /// Converts vector of S into vector of T, + /// or just copies if same type. + template + SYS_FORCE_INLINE UT_FixedVector(const UT_FixedVector &that) noexcept + { + for (exint i = 0; i < SIZE; ++i) + vec[i] = that[i]; + } + + template + SYS_FORCE_INLINE UT_FixedVector(const S that[SIZE]) noexcept + { + for (exint i = 0; i < SIZE; ++i) + vec[i] = that[i]; + } + + SYS_FORCE_INLINE const T &operator[](exint i) const noexcept + { + UT_ASSERT_P(i >= 0 && i < SIZE); + return vec[i]; + } + SYS_FORCE_INLINE T &operator[](exint i) noexcept + { + UT_ASSERT_P(i >= 0 && i < SIZE); + return vec[i]; + } + + SYS_FORCE_INLINE constexpr const T *data() const noexcept + { + return vec; + } + SYS_FORCE_INLINE T *data() noexcept + { + return vec; + } + + SYS_FORCE_INLINE ThisType &operator=(const ThisType &that) = default; + SYS_FORCE_INLINE ThisType &operator=(ThisType &&that) = default; + + template + SYS_FORCE_INLINE ThisType &operator=(const UT_FixedVector &that) noexcept + { + for (exint i = 0; i < SIZE; ++i) + vec[i] = that[i]; + return *this; + } + SYS_FORCE_INLINE const ThisType &operator=(T that) noexcept + { + for (exint i = 0; i < SIZE; ++i) + vec[i] = that; + return *this; + } + template + SYS_FORCE_INLINE void operator+=(const UT_FixedVector &that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] += that[i]; + } + SYS_FORCE_INLINE void operator+=(T that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] += that; + } + template + SYS_FORCE_INLINE auto operator+(const UT_FixedVector &that) const -> UT_FixedVector + { + using Type = decltype(vec[0]+that[0]); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] + that[i]; + return result; + } + template + SYS_FORCE_INLINE void operator-=(const UT_FixedVector &that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] -= that[i]; + } + SYS_FORCE_INLINE void operator-=(T that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] -= that; + } + template + SYS_FORCE_INLINE auto operator-(const UT_FixedVector &that) const -> UT_FixedVector + { + using Type = decltype(vec[0]-that[0]); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] - that[i]; + return result; + } + template + SYS_FORCE_INLINE void operator*=(const UT_FixedVector &that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] *= that[i]; + } + template + SYS_FORCE_INLINE auto operator*(const UT_FixedVector &that) const -> UT_FixedVector + { + using Type = decltype(vec[0]*that[0]); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] * that[i]; + return result; + } + SYS_FORCE_INLINE void operator*=(T that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] *= that; + } + SYS_FORCE_INLINE UT_FixedVector operator*(T that) const + { + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] * that; + return result; + } + template + SYS_FORCE_INLINE void operator/=(const UT_FixedVector &that) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] /= that[i]; + } + template + SYS_FORCE_INLINE auto operator/(const UT_FixedVector &that) const -> UT_FixedVector + { + using Type = decltype(vec[0]/that[0]); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] / that[i]; + return result; + } + + SYS_FORCE_INLINE void operator/=(T that) + { + if (std::is_integral::value) + { + for (exint i = 0; i < SIZE; ++i) + vec[i] /= that; + } + else + { + that = 1/that; + for (exint i = 0; i < SIZE; ++i) + vec[i] *= that; + } + } + SYS_FORCE_INLINE UT_FixedVector operator/(T that) const + { + UT_FixedVector result; + if (std::is_integral::value) + { + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] / that; + } + else + { + that = 1/that; + for (exint i = 0; i < SIZE; ++i) + result[i] = vec[i] * that; + } + return result; + } + SYS_FORCE_INLINE void negate() + { + for (exint i = 0; i < SIZE; ++i) + vec[i] = -vec[i]; + } + + SYS_FORCE_INLINE UT_FixedVector operator-() const + { + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = -vec[i]; + return result; + } + + template + SYS_FORCE_INLINE bool operator==(const UT_FixedVector &that) const noexcept + { + for (exint i = 0; i < SIZE; ++i) + { + if (vec[i] != T(that[i])) + return false; + } + return true; + } + template + SYS_FORCE_INLINE bool operator!=(const UT_FixedVector &that) const noexcept + { + return !(*this==that); + } + SYS_FORCE_INLINE bool isZero() const noexcept + { + for (exint i = 0; i < SIZE; ++i) + { + if (vec[i] != T(0)) + return false; + } + return true; + } + SYS_FORCE_INLINE T maxComponent() const + { + T v = vec[0]; + for (exint i = 1; i < SIZE; ++i) + v = (vec[i] > v) ? vec[i] : v; + return v; + } + SYS_FORCE_INLINE T minComponent() const + { + T v = vec[0]; + for (exint i = 1; i < SIZE; ++i) + v = (vec[i] < v) ? vec[i] : v; + return v; + } + SYS_FORCE_INLINE T avgComponent() const + { + T v = vec[0]; + for (exint i = 1; i < SIZE; ++i) + v += vec[i]; + return v / SIZE; + } + + SYS_FORCE_INLINE T length2() const noexcept + { + T a0(vec[0]); + T result(a0*a0); + for (exint i = 1; i < SIZE; ++i) + { + T ai(vec[i]); + result += ai*ai; + } + return result; + } + SYS_FORCE_INLINE T length() const + { + T len2 = length2(); + return SYSsqrt(len2); + } + template + SYS_FORCE_INLINE auto dot(const UT_FixedVector &that) const -> decltype(vec[0]*that[0]) + { + using TheType = decltype(vec[0]*that.vec[0]); + TheType result(vec[0]*that[0]); + for (exint i = 1; i < SIZE; ++i) + result += vec[i]*that[i]; + return result; + } + template + SYS_FORCE_INLINE auto distance2(const UT_FixedVector &that) const -> decltype(vec[0]-that[0]) + { + using TheType = decltype(vec[0]-that[0]); + TheType v(vec[0] - that[0]); + TheType result(v*v); + for (exint i = 1; i < SIZE; ++i) + { + v = vec[i] - that[i]; + result += v*v; + } + return result; + } + template + SYS_FORCE_INLINE auto distance(const UT_FixedVector &that) const -> decltype(vec[0]-that[0]) + { + auto dist2 = distance2(that); + return SYSsqrt(dist2); + } + + SYS_FORCE_INLINE T normalize() + { + T len2 = length2(); + if (len2 == T(0)) + return T(0); + if (len2 == T(1)) + return T(1); + T len = SYSsqrt(len2); + // Check if the square root is equal 1. sqrt(1+dx) ~ 1+dx/2, + // so it may get rounded to 1 when it wasn't 1 before. + if (len != T(1)) + (*this) /= len; + return len; + } +}; + +/// NOTE: Strictly speaking, this should use decltype(that*a[0]), +/// but in the interests of avoiding accidental precision escalation, +/// it uses T. +template +SYS_FORCE_INLINE UT_FixedVector operator*(const S &that,const UT_FixedVector &a) +{ + T t(that); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = t * a[i]; + return result; +} + +template +SYS_FORCE_INLINE auto +dot(const UT_FixedVector &a, const UT_FixedVector &b) -> decltype(a[0]*b[0]) +{ + return a.dot(b); +} + +template +SYS_FORCE_INLINE auto +SYSmin(const UT_FixedVector &a, const UT_FixedVector &b) -> UT_FixedVector +{ + using Type = decltype(a[0]+b[1]); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = SYSmin(Type(a[i]), Type(b[i])); + return result; +} + +template +SYS_FORCE_INLINE auto +SYSmax(const UT_FixedVector &a, const UT_FixedVector &b) -> UT_FixedVector +{ + using Type = decltype(a[0]+b[1]); + UT_FixedVector result; + for (exint i = 0; i < SIZE; ++i) + result[i] = SYSmax(Type(a[i]), Type(b[i])); + return result; +} + +template +struct UT_FixedVectorTraits +{ + typedef UT_FixedVector FixedVectorType; + typedef T DataType; + static const exint TupleSize = 1; + static const bool isVectorType = false; +}; + +template +struct UT_FixedVectorTraits > +{ + typedef UT_FixedVector FixedVectorType; + typedef T DataType; + static const exint TupleSize = SIZE; + static const bool isVectorType = true; +}; +}} + +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Simple wrappers on tbb interface + */ + +#ifndef __UT_ParallelUtil__ +#define __UT_ParallelUtil__ + + + +#include // This is just included for std::thread::hardware_concurrency() +namespace igl { namespace FastWindingNumber { +namespace UT_Thread { inline int getNumProcessors() { + return std::thread::hardware_concurrency(); +}} + +//#include "tbb/blocked_range.h" +//#include "tbb/parallel_for.h" +////namespace tbb { class split; } +// +///// Declare prior to use. +//template +//using UT_BlockedRange = tbb::blocked_range; +// +//// Default implementation that calls range.size() +//template< typename RANGE > +//struct UT_EstimatorNumItems +//{ +// UT_EstimatorNumItems() {} +// +// size_t operator()(const RANGE& range) const +// { +// return range.size(); +// } +//}; +// +///// This is needed by UT_CoarsenedRange +//template +//inline size_t UTestimatedNumItems(const RANGE& range) +//{ +// return UT_EstimatorNumItems()(range); +//} +// +///// UT_CoarsenedRange: This should be used only inside +///// UT_ParallelFor and UT_ParallelReduce +///// This class wraps an existing range with a new range. +///// This allows us to use simple_partitioner, rather than +///// auto_partitioner, which has disastrous performance with +///// the default grain size in ttb 4. +//template< typename RANGE > +//class UT_CoarsenedRange : public RANGE +//{ +//public: +// // Compiler-generated versions are fine: +// // ~UT_CoarsenedRange(); +// // UT_CoarsenedRange(const UT_CoarsenedRange&); +// +// // Split into two sub-ranges: +// UT_CoarsenedRange(UT_CoarsenedRange& range, tbb::split spl) : +// RANGE(range, spl), +// myGrainSize(range.myGrainSize) +// { +// } +// +// // Inherited: bool empty() const +// +// bool is_divisible() const +// { +// return +// RANGE::is_divisible() && +// (UTestimatedNumItems(static_cast(*this)) > myGrainSize); +// } +// +//private: +// size_t myGrainSize; +// +// UT_CoarsenedRange(const RANGE& base_range, const size_t grain_size) : +// RANGE(base_range), +// myGrainSize(grain_size) +// { +// } +// +// template +// friend void UTparallelFor( +// const Range &range, const Body &body, +// const int subscribe_ratio, const int min_grain_size +// ); +//}; +// +///// Run the @c body function over a range in parallel. +///// UTparallelFor attempts to spread the range out over at most +///// subscribe_ratio * num_processor tasks. +///// The factor subscribe_ratio can be used to help balance the load. +///// UTparallelFor() uses tbb for its implementation. +///// The used grain size is the maximum of min_grain_size and +///// if UTestimatedNumItems(range) / (subscribe_ratio * num_processor). +///// If subscribe_ratio == 0, then a grain size of min_grain_size will be used. +///// A range can be split only when UTestimatedNumItems(range) exceeds the +///// grain size the range is divisible. +// +///// +///// Requirements for the Range functor are: +///// - the requirements of the tbb Range Concept +///// - UT_estimatorNumItems must return the the estimated number of work items +///// for the range. When Range::size() is not the correct estimate, then a +///// (partial) specialization of UT_estimatorNumItemsimatorRange must be provided +///// for the type Range. +///// +///// Requirements for the Body function are: +///// - @code Body(const Body &); @endcode @n +///// Copy Constructor +///// - @code Body()::~Body(); @endcode @n +///// Destructor +///// - @code void Body::operator()(const Range &range) const; @endcode +///// Function call to perform operation on the range. Note the operator is +///// @b const. +///// +///// The requirements for a Range object are: +///// - @code Range::Range(const Range&); @endcode @n +///// Copy constructor +///// - @code Range::~Range(); @endcode @n +///// Destructor +///// - @code bool Range::is_divisible() const; @endcode @n +///// True if the range can be partitioned into two sub-ranges +///// - @code bool Range::empty() const; @endcode @n +///// True if the range is empty +///// - @code Range::Range(Range &r, UT_Split) const; @endcode @n +///// Split the range @c r into two sub-ranges (i.e. modify @c r and *this) +///// +///// Example: @code +///// class Square { +///// public: +///// Square(double *data) : myData(data) {} +///// ~Square(); +///// void operator()(const UT_BlockedRange &range) const +///// { +///// for (int64 i = range.begin(); i != range.end(); ++i) +///// myData[i] *= myData[i]; +///// } +///// double *myData; +///// }; +///// ... +///// +///// void +///// parallel_square(double *array, int64 length) +///// { +///// UTparallelFor(UT_BlockedRange(0, length), Square(array)); +///// } +///// @endcode +///// +///// @see UTparallelReduce(), UT_BlockedRange() +// +//template +//void UTparallelFor( +// const Range &range, const Body &body, +// const int subscribe_ratio = 2, +// const int min_grain_size = 1 +//) +//{ +// const size_t num_processors( UT_Thread::getNumProcessors() ); +// +// UT_ASSERT( num_processors >= 1 ); +// UT_ASSERT( min_grain_size >= 1 ); +// UT_ASSERT( subscribe_ratio >= 0 ); +// +// const size_t est_range_size( UTestimatedNumItems(range) ); +// +// // Don't run on an empty range! +// if (est_range_size == 0) +// return; +// +// // Avoid tbb overhead if entire range needs to be single threaded +// if (num_processors == 1 || est_range_size <= min_grain_size) +// { +// body(range); +// return; +// } +// +// size_t grain_size(min_grain_size); +// if( subscribe_ratio > 0 ) +// grain_size = std::max( +// grain_size, +// est_range_size / (subscribe_ratio * num_processors) +// ); +// +// UT_CoarsenedRange< Range > coarsened_range(range, grain_size); +// +// tbb::parallel_for(coarsened_range, body, tbb::simple_partitioner()); +//} +// +///// Version of UTparallelFor that is tuned for the case where the range +///// consists of lightweight items, for example, +///// float additions or matrix-vector multiplications. +//template +//void +//UTparallelForLightItems(const Range &range, const Body &body) +//{ +// UTparallelFor(range, body, 2, 1024); +//} +// +///// UTserialFor can be used as a debugging tool to quickly replace a parallel +///// for with a serial for. +//template +//void UTserialFor(const Range &range, const Body &body) +// { body(range); } +// +}} +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Bounding Volume Hierarchy (BVH) implementation. + * To call functions not implemented here, also include UT_BVHImpl.h + */ + +#pragma once + +#ifndef __HDK_UT_BVH_h__ +#define __HDK_UT_BVH_h__ + + + + +#include +#include +namespace igl { namespace FastWindingNumber { + +template class UT_Array; +class v4uf; +class v4uu; + +namespace HDK_Sample { + +namespace UT { + +template +struct Box { + T vals[NAXES][2]; + + SYS_FORCE_INLINE Box() noexcept = default; + SYS_FORCE_INLINE constexpr Box(const Box &other) noexcept = default; + SYS_FORCE_INLINE constexpr Box(Box &&other) noexcept = default; + SYS_FORCE_INLINE Box& operator=(const Box &other) noexcept = default; + SYS_FORCE_INLINE Box& operator=(Box &&other) noexcept = default; + + template + SYS_FORCE_INLINE Box(const Box& other) noexcept { + static_assert((std::is_pod>::value) || !std::is_pod::value, + "UT::Box should be POD, for better performance in UT_Array, etc."); + + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = T(other.vals[axis][0]); + vals[axis][1] = T(other.vals[axis][1]); + } + } + template + SYS_FORCE_INLINE Box(const UT_FixedVector& pt) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = pt[axis]; + vals[axis][1] = pt[axis]; + } + } + template + SYS_FORCE_INLINE Box& operator=(const Box& other) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = T(other.vals[axis][0]); + vals[axis][1] = T(other.vals[axis][1]); + } + return *this; + } + + SYS_FORCE_INLINE const T* operator[](const size_t axis) const noexcept { + UT_ASSERT_P(axis < NAXES); + return vals[axis]; + } + SYS_FORCE_INLINE T* operator[](const size_t axis) noexcept { + UT_ASSERT_P(axis < NAXES); + return vals[axis]; + } + + SYS_FORCE_INLINE void initBounds() noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = std::numeric_limits::max(); + vals[axis][1] = -std::numeric_limits::max(); + } + } + /// Copy the source box. + /// NOTE: This is so that in templated code that may have a Box or a + /// UT_FixedVector, it can call initBounds and still work. + SYS_FORCE_INLINE void initBounds(const Box& src) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = src.vals[axis][0]; + vals[axis][1] = src.vals[axis][1]; + } + } + /// Initialize with the union of the source boxes. + /// NOTE: This is so that in templated code that may have Box's or a + /// UT_FixedVector's, it can call initBounds and still work. + SYS_FORCE_INLINE void initBoundsUnordered(const Box& src0, const Box& src1) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = SYSmin(src0.vals[axis][0], src1.vals[axis][0]); + vals[axis][1] = SYSmax(src0.vals[axis][1], src1.vals[axis][1]); + } + } + SYS_FORCE_INLINE void combine(const Box& src) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + T& minv = vals[axis][0]; + T& maxv = vals[axis][1]; + const T curminv = src.vals[axis][0]; + const T curmaxv = src.vals[axis][1]; + minv = (minv < curminv) ? minv : curminv; + maxv = (maxv > curmaxv) ? maxv : curmaxv; + } + } + SYS_FORCE_INLINE void enlargeBounds(const Box& src) noexcept { + combine(src); + } + + template + SYS_FORCE_INLINE + void initBounds(const UT_FixedVector& pt) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = pt[axis]; + vals[axis][1] = pt[axis]; + } + } + template + SYS_FORCE_INLINE + void initBounds(const UT_FixedVector& min, const UT_FixedVector& max) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = min[axis]; + vals[axis][1] = max[axis]; + } + } + template + SYS_FORCE_INLINE + void initBoundsUnordered(const UT_FixedVector& p0, const UT_FixedVector& p1) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = SYSmin(p0[axis], p1[axis]); + vals[axis][1] = SYSmax(p0[axis], p1[axis]); + } + } + template + SYS_FORCE_INLINE + void enlargeBounds(const UT_FixedVector& pt) noexcept { + for (uint axis = 0; axis < NAXES; ++axis) { + vals[axis][0] = SYSmin(vals[axis][0], pt[axis]); + vals[axis][1] = SYSmax(vals[axis][1], pt[axis]); + } + } + + SYS_FORCE_INLINE + UT_FixedVector getMin() const noexcept { + UT_FixedVector v; + for (uint axis = 0; axis < NAXES; ++axis) { + v[axis] = vals[axis][0]; + } + return v; + } + + SYS_FORCE_INLINE + UT_FixedVector getMax() const noexcept { + UT_FixedVector v; + for (uint axis = 0; axis < NAXES; ++axis) { + v[axis] = vals[axis][1]; + } + return v; + } + + T diameter2() const noexcept { + T diff = (vals[0][1]-vals[0][0]); + T sum = diff*diff; + for (uint axis = 1; axis < NAXES; ++axis) { + diff = (vals[axis][1]-vals[axis][0]); + sum += diff*diff; + } + return sum; + } + T volume() const noexcept { + T product = (vals[0][1]-vals[0][0]); + for (uint axis = 1; axis < NAXES; ++axis) { + product *= (vals[axis][1]-vals[axis][0]); + } + return product; + } + T half_surface_area() const noexcept { + if (NAXES==1) { + // NOTE: Although this should technically be 1, + // that doesn't make any sense as a heuristic, + // so we fall back to the "volume" of this box. + return (vals[0][1]-vals[0][0]); + } + if (NAXES==2) { + const T d0 = (vals[0][1]-vals[0][0]); + const T d1 = (vals[1][1]-vals[1][0]); + return d0 + d1; + } + if (NAXES==3) { + const T d0 = (vals[0][1]-vals[0][0]); + const T d1 = (vals[1][1]-vals[1][0]); + const T d2 = (vals[2][1]-vals[2][0]); + return d0*d1 + d1*d2 + d2*d0; + } + if (NAXES==4) { + const T d0 = (vals[0][1]-vals[0][0]); + const T d1 = (vals[1][1]-vals[1][0]); + const T d2 = (vals[2][1]-vals[2][0]); + const T d3 = (vals[3][1]-vals[3][0]); + // This is just d0d1d2 + d1d2d3 + d2d3d0 + d3d0d1 refactored. + const T d0d1 = d0*d1; + const T d2d3 = d2*d3; + return d0d1*(d2+d3) + d2d3*(d0+d1); + } + + T sum = 0; + for (uint skipped_axis = 0; skipped_axis < NAXES; ++skipped_axis) { + T product = 1; + for (uint axis = 0; axis < NAXES; ++axis) { + if (axis != skipped_axis) { + product *= (vals[axis][1]-vals[axis][0]); + } + } + sum += product; + } + return sum; + } + T axis_sum() const noexcept { + T sum = (vals[0][1]-vals[0][0]); + for (uint axis = 1; axis < NAXES; ++axis) { + sum += (vals[axis][1]-vals[axis][0]); + } + return sum; + } + template + SYS_FORCE_INLINE void intersect( + T &box_tmin, + T &box_tmax, + const UT_FixedVector &signs, + const UT_FixedVector &origin, + const UT_FixedVector &inverse_direction + ) const noexcept { + for (int axis = 0; axis < NAXES; ++axis) + { + uint sign = signs[axis]; + T t1 = (vals[axis][sign] - origin[axis]) * inverse_direction[axis]; + T t2 = (vals[axis][sign^1] - origin[axis]) * inverse_direction[axis]; + box_tmin = SYSmax(t1, box_tmin); + box_tmax = SYSmin(t2, box_tmax); + } + } + SYS_FORCE_INLINE void intersect(const Box& other, Box& dest) const noexcept { + for (int axis = 0; axis < NAXES; ++axis) + { + dest.vals[axis][0] = SYSmax(vals[axis][0], other.vals[axis][0]); + dest.vals[axis][1] = SYSmin(vals[axis][1], other.vals[axis][1]); + } + } + template + SYS_FORCE_INLINE T minDistance2( + const UT_FixedVector &p + ) const noexcept { + T diff = SYSmax(SYSmax(vals[0][0]-p[0], p[0]-vals[0][1]), T(0.0f)); + T d2 = diff*diff; + for (int axis = 1; axis < NAXES; ++axis) + { + diff = SYSmax(SYSmax(vals[axis][0]-p[axis], p[axis]-vals[axis][1]), T(0.0f)); + d2 += diff*diff; + } + return d2; + } + template + SYS_FORCE_INLINE T maxDistance2( + const UT_FixedVector &p + ) const noexcept { + T diff = SYSmax(p[0]-vals[0][0], vals[0][1]-p[0]); + T d2 = diff*diff; + for (int axis = 1; axis < NAXES; ++axis) + { + diff = SYSmax(p[axis]-vals[axis][0], vals[axis][1]-p[axis]); + d2 += diff*diff; + } + return d2; + } +}; + +/// Used by BVH::init to specify the heuristic to use for choosing between different box splits. +/// I tried putting this inside the BVH class, but I had difficulty getting it to compile. +enum class BVH_Heuristic { + /// Tries to minimize the sum of axis lengths of the boxes. + /// This is useful for applications where the probability of a box being applicable to a + /// query is proportional to the "length", e.g. the probability of a random infinite plane + /// intersecting the box. + BOX_PERIMETER, + + /// Tries to minimize the "surface area" of the boxes. + /// In 3D, uses the surface area; in 2D, uses the perimeter; in 1D, uses the axis length. + /// This is what most applications, e.g. ray tracing, should use, particularly when the + /// probability of a box being applicable to a query is proportional to the surface "area", + /// e.g. the probability of a random ray hitting the box. + /// + /// NOTE: USE THIS ONE IF YOU ARE UNSURE! + BOX_AREA, + + /// Tries to minimize the "volume" of the boxes. + /// Uses the product of all axis lengths as a heuristic, (volume in 3D, area in 2D, length in 1D). + /// This is useful for applications where the probability of a box being applicable to a + /// query is proportional to the "volume", e.g. the probability of a random point being inside the box. + BOX_VOLUME, + + /// Tries to minimize the "radii" of the boxes (i.e. the distance from the centre to a corner). + /// This is useful for applications where the probability of a box being applicable to a + /// query is proportional to the distance to the box centre, e.g. the probability of a random + /// infinite plane being within the "radius" of the centre. + BOX_RADIUS, + + /// Tries to minimize the squared "radii" of the boxes (i.e. the squared distance from the centre to a corner). + /// This is useful for applications where the probability of a box being applicable to a + /// query is proportional to the squared distance to the box centre, e.g. the probability of a random + /// ray passing within the "radius" of the centre. + BOX_RADIUS2, + + /// Tries to minimize the cubed "radii" of the boxes (i.e. the cubed distance from the centre to a corner). + /// This is useful for applications where the probability of a box being applicable to a + /// query is proportional to the cubed distance to the box centre, e.g. the probability of a random + /// point being within the "radius" of the centre. + BOX_RADIUS3, + + /// Tries to minimize the depth of the tree by primarily splitting at the median of the max axis. + /// It may fall back to minimizing the area, but the tree depth should be unaffected. + /// + /// FIXME: This is not fully implemented yet. + MEDIAN_MAX_AXIS +}; + +template +class BVH { +public: + using INT_TYPE = uint; + struct Node { + INT_TYPE child[N]; + + static constexpr INT_TYPE theN = N; + static constexpr INT_TYPE EMPTY = INT_TYPE(-1); + static constexpr INT_TYPE INTERNAL_BIT = (INT_TYPE(1)<<(sizeof(INT_TYPE)*8 - 1)); + SYS_FORCE_INLINE static INT_TYPE markInternal(INT_TYPE internal_node_num) noexcept { + return internal_node_num | INTERNAL_BIT; + } + SYS_FORCE_INLINE static bool isInternal(INT_TYPE node_int) noexcept { + return (node_int & INTERNAL_BIT) != 0; + } + SYS_FORCE_INLINE static INT_TYPE getInternalNum(INT_TYPE node_int) noexcept { + return node_int & ~INTERNAL_BIT; + } + }; +private: + struct FreeDeleter { + SYS_FORCE_INLINE void operator()(Node* p) const { + if (p) { + // The pointer was allocated with malloc by UT_Array, + // so it must be freed with free. + free(p); + } + } + }; + + std::unique_ptr myRoot; + INT_TYPE myNumNodes; +public: + SYS_FORCE_INLINE BVH() noexcept : myRoot(nullptr), myNumNodes(0) {} + + template + inline void init(const BOX_TYPE* boxes, const INT_TYPE nboxes, SRC_INT_TYPE* indices=nullptr, bool reorder_indices=false, INT_TYPE max_items_per_leaf=1) noexcept; + + template + inline void init(Box axes_minmax, const BOX_TYPE* boxes, INT_TYPE nboxes, SRC_INT_TYPE* indices=nullptr, bool reorder_indices=false, INT_TYPE max_items_per_leaf=1) noexcept; + + SYS_FORCE_INLINE + INT_TYPE getNumNodes() const noexcept + { + return myNumNodes; + } + SYS_FORCE_INLINE + const Node *getNodes() const noexcept + { + return myRoot.get(); + } + + SYS_FORCE_INLINE + void clear() noexcept { + myRoot.reset(); + myNumNodes = 0; + } + + /// For each node, this effectively does: + /// LOCAL_DATA local_data[MAX_ORDER]; + /// bool descend = functors.pre(nodei, parent_data); + /// if (!descend) + /// return; + /// for each child { + /// if (isitem(child)) + /// functors.item(getitemi(child), nodei, local_data[child]); + /// else if (isnode(child)) + /// recurse(getnodei(child), local_data); + /// } + /// functors.post(nodei, parent_nodei, data_for_parent, num_children, local_data); + template + inline void traverse( + FUNCTORS &functors, + LOCAL_DATA *data_for_parent=nullptr) const noexcept; + + /// This acts like the traverse function, except if the number of nodes in two subtrees + /// of a node contain at least parallel_threshold nodes, they may be executed in parallel. + /// If parallel_threshold is 0, even item_functor may be executed on items in parallel. + /// NOTE: Make sure that your functors don't depend on the order that they're executed in, + /// e.g. don't add values from sibling nodes together except in post functor, + /// else they might have nondeterministic roundoff or miss some values entirely. + template + inline void traverseParallel( + INT_TYPE parallel_threshold, + FUNCTORS &functors, + LOCAL_DATA *data_for_parent=nullptr) const noexcept; + + /// For each node, this effectively does: + /// LOCAL_DATA local_data[MAX_ORDER]; + /// uint descend = functors.pre(nodei, parent_data); + /// if (!descend) + /// return; + /// for each child { + /// if (!(descend & (1< + inline void traverseVector( + FUNCTORS &functors, + LOCAL_DATA *data_for_parent=nullptr) const noexcept; + + /// Prints a text representation of the tree to stdout. + inline void debugDump() const; + + template + static inline void createTrivialIndices(SRC_INT_TYPE* indices, const INT_TYPE n) noexcept; + +private: + template + inline void traverseHelper( + INT_TYPE nodei, + INT_TYPE parent_nodei, + FUNCTORS &functors, + LOCAL_DATA *data_for_parent=nullptr) const noexcept; + + template + inline void traverseParallelHelper( + INT_TYPE nodei, + INT_TYPE parent_nodei, + INT_TYPE parallel_threshold, + INT_TYPE next_node_id, + FUNCTORS &functors, + LOCAL_DATA *data_for_parent=nullptr) const noexcept; + + template + inline void traverseVectorHelper( + INT_TYPE nodei, + INT_TYPE parent_nodei, + FUNCTORS &functors, + LOCAL_DATA *data_for_parent=nullptr) const noexcept; + + template + static inline void computeFullBoundingBox(Box& axes_minmax, const BOX_TYPE* boxes, const INT_TYPE nboxes, SRC_INT_TYPE* indices) noexcept; + + template + static inline void initNode(UT_Array& nodes, Node &node, const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, const INT_TYPE nboxes) noexcept; + + template + static inline void initNodeReorder(UT_Array& nodes, Node &node, const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, const INT_TYPE nboxes, const INT_TYPE indices_offset, const INT_TYPE max_items_per_leaf) noexcept; + + template + static inline void multiSplit(const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, INT_TYPE nboxes, SRC_INT_TYPE* sub_indices[N+1], Box sub_boxes[N]) noexcept; + + template + static inline void split(const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, INT_TYPE nboxes, SRC_INT_TYPE*& split_indices, Box* split_boxes) noexcept; + + template + static inline void adjustParallelChildNodes(INT_TYPE nparallel, UT_Array& nodes, Node& node, UT_Array* parallel_nodes, SRC_INT_TYPE* sub_indices) noexcept; + + template + static inline void nthElement(const BOX_TYPE* boxes, SRC_INT_TYPE* indices, const SRC_INT_TYPE* indices_end, const uint axis, SRC_INT_TYPE*const nth) noexcept; + + template + static inline void partitionByCentre(const BOX_TYPE* boxes, SRC_INT_TYPE*const indices, const SRC_INT_TYPE*const indices_end, const uint axis, const T pivotx2, SRC_INT_TYPE*& ppivot_start, SRC_INT_TYPE*& ppivot_end) noexcept; + + /// An overestimate of the number of nodes needed. + /// At worst, we could have only 2 children in every leaf, and + /// then above that, we have a geometric series with r=1/N and a=(sub_nboxes/2)/N + /// The true worst case might be a little worst than this, but + /// it's probably fairly unlikely. + SYS_FORCE_INLINE static INT_TYPE nodeEstimate(const INT_TYPE nboxes) noexcept { + return nboxes/2 + nboxes/(2*(N-1)); + } + + template + SYS_FORCE_INLINE static T unweightedHeuristic(const Box& box) noexcept { + if (H == BVH_Heuristic::BOX_PERIMETER) { + return box.axis_sum(); + } + if (H == BVH_Heuristic::BOX_AREA) { + return box.half_surface_area(); + } + if (H == BVH_Heuristic::BOX_VOLUME) { + return box.volume(); + } + if (H == BVH_Heuristic::BOX_RADIUS) { + T diameter2 = box.diameter2(); + return SYSsqrt(diameter2); + } + if (H == BVH_Heuristic::BOX_RADIUS2) { + return box.diameter2(); + } + if (H == BVH_Heuristic::BOX_RADIUS3) { + T diameter2 = box.diameter2(); + return diameter2*SYSsqrt(diameter2); + } + UT_ASSERT_MSG(0, "BVH_Heuristic::MEDIAN_MAX_AXIS should be handled separately by caller!"); + return T(1); + } + + /// 16 equal-length spans (15 evenly-spaced splits) should be enough for a decent heuristic + static constexpr INT_TYPE NSPANS = 16; + static constexpr INT_TYPE NSPLITS = NSPANS-1; + + /// At least 1/16 of all boxes must be on each side, else we could end up with a very deep tree + static constexpr INT_TYPE MIN_FRACTION = 16; +}; + +} // UT namespace + +template +using UT_BVH = UT::BVH; + +} // End HDK_Sample namespace +}} +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Bounding Volume Hierarchy (BVH) implementation. + * The main file is UT_BVH.h; this file is separate so that + * files that don't actually need to call functions on the BVH + * won't have unnecessary headers and functions included. + */ + +#pragma once + +#ifndef __HDK_UT_BVHImpl_h__ +#define __HDK_UT_BVHImpl_h__ + + + + + + + + +#include + +#include +#include + +namespace igl { namespace FastWindingNumber { +namespace HDK_Sample { + +namespace UT { + +template +SYS_FORCE_INLINE bool utBoxExclude(const UT::Box& box) noexcept { + bool has_nan_or_inf = !SYSisFinite(box[0][0]); + has_nan_or_inf |= !SYSisFinite(box[0][1]); + for (uint axis = 1; axis < NAXES; ++axis) + { + has_nan_or_inf |= !SYSisFinite(box[axis][0]); + has_nan_or_inf |= !SYSisFinite(box[axis][1]); + } + return has_nan_or_inf; +} +template +SYS_FORCE_INLINE bool utBoxExclude(const UT::Box& box) noexcept { + const int32 *pboxints = reinterpret_cast(&box); + // Fast check for NaN or infinity: check if exponent bits are 0xFF. + bool has_nan_or_inf = ((pboxints[0] & 0x7F800000) == 0x7F800000); + has_nan_or_inf |= ((pboxints[1] & 0x7F800000) == 0x7F800000); + for (uint axis = 1; axis < NAXES; ++axis) + { + has_nan_or_inf |= ((pboxints[2*axis] & 0x7F800000) == 0x7F800000); + has_nan_or_inf |= ((pboxints[2*axis + 1] & 0x7F800000) == 0x7F800000); + } + return has_nan_or_inf; +} +template +SYS_FORCE_INLINE T utBoxCenter(const UT::Box& box, uint axis) noexcept { + const T* v = box.vals[axis]; + return v[0] + v[1]; +} +template +struct ut_BoxCentre { + constexpr static uint scale = 2; +}; +template +SYS_FORCE_INLINE T utBoxExclude(const UT_FixedVector& position) noexcept { + bool has_nan_or_inf = !SYSisFinite(position[0]); + for (uint axis = 1; axis < NAXES; ++axis) + has_nan_or_inf |= !SYSisFinite(position[axis]); + return has_nan_or_inf; +} +template +SYS_FORCE_INLINE bool utBoxExclude(const UT_FixedVector& position) noexcept { + const int32 *ppositionints = reinterpret_cast(&position); + // Fast check for NaN or infinity: check if exponent bits are 0xFF. + bool has_nan_or_inf = ((ppositionints[0] & 0x7F800000) == 0x7F800000); + for (uint axis = 1; axis < NAXES; ++axis) + has_nan_or_inf |= ((ppositionints[axis] & 0x7F800000) == 0x7F800000); + return has_nan_or_inf; +} +template +SYS_FORCE_INLINE T utBoxCenter(const UT_FixedVector& position, uint axis) noexcept { + return position[axis]; +} +template +struct ut_BoxCentre> { + constexpr static uint scale = 1; +}; + +template +inline INT_TYPE utExcludeNaNInfBoxIndices(const BOX_TYPE* boxes, SRC_INT_TYPE* indices, INT_TYPE& nboxes) noexcept +{ + constexpr INT_TYPE PARALLEL_THRESHOLD = 65536; + INT_TYPE ntasks = 1; + //if (nboxes >= PARALLEL_THRESHOLD) + //{ + // INT_TYPE nprocessors = UT_Thread::getNumProcessors(); + // ntasks = (nprocessors > 1) ? SYSmin(4*nprocessors, nboxes/(PARALLEL_THRESHOLD/2)) : 1; + //} + //if (ntasks == 1) + { + // Serial: easy case; just loop through. + + const SRC_INT_TYPE* indices_end = indices + nboxes; + + // Loop through forward once + SRC_INT_TYPE* psrc_index = indices; + for (; psrc_index != indices_end; ++psrc_index) + { + const bool exclude = utBoxExclude(boxes[*psrc_index]); + if (exclude) + break; + } + if (psrc_index == indices_end) + return 0; + + // First NaN or infinite box + SRC_INT_TYPE* nan_start = psrc_index; + for (++psrc_index; psrc_index != indices_end; ++psrc_index) + { + const bool exclude = utBoxExclude(boxes[*psrc_index]); + if (!exclude) + { + *nan_start = *psrc_index; + ++nan_start; + } + } + nboxes = nan_start-indices; + return indices_end - nan_start; + } + +} + +template +template +inline void BVH::init(const BOX_TYPE* boxes, const INT_TYPE nboxes, SRC_INT_TYPE* indices, bool reorder_indices, INT_TYPE max_items_per_leaf) noexcept { + Box axes_minmax; + computeFullBoundingBox(axes_minmax, boxes, nboxes, indices); + + init(axes_minmax, boxes, nboxes, indices, reorder_indices, max_items_per_leaf); +} + +template +template +inline void BVH::init(Box axes_minmax, const BOX_TYPE* boxes, INT_TYPE nboxes, SRC_INT_TYPE* indices, bool reorder_indices, INT_TYPE max_items_per_leaf) noexcept { + // Clear the tree in advance to save memory. + myRoot.reset(); + + if (nboxes == 0) { + myNumNodes = 0; + return; + } + + UT_Array local_indices; + if (!indices) { + local_indices.setSizeNoInit(nboxes); + indices = local_indices.array(); + createTrivialIndices(indices, nboxes); + } + + // Exclude any boxes with NaNs or infinities by shifting down indices + // over the bad box indices and updating nboxes. + INT_TYPE nexcluded = utExcludeNaNInfBoxIndices(boxes, indices, nboxes); + if (nexcluded != 0) { + if (nboxes == 0) { + myNumNodes = 0; + return; + } + computeFullBoundingBox(axes_minmax, boxes, nboxes, indices); + } + + UT_Array nodes; + // Preallocate an overestimate of the number of nodes needed. + nodes.setCapacity(nodeEstimate(nboxes)); + nodes.setSize(1); + if (reorder_indices) + initNodeReorder(nodes, nodes[0], axes_minmax, boxes, indices, nboxes, 0, max_items_per_leaf); + else + initNode(nodes, nodes[0], axes_minmax, boxes, indices, nboxes); + + // If capacity is more than 12.5% over the size, rellocate. + if (8*nodes.capacity() > 9*nodes.size()) { + nodes.setCapacity(nodes.size()); + } + // Steal ownership of the array from the UT_Array + myRoot.reset(nodes.array()); + myNumNodes = nodes.size(); + nodes.unsafeClearData(); +} + +template +template +inline void BVH::traverse( + FUNCTORS &functors, + LOCAL_DATA* data_for_parent) const noexcept +{ + if (!myRoot) + return; + + // NOTE: The root is always index 0. + traverseHelper(0, INT_TYPE(-1), functors, data_for_parent); +} +template +template +inline void BVH::traverseHelper( + INT_TYPE nodei, + INT_TYPE parent_nodei, + FUNCTORS &functors, + LOCAL_DATA* data_for_parent) const noexcept +{ + const Node &node = myRoot[nodei]; + bool descend = functors.pre(nodei, data_for_parent); + if (!descend) + return; + LOCAL_DATA local_data[N]; + INT_TYPE s; + for (s = 0; s < N; ++s) { + const INT_TYPE node_int = node.child[s]; + if (Node::isInternal(node_int)) { + if (node_int == Node::EMPTY) { + // NOTE: Anything after this will be empty too, so we can break. + break; + } + traverseHelper(Node::getInternalNum(node_int), nodei, functors, &local_data[s]); + } + else { + functors.item(node_int, nodei, local_data[s]); + } + } + // NOTE: s is now the number of non-empty entries in this node. + functors.post(nodei, parent_nodei, data_for_parent, s, local_data); +} + +template +template +inline void BVH::traverseParallel( + INT_TYPE parallel_threshold, + FUNCTORS& functors, + LOCAL_DATA* data_for_parent) const noexcept +{ + if (!myRoot) + return; + + // NOTE: The root is always index 0. + traverseParallelHelper(0, INT_TYPE(-1), parallel_threshold, myNumNodes, functors, data_for_parent); +} +template +template +inline void BVH::traverseParallelHelper( + INT_TYPE nodei, + INT_TYPE parent_nodei, + INT_TYPE parallel_threshold, + INT_TYPE next_node_id, + FUNCTORS& functors, + LOCAL_DATA* data_for_parent) const noexcept +{ + const Node &node = myRoot[nodei]; + bool descend = functors.pre(nodei, data_for_parent); + if (!descend) + return; + + // To determine the number of nodes in a child's subtree, we take the next + // node ID minus the current child's node ID. + INT_TYPE next_nodes[N]; + INT_TYPE nnodes[N]; + INT_TYPE nchildren = N; + INT_TYPE nparallel = 0; + // s is currently unsigned, so we check s < N for bounds check. + // The s >= 0 check is in case s ever becomes signed, and should be + // automatically removed by the compiler for unsigned s. + for (INT_TYPE s = N-1; (std::is_signed::value ? (s >= 0) : (s < N)); --s) { + const INT_TYPE node_int = node.child[s]; + if (node_int == Node::EMPTY) { + --nchildren; + continue; + } + next_nodes[s] = next_node_id; + if (Node::isInternal(node_int)) { + // NOTE: This depends on BVH::initNode appending the child nodes + // in between their content, instead of all at once. + INT_TYPE child_node_id = Node::getInternalNum(node_int); + nnodes[s] = next_node_id - child_node_id; + next_node_id = child_node_id; + } + else { + nnodes[s] = 0; + } + nparallel += (nnodes[s] >= parallel_threshold); + } + + LOCAL_DATA local_data[N]; + if (nparallel >= 2) { + // Do any non-parallel ones first + if (nparallel < nchildren) { + for (INT_TYPE s = 0; s < N; ++s) { + if (nnodes[s] >= parallel_threshold) { + continue; + } + const INT_TYPE node_int = node.child[s]; + if (Node::isInternal(node_int)) { + if (node_int == Node::EMPTY) { + // NOTE: Anything after this will be empty too, so we can break. + break; + } + traverseHelper(Node::getInternalNum(node_int), nodei, functors, &local_data[s]); + } + else { + functors.item(node_int, nodei, local_data[s]); + } + } + } + // Now do the parallel ones + igl::parallel_for( + nparallel, + [this,nodei,&node,&nnodes,&next_nodes,¶llel_threshold,&functors,&local_data](int taski) + { + INT_TYPE parallel_count = 0; + // NOTE: The check for s < N is just so that the compiler can + // (hopefully) figure out that it can fully unroll the loop. + INT_TYPE s; + for (s = 0; s < N; ++s) { + if (nnodes[s] < parallel_threshold) { + continue; + } + if (parallel_count == taski) { + break; + } + ++parallel_count; + } + const INT_TYPE node_int = node.child[s]; + if (Node::isInternal(node_int)) { + UT_ASSERT_MSG_P(node_int != Node::EMPTY, "Empty entries should have been excluded above."); + traverseParallelHelper(Node::getInternalNum(node_int), nodei, parallel_threshold, next_nodes[s], functors, &local_data[s]); + } + else { + functors.item(node_int, nodei, local_data[s]); + } + }); + } + else { + // All in serial + for (INT_TYPE s = 0; s < N; ++s) { + const INT_TYPE node_int = node.child[s]; + if (Node::isInternal(node_int)) { + if (node_int == Node::EMPTY) { + // NOTE: Anything after this will be empty too, so we can break. + break; + } + traverseHelper(Node::getInternalNum(node_int), nodei, functors, &local_data[s]); + } + else { + functors.item(node_int, nodei, local_data[s]); + } + } + } + functors.post(nodei, parent_nodei, data_for_parent, nchildren, local_data); +} + +template +template +inline void BVH::traverseVector( + FUNCTORS &functors, + LOCAL_DATA* data_for_parent) const noexcept +{ + if (!myRoot) + return; + + // NOTE: The root is always index 0. + traverseVectorHelper(0, INT_TYPE(-1), functors, data_for_parent); +} +template +template +inline void BVH::traverseVectorHelper( + INT_TYPE nodei, + INT_TYPE parent_nodei, + FUNCTORS &functors, + LOCAL_DATA* data_for_parent) const noexcept +{ + const Node &node = myRoot[nodei]; + INT_TYPE descend = functors.pre(nodei, data_for_parent); + if (!descend) + return; + LOCAL_DATA local_data[N]; + INT_TYPE s; + for (s = 0; s < N; ++s) { + if ((descend>>s) & 1) { + const INT_TYPE node_int = node.child[s]; + if (Node::isInternal(node_int)) { + if (node_int == Node::EMPTY) { + // NOTE: Anything after this will be empty too, so we can break. + descend &= (INT_TYPE(1)< +template +inline void BVH::createTrivialIndices(SRC_INT_TYPE* indices, const INT_TYPE n) noexcept { + igl::parallel_for(n, [indices,n](INT_TYPE i) { indices[i] = i; }, 65536); +} + +template +template +inline void BVH::computeFullBoundingBox(Box& axes_minmax, const BOX_TYPE* boxes, const INT_TYPE nboxes, SRC_INT_TYPE* indices) noexcept { + if (!nboxes) { + axes_minmax.initBounds(); + return; + } + INT_TYPE ntasks = 1; + if (nboxes >= 2*4096) { + INT_TYPE nprocessors = UT_Thread::getNumProcessors(); + ntasks = (nprocessors > 1) ? SYSmin(4*nprocessors, nboxes/4096) : 1; + } + if (ntasks == 1) { + Box box; + if (indices) { + box.initBounds(boxes[indices[0]]); + for (INT_TYPE i = 1; i < nboxes; ++i) { + box.combine(boxes[indices[i]]); + } + } + else { + box.initBounds(boxes[0]); + for (INT_TYPE i = 1; i < nboxes; ++i) { + box.combine(boxes[i]); + } + } + axes_minmax = box; + } + else { + UT_SmallArray> parallel_boxes; + Box box; + igl::parallel_for( + nboxes, + [¶llel_boxes](int n){parallel_boxes.setSize(n);}, + [¶llel_boxes,indices,&boxes](int i, int t) + { + if(indices) + { + parallel_boxes[t].combine(boxes[indices[i]]); + }else + { + parallel_boxes[t].combine(boxes[i]); + } + }, + [¶llel_boxes,&box](int t) + { + if(t == 0) + { + box = parallel_boxes[0]; + }else + { + box.combine(parallel_boxes[t]); + } + }); + + axes_minmax = box; + } +} + +template +template +inline void BVH::initNode(UT_Array& nodes, Node &node, const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, const INT_TYPE nboxes) noexcept { + if (nboxes <= N) { + // Fits in one node + for (INT_TYPE i = 0; i < nboxes; ++i) { + node.child[i] = indices[i]; + } + for (INT_TYPE i = nboxes; i < N; ++i) { + node.child[i] = Node::EMPTY; + } + return; + } + + SRC_INT_TYPE* sub_indices[N+1]; + Box sub_boxes[N]; + + if (N == 2) { + sub_indices[0] = indices; + sub_indices[2] = indices+nboxes; + split(axes_minmax, boxes, indices, nboxes, sub_indices[1], &sub_boxes[0]); + } + else { + multiSplit(axes_minmax, boxes, indices, nboxes, sub_indices, sub_boxes); + } + + // Count the number of nodes to run in parallel and fill in single items in this node + INT_TYPE nparallel = 0; + static constexpr INT_TYPE PARALLEL_THRESHOLD = 1024; + for (INT_TYPE i = 0; i < N; ++i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes == 1) { + node.child[i] = sub_indices[i][0]; + } + else if (sub_nboxes >= PARALLEL_THRESHOLD) { + ++nparallel; + } + } + + // NOTE: Child nodes of this node need to be placed just before the nodes in + // their corresponding subtree, in between the subtrees, because + // traverseParallel uses the difference between the child node IDs + // to determine the number of nodes in the subtree. + + // Recurse + if (nparallel >= 2) { + UT_SmallArray> parallel_nodes; + UT_SmallArray parallel_parent_nodes; + parallel_nodes.setSize(nparallel); + parallel_parent_nodes.setSize(nparallel); + igl::parallel_for( + nparallel, + [¶llel_nodes,¶llel_parent_nodes,&sub_indices,boxes,&sub_boxes](int taski) + { + // First, find which child this is + INT_TYPE counted_parallel = 0; + INT_TYPE sub_nboxes; + INT_TYPE childi; + for (childi = 0; childi < N; ++childi) { + sub_nboxes = sub_indices[childi+1]-sub_indices[childi]; + if (sub_nboxes >= PARALLEL_THRESHOLD) { + if (counted_parallel == taski) { + break; + } + ++counted_parallel; + } + } + UT_ASSERT_P(counted_parallel == taski); + + UT_Array& local_nodes = parallel_nodes[taski]; + // Preallocate an overestimate of the number of nodes needed. + // At worst, we could have only 2 children in every leaf, and + // then above that, we have a geometric series with r=1/N and a=(sub_nboxes/2)/N + // The true worst case might be a little worst than this, but + // it's probably fairly unlikely. + local_nodes.setCapacity(nodeEstimate(sub_nboxes)); + Node& parent_node = parallel_parent_nodes[taski]; + + // We'll have to fix the internal node numbers in parent_node and local_nodes later + initNode(local_nodes, parent_node, sub_boxes[childi], boxes, sub_indices[childi], sub_nboxes); + }); + + INT_TYPE counted_parallel = 0; + for (INT_TYPE i = 0; i < N; ++i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes != 1) { + INT_TYPE local_nodes_start = nodes.size(); + node.child[i] = Node::markInternal(local_nodes_start); + if (sub_nboxes >= PARALLEL_THRESHOLD) { + // First, adjust the root child node + Node child_node = parallel_parent_nodes[counted_parallel]; + ++local_nodes_start; + for (INT_TYPE childi = 0; childi < N; ++childi) { + INT_TYPE child_child = child_node.child[childi]; + if (Node::isInternal(child_child) && child_child != Node::EMPTY) { + child_child += local_nodes_start; + child_node.child[childi] = child_child; + } + } + + // Make space in the array for the sub-child nodes + const UT_Array& local_nodes = parallel_nodes[counted_parallel]; + ++counted_parallel; + INT_TYPE n = local_nodes.size(); + nodes.bumpCapacity(local_nodes_start + n); + nodes.setSizeNoInit(local_nodes_start + n); + nodes[local_nodes_start-1] = child_node; + } + else { + nodes.bumpCapacity(local_nodes_start + 1); + nodes.setSizeNoInit(local_nodes_start + 1); + initNode(nodes, nodes[local_nodes_start], sub_boxes[i], boxes, sub_indices[i], sub_nboxes); + } + } + } + + // Now, adjust and copy all sub-child nodes that were made in parallel + adjustParallelChildNodes(nparallel, nodes, node, parallel_nodes.array(), sub_indices); + } + else { + for (INT_TYPE i = 0; i < N; ++i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes != 1) { + INT_TYPE local_nodes_start = nodes.size(); + node.child[i] = Node::markInternal(local_nodes_start); + nodes.bumpCapacity(local_nodes_start + 1); + nodes.setSizeNoInit(local_nodes_start + 1); + initNode(nodes, nodes[local_nodes_start], sub_boxes[i], boxes, sub_indices[i], sub_nboxes); + } + } + } +} + +template +template +inline void BVH::initNodeReorder(UT_Array& nodes, Node &node, const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, INT_TYPE nboxes, const INT_TYPE indices_offset, const INT_TYPE max_items_per_leaf) noexcept { + if (nboxes <= N) { + // Fits in one node + for (INT_TYPE i = 0; i < nboxes; ++i) { + node.child[i] = indices_offset+i; + } + for (INT_TYPE i = nboxes; i < N; ++i) { + node.child[i] = Node::EMPTY; + } + return; + } + + SRC_INT_TYPE* sub_indices[N+1]; + Box sub_boxes[N]; + + if (N == 2) { + sub_indices[0] = indices; + sub_indices[2] = indices+nboxes; + split(axes_minmax, boxes, indices, nboxes, sub_indices[1], &sub_boxes[0]); + } + else { + multiSplit(axes_minmax, boxes, indices, nboxes, sub_indices, sub_boxes); + } + + // Move any children with max_items_per_leaf or fewer indices before any children with more, + // for better cache coherence when we're accessing data in a corresponding array. + INT_TYPE nleaves = 0; + UT_SmallArray leaf_indices; + SRC_INT_TYPE leaf_sizes[N]; + INT_TYPE sub_nboxes0 = sub_indices[1]-sub_indices[0]; + if (sub_nboxes0 <= max_items_per_leaf) { + leaf_sizes[0] = sub_nboxes0; + for (int j = 0; j < sub_nboxes0; ++j) + leaf_indices.append(sub_indices[0][j]); + ++nleaves; + } + INT_TYPE sub_nboxes1 = sub_indices[2]-sub_indices[1]; + if (sub_nboxes1 <= max_items_per_leaf) { + leaf_sizes[nleaves] = sub_nboxes1; + for (int j = 0; j < sub_nboxes1; ++j) + leaf_indices.append(sub_indices[1][j]); + ++nleaves; + } + for (INT_TYPE i = 2; i < N; ++i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes <= max_items_per_leaf) { + leaf_sizes[nleaves] = sub_nboxes; + for (int j = 0; j < sub_nboxes; ++j) + leaf_indices.append(sub_indices[i][j]); + ++nleaves; + } + } + if (nleaves > 0) { + // NOTE: i < N condition is because INT_TYPE is unsigned. + // i >= 0 condition is in case INT_TYPE is changed to signed. + INT_TYPE move_distance = 0; + INT_TYPE index_move_distance = 0; + for (INT_TYPE i = N-1; (std::is_signed::value ? (i >= 0) : (i < N)); --i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes <= max_items_per_leaf) { + ++move_distance; + index_move_distance += sub_nboxes; + } + else if (move_distance > 0) { + SRC_INT_TYPE *start_src_index = sub_indices[i]; + for (SRC_INT_TYPE *src_index = sub_indices[i+1]-1; src_index >= start_src_index; --src_index) { + src_index[index_move_distance] = src_index[0]; + } + sub_indices[i+move_distance] = sub_indices[i]+index_move_distance; + } + } + index_move_distance = 0; + for (INT_TYPE i = 0; i < nleaves; ++i) { + INT_TYPE sub_nboxes = leaf_sizes[i]; + sub_indices[i] = indices+index_move_distance; + for (int j = 0; j < sub_nboxes; ++j) + indices[index_move_distance+j] = leaf_indices[index_move_distance+j]; + index_move_distance += sub_nboxes; + } + } + + // Count the number of nodes to run in parallel and fill in single items in this node + INT_TYPE nparallel = 0; + static constexpr INT_TYPE PARALLEL_THRESHOLD = 1024; + for (INT_TYPE i = 0; i < N; ++i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes <= max_items_per_leaf) { + node.child[i] = indices_offset+(sub_indices[i]-sub_indices[0]); + } + else if (sub_nboxes >= PARALLEL_THRESHOLD) { + ++nparallel; + } + } + + // NOTE: Child nodes of this node need to be placed just before the nodes in + // their corresponding subtree, in between the subtrees, because + // traverseParallel uses the difference between the child node IDs + // to determine the number of nodes in the subtree. + + // Recurse + if (nparallel >= 2 && false) { + assert(false && "Not implemented; should never get here"); + exit(1); + // // Do the parallel ones first, so that they can be inserted in the right place. + // // Although the choice may seem somewhat arbitrary, we need the results to be + // // identical whether we choose to parallelize or not, and in case we change the + // // threshold later. + // UT_SmallArray,4*sizeof(UT_Array)> parallel_nodes; + // parallel_nodes.setSize(nparallel); + // UT_SmallArray parallel_parent_nodes; + // parallel_parent_nodes.setSize(nparallel); + // UTparallelFor(UT_BlockedRange(0,nparallel), [¶llel_nodes,¶llel_parent_nodes,&sub_indices,boxes,&sub_boxes,indices_offset,max_items_per_leaf](const UT_BlockedRange& r) { + // for (INT_TYPE taski = r.begin(), end = r.end(); taski < end; ++taski) { + // // First, find which child this is + // INT_TYPE counted_parallel = 0; + // INT_TYPE sub_nboxes; + // INT_TYPE childi; + // for (childi = 0; childi < N; ++childi) { + // sub_nboxes = sub_indices[childi+1]-sub_indices[childi]; + // if (sub_nboxes >= PARALLEL_THRESHOLD) { + // if (counted_parallel == taski) { + // break; + // } + // ++counted_parallel; + // } + // } + // UT_ASSERT_P(counted_parallel == taski); + + // UT_Array& local_nodes = parallel_nodes[taski]; + // // Preallocate an overestimate of the number of nodes needed. + // // At worst, we could have only 2 children in every leaf, and + // // then above that, we have a geometric series with r=1/N and a=(sub_nboxes/2)/N + // // The true worst case might be a little worst than this, but + // // it's probably fairly unlikely. + // local_nodes.setCapacity(nodeEstimate(sub_nboxes)); + // Node& parent_node = parallel_parent_nodes[taski]; + + // // We'll have to fix the internal node numbers in parent_node and local_nodes later + // initNodeReorder(local_nodes, parent_node, sub_boxes[childi], boxes, sub_indices[childi], sub_nboxes, + // indices_offset+(sub_indices[childi]-sub_indices[0]), max_items_per_leaf); + // } + // }, 0, 1); + + // INT_TYPE counted_parallel = 0; + // for (INT_TYPE i = 0; i < N; ++i) { + // INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + // if (sub_nboxes > max_items_per_leaf) { + // INT_TYPE local_nodes_start = nodes.size(); + // node.child[i] = Node::markInternal(local_nodes_start); + // if (sub_nboxes >= PARALLEL_THRESHOLD) { + // // First, adjust the root child node + // Node child_node = parallel_parent_nodes[counted_parallel]; + // ++local_nodes_start; + // for (INT_TYPE childi = 0; childi < N; ++childi) { + // INT_TYPE child_child = child_node.child[childi]; + // if (Node::isInternal(child_child) && child_child != Node::EMPTY) { + // child_child += local_nodes_start; + // child_node.child[childi] = child_child; + // } + // } + + // // Make space in the array for the sub-child nodes + // const UT_Array& local_nodes = parallel_nodes[counted_parallel]; + // ++counted_parallel; + // INT_TYPE n = local_nodes.size(); + // nodes.bumpCapacity(local_nodes_start + n); + // nodes.setSizeNoInit(local_nodes_start + n); + // nodes[local_nodes_start-1] = child_node; + // } + // else { + // nodes.bumpCapacity(local_nodes_start + 1); + // nodes.setSizeNoInit(local_nodes_start + 1); + // initNodeReorder(nodes, nodes[local_nodes_start], sub_boxes[i], boxes, sub_indices[i], sub_nboxes, + // indices_offset+(sub_indices[i]-sub_indices[0]), max_items_per_leaf); + // } + // } + // } + + // // Now, adjust and copy all sub-child nodes that were made in parallel + // adjustParallelChildNodes(nparallel, nodes, node, parallel_nodes.array(), sub_indices); + } + else { + for (INT_TYPE i = 0; i < N; ++i) { + INT_TYPE sub_nboxes = sub_indices[i+1]-sub_indices[i]; + if (sub_nboxes > max_items_per_leaf) { + INT_TYPE local_nodes_start = nodes.size(); + node.child[i] = Node::markInternal(local_nodes_start); + nodes.bumpCapacity(local_nodes_start + 1); + nodes.setSizeNoInit(local_nodes_start + 1); + initNodeReorder(nodes, nodes[local_nodes_start], sub_boxes[i], boxes, sub_indices[i], sub_nboxes, + indices_offset+(sub_indices[i]-sub_indices[0]), max_items_per_leaf); + } + } + } +} + +template +template +inline void BVH::multiSplit(const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, INT_TYPE nboxes, SRC_INT_TYPE* sub_indices[N+1], Box sub_boxes[N]) noexcept { + sub_indices[0] = indices; + sub_indices[2] = indices+nboxes; + split(axes_minmax, boxes, indices, nboxes, sub_indices[1], &sub_boxes[0]); + + if (N == 2) { + return; + } + + if (H == BVH_Heuristic::MEDIAN_MAX_AXIS) { + SRC_INT_TYPE* sub_indices_startend[2*N]; + Box sub_boxes_unsorted[N]; + sub_boxes_unsorted[0] = sub_boxes[0]; + sub_boxes_unsorted[1] = sub_boxes[1]; + sub_indices_startend[0] = sub_indices[0]; + sub_indices_startend[1] = sub_indices[1]; + sub_indices_startend[2] = sub_indices[1]; + sub_indices_startend[3] = sub_indices[2]; + for (INT_TYPE nsub = 2; nsub < N; ++nsub) { + SRC_INT_TYPE* selected_start = sub_indices_startend[0]; + SRC_INT_TYPE* selected_end = sub_indices_startend[1]; + Box sub_box = sub_boxes_unsorted[0]; + + // Shift results back. + for (INT_TYPE i = 0; i < nsub-1; ++i) { + sub_indices_startend[2*i ] = sub_indices_startend[2*i+2]; + sub_indices_startend[2*i+1] = sub_indices_startend[2*i+3]; + } + for (INT_TYPE i = 0; i < nsub-1; ++i) { + sub_boxes_unsorted[i] = sub_boxes_unsorted[i-1]; + } + + // Do the split + split(sub_box, boxes, selected_start, selected_end-selected_start, sub_indices_startend[2*nsub-1], &sub_boxes_unsorted[nsub]); + sub_indices_startend[2*nsub-2] = selected_start; + sub_indices_startend[2*nsub] = sub_indices_startend[2*nsub-1]; + sub_indices_startend[2*nsub+1] = selected_end; + + // Sort pointers so that they're in the correct order + sub_indices[N] = indices+nboxes; + for (INT_TYPE i = 0; i < N; ++i) { + SRC_INT_TYPE* prev_pointer = (i != 0) ? sub_indices[i-1] : nullptr; + SRC_INT_TYPE* min_pointer = nullptr; + Box box; + for (INT_TYPE j = 0; j < N; ++j) { + SRC_INT_TYPE* cur_pointer = sub_indices_startend[2*j]; + if ((cur_pointer > prev_pointer) && (!min_pointer || (cur_pointer < min_pointer))) { + min_pointer = cur_pointer; + box = sub_boxes_unsorted[j]; + } + } + UT_ASSERT_P(min_pointer); + sub_indices[i] = min_pointer; + sub_boxes[i] = box; + } + } + } + else { + T sub_box_areas[N]; + sub_box_areas[0] = unweightedHeuristic(sub_boxes[0]); + sub_box_areas[1] = unweightedHeuristic(sub_boxes[1]); + for (INT_TYPE nsub = 2; nsub < N; ++nsub) { + // Choose which one to split + INT_TYPE split_choice = INT_TYPE(-1); + T max_heuristic; + for (INT_TYPE i = 0; i < nsub; ++i) { + const INT_TYPE index_count = (sub_indices[i+1]-sub_indices[i]); + if (index_count > 1) { + const T heuristic = sub_box_areas[i]*index_count; + if (split_choice == INT_TYPE(-1) || heuristic > max_heuristic) { + split_choice = i; + max_heuristic = heuristic; + } + } + } + UT_ASSERT_MSG_P(split_choice != INT_TYPE(-1), "There should always be at least one that can be split!"); + + SRC_INT_TYPE* selected_start = sub_indices[split_choice]; + SRC_INT_TYPE* selected_end = sub_indices[split_choice+1]; + + // Shift results over; we can skip the one we selected. + for (INT_TYPE i = nsub; i > split_choice; --i) { + sub_indices[i+1] = sub_indices[i]; + } + for (INT_TYPE i = nsub-1; i > split_choice; --i) { + sub_boxes[i+1] = sub_boxes[i]; + } + for (INT_TYPE i = nsub-1; i > split_choice; --i) { + sub_box_areas[i+1] = sub_box_areas[i]; + } + + // Do the split + split(sub_boxes[split_choice], boxes, selected_start, selected_end-selected_start, sub_indices[split_choice+1], &sub_boxes[split_choice]); + sub_box_areas[split_choice] = unweightedHeuristic(sub_boxes[split_choice]); + sub_box_areas[split_choice+1] = unweightedHeuristic(sub_boxes[split_choice+1]); + } + } +} + +template +template +inline void BVH::split(const Box& axes_minmax, const BOX_TYPE* boxes, SRC_INT_TYPE* indices, INT_TYPE nboxes, SRC_INT_TYPE*& split_indices, Box* split_boxes) noexcept { + if (nboxes == 2) { + split_boxes[0].initBounds(boxes[indices[0]]); + split_boxes[1].initBounds(boxes[indices[1]]); + split_indices = indices+1; + return; + } + UT_ASSERT_MSG_P(nboxes > 2, "Cases with less than 3 boxes should have already been handled!"); + + if (H == BVH_Heuristic::MEDIAN_MAX_AXIS) { + UT_ASSERT_MSG(0, "FIXME: Implement this!!!"); + } + + constexpr INT_TYPE SMALL_LIMIT = 6; + if (nboxes <= SMALL_LIMIT) { + // Special case for a small number of boxes: check all (2^(n-1))-1 partitions. + // Without loss of generality, we assume that box 0 is in partition 0, + // and that not all boxes are in partition 0. + Box local_boxes[SMALL_LIMIT]; + for (INT_TYPE box = 0; box < nboxes; ++box) { + local_boxes[box].initBounds(boxes[indices[box]]); + //printf("Box %u: (%f-%f)x(%f-%f)x(%f-%f)\n", uint(box), local_boxes[box].vals[0][0], local_boxes[box].vals[0][1], local_boxes[box].vals[1][0], local_boxes[box].vals[1][1], local_boxes[box].vals[2][0], local_boxes[box].vals[2][1]); + } + const INT_TYPE partition_limit = (INT_TYPE(1)<<(nboxes-1)); + INT_TYPE best_partition = INT_TYPE(-1); + T best_heuristic; + for (INT_TYPE partition_bits = 1; partition_bits < partition_limit; ++partition_bits) { + Box sub_boxes[2]; + sub_boxes[0] = local_boxes[0]; + sub_boxes[1].initBounds(); + INT_TYPE sub_counts[2] = {1,0}; + for (INT_TYPE bit = 0; bit < nboxes-1; ++bit) { + INT_TYPE dest = (partition_bits>>bit)&1; + sub_boxes[dest].combine(local_boxes[bit+1]); + ++sub_counts[dest]; + } + //printf("Partition bits %u: sub_box[0]: (%f-%f)x(%f-%f)x(%f-%f)\n", uint(partition_bits), sub_boxes[0].vals[0][0], sub_boxes[0].vals[0][1], sub_boxes[0].vals[1][0], sub_boxes[0].vals[1][1], sub_boxes[0].vals[2][0], sub_boxes[0].vals[2][1]); + //printf("Partition bits %u: sub_box[1]: (%f-%f)x(%f-%f)x(%f-%f)\n", uint(partition_bits), sub_boxes[1].vals[0][0], sub_boxes[1].vals[0][1], sub_boxes[1].vals[1][0], sub_boxes[1].vals[1][1], sub_boxes[1].vals[2][0], sub_boxes[1].vals[2][1]); + const T heuristic = + unweightedHeuristic(sub_boxes[0])*sub_counts[0] + + unweightedHeuristic(sub_boxes[1])*sub_counts[1]; + //printf("Partition bits %u: heuristic = %f (= %f*%u + %f*%u)\n",uint(partition_bits),heuristic, unweightedHeuristic(sub_boxes[0]), uint(sub_counts[0]), unweightedHeuristic(sub_boxes[1]), uint(sub_counts[1])); + if (best_partition == INT_TYPE(-1) || heuristic < best_heuristic) { + //printf(" New best\n"); + best_partition = partition_bits; + best_heuristic = heuristic; + split_boxes[0] = sub_boxes[0]; + split_boxes[1] = sub_boxes[1]; + } + } + +#if 0 // This isn't actually necessary with the current design, because I changed how the number of subtree nodes is determined. + // If best_partition is partition_limit-1, there's only 1 box + // in partition 0. We should instead put this in partition 1, + // so that we can help always have the internal node indices first + // in each node. That gets used to (fairly) quickly determine + // the number of nodes in a sub-tree. + if (best_partition == partition_limit - 1) { + // Put the first index last. + SRC_INT_TYPE last_index = indices[0]; + SRC_INT_TYPE* dest_indices = indices; + SRC_INT_TYPE* local_split_indices = indices + nboxes-1; + for (; dest_indices != local_split_indices; ++dest_indices) { + dest_indices[0] = dest_indices[1]; + } + *local_split_indices = last_index; + split_indices = local_split_indices; + + // Swap the boxes + const Box temp_box = sub_boxes[0]; + sub_boxes[0] = sub_boxes[1]; + sub_boxes[1] = temp_box; + return; + } +#endif + + // Reorder the indices. + // NOTE: Index 0 is always in partition 0, so can stay put. + SRC_INT_TYPE local_indices[SMALL_LIMIT-1]; + for (INT_TYPE box = 0; box < nboxes-1; ++box) { + local_indices[box] = indices[box+1]; + } + SRC_INT_TYPE* dest_indices = indices+1; + SRC_INT_TYPE* src_indices = local_indices; + // Copy partition 0 + for (INT_TYPE bit = 0; bit < nboxes-1; ++bit, ++src_indices) { + if (!((best_partition>>bit)&1)) { + //printf("Copying %u into partition 0\n",uint(*src_indices)); + *dest_indices = *src_indices; + ++dest_indices; + } + } + split_indices = dest_indices; + // Copy partition 1 + src_indices = local_indices; + for (INT_TYPE bit = 0; bit < nboxes-1; ++bit, ++src_indices) { + if ((best_partition>>bit)&1) { + //printf("Copying %u into partition 1\n",uint(*src_indices)); + *dest_indices = *src_indices; + ++dest_indices; + } + } + return; + } + + uint max_axis = 0; + T max_axis_length = axes_minmax.vals[0][1] - axes_minmax.vals[0][0]; + for (uint axis = 1; axis < NAXES; ++axis) { + const T axis_length = axes_minmax.vals[axis][1] - axes_minmax.vals[axis][0]; + if (axis_length > max_axis_length) { + max_axis = axis; + max_axis_length = axis_length; + } + } + + if (!(max_axis_length > T(0))) { + // All boxes are a single point or NaN. + // Pick an arbitrary split point. + split_indices = indices + nboxes/2; + split_boxes[0] = axes_minmax; + split_boxes[1] = axes_minmax; + return; + } + + const INT_TYPE axis = max_axis; + + constexpr INT_TYPE MID_LIMIT = 2*NSPANS; + if (nboxes <= MID_LIMIT) { + // Sort along axis, and try all possible splits. + +#if 1 + // First, compute midpoints + T midpointsx2[MID_LIMIT]; + for (INT_TYPE i = 0; i < nboxes; ++i) { + midpointsx2[i] = utBoxCenter(boxes[indices[i]], axis); + } + SRC_INT_TYPE local_indices[MID_LIMIT]; + for (INT_TYPE i = 0; i < nboxes; ++i) { + local_indices[i] = i; + } + + const INT_TYPE chunk_starts[5] = {0, nboxes/4, nboxes/2, INT_TYPE((3*uint64(nboxes))/4), nboxes}; + + // For sorting, insertion sort 4 chunks and merge them + for (INT_TYPE chunk = 0; chunk < 4; ++chunk) { + const INT_TYPE start = chunk_starts[chunk]; + const INT_TYPE end = chunk_starts[chunk+1]; + for (INT_TYPE i = start+1; i < end; ++i) { + SRC_INT_TYPE indexi = local_indices[i]; + T vi = midpointsx2[indexi]; + for (INT_TYPE j = start; j < i; ++j) { + SRC_INT_TYPE indexj = local_indices[j]; + T vj = midpointsx2[indexj]; + if (vi < vj) { + do { + local_indices[j] = indexi; + indexi = indexj; + ++j; + if (j == i) { + local_indices[j] = indexi; + break; + } + indexj = local_indices[j]; + } while (true); + break; + } + } + } + } + // Merge chunks into another buffer + SRC_INT_TYPE local_indices_temp[MID_LIMIT]; + std::merge(local_indices, local_indices+chunk_starts[1], + local_indices+chunk_starts[1], local_indices+chunk_starts[2], + local_indices_temp, [&midpointsx2](const SRC_INT_TYPE a, const SRC_INT_TYPE b)->bool { + return midpointsx2[a] < midpointsx2[b]; + }); + std::merge(local_indices+chunk_starts[2], local_indices+chunk_starts[3], + local_indices+chunk_starts[3], local_indices+chunk_starts[4], + local_indices_temp+chunk_starts[2], [&midpointsx2](const SRC_INT_TYPE a, const SRC_INT_TYPE b)->bool { + return midpointsx2[a] < midpointsx2[b]; + }); + std::merge(local_indices_temp, local_indices_temp+chunk_starts[2], + local_indices_temp+chunk_starts[2], local_indices_temp+chunk_starts[4], + local_indices, [&midpointsx2](const SRC_INT_TYPE a, const SRC_INT_TYPE b)->bool { + return midpointsx2[a] < midpointsx2[b]; + }); + + // Translate local_indices into indices + for (INT_TYPE i = 0; i < nboxes; ++i) { + local_indices[i] = indices[local_indices[i]]; + } + // Copy back + for (INT_TYPE i = 0; i < nboxes; ++i) { + indices[i] = local_indices[i]; + } +#else + std::stable_sort(indices, indices+nboxes, [boxes,max_axis](SRC_INT_TYPE a, SRC_INT_TYPE b)->bool { + return utBoxCenter(boxes[a], max_axis) < utBoxCenter(boxes[b], max_axis); + }); +#endif + + // Accumulate boxes + Box left_boxes[MID_LIMIT-1]; + Box right_boxes[MID_LIMIT-1]; + const INT_TYPE nsplits = nboxes-1; + Box box_accumulator(boxes[local_indices[0]]); + left_boxes[0] = box_accumulator; + for (INT_TYPE i = 1; i < nsplits; ++i) { + box_accumulator.combine(boxes[local_indices[i]]); + left_boxes[i] = box_accumulator; + } + box_accumulator.initBounds(boxes[local_indices[nsplits-1]]); + right_boxes[nsplits-1] = box_accumulator; + for (INT_TYPE i = nsplits-1; i > 0; --i) { + box_accumulator.combine(boxes[local_indices[i]]); + right_boxes[i-1] = box_accumulator; + } + + INT_TYPE best_split = 0; + T best_local_heuristic = + unweightedHeuristic(left_boxes[0]) + + unweightedHeuristic(right_boxes[0])*(nboxes-1); + for (INT_TYPE split = 1; split < nsplits; ++split) { + const T heuristic = + unweightedHeuristic(left_boxes[split])*(split+1) + + unweightedHeuristic(right_boxes[split])*(nboxes-(split+1)); + if (heuristic < best_local_heuristic) { + best_split = split; + best_local_heuristic = heuristic; + } + } + split_indices = indices+best_split+1; + split_boxes[0] = left_boxes[best_split]; + split_boxes[1] = right_boxes[best_split]; + return; + } + + const T axis_min = axes_minmax.vals[max_axis][0]; + const T axis_length = max_axis_length; + Box span_boxes[NSPANS]; + for (INT_TYPE i = 0; i < NSPANS; ++i) { + span_boxes[i].initBounds(); + } + INT_TYPE span_counts[NSPANS]; + for (INT_TYPE i = 0; i < NSPANS; ++i) { + span_counts[i] = 0; + } + + const T axis_min_x2 = ut_BoxCentre::scale*axis_min; + // NOTE: Factor of 0.5 is factored out of the average when using the average value to determine the span that a box lies in. + const T axis_index_scale = (T(1.0/ut_BoxCentre::scale)*NSPANS)/axis_length; + constexpr INT_TYPE BOX_SPANS_PARALLEL_THRESHOLD = 2048; + INT_TYPE ntasks = 1; + if (nboxes >= BOX_SPANS_PARALLEL_THRESHOLD) { + INT_TYPE nprocessors = UT_Thread::getNumProcessors(); + ntasks = (nprocessors > 1) ? SYSmin(4*nprocessors, nboxes/(BOX_SPANS_PARALLEL_THRESHOLD/2)) : 1; + } + if (ntasks == 1) { + for (INT_TYPE indexi = 0; indexi < nboxes; ++indexi) { + const auto& box = boxes[indices[indexi]]; + const T sum = utBoxCenter(box, axis); + const uint span_index = SYSclamp(int((sum-axis_min_x2)*axis_index_scale), int(0), int(NSPANS-1)); + ++span_counts[span_index]; + Box& span_box = span_boxes[span_index]; + span_box.combine(box); + } + } + else { + UT_SmallArray> parallel_boxes; + UT_SmallArray parallel_counts; + igl::parallel_for( + nboxes, + [¶llel_boxes,¶llel_counts](int n) + { + parallel_boxes.setSize( NSPANS*n); + parallel_counts.setSize(NSPANS*n); + for(int t = 0;t& span_box = parallel_boxes[t*NSPANS+span_index]; + span_box.combine(box); + }, + [¶llel_boxes,¶llel_counts,&span_boxes,&span_counts](int t) + { + for(int i = 0;i left_boxes[NSPLITS]; + // Spans 1 to NSPANS-1 + Box right_boxes[NSPLITS]; + + // Accumulate boxes + Box box_accumulator = span_boxes[0]; + left_boxes[0] = box_accumulator; + for (INT_TYPE i = 1; i < NSPLITS; ++i) { + box_accumulator.combine(span_boxes[i]); + left_boxes[i] = box_accumulator; + } + box_accumulator = span_boxes[NSPANS-1]; + right_boxes[NSPLITS-1] = box_accumulator; + for (INT_TYPE i = NSPLITS-1; i > 0; --i) { + box_accumulator.combine(span_boxes[i]); + right_boxes[i-1] = box_accumulator; + } + + INT_TYPE left_counts[NSPLITS]; + + // Accumulate counts + INT_TYPE count_accumulator = span_counts[0]; + left_counts[0] = count_accumulator; + for (INT_TYPE spliti = 1; spliti < NSPLITS; ++spliti) { + count_accumulator += span_counts[spliti]; + left_counts[spliti] = count_accumulator; + } + + // Check which split is optimal, making sure that at least 1/MIN_FRACTION of all boxes are on each side. + const INT_TYPE min_count = nboxes/MIN_FRACTION; + UT_ASSERT_MSG_P(min_count > 0, "MID_LIMIT above should have been large enough that nboxes would be > MIN_FRACTION"); + const INT_TYPE max_count = ((MIN_FRACTION-1)*uint64(nboxes))/MIN_FRACTION; + UT_ASSERT_MSG_P(max_count < nboxes, "I'm not sure how this could happen mathematically, but it needs to be checked."); + T smallest_heuristic = std::numeric_limits::infinity(); + INT_TYPE split_index = -1; + for (INT_TYPE spliti = 0; spliti < NSPLITS; ++spliti) { + const INT_TYPE left_count = left_counts[spliti]; + if (left_count < min_count || left_count > max_count) { + continue; + } + const INT_TYPE right_count = nboxes-left_count; + const T heuristic = + left_count*unweightedHeuristic(left_boxes[spliti]) + + right_count*unweightedHeuristic(right_boxes[spliti]); + if (heuristic < smallest_heuristic) { + smallest_heuristic = heuristic; + split_index = spliti; + } + } + + SRC_INT_TYPE*const indices_end = indices+nboxes; + + if (split_index == -1) { + // No split was anywhere close to balanced, so we fall back to searching for one. + + // First, find the span containing the "balance" point, namely where left_counts goes from + // being less than min_count to more than max_count. + // If that's span 0, use max_count as the ordered index to select, + // if it's span NSPANS-1, use min_count as the ordered index to select, + // else use nboxes/2 as the ordered index to select. + //T min_pivotx2 = -std::numeric_limits::infinity(); + //T max_pivotx2 = std::numeric_limits::infinity(); + SRC_INT_TYPE* nth_index; + if (left_counts[0] > max_count) { + // Search for max_count ordered index + nth_index = indices+max_count; + //max_pivotx2 = max_axis_min_x2 + max_axis_length/(NSPANS/ut_BoxCentre::scale); + } + else if (left_counts[NSPLITS-1] < min_count) { + // Search for min_count ordered index + nth_index = indices+min_count; + //min_pivotx2 = max_axis_min_x2 + max_axis_length - max_axis_length/(NSPANS/ut_BoxCentre::scale); + } + else { + // Search for nboxes/2 ordered index + nth_index = indices+nboxes/2; + //for (INT_TYPE spliti = 1; spliti < NSPLITS; ++spliti) { + // // The second condition should be redundant, but is just in case. + // if (left_counts[spliti] > max_count || spliti == NSPLITS-1) { + // min_pivotx2 = max_axis_min_x2 + spliti*max_axis_length/(NSPANS/ut_BoxCentre::scale); + // max_pivotx2 = max_axis_min_x2 + (spliti+1)*max_axis_length/(NSPANS/ut_BoxCentre::scale); + // break; + // } + //} + } + nthElement(boxes,indices,indices+nboxes,max_axis,nth_index);//,min_pivotx2,max_pivotx2); + + split_indices = nth_index; + Box left_box(boxes[indices[0]]); + for (SRC_INT_TYPE* left_indices = indices+1; left_indices < nth_index; ++left_indices) { + left_box.combine(boxes[*left_indices]); + } + Box right_box(boxes[nth_index[0]]); + for (SRC_INT_TYPE* right_indices = nth_index+1; right_indices < indices_end; ++right_indices) { + right_box.combine(boxes[*right_indices]); + } + split_boxes[0] = left_box; + split_boxes[1] = right_box; + } + else { + const T pivotx2 = axis_min_x2 + (split_index+1)*axis_length/(NSPANS/ut_BoxCentre::scale); + SRC_INT_TYPE* ppivot_start; + SRC_INT_TYPE* ppivot_end; + partitionByCentre(boxes,indices,indices+nboxes,max_axis,pivotx2,ppivot_start,ppivot_end); + + split_indices = indices + left_counts[split_index]; + + // Ignoring roundoff error, we would have + // split_indices >= ppivot_start && split_indices <= ppivot_end, + // but it may not always be in practice. + if (split_indices >= ppivot_start && split_indices <= ppivot_end) { + split_boxes[0] = left_boxes[split_index]; + split_boxes[1] = right_boxes[split_index]; + return; + } + + // Roundoff error changed the split, so we need to recompute the boxes. + if (split_indices < ppivot_start) { + split_indices = ppivot_start; + } + else {//(split_indices > ppivot_end) + split_indices = ppivot_end; + } + + // Emergency checks, just in case + if (split_indices == indices) { + ++split_indices; + } + else if (split_indices == indices_end) { + --split_indices; + } + + Box left_box(boxes[indices[0]]); + for (SRC_INT_TYPE* left_indices = indices+1; left_indices < split_indices; ++left_indices) { + left_box.combine(boxes[*left_indices]); + } + Box right_box(boxes[split_indices[0]]); + for (SRC_INT_TYPE* right_indices = split_indices+1; right_indices < indices_end; ++right_indices) { + right_box.combine(boxes[*right_indices]); + } + split_boxes[0] = left_box; + split_boxes[1] = right_box; + } +} + +template +template +inline void BVH::adjustParallelChildNodes(INT_TYPE nparallel, UT_Array& nodes, Node& node, UT_Array* parallel_nodes, SRC_INT_TYPE* sub_indices) noexcept +{ + // Alec: No need to parallelize this... + //UTparallelFor(UT_BlockedRange(0,nparallel), [&node,&nodes,¶llel_nodes,&sub_indices](const UT_BlockedRange& r) { + INT_TYPE counted_parallel = 0; + INT_TYPE childi = 0; + for(int taski = 0;taski < nparallel; taski++) + { + //for (INT_TYPE taski = r.begin(), end = r.end(); taski < end; ++taski) { + // First, find which child this is + INT_TYPE sub_nboxes; + for (; childi < N; ++childi) { + sub_nboxes = sub_indices[childi+1]-sub_indices[childi]; + if (sub_nboxes >= PARALLEL_THRESHOLD) { + if (counted_parallel == taski) { + break; + } + ++counted_parallel; + } + } + UT_ASSERT_P(counted_parallel == taski); + + const UT_Array& local_nodes = parallel_nodes[counted_parallel]; + INT_TYPE n = local_nodes.size(); + INT_TYPE local_nodes_start = Node::getInternalNum(node.child[childi])+1; + ++counted_parallel; + ++childi; + + for (INT_TYPE j = 0; j < n; ++j) { + Node local_node = local_nodes[j]; + for (INT_TYPE childj = 0; childj < N; ++childj) { + INT_TYPE local_child = local_node.child[childj]; + if (Node::isInternal(local_child) && local_child != Node::EMPTY) { + local_child += local_nodes_start; + local_node.child[childj] = local_child; + } + } + nodes[local_nodes_start+j] = local_node; + } + } +} + +template +template +void BVH::nthElement(const BOX_TYPE* boxes, SRC_INT_TYPE* indices, const SRC_INT_TYPE* indices_end, const uint axis, SRC_INT_TYPE*const nth) noexcept {//, const T min_pivotx2, const T max_pivotx2) noexcept { + while (true) { + // Choose median of first, middle, and last as the pivot + T pivots[3] = { + utBoxCenter(boxes[indices[0]], axis), + utBoxCenter(boxes[indices[(indices_end-indices)/2]], axis), + utBoxCenter(boxes[*(indices_end-1)], axis) + }; + if (pivots[0] < pivots[1]) { + const T temp = pivots[0]; + pivots[0] = pivots[1]; + pivots[1] = temp; + } + if (pivots[0] < pivots[2]) { + const T temp = pivots[0]; + pivots[0] = pivots[2]; + pivots[2] = temp; + } + if (pivots[1] < pivots[2]) { + const T temp = pivots[1]; + pivots[1] = pivots[2]; + pivots[2] = temp; + } + T mid_pivotx2 = pivots[1]; +#if 0 + // We limit the pivot, because we know that the true value is between min and max + if (mid_pivotx2 < min_pivotx2) { + mid_pivotx2 = min_pivotx2; + } + else if (mid_pivotx2 > max_pivotx2) { + mid_pivotx2 = max_pivotx2; + } +#endif + SRC_INT_TYPE* pivot_start; + SRC_INT_TYPE* pivot_end; + partitionByCentre(boxes,indices,indices_end,axis,mid_pivotx2,pivot_start,pivot_end); + if (nth < pivot_start) { + indices_end = pivot_start; + } + else if (nth < pivot_end) { + // nth is in the middle of the pivot range, + // which is in the right place, so we're done. + return; + } + else { + indices = pivot_end; + } + if (indices_end <= indices+1) { + return; + } + } +} + +template +template +void BVH::partitionByCentre(const BOX_TYPE* boxes, SRC_INT_TYPE*const indices, const SRC_INT_TYPE*const indices_end, const uint axis, const T pivotx2, SRC_INT_TYPE*& ppivot_start, SRC_INT_TYPE*& ppivot_end) noexcept { + // TODO: Consider parallelizing this! + + // First element >= pivot + SRC_INT_TYPE* pivot_start = indices; + // First element > pivot + SRC_INT_TYPE* pivot_end = indices; + + // Loop through forward once + for (SRC_INT_TYPE* psrc_index = indices; psrc_index != indices_end; ++psrc_index) { + const T srcsum = utBoxCenter(boxes[*psrc_index], axis); + if (srcsum < pivotx2) { + if (psrc_index != pivot_start) { + if (pivot_start == pivot_end) { + // Common case: nothing equal to the pivot + const SRC_INT_TYPE temp = *psrc_index; + *psrc_index = *pivot_start; + *pivot_start = temp; + } + else { + // Less common case: at least one thing equal to the pivot + const SRC_INT_TYPE temp = *psrc_index; + *psrc_index = *pivot_end; + *pivot_end = *pivot_start; + *pivot_start = temp; + } + } + ++pivot_start; + ++pivot_end; + } + else if (srcsum == pivotx2) { + // Add to the pivot area + if (psrc_index != pivot_end) { + const SRC_INT_TYPE temp = *psrc_index; + *psrc_index = *pivot_end; + *pivot_end = temp; + } + ++pivot_end; + } + } + ppivot_start = pivot_start; + ppivot_end = pivot_end; +} + +#if 0 +template +void BVH::debugDump() const { + printf("\nNode 0: {\n"); + UT_WorkBuffer indent; + indent.append(80, ' '); + UT_Array stack; + stack.append(0); + stack.append(0); + while (!stack.isEmpty()) { + int depth = stack.size()/2; + if (indent.length() < 4*depth) { + indent.append(4, ' '); + } + INT_TYPE cur_nodei = stack[stack.size()-2]; + INT_TYPE cur_i = stack[stack.size()-1]; + if (cur_i == N) { + printf(indent.buffer()+indent.length()-(4*(depth-1))); + printf("}\n"); + stack.removeLast(); + stack.removeLast(); + continue; + } + ++stack[stack.size()-1]; + Node& cur_node = myRoot[cur_nodei]; + INT_TYPE child_nodei = cur_node.child[cur_i]; + if (Node::isInternal(child_nodei)) { + if (child_nodei == Node::EMPTY) { + printf(indent.buffer()+indent.length()-(4*(depth-1))); + printf("}\n"); + stack.removeLast(); + stack.removeLast(); + continue; + } + INT_TYPE internal_node = Node::getInternalNum(child_nodei); + printf(indent.buffer()+indent.length()-(4*depth)); + printf("Node %u: {\n", uint(internal_node)); + stack.append(internal_node); + stack.append(0); + continue; + } + else { + printf(indent.buffer()+indent.length()-(4*depth)); + printf("Tri %u\n", uint(child_nodei)); + } + } +} +#endif + +} // UT namespace +} // End HDK_Sample namespace +}} +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Functions and structures for computing solid angles. + */ + +#pragma once + +#ifndef __HDK_UT_SolidAngle_h__ +#define __HDK_UT_SolidAngle_h__ + + + + + +#include + +namespace igl { namespace FastWindingNumber { +namespace HDK_Sample { + +template +using UT_Vector2T = UT_FixedVector; +template +using UT_Vector3T = UT_FixedVector; + +template +SYS_FORCE_INLINE T cross(const UT_Vector2T &v1, const UT_Vector2T &v2) +{ + return v1[0]*v2[1] - v1[1]*v2[0]; +} + +template +SYS_FORCE_INLINE +UT_Vector3T cross(const UT_Vector3T &v1, const UT_Vector3T &v2) +{ + UT_Vector3T result; + // compute the cross product: + result[0] = v1[1]*v2[2] - v1[2]*v2[1]; + result[1] = v1[2]*v2[0] - v1[0]*v2[2]; + result[2] = v1[0]*v2[1] - v1[1]*v2[0]; + return result; +} + +/// Returns the signed solid angle subtended by triangle abc +/// from query point. +/// +/// WARNING: This uses the right-handed normal convention, whereas most of +/// Houdini uses the left-handed normal convention, so either +/// negate the output, or swap b and c if you want it to be +/// positive inside and negative outside. +template +inline T UTsignedSolidAngleTri( + const UT_Vector3T &a, + const UT_Vector3T &b, + const UT_Vector3T &c, + const UT_Vector3T &query) +{ + // Make a, b, and c relative to query + UT_Vector3T qa = a-query; + UT_Vector3T qb = b-query; + UT_Vector3T qc = c-query; + + const T alength = qa.length(); + const T blength = qb.length(); + const T clength = qc.length(); + + // If any triangle vertices are coincident with query, + // query is on the surface, which we treat as no solid angle. + if (alength == 0 || blength == 0 || clength == 0) + return T(0); + + // Normalize the vectors + qa /= alength; + qb /= blength; + qc /= clength; + + // The formula on Wikipedia has roughly dot(qa,cross(qb,qc)), + // but that's unstable when qa, qb, and qc are very close, + // (e.g. if the input triangle was very far away). + // This should be equivalent, but more stable. + const T numerator = dot(qa, cross(qb-qa, qc-qa)); + + // If numerator is 0, regardless of denominator, query is on the + // surface, which we treat as no solid angle. + if (numerator == 0) + return T(0); + + const T denominator = T(1) + dot(qa,qb) + dot(qa,qc) + dot(qb,qc); + + return T(2)*SYSatan2(numerator, denominator); +} + +template +inline T UTsignedSolidAngleQuad( + const UT_Vector3T &a, + const UT_Vector3T &b, + const UT_Vector3T &c, + const UT_Vector3T &d, + const UT_Vector3T &query) +{ + // Make a, b, c, and d relative to query + UT_Vector3T v[4] = { + a-query, + b-query, + c-query, + d-query + }; + + const T lengths[4] = { + v[0].length(), + v[1].length(), + v[2].length(), + v[3].length() + }; + + // If any quad vertices are coincident with query, + // query is on the surface, which we treat as no solid angle. + // We could add the contribution from the non-planar part, + // but in the context of a mesh, we'd still miss some, like + // we do in the triangle case. + if (lengths[0] == T(0) || lengths[1] == T(0) || lengths[2] == T(0) || lengths[3] == T(0)) + return T(0); + + // Normalize the vectors + v[0] /= lengths[0]; + v[1] /= lengths[1]; + v[2] /= lengths[2]; + v[3] /= lengths[3]; + + // Compute (unnormalized, but consistently-scaled) barycentric coordinates + // for the query point inside the tetrahedron of points. + // If 0 or 4 of the coordinates are positive, (or slightly negative), the + // query is (approximately) inside, so the choice of triangulation matters. + // Otherwise, the triangulation doesn't matter. + + const UT_Vector3T diag02 = v[2]-v[0]; + const UT_Vector3T diag13 = v[3]-v[1]; + const UT_Vector3T v01 = v[1]-v[0]; + const UT_Vector3T v23 = v[3]-v[2]; + + T bary[4]; + bary[0] = dot(v[3],cross(v23,diag13)); + bary[1] = -dot(v[2],cross(v23,diag02)); + bary[2] = -dot(v[1],cross(v01,diag13)); + bary[3] = dot(v[0],cross(v01,diag02)); + + const T dot01 = dot(v[0],v[1]); + const T dot12 = dot(v[1],v[2]); + const T dot23 = dot(v[2],v[3]); + const T dot30 = dot(v[3],v[0]); + + T omega = T(0); + + // Equation of a bilinear patch in barycentric coordinates of its + // tetrahedron is x0*x2 = x1*x3. Less is one side; greater is other. + if (bary[0]*bary[2] < bary[1]*bary[3]) + { + // Split 0-2: triangles 0,1,2 and 0,2,3 + const T numerator012 = bary[3]; + const T numerator023 = bary[1]; + const T dot02 = dot(v[0],v[2]); + + // If numerator is 0, regardless of denominator, query is on the + // surface, which we treat as no solid angle. + if (numerator012 != T(0)) + { + const T denominator012 = T(1) + dot01 + dot12 + dot02; + omega = SYSatan2(numerator012, denominator012); + } + if (numerator023 != T(0)) + { + const T denominator023 = T(1) + dot02 + dot23 + dot30; + omega += SYSatan2(numerator023, denominator023); + } + } + else + { + // Split 1-3: triangles 0,1,3 and 1,2,3 + const T numerator013 = -bary[2]; + const T numerator123 = -bary[0]; + const T dot13 = dot(v[1],v[3]); + + // If numerator is 0, regardless of denominator, query is on the + // surface, which we treat as no solid angle. + if (numerator013 != T(0)) + { + const T denominator013 = T(1) + dot01 + dot13 + dot30; + omega = SYSatan2(numerator013, denominator013); + } + if (numerator123 != T(0)) + { + const T denominator123 = T(1) + dot12 + dot23 + dot13; + omega += SYSatan2(numerator123, denominator123); + } + } + return T(2)*omega; +} + +/// Class for quickly approximating signed solid angle of a large mesh +/// from many query points. This is useful for computing the +/// generalized winding number at many points. +/// +/// NOTE: This is currently only instantiated for . +template +class UT_SolidAngle +{ +public: + /// This is outlined so that we don't need to include UT_BVHImpl.h + inline UT_SolidAngle(); + /// This is outlined so that we don't need to include UT_BVHImpl.h + inline ~UT_SolidAngle(); + + /// NOTE: This does not take ownership over triangle_points or positions, + /// but does keep pointers to them, so the caller must keep them in + /// scope for the lifetime of this structure. + UT_SolidAngle( + const int ntriangles, + const int *const triangle_points, + const int npoints, + const UT_Vector3T *const positions, + const int order = 2) + : UT_SolidAngle() + { init(ntriangles, triangle_points, npoints, positions, order); } + + /// Initialize the tree and data. + /// NOTE: It is safe to call init on a UT_SolidAngle that has had init + /// called on it before, to re-initialize it. + inline void init( + const int ntriangles, + const int *const triangle_points, + const int npoints, + const UT_Vector3T *const positions, + const int order = 2); + + /// Frees myTree and myData, and clears the rest. + inline void clear(); + + /// Returns true if this is clear + bool isClear() const + { return myNTriangles == 0; } + + /// Returns an approximation of the signed solid angle of the mesh from the specified query_point + /// accuracy_scale is the value of (maxP/q) beyond which the approximation of the box will be used. + inline T computeSolidAngle(const UT_Vector3T &query_point, const T accuracy_scale = T(2.0)) const; + +private: + struct BoxData; + + static constexpr uint BVH_N = 4; + UT_BVH myTree; + int myNBoxes; + int myOrder; + std::unique_ptr myData; + int myNTriangles; + const int *myTrianglePoints; + int myNPoints; + const UT_Vector3T *myPositions; +}; + +template +inline T UTsignedAngleSegment( + const UT_Vector2T &a, + const UT_Vector2T &b, + const UT_Vector2T &query) +{ + // Make a and b relative to query + UT_Vector2T qa = a-query; + UT_Vector2T qb = b-query; + + // If any segment vertices are coincident with query, + // query is on the segment, which we treat as no angle. + if (qa.isZero() || qb.isZero()) + return T(0); + + // numerator = |qa||qb|sin(theta) + const T numerator = cross(qa, qb); + + // If numerator is 0, regardless of denominator, query is on the + // surface, which we treat as no solid angle. + if (numerator == 0) + return T(0); + + // denominator = |qa||qb|cos(theta) + const T denominator = dot(qa,qb); + + // numerator/denominator = tan(theta) + return SYSatan2(numerator, denominator); +} + +/// Class for quickly approximating signed subtended angle of a large curve +/// from many query points. This is useful for computing the +/// generalized winding number at many points. +/// +/// NOTE: This is currently only instantiated for . +template +class UT_SubtendedAngle +{ +public: + /// This is outlined so that we don't need to include UT_BVHImpl.h + inline UT_SubtendedAngle(); + /// This is outlined so that we don't need to include UT_BVHImpl.h + inline ~UT_SubtendedAngle(); + + /// NOTE: This does not take ownership over segment_points or positions, + /// but does keep pointers to them, so the caller must keep them in + /// scope for the lifetime of this structure. + UT_SubtendedAngle( + const int nsegments, + const int *const segment_points, + const int npoints, + const UT_Vector2T *const positions, + const int order = 2) + : UT_SubtendedAngle() + { init(nsegments, segment_points, npoints, positions, order); } + + /// Initialize the tree and data. + /// NOTE: It is safe to call init on a UT_SolidAngle that has had init + /// called on it before, to re-initialize it. + inline void init( + const int nsegments, + const int *const segment_points, + const int npoints, + const UT_Vector2T *const positions, + const int order = 2); + + /// Frees myTree and myData, and clears the rest. + inline void clear(); + + /// Returns true if this is clear + bool isClear() const + { return myNSegments == 0; } + + /// Returns an approximation of the signed solid angle of the mesh from the specified query_point + /// accuracy_scale is the value of (maxP/q) beyond which the approximation of the box will be used. + inline T computeAngle(const UT_Vector2T &query_point, const T accuracy_scale = T(2.0)) const; + +private: + struct BoxData; + + static constexpr uint BVH_N = 4; + UT_BVH myTree; + int myNBoxes; + int myOrder; + std::unique_ptr myData; + int myNSegments; + const int *mySegmentPoints; + int myNPoints; + const UT_Vector2T *myPositions; +}; + +} // End HDK_Sample namespace +}} +#endif +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * A wrapper function for the "free" function, used by UT_(Small)Array + */ + + + +#include + +namespace igl { namespace FastWindingNumber { + +// This needs to be here or else the warning suppression doesn't work because +// the templated calling code won't otherwise be compiled until after we've +// already popped the warning.state. So we just always disable this at file +// scope here. +#if defined(__GNUC__) && !defined(__clang__) + _Pragma("GCC diagnostic push") + _Pragma("GCC diagnostic ignored \"-Wfree-nonheap-object\"") +#endif +inline void ut_ArrayImplFree(void *p) +{ + free(p); +} +#if defined(__GNUC__) && !defined(__clang__) + _Pragma("GCC diagnostic pop") +#endif +} } +/* + * Copyright (c) 2018 Side Effects Software Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * COMMENTS: + * Functions and structures for computing solid angles. + */ + + + + + + + + +#include +#include +#include + +#define SOLID_ANGLE_TIME_PRECOMPUTE 0 + +#if SOLID_ANGLE_TIME_PRECOMPUTE +#include +#endif + +#define SOLID_ANGLE_DEBUG 0 +#if SOLID_ANGLE_DEBUG +#include +#endif + +#define TAYLOR_SERIES_ORDER 2 + +namespace igl { namespace FastWindingNumber { + +namespace HDK_Sample { + +template +struct UT_SolidAngle::BoxData +{ + void clear() + { + // Set everything to zero + memset(this,0,sizeof(*this)); + } + + using Type = typename std::conditional::value, v4uf, UT_FixedVector>::type; + using SType = typename std::conditional::value, v4uf, UT_FixedVector>::type; + + /// An upper bound on the squared distance from myAverageP to the farthest point in the box. + SType myMaxPDist2; + + /// Centre of mass of the mesh surface in this box + UT_FixedVector myAverageP; + + /// Unnormalized, area-weighted normal of the mesh in this box + UT_FixedVector myN; + +#if TAYLOR_SERIES_ORDER >= 1 + /// Values for Omega_1 + /// @{ + UT_FixedVector myNijDiag; // Nxx, Nyy, Nzz + Type myNxy_Nyx; // Nxy+Nyx + Type myNyz_Nzy; // Nyz+Nzy + Type myNzx_Nxz; // Nzx+Nxz + /// @} +#endif + +#if TAYLOR_SERIES_ORDER >= 2 + /// Values for Omega_2 + /// @{ + UT_FixedVector myNijkDiag; // Nxxx, Nyyy, Nzzz + Type mySumPermuteNxyz; // (Nxyz+Nxzy+Nyzx+Nyxz+Nzxy+Nzyx) = 2*(Nxyz+Nyzx+Nzxy) + Type my2Nxxy_Nyxx; // Nxxy+Nxyx+Nyxx = 2Nxxy+Nyxx + Type my2Nxxz_Nzxx; // Nxxz+Nxzx+Nzxx = 2Nxxz+Nzxx + Type my2Nyyz_Nzyy; // Nyyz+Nyzy+Nzyy = 2Nyyz+Nzyy + Type my2Nyyx_Nxyy; // Nyyx+Nyxy+Nxyy = 2Nyyx+Nxyy + Type my2Nzzx_Nxzz; // Nzzx+Nzxz+Nxzz = 2Nzzx+Nxzz + Type my2Nzzy_Nyzz; // Nzzy+Nzyz+Nyzz = 2Nzzy+Nyzz + /// @} +#endif +}; + +template +inline UT_SolidAngle::UT_SolidAngle() + : myTree() + , myNBoxes(0) + , myOrder(2) + , myData(nullptr) + , myNTriangles(0) + , myTrianglePoints(nullptr) + , myNPoints(0) + , myPositions(nullptr) +{} + +template +inline UT_SolidAngle::~UT_SolidAngle() +{ + // Default destruction works, but this needs to be outlined + // to avoid having to include UT_BVHImpl.h in the header, + // (for the UT_UniquePtr destructor.) +} + +template +inline void UT_SolidAngle::init( + const int ntriangles, + const int *const triangle_points, + const int npoints, + const UT_Vector3T *const positions, + const int order) +{ +#if SOLID_ANGLE_DEBUG + UTdebugFormat(""); + UTdebugFormat(""); + UTdebugFormat("Building BVH for {} ntriangles on {} points:", ntriangles, npoints); +#endif + myOrder = order; + myNTriangles = ntriangles; + myTrianglePoints = triangle_points; + myNPoints = npoints; + myPositions = positions; + +#if SOLID_ANGLE_TIME_PRECOMPUTE + UT_StopWatch timer; + timer.start(); +#endif + UT_SmallArray> triangle_boxes; + triangle_boxes.setSizeNoInit(ntriangles); + if (ntriangles < 16*1024) + { + const int *cur_triangle_points = triangle_points; + for (int i = 0; i < ntriangles; ++i, cur_triangle_points += 3) + { + UT::Box &box = triangle_boxes[i]; + box.initBounds(positions[cur_triangle_points[0]]); + box.enlargeBounds(positions[cur_triangle_points[1]]); + box.enlargeBounds(positions[cur_triangle_points[2]]); + } + } + else + { + igl::parallel_for(ntriangles, + [triangle_points,&triangle_boxes,positions](int i) + { + const int *cur_triangle_points = triangle_points + i*3; + UT::Box &box = triangle_boxes[i]; + box.initBounds(positions[cur_triangle_points[0]]); + box.enlargeBounds(positions[cur_triangle_points[1]]); + box.enlargeBounds(positions[cur_triangle_points[2]]); + }); + } +#if SOLID_ANGLE_TIME_PRECOMPUTE + double time = timer.stop(); + UTdebugFormat("{} s to create bounding boxes.", time); + timer.start(); +#endif + myTree.template init(triangle_boxes.array(), ntriangles); +#if SOLID_ANGLE_TIME_PRECOMPUTE + time = timer.stop(); + UTdebugFormat("{} s to initialize UT_BVH structure. {} nodes", time, myTree.getNumNodes()); +#endif + + //myTree.debugDump(); + + const int nnodes = myTree.getNumNodes(); + + myNBoxes = nnodes; + BoxData *box_data = new BoxData[nnodes]; + myData.reset(box_data); + + // Some data are only needed during initialization. + struct LocalData + { + // Bounding box + UT::Box myBox; + + // P and N are needed from each child for computing Nij. + UT_Vector3T myAverageP; + UT_Vector3T myAreaP; + UT_Vector3T myN; + + // Unsigned area is needed for computing the average position. + T myArea; + +#if TAYLOR_SERIES_ORDER >= 1 + // These are needed for computing Nijk. + UT_Vector3T myNijDiag; + T myNxy; T myNyx; + T myNyz; T myNzy; + T myNzx; T myNxz; +#endif + +#if TAYLOR_SERIES_ORDER >= 2 + UT_Vector3T myNijkDiag; // Nxxx, Nyyy, Nzzz + T mySumPermuteNxyz; // (Nxyz+Nxzy+Nyzx+Nyxz+Nzxy+Nzyx) = 2*(Nxyz+Nyzx+Nzxy) + T my2Nxxy_Nyxx; // Nxxy+Nxyx+Nyxx = 2Nxxy+Nyxx + T my2Nxxz_Nzxx; // Nxxz+Nxzx+Nzxx = 2Nxxz+Nzxx + T my2Nyyz_Nzyy; // Nyyz+Nyzy+Nzyy = 2Nyyz+Nzyy + T my2Nyyx_Nxyy; // Nyyx+Nyxy+Nxyy = 2Nyyx+Nxyy + T my2Nzzx_Nxzz; // Nzzx+Nzxz+Nxzz = 2Nzzx+Nxzz + T my2Nzzy_Nyzz; // Nzzy+Nzyz+Nyzz = 2Nzzy+Nyzz +#endif + }; + + struct PrecomputeFunctors + { + BoxData *const myBoxData; + const UT::Box *const myTriangleBoxes; + const int *const myTrianglePoints; + const UT_Vector3T *const myPositions; + const int myOrder; + + PrecomputeFunctors( + BoxData *box_data, + const UT::Box *triangle_boxes, + const int *triangle_points, + const UT_Vector3T *positions, + const int order) + : myBoxData(box_data) + , myTriangleBoxes(triangle_boxes) + , myTrianglePoints(triangle_points) + , myPositions(positions) + , myOrder(order) + {} + constexpr SYS_FORCE_INLINE bool pre(const int nodei, LocalData *data_for_parent) const + { + return true; + } + void item(const int itemi, const int parent_nodei, LocalData &data_for_parent) const + { + const UT_Vector3T *const positions = myPositions; + const int *const cur_triangle_points = myTrianglePoints + 3*itemi; + const UT_Vector3T a = positions[cur_triangle_points[0]]; + const UT_Vector3T b = positions[cur_triangle_points[1]]; + const UT_Vector3T c = positions[cur_triangle_points[2]]; + const UT_Vector3T ab = b-a; + const UT_Vector3T ac = c-a; + + const UT::Box &triangle_box = myTriangleBoxes[itemi]; + data_for_parent.myBox.initBounds(triangle_box.getMin(), triangle_box.getMax()); + + // Area-weighted normal (unnormalized) + const UT_Vector3T N = T(0.5)*cross(ab,ac); + const T area2 = N.length2(); + const T area = SYSsqrt(area2); + const UT_Vector3T P = (a+b+c)/3; + data_for_parent.myAverageP = P; + data_for_parent.myAreaP = P*area; + data_for_parent.myN = N; +#if SOLID_ANGLE_DEBUG + UTdebugFormat(""); + UTdebugFormat("Triangle {}: P = {}; N = {}; area = {}", itemi, P, N, area); + UTdebugFormat(" box = {}", data_for_parent.myBox); +#endif + + data_for_parent.myArea = area; +#if TAYLOR_SERIES_ORDER >= 1 + const int order = myOrder; + if (order < 1) + return; + + // NOTE: Due to P being at the centroid, triangles have Nij = 0 + // contributions to Nij. + data_for_parent.myNijDiag = T(0); + data_for_parent.myNxy = 0; data_for_parent.myNyx = 0; + data_for_parent.myNyz = 0; data_for_parent.myNzy = 0; + data_for_parent.myNzx = 0; data_for_parent.myNxz = 0; +#endif + +#if TAYLOR_SERIES_ORDER >= 2 + if (order < 2) + return; + + // If it's zero-length, the results are zero, so we can skip. + if (area == 0) + { + data_for_parent.myNijkDiag = T(0); + data_for_parent.mySumPermuteNxyz = 0; + data_for_parent.my2Nxxy_Nyxx = 0; + data_for_parent.my2Nxxz_Nzxx = 0; + data_for_parent.my2Nyyz_Nzyy = 0; + data_for_parent.my2Nyyx_Nxyy = 0; + data_for_parent.my2Nzzx_Nxzz = 0; + data_for_parent.my2Nzzy_Nyzz = 0; + return; + } + + // We need to use the NORMALIZED normal to multiply the integrals by. + UT_Vector3T n = N/area; + + // Figure out the order of a, b, and c in x, y, and z + // for use in computing the integrals for Nijk. + UT_Vector3T values[3] = {a, b, c}; + + int order_x[3] = {0,1,2}; + if (a[0] > b[0]) + std::swap(order_x[0],order_x[1]); + if (values[order_x[0]][0] > c[0]) + std::swap(order_x[0],order_x[2]); + if (values[order_x[1]][0] > values[order_x[2]][0]) + std::swap(order_x[1],order_x[2]); + T dx = values[order_x[2]][0] - values[order_x[0]][0]; + + int order_y[3] = {0,1,2}; + if (a[1] > b[1]) + std::swap(order_y[0],order_y[1]); + if (values[order_y[0]][1] > c[1]) + std::swap(order_y[0],order_y[2]); + if (values[order_y[1]][1] > values[order_y[2]][1]) + std::swap(order_y[1],order_y[2]); + T dy = values[order_y[2]][1] - values[order_y[0]][1]; + + int order_z[3] = {0,1,2}; + if (a[2] > b[2]) + std::swap(order_z[0],order_z[1]); + if (values[order_z[0]][2] > c[2]) + std::swap(order_z[0],order_z[2]); + if (values[order_z[1]][2] > values[order_z[2]][2]) + std::swap(order_z[1],order_z[2]); + T dz = values[order_z[2]][2] - values[order_z[0]][2]; + + auto &&compute_integrals = []( + const UT_Vector3T &a, + const UT_Vector3T &b, + const UT_Vector3T &c, + const UT_Vector3T &P, + T *integral_ii, + T *integral_ij, + T *integral_ik, + const int i) + { +#if SOLID_ANGLE_DEBUG + UTdebugFormat(" Splitting on {}; a = {}; b = {}; c = {}", char('x'+i), a, b, c); +#endif + // NOTE: a, b, and c must be in order of the i axis. + // We're splitting the triangle at the middle i coordinate. + const UT_Vector3T oab = b - a; + const UT_Vector3T oac = c - a; + const UT_Vector3T ocb = b - c; + UT_ASSERT_MSG_P(oac[i] > 0, "This should have been checked by the caller."); + const T t = oab[i]/oac[i]; + UT_ASSERT_MSG_P(t >= 0 && t <= 1, "Either sorting must have gone wrong, or there are input NaNs."); + + const int j = (i==2) ? 0 : (i+1); + const int k = (j==2) ? 0 : (j+1); + const T jdiff = t*oac[j] - oab[j]; + const T kdiff = t*oac[k] - oab[k]; + UT_Vector3T cross_a; + cross_a[0] = (jdiff*oab[k] - kdiff*oab[j]); + cross_a[1] = kdiff*oab[i]; + cross_a[2] = jdiff*oab[i]; + UT_Vector3T cross_c; + cross_c[0] = (jdiff*ocb[k] - kdiff*ocb[j]); + cross_c[1] = kdiff*ocb[i]; + cross_c[2] = jdiff*ocb[i]; + const T area_scale_a = cross_a.length(); + const T area_scale_c = cross_c.length(); + const T Pai = a[i] - P[i]; + const T Pci = c[i] - P[i]; + + // Integral over the area of the triangle of (pi^2)dA, + // by splitting the triangle into two at b, the a side + // and the c side. + const T int_ii_a = area_scale_a*(T(0.5)*Pai*Pai + T(2.0/3.0)*Pai*oab[i] + T(0.25)*oab[i]*oab[i]); + const T int_ii_c = area_scale_c*(T(0.5)*Pci*Pci + T(2.0/3.0)*Pci*ocb[i] + T(0.25)*ocb[i]*ocb[i]); + *integral_ii = int_ii_a + int_ii_c; +#if SOLID_ANGLE_DEBUG + UTdebugFormat(" integral_{}{}_a = {}; integral_{}{}_c = {}", char('x'+i), char('x'+i), int_ii_a, char('x'+i), char('x'+i), int_ii_c); +#endif + + int jk = j; + T *integral = integral_ij; + T diff = jdiff; + while (true) // This only does 2 iterations, one for j and one for k + { + if (integral) + { + T obmidj = b[jk] + T(0.5)*diff; + T oabmidj = obmidj - a[jk]; + T ocbmidj = obmidj - c[jk]; + T Paj = a[jk] - P[jk]; + T Pcj = c[jk] - P[jk]; + // Integral over the area of the triangle of (pi*pj)dA + const T int_ij_a = area_scale_a*(T(0.5)*Pai*Paj + T(1.0/3.0)*Pai*oabmidj + T(1.0/3.0)*Paj*oab[i] + T(0.25)*oab[i]*oabmidj); + const T int_ij_c = area_scale_c*(T(0.5)*Pci*Pcj + T(1.0/3.0)*Pci*ocbmidj + T(1.0/3.0)*Pcj*ocb[i] + T(0.25)*ocb[i]*ocbmidj); + *integral = int_ij_a + int_ij_c; +#if SOLID_ANGLE_DEBUG + UTdebugFormat(" integral_{}{}_a = {}; integral_{}{}_c = {}", char('x'+i), char('x'+jk), int_ij_a, char('x'+i), char('x'+jk), int_ij_c); +#endif + } + if (jk == k) + break; + jk = k; + integral = integral_ik; + diff = kdiff; + } + }; + + T integral_xx = 0; + T integral_xy = 0; + T integral_yy = 0; + T integral_yz = 0; + T integral_zz = 0; + T integral_zx = 0; + // Note that if the span of any axis is zero, the integral must be zero, + // since there's a factor of (p_i-P_i), i.e. value minus average, + // and every value must be equal to the average, giving zero. + if (dx > 0) + { + compute_integrals( + values[order_x[0]], values[order_x[1]], values[order_x[2]], P, + &integral_xx, ((dx >= dy && dy > 0) ? &integral_xy : nullptr), ((dx >= dz && dz > 0) ? &integral_zx : nullptr), 0); + } + if (dy > 0) + { + compute_integrals( + values[order_y[0]], values[order_y[1]], values[order_y[2]], P, + &integral_yy, ((dy >= dz && dz > 0) ? &integral_yz : nullptr), ((dx < dy && dx > 0) ? &integral_xy : nullptr), 1); + } + if (dz > 0) + { + compute_integrals( + values[order_z[0]], values[order_z[1]], values[order_z[2]], P, + &integral_zz, ((dx < dz && dx > 0) ? &integral_zx : nullptr), ((dy < dz && dy > 0) ? &integral_yz : nullptr), 2); + } + + UT_Vector3T Niii; + Niii[0] = integral_xx; + Niii[1] = integral_yy; + Niii[2] = integral_zz; + Niii *= n; + data_for_parent.myNijkDiag = Niii; + data_for_parent.mySumPermuteNxyz = 2*(n[0]*integral_yz + n[1]*integral_zx + n[2]*integral_xy); + T Nxxy = n[0]*integral_xy; + T Nxxz = n[0]*integral_zx; + T Nyyz = n[1]*integral_yz; + T Nyyx = n[1]*integral_xy; + T Nzzx = n[2]*integral_zx; + T Nzzy = n[2]*integral_yz; + data_for_parent.my2Nxxy_Nyxx = 2*Nxxy + n[1]*integral_xx; + data_for_parent.my2Nxxz_Nzxx = 2*Nxxz + n[2]*integral_xx; + data_for_parent.my2Nyyz_Nzyy = 2*Nyyz + n[2]*integral_yy; + data_for_parent.my2Nyyx_Nxyy = 2*Nyyx + n[0]*integral_yy; + data_for_parent.my2Nzzx_Nxzz = 2*Nzzx + n[0]*integral_zz; + data_for_parent.my2Nzzy_Nyzz = 2*Nzzy + n[1]*integral_zz; +#if SOLID_ANGLE_DEBUG + UTdebugFormat(" integral_xx = {}; yy = {}; zz = {}", integral_xx, integral_yy, integral_zz); + UTdebugFormat(" integral_xy = {}; yz = {}; zx = {}", integral_xy, integral_yz, integral_zx); +#endif +#endif + } + + void post(const int nodei, const int parent_nodei, LocalData *data_for_parent, const int nchildren, const LocalData *child_data_array) const + { + // NOTE: Although in the general case, data_for_parent may be null for the root call, + // this functor assumes that it's non-null, so the call below must pass a non-null pointer. + + BoxData ¤t_box_data = myBoxData[nodei]; + + UT_Vector3T N = child_data_array[0].myN; + ((T*)¤t_box_data.myN[0])[0] = N[0]; + ((T*)¤t_box_data.myN[1])[0] = N[1]; + ((T*)¤t_box_data.myN[2])[0] = N[2]; + UT_Vector3T areaP = child_data_array[0].myAreaP; + T area = child_data_array[0].myArea; + UT_Vector3T local_P = child_data_array[0].myAverageP; + ((T*)¤t_box_data.myAverageP[0])[0] = local_P[0]; + ((T*)¤t_box_data.myAverageP[1])[0] = local_P[1]; + ((T*)¤t_box_data.myAverageP[2])[0] = local_P[2]; + for (int i = 1; i < nchildren; ++i) + { + const UT_Vector3T local_N = child_data_array[i].myN; + N += local_N; + ((T*)¤t_box_data.myN[0])[i] = local_N[0]; + ((T*)¤t_box_data.myN[1])[i] = local_N[1]; + ((T*)¤t_box_data.myN[2])[i] = local_N[2]; + areaP += child_data_array[i].myAreaP; + area += child_data_array[i].myArea; + const UT_Vector3T local_P = child_data_array[i].myAverageP; + ((T*)¤t_box_data.myAverageP[0])[i] = local_P[0]; + ((T*)¤t_box_data.myAverageP[1])[i] = local_P[1]; + ((T*)¤t_box_data.myAverageP[2])[i] = local_P[2]; + } + for (int i = nchildren; i < BVH_N; ++i) + { + // Set to zero, just to avoid false positives for uses of uninitialized memory. + ((T*)¤t_box_data.myN[0])[i] = 0; + ((T*)¤t_box_data.myN[1])[i] = 0; + ((T*)¤t_box_data.myN[2])[i] = 0; + ((T*)¤t_box_data.myAverageP[0])[i] = 0; + ((T*)¤t_box_data.myAverageP[1])[i] = 0; + ((T*)¤t_box_data.myAverageP[2])[i] = 0; + } + data_for_parent->myN = N; + data_for_parent->myAreaP = areaP; + data_for_parent->myArea = area; + + UT::Box box(child_data_array[0].myBox); + for (int i = 1; i < nchildren; ++i) + box.enlargeBounds(child_data_array[i].myBox); + + // Normalize P + UT_Vector3T averageP; + if (area > 0) + averageP = areaP/area; + else + averageP = T(0.5)*(box.getMin() + box.getMax()); + data_for_parent->myAverageP = averageP; + + data_for_parent->myBox = box; + + for (int i = 0; i < nchildren; ++i) + { + const UT::Box &local_box(child_data_array[i].myBox); + const UT_Vector3T &local_P = child_data_array[i].myAverageP; + const UT_Vector3T maxPDiff = SYSmax(local_P-UT_Vector3T(local_box.getMin()), UT_Vector3T(local_box.getMax())-local_P); + ((T*)¤t_box_data.myMaxPDist2)[i] = maxPDiff.length2(); + } + for (int i = nchildren; i < BVH_N; ++i) + { + // This child is non-existent. If we set myMaxPDist2 to infinity, it will never + // use the approximation, and the traverseVector function can check for EMPTY. + ((T*)¤t_box_data.myMaxPDist2)[i] = std::numeric_limits::infinity(); + } + +#if TAYLOR_SERIES_ORDER >= 1 + const int order = myOrder; + if (order >= 1) + { + // We now have the current box's P, so we can adjust Nij and Nijk + data_for_parent->myNijDiag = child_data_array[0].myNijDiag; + data_for_parent->myNxy = 0; + data_for_parent->myNyx = 0; + data_for_parent->myNyz = 0; + data_for_parent->myNzy = 0; + data_for_parent->myNzx = 0; + data_for_parent->myNxz = 0; +#if TAYLOR_SERIES_ORDER >= 2 + data_for_parent->myNijkDiag = child_data_array[0].myNijkDiag; + data_for_parent->mySumPermuteNxyz = child_data_array[0].mySumPermuteNxyz; + data_for_parent->my2Nxxy_Nyxx = child_data_array[0].my2Nxxy_Nyxx; + data_for_parent->my2Nxxz_Nzxx = child_data_array[0].my2Nxxz_Nzxx; + data_for_parent->my2Nyyz_Nzyy = child_data_array[0].my2Nyyz_Nzyy; + data_for_parent->my2Nyyx_Nxyy = child_data_array[0].my2Nyyx_Nxyy; + data_for_parent->my2Nzzx_Nxzz = child_data_array[0].my2Nzzx_Nxzz; + data_for_parent->my2Nzzy_Nyzz = child_data_array[0].my2Nzzy_Nyzz; +#endif + + for (int i = 1; i < nchildren; ++i) + { + data_for_parent->myNijDiag += child_data_array[i].myNijDiag; +#if TAYLOR_SERIES_ORDER >= 2 + data_for_parent->myNijkDiag += child_data_array[i].myNijkDiag; + data_for_parent->mySumPermuteNxyz += child_data_array[i].mySumPermuteNxyz; + data_for_parent->my2Nxxy_Nyxx += child_data_array[i].my2Nxxy_Nyxx; + data_for_parent->my2Nxxz_Nzxx += child_data_array[i].my2Nxxz_Nzxx; + data_for_parent->my2Nyyz_Nzyy += child_data_array[i].my2Nyyz_Nzyy; + data_for_parent->my2Nyyx_Nxyy += child_data_array[i].my2Nyyx_Nxyy; + data_for_parent->my2Nzzx_Nxzz += child_data_array[i].my2Nzzx_Nxzz; + data_for_parent->my2Nzzy_Nyzz += child_data_array[i].my2Nzzy_Nyzz; +#endif + } + for (int j = 0; j < 3; ++j) + ((T*)¤t_box_data.myNijDiag[j])[0] = child_data_array[0].myNijDiag[j]; + ((T*)¤t_box_data.myNxy_Nyx)[0] = child_data_array[0].myNxy + child_data_array[0].myNyx; + ((T*)¤t_box_data.myNyz_Nzy)[0] = child_data_array[0].myNyz + child_data_array[0].myNzy; + ((T*)¤t_box_data.myNzx_Nxz)[0] = child_data_array[0].myNzx + child_data_array[0].myNxz; + for (int j = 0; j < 3; ++j) + ((T*)¤t_box_data.myNijkDiag[j])[0] = child_data_array[0].myNijkDiag[j]; + ((T*)¤t_box_data.mySumPermuteNxyz)[0] = child_data_array[0].mySumPermuteNxyz; + ((T*)¤t_box_data.my2Nxxy_Nyxx)[0] = child_data_array[0].my2Nxxy_Nyxx; + ((T*)¤t_box_data.my2Nxxz_Nzxx)[0] = child_data_array[0].my2Nxxz_Nzxx; + ((T*)¤t_box_data.my2Nyyz_Nzyy)[0] = child_data_array[0].my2Nyyz_Nzyy; + ((T*)¤t_box_data.my2Nyyx_Nxyy)[0] = child_data_array[0].my2Nyyx_Nxyy; + ((T*)¤t_box_data.my2Nzzx_Nxzz)[0] = child_data_array[0].my2Nzzx_Nxzz; + ((T*)¤t_box_data.my2Nzzy_Nyzz)[0] = child_data_array[0].my2Nzzy_Nyzz; + for (int i = 1; i < nchildren; ++i) + { + for (int j = 0; j < 3; ++j) + ((T*)¤t_box_data.myNijDiag[j])[i] = child_data_array[i].myNijDiag[j]; + ((T*)¤t_box_data.myNxy_Nyx)[i] = child_data_array[i].myNxy + child_data_array[i].myNyx; + ((T*)¤t_box_data.myNyz_Nzy)[i] = child_data_array[i].myNyz + child_data_array[i].myNzy; + ((T*)¤t_box_data.myNzx_Nxz)[i] = child_data_array[i].myNzx + child_data_array[i].myNxz; + for (int j = 0; j < 3; ++j) + ((T*)¤t_box_data.myNijkDiag[j])[i] = child_data_array[i].myNijkDiag[j]; + ((T*)¤t_box_data.mySumPermuteNxyz)[i] = child_data_array[i].mySumPermuteNxyz; + ((T*)¤t_box_data.my2Nxxy_Nyxx)[i] = child_data_array[i].my2Nxxy_Nyxx; + ((T*)¤t_box_data.my2Nxxz_Nzxx)[i] = child_data_array[i].my2Nxxz_Nzxx; + ((T*)¤t_box_data.my2Nyyz_Nzyy)[i] = child_data_array[i].my2Nyyz_Nzyy; + ((T*)¤t_box_data.my2Nyyx_Nxyy)[i] = child_data_array[i].my2Nyyx_Nxyy; + ((T*)¤t_box_data.my2Nzzx_Nxzz)[i] = child_data_array[i].my2Nzzx_Nxzz; + ((T*)¤t_box_data.my2Nzzy_Nyzz)[i] = child_data_array[i].my2Nzzy_Nyzz; + } + for (int i = nchildren; i < BVH_N; ++i) + { + // Set to zero, just to avoid false positives for uses of uninitialized memory. + for (int j = 0; j < 3; ++j) + ((T*)¤t_box_data.myNijDiag[j])[i] = 0; + ((T*)¤t_box_data.myNxy_Nyx)[i] = 0; + ((T*)¤t_box_data.myNyz_Nzy)[i] = 0; + ((T*)¤t_box_data.myNzx_Nxz)[i] = 0; + for (int j = 0; j < 3; ++j) + ((T*)¤t_box_data.myNijkDiag[j])[i] = 0; + ((T*)¤t_box_data.mySumPermuteNxyz)[i] = 0; + ((T*)¤t_box_data.my2Nxxy_Nyxx)[i] = 0; + ((T*)¤t_box_data.my2Nxxz_Nzxx)[i] = 0; + ((T*)¤t_box_data.my2Nyyz_Nzyy)[i] = 0; + ((T*)¤t_box_data.my2Nyyx_Nxyy)[i] = 0; + ((T*)¤t_box_data.my2Nzzx_Nxzz)[i] = 0; + ((T*)¤t_box_data.my2Nzzy_Nyzz)[i] = 0; + } + + for (int i = 0; i < nchildren; ++i) + { + const LocalData &child_data = child_data_array[i]; + UT_Vector3T displacement = child_data.myAverageP - UT_Vector3T(data_for_parent->myAverageP); + UT_Vector3T N = child_data.myN; + + // Adjust Nij for the change in centre P + data_for_parent->myNijDiag += N*displacement; + T Nxy = child_data.myNxy + N[0]*displacement[1]; + T Nyx = child_data.myNyx + N[1]*displacement[0]; + T Nyz = child_data.myNyz + N[1]*displacement[2]; + T Nzy = child_data.myNzy + N[2]*displacement[1]; + T Nzx = child_data.myNzx + N[2]*displacement[0]; + T Nxz = child_data.myNxz + N[0]*displacement[2]; + + data_for_parent->myNxy += Nxy; + data_for_parent->myNyx += Nyx; + data_for_parent->myNyz += Nyz; + data_for_parent->myNzy += Nzy; + data_for_parent->myNzx += Nzx; + data_for_parent->myNxz += Nxz; + +#if TAYLOR_SERIES_ORDER >= 2 + if (order >= 2) + { + // Adjust Nijk for the change in centre P + data_for_parent->myNijkDiag += T(2)*displacement*child_data.myNijDiag + displacement*displacement*child_data.myN; + data_for_parent->mySumPermuteNxyz += (displacement[0]*(Nyz+Nzy) + displacement[1]*(Nzx+Nxz) + displacement[2]*(Nxy+Nyx)); + data_for_parent->my2Nxxy_Nyxx += + 2*(displacement[1]*child_data.myNijDiag[0] + displacement[0]*child_data.myNxy + N[0]*displacement[0]*displacement[1]) + + 2*child_data.myNyx*displacement[0] + N[1]*displacement[0]*displacement[0]; + data_for_parent->my2Nxxz_Nzxx += + 2*(displacement[2]*child_data.myNijDiag[0] + displacement[0]*child_data.myNxz + N[0]*displacement[0]*displacement[2]) + + 2*child_data.myNzx*displacement[0] + N[2]*displacement[0]*displacement[0]; + data_for_parent->my2Nyyz_Nzyy += + 2*(displacement[2]*child_data.myNijDiag[1] + displacement[1]*child_data.myNyz + N[1]*displacement[1]*displacement[2]) + + 2*child_data.myNzy*displacement[1] + N[2]*displacement[1]*displacement[1]; + data_for_parent->my2Nyyx_Nxyy += + 2*(displacement[0]*child_data.myNijDiag[1] + displacement[1]*child_data.myNyx + N[1]*displacement[1]*displacement[0]) + + 2*child_data.myNxy*displacement[1] + N[0]*displacement[1]*displacement[1]; + data_for_parent->my2Nzzx_Nxzz += + 2*(displacement[0]*child_data.myNijDiag[2] + displacement[2]*child_data.myNzx + N[2]*displacement[2]*displacement[0]) + + 2*child_data.myNxz*displacement[2] + N[0]*displacement[2]*displacement[2]; + data_for_parent->my2Nzzy_Nyzz += + 2*(displacement[1]*child_data.myNijDiag[2] + displacement[2]*child_data.myNzy + N[2]*displacement[2]*displacement[1]) + + 2*child_data.myNyz*displacement[2] + N[1]*displacement[2]*displacement[2]; + } +#endif + } + } +#endif +#if SOLID_ANGLE_DEBUG + UTdebugFormat(""); + UTdebugFormat("Node {}: nchildren = {}; maxP = {}", nodei, nchildren, SYSsqrt(current_box_data.myMaxPDist2)); + UTdebugFormat(" P = {}; N = {}", current_box_data.myAverageP, current_box_data.myN); +#if TAYLOR_SERIES_ORDER >= 1 + UTdebugFormat(" Nii = {}", current_box_data.myNijDiag); + UTdebugFormat(" Nxy+Nyx = {}; Nyz+Nzy = {}; Nyz+Nzy = {}", current_box_data.myNxy_Nyx, current_box_data.myNyz_Nzy, current_box_data.myNzx_Nxz); +#if TAYLOR_SERIES_ORDER >= 2 + UTdebugFormat(" Niii = {}; 2(Nxyz+Nyzx+Nzxy) = {}", current_box_data.myNijkDiag, current_box_data.mySumPermuteNxyz); + UTdebugFormat(" 2Nxxy+Nyxx = {}; 2Nxxz+Nzxx = {}", current_box_data.my2Nxxy_Nyxx, current_box_data.my2Nxxz_Nzxx); + UTdebugFormat(" 2Nyyz+Nzyy = {}; 2Nyyx+Nxyy = {}", current_box_data.my2Nyyz_Nzyy, current_box_data.my2Nyyx_Nxyy); + UTdebugFormat(" 2Nzzx+Nxzz = {}; 2Nzzy+Nyzz = {}", current_box_data.my2Nzzx_Nxzz, current_box_data.my2Nzzy_Nyzz); +#endif +#endif +#endif + } + }; + +#if SOLID_ANGLE_TIME_PRECOMPUTE + timer.start(); +#endif + const PrecomputeFunctors functors(box_data, triangle_boxes.array(), triangle_points, positions, order); + // NOTE: post-functor relies on non-null data_for_parent, so we have to pass one. + LocalData local_data; + myTree.template traverseParallel(4096, functors, &local_data); + //myTree.template traverse(functors); +#if SOLID_ANGLE_TIME_PRECOMPUTE + time = timer.stop(); + UTdebugFormat("{} s to precompute coefficients.", time); +#endif +} + +template +inline void UT_SolidAngle::clear() +{ + myTree.clear(); + myNBoxes = 0; + myOrder = 2; + myData.reset(); + myNTriangles = 0; + myTrianglePoints = nullptr; + myNPoints = 0; + myPositions = nullptr; +} + +template +inline T UT_SolidAngle::computeSolidAngle(const UT_Vector3T &query_point, const T accuracy_scale) const +{ + const T accuracy_scale2 = accuracy_scale*accuracy_scale; + + struct SolidAngleFunctors + { + const BoxData *const myBoxData; + const UT_Vector3T myQueryPoint; + const T myAccuracyScale2; + const UT_Vector3T *const myPositions; + const int *const myTrianglePoints; + const int myOrder; + + SolidAngleFunctors( + const BoxData *const box_data, + const UT_Vector3T &query_point, + const T accuracy_scale2, + const int order, + const UT_Vector3T *const positions, + const int *const triangle_points) + : myBoxData(box_data) + , myQueryPoint(query_point) + , myAccuracyScale2(accuracy_scale2) + , myOrder(order) + , myPositions(positions) + , myTrianglePoints(triangle_points) + {} + uint pre(const int nodei, T *data_for_parent) const + { + const BoxData &data = myBoxData[nodei]; + const typename BoxData::Type maxP2 = data.myMaxPDist2; + UT_FixedVector q; + q[0] = typename BoxData::Type(myQueryPoint[0]); + q[1] = typename BoxData::Type(myQueryPoint[1]); + q[2] = typename BoxData::Type(myQueryPoint[2]); + q -= data.myAverageP; + const typename BoxData::Type qlength2 = q[0]*q[0] + q[1]*q[1] + q[2]*q[2]; + + // If the query point is within a factor of accuracy_scale of the box radius, + // it's assumed to be not a good enough approximation, so it needs to descend. + // TODO: Is there a way to estimate the error? + static_assert((std::is_same::value), "FIXME: Implement support for other tuple types!"); + v4uu descend_mask = (qlength2 <= maxP2*myAccuracyScale2); + uint descend_bitmask = _mm_movemask_ps(V4SF(descend_mask.vector)); + constexpr uint allchildbits = ((uint(1)<= 1 + const int order = myOrder; + if (order >= 1) + { + const UT_FixedVector q2 = q*q; + const typename BoxData::Type qlength_m3 = qlength_m2*qlength_m1; + const typename BoxData::Type Omega_1 = + qlength_m3*(data.myNijDiag[0] + data.myNijDiag[1] + data.myNijDiag[2] + -typename BoxData::Type(3.0)*(dot(q2,data.myNijDiag) + + q[0]*q[1]*data.myNxy_Nyx + + q[0]*q[2]*data.myNzx_Nxz + + q[1]*q[2]*data.myNyz_Nzy)); + Omega_approx += Omega_1; +#if TAYLOR_SERIES_ORDER >= 2 + if (order >= 2) + { + const UT_FixedVector q3 = q2*q; + const typename BoxData::Type qlength_m4 = qlength_m2*qlength_m2; + typename BoxData::Type temp0[3] = { + data.my2Nyyx_Nxyy+data.my2Nzzx_Nxzz, + data.my2Nzzy_Nyzz+data.my2Nxxy_Nyxx, + data.my2Nxxz_Nzxx+data.my2Nyyz_Nzyy + }; + typename BoxData::Type temp1[3] = { + q[1]*data.my2Nxxy_Nyxx + q[2]*data.my2Nxxz_Nzxx, + q[2]*data.my2Nyyz_Nzyy + q[0]*data.my2Nyyx_Nxyy, + q[0]*data.my2Nzzx_Nxzz + q[1]*data.my2Nzzy_Nyzz + }; + const typename BoxData::Type Omega_2 = + qlength_m4*(typename BoxData::Type(1.5)*dot(q, typename BoxData::Type(3)*data.myNijkDiag + UT_FixedVector(temp0)) + -typename BoxData::Type(7.5)*(dot(q3,data.myNijkDiag) + q[0]*q[1]*q[2]*data.mySumPermuteNxyz + dot(q2, UT_FixedVector(temp1)))); + Omega_approx += Omega_2; + } +#endif + } +#endif + + // If q is so small that we got NaNs and we just have a + // small bounding box, it needs to descend. + const v4uu mask = Omega_approx.isFinite() & ~descend_mask; + Omega_approx = Omega_approx & mask; + descend_bitmask = (~_mm_movemask_ps(V4SF(mask.vector))) & allchildbits; + + T sum = Omega_approx[0]; + for (int i = 1; i < BVH_N; ++i) + sum += Omega_approx[i]; + *data_for_parent = sum; + + return descend_bitmask; + } + void item(const int itemi, const int parent_nodei, T &data_for_parent) const + { + const UT_Vector3T *const positions = myPositions; + const int *const cur_triangle_points = myTrianglePoints + 3*itemi; + const UT_Vector3T a = positions[cur_triangle_points[0]]; + const UT_Vector3T b = positions[cur_triangle_points[1]]; + const UT_Vector3T c = positions[cur_triangle_points[2]]; + + data_for_parent = UTsignedSolidAngleTri(a, b, c, myQueryPoint); + } + SYS_FORCE_INLINE void post(const int nodei, const int parent_nodei, T *data_for_parent, const int nchildren, const T *child_data_array, const uint descend_bits) const + { + T sum = (descend_bits&1) ? child_data_array[0] : 0; + for (int i = 1; i < nchildren; ++i) + sum += ((descend_bits>>i)&1) ? child_data_array[i] : 0; + + *data_for_parent += sum; + } + }; + const SolidAngleFunctors functors(myData.get(), query_point, accuracy_scale2, myOrder, myPositions, myTrianglePoints); + + T sum; + myTree.traverseVector(functors, &sum); + return sum; +} + +template +struct UT_SubtendedAngle::BoxData +{ + void clear() + { + // Set everything to zero + memset(this,0,sizeof(*this)); + } + + using Type = typename std::conditional::value, v4uf, UT_FixedVector>::type; + using SType = typename std::conditional::value, v4uf, UT_FixedVector>::type; + + /// An upper bound on the squared distance from myAverageP to the farthest point in the box. + SType myMaxPDist2; + + /// Centre of mass of the mesh surface in this box + UT_FixedVector myAverageP; + + /// Unnormalized, area-weighted normal of the mesh in this box + UT_FixedVector myN; + + /// Values for Omega_1 + /// @{ + UT_FixedVector myNijDiag; // Nxx, Nyy + Type myNxy_Nyx; // Nxy+Nyx + /// @} + + /// Values for Omega_2 + /// @{ + UT_FixedVector myNijkDiag; // Nxxx, Nyyy + Type my2Nxxy_Nyxx; // Nxxy+Nxyx+Nyxx = 2Nxxy+Nyxx + Type my2Nyyx_Nxyy; // Nyyx+Nyxy+Nxyy = 2Nyyx+Nxyy + /// @} +}; + +template +inline UT_SubtendedAngle::UT_SubtendedAngle() + : myTree() + , myNBoxes(0) + , myOrder(2) + , myData(nullptr) + , myNSegments(0) + , mySegmentPoints(nullptr) + , myNPoints(0) + , myPositions(nullptr) +{} + +template +inline UT_SubtendedAngle::~UT_SubtendedAngle() +{ + // Default destruction works, but this needs to be outlined + // to avoid having to include UT_BVHImpl.h in the header, + // (for the UT_UniquePtr destructor.) +} + +template +inline void UT_SubtendedAngle::init( + const int nsegments, + const int *const segment_points, + const int npoints, + const UT_Vector2T *const positions, + const int order) +{ +#if SOLID_ANGLE_DEBUG + UTdebugFormat(""); + UTdebugFormat(""); + UTdebugFormat("Building BVH for {} segments on {} points:", nsegments, npoints); +#endif + myOrder = order; + myNSegments = nsegments; + mySegmentPoints = segment_points; + myNPoints = npoints; + myPositions = positions; + +#if SOLID_ANGLE_TIME_PRECOMPUTE + UT_StopWatch timer; + timer.start(); +#endif + UT_SmallArray> segment_boxes; + segment_boxes.setSizeNoInit(nsegments); + if (nsegments < 16*1024) + { + const int *cur_segment_points = segment_points; + for (int i = 0; i < nsegments; ++i, cur_segment_points += 2) + { + UT::Box &box = segment_boxes[i]; + box.initBounds(positions[cur_segment_points[0]]); + box.enlargeBounds(positions[cur_segment_points[1]]); + } + } + else + { + igl::parallel_for(nsegments, + [segment_points,&segment_boxes,positions](int i) + { + const int *cur_segment_points = segment_points + i*2; + UT::Box &box = segment_boxes[i]; + box.initBounds(positions[cur_segment_points[0]]); + box.enlargeBounds(positions[cur_segment_points[1]]); + }); + } +#if SOLID_ANGLE_TIME_PRECOMPUTE + double time = timer.stop(); + UTdebugFormat("{} s to create bounding boxes.", time); + timer.start(); +#endif + myTree.template init(segment_boxes.array(), nsegments); +#if SOLID_ANGLE_TIME_PRECOMPUTE + time = timer.stop(); + UTdebugFormat("{} s to initialize UT_BVH structure. {} nodes", time, myTree.getNumNodes()); +#endif + + //myTree.debugDump(); + + const int nnodes = myTree.getNumNodes(); + + myNBoxes = nnodes; + BoxData *box_data = new BoxData[nnodes]; + myData.reset(box_data); + + // Some data are only needed during initialization. + struct LocalData + { + // Bounding box + UT::Box myBox; + + // P and N are needed from each child for computing Nij. + UT_Vector2T myAverageP; + UT_Vector2T myLengthP; + UT_Vector2T myN; + + // Unsigned length is needed for computing the average position. + T myLength; + + // These are needed for computing Nijk. + UT_Vector2T myNijDiag; + T myNxy; T myNyx; + + UT_Vector2T myNijkDiag; // Nxxx, Nyyy + T my2Nxxy_Nyxx; // Nxxy+Nxyx+Nyxx = 2Nxxy+Nyxx + T my2Nyyx_Nxyy; // Nyyx+Nyxy+Nxyy = 2Nyyx+Nxyy + }; + + struct PrecomputeFunctors + { + BoxData *const myBoxData; + const UT::Box *const mySegmentBoxes; + const int *const mySegmentPoints; + const UT_Vector2T *const myPositions; + const int myOrder; + + PrecomputeFunctors( + BoxData *box_data, + const UT::Box *segment_boxes, + const int *segment_points, + const UT_Vector2T *positions, + const int order) + : myBoxData(box_data) + , mySegmentBoxes(segment_boxes) + , mySegmentPoints(segment_points) + , myPositions(positions) + , myOrder(order) + {} + constexpr SYS_FORCE_INLINE bool pre(const int nodei, LocalData *data_for_parent) const + { + return true; + } + void item(const int itemi, const int parent_nodei, LocalData &data_for_parent) const + { + const UT_Vector2T *const positions = myPositions; + const int *const cur_segment_points = mySegmentPoints + 2*itemi; + const UT_Vector2T a = positions[cur_segment_points[0]]; + const UT_Vector2T b = positions[cur_segment_points[1]]; + const UT_Vector2T ab = b-a; + + const UT::Box &segment_box = mySegmentBoxes[itemi]; + data_for_parent.myBox = segment_box; + + // Length-weighted normal (unnormalized) + UT_Vector2T N; + N[0] = ab[1]; + N[1] = -ab[0]; + const T length2 = ab.length2(); + const T length = SYSsqrt(length2); + const UT_Vector2T P = T(0.5)*(a+b); + data_for_parent.myAverageP = P; + data_for_parent.myLengthP = P*length; + data_for_parent.myN = N; +#if SOLID_ANGLE_DEBUG + UTdebugFormat(""); + UTdebugFormat("Triangle {}: P = {}; N = {}; length = {}", itemi, P, N, length); + UTdebugFormat(" box = {}", data_for_parent.myBox); +#endif + + data_for_parent.myLength = length; + const int order = myOrder; + if (order < 1) + return; + + // NOTE: Due to P being at the centroid, segments have Nij = 0 + // contributions to Nij. + data_for_parent.myNijDiag = T(0); + data_for_parent.myNxy = 0; data_for_parent.myNyx = 0; + + if (order < 2) + return; + + // If it's zero-length, the results are zero, so we can skip. + if (length == 0) + { + data_for_parent.myNijkDiag = T(0); + data_for_parent.my2Nxxy_Nyxx = 0; + data_for_parent.my2Nyyx_Nxyy = 0; + return; + } + + T integral_xx = ab[0]*ab[0]/T(12); + T integral_xy = ab[0]*ab[1]/T(12); + T integral_yy = ab[1]*ab[1]/T(12); + data_for_parent.myNijkDiag[0] = integral_xx*N[0]; + data_for_parent.myNijkDiag[1] = integral_yy*N[1]; + T Nxxy = N[0]*integral_xy; + T Nyxx = N[1]*integral_xx; + T Nyyx = N[1]*integral_xy; + T Nxyy = N[0]*integral_yy; + data_for_parent.my2Nxxy_Nyxx = 2*Nxxy + Nyxx; + data_for_parent.my2Nyyx_Nxyy = 2*Nyyx + Nxyy; +#if SOLID_ANGLE_DEBUG + UTdebugFormat(" integral_xx = {}; yy = {}", integral_xx, integral_yy); + UTdebugFormat(" integral_xy = {}", integral_xy); +#endif + } + + void post(const int nodei, const int parent_nodei, LocalData *data_for_parent, const int nchildren, const LocalData *child_data_array) const + { + // NOTE: Although in the general case, data_for_parent may be null for the root call, + // this functor assumes that it's non-null, so the call below must pass a non-null pointer. + + BoxData ¤t_box_data = myBoxData[nodei]; + + UT_Vector2T N = child_data_array[0].myN; + ((T*)¤t_box_data.myN[0])[0] = N[0]; + ((T*)¤t_box_data.myN[1])[0] = N[1]; + UT_Vector2T lengthP = child_data_array[0].myLengthP; + T length = child_data_array[0].myLength; + const UT_Vector2T local_P = child_data_array[0].myAverageP; + ((T*)¤t_box_data.myAverageP[0])[0] = local_P[0]; + ((T*)¤t_box_data.myAverageP[1])[0] = local_P[1]; + for (int i = 1; i < nchildren; ++i) + { + const UT_Vector2T local_N = child_data_array[i].myN; + N += local_N; + ((T*)¤t_box_data.myN[0])[i] = local_N[0]; + ((T*)¤t_box_data.myN[1])[i] = local_N[1]; + lengthP += child_data_array[i].myLengthP; + length += child_data_array[i].myLength; + const UT_Vector2T local_P = child_data_array[i].myAverageP; + ((T*)¤t_box_data.myAverageP[0])[i] = local_P[0]; + ((T*)¤t_box_data.myAverageP[1])[i] = local_P[1]; + } + for (int i = nchildren; i < BVH_N; ++i) + { + // Set to zero, just to avoid false positives for uses of uninitialized memory. + ((T*)¤t_box_data.myN[0])[i] = 0; + ((T*)¤t_box_data.myN[1])[i] = 0; + ((T*)¤t_box_data.myAverageP[0])[i] = 0; + ((T*)¤t_box_data.myAverageP[1])[i] = 0; + } + data_for_parent->myN = N; + data_for_parent->myLengthP = lengthP; + data_for_parent->myLength = length; + + UT::Box box(child_data_array[0].myBox); + for (int i = 1; i < nchildren; ++i) + box.combine(child_data_array[i].myBox); + + // Normalize P + UT_Vector2T averageP; + if (length > 0) + averageP = lengthP/length; + else + averageP = T(0.5)*(box.getMin() + box.getMax()); + data_for_parent->myAverageP = averageP; + + data_for_parent->myBox = box; + + for (int i = 0; i < nchildren; ++i) + { + const UT::Box &local_box(child_data_array[i].myBox); + const UT_Vector2T &local_P = child_data_array[i].myAverageP; + const UT_Vector2T maxPDiff = SYSmax(local_P-UT_Vector2T(local_box.getMin()), UT_Vector2T(local_box.getMax())-local_P); + ((T*)¤t_box_data.myMaxPDist2)[i] = maxPDiff.length2(); + } + for (int i = nchildren; i < BVH_N; ++i) + { + // This child is non-existent. If we set myMaxPDist2 to infinity, it will never + // use the approximation, and the traverseVector function can check for EMPTY. + ((T*)¤t_box_data.myMaxPDist2)[i] = std::numeric_limits::infinity(); + } + + const int order = myOrder; + if (order >= 1) + { + // We now have the current box's P, so we can adjust Nij and Nijk + data_for_parent->myNijDiag = child_data_array[0].myNijDiag; + data_for_parent->myNxy = 0; + data_for_parent->myNyx = 0; + data_for_parent->myNijkDiag = child_data_array[0].myNijkDiag; + data_for_parent->my2Nxxy_Nyxx = child_data_array[0].my2Nxxy_Nyxx; + data_for_parent->my2Nyyx_Nxyy = child_data_array[0].my2Nyyx_Nxyy; + + for (int i = 1; i < nchildren; ++i) + { + data_for_parent->myNijDiag += child_data_array[i].myNijDiag; + data_for_parent->myNijkDiag += child_data_array[i].myNijkDiag; + data_for_parent->my2Nxxy_Nyxx += child_data_array[i].my2Nxxy_Nyxx; + data_for_parent->my2Nyyx_Nxyy += child_data_array[i].my2Nyyx_Nxyy; + } + for (int j = 0; j < 2; ++j) + ((T*)¤t_box_data.myNijDiag[j])[0] = child_data_array[0].myNijDiag[j]; + ((T*)¤t_box_data.myNxy_Nyx)[0] = child_data_array[0].myNxy + child_data_array[0].myNyx; + for (int j = 0; j < 2; ++j) + ((T*)¤t_box_data.myNijkDiag[j])[0] = child_data_array[0].myNijkDiag[j]; + ((T*)¤t_box_data.my2Nxxy_Nyxx)[0] = child_data_array[0].my2Nxxy_Nyxx; + ((T*)¤t_box_data.my2Nyyx_Nxyy)[0] = child_data_array[0].my2Nyyx_Nxyy; + for (int i = 1; i < nchildren; ++i) + { + for (int j = 0; j < 2; ++j) + ((T*)¤t_box_data.myNijDiag[j])[i] = child_data_array[i].myNijDiag[j]; + ((T*)¤t_box_data.myNxy_Nyx)[i] = child_data_array[i].myNxy + child_data_array[i].myNyx; + for (int j = 0; j < 2; ++j) + ((T*)¤t_box_data.myNijkDiag[j])[i] = child_data_array[i].myNijkDiag[j]; + ((T*)¤t_box_data.my2Nxxy_Nyxx)[i] = child_data_array[i].my2Nxxy_Nyxx; + ((T*)¤t_box_data.my2Nyyx_Nxyy)[i] = child_data_array[i].my2Nyyx_Nxyy; + } + for (int i = nchildren; i < BVH_N; ++i) + { + // Set to zero, just to avoid false positives for uses of uninitialized memory. + for (int j = 0; j < 2; ++j) + ((T*)¤t_box_data.myNijDiag[j])[i] = 0; + ((T*)¤t_box_data.myNxy_Nyx)[i] = 0; + for (int j = 0; j < 2; ++j) + ((T*)¤t_box_data.myNijkDiag[j])[i] = 0; + ((T*)¤t_box_data.my2Nxxy_Nyxx)[i] = 0; + ((T*)¤t_box_data.my2Nyyx_Nxyy)[i] = 0; + } + + for (int i = 0; i < nchildren; ++i) + { + const LocalData &child_data = child_data_array[i]; + UT_Vector2T displacement = child_data.myAverageP - UT_Vector2T(data_for_parent->myAverageP); + UT_Vector2T N = child_data.myN; + + // Adjust Nij for the change in centre P + data_for_parent->myNijDiag += N*displacement; + T Nxy = child_data.myNxy + N[0]*displacement[1]; + T Nyx = child_data.myNyx + N[1]*displacement[0]; + + data_for_parent->myNxy += Nxy; + data_for_parent->myNyx += Nyx; + + if (order >= 2) + { + // Adjust Nijk for the change in centre P + data_for_parent->myNijkDiag += T(2)*displacement*child_data.myNijDiag + displacement*displacement*child_data.myN; + data_for_parent->my2Nxxy_Nyxx += + 2*(displacement[1]*child_data.myNijDiag[0] + displacement[0]*child_data.myNxy + N[0]*displacement[0]*displacement[1]) + + 2*child_data.myNyx*displacement[0] + N[1]*displacement[0]*displacement[0]; + data_for_parent->my2Nyyx_Nxyy += + 2*(displacement[0]*child_data.myNijDiag[1] + displacement[1]*child_data.myNyx + N[1]*displacement[1]*displacement[0]) + + 2*child_data.myNxy*displacement[1] + N[0]*displacement[1]*displacement[1]; + } + } + } +#if SOLID_ANGLE_DEBUG + UTdebugFormat(""); + UTdebugFormat("Node {}: nchildren = {}; maxP = {}", nodei, nchildren, SYSsqrt(current_box_data.myMaxPDist2)); + UTdebugFormat(" P = {}; N = {}", current_box_data.myAverageP, current_box_data.myN); + UTdebugFormat(" Nii = {}", current_box_data.myNijDiag); + UTdebugFormat(" Nxy+Nyx = {}", current_box_data.myNxy_Nyx); + UTdebugFormat(" Niii = {}", current_box_data.myNijkDiag); + UTdebugFormat(" 2Nxxy+Nyxx = {}; 2Nyyx+Nxyy = {}", current_box_data.my2Nxxy_Nyxx, current_box_data.my2Nyyx_Nxyy); +#endif + } + }; + +#if SOLID_ANGLE_TIME_PRECOMPUTE + timer.start(); +#endif + const PrecomputeFunctors functors(box_data, segment_boxes.array(), segment_points, positions, order); + // NOTE: post-functor relies on non-null data_for_parent, so we have to pass one. + LocalData local_data; + myTree.template traverseParallel(4096, functors, &local_data); + //myTree.template traverse(functors); +#if SOLID_ANGLE_TIME_PRECOMPUTE + time = timer.stop(); + UTdebugFormat("{} s to precompute coefficients.", time); +#endif +} + +template +inline void UT_SubtendedAngle::clear() +{ + myTree.clear(); + myNBoxes = 0; + myOrder = 2; + myData.reset(); + myNSegments = 0; + mySegmentPoints = nullptr; + myNPoints = 0; + myPositions = nullptr; +} + +template +inline T UT_SubtendedAngle::computeAngle(const UT_Vector2T &query_point, const T accuracy_scale) const +{ + const T accuracy_scale2 = accuracy_scale*accuracy_scale; + + struct AngleFunctors + { + const BoxData *const myBoxData; + const UT_Vector2T myQueryPoint; + const T myAccuracyScale2; + const UT_Vector2T *const myPositions; + const int *const mySegmentPoints; + const int myOrder; + + AngleFunctors( + const BoxData *const box_data, + const UT_Vector2T &query_point, + const T accuracy_scale2, + const int order, + const UT_Vector2T *const positions, + const int *const segment_points) + : myBoxData(box_data) + , myQueryPoint(query_point) + , myAccuracyScale2(accuracy_scale2) + , myOrder(order) + , myPositions(positions) + , mySegmentPoints(segment_points) + {} + uint pre(const int nodei, T *data_for_parent) const + { + const BoxData &data = myBoxData[nodei]; + const typename BoxData::Type maxP2 = data.myMaxPDist2; + UT_FixedVector q; + q[0] = typename BoxData::Type(myQueryPoint[0]); + q[1] = typename BoxData::Type(myQueryPoint[1]); + q -= data.myAverageP; + const typename BoxData::Type qlength2 = q[0]*q[0] + q[1]*q[1]; + + // If the query point is within a factor of accuracy_scale of the box radius, + // it's assumed to be not a good enough approximation, so it needs to descend. + // TODO: Is there a way to estimate the error? + static_assert((std::is_same::value), "FIXME: Implement support for other tuple types!"); + v4uu descend_mask = (qlength2 <= maxP2*myAccuracyScale2); + uint descend_bitmask = _mm_movemask_ps(V4SF(descend_mask.vector)); + constexpr uint allchildbits = ((uint(1)<= 1) + { + const UT_FixedVector q2 = q*q; + const typename BoxData::Type Omega_1 = + qlength_m2*(data.myNijDiag[0] + data.myNijDiag[1] + -typename BoxData::Type(2.0)*(dot(q2,data.myNijDiag) + + q[0]*q[1]*data.myNxy_Nyx)); + Omega_approx += Omega_1; + if (order >= 2) + { + const UT_FixedVector q3 = q2*q; + const typename BoxData::Type qlength_m3 = qlength_m2*qlength_m1; + typename BoxData::Type temp0[2] = { + data.my2Nyyx_Nxyy, + data.my2Nxxy_Nyxx + }; + typename BoxData::Type temp1[2] = { + q[1]*data.my2Nxxy_Nyxx, + q[0]*data.my2Nyyx_Nxyy + }; + const typename BoxData::Type Omega_2 = + qlength_m3*(dot(q, typename BoxData::Type(3)*data.myNijkDiag + UT_FixedVector(temp0)) + -typename BoxData::Type(4.0)*(dot(q3,data.myNijkDiag) + dot(q2, UT_FixedVector(temp1)))); + Omega_approx += Omega_2; + } + } + + // If q is so small that we got NaNs and we just have a + // small bounding box, it needs to descend. + const v4uu mask = Omega_approx.isFinite() & ~descend_mask; + Omega_approx = Omega_approx & mask; + descend_bitmask = (~_mm_movemask_ps(V4SF(mask.vector))) & allchildbits; + + T sum = Omega_approx[0]; + for (int i = 1; i < BVH_N; ++i) + sum += Omega_approx[i]; + *data_for_parent = sum; + + return descend_bitmask; + } + void item(const int itemi, const int parent_nodei, T &data_for_parent) const + { + const UT_Vector2T *const positions = myPositions; + const int *const cur_segment_points = mySegmentPoints + 2*itemi; + const UT_Vector2T a = positions[cur_segment_points[0]]; + const UT_Vector2T b = positions[cur_segment_points[1]]; + + data_for_parent = UTsignedAngleSegment(a, b, myQueryPoint); + } + SYS_FORCE_INLINE void post(const int nodei, const int parent_nodei, T *data_for_parent, const int nchildren, const T *child_data_array, const uint descend_bits) const + { + T sum = (descend_bits&1) ? child_data_array[0] : 0; + for (int i = 1; i < nchildren; ++i) + sum += ((descend_bits>>i)&1) ? child_data_array[i] : 0; + + *data_for_parent += sum; + } + }; + const AngleFunctors functors(myData.get(), query_point, accuracy_scale2, myOrder, myPositions, mySegmentPoints); + + T sum; + myTree.traverseVector(functors, &sum); + return sum; +} + +// Instantiate our templates. +//template class UT_SolidAngle; +// FIXME: The SIMD parts will need to be handled differently in order to support fpreal64. +//template class UT_SolidAngle; +//template class UT_SolidAngle; +//template class UT_SubtendedAngle; +//template class UT_SubtendedAngle; +//template class UT_SubtendedAngle; + +} // End HDK_Sample namespace +}} diff --git a/vendor/libigl/include/igl/FileEncoding.h b/vendor/libigl/include/igl/FileEncoding.h new file mode 100644 index 0000000000000000000000000000000000000000..4b5011abb0f8e608755b139cf013e9b434b7d7bc --- /dev/null +++ b/vendor/libigl/include/igl/FileEncoding.h @@ -0,0 +1,21 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Jérémie Dumas +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FILEENCODING_H +#define IGL_FILEENCODING_H + +namespace igl +{ + +enum class FileEncoding { + Binary, + Ascii +}; + +} + +#endif diff --git a/vendor/libigl/include/igl/FileMemoryStream.h b/vendor/libigl/include/igl/FileMemoryStream.h new file mode 100644 index 0000000000000000000000000000000000000000..24d153ead0c75fef475c188c13877d976cae7acb --- /dev/null +++ b/vendor/libigl/include/igl/FileMemoryStream.h @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Jérémie Dumas +// Copyright (C) 2021 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FILEMEMORYSTREAM_H +#define IGL_FILEMEMORYSTREAM_H + +#include "igl_inline.h" + +#include +#include +#include + +namespace igl { + struct FileMemoryBuffer : public std::streambuf + { + char *p_start{nullptr}; + char *p_end{nullptr}; + size_t size; + + FileMemoryBuffer(char const *first_elem, size_t size) + : p_start(const_cast(first_elem)), p_end(p_start + size), + size(size) + { + setg(p_start, p_start, p_end); + } + + pos_type seekoff( + off_type off, + std::ios_base::seekdir dir, + std::ios_base::openmode which) override + { + if (dir == std::ios_base::cur) + { + gbump(static_cast(off)); + }else + { + setg(p_start,(dir==std::ios_base::beg ? p_start : p_end) + off,p_end); + } + return gptr() - p_start; + } + + pos_type seekpos(pos_type pos, std::ios_base::openmode which) override + { + return seekoff(pos, std::ios_base::beg, which); + } + }; + + struct FileMemoryStream : virtual FileMemoryBuffer, public std::istream + { + FileMemoryStream( char const *first_elem, size_t size) + : FileMemoryBuffer(first_elem, size), + std::istream( static_cast(this)) + {} + }; +} + +#endif + diff --git a/vendor/libigl/include/igl/HalfEdgeIterator.cpp b/vendor/libigl/include/igl/HalfEdgeIterator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..982c295f051b3eef9963e47dc1e00b645c18f165 --- /dev/null +++ b/vendor/libigl/include/igl/HalfEdgeIterator.cpp @@ -0,0 +1,162 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "HalfEdgeIterator.h" + +template +IGL_INLINE igl::HalfEdgeIterator::HalfEdgeIterator( + const Eigen::MatrixBase& _F, + const Eigen::MatrixBase& _FF, + const Eigen::MatrixBase& _FFi, + int _fi, + int _ei, + bool _reverse +) +: fi(_fi), ei(_ei), reverse(_reverse), F(_F), FF(_FF), FFi(_FFi) +{} + +template +IGL_INLINE void igl::HalfEdgeIterator::flipF() +{ + if (isBorder()) + return; + + int fin = (FF)(fi,ei); + int ein = (FFi)(fi,ei); + + fi = fin; + ei = ein; + reverse = !reverse; +} + + +// Change Edge +template +IGL_INLINE void igl::HalfEdgeIterator::flipE() +{ + if (!reverse) + ei = (ei+2)%3; // ei-1 + else + ei = (ei+1)%3; + + reverse = !reverse; +} + +// Change Vertex +template +IGL_INLINE void igl::HalfEdgeIterator::flipV() +{ + reverse = !reverse; +} + +template +IGL_INLINE bool igl::HalfEdgeIterator::isBorder() +{ + return (FF)(fi,ei) == -1; +} + +/*! + * Returns the next edge skipping the border + * _________ + * /\ c | b /\ + * / \ | / \ + * / d \ | / a \ + * /______\|/______\ + * v + * In this example, if a and d are of-border and the pos is iterating counterclockwise, this method iterate through the faces incident on vertex v, + * producing the sequence a, b, c, d, a, b, c, ... + */ +template +IGL_INLINE bool igl::HalfEdgeIterator::NextFE() +{ + if ( isBorder() ) // we are on a border + { + do + { + flipF(); + flipE(); + } while (!isBorder()); + flipE(); + return false; + } + else + { + flipF(); + flipE(); + return true; + } +} + +// Get vertex index +template +IGL_INLINE int igl::HalfEdgeIterator::Vi() +{ + assert(fi >= 0); + assert(fi < F.rows()); + assert(ei >= 0); + assert(ei <= 2); + + if (!reverse) + return (F)(fi,ei); + else + return (F)(fi,(ei+1)%3); +} + +// Get face index +template +IGL_INLINE int igl::HalfEdgeIterator::Fi() +{ + return fi; +} + +// Get edge index +template +IGL_INLINE int igl::HalfEdgeIterator::Ei() +{ + return ei; +} + + +template +IGL_INLINE bool igl::HalfEdgeIterator::operator==(HalfEdgeIterator& p2) +{ + return + ( + (fi == p2.fi) && + (ei == p2.ei) && + (reverse == p2.reverse) && + (F == p2.F) && + (FF == p2.FF) && + (FFi == p2.FFi) + ); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template igl::HalfEdgeIterator ,Eigen::Matrix ,Eigen::Matrix >::HalfEdgeIterator(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, bool); +template igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::HalfEdgeIterator(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, bool); +template bool igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::NextFE(); +template int igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::Ei(); +template int igl::HalfEdgeIterator ,Eigen::Matrix,Eigen::Matrix >::Ei(); +template int igl::HalfEdgeIterator ,Eigen::Matrix ,Eigen::Matrix >::Ei(); +template int igl::HalfEdgeIterator ,Eigen::Matrix ,Eigen::Matrix >::Fi(); +template bool igl::HalfEdgeIterator ,Eigen::Matrix ,Eigen::Matrix >::NextFE(); +template int igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::Vi(); +template igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::HalfEdgeIterator(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, bool); +template int igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::Fi(); +template void igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::flipE(); +template void igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::flipE(); +template void igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::flipF(); +template void igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::flipF(); +template void igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::flipV(); +template bool igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >::operator==(igl::HalfEdgeIterator,Eigen::Matrix,Eigen::Matrix >&); +template int igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::Fi(); +template bool igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::NextFE(); +template bool igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::isBorder(); +template bool igl::HalfEdgeIterator, Eigen::Matrix, Eigen::Matrix >::isBorder(); +#endif diff --git a/vendor/libigl/include/igl/Hit.h b/vendor/libigl/include/igl/Hit.h new file mode 100644 index 0000000000000000000000000000000000000000..e0034efcf8b0d208f0bb93257368251152a5b4c6 --- /dev/null +++ b/vendor/libigl/include/igl/Hit.h @@ -0,0 +1,29 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// 2014 Christian Schüller +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_HIT_H +#define IGL_HIT_H + +namespace igl +{ + // Reimplementation of the embree::Hit struct from embree1.0 + // + // TODO: template on floating point type + struct Hit + { + int id; // primitive id + int gid; // geometry id (not used) + // barycentric coordinates so that + // pos = V.row(F(id,0))*(1-u-v)+V.row(F(id,1))*u+V.row(F(id,2))*v; + float u,v; + // parametric distance so that + // pos = origin + t * dir + float t; + }; +} +#endif diff --git a/vendor/libigl/include/igl/LinSpaced.h b/vendor/libigl/include/igl/LinSpaced.h new file mode 100644 index 0000000000000000000000000000000000000000..d40db33d35f84a87814d4a99fbccd70d55f18fa6 --- /dev/null +++ b/vendor/libigl/include/igl/LinSpaced.h @@ -0,0 +1,61 @@ +#ifndef IGL_LINSPACED_H +#define IGL_LINSPACED_H +#include +// This function is not intended to be a permanent function of libigl. Rather +// it is a "drop-in" workaround for documented bug in Eigen: +// http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1383 +// +// Replace: +// +// Eigen::VectorXi::LinSpaced(size,low,high); +// +// With: +// +// igl::LinSpaced(size,low,high); +// +// Specifcally, this version will _always_ return an empty vector if size==0, +// regardless of the values for low and high. If size != 0, then this simply +// returns the result of Eigen::Derived::LinSpaced. +// +// Until this bug is fixed, we should also avoid calls to the member function +// `.setLinSpaced`. This means replacing: +// +// a.setLinSpaced(size,low,high); +// +// with +// +// a = igl::LinSpaced(size,low,high); +// +namespace igl +{ + template + //inline typename Eigen::DenseBase< Derived >::RandomAccessLinSpacedReturnType + inline Derived LinSpaced( + typename Derived::Index size, + const typename Derived::Scalar & low, + const typename Derived::Scalar & high); +} + +// Implementation + +template +//inline typename Eigen::DenseBase< Derived >::RandomAccessLinSpacedReturnType +inline Derived +igl::LinSpaced( + typename Derived::Index size, + const typename Derived::Scalar & low, + const typename Derived::Scalar & high) +{ + if(size == 0) + { + // Force empty vector with correct "RandomAccessLinSpacedReturnType" type. + return Derived::LinSpaced(0,0,1); + }else if(high < low) + { + return low-Derived::LinSpaced(size,low-low,low-high).array(); + }else{ + return Derived::LinSpaced(size,low,high); + } +} + +#endif diff --git a/vendor/libigl/include/igl/MappingEnergyType.h b/vendor/libigl/include/igl/MappingEnergyType.h new file mode 100644 index 0000000000000000000000000000000000000000..1eeeb778b43b2a11349b8bc57a50b6b0c724a958 --- /dev/null +++ b/vendor/libigl/include/igl/MappingEnergyType.h @@ -0,0 +1,27 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Zhongshi Jiang +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MAPPINGENERGYTYPE_H +#define IGL_MAPPINGENERGYTYPE_H +namespace igl +{ + // Energy Types used for Parameterization/Mapping. + // Refer to SLIM [Rabinovich et al. 2017] for more details + // Todo: Integrate with ARAPEnergyType + + enum MappingEnergyType + { + ARAP = 0, + LOG_ARAP = 1, + SYMMETRIC_DIRICHLET = 2, + CONFORMAL = 3, + EXP_CONFORMAL = 4, + EXP_SYMMETRIC_DIRICHLET = 5, + NUM_SLIM_ENERGY_TYPES = 6 + }; +} +#endif diff --git a/vendor/libigl/include/igl/MeshBooleanType.h b/vendor/libigl/include/igl/MeshBooleanType.h new file mode 100644 index 0000000000000000000000000000000000000000..2eb293624294b7986f73aa779f65014807ce1c8e --- /dev/null +++ b/vendor/libigl/include/igl/MeshBooleanType.h @@ -0,0 +1,23 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MESH_BOOLEAN_TYPE_H +#define IGL_MESH_BOOLEAN_TYPE_H +namespace igl +{ + enum MeshBooleanType + { + MESH_BOOLEAN_TYPE_UNION = 0, + MESH_BOOLEAN_TYPE_INTERSECT = 1, + MESH_BOOLEAN_TYPE_MINUS = 2, + MESH_BOOLEAN_TYPE_XOR = 3, + MESH_BOOLEAN_TYPE_RESOLVE = 4, + NUM_MESH_BOOLEAN_TYPES = 5 + }; +}; + +#endif diff --git a/vendor/libigl/include/igl/MshLoader.h b/vendor/libigl/include/igl/MshLoader.h new file mode 100644 index 0000000000000000000000000000000000000000..67ef46932d98e8a112ced5a2e7d651c2fd263758 --- /dev/null +++ b/vendor/libigl/include/igl/MshLoader.h @@ -0,0 +1,190 @@ +// based on MSH reader from PyMesh + +// Copyright (c) 2015 Qingnan Zhou +// Copyright (C) 2020 Vladimir Fonov +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MSH_LOADER_H +#define IGL_MSH_LOADER_H +#include "igl_inline.h" + +#include +#include +#include +#include +#include + +namespace igl { + +// Class for loading information from .msh file +// depends only on c++stl library +class MshLoader { + public: + + struct msh_struct { + int tag,el_type; + msh_struct(int _tag=0,int _type=0): + tag(_tag),el_type(_type){} + bool operator== (const msh_struct& a) const { + return this->tag==a.tag && + this->el_type==a.el_type; + } + + bool operator< (const msh_struct& a) const { + return (this->tag*100+this->el_type) < + (a.tag*100+a.el_type); + } + }; + + typedef double Float; + + typedef std::vector IndexVector; + typedef std::vector IntVector; + typedef std::vector FloatVector; + typedef std::vector FloatField; + typedef std::vector IntField; + typedef std::vector FieldNames; + typedef std::multimap StructIndex; + typedef std::vector StructVector; + + enum {ELEMENT_LINE=1, ELEMENT_TRI=2, ELEMENT_QUAD=3, + ELEMENT_TET=4, ELEMENT_HEX=5, ELEMENT_PRISM=6, + ELEMENT_PYRAMID=7, + // 2nd order elements + ELEMENT_LINE_2ND_ORDER=8, ELEMENT_TRI_2ND_ORDER=9, + ELEMENT_QUAD_2ND_ORDER=10,ELEMENT_TET_2ND_ORDER=11, + ELEMENT_HEX_2ND_ORDER=12, ELEMENT_PRISM_2ND_ORDER=13, + ELEMENT_PYRAMID_2ND_ORDER=14, + // other elements + ELEMENT_POINT=15 }; + public: + MshLoader(const std::string &filename); + + public: + + // get nodes , x,y,z sequentially + const FloatVector& get_nodes() const { return m_nodes; } + // get elements , identifying nodes that create an element + // variable length per element + const IndexVector& get_elements() const { return m_elements; } + + // get element types + const IntVector& get_elements_types() const { return m_elements_types; } + // get element lengths + const IntVector& get_elements_lengths() const { return m_elements_lengths; } + // get element tags ( physical (0) and elementary (1) ) + const IntField& get_elements_tags() const { return m_elements_tags; } + // get element IDs + const IntVector& get_elements_ids() const { return m_elements_ids; } + + // get reverse index from node to element + const IndexVector& get_elements_nodes_idx() const { return m_elements_nodes_idx; } + + // get fields assigned per node, all fields and components sequentially + const FloatField& get_node_fields() const { return m_node_fields;} + // get node field names, + const FieldNames& get_node_fields_names() const { return m_node_fields_names;} + // get number of node field components + const IntVector& get_node_fields_components() const {return m_node_fields_components;} + + int get_node_field_components(size_t c) const + { + return m_node_fields_components[c]; + } + + // get fields assigned per element, all fields and components sequentially + const FloatField& get_element_fields() const { return m_element_fields;} + // get element field names + const FieldNames& get_element_fields_names() const { return m_element_fields_names;} + // get number of element field components + const IntVector& get_element_fields_components() const {return m_element_fields_components;} + + int get_element_field_components(size_t c) const { + return m_element_fields_components[c]; + } + // check if field is present at node level + bool is_node_field(const std::string& fieldname) const { + return (std::find(std::begin(m_node_fields_names), + std::end(m_node_fields_names), + fieldname) != std::end(m_node_fields_names) ); + } + // check if field is present at element level + bool is_element_field(const std::string& fieldname) const { + return (std::find(std::begin(m_element_fields_names), + std::end(m_element_fields_names), + fieldname) != std::end(m_node_fields_names) ); + } + + // check if all elements have ids assigned sequentially + bool is_element_map_identity() const ; + + // create tag index + // tag_column: ( physical (0) or elementary (1) ) specifying which tag to use + void index_structures(int tag_column); + + // get tag index, call index_structure_tags first + const StructIndex& get_structure_index() const + { + return m_structure_index; + } + + // get size of a structure identified by tag and element type + const StructIndex& get_structure_length() const + { + return m_structure_length; + } + + //! get list of structures + const StructVector& get_structures() const + { + return m_structures; + } + + public: + // helper function, calculate number of nodes associated with an element + static int num_nodes_per_elem_type(int elem_type); + + private: + void parse_nodes(std::ifstream& fin); + void parse_elements(std::ifstream& fin); + void parse_node_field(std::ifstream& fin); + void parse_element_field(std::ifstream& fin); + void parse_unknown_field(std::ifstream& fin, + const std::string& fieldname); + + private: + bool m_binary; + size_t m_data_size; + + FloatVector m_nodes; // len x 3 vector + + IndexVector m_elements; // linear array for nodes corresponding to each element + IndexVector m_elements_nodes_idx; // element indexes + + IntVector m_elements_ids; // element id's + IntVector m_elements_types; // Element types + IntVector m_elements_lengths; // Element lengths + IntField m_elements_tags; // Element tags, currently 2xtags per element + + FloatField m_node_fields; // Float field defined at each node + IntVector m_node_fields_components; // Number of components for node field + FieldNames m_node_fields_names; // Node field name + + FloatField m_element_fields; // Float field defined at each element + IntVector m_element_fields_components; // Number of components for element field + FieldNames m_element_fields_names; // Element field name + + StructIndex m_structure_index; // index tag ids + StructVector m_structures; // unique structures + StructIndex m_structure_length; // length of structures with consistent element type +}; + +} //igl + +#ifndef IGL_STATIC_LIBRARY +# include "MshLoader.cpp" +#endif + +#endif //IGL_MSH_LOADER_H \ No newline at end of file diff --git a/vendor/libigl/include/igl/MshSaver.cpp b/vendor/libigl/include/igl/MshSaver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac941af83aa75187155f15c24a944b65a731967e --- /dev/null +++ b/vendor/libigl/include/igl/MshSaver.cpp @@ -0,0 +1,347 @@ +// based on MSH writer from PyMesh + +// Copyright (c) 2015 Qingnan Zhou +// Copyright (C) 2020 Vladimir Fonov +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "MshSaver.h" + +#include +#include +#include +#include + + +IGL_INLINE igl::MshSaver::MshSaver(const std::string& filename, bool binary) : + m_binary(binary), m_num_nodes(0), m_num_elements(0) { + if (!m_binary) { + fout.open(filename.c_str(), std::fstream::out); + } else { + fout.open(filename.c_str(), std::fstream::binary); + } + if (!fout) { + std::stringstream err_msg; + err_msg << "Error opening " << filename << " to write msh file." << std::endl; + throw std::ios_base::failure(err_msg.str()); + } +} + +IGL_INLINE igl::MshSaver::~MshSaver() { + fout.close(); +} + +IGL_INLINE void igl::MshSaver::save_mesh( + const FloatVector& nodes, + const IndexVector& elements, + const IntVector& element_lengths, + const IntVector& element_types, + const IntVector& element_tags + ) { + + save_header(); + + save_nodes(nodes); + + save_elements(elements, element_lengths, element_types, element_tags ); +} + +IGL_INLINE void igl::MshSaver::save_header() { + if (!m_binary) { + fout << "$MeshFormat" << std::endl; + fout << "2.2 0 " << sizeof(double) << std::endl; + fout << "$EndMeshFormat" << std::endl; + fout.precision(17); + } else { + fout << "$MeshFormat" << std::endl; + fout << "2.2 1 " << sizeof(double) << std::endl; + int one = 1; + fout.write((char*)&one, sizeof(int)); + fout << "\n$EndMeshFormat" << std::endl; + } + fout.flush(); +} + +IGL_INLINE void igl::MshSaver::save_nodes(const FloatVector& nodes) { + // Save nodes. + // 3D hadrcoded + m_num_nodes = nodes.size() / 3; + fout << "$Nodes" << std::endl; + fout << m_num_nodes << std::endl; + if (!m_binary) { + for (size_t i=0; i 0) { + //int elem_type = el_type; + int num_elems = m_num_elements; + //int tags = 0; + if (!m_binary) { + size_t el_ptr=0; + for (size_t i=0;i( elements[el_ptr + e] )+1; + fout.write((const char*)&_elem, sizeof(int)); + } + el_ptr+=elem_len; + } + } + } + } + fout << "$EndElements" << std::endl; + fout.flush(); +} + +IGL_INLINE void igl::MshSaver::save_scalar_field(const std::string& fieldname, const FloatVector& field) { + assert(field.size() == m_num_nodes); + fout << "$NodeData" << std::endl; + fout << "1" << std::endl; // num string tags. + fout << "\"" << fieldname << "\"" << std::endl; + fout << "1" << std::endl; // num real tags. + fout << "0.0" << std::endl; // time value. + fout << "3" << std::endl; // num int tags. + fout << "0" << std::endl; // the time step + fout << "1" << std::endl; // 1-component scalar field. + fout << m_num_nodes << std::endl; // number of nodes + + if (m_binary) { + for (size_t i=0; i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_NORMALTYPE_H +#define IGL_NORMALTYPE_H + +namespace igl +{ + // PER_VERTEX_NORMALS Normals computed per vertex based on incident faces + // PER_FACE_NORMALS Normals computed per face + // PER_CORNER_NORMALS Normals computed per corner (aka wedge) based on + // incident faces without sharp edge + enum NormalType + { + PER_VERTEX_NORMALS, + PER_FACE_NORMALS, + PER_CORNER_NORMALS + }; +# define NUM_NORMAL_TYPE 3 +} + +#endif + diff --git a/vendor/libigl/include/igl/ONE.h b/vendor/libigl/include/igl/ONE.h new file mode 100644 index 0000000000000000000000000000000000000000..93c509d4e2f970ae81d15e9b8723ce90f51fe3e2 --- /dev/null +++ b/vendor/libigl/include/igl/ONE.h @@ -0,0 +1,22 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ONE_H +#define IGL_ONE_H +namespace igl +{ + // Often one needs a reference to a dummy variable containing one as its + // value, for example when using AntTweakBar's + // TwSetParam( "3D View", "opened", TW_PARAM_INT32, 1, &INT_ONE); + const char CHAR_ONE = 1; + const int INT_ONE = 1; + const unsigned int UNSIGNED_INT_ONE = 1; + const double DOUBLE_ONE = 1; + const float FLOAT_ONE = 1; +} +#endif + diff --git a/vendor/libigl/include/igl/PI.h b/vendor/libigl/include/igl/PI.h new file mode 100644 index 0000000000000000000000000000000000000000..520649cc7f9b81f53d5f0f61c9de65299ff31dc8 --- /dev/null +++ b/vendor/libigl/include/igl/PI.h @@ -0,0 +1,19 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PI_H +#define IGL_PI_H +namespace igl +{ + // Use standard mathematical constants' M_PI if available +#ifdef M_PI + constexpr double PI = M_PI; +#else + constexpr double PI = 3.1415926535897932384626433832795; +#endif +} +#endif diff --git a/vendor/libigl/include/igl/REDRUM.h b/vendor/libigl/include/igl/REDRUM.h new file mode 100644 index 0000000000000000000000000000000000000000..79ab72ffd189f7bd91abdc29c5718d6e8224f677 --- /dev/null +++ b/vendor/libigl/include/igl/REDRUM.h @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_REDRUM_H +#define IGL_REDRUM_H + +// Q: These should probably be inside the igl namespace. What's the correct +// way to do that? +// A: I guess the right way is to not use a macro but a proper function with +// streams as input and output. + +// ANSI color codes for formatting iostream style output + +#ifdef IGL_REDRUM_NOOP + +// Bold Red, etc. +#define NORUM(X) X +#define REDRUM(X) X +#define GREENRUM(X) X +#define YELLOWRUM(X) X +#define BLUERUM(X) X +#define MAGENTARUM(X) X +#define CYANRUM(X) X +// Regular Red, etc. +#define REDGIN(X) X +#define GREENGIN(X) X +#define YELLOWGIN(X) X +#define BLUEGIN(X) X +#define MAGENTAGIN(X) X +#define CYANGIN(X) X + +#else + +// Bold Red, etc. +#define NORUM(X) ""< +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_STR_H +#define IGL_STR_H +// http://stackoverflow.com/a/2433143/148668 +#include +#include +// Suppose you have a function: +// void func(std::string c); +// Then you can write: +// func(STR("foo"<<1<<"bar")); +#define STR(X) static_cast(std::ostringstream().flush() << X).str() +#endif diff --git a/vendor/libigl/include/igl/Singular_Value_Decomposition_Givens_QR_Factorization_Kernel.hpp b/vendor/libigl/include/igl/Singular_Value_Decomposition_Givens_QR_Factorization_Kernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2207285aa739134aaf61a81a4a71de6a18cf4651 --- /dev/null +++ b/vendor/libigl/include/igl/Singular_Value_Decomposition_Givens_QR_Factorization_Kernel.hpp @@ -0,0 +1,128 @@ +//##################################################################### +// Copyright (c) 2010-2011, Eftychios Sifakis. +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or +// other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +//##################################################################### + +//########################################################### +// Compute the Givens half-angle, construct the Givens quaternion and the rotation sine/cosine (for the full angle) +//########################################################### + +#ifdef _WIN32 + #undef max + #undef min +#endif + +ENABLE_SCALAR_IMPLEMENTATION(Ssh.f=SANPIVOT.f*SANPIVOT.f;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_mul_ps(VANPIVOT,VANPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_mul_ps(VANPIVOT,VANPIVOT);) +ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=(Ssh.f>=Ssmall_number.f)?0xffffffff:0;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_cmpge_ps(Vsh,Vsmall_number);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_cmp_ps(Vsh,Vsmall_number, _CMP_GE_OS);) //ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_cmpge_ps(Vsh,Vsmall_number);) +ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=Ssh.ui&SANPIVOT.ui;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_and_ps(Vsh,VANPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_and_ps(Vsh,VANPIVOT);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp5.f=0.;) ENABLE_SSE_IMPLEMENTATION(Vtmp5=_mm_xor_ps(Vtmp5,Vtmp5);) ENABLE_AVX_IMPLEMENTATION(Vtmp5=_mm256_xor_ps(Vtmp5,Vtmp5);) +ENABLE_SCALAR_IMPLEMENTATION(Sch.f=Stmp5.f-SAPIVOT.f;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_sub_ps(Vtmp5,VAPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_sub_ps(Vtmp5,VAPIVOT);) +ENABLE_SCALAR_IMPLEMENTATION(Sch.f=std::max(Sch.f,SAPIVOT.f);) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_max_ps(Vch,VAPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_max_ps(Vch,VAPIVOT);) +ENABLE_SCALAR_IMPLEMENTATION(Sch.f=std::max(Sch.f,Ssmall_number.f);) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_max_ps(Vch,Vsmall_number);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_max_ps(Vch,Vsmall_number);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp5.ui=(SAPIVOT.f>=Stmp5.f)?0xffffffff:0;) ENABLE_SSE_IMPLEMENTATION(Vtmp5=_mm_cmpge_ps(VAPIVOT,Vtmp5);) ENABLE_AVX_IMPLEMENTATION(Vtmp5=_mm256_cmp_ps(VAPIVOT,Vtmp5, _CMP_GE_OS);) //ENABLE_AVX_IMPLEMENTATION(Vtmp5=_mm256_cmpge_ps(VAPIVOT,Vtmp5);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sch.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vch,Vch);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vch,Vch);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ssh.f*Ssh.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vsh,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vsh,Vsh);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Stmp1.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_add_ps(Vtmp1,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_add_ps(Vtmp1,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=rsqrt(Stmp2.f);) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_rsqrt_ps(Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_rsqrt_ps(Vtmp2);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp4.f=Stmp1.f*Sone_half.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp4=_mm_mul_ps(Vtmp1,Vone_half);) ENABLE_AVX_IMPLEMENTATION(Vtmp4=_mm256_mul_ps(Vtmp1,Vone_half);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp4);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp3);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp2.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp2,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp2,Vtmp3);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f+Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_add_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_add_ps(Vtmp1,Vtmp4);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f-Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_sub_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_sub_ps(Vtmp1,Vtmp3);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f*Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vtmp1,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vtmp1,Vtmp2);) + +ENABLE_SCALAR_IMPLEMENTATION(Sch.f=Sch.f+Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_add_ps(Vch,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_add_ps(Vch,Vtmp1);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.ui=~Stmp5.ui&Ssh.ui;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_andnot_ps(Vtmp5,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=Vch;) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.ui=~Stmp5.ui&Sch.ui;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_andnot_ps(Vtmp5,Vch);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_blendv_ps(Vsh,Vch,Vtmp5);) +ENABLE_SCALAR_IMPLEMENTATION(Sch.ui=Stmp5.ui&Sch.ui;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_and_ps(Vtmp5,Vch);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_blendv_ps(Vtmp1,Vsh,Vtmp5);) +ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=Stmp5.ui&Ssh.ui;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_and_ps(Vtmp5,Vsh);) +ENABLE_SCALAR_IMPLEMENTATION(Sch.ui=Sch.ui|Stmp1.ui;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_or_ps(Vch,Vtmp1);) +ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=Ssh.ui|Stmp2.ui;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_or_ps(Vsh,Vtmp2);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sch.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vch,Vch);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vch,Vch);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ssh.f*Ssh.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vsh,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vsh,Vsh);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Stmp1.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_add_ps(Vtmp1,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_add_ps(Vtmp1,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=rsqrt(Stmp2.f);) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_rsqrt_ps(Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_rsqrt_ps(Vtmp2);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp4.f=Stmp1.f*Sone_half.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp4=_mm_mul_ps(Vtmp1,Vone_half);) ENABLE_AVX_IMPLEMENTATION(Vtmp4=_mm256_mul_ps(Vtmp1,Vone_half);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp4);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp3);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp2.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp2,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp2,Vtmp3);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f+Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_add_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_add_ps(Vtmp1,Vtmp4);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f-Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_sub_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_sub_ps(Vtmp1,Vtmp3);) + +ENABLE_SCALAR_IMPLEMENTATION(Sch.f=Sch.f*Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_mul_ps(Vch,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_mul_ps(Vch,Vtmp1);) +ENABLE_SCALAR_IMPLEMENTATION(Ssh.f=Ssh.f*Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_mul_ps(Vsh,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_mul_ps(Vsh,Vtmp1);) + +ENABLE_SCALAR_IMPLEMENTATION(Sc.f=Sch.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vc=_mm_mul_ps(Vch,Vch);) ENABLE_AVX_IMPLEMENTATION(Vc=_mm256_mul_ps(Vch,Vch);)ENABLE_SCALAR_IMPLEMENTATION(Ss.f=Ssh.f*Ssh.f;) ENABLE_SSE_IMPLEMENTATION(Vs=_mm_mul_ps(Vsh,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vs=_mm256_mul_ps(Vsh,Vsh);) +ENABLE_SCALAR_IMPLEMENTATION(Sc.f=Sc.f-Ss.f;) ENABLE_SSE_IMPLEMENTATION(Vc=_mm_sub_ps(Vc,Vs);) ENABLE_AVX_IMPLEMENTATION(Vc=_mm256_sub_ps(Vc,Vs);) +ENABLE_SCALAR_IMPLEMENTATION(Ss.f=Ssh.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vs=_mm_mul_ps(Vsh,Vch);) ENABLE_AVX_IMPLEMENTATION(Vs=_mm256_mul_ps(Vsh,Vch);) +ENABLE_SCALAR_IMPLEMENTATION(Ss.f=Ss.f+Ss.f;) ENABLE_SSE_IMPLEMENTATION(Vs=_mm_add_ps(Vs,Vs);) ENABLE_AVX_IMPLEMENTATION(Vs=_mm256_add_ps(Vs,Vs);) + +//########################################################### +// Rotate matrix A +//########################################################### + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SA11.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VA11);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VA11);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SA21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VA21);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VA21);) +ENABLE_SCALAR_IMPLEMENTATION(SA11.f=Sc.f*SA11.f;) ENABLE_SSE_IMPLEMENTATION(VA11=_mm_mul_ps(Vc,VA11);) ENABLE_AVX_IMPLEMENTATION(VA11=_mm256_mul_ps(Vc,VA11);) +ENABLE_SCALAR_IMPLEMENTATION(SA21.f=Sc.f*SA21.f;) ENABLE_SSE_IMPLEMENTATION(VA21=_mm_mul_ps(Vc,VA21);) ENABLE_AVX_IMPLEMENTATION(VA21=_mm256_mul_ps(Vc,VA21);) +ENABLE_SCALAR_IMPLEMENTATION(SA11.f=SA11.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VA11=_mm_add_ps(VA11,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VA11=_mm256_add_ps(VA11,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(SA21.f=SA21.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VA21=_mm_sub_ps(VA21,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VA21=_mm256_sub_ps(VA21,Vtmp1);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SA12.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VA12);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VA12);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SA22.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VA22);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VA22);) +ENABLE_SCALAR_IMPLEMENTATION(SA12.f=Sc.f*SA12.f;) ENABLE_SSE_IMPLEMENTATION(VA12=_mm_mul_ps(Vc,VA12);) ENABLE_AVX_IMPLEMENTATION(VA12=_mm256_mul_ps(Vc,VA12);) +ENABLE_SCALAR_IMPLEMENTATION(SA22.f=Sc.f*SA22.f;) ENABLE_SSE_IMPLEMENTATION(VA22=_mm_mul_ps(Vc,VA22);) ENABLE_AVX_IMPLEMENTATION(VA22=_mm256_mul_ps(Vc,VA22);) +ENABLE_SCALAR_IMPLEMENTATION(SA12.f=SA12.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VA12=_mm_add_ps(VA12,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VA12=_mm256_add_ps(VA12,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(SA22.f=SA22.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VA22=_mm_sub_ps(VA22,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VA22=_mm256_sub_ps(VA22,Vtmp1);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SA13.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VA13);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VA13);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SA23.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VA23);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VA23);) +ENABLE_SCALAR_IMPLEMENTATION(SA13.f=Sc.f*SA13.f;) ENABLE_SSE_IMPLEMENTATION(VA13=_mm_mul_ps(Vc,VA13);) ENABLE_AVX_IMPLEMENTATION(VA13=_mm256_mul_ps(Vc,VA13);) +ENABLE_SCALAR_IMPLEMENTATION(SA23.f=Sc.f*SA23.f;) ENABLE_SSE_IMPLEMENTATION(VA23=_mm_mul_ps(Vc,VA23);) ENABLE_AVX_IMPLEMENTATION(VA23=_mm256_mul_ps(Vc,VA23);) +ENABLE_SCALAR_IMPLEMENTATION(SA13.f=SA13.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VA13=_mm_add_ps(VA13,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VA13=_mm256_add_ps(VA13,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(SA23.f=SA23.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VA23=_mm_sub_ps(VA23,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VA23=_mm256_sub_ps(VA23,Vtmp1);) + +//########################################################### +// Update matrix U +//########################################################### + +#ifdef COMPUTE_U_AS_MATRIX +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SU11.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VU11);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VU11);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SU12.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VU12);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VU12);) +ENABLE_SCALAR_IMPLEMENTATION(SU11.f=Sc.f*SU11.f;) ENABLE_SSE_IMPLEMENTATION(VU11=_mm_mul_ps(Vc,VU11);) ENABLE_AVX_IMPLEMENTATION(VU11=_mm256_mul_ps(Vc,VU11);) +ENABLE_SCALAR_IMPLEMENTATION(SU12.f=Sc.f*SU12.f;) ENABLE_SSE_IMPLEMENTATION(VU12=_mm_mul_ps(Vc,VU12);) ENABLE_AVX_IMPLEMENTATION(VU12=_mm256_mul_ps(Vc,VU12);) +ENABLE_SCALAR_IMPLEMENTATION(SU11.f=SU11.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VU11=_mm_add_ps(VU11,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VU11=_mm256_add_ps(VU11,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(SU12.f=SU12.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VU12=_mm_sub_ps(VU12,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VU12=_mm256_sub_ps(VU12,Vtmp1);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SU21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VU21);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VU21);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SU22.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VU22);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VU22);) +ENABLE_SCALAR_IMPLEMENTATION(SU21.f=Sc.f*SU21.f;) ENABLE_SSE_IMPLEMENTATION(VU21=_mm_mul_ps(Vc,VU21);) ENABLE_AVX_IMPLEMENTATION(VU21=_mm256_mul_ps(Vc,VU21);) +ENABLE_SCALAR_IMPLEMENTATION(SU22.f=Sc.f*SU22.f;) ENABLE_SSE_IMPLEMENTATION(VU22=_mm_mul_ps(Vc,VU22);) ENABLE_AVX_IMPLEMENTATION(VU22=_mm256_mul_ps(Vc,VU22);) +ENABLE_SCALAR_IMPLEMENTATION(SU21.f=SU21.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VU21=_mm_add_ps(VU21,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VU21=_mm256_add_ps(VU21,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(SU22.f=SU22.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VU22=_mm_sub_ps(VU22,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VU22=_mm256_sub_ps(VU22,Vtmp1);) + +ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SU31.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VU31);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VU31);) +ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SU32.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VU32);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VU32);) +ENABLE_SCALAR_IMPLEMENTATION(SU31.f=Sc.f*SU31.f;) ENABLE_SSE_IMPLEMENTATION(VU31=_mm_mul_ps(Vc,VU31);) ENABLE_AVX_IMPLEMENTATION(VU31=_mm256_mul_ps(Vc,VU31);) +ENABLE_SCALAR_IMPLEMENTATION(SU32.f=Sc.f*SU32.f;) ENABLE_SSE_IMPLEMENTATION(VU32=_mm_mul_ps(Vc,VU32);) ENABLE_AVX_IMPLEMENTATION(VU32=_mm256_mul_ps(Vc,VU32);) +ENABLE_SCALAR_IMPLEMENTATION(SU31.f=SU31.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VU31=_mm_add_ps(VU31,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VU31=_mm256_add_ps(VU31,Vtmp2);) +ENABLE_SCALAR_IMPLEMENTATION(SU32.f=SU32.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VU32=_mm_sub_ps(VU32,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VU32=_mm256_sub_ps(VU32,Vtmp1);) +#endif diff --git a/vendor/libigl/include/igl/Singular_Value_Decomposition_Kernel_Declarations.hpp b/vendor/libigl/include/igl/Singular_Value_Decomposition_Kernel_Declarations.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0c3b3ff878d49073810afaf2b797dcf6e6e9c5fd --- /dev/null +++ b/vendor/libigl/include/igl/Singular_Value_Decomposition_Kernel_Declarations.hpp @@ -0,0 +1,137 @@ +//##################################################################### +// Copyright (c) 2010-2011, Eftychios Sifakis. +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or +// other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +//##################################################################### + +//########################################################### +// Local variable declarations +//########################################################### + +#ifdef PRINT_DEBUGGING_OUTPUT + +#ifdef USE_SSE_IMPLEMENTATION + float buf[4]; + float A11,A21,A31,A12,A22,A32,A13,A23,A33; + float S11,S21,S31,S22,S32,S33; +#ifdef COMPUTE_V_AS_QUATERNION + float QVS,QVVX,QVVY,QVVZ; +#endif +#ifdef COMPUTE_V_AS_MATRIX + float V11,V21,V31,V12,V22,V32,V13,V23,V33; +#endif +#ifdef COMPUTE_U_AS_QUATERNION + float QUS,QUVX,QUVY,QUVZ; +#endif +#ifdef COMPUTE_U_AS_MATRIX + float U11,U21,U31,U12,U22,U32,U13,U23,U33; +#endif +#endif + +#ifdef USE_AVX_IMPLEMENTATION + float buf[8]; + float A11,A21,A31,A12,A22,A32,A13,A23,A33; + float S11,S21,S31,S22,S32,S33; +#ifdef COMPUTE_V_AS_QUATERNION + float QVS,QVVX,QVVY,QVVZ; +#endif +#ifdef COMPUTE_V_AS_MATRIX + float V11,V21,V31,V12,V22,V32,V13,V23,V33; +#endif +#ifdef COMPUTE_U_AS_QUATERNION + float QUS,QUVX,QUVY,QUVZ; +#endif +#ifdef COMPUTE_U_AS_MATRIX + float U11,U21,U31,U12,U22,U32,U13,U23,U33; +#endif +#endif + +#endif + +const float Four_Gamma_Squared=sqrt(8.)+3.; +const float Sine_Pi_Over_Eight=.5*sqrt(2.-sqrt(2.)); +const float Cosine_Pi_Over_Eight=.5*sqrt(2.+sqrt(2.)); + +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sfour_gamma_squared;) ENABLE_SSE_IMPLEMENTATION(__m128 Vfour_gamma_squared;) ENABLE_AVX_IMPLEMENTATION(__m256 Vfour_gamma_squared;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ssine_pi_over_eight;) ENABLE_SSE_IMPLEMENTATION(__m128 Vsine_pi_over_eight;) ENABLE_AVX_IMPLEMENTATION(__m256 Vsine_pi_over_eight;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Scosine_pi_over_eight;) ENABLE_SSE_IMPLEMENTATION(__m128 Vcosine_pi_over_eight;) ENABLE_AVX_IMPLEMENTATION(__m256 Vcosine_pi_over_eight;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sone_half;) ENABLE_SSE_IMPLEMENTATION(__m128 Vone_half;) ENABLE_AVX_IMPLEMENTATION(__m256 Vone_half;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sone;) ENABLE_SSE_IMPLEMENTATION(__m128 Vone;) ENABLE_AVX_IMPLEMENTATION(__m256 Vone;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stiny_number;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtiny_number;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtiny_number;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ssmall_number;) ENABLE_SSE_IMPLEMENTATION(__m128 Vsmall_number;) ENABLE_AVX_IMPLEMENTATION(__m256 Vsmall_number;) + +ENABLE_SCALAR_IMPLEMENTATION(Sfour_gamma_squared.f=Four_Gamma_Squared;) ENABLE_SSE_IMPLEMENTATION(Vfour_gamma_squared=_mm_set1_ps(Four_Gamma_Squared);) ENABLE_AVX_IMPLEMENTATION(Vfour_gamma_squared=_mm256_set1_ps(Four_Gamma_Squared);) +ENABLE_SCALAR_IMPLEMENTATION(Ssine_pi_over_eight.f=Sine_Pi_Over_Eight;) ENABLE_SSE_IMPLEMENTATION(Vsine_pi_over_eight=_mm_set1_ps(Sine_Pi_Over_Eight);) ENABLE_AVX_IMPLEMENTATION(Vsine_pi_over_eight=_mm256_set1_ps(Sine_Pi_Over_Eight);) +ENABLE_SCALAR_IMPLEMENTATION(Scosine_pi_over_eight.f=Cosine_Pi_Over_Eight;) ENABLE_SSE_IMPLEMENTATION(Vcosine_pi_over_eight=_mm_set1_ps(Cosine_Pi_Over_Eight);) ENABLE_AVX_IMPLEMENTATION(Vcosine_pi_over_eight=_mm256_set1_ps(Cosine_Pi_Over_Eight);) +ENABLE_SCALAR_IMPLEMENTATION(Sone_half.f=.5;) ENABLE_SSE_IMPLEMENTATION(Vone_half=_mm_set1_ps(.5);) ENABLE_AVX_IMPLEMENTATION(Vone_half=_mm256_set1_ps(.5);) +ENABLE_SCALAR_IMPLEMENTATION(Sone.f=1.;) ENABLE_SSE_IMPLEMENTATION(Vone=_mm_set1_ps(1.);) ENABLE_AVX_IMPLEMENTATION(Vone=_mm256_set1_ps(1.);) +ENABLE_SCALAR_IMPLEMENTATION(Stiny_number.f=1.e-20;) ENABLE_SSE_IMPLEMENTATION(Vtiny_number=_mm_set1_ps(1.e-20);) ENABLE_AVX_IMPLEMENTATION(Vtiny_number=_mm256_set1_ps(1.e-20);) +ENABLE_SCALAR_IMPLEMENTATION(Ssmall_number.f=1.e-12;) ENABLE_SSE_IMPLEMENTATION(Vsmall_number=_mm_set1_ps(1.e-12);) ENABLE_AVX_IMPLEMENTATION(Vsmall_number=_mm256_set1_ps(1.e-12);) + +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa11;) ENABLE_SSE_IMPLEMENTATION(__m128 Va11;) ENABLE_AVX_IMPLEMENTATION(__m256 Va11;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa21;) ENABLE_SSE_IMPLEMENTATION(__m128 Va21;) ENABLE_AVX_IMPLEMENTATION(__m256 Va21;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa31;) ENABLE_SSE_IMPLEMENTATION(__m128 Va31;) ENABLE_AVX_IMPLEMENTATION(__m256 Va31;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa12;) ENABLE_SSE_IMPLEMENTATION(__m128 Va12;) ENABLE_AVX_IMPLEMENTATION(__m256 Va12;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa22;) ENABLE_SSE_IMPLEMENTATION(__m128 Va22;) ENABLE_AVX_IMPLEMENTATION(__m256 Va22;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa32;) ENABLE_SSE_IMPLEMENTATION(__m128 Va32;) ENABLE_AVX_IMPLEMENTATION(__m256 Va32;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa13;) ENABLE_SSE_IMPLEMENTATION(__m128 Va13;) ENABLE_AVX_IMPLEMENTATION(__m256 Va13;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa23;) ENABLE_SSE_IMPLEMENTATION(__m128 Va23;) ENABLE_AVX_IMPLEMENTATION(__m256 Va23;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa33;) ENABLE_SSE_IMPLEMENTATION(__m128 Va33;) ENABLE_AVX_IMPLEMENTATION(__m256 Va33;) + +#ifdef COMPUTE_V_AS_MATRIX +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv11;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv11;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv11;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv21;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv21;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv21;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv31;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv31;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv31;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv12;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv12;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv12;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv22;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv22;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv22;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv32;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv32;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv32;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv13;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv13;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv13;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv23;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv23;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv23;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv33;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv33;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv33;) +#endif + +#ifdef COMPUTE_V_AS_QUATERNION +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvs;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvs;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvs;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvx;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvx;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvx;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvy;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvy;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvy;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvz;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvz;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvz;) +#endif + +#ifdef COMPUTE_U_AS_MATRIX +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su11;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu11;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu11;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su21;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu21;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu21;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su31;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu31;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu31;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su12;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu12;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu12;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su22;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu22;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu22;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su32;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu32;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu32;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su13;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu13;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu13;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su23;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu23;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu23;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su33;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu33;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu33;) +#endif + +#ifdef COMPUTE_U_AS_QUATERNION +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squs;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqus;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqus;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squvx;) ENABLE_SSE_IMPLEMENTATION(__m128 Vquvx;) ENABLE_AVX_IMPLEMENTATION(__m256 Vquvx;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squvy;) ENABLE_SSE_IMPLEMENTATION(__m128 Vquvy;) ENABLE_AVX_IMPLEMENTATION(__m256 Vquvy;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squvz;) ENABLE_SSE_IMPLEMENTATION(__m128 Vquvz;) ENABLE_AVX_IMPLEMENTATION(__m256 Vquvz;) +#endif + +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sc;) ENABLE_SSE_IMPLEMENTATION(__m128 Vc;) ENABLE_AVX_IMPLEMENTATION(__m256 Vc;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sch;) ENABLE_SSE_IMPLEMENTATION(__m128 Vch;) ENABLE_AVX_IMPLEMENTATION(__m256 Vch;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ssh;) ENABLE_SSE_IMPLEMENTATION(__m128 Vsh;) ENABLE_AVX_IMPLEMENTATION(__m256 Vsh;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp1;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp1;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp1;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp2;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp2;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp2;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp3;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp3;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp3;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp4;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp4;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp4;) +ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp5;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp5;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp5;) diff --git a/vendor/libigl/include/igl/Singular_Value_Decomposition_Main_Kernel_Body.hpp b/vendor/libigl/include/igl/Singular_Value_Decomposition_Main_Kernel_Body.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e8898a8aa8e920ab7c2cd0bfaac5acc2e4991daf --- /dev/null +++ b/vendor/libigl/include/igl/Singular_Value_Decomposition_Main_Kernel_Body.hpp @@ -0,0 +1,1277 @@ +//##################################################################### +// Copyright (c) 2010-2011, Eftychios Sifakis. +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or +// other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +//##################################################################### + +#ifdef __INTEL_COMPILER +#pragma warning( disable : 592 ) +#endif + +// #define USE_ACCURATE_RSQRT_IN_JACOBI_CONJUGATION +// #define PERFORM_STRICT_QUATERNION_RENORMALIZATION + +{ // Begin block : Scope of qV (if not maintained) + +#ifndef COMPUTE_V_AS_QUATERNION + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvs;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvs;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvs;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvx;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvx;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvx;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvy;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvy;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvy;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvz;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvz;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvz;) +#endif + +{ // Begin block : Symmetric eigenanalysis + + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss11;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs11;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs11;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss21;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs21;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs21;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss31;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs31;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs31;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss22;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs22;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs22;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss32;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs32;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs32;) + ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss33;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs33;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs33;) + + ENABLE_SCALAR_IMPLEMENTATION(Sqvs.f=1.;) ENABLE_SSE_IMPLEMENTATION(Vqvs=Vone;) ENABLE_AVX_IMPLEMENTATION(Vqvs=Vone;) + ENABLE_SCALAR_IMPLEMENTATION(Sqvvx.f=0.;) ENABLE_SSE_IMPLEMENTATION(Vqvvx=_mm_xor_ps(Vqvvx,Vqvvx);) ENABLE_AVX_IMPLEMENTATION(Vqvvx=_mm256_xor_ps(Vqvvx,Vqvvx);) + ENABLE_SCALAR_IMPLEMENTATION(Sqvvy.f=0.;) ENABLE_SSE_IMPLEMENTATION(Vqvvy=_mm_xor_ps(Vqvvy,Vqvvy);) ENABLE_AVX_IMPLEMENTATION(Vqvvy=_mm256_xor_ps(Vqvvy,Vqvvy);) + ENABLE_SCALAR_IMPLEMENTATION(Sqvvz.f=0.;) ENABLE_SSE_IMPLEMENTATION(Vqvvz=_mm_xor_ps(Vqvvz,Vqvvz);) ENABLE_AVX_IMPLEMENTATION(Vqvvz=_mm256_xor_ps(Vqvvz,Vqvvz);) + + //########################################################### + // Compute normal equations matrix + //########################################################### + + ENABLE_SCALAR_IMPLEMENTATION(Ss11.f=Sa11.f*Sa11.f;) ENABLE_SSE_IMPLEMENTATION(Vs11=_mm_mul_ps(Va11,Va11);) ENABLE_AVX_IMPLEMENTATION(Vs11=_mm256_mul_ps(Va11,Va11);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa21.f*Sa21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va21,Va21);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va21,Va21);) + ENABLE_SCALAR_IMPLEMENTATION(Ss11.f=Stmp1.f+Ss11.f;) ENABLE_SSE_IMPLEMENTATION(Vs11=_mm_add_ps(Vtmp1,Vs11);) ENABLE_AVX_IMPLEMENTATION(Vs11=_mm256_add_ps(Vtmp1,Vs11);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa31.f*Sa31.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va31,Va31);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va31,Va31);) + ENABLE_SCALAR_IMPLEMENTATION(Ss11.f=Stmp1.f+Ss11.f;) ENABLE_SSE_IMPLEMENTATION(Vs11=_mm_add_ps(Vtmp1,Vs11);) ENABLE_AVX_IMPLEMENTATION(Vs11=_mm256_add_ps(Vtmp1,Vs11);) + + ENABLE_SCALAR_IMPLEMENTATION(Ss21.f=Sa12.f*Sa11.f;) ENABLE_SSE_IMPLEMENTATION(Vs21=_mm_mul_ps(Va12,Va11);) ENABLE_AVX_IMPLEMENTATION(Vs21=_mm256_mul_ps(Va12,Va11);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa22.f*Sa21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va22,Va21);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va22,Va21);) + ENABLE_SCALAR_IMPLEMENTATION(Ss21.f=Stmp1.f+Ss21.f;) ENABLE_SSE_IMPLEMENTATION(Vs21=_mm_add_ps(Vtmp1,Vs21);) ENABLE_AVX_IMPLEMENTATION(Vs21=_mm256_add_ps(Vtmp1,Vs21);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa32.f*Sa31.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va32,Va31);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va32,Va31);) + ENABLE_SCALAR_IMPLEMENTATION(Ss21.f=Stmp1.f+Ss21.f;) ENABLE_SSE_IMPLEMENTATION(Vs21=_mm_add_ps(Vtmp1,Vs21);) ENABLE_AVX_IMPLEMENTATION(Vs21=_mm256_add_ps(Vtmp1,Vs21);) + + ENABLE_SCALAR_IMPLEMENTATION(Ss31.f=Sa13.f*Sa11.f;) ENABLE_SSE_IMPLEMENTATION(Vs31=_mm_mul_ps(Va13,Va11);) ENABLE_AVX_IMPLEMENTATION(Vs31=_mm256_mul_ps(Va13,Va11);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa23.f*Sa21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va23,Va21);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va23,Va21);) + ENABLE_SCALAR_IMPLEMENTATION(Ss31.f=Stmp1.f+Ss31.f;) ENABLE_SSE_IMPLEMENTATION(Vs31=_mm_add_ps(Vtmp1,Vs31);) ENABLE_AVX_IMPLEMENTATION(Vs31=_mm256_add_ps(Vtmp1,Vs31);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa33.f*Sa31.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va33,Va31);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va33,Va31);) + ENABLE_SCALAR_IMPLEMENTATION(Ss31.f=Stmp1.f+Ss31.f;) ENABLE_SSE_IMPLEMENTATION(Vs31=_mm_add_ps(Vtmp1,Vs31);) ENABLE_AVX_IMPLEMENTATION(Vs31=_mm256_add_ps(Vtmp1,Vs31);) + + ENABLE_SCALAR_IMPLEMENTATION(Ss22.f=Sa12.f*Sa12.f;) ENABLE_SSE_IMPLEMENTATION(Vs22=_mm_mul_ps(Va12,Va12);) ENABLE_AVX_IMPLEMENTATION(Vs22=_mm256_mul_ps(Va12,Va12);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa22.f*Sa22.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va22,Va22);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va22,Va22);) + ENABLE_SCALAR_IMPLEMENTATION(Ss22.f=Stmp1.f+Ss22.f;) ENABLE_SSE_IMPLEMENTATION(Vs22=_mm_add_ps(Vtmp1,Vs22);) ENABLE_AVX_IMPLEMENTATION(Vs22=_mm256_add_ps(Vtmp1,Vs22);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa32.f*Sa32.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va32,Va32);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va32,Va32);) + ENABLE_SCALAR_IMPLEMENTATION(Ss22.f=Stmp1.f+Ss22.f;) ENABLE_SSE_IMPLEMENTATION(Vs22=_mm_add_ps(Vtmp1,Vs22);) ENABLE_AVX_IMPLEMENTATION(Vs22=_mm256_add_ps(Vtmp1,Vs22);) + + ENABLE_SCALAR_IMPLEMENTATION(Ss32.f=Sa13.f*Sa12.f;) ENABLE_SSE_IMPLEMENTATION(Vs32=_mm_mul_ps(Va13,Va12);) ENABLE_AVX_IMPLEMENTATION(Vs32=_mm256_mul_ps(Va13,Va12);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa23.f*Sa22.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va23,Va22);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va23,Va22);) + ENABLE_SCALAR_IMPLEMENTATION(Ss32.f=Stmp1.f+Ss32.f;) ENABLE_SSE_IMPLEMENTATION(Vs32=_mm_add_ps(Vtmp1,Vs32);) ENABLE_AVX_IMPLEMENTATION(Vs32=_mm256_add_ps(Vtmp1,Vs32);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa33.f*Sa32.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va33,Va32);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va33,Va32);) + ENABLE_SCALAR_IMPLEMENTATION(Ss32.f=Stmp1.f+Ss32.f;) ENABLE_SSE_IMPLEMENTATION(Vs32=_mm_add_ps(Vtmp1,Vs32);) ENABLE_AVX_IMPLEMENTATION(Vs32=_mm256_add_ps(Vtmp1,Vs32);) + + ENABLE_SCALAR_IMPLEMENTATION(Ss33.f=Sa13.f*Sa13.f;) ENABLE_SSE_IMPLEMENTATION(Vs33=_mm_mul_ps(Va13,Va13);) ENABLE_AVX_IMPLEMENTATION(Vs33=_mm256_mul_ps(Va13,Va13);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa23.f*Sa23.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va23,Va23);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va23,Va23);) + ENABLE_SCALAR_IMPLEMENTATION(Ss33.f=Stmp1.f+Ss33.f;) ENABLE_SSE_IMPLEMENTATION(Vs33=_mm_add_ps(Vtmp1,Vs33);) ENABLE_AVX_IMPLEMENTATION(Vs33=_mm256_add_ps(Vtmp1,Vs33);) + ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sa33.f*Sa33.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Va33,Va33);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Va33,Va33);) + ENABLE_SCALAR_IMPLEMENTATION(Ss33.f=Stmp1.f+Ss33.f;) ENABLE_SSE_IMPLEMENTATION(Vs33=_mm_add_ps(Vtmp1,Vs33);) ENABLE_AVX_IMPLEMENTATION(Vs33=_mm256_add_ps(Vtmp1,Vs33);) + + //########################################################### + // Solve symmetric eigenproblem using Jacobi iteration + //########################################################### + + for(int sweep=1;sweep<=4;sweep++){ + + // First Jacobi conjugation + +#define SS11 Ss11 +#define SS21 Ss21 +#define SS31 Ss31 +#define SS22 Ss22 +#define SS32 Ss32 +#define SS33 Ss33 +#define SQVVX Sqvvx +#define SQVVY Sqvvy +#define SQVVZ Sqvvz +#define STMP1 Stmp1 +#define STMP2 Stmp2 +#define STMP3 Stmp3 + +#define VS11 Vs11 +#define VS21 Vs21 +#define VS31 Vs31 +#define VS22 Vs22 +#define VS32 Vs32 +#define VS33 Vs33 +#define VQVVX Vqvvx +#define VQVVY Vqvvy +#define VQVVZ Vqvvz +#define VTMP1 Vtmp1 +#define VTMP2 Vtmp2 +#define VTMP3 Vtmp3 + +#include "Singular_Value_Decomposition_Jacobi_Conjugation_Kernel.hpp" + +#undef SS11 +#undef SS21 +#undef SS31 +#undef SS22 +#undef SS32 +#undef SS33 +#undef SQVVX +#undef SQVVY +#undef SQVVZ +#undef STMP1 +#undef STMP2 +#undef STMP3 + +#undef VS11 +#undef VS21 +#undef VS31 +#undef VS22 +#undef VS32 +#undef VS33 +#undef VQVVX +#undef VQVVY +#undef VQVVZ +#undef VTMP1 +#undef VTMP2 +#undef VTMP3 + + // Second Jacobi conjugation + +#define SS11 Ss22 +#define SS21 Ss32 +#define SS31 Ss21 +#define SS22 Ss33 +#define SS32 Ss31 +#define SS33 Ss11 +#define SQVVX Sqvvy +#define SQVVY Sqvvz +#define SQVVZ Sqvvx +#define STMP1 Stmp2 +#define STMP2 Stmp3 +#define STMP3 Stmp1 + +#define VS11 Vs22 +#define VS21 Vs32 +#define VS31 Vs21 +#define VS22 Vs33 +#define VS32 Vs31 +#define VS33 Vs11 +#define VQVVX Vqvvy +#define VQVVY Vqvvz +#define VQVVZ Vqvvx +#define VTMP1 Vtmp2 +#define VTMP2 Vtmp3 +#define VTMP3 Vtmp1 + +#include "Singular_Value_Decomposition_Jacobi_Conjugation_Kernel.hpp" + +#undef SS11 +#undef SS21 +#undef SS31 +#undef SS22 +#undef SS32 +#undef SS33 +#undef SQVVX +#undef SQVVY +#undef SQVVZ +#undef STMP1 +#undef STMP2 +#undef STMP3 + +#undef VS11 +#undef VS21 +#undef VS31 +#undef VS22 +#undef VS32 +#undef VS33 +#undef VQVVX +#undef VQVVY +#undef VQVVZ +#undef VTMP1 +#undef VTMP2 +#undef VTMP3 + + // Third Jacobi conjugation + +#define SS11 Ss33 +#define SS21 Ss31 +#define SS31 Ss32 +#define SS22 Ss11 +#define SS32 Ss21 +#define SS33 Ss22 +#define SQVVX Sqvvz +#define SQVVY Sqvvx +#define SQVVZ Sqvvy +#define STMP1 Stmp3 +#define STMP2 Stmp1 +#define STMP3 Stmp2 + +#define VS11 Vs33 +#define VS21 Vs31 +#define VS31 Vs32 +#define VS22 Vs11 +#define VS32 Vs21 +#define VS33 Vs22 +#define VQVVX Vqvvz +#define VQVVY Vqvvx +#define VQVVZ Vqvvy +#define VTMP1 Vtmp3 +#define VTMP2 Vtmp1 +#define VTMP3 Vtmp2 + +#include "Singular_Value_Decomposition_Jacobi_Conjugation_Kernel.hpp" + +#undef SS11 +#undef SS21 +#undef SS31 +#undef SS22 +#undef SS32 +#undef SS33 +#undef SQVVX +#undef SQVVY +#undef SQVVZ +#undef STMP1 +#undef STMP2 +#undef STMP3 + +#undef VS11 +#undef VS21 +#undef VS31 +#undef VS22 +#undef VS32 +#undef VS33 +#undef VQVVX +#undef VQVVY +#undef VQVVZ +#undef VTMP1 +#undef VTMP2 +#undef VTMP3 + } + +#ifdef PRINT_DEBUGGING_OUTPUT +#ifdef USE_SCALAR_IMPLEMENTATION + std::cout<<"Scalar S ="< +#include +#endif + +// Prevent warnings +#ifdef ENABLE_SCALAR_IMPLEMENTATION +# undef ENABLE_SCALAR_IMPLEMENTATION +#endif +#ifdef ENABLE_SSE_IMPLEMENTATION +# undef ENABLE_SSE_IMPLEMENTATION +#endif +#ifdef ENABLE_AVX_IMPLEMENTATION +# undef ENABLE_AVX_IMPLEMENTATION +#endif + +#ifdef USE_SCALAR_IMPLEMENTATION +#define ENABLE_SCALAR_IMPLEMENTATION(X) X +#else +#define ENABLE_SCALAR_IMPLEMENTATION(X) +#endif + +#ifdef USE_SSE_IMPLEMENTATION +#define ENABLE_SSE_IMPLEMENTATION(X) X +#else +#define ENABLE_SSE_IMPLEMENTATION(X) +#endif + +#ifdef USE_AVX_IMPLEMENTATION +#include +#define ENABLE_AVX_IMPLEMENTATION(X) X +#else +// Stefan: removed include. Why does it import MMX instructions, shouldn't this be under the #ifdef USE_SSE_IMPLEMENTATION above? +//#include +#define ENABLE_AVX_IMPLEMENTATION(X) +#endif + +#ifdef USE_SCALAR_IMPLEMENTATION +// Alec: Why is this using sse intrinsics if it's supposed to be the scalar +// implementation? +#ifdef __SSE__ +#include +// Changed to inline +inline float rsqrt(const float f) +{ + float buf[4]; + buf[0]=f; + __m128 v=_mm_loadu_ps(buf); + v=_mm_rsqrt_ss(v); + _mm_storeu_ps(buf,v); + return buf[0]; +} +#else +#include +inline float rsqrt(const float f) +{ + return 1./sqrtf(f); +} +#endif +#endif + + diff --git a/vendor/libigl/include/igl/SortableRow.h b/vendor/libigl/include/igl/SortableRow.h new file mode 100644 index 0000000000000000000000000000000000000000..2a6d8c3e87777db65203327833226ddf82cde7d8 --- /dev/null +++ b/vendor/libigl/include/igl/SortableRow.h @@ -0,0 +1,66 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SORTABLE_ROW_H +#define IGL_SORTABLE_ROW_H + +// Simple class to contain a rowvector which allows rowwise sorting and +// reordering +#include + +namespace igl +{ + // Templates: + // T should be a matrix that implements .size(), and operator(int i) + template + class SortableRow + { + public: + T data; + public: + SortableRow():data(){}; + SortableRow(const T & data):data(data){}; + bool operator<(const SortableRow & that) const + { + // Lexicographical + int minc = (this->data.size() < that.data.size()? + this->data.size() : that.data.size()); + // loop over columns + for(int i = 0;idata(i) == that.data(i)) + { + continue; + } + return this->data(i) < that.data(i); + } + // All characters the same, comes done to length + return this->data.size()data.size() != that.data.size()) + { + return false; + } + for(int i = 0;idata.size();i++) + { + if(this->data(i) != that.data(i)) + { + return false; + } + } + return true; + }; + bool operator!=(const SortableRow & that) const + { + return !(*this == that); + }; + }; +} + +#endif diff --git a/vendor/libigl/include/igl/Timer.h b/vendor/libigl/include/igl/Timer.h new file mode 100644 index 0000000000000000000000000000000000000000..ac9e55e6b93d51479067af6ec02327014803c697 --- /dev/null +++ b/vendor/libigl/include/igl/Timer.h @@ -0,0 +1,179 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +// High Resolution Timer. +// +// Resolution on Mac (clock tick) +// Resolution on Linux (1 us not tested) +// Resolution on Windows (clock tick not tested) + +#ifndef IGL_TIMER_H +#define IGL_TIMER_H + +#ifdef WIN32 // Windows system specific +#include +#elif __APPLE__ // Unix based system specific +#include // for mach_absolute_time +#else +#include +#endif +#include + +namespace igl +{ + class Timer + { + public: + // default constructor + Timer(): + stopped(0), +#ifdef WIN32 + frequency(), + startCount(), + endCount() +#elif __APPLE__ + startCount(0), + endCount(0) +#else + startCount(), + endCount() +#endif + { +#ifdef WIN32 + QueryPerformanceFrequency(&frequency); + startCount.QuadPart = 0; + endCount.QuadPart = 0; +#elif __APPLE__ + startCount = 0; + endCount = 0; +#else + startCount.tv_sec = startCount.tv_usec = 0; + endCount.tv_sec = endCount.tv_usec = 0; +#endif + + stopped = 0; + } + // default destructor + ~Timer() + { + + } + +#ifdef __APPLE__ + //Raw mach_absolute_times going in, difference in seconds out + double subtractTimes( uint64_t endTime, uint64_t startTime ) + { + uint64_t difference = endTime - startTime; + static double conversion = 0.0; + + if( conversion == 0.0 ) + { + mach_timebase_info_data_t info; + kern_return_t err = mach_timebase_info( &info ); + + //Convert the timebase into seconds + if( err == 0 ) + conversion = 1e-9 * (double) info.numer / (double) info.denom; + } + + return conversion * (double) difference; + } +#endif + + // start timer + void start() + { + stopped = 0; // reset stop flag +#ifdef WIN32 + QueryPerformanceCounter(&startCount); +#elif __APPLE__ + startCount = mach_absolute_time(); +#else + gettimeofday(&startCount, NULL); +#endif + + } + + // stop the timer + void stop() + { + stopped = 1; // set timer stopped flag + +#ifdef WIN32 + QueryPerformanceCounter(&endCount); +#elif __APPLE__ + endCount = mach_absolute_time(); +#else + gettimeofday(&endCount, NULL); +#endif + + } + // get elapsed time in second + double getElapsedTime() + { + return this->getElapsedTimeInSec(); + } + // get elapsed time in second (same as getElapsedTime) + double getElapsedTimeInSec() + { + return this->getElapsedTimeInMicroSec() * 0.000001; + } + + // get elapsed time in milli-second + double getElapsedTimeInMilliSec() + { + return this->getElapsedTimeInMicroSec() * 0.001; + } + // get elapsed time in micro-second + double getElapsedTimeInMicroSec() + { + double startTimeInMicroSec = 0; + double endTimeInMicroSec = 0; + +#ifdef WIN32 + if(!stopped) + QueryPerformanceCounter(&endCount); + + startTimeInMicroSec = + startCount.QuadPart * (1000000.0 / frequency.QuadPart); + endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart); +#elif __APPLE__ + if (!stopped) + endCount = mach_absolute_time(); + + return subtractTimes(endCount,startCount)/1e-6; +#else + if(!stopped) + gettimeofday(&endCount, NULL); + + startTimeInMicroSec = + (startCount.tv_sec * 1000000.0) + startCount.tv_usec; + endTimeInMicroSec = (endCount.tv_sec * 1000000.0) + endCount.tv_usec; +#endif + + return endTimeInMicroSec - startTimeInMicroSec; + } + + private: + // stop flag + int stopped; +#ifdef WIN32 + // ticks per second + LARGE_INTEGER frequency; + LARGE_INTEGER startCount; + LARGE_INTEGER endCount; +#elif __APPLE__ + uint64_t startCount; + uint64_t endCount; +#else + timeval startCount; + timeval endCount; +#endif + }; +} +#endif // TIMER_H_DEF + diff --git a/vendor/libigl/include/igl/WindingNumberAABB.h b/vendor/libigl/include/igl/WindingNumberAABB.h new file mode 100644 index 0000000000000000000000000000000000000000..d7f761ba022cdbd96b73c6968b436c7b6964992f --- /dev/null +++ b/vendor/libigl/include/igl/WindingNumberAABB.h @@ -0,0 +1,389 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +// # MUTUAL DEPENDENCY ISSUE FOR HEADER ONLY VERSION +// MUST INCLUDE winding_number.h first before guard: +#include "winding_number.h" + +#ifndef IGL_WINDINGNUMBERAABB_H +#define IGL_WINDINGNUMBERAABB_H +#include "WindingNumberTree.h" + +namespace igl +{ + template < + typename Point, + typename DerivedV, + typename DerivedF > + class WindingNumberAABB : public WindingNumberTree + { + protected: + Point min_corner; + Point max_corner; + typename DerivedV::Scalar total_positive_area; + public: + enum SplitMethod + { + CENTER_ON_LONGEST_AXIS = 0, + MEDIAN_ON_LONGEST_AXIS = 1, + NUM_SPLIT_METHODS = 2 + } split_method; + public: + inline WindingNumberAABB(): + total_positive_area(std::numeric_limits::infinity()), + split_method(MEDIAN_ON_LONGEST_AXIS) + {} + inline WindingNumberAABB( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F); + inline WindingNumberAABB( + const WindingNumberTree & parent, + const Eigen::MatrixBase & F); + // Initialize some things + inline void set_mesh( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F); + inline void init(); + inline bool inside(const Point & p) const; + inline virtual void grow(); + // Compute min and max corners + inline void compute_min_max_corners(); + inline typename DerivedV::Scalar max_abs_winding_number(const Point & p) const; + inline typename DerivedV::Scalar max_simple_abs_winding_number(const Point & p) const; + }; +} + +// Implementation + +#include "winding_number.h" + +#include "barycenter.h" +#include "median.h" +#include "doublearea.h" +#include "per_face_normals.h" + +#include +#include +#include + +// Minimum number of faces in a hierarchy element (this is probably dependent +// on speed of machine and compiler optimization) +#ifndef WindingNumberAABB_MIN_F +# define WindingNumberAABB_MIN_F 100 +#endif + +template +inline void igl::WindingNumberAABB::set_mesh( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F) +{ + igl::WindingNumberTree::set_mesh(V,F); + init(); +} + +template +inline void igl::WindingNumberAABB::init() +{ + using namespace Eigen; + assert(max_corner.size() == 3); + assert(min_corner.size() == 3); + compute_min_max_corners(); + Eigen::Matrix dblA; + doublearea(this->getV(),this->getF(),dblA); + total_positive_area = dblA.sum()/2.0; +} + +template +inline igl::WindingNumberAABB::WindingNumberAABB( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F): + WindingNumberTree(V,F), + min_corner(), + max_corner(), + total_positive_area( + std::numeric_limits::infinity()), + split_method(MEDIAN_ON_LONGEST_AXIS) +{ + init(); +} + +template +inline igl::WindingNumberAABB::WindingNumberAABB( + const WindingNumberTree & parent, + const Eigen::MatrixBase & F): + WindingNumberTree(parent,F), + min_corner(), + max_corner(), + total_positive_area( + std::numeric_limits::infinity()), + split_method(MEDIAN_ON_LONGEST_AXIS) +{ + init(); +} + +template +inline void igl::WindingNumberAABB::grow() +{ + using namespace std; + using namespace Eigen; + // Clear anything that already exists + this->delete_children(); + + //cout<<"cap.rows(): "<getcap().rows()<getF().rows()<getF().rows() <= (WindingNumberAABB_MIN_F>0?WindingNumberAABB_MIN_F:0) || + (this->getcap().rows() - 2) >= this->getF().rows()) + { + // Don't grow + return; + } + + // Compute longest direction + int max_d = -1; + typename DerivedV::Scalar max_len = + -numeric_limits::infinity(); + for(int d = 0;d max_len ) + { + max_len = (max_corner[d] - min_corner[d]); + max_d = d; + } + } + // Compute facet barycenters + Eigen::Matrix BC; + barycenter(this->getV(),this->getF(),BC); + + + // Blerg, why is selecting rows so difficult + + typename DerivedV::Scalar split_value; + // Split in longest direction + switch(split_method) + { + case MEDIAN_ON_LONGEST_AXIS: + // Determine median + median(BC.col(max_d),split_value); + break; + default: + assert(false); + case CENTER_ON_LONGEST_AXIS: + split_value = 0.5*(max_corner[max_d] + min_corner[max_d]); + break; + } + //cout<<"c: "<<0.5*(max_corner[max_d] + min_corner[max_d])<<" "<< + // "m: "< id( this->getF().rows()); + for(int i = 0;igetF().rows();i++) + { + if(BC(i,max_d) <= split_value) + { + id[i] = 0; //left + }else + { + id[i] = 1; //right + } + } + + const int lefts = (int) count(id.begin(),id.end(),0); + const int rights = (int) count(id.begin(),id.end(),1); + if(lefts == 0 || rights == 0) + { + // badly balanced base case (could try to recut) + return; + } + assert(lefts+rights == this->getF().rows()); + DerivedF leftF(lefts, this->getF().cols()); + DerivedF rightF(rights,this->getF().cols()); + int left_i = 0; + int right_i = 0; + for(int i = 0;igetF().rows();i++) + { + if(id[i] == 0) + { + leftF.row(left_i++) = this->getF().row(i); + }else if(id[i] == 1) + { + rightF.row(right_i++) = this->getF().row(i); + }else + { + assert(false); + } + } + assert(right_i == rightF.rows()); + assert(left_i == leftF.rows()); + // Finally actually grow children and Recursively grow + WindingNumberAABB * leftWindingNumberAABB = + new WindingNumberAABB(*this,leftF); + leftWindingNumberAABB->grow(); + this->children.push_back(leftWindingNumberAABB); + WindingNumberAABB * rightWindingNumberAABB = + new WindingNumberAABB(*this,rightF); + rightWindingNumberAABB->grow(); + this->children.push_back(rightWindingNumberAABB); +} + +template +inline bool igl::WindingNumberAABB::inside(const Point & p) const +{ + assert(p.size() == max_corner.size()); + assert(p.size() == min_corner.size()); + for(int i = 0;i= max_corner(i)) + // **MUST** be conservative + if( p(i) < min_corner(i) || p(i) > max_corner(i)) + { + return false; + } + } + return true; +} + +template +inline void igl::WindingNumberAABB::compute_min_max_corners() +{ + using namespace std; + // initialize corners + for(int d = 0;d::infinity(); + max_corner[d] = -numeric_limits::infinity(); + } + + this->center = Point(0,0,0); + // Loop over facets + for(int i = 0;igetF().rows();i++) + { + for(int j = 0;jgetF().cols();j++) + { + for(int d = 0;dgetV()(this->getF()(i,j),d) < min_corner[d] ? + this->getV()(this->getF()(i,j),d) : min_corner[d]; + max_corner[d] = + this->getV()(this->getF()(i,j),d) > max_corner[d] ? + this->getV()(this->getF()(i,j),d) : max_corner[d]; + } + // This is biased toward vertices incident on more than one face, but + // perhaps that's good + this->center += this->getV().row(this->getF()(i,j)); + } + } + // Average + this->center.array() /= this->getF().size(); + + //cout<<"min_corner: "<min_corner.transpose()<center.transpose()<max_corner.transpose()<max_corner + this->min_corner)*0.5).transpose()<radius = (max_corner-min_corner).norm()/2.0; +} + +template +inline typename DerivedV::Scalar +igl::WindingNumberAABB::max_abs_winding_number(const Point & p) const +{ + using namespace std; + // Only valid if not inside + if(inside(p)) + { + return numeric_limits::infinity(); + } + // Q: we know the total positive area so what's the most this could project + // to? Remember it could be layered in the same direction. + return numeric_limits::infinity(); +} + +template +inline typename DerivedV::Scalar + igl::WindingNumberAABB::max_simple_abs_winding_number( + const Point & p) const +{ + using namespace std; + using namespace Eigen; + // Only valid if not inside + if(inside(p)) + { + return numeric_limits::infinity(); + } + // Max simple is the same as sum of positive winding number contributions of + // bounding box + + // begin precomputation + //MatrixXd BV((int)pow(2,3),3); + typedef + Eigen::Matrix + MatrixXS; + typedef + Eigen::Matrix + MatrixXF; + MatrixXS BV((int)(1<<3),3); + BV << + min_corner[0],min_corner[1],min_corner[2], + min_corner[0],min_corner[1],max_corner[2], + min_corner[0],max_corner[1],min_corner[2], + min_corner[0],max_corner[1],max_corner[2], + max_corner[0],min_corner[1],min_corner[2], + max_corner[0],min_corner[1],max_corner[2], + max_corner[0],max_corner[1],min_corner[2], + max_corner[0],max_corner[1],max_corner[2]; + MatrixXF BF(2*2*3,3); + BF << + 0,6,4, + 0,2,6, + 0,3,2, + 0,1,3, + 2,7,6, + 2,3,7, + 4,6,7, + 4,7,5, + 0,4,5, + 0,5,1, + 1,5,7, + 1,7,3; + MatrixXS BFN; + per_face_normals(BV,BF,BFN); + // end of precomputation + + // Only keep those with positive dot products + MatrixXF PBF(BF.rows(),BF.cols()); + int pbfi = 0; + Point p2c = 0.5*(min_corner+max_corner)-p; + for(int i = 0;i 0) + { + PBF.row(pbfi++) = BF.row(i); + } + } + PBF.conservativeResize(pbfi,PBF.cols()); + return igl::winding_number(BV,PBF,p); +} + +// This is a bullshit template because AABB annoyingly needs templates for bad +// combinations of 3D V with DIM=2 AABB +// +// _Define_ as a no-op rather than monkeying around with the proper code above +namespace igl +{ + template <> inline igl::WindingNumberAABB,Eigen::Matrix,Eigen::Matrix>::WindingNumberAABB(const Eigen::MatrixBase> & V, const Eigen::MatrixBase> & F){}; + template <> inline void igl::WindingNumberAABB,Eigen::Matrix,Eigen::Matrix>::grow(){}; + template <> inline void igl::WindingNumberAABB,Eigen::Matrix,Eigen::Matrix>::init(){}; + +} + +#endif diff --git a/vendor/libigl/include/igl/WindingNumberTree.h b/vendor/libigl/include/igl/WindingNumberTree.h new file mode 100644 index 0000000000000000000000000000000000000000..91d084e6ce0226a8128a47e725d0ded2d4b7f1ed --- /dev/null +++ b/vendor/libigl/include/igl/WindingNumberTree.h @@ -0,0 +1,501 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WINDINGNUMBERTREE_H +#define IGL_WINDINGNUMBERTREE_H +#include +#include +#include +#include "WindingNumberMethod.h" + +namespace igl +{ + // Space partitioning tree for computing winding number hierarchically. + // + // Templates: + // Point type for points in space, e.g. Eigen::Vector3d + template < + typename Point, + typename DerivedV, + typename DerivedF > + class WindingNumberTree + { + public: + // Method to use (see enum above) + //static double min_max_w; + static std::map< + std::pair, + typename DerivedV::Scalar> + cached; + // This is only need to fill in references, it should never actually be touched + // and shouldn't cause race conditions. (This is a hack, but I think it's "safe") + static DerivedV dummyV; + protected: + WindingNumberMethod method; + const WindingNumberTree * parent; + std::list children; + typedef + Eigen::Matrix + MatrixXS; + typedef + Eigen::Matrix + MatrixXF; + //// List of boundary edges (recall edges are vertices in 2d) + //const Eigen::MatrixXi boundary; + // Base mesh vertices + DerivedV & V; + // Base mesh vertices with duplicates removed + MatrixXS SV; + // Facets in this bounding volume + MatrixXF F; + // Tessellated boundary curve + MatrixXF cap; + // Upper Bound on radius of enclosing ball + typename DerivedV::Scalar radius; + // (Approximate) center (of mass) + Point center; + public: + inline WindingNumberTree(); + // For root + inline WindingNumberTree( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F); + // For chilluns + inline WindingNumberTree( + const WindingNumberTree & parent, + const Eigen::MatrixBase & F); + inline virtual ~WindingNumberTree(); + inline void delete_children(); + inline virtual void set_mesh( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F); + // Set method + inline void set_method( const WindingNumberMethod & m); + public: + inline const DerivedV & getV() const; + inline const MatrixXF & getF() const; + inline const MatrixXF & getcap() const; + // Grow the Tree recursively + inline virtual void grow(); + // Determine whether a given point is inside the bounding + // + // Inputs: + // p query point + // Returns true if the point p is inside this bounding volume + inline virtual bool inside(const Point & p) const; + // Compute the (partial) winding number of a given point p + // According to method + // + // Inputs: + // p query point + // Returns winding number + inline typename DerivedV::Scalar winding_number(const Point & p) const; + // Same as above, but always computes winding number using exact method + // (sum over every facet) + inline typename DerivedV::Scalar winding_number_all(const Point & p) const; + // Same as above, but always computes using sum over tessllated boundary + inline typename DerivedV::Scalar winding_number_boundary(const Point & p) const; + //// Same as winding_number above, but if max_simple_abs_winding_number is + //// less than some threshold min_max_w just return 0 (colloquially the "fast + //// multipole method) + //// + //// + //// Inputs: + //// p query point + //// min_max_w minimum max simple w to be processed + //// Returns approximate winding number + //double winding_number_approx_simple( + // const Point & p, + // const double min_max_w); + // Print contents of Tree + // + // Optional input: + // tab tab to show depth + inline void print(const char * tab=""); + // Determine max absolute winding number + // + // Inputs: + // p query point + // Returns max winding number of + inline virtual typename DerivedV::Scalar max_abs_winding_number(const Point & p) const; + // Same as above, but stronger assumptions on (V,F). Assumes (V,F) is a + // simple polyhedron + inline virtual typename DerivedV::Scalar max_simple_abs_winding_number(const Point & p) const; + // Compute or read cached winding number for point p with respect to mesh + // in bounding box, recursing according to approximation criteria + // + // Inputs: + // p query point + // that WindingNumberTree containing mesh w.r.t. which we're computing w.n. + // Returns cached winding number + inline virtual typename DerivedV::Scalar cached_winding_number(const WindingNumberTree & that, const Point & p) const; + }; +} + +// Implementation + +#include "WindingNumberTree.h" +#include "winding_number.h" +#include "triangle_fan.h" +#include "exterior_edges.h" + +#include +#include + +#include +#include + +//template +//WindingNumberMethod WindingNumberTree::method = EXACT_WINDING_NUMBER_METHOD; +//template +//double WindingNumberTree::min_max_w = 0; +template +std::map< std::pair*,const igl::WindingNumberTree*>, typename DerivedV::Scalar> + igl::WindingNumberTree::cached; + +template +inline igl::WindingNumberTree::WindingNumberTree(): + method(EXACT_WINDING_NUMBER_METHOD), + parent(NULL), + V(dummyV), + SV(), + F(), + cap(), + radius(std::numeric_limits::infinity()), + center(0,0,0) +{ +} + +template +inline igl::WindingNumberTree::WindingNumberTree( + const Eigen::MatrixBase & _V, + const Eigen::MatrixBase & _F): + method(EXACT_WINDING_NUMBER_METHOD), + parent(NULL), + V(dummyV), + SV(), + F(), + cap(), + radius(std::numeric_limits::infinity()), + center(0,0,0) +{ + set_mesh(_V,_F); +} + +template +inline void igl::WindingNumberTree::set_mesh( + const Eigen::MatrixBase & _V, + const Eigen::MatrixBase & _F) +{ + using namespace std; + // Remove any exactly duplicate vertices + // Q: Can this ever increase the complexity of the boundary? + // Q: Would we gain even more by remove almost exactly duplicate vertices? + MatrixXF SF,SVI,SVJ; + igl::remove_duplicate_vertices(_V,_F,0.0,SV,SVI,SVJ,F); + triangle_fan(igl::exterior_edges(F),cap); + V = SV; +} + +template +inline igl::WindingNumberTree::WindingNumberTree( + const igl::WindingNumberTree & parent, + const Eigen::MatrixBase & _F): + method(parent.method), + parent(&parent), + V(parent.V), + SV(), + F(_F), + cap(triangle_fan(igl::exterior_edges(_F))) +{ +} + +template +inline igl::WindingNumberTree::~WindingNumberTree() +{ + delete_children(); +} + +template +inline void igl::WindingNumberTree::delete_children() +{ + using namespace std; + // Delete children + typename list* >::iterator cit = children.begin(); + while(cit != children.end()) + { + // clear the memory of this item + delete (* cit); + // erase from list, returns next element in iterator + cit = children.erase(cit); + } +} + +template +inline void igl::WindingNumberTree::set_method(const WindingNumberMethod & m) +{ + this->method = m; + for(auto child : children) + { + child->set_method(m); + } +} + +template +inline const DerivedV & igl::WindingNumberTree::getV() const +{ + return V; +} + +template +inline const typename igl::WindingNumberTree::MatrixXF& + igl::WindingNumberTree::getF() const +{ + return F; +} + +template +inline const typename igl::WindingNumberTree::MatrixXF& + igl::WindingNumberTree::getcap() const +{ + return cap; +} + +template +inline void igl::WindingNumberTree::grow() +{ + // Don't grow + return; +} + +template +inline bool igl::WindingNumberTree::inside(const Point & /*p*/) const +{ + return true; +} + +template +inline typename DerivedV::Scalar +igl::WindingNumberTree::winding_number(const Point & p) const +{ + using namespace std; + //cout<<"+"<0) + { + // Recurse on each child and accumulate + typename DerivedV::Scalar sum = 0; + for( + typename list* >::const_iterator cit = children.begin(); + cit != children.end(); + cit++) + { + switch(method) + { + case EXACT_WINDING_NUMBER_METHOD: + sum += (*cit)->winding_number(p); + break; + case APPROX_SIMPLE_WINDING_NUMBER_METHOD: + case APPROX_CACHE_WINDING_NUMBER_METHOD: + //if((*cit)->max_simple_abs_winding_number(p) > min_max_w) + //{ + sum += (*cit)->winding_number(p); + //} + break; + default: + assert(false); + break; + } + } + return sum; + }else + { + return winding_number_all(p); + } + }else{ + // Otherwise we can just consider boundary + // Q: If we using the "multipole" method should we also subdivide the + // boundary case? + if((cap.rows() - 2) < F.rows()) + { + switch(method) + { + case EXACT_WINDING_NUMBER_METHOD: + return winding_number_boundary(p); + case APPROX_SIMPLE_WINDING_NUMBER_METHOD: + { + typename DerivedV::Scalar dist = (p-center).norm(); + // Radius is already an overestimate of inside + if(dist>1.0*radius) + { + return 0; + }else + { + return winding_number_boundary(p); + } + } + case APPROX_CACHE_WINDING_NUMBER_METHOD: + { + return parent->cached_winding_number(*this,p); + } + default: assert(false);break; + } + }else + { + // doesn't pay off to use boundary + return winding_number_all(p); + } + } + return 0; +} + +template +inline typename DerivedV::Scalar + igl::WindingNumberTree::winding_number_all(const Point & p) const +{ + return igl::winding_number(V,F,p); +} + +template +inline typename DerivedV::Scalar +igl::WindingNumberTree::winding_number_boundary(const Point & p) const +{ + using namespace Eigen; + using namespace std; + return igl::winding_number(V,cap,p); +} + +//template +//inline double igl::WindingNumberTree::winding_number_approx_simple( +// const Point & p, +// const double min_max_w) +//{ +// using namespace std; +// if(max_simple_abs_winding_number(p) > min_max_w) +// { +// return winding_number(p); +// }else +// { +// cout<<"Skipped! "< +inline void igl::WindingNumberTree::print(const char * tab) +{ + using namespace std; + // Print all facets + cout<* >::iterator cit = children.begin(); + cit != children.end(); + cit++) + { + cout<<","<print((string(tab)+"").c_str()); + } +} + +template +inline typename DerivedV::Scalar +igl::WindingNumberTree::max_abs_winding_number(const Point & /*p*/) const +{ + return std::numeric_limits::infinity(); +} + +template +inline typename DerivedV::Scalar +igl::WindingNumberTree::max_simple_abs_winding_number( + const Point & /*p*/) const +{ + using namespace std; + return numeric_limits::infinity(); +} + +template +inline typename DerivedV::Scalar +igl::WindingNumberTree::cached_winding_number( + const igl::WindingNumberTree & that, + const Point & p) const +{ + using namespace std; + // Simple metric for `is_far` + // + // this that + // -------- + // ----- / | \ . + // / r \ / R \ . + // | p ! | | ! | + // \_____/ \ / + // \________/ + // + // + // a = angle formed by trapazoid formed by raising sides with lengths r and R + // at respective centers. + // + // a = atan2(R-r,d), where d is the distance between centers + + // That should be bigger (what about parent? what about sister?) + bool is_far = this->radiusradius, + (that.center - this->center).norm()); + assert(a>0); + is_far = (a this_that(this,&that); + // Need to compute it for first time? + if(cached.count(this_that)==0) + { + cached[this_that] = + that.winding_number_boundary(this->center); + } + return cached[this_that]; + }else if(children.size() == 0) + { + // not far and hierarchy ended too soon: can't use cache + return that.winding_number_boundary(p); + }else + { + for( + typename list* >::const_iterator cit = children.begin(); + cit != children.end(); + cit++) + { + if((*cit)->inside(p)) + { + return (*cit)->cached_winding_number(that,p); + } + } + // Not inside any children? This can totally happen because bounding boxes + // are set to bound contained facets. So sibilings may overlap and their + // union may not contain their parent (though, their union is certainly a + // subset of their parent). + assert(false); + } + return 0; +} + +// Explicit instantiation of static variable +template < + typename Point, + typename DerivedV, + typename DerivedF > +DerivedV igl::WindingNumberTree::dummyV; + +#endif diff --git a/vendor/libigl/include/igl/accumarray.cpp b/vendor/libigl/include/igl/accumarray.cpp new file mode 100644 index 0000000000000000000000000000000000000000..28d42cc7158713ac3bf07a22c4d2391933f13ade --- /dev/null +++ b/vendor/libigl/include/igl/accumarray.cpp @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "accumarray.h" +#include + +template < + typename DerivedS, + typename DerivedV, + typename DerivedA + > +void igl::accumarray( + const Eigen::MatrixBase & S, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & A) +{ + assert(V.size() == S.size() && "S and V should be same size"); + if(S.size() == 0) { A.resize(0,1); return; } + A.setZero(S.maxCoeff()+1,1); + for(int s = 0;s +void igl::accumarray( + const Eigen::MatrixBase & S, + const typename DerivedA::Scalar V, + Eigen::PlainObjectBase & A) +{ + if(S.size() == 0) { A.resize(0,1); return; } + A.setZero(S.maxCoeff()+1,1); + for(int s = 0;s, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&); +template void igl::accumarray, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/accumarray.h b/vendor/libigl/include/igl/accumarray.h new file mode 100644 index 0000000000000000000000000000000000000000..1afbddb7647e63577c358a8796caf591160dcdf4 --- /dev/null +++ b/vendor/libigl/include/igl/accumarray.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef ACCUMARRY_H +#define ACCUMARRY_H +#include "igl_inline.h" +#include +namespace igl +{ + // ACCUMARRY Like Matlab's accumarray. Accumulate values in V using subscripts + // in S. + // + // Inputs: + // S #S list of subscripts + // V #V list of values + // Outputs: + // A max(subs)+1 list of accumulated values + template < + typename DerivedS, + typename DerivedV, + typename DerivedA + > + void accumarray( + const Eigen::MatrixBase & S, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & A); + // Inputs: + // S #S list of subscripts + // V single value used for all + // Outputs: + // A max(subs)+1 list of accumulated values + template < + typename DerivedS, + typename DerivedA + > + void accumarray( + const Eigen::MatrixBase & S, + const typename DerivedA::Scalar V, + Eigen::PlainObjectBase & A); +} + +#ifndef IGL_STATIC_LIBRARY +# include "accumarray.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/active_set.cpp b/vendor/libigl/include/igl/active_set.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7112e8b166aaddde8dfa8c9985aad32bf7f2be8 --- /dev/null +++ b/vendor/libigl/include/igl/active_set.cpp @@ -0,0 +1,370 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "active_set.h" +#include "min_quad_with_fixed.h" +#include "slice.h" +#include "slice_into.h" +#include "cat.h" +//#include "matlab_format.h" + +#include +#include +#include + +template < + typename AT, + typename DerivedB, + typename Derivedknown, + typename DerivedY, + typename AeqT, + typename DerivedBeq, + typename AieqT, + typename DerivedBieq, + typename Derivedlx, + typename Derivedux, + typename DerivedZ + > +IGL_INLINE igl::SolverStatus igl::active_set( + const Eigen::SparseMatrix& A, + const Eigen::PlainObjectBase & B, + const Eigen::PlainObjectBase & known, + const Eigen::PlainObjectBase & Y, + const Eigen::SparseMatrix& Aeq, + const Eigen::PlainObjectBase & Beq, + const Eigen::SparseMatrix& Aieq, + const Eigen::PlainObjectBase & Bieq, + const Eigen::PlainObjectBase & p_lx, + const Eigen::PlainObjectBase & p_ux, + const igl::active_set_params & params, + Eigen::PlainObjectBase & Z + ) +{ +//#define ACTIVE_SET_CPP_DEBUG +#if defined(ACTIVE_SET_CPP_DEBUG) && !defined(_MSC_VER) +# warning "ACTIVE_SET_CPP_DEBUG" +#endif + using namespace Eigen; + using namespace std; + SolverStatus ret = SOLVER_STATUS_ERROR; + const int n = A.rows(); + assert(n == A.cols() && "A must be square"); + // Discard const qualifiers + //if(B.size() == 0) + //{ + // B = DerivedB::Zero(n,1); + //} + assert(n == B.rows() && "B.rows() must match A.rows()"); + assert(B.cols() == 1 && "B must be a column vector"); + assert(Y.cols() == 1 && "Y must be a column vector"); + assert((Aeq.size() == 0 && Beq.size() == 0) || Aeq.cols() == n); + assert((Aeq.size() == 0 && Beq.size() == 0) || Aeq.rows() == Beq.rows()); + assert((Aeq.size() == 0 && Beq.size() == 0) || Beq.cols() == 1); + assert((Aieq.size() == 0 && Bieq.size() == 0) || Aieq.cols() == n); + assert((Aieq.size() == 0 && Bieq.size() == 0) || Aieq.rows() == Bieq.rows()); + assert((Aieq.size() == 0 && Bieq.size() == 0) || Bieq.cols() == 1); + Eigen::Matrix lx; + Eigen::Matrix ux; + if(p_lx.size() == 0) + { + lx = Derivedlx::Constant( + n,1,-numeric_limits::max()); + }else + { + lx = p_lx; + } + if(p_ux.size() == 0) + { + ux = Derivedux::Constant( + n,1,numeric_limits::max()); + }else + { + ux = p_ux; + } + assert(lx.rows() == n && "lx must have n rows"); + assert(ux.rows() == n && "ux must have n rows"); + assert(ux.cols() == 1 && "lx must be a column vector"); + assert(lx.cols() == 1 && "ux must be a column vector"); + assert((ux.array()-lx.array()).minCoeff() > 0 && "ux(i) must be > lx(i)"); + if(Z.size() != 0) + { + // Initial guess should have correct size + assert(Z.rows() == n && "Z must have n rows"); + assert(Z.cols() == 1 && "Z must be a column vector"); + } + assert(known.cols() == 1 && "known must be a column vector"); + // Number of knowns + const int nk = known.size(); + + // Initialize active sets + typedef int BOOL; +#define TRUE 1 +#define FALSE 0 + Matrix as_lx = Matrix::Constant(n,1,FALSE); + Matrix as_ux = Matrix::Constant(n,1,FALSE); + Matrix as_ieq = Matrix::Constant(Aieq.rows(),1,FALSE); + + // Keep track of previous Z for comparison + DerivedZ old_Z; + old_Z = DerivedZ::Constant( + n,1,numeric_limits::max()); + + int iter = 0; + while(true) + { +#ifdef ACTIVE_SET_CPP_DEBUG + cout<<"Iteration: "< 0) + { + for(int z = 0;z < n;z++) + { + if(Z(z) < lx(z)) + { + new_as_lx += (as_lx(z)?0:1); + //new_as_lx++; + as_lx(z) = TRUE; + } + if(Z(z) > ux(z)) + { + new_as_ux += (as_ux(z)?0:1); + //new_as_ux++; + as_ux(z) = TRUE; + } + } + if(Aieq.rows() > 0) + { + DerivedZ AieqZ; + AieqZ = Aieq*Z; + for(int a = 0;a Bieq(a)) + { + new_as_ieq += (as_ieq(a)?0:1); + as_ieq(a) = TRUE; + } + } + } +#ifdef ACTIVE_SET_CPP_DEBUG + cout<<" new_as_lx: "< as_ieq_list(as_ieq_count,1); + // Gather active constraints and resp. rhss + DerivedBeq Beq_i; + Beq_i.resize(Beq.rows()+as_ieq_count,1); + Beq_i.head(Beq.rows()) = Beq; + { + int k =0; + for(int a=0;a Aeq_i,Aieq_i; + slice(Aieq,as_ieq_list,1,Aieq_i); + // Append to equality constraints + cat(1,Aeq,Aieq_i,Aeq_i); + + + min_quad_with_fixed_data data; +#ifndef NDEBUG + { + // NO DUPES! + Matrix fixed = Matrix::Constant(n,1,FALSE); + for(int k = 0;k 0 && Aeq_i.rows() > Aeq.rows()) + { + cerr<<" *Are you sure rows of [Aeq;Aieq] are linearly independent?*"<< + endl; + } + ret = SOLVER_STATUS_ERROR; + break; + } +#ifdef ACTIVE_SET_CPP_DEBUG + cout<<" min_quad_with_fixed_solve"< Ak; + // Slow + slice(A,known_i,1,Ak); + DerivedB Bk; + slice(B,known_i,Bk); + MatrixXd Lambda_known_i = -(0.5*Ak*Z + 0.5*Bk); + // reverse the lambda values for lx + Lambda_known_i.block(nk,0,as_lx_count,1) = + (-1*Lambda_known_i.block(nk,0,as_lx_count,1)).eval(); + + // Extract Lagrange multipliers for Aieq_i (always at back of sol) + VectorXd Lambda_Aieq_i(Aieq_i.rows(),1); + for(int l = 0;l0 && iter>=params.max_iter) + { + ret = SOLVER_STATUS_MAX_ITER; + break; + } + + } + + return ret; +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template igl::SolverStatus igl::active_set, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::SparseMatrix const&, Eigen::PlainObjectBase > const&, Eigen::SparseMatrix const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, igl::active_set_params const&, Eigen::PlainObjectBase >&); +template igl::SolverStatus igl::active_set, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::SparseMatrix const&, Eigen::PlainObjectBase > const&, Eigen::SparseMatrix const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, igl::active_set_params const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/adjacency_list.cpp b/vendor/libigl/include/igl/adjacency_list.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa6579e3bc7462678b1d8fe89da7f5b8aa5925f9 --- /dev/null +++ b/vendor/libigl/include/igl/adjacency_list.cpp @@ -0,0 +1,180 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "adjacency_list.h" + +#include "verbose.h" +#include + +template +IGL_INLINE void igl::adjacency_list( + const Eigen::MatrixBase & F, + std::vector >& A, + bool sorted) +{ + A.clear(); + A.resize(F.maxCoeff()+1); + + // Loop over faces + for(int i = 0;i d + int s = F(i,j); + int d = F(i,(j+1)%F.cols()); + A.at(s).push_back(d); + A.at(d).push_back(s); + } + } + + // Remove duplicates + for(int i=0; i<(int)A.size();++i) + { + std::sort(A[i].begin(), A[i].end()); + A[i].erase(std::unique(A[i].begin(), A[i].end()), A[i].end()); + } + + // If needed, sort every VV + if (sorted) + { + // Loop over faces + + // for every vertex v store a set of ordered edges not incident to v that belongs to triangle incident on v. + std::vector > > SR; + SR.resize(A.size()); + + for(int i = 0;i d + int s = F(i,j); + int d = F(i,(j+1)%F.cols()); + // Get index of opposing vertex v + int v = F(i,(j+2)%F.cols()); + + std::vector e(2); + e[0] = d; + e[1] = v; + SR[s].push_back(e); + } + } + + for(int v=0; v<(int)SR.size();++v) + { + std::vector& vv = A.at(v); + std::vector >& sr = SR[v]; + + std::vector > pn = sr; + + // Compute previous/next for every element in sr + for(int i=0;i<(int)sr.size();++i) + { + int a = sr[i][0]; + int b = sr[i][1]; + + // search for previous + int p = -1; + for(int j=0;j<(int)sr.size();++j) + if(sr[j][1] == a) + p = j; + pn[i][0] = p; + + // search for next + int n = -1; + for(int j=0;j<(int)sr.size();++j) + if(sr[j][0] == b) + n = j; + pn[i][1] = n; + + } + + // assume manifoldness (look for beginning of a single chain) + int c = 0; + for(int j=0; j<=(int)sr.size();++j) + if (pn[c][0] != -1) + c = pn[c][0]; + + if (pn[c][0] == -1) // border case + { + // finally produce the new vv relation + for(int j=0; j<(int)sr.size();++j) + { + vv[j] = sr[c][0]; + if (pn[c][1] != -1) + c = pn[c][1]; + } + vv.back() = sr[c][1]; + } + else + { + // finally produce the new vv relation + for(int j=0; j<(int)sr.size();++j) + { + vv[j] = sr[c][0]; + + c = pn[c][1]; + } + } + } + } +} + +template +IGL_INLINE void igl::adjacency_list( + const std::vector > & F, + std::vector >& A) +{ + A.clear(); + + // Find maxCoeff + Index maxCoeff = 0; + for(const auto &vec : F) + { + for(int coeff : vec) + { + maxCoeff = std::max(coeff, maxCoeff); + } + } + A.resize(maxCoeff + 1); + + // Loop over faces + for(int i = 0;i d + int s = F[i][j]; + int d = F[i][(j+1)%F[i].size()]; + A.at(s).push_back(d); + A.at(d).push_back(s); + } + } + + // Remove duplicates + for(int i=0; i<(int)A.size();++i) + { + std::sort(A[i].begin(), A[i].end()); + A[i].erase(std::unique(A[i].begin(), A[i].end()), A[i].end()); + } + +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::adjacency_list, int>(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, bool); +// generated by autoexplicit.sh +template void igl::adjacency_list, int>(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, bool); +template void igl::adjacency_list, int>(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, bool); +template void igl::adjacency_list, unsigned int>(class Eigen::MatrixBase > const &, class std::vector >, class std::allocator > > > &, bool); +template void igl::adjacency_list(std::vector >, std::allocator > > > const&, std::vector >, std::allocator > > >&); +#endif diff --git a/vendor/libigl/include/igl/adjacency_list.h b/vendor/libigl/include/igl/adjacency_list.h new file mode 100644 index 0000000000000000000000000000000000000000..e9040da8b1f17fe33375e78156c0c0114408132e --- /dev/null +++ b/vendor/libigl/include/igl/adjacency_list.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ADJACENCY_LIST_H +#define IGL_ADJACENCY_LIST_H +#include "igl_inline.h" + +#include +#include +#include +namespace igl +{ + // Constructs the graph adjacency list of a given mesh (V,F) + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Inputs: + // F #F by dim list of mesh faces (must be triangles) + // sorted flag that indicates if the list should be sorted counter-clockwise + // Outputs: + // A vector > containing at row i the adjacent vertices of vertex i + // + // Example: + // // Mesh in (V,F) + // vector > A; + // adjacency_list(F,A); + // + // See also: edges, cotmatrix, diag + template + IGL_INLINE void adjacency_list( + const Eigen::MatrixBase & F, + std::vector >& A, + bool sorted = false); + + // Variant that accepts polygonal faces. + // Each element of F is a set of indices of a polygonal face. + template + IGL_INLINE void adjacency_list( + const std::vector > & F, + std::vector >& A); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "adjacency_list.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/adjacency_matrix.cpp b/vendor/libigl/include/igl/adjacency_matrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b4fae32b5bdd4ed9c303175fd89f55d7112b105 --- /dev/null +++ b/vendor/libigl/include/igl/adjacency_matrix.cpp @@ -0,0 +1,125 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "adjacency_matrix.h" + +#include "verbose.h" + +#include + +template +IGL_INLINE void igl::adjacency_matrix( + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& A) +{ + using namespace std; + using namespace Eigen; + typedef typename DerivedF::Scalar Index; + + typedef Triplet IJV; + vector ijv; + ijv.reserve(F.size()*2); + // Loop over **simplex** (i.e., **not quad**) + for(int i = 0;i d + Index s = F(i,j); + Index d = F(i,k); + ijv.push_back(IJV(s,d,1)); + ijv.push_back(IJV(d,s,1)); + } + } + + const Index n = F.maxCoeff()+1; + A.resize(n,n); + switch(F.cols()) + { + case 3: + A.reserve(6*(F.maxCoeff()+1)); + break; + case 4: + A.reserve(26*(F.maxCoeff()+1)); + break; + } + A.setFromTriplets(ijv.begin(),ijv.end()); + + // Force all non-zeros to be one + + // Iterate over outside + for(int k=0; k::InnerIterator it (A,k); it; ++it) + { + assert(it.value() != 0); + A.coeffRef(it.row(),it.col()) = 1; + } + } +} + +template +IGL_INLINE void igl::adjacency_matrix( + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::SparseMatrix& A) +{ + using namespace std; + using namespace Eigen; + + typedef Triplet IJV; + vector ijv; + ijv.reserve(C(C.size()-1)*2); + typedef typename DerivedI::Scalar Index; + const Index n = I.maxCoeff()+1; + { + // loop over polygons + for(Index p = 0;p::InnerIterator it (A,k); it; ++it) + { + assert(it.value() != 0); + A.coeffRef(it.row(),it.col()) = 1; + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::adjacency_matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix& ); +// generated by autoexplicit.sh +template void igl::adjacency_matrix, bool>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::adjacency_matrix, double>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::adjacency_matrix, int>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::adjacency_matrix, int>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/adjacency_matrix.h b/vendor/libigl/include/igl/adjacency_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..79aa976e47c3a2736d961999654ebf73d613fe85 --- /dev/null +++ b/vendor/libigl/include/igl/adjacency_matrix.h @@ -0,0 +1,66 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ADJACENCY_MATRIX_H +#define IGL_ADJACENCY_MATRIX_H +#include "igl_inline.h" + +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include + +namespace igl +{ + // Constructs the graph adjacency matrix of a given mesh (V,F) + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Inputs: + // F #F by dim list of mesh simplices + // Outputs: + // A max(F)+1 by max(F)+1 adjacency matrix, each row i corresponding to V(i,:) + // + // Example: + // // Mesh in (V,F) + // Eigen::SparseMatrix A; + // adjacency_matrix(F,A); + // // sum each row + // SparseVector Asum; + // sum(A,1,Asum); + // // Convert row sums into diagonal of sparse matrix + // SparseMatrix Adiag; + // diag(Asum,Adiag); + // // Build uniform laplacian + // SparseMatrix U; + // U = A-Adiag; + // + // See also: edges, cotmatrix, diag + template + IGL_INLINE void adjacency_matrix( + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& A); + // Constructs an vertex adjacency for a polygon mesh. + // + // Inputs: + // I #I vectorized list of polygon corner indices into rows of some matrix V + // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = + // size of the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the + // indices of the ith polygon + // Outputs: + // A max(I)+1 by max(I)+1 adjacency matrix, each row i corresponding to V(i,:) + // + template + IGL_INLINE void adjacency_matrix( + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::SparseMatrix& A); +} + +#ifndef IGL_STATIC_LIBRARY +# include "adjacency_matrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/all.cpp b/vendor/libigl/include/igl/all.cpp new file mode 100644 index 0000000000000000000000000000000000000000..35245eacbe2d80b10e1c03d586416de0ca6ae280 --- /dev/null +++ b/vendor/libigl/include/igl/all.cpp @@ -0,0 +1,26 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "all.h" +#include "redux.h" + + +template +IGL_INLINE void igl::all( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase& B) +{ + typedef typename DerivedB::Scalar Scalar; + igl::redux(A,dim,[](Scalar a, Scalar b){ return a && b!=0;},B); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif + + diff --git a/vendor/libigl/include/igl/all.h b/vendor/libigl/include/igl/all.h new file mode 100644 index 0000000000000000000000000000000000000000..6e84fdd52f37cd05992ed10816ee0b914eaa907a --- /dev/null +++ b/vendor/libigl/include/igl/all.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ALL_H +#define IGL_ALL_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // For Dense matrices use: A.rowwise().all() or A.colwise().all() + // + // Inputs: + // A m by n sparse matrix + // dim dimension along which to check for all (1 or 2) + // Output: + // B n-long vector (if dim == 1) + // or + // B m-long vector (if dim == 2) + // + template + IGL_INLINE void all( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase& B); +} +#ifndef IGL_STATIC_LIBRARY +# include "all.cpp" +#endif +#endif + + diff --git a/vendor/libigl/include/igl/all_pairs_distances.cpp b/vendor/libigl/include/igl/all_pairs_distances.cpp new file mode 100644 index 0000000000000000000000000000000000000000..608cf9b85773608c84336675b7d34ba16c6771f7 --- /dev/null +++ b/vendor/libigl/include/igl/all_pairs_distances.cpp @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "all_pairs_distances.h" +#include + +template +IGL_INLINE void igl::all_pairs_distances( + const Mat & V, + const Mat & U, + const bool squared, + Mat & D) +{ + // dimension should be the same + assert(V.cols() == U.cols()); + // resize output + D.resize(V.rows(),U.rows()); + for(int i = 0;i >(Eigen::Matrix const&, Eigen::Matrix const&, bool, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/all_pairs_distances.h b/vendor/libigl/include/igl/all_pairs_distances.h new file mode 100644 index 0000000000000000000000000000000000000000..9acc1b73075f6e94dea5f276742415f2b809d55a --- /dev/null +++ b/vendor/libigl/include/igl/all_pairs_distances.h @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ALL_PAIRS_DISTANCES_H +#define IGL_ALL_PAIRS_DISTANCES_H +#include "igl_inline.h" + +namespace igl +{ + // ALL_PAIRS_DISTANCES compute distances between each point i in V and point j + // in U + // + // D = all_pairs_distances(V,U) + // + // Templates: + // Mat matrix class like MatrixXd + // Inputs: + // V #V by dim list of points + // U #U by dim list of points + // squared whether to return squared distances + // Outputs: + // D #V by #U matrix of distances, where D(i,j) gives the distance or + // squareed distance between V(i,:) and U(j,:) + // + template + IGL_INLINE void all_pairs_distances( + const Mat & V, + const Mat & U, + const bool squared, + Mat & D); +} + +#ifndef IGL_STATIC_LIBRARY +# include "all_pairs_distances.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/ambient_occlusion.cpp b/vendor/libigl/include/igl/ambient_occlusion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b72319e065dd1b4286f6aa05936ba8ecd47dc91 --- /dev/null +++ b/vendor/libigl/include/igl/ambient_occlusion.cpp @@ -0,0 +1,139 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ambient_occlusion.h" +#include "random_dir.h" +#include "ray_mesh_intersect.h" +#include "EPS.h" +#include "Hit.h" +#include "parallel_for.h" +#include +#include +#include + +template < + typename DerivedP, + typename DerivedN, + typename DerivedS > +IGL_INLINE void igl::ambient_occlusion( + const std::function< + bool( + const Eigen::Vector3f&, + const Eigen::Vector3f&) + > & shoot_ray, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + using namespace Eigen; + const int n = P.rows(); + // Resize output + S.resize(n,1); + // Embree seems to be parallel when constructing but not when tracing rays + const MatrixXf D = random_dir_stratified(num_samples).cast(); + + const auto & inner = [&P,&N,&num_samples,&D,&S,&shoot_ray](const int p) + { + const Vector3f origin = P.row(p).template cast(); + const Vector3f normal = N.row(p).template cast(); + int num_hits = 0; + for(int s = 0;s +IGL_INLINE void igl::ambient_occlusion( + const igl::AABB & aabb, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + const auto & shoot_ray = [&aabb,&V,&F]( + const Eigen::Vector3f& _s, + const Eigen::Vector3f& dir)->bool + { + Eigen::Vector3f s = _s+1e-4*dir; + igl::Hit hit; + return aabb.intersect_ray( + V, + F, + s .cast().eval(), + dir.cast().eval(), + hit); + }; + return ambient_occlusion(shoot_ray,P,N,num_samples,S); + +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > +IGL_INLINE void igl::ambient_occlusion( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + if(F.rows() < 100) + { + // Super naive + const auto & shoot_ray = [&V,&F]( + const Eigen::Vector3f& _s, + const Eigen::Vector3f& dir)->bool + { + Eigen::Vector3f s = _s+1e-4*dir; + igl::Hit hit; + return ray_mesh_intersect(s,dir,V,F,hit); + }; + return ambient_occlusion(shoot_ray,P,N,num_samples,S); + } + AABB aabb; + aabb.init(V,F); + return ambient_occlusion(aabb,V,F,P,N,num_samples,S); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::ambient_occlusion, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/ambient_occlusion.h b/vendor/libigl/include/igl/ambient_occlusion.h new file mode 100644 index 0000000000000000000000000000000000000000..5e67ff598bfb9d570a115dc0c6c7cd3e3502a7a1 --- /dev/null +++ b/vendor/libigl/include/igl/ambient_occlusion.h @@ -0,0 +1,80 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_AMBIENT_OCCLUSION_H +#define IGL_AMBIENT_OCCLUSION_H +#include "igl_inline.h" +#include "AABB.h" +#include +#include +namespace igl +{ + // Compute ambient occlusion per given point + // + // Inputs: + // shoot_ray function handle that outputs hits of a given ray against a + // mesh (embedded in function handles as captured variable/data) + // P #P by 3 list of origin points + // N #P by 3 list of origin normals + // Outputs: + // S #P list of ambient occlusion values between 1 (fully occluded) and + // 0 (not occluded) + // + template < + typename DerivedP, + typename DerivedN, + typename DerivedS > + IGL_INLINE void ambient_occlusion( + const std::function< + bool( + const Eigen::Vector3f&, + const Eigen::Vector3f&) + > & shoot_ray, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S); + // Inputs: + // AABB axis-aligned bounding box hierarchy around (V,F) + template < + typename DerivedV, + int DIM, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > + IGL_INLINE void ambient_occlusion( + const igl::AABB & aabb, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S); + // Inputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh face indices into V + template < + typename DerivedV, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > + IGL_INLINE void ambient_occlusion( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S); + +}; +#ifndef IGL_STATIC_LIBRARY +# include "ambient_occlusion.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/angular_distance.cpp b/vendor/libigl/include/igl/angular_distance.cpp new file mode 100644 index 0000000000000000000000000000000000000000..803c290c973e831002fdd2d9d4282161c157377a --- /dev/null +++ b/vendor/libigl/include/igl/angular_distance.cpp @@ -0,0 +1,20 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "angular_distance.h" +#include +#include +IGL_INLINE double igl::angular_distance( + const Eigen::Quaterniond & A, + const Eigen::Quaterniond & B) +{ + assert(fabs(A.norm()-1) +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ANGULAR_DISTANCE_H +#define IGL_ANGULAR_DISTANCE_H +#include "igl_inline.h" +#include +namespace igl +{ + // The "angular distance" between two unit quaternions is the angle of the + // smallest rotation (treated as an Axis and Angle) that takes A to B. + // + // Inputs: + // A unit quaternion + // B unit quaternion + // Returns angular distance + IGL_INLINE double angular_distance( + const Eigen::Quaterniond & A, + const Eigen::Quaterniond & B); +} + +#ifndef IGL_STATIC_LIBRARY +#include "angular_distance.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/any.h b/vendor/libigl/include/igl/any.h new file mode 100644 index 0000000000000000000000000000000000000000..08a80e4cb7c575e9b97a9f127cdb63ff9827442e --- /dev/null +++ b/vendor/libigl/include/igl/any.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ANY_H +#define IGL_ANY_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // For Dense matrices use: A.rowwise().any() or A.colwise().any() + // + // Inputs: + // A m by n sparse matrix + // dim dimension along which to check for any (1 or 2) + // Output: + // B n-long vector (if dim == 1) + // or + // B m-long vector (if dim == 2) + // + template + IGL_INLINE void any( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase& B); +} +#ifndef IGL_STATIC_LIBRARY +# include "any.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/any_of.cpp b/vendor/libigl/include/igl/any_of.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9defd03395767faa9d3fcb2d2bb3284b3818d749 --- /dev/null +++ b/vendor/libigl/include/igl/any_of.cpp @@ -0,0 +1,20 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "any_of.h" +#include +template +IGL_INLINE bool igl::any_of(const Mat & S) +{ + return std::any_of(S.data(),S.data()+S.size(),[](bool s){return s;}); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template bool igl::any_of >(Eigen::Matrix const&); +#endif + diff --git a/vendor/libigl/include/igl/any_of.h b/vendor/libigl/include/igl/any_of.h new file mode 100644 index 0000000000000000000000000000000000000000..95ec1d373eff70102ca340be00afb641221e7a61 --- /dev/null +++ b/vendor/libigl/include/igl/any_of.h @@ -0,0 +1,26 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ANY_OF_H +#define IGL_ANY_OF_H +#include "igl_inline.h" +namespace igl +{ + // Wrapper for STL `any_of` for matrix types + // + // Inputs: + // S matrix + // Returns whether any entries are true + // + // Seems that Eigen (now) implements this for `Eigen::Array` + template + IGL_INLINE bool any_of(const Mat & S); +} +#ifndef IGL_STATIC_LIBRARY +# include "any_of.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/arap_dof.cpp b/vendor/libigl/include/igl/arap_dof.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eaf2ea71f668d064e9a36b83b923c69c8d54bc2b --- /dev/null +++ b/vendor/libigl/include/igl/arap_dof.cpp @@ -0,0 +1,884 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "arap_dof.h" + +#include "cotmatrix.h" +#include "massmatrix.h" +#include "speye.h" +#include "repdiag.h" +#include "repmat.h" +#include "slice.h" +#include "colon.h" +#include "is_sparse.h" +#include "mode.h" +#include "is_symmetric.h" +#include "group_sum_matrix.h" +#include "arap_rhs.h" +#include "covariance_scatter_matrix.h" +#include "fit_rotations.h" + +#include "verbose.h" +#include "print_ijv.h" + +#include "get_seconds_hires.h" +//#include "MKLEigenInterface.h" +#include "kkt_inverse.h" +#include "get_seconds.h" +#include "columnize.h" + +// defined if no early exit is supported, i.e., always take a fixed number of iterations +#define IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT + +// A careful derivation of this implementation is given in the corresponding +// matlab function arap_dof.m +template +IGL_INLINE bool igl::arap_dof_precomputation( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const LbsMatrixType & M, + const Eigen::Matrix & G, + ArapDOFData & data) +{ + using namespace Eigen; + typedef Matrix MatrixXS; + // number of mesh (domain) vertices + int n = V.rows(); + // cache problem size + data.n = n; + // dimension of mesh + data.dim = V.cols(); + assert(data.dim == M.rows()/n); + assert(data.dim*n == M.rows()); + if(data.dim == 3) + { + // Check if z-coordinate is all zeros + if(V.col(2).minCoeff() == 0 && V.col(2).maxCoeff() == 0) + { + data.effective_dim = 2; + } + }else + { + data.effective_dim = data.dim; + } + // Number of handles + data.m = M.cols()/data.dim/(data.dim+1); + assert(data.m*data.dim*(data.dim+1) == M.cols()); + //assert(m == C.rows()); + + //printf("n=%d; dim=%d; m=%d;\n",n,data.dim,data.m); + + // Build cotangent laplacian + SparseMatrix Lcot; + //printf("cotmatrix()\n"); + cotmatrix(V,F,Lcot); + // Discrete laplacian (should be minus matlab version) + SparseMatrix Lapl = -2.0*Lcot; +#ifdef EXTREME_VERBOSE + cout<<"LaplIJV=["< G_sum; + if(G.size() == 0) + { + speye(n,G_sum); + }else + { + // groups are defined per vertex, convert to per face using mode + Eigen::Matrix GG; + if(data.energy == ARAP_ENERGY_TYPE_ELEMENTS) + { + MatrixXi GF(F.rows(),F.cols()); + for(int j = 0;j GFj; + slice(G,F.col(j),GFj); + GF.col(j) = GFj; + } + mode(GF,2,GG); + }else + { + GG=G; + } + //printf("group_sum_matrix()\n"); + group_sum_matrix(GG,G_sum); + } + +#ifdef EXTREME_VERBOSE + cout<<"G_sumIJV=["< CSM; + //printf("covariance_scatter_matrix()\n"); + covariance_scatter_matrix(V,F,data.energy,CSM); +#ifdef EXTREME_VERBOSE + cout<<"CSMIJV=["< G_sum_dim; + repdiag(G_sum,data.dim,G_sum_dim); + CSM = (G_sum_dim * CSM).eval(); +#ifdef EXTREME_VERBOSE + cout<<"CSMIJV=["< span_n(n); + for(int i = 0;i span_mlbs_cols(M.cols()); + for(int i = 0;i CSMj; + //printf("CSM_M(): slice\n"); + slice( + CSM, + colon(j*k,(j+1)*k-1), + colon(j*n,(j+1)*n-1), + CSMj); + assert(CSMj.rows() == k); + assert(CSMj.cols() == n); + LbsMatrixType CSMjM_i = CSMj * M_i; + if(is_sparse(CSMjM_i)) + { + // Convert to full + //printf("CSM_M(): full\n"); + MatrixXd CSMjM_ifull(CSMjM_i); +// printf("CSM_M[%d]: %d %d\n",i,data.CSM_M[i].rows(),data.CSM_M[i].cols()); +// printf("CSM_M[%d].block(%d*%d=%d,0,%d,%d): %d %d\n",i,j,k,CSMjM_i.rows(),CSMjM_i.cols(), +// data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()).rows(), +// data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()).cols()); +// printf("CSM_MjMi: %d %d\n",i,CSMjM_i.rows(),CSMjM_i.cols()); +// printf("CSM_MjM_ifull: %d %d\n",i,CSMjM_ifull.rows(),CSMjM_ifull.cols()); + data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()) = CSMjM_ifull; + }else + { + data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()) = CSMjM_i; + } + } +#ifdef EXTREME_VERBOSE + cout<<"CSM_Mi=["< K; + arap_rhs(V,F,V.cols(),data.energy,K); +//#ifdef EXTREME_VERBOSE +// cout<<"KIJV=["< G_sumT = G_sum.transpose(); + SparseMatrix G_sumT_dim_dim; + repdiag(G_sumT,data.dim*data.dim,G_sumT_dim_dim); + LbsMatrixType MT = M.transpose(); + // If this is a bottle neck then consider reordering matrix multiplication + data.M_KG = -4.0 * (MT * (K * G_sumT_dim_dim)); +//#ifdef EXTREME_VERBOSE +// cout<<"data.M_KGIJV=["< A; + repdiag(Lapl,data.dim,A); + data.Q = MT * (A * M); +//#ifdef EXTREME_VERBOSE +// cout<<"QIJV=["< Mass; + //printf("massmatrix()\n"); + massmatrix(V,F,(F.cols()>3?MASSMATRIX_TYPE_BARYCENTRIC:MASSMATRIX_TYPE_VORONOI),Mass); + //cout<<"MIJV=["< Mass_rep; + repdiag(Mass,data.dim,Mass_rep); + + // Multiply either side by weights matrix (should be dense) + data.Mass_tilde = MT * Mass_rep * M; + MatrixXd ones(data.dim*data.n,data.dim); + for(int i = 0;i + inline static SSCALAR maxBlokErr(const Eigen::Matrix3f &blok) + { + SSCALAR mD; + SSCALAR value = blok(0,0); + SSCALAR diff1 = fabs(blok(1,1) - value); + SSCALAR diff2 = fabs(blok(2,2) - value); + if (diff1 > diff2) mD = diff1; + else mD = diff2; + + for (int v=0; v<3; v++) + { + for (int w=0; w<3; w++) + { + if (v == w) + { + continue; + } + if (mD < fabs(blok(v, w))) + { + mD = fabs(blok(v, w)); + } + } + } + + return mD; + } + + // converts CSM_M_SSCALAR[0], CSM_M_SSCALAR[1], CSM_M_SSCALAR[2] into one + // "condensed" matrix CSM while checking we're not losing any information by + // this process; specifically, returns maximal difference from scaled 3x3 + // identity blocks, which should be pretty small number + template + static typename MatrixXS::Scalar condense_CSM( + const std::vector &CSM_M_SSCALAR, + int numBones, + int dim, + MatrixXS &CSM) + { + const int numRows = CSM_M_SSCALAR[0].rows(); + assert(CSM_M_SSCALAR[0].cols() == dim*(dim+1)*numBones); + assert(CSM_M_SSCALAR[1].cols() == dim*(dim+1)*numBones); + assert(CSM_M_SSCALAR[2].cols() == dim*(dim+1)*numBones); + assert(CSM_M_SSCALAR[1].rows() == numRows); + assert(CSM_M_SSCALAR[2].rows() == numRows); + + const int numCols = (dim + 1)*numBones; + CSM.resize(numRows, numCols); + + typedef typename MatrixXS::Scalar SSCALAR; + SSCALAR maxDiff = 0.0f; + + for (int r=0; r(blok); + if (mD > maxDiff) maxDiff = mD; + + // use the first value: + CSM(r, coord*numBones + b) = blok(0,0); + } + } + } + + return maxDiff; + } + + // splits x_0, ... , x_dim coordinates in column vector 'L' into a numBones*(dimp1) x dim matrix 'Lsep'; + // assumes 'Lsep' has already been preallocated + // + // is this the same as uncolumnize? no. + template + static void splitColumns( + const MatL &L, + int numBones, + int dim, + int dimp1, + MatLsep &Lsep) + { + assert(L.cols() == 1); + assert(L.rows() == dim*(dimp1)*numBones); + + assert(Lsep.rows() == (dimp1)*numBones && Lsep.cols() == dim); + + for (int b=0; b + static void mergeColumns(const MatrixXS &Lsep, int numBones, int dim, int dimp1, MatrixXS &L) + { + assert(L.cols() == 1); + assert(L.rows() == dim*(dimp1)*numBones); + + assert(Lsep.rows() == (dimp1)*numBones && Lsep.cols() == dim); + + for (int b=0; b + static typename MatrixXS::Scalar condense_Solve1(MatrixXS &Solve1, int numBones, int numGroups, int dim, MatrixXS &CSolve1) + { + assert(Solve1.rows() == dim*(dim + 1)*numBones); + assert(Solve1.cols() == dim*dim*numGroups); + + typedef typename MatrixXS::Scalar SSCALAR; + SSCALAR maxDiff = 0.0f; + + CSolve1.resize((dim + 1)*numBones, dim*numGroups); + for (int rowCoord=0; rowCoord(blok); + if (mD > maxDiff) maxDiff = mD; + + CSolve1(rowCoord*numBones + b, colCoord*numGroups + g) = blok(0,0); + } + } + } + } + + return maxDiff; + } +} + +template +IGL_INLINE bool igl::arap_dof_recomputation( + const Eigen::Matrix & fixed_dim, + const Eigen::SparseMatrix & A_eq, + ArapDOFData & data) +{ + using namespace Eigen; + typedef Matrix MatrixXS; + + LbsMatrixType * Q; + LbsMatrixType Qdyn; + if(data.with_dynamics) + { + // multiply by 1/timestep and to quadratic coefficients matrix + // Might be missing a 0.5 here + LbsMatrixType Q_copy = data.Q; + Qdyn = Q_copy + (1.0/(data.h*data.h))*data.Mass_tilde; + Q = &Qdyn; + + // This may/should be superfluous + //printf("is_symmetric()\n"); + if(!is_symmetric(*Q)) + { + //printf("Fixing symmetry...\n"); + // "Fix" symmetry + LbsMatrixType QT = (*Q).transpose(); + LbsMatrixType Q_copy = *Q; + *Q = 0.5*(Q_copy+QT); + // Check that ^^^ this really worked. It doesn't always + //assert(is_symmetric(*Q)); + } + }else + { + Q = &data.Q; + } + + assert((int)data.CSM_M.size() == data.dim); + assert(A_eq.cols() == data.m*data.dim*(data.dim+1)); + data.fixed_dim = fixed_dim; + + if(fixed_dim.size() > 0) + { + assert(fixed_dim.maxCoeff() < data.m*data.dim*(data.dim+1)); + assert(fixed_dim.minCoeff() >= 0); + } + +#ifdef EXTREME_VERBOSE + cout<<"data.fixed_dim=["<(), + M_Solve.block(0, fsRows, fsRows, fsCols2).template cast(); + + if(data.with_dynamics) + { + printf( + "---------------------------------------------------------------------\n" + "\n\n\nWITH DYNAMICS recomputation\n\n\n" + "---------------------------------------------------------------------\n" + ); + // Also need to save Π1 before it gets multiplied by Ktilde (aka M_KG) + data.Pi_1 = M_Solve.block(0, 0, fsRows, fsRows).template cast(); + } + + // Precompute condensed matrices, + // first CSM: + std::vector CSM_M_SSCALAR; + CSM_M_SSCALAR.resize(data.dim); + for (int i=0; i(); + SSCALAR maxErr1 = condense_CSM(CSM_M_SSCALAR, data.m, data.dim, data.CSM); + verbose("condense_CSM maxErr = %.15f (this should be close to zero)\n", maxErr1); + assert(fabs(maxErr1) < 1e-5); + + // and then solveBlock1: + // number of groups + const int k = data.CSM_M[0].rows()/data.dim; + MatrixXS SolveBlock1 = data.M_FullSolve.block(0, 0, data.M_FullSolve.rows(), data.dim * data.dim * k); + SSCALAR maxErr2 = condense_Solve1(SolveBlock1, data.m, k, data.dim, data.CSolveBlock1); + verbose("condense_Solve1 maxErr = %.15f (this should be close to zero)\n", maxErr2); + assert(fabs(maxErr2) < 1e-5); + + return true; +} + +template +IGL_INLINE bool igl::arap_dof_update( + const ArapDOFData & data, + const Eigen::Matrix & B_eq, + const Eigen::MatrixXd & L0, + const int max_iters, + const double +#ifdef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT + tol, +#else + /*tol*/, +#endif + Eigen::MatrixXd & L + ) +{ + using namespace Eigen; + typedef Matrix MatrixXS; +#ifdef ARAP_GLOBAL_TIMING + double timer_start = get_seconds_hires(); +#endif + + // number of dimensions + assert((int)data.CSM_M.size() == data.dim); + assert((int)L0.size() == (data.m)*data.dim*(data.dim+1)); + assert(max_iters >= 0); + assert(tol >= 0); + + // timing variables + double + sec_start, + sec_covGather, + sec_fitRotations, + //sec_rhs, + sec_prepMult, + sec_solve, sec_end; + + assert(L0.cols() == 1); +#ifdef EXTREME_VERBOSE + cout<<"dim="<(); + + int iters = 0; +#ifndef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT + double max_diff = tol+1; +#endif + + MatrixXS S(k*data.dim,data.dim); + MatrixXS R(data.dim,data.dim*k); + Eigen::Matrix Rcol(data.dim * data.dim * k); + Matrix B_eq_SSCALAR = B_eq.cast(); + Matrix B_eq_fix_SSCALAR; + Matrix L0SSCALAR = L0.cast(); + slice(L0SSCALAR, data.fixed_dim, B_eq_fix_SSCALAR); + //MatrixXS rhsFull(Rcol.rows() + B_eq.rows() + B_eq_fix_SSCALAR.rows(), 1); + + MatrixXS Lsep(data.m*(data.dim + 1), 3); + const MatrixXS L_part2 = + data.M_FullSolve.block(0, Rcol.rows(), data.M_FullSolve.rows(), B_eq_SSCALAR.rows()) * B_eq_SSCALAR; + const MatrixXS L_part3 = + data.M_FullSolve.block(0, Rcol.rows() + B_eq_SSCALAR.rows(), data.M_FullSolve.rows(), B_eq_fix_SSCALAR.rows()) * B_eq_fix_SSCALAR; + MatrixXS L_part2and3 = L_part2 + L_part3; + + // preallocate workspace variables: + MatrixXS Rxyz(k*data.dim, data.dim); + MatrixXS L_part1xyz((data.dim + 1) * data.m, data.dim); + MatrixXS L_part1(data.dim * (data.dim + 1) * data.m, 1); + +#ifdef ARAP_GLOBAL_TIMING + double timer_prepFinished = get_seconds_hires(); +#endif + +#ifdef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT + while(iters < max_iters) +#else + while(iters < max_iters && max_diff > tol) +#endif + { + if(data.print_timings) + { + sec_start = get_seconds_hires(); + } + +#ifndef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT + L_prev = L_SSCALAR; +#endif + /////////////////////////////////////////////////////////////////////////// + // Local step: Fix positions, fit rotations + /////////////////////////////////////////////////////////////////////////// + + // Gather covariance matrices + + splitColumns(L_SSCALAR, data.m, data.dim, data.dim + 1, Lsep); + + S = data.CSM * Lsep; + // interestingly, this doesn't seem to be so slow, but + //MKL is still 2x faster (probably due to AVX) + //#ifdef IGL_ARAP_DOF_DOUBLE_PRECISION_SOLVE + // MKL_matMatMult_double(S, data.CSM, Lsep); + //#else + // MKL_matMatMult_single(S, data.CSM, Lsep); + //#endif + + if(data.print_timings) + { + sec_covGather = get_seconds_hires(); + } + +#ifdef EXTREME_VERBOSE + cout<<"S=["<(); + + MatrixXd temp_g = data.fgrav*(data.grav_mag*data.grav_dir); + + assert(data.fext.rows() == temp_g.rows()); + assert(data.fext.cols() == temp_g.cols()); + MatrixXd temp2 = data.Mass_tilde * temp_d + temp_g + data.fext.template cast(); + MatrixXS temp2_f = temp2.template cast(); + L_part1_dyn = data.Pi_1 * temp2_f; + L_part1.array() = L_part1.array() + L_part1_dyn.array(); + } + + //L_SSCALAR = L_part1 + L_part2and3; + assert(L_SSCALAR.rows() == L_part1.rows() && L_SSCALAR.rows() == L_part2and3.rows()); + for (int i=0; i(); + assert(L.cols() == 1); + +#ifdef ARAP_GLOBAL_TIMING + double timer_finito = get_seconds_hires(); + printf( + "ARAP preparation = %f, " + "all %i iterations = %f [ms]\n", + (timer_prepFinished - timer_start)*1000.0, + max_iters, + (timer_finito - timer_prepFinished)*1000.0); +#endif + + return true; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template bool igl::arap_dof_update, double>(ArapDOFData, double> const&, Eigen::Matrix const&, Eigen::Matrix const&, int, double, Eigen::Matrix&); +template bool igl::arap_dof_recomputation, double>(Eigen::Matrix const&, Eigen::SparseMatrix const&, ArapDOFData, double>&); +template bool igl::arap_dof_precomputation, double>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, ArapDOFData, double>&); +template bool igl::arap_dof_update, float>(igl::ArapDOFData, float> const&, Eigen::Matrix const&, Eigen::Matrix const&, int, double, Eigen::Matrix&); +template bool igl::arap_dof_recomputation, float>(Eigen::Matrix const&, Eigen::SparseMatrix const&, igl::ArapDOFData, float>&); +template bool igl::arap_dof_precomputation, float>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, igl::ArapDOFData, float>&); +#endif diff --git a/vendor/libigl/include/igl/arap_dof.h b/vendor/libigl/include/igl/arap_dof.h new file mode 100644 index 0000000000000000000000000000000000000000..f3647a3a18c44a42bcc21aefecd1420e0b2c2e90 --- /dev/null +++ b/vendor/libigl/include/igl/arap_dof.h @@ -0,0 +1,244 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ARAP_ENERGY_TYPE_DOF_H +#define IGL_ARAP_ENERGY_TYPE_DOF_H +#include "igl_inline.h" + +#include +#include +#include "ARAPEnergyType.h" +#include + +namespace igl +{ + // Caller example: + // + // Once: + // arap_dof_precomputation(...) + // + // Each frame: + // while(not satisfied) + // arap_dof_update(...) + // end + + template + struct ArapDOFData; + + /////////////////////////////////////////////////////////////////////////// + // + // Arap DOF precomputation consists of two parts the computation. The first is + // that which depends solely on the mesh (V,F), the linear blend skinning + // weights (M) and the groups G. Then there's the part that depends on the + // previous precomputation and the list of free and fixed vertices. + // + /////////////////////////////////////////////////////////////////////////// + + + // The code and variables differ from the description in Section 3 of "Fast + // Automatic Skinning Transformations" by [Jacobson et al. 2012] + // + // Here is a useful conversion table: + // + // [article] [code] + // S = \tilde{K} T S = CSM * Lsep + // S --> R S --> R --shuffled--> Rxyz + // Gamma_solve RT = Pi_1 \tilde{K} RT L_part1xyz = CSolveBlock1 * Rxyz + // Pi_1 \tilde{K} CSolveBlock1 + // Peq = [T_full; P_pos] + // T_full B_eq_fix <--- L0 + // P_pos B_eq + // Pi_2 * P_eq = Lpart2and3 = Lpart2 + Lpart3 + // Pi_2_left T_full + Lpart3 = M_fullsolve(right) * B_eq_fix + // Pi_2_right P_pos Lpart2 = M_fullsolve(left) * B_eq + // T = [Pi_1 Pi_2] [\tilde{K}TRT P_eq] L = Lpart1 + Lpart2and3 + // + + // Precomputes the system we are going to optimize. This consists of building + // constructor matrices (to compute covariance matrices from transformations + // and to build the poisson solve right hand side from rotation matrix entries) + // and also prefactoring the poisson system. + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by {3|4} list of face indices + // M #V * dim by #handles * dim * (dim+1) matrix such that + // new_V(:) = LBS(V,W,A) = reshape(M * A,size(V)), where A is a column + // vectors formed by the entries in each handle's dim by dim+1 + // transformation matrix. Specifcally, A = + // reshape(permute(Astack,[3 1 2]),n*dim*(dim+1),1) + // or A = [Lxx;Lyx;Lxy;Lyy;tx;ty], and likewise for other dim + // if Astack(:,:,i) is the dim by (dim+1) transformation at handle i + // handles are ordered according to P then BE (point handles before bone + // handles) + // G #V list of group indices (1 to k) for each vertex, such that vertex i + // is assigned to group G(i) + // Outputs: + // data structure containing all necessary precomputation for calling + // arap_dof_update + // Returns true on success, false on error + // + // See also: lbs_matrix_column + template + IGL_INLINE bool arap_dof_precomputation( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const LbsMatrixType & M, + const Eigen::Matrix & G, + ArapDOFData & data); + + // Should always be called after arap_dof_precomputation, but may be called in + // between successive calls to arap_dof_update, recomputes precomputation + // given that there are only changes in free and fixed + // + // Inputs: + // fixed_dim list of transformation element indices for fixed (or partailly + // fixed) handles: not necessarily the complement of 'free' + // NOTE: the constraints for fixed transformations still need to be + // present in A_eq + // A_eq dim*#constraint_points by m*dim*(dim+1) matrix of linear equality + // constraint coefficients. Each row corresponds to a linear constraint, + // so that A_eq * L = Beq says that the linear transformation entries in + // the column L should produce the user supplied positional constraints + // for each handle in Beq. The row A_eq(i*dim+d) corresponds to the + // constrain on coordinate d of position i + // Outputs: + // data structure containing all necessary precomputation for calling + // arap_dof_update + // Returns true on success, false on error + // + // See also: lbs_matrix_column + template + IGL_INLINE bool arap_dof_recomputation( + const Eigen::Matrix & fixed_dim, + const Eigen::SparseMatrix & A_eq, + ArapDOFData & data); + + // Optimizes the transformations attached to each weight function based on + // precomputed system. + // + // Inputs: + // data precomputation data struct output from arap_dof_precomputation + // Beq dim*#constraint_points constraint values. + // L0 #handles * dim * dim+1 list of initial guess transformation entries, + // also holds fixed transformation entries for fixed handles + // max_iters maximum number of iterations + // tol stopping criteria parameter. If variables (linear transformation + // matrix entries) change by less than 'tol' the optimization terminates, + // 0.75 (weak tolerance) + // 0.0 (extreme tolerance) + // Outputs: + // L #handles * dim * dim+1 list of final optimized transformation entries, + // allowed to be the same as L + template + IGL_INLINE bool arap_dof_update( + const ArapDOFData & data, + const Eigen::Matrix & B_eq, + const Eigen::MatrixXd & L0, + const int max_iters, + const double tol, + Eigen::MatrixXd & L + ); + + // Structure that contains fields for all precomputed data or data that needs + // to be remembered at update + template + struct ArapDOFData + { + typedef Eigen::Matrix MatrixXS; + // Type of arap energy we're solving + igl::ARAPEnergyType energy; + //// LU decomposition precomptation data; note: not used by araf_dop_update + //// any more, replaced by M_FullSolve + //igl::min_quad_with_fixed_data lu_data; + // List of indices of fixed transformation entries + Eigen::Matrix fixed_dim; + // List of precomputed covariance scatter matrices multiplied by lbs + // matrices + //std::vector > CSM_M; + std::vector CSM_M; + LbsMatrixType M_KG; + // Number of mesh vertices + int n; + // Number of weight functions + int m; + // Number of dimensions + int dim; + // Effective dimensions + int effective_dim; + // List of indices into C of positional constraints + Eigen::Matrix interpolated; + std::vector free_mask; + // Full quadratic coefficients matrix before lagrangian (should be dense) + LbsMatrixType Q; + + + //// Solve matrix for the global step + //Eigen::MatrixXd M_Solve; // TODO: remove from here + + // Full solve matrix that contains also conversion from rotations to the right hand side, + // i.e., solves Poisson transformations just from rotations and positional constraints + MatrixXS M_FullSolve; + + // Precomputed condensed matrices (3x3 commutators folded to 1x1): + MatrixXS CSM; + MatrixXS CSolveBlock1; + + // Print timings at each update + bool print_timings; + + // Dynamics + bool with_dynamics; + // I'm hiding the extra dynamics stuff in this struct, which sort of defeats + // the purpose of this function-based coding style... + + // Time step + double h; + + // L0 #handles * dim * dim+1 list of transformation entries from + // previous solve + MatrixXS L0; + //// Lm1 #handles * dim * dim+1 list of transformation entries from + //// previous-previous solve + //MatrixXS Lm1; + // "Velocity" + MatrixXS Lvel0; + + // #V by dim matrix of external forces + // fext + MatrixXS fext; + + // Mass_tilde: MT * Mass * M + LbsMatrixType Mass_tilde; + + // Force due to gravity (premultiplier) + Eigen::MatrixXd fgrav; + // Direction of gravity + Eigen::Vector3d grav_dir; + // Magnitude of gravity + double grav_mag; + + // Π1 from the paper + MatrixXS Pi_1; + + // Default values + ArapDOFData(): + energy(igl::ARAP_ENERGY_TYPE_SPOKES), + with_dynamics(false), + h(1), + grav_dir(0,-1,0), + grav_mag(0) + { + } + }; +} + +#ifndef IGL_STATIC_LIBRARY +# include "arap_dof.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/arap_linear_block.h b/vendor/libigl/include/igl/arap_linear_block.h new file mode 100644 index 0000000000000000000000000000000000000000..9983550aab64302665a8fd7ca60aa509eca33fc2 --- /dev/null +++ b/vendor/libigl/include/igl/arap_linear_block.h @@ -0,0 +1,78 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ARAP_LINEAR_BLOCK_H +#define IGL_ARAP_LINEAR_BLOCK_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // ARAP_LINEAR_BLOCK constructs a block of the matrix which constructs the + // linear terms of a given arap energy. When treating rotations as knowns + // (arranged in a column) then this constructs Kd of K such that the linear + // portion of the energy is as a column: + // K * R = [Kx Z ... Ky Z ... + // Z Kx ... Z Ky ... + // ... ] + // These blocks are also used to build the "covariance scatter matrices". + // Here we want to build a scatter matrix that multiplies against positions + // (treated as known) producing covariance matrices to fit each rotation. + // Notice that in the case of the RHS of the poisson solve the rotations are + // known and the positions unknown, and vice versa for rotation fitting. + // These linear block just relate the rotations to the positions, linearly in + // each. + // + // Templates: + // MatV vertex position matrix, e.g. Eigen::MatrixXd + // MatF face index matrix, e.g. Eigen::MatrixXd + // Scalar e.g. double + // Inputs: + // V #V by dim list of initial domain positions + // F #F by #simplex size list of triangle indices into V + // d coordinate of linear constructor to build + // energy ARAPEnergyType enum value defining which energy is being used. + // See ARAPEnergyType.h for valid options and explanations. + // Outputs: + // Kd #V by #V/#F block of the linear constructor matrix corresponding to + // coordinate d + // + template + IGL_INLINE void arap_linear_block( + const MatV & V, + const MatF & F, + const int d, + const igl::ARAPEnergyType energy, + MatK & Kd); + // Helper functions for each energy type + template + IGL_INLINE void arap_linear_block_spokes( + const MatV & V, + const MatF & F, + const int d, + MatK & Kd); + template + IGL_INLINE void arap_linear_block_spokes_and_rims( + const MatV & V, + const MatF & F, + const int d, + MatK & Kd); + template + IGL_INLINE void arap_linear_block_elements( + const MatV & V, + const MatF & F, + const int d, + MatK & Kd); +} + +#ifndef IGL_STATIC_LIBRARY +# include "arap_linear_block.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/average_onto_faces.h b/vendor/libigl/include/igl/average_onto_faces.h new file mode 100644 index 0000000000000000000000000000000000000000..6fc358b79310a7932c9e0ffc36938e2ca6667619 --- /dev/null +++ b/vendor/libigl/include/igl/average_onto_faces.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_AVERAGE_ONTO_FACES_H +#define IGL_AVERAGE_ONTO_FACES_H +#include "igl_inline.h" + +#include +namespace igl +{ + // average_onto_vertices + // Move a scalar field defined on faces to vertices by averaging + // + // Input: + // F #F by ss list of simples/faces + // S #V by dim list of per-vertex values + // Output: + // SF #F by dim list of per-face values + template + IGL_INLINE void average_onto_faces( + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & S, + Eigen::PlainObjectBase & SF); +} + +#ifndef IGL_STATIC_LIBRARY +# include "average_onto_faces.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/average_onto_vertices.cpp b/vendor/libigl/include/igl/average_onto_vertices.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5994605708ba686d0d731d01c86cf749c59efc90 --- /dev/null +++ b/vendor/libigl/include/igl/average_onto_vertices.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "average_onto_vertices.h" + +template +IGL_INLINE void igl::average_onto_vertices(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &S, + Eigen::PlainObjectBase &SV) +{ + SV = DerivedS::Zero(V.rows(),S.cols()); + Eigen::Matrix COUNT(V.rows()); + COUNT.setZero(); + for (int i = 0; i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_AVERAGE_ONTO_VERTICES_H +#define IGL_AVERAGE_ONTO_VERTICES_H +#include "igl_inline.h" + +#include +namespace igl +{ + // average_onto_vertices + // Move a scalar field defined on faces to vertices by averaging + // + // Input: + // V,F: mesh + // S: scalar field defined on faces, Fx1 + // + // Output: + // SV: scalar field defined on vertices + template + IGL_INLINE void average_onto_vertices(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &S, + Eigen::PlainObjectBase &SV); +} + +#ifndef IGL_STATIC_LIBRARY +# include "average_onto_vertices.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/avg_edge_length.h b/vendor/libigl/include/igl/avg_edge_length.h new file mode 100644 index 0000000000000000000000000000000000000000..3c224bfa45e31dba85668a541514a1116742f4a5 --- /dev/null +++ b/vendor/libigl/include/igl/avg_edge_length.h @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_AVERAGEEDGELENGTH_H +#define IGL_AVERAGEEDGELENGTH_H + +#include "igl_inline.h" +#include +#include +#include + +namespace igl +{ + // Compute the average edge length for the given triangle mesh + // Templates: + // DerivedV derived from vertex positions matrix type: i.e. MatrixXd + // DerivedF derived from face indices matrix type: i.e. MatrixXi + // DerivedL derived from edge lengths matrix type: i.e. MatrixXd + // Inputs: + // V eigen matrix #V by 3 + // F #F by simplex-size list of mesh faces (must be simplex) + // Outputs: + // l average edge length + // + // See also: adjacency_matrix + template + IGL_INLINE double avg_edge_length( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "avg_edge_length.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/axis_angle_to_quat.cpp b/vendor/libigl/include/igl/axis_angle_to_quat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..009d0522ce51a82b1afa7e1f919ac4ba4bef642a --- /dev/null +++ b/vendor/libigl/include/igl/axis_angle_to_quat.cpp @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "axis_angle_to_quat.h" +#include "EPS.h" +#include + +// http://www.antisphere.com/Wiki/tools:anttweakbar +template +IGL_INLINE void igl::axis_angle_to_quat( + const Q_type *axis, + const Q_type angle, + Q_type *out) +{ + Q_type n = axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]; + if( fabs(n)>igl::EPS()) + { + Q_type f = 0.5*angle; + out[3] = cos(f); + f = sin(f)/sqrt(n); + out[0] = axis[0]*f; + out[1] = axis[1]*f; + out[2] = axis[2]*f; + } + else + { + out[3] = 1.0; + out[0] = out[1] = out[2] = 0.0; + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::axis_angle_to_quat(double const*, double, double*); +// generated by autoexplicit.sh +template void igl::axis_angle_to_quat(float const*, float, float*); +#endif diff --git a/vendor/libigl/include/igl/axis_angle_to_quat.h b/vendor/libigl/include/igl/axis_angle_to_quat.h new file mode 100644 index 0000000000000000000000000000000000000000..6533b1becd367b64e77d5673d1ac1a25dad31eb6 --- /dev/null +++ b/vendor/libigl/include/igl/axis_angle_to_quat.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_AXIS_ANGLE_TO_QUAT_H +#define IGL_AXIS_ANGLE_TO_QUAT_H +#include "igl_inline.h" + +namespace igl +{ + // Convert axis angle representation of a rotation to a quaternion + // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), + // such that q = x*i + y*j + z*k + w + // Inputs: + // axis 3d vector + // angle scalar + // Outputs: + // quaternion + template + IGL_INLINE void axis_angle_to_quat( + const Q_type *axis, + const Q_type angle, + Q_type *out); +} + +#ifndef IGL_STATIC_LIBRARY +# include "axis_angle_to_quat.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/barycenter.h b/vendor/libigl/include/igl/barycenter.h new file mode 100644 index 0000000000000000000000000000000000000000..ef78e94a63e6d4b70e2746f62f227af62af60560 --- /dev/null +++ b/vendor/libigl/include/igl/barycenter.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BARYCENTER_H +#define IGL_BARYCENTER_H +#include "igl_inline.h" +#include +namespace igl +{ + // Computes the barycenter of every simplex + // + // Inputs: + // V #V x dim matrix of vertex coordinates + // F #F x simplex_size matrix of indices of simplex corners into V + // Output: + // BC #F x dim matrix of 3d vertices + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedBC> + IGL_INLINE void barycenter( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & BC); +} + +#ifndef IGL_STATIC_LIBRARY +# include "barycenter.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/barycentric_coordinates.h b/vendor/libigl/include/igl/barycentric_coordinates.h new file mode 100644 index 0000000000000000000000000000000000000000..ec08669f29d1d1cb8ce8f018f861add724f6a94d --- /dev/null +++ b/vendor/libigl/include/igl/barycentric_coordinates.h @@ -0,0 +1,68 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BARYCENTRIC_COORDINATES_H +#define IGL_BARYCENTRIC_COORDINATES_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute barycentric coordinates in a tet + // + // Inputs: + // P #P by 3 Query points in 3d + // A #P by 3 Tet corners in 3d + // B #P by 3 Tet corners in 3d + // C #P by 3 Tet corners in 3d + // D #P by 3 Tet corners in 3d + // Outputs: + // L #P by 4 list of barycentric coordinates + // + template < + typename DerivedP, + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedD, + typename DerivedL> + IGL_INLINE void barycentric_coordinates( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & D, + Eigen::PlainObjectBase & L); + // Compute barycentric coordinates in a triangle + // + // Inputs: + // P #P by dim Query points + // A #P by dim Triangle corners + // B #P by dim Triangle corners + // C #P by dim Triangle corners + // Outputs: + // L #P by 3 list of barycentric coordinates + // + template < + typename DerivedP, + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedL> + IGL_INLINE void barycentric_coordinates( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & L); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "barycentric_coordinates.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/barycentric_interpolation.h b/vendor/libigl/include/igl/barycentric_interpolation.h new file mode 100644 index 0000000000000000000000000000000000000000..3255c6eb8fbfc516edf35a921b21733f9d092ec7 --- /dev/null +++ b/vendor/libigl/include/igl/barycentric_interpolation.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BARYCENTRIC_INTERPOLATION_H +#define IGL_BARYCENTRIC_INTERPOLATION_H +#include "igl_inline.h" +#include +namespace igl +{ + // Interpolate data on a triangle mesh using barycentric coordinates + // + // Inputs: + // D #D by dim list of per-vertex data + // F #F by 3 list of triangle indices + // B #X by 3 list of barycentric corodinates + // I #X list of triangle indices + // Outputs: + // X #X by dim list of interpolated data + template < + typename DerivedD, + typename DerivedF, + typename DerivedB, + typename DerivedI, + typename DerivedX> + IGL_INLINE void barycentric_interpolation( + const Eigen::MatrixBase & D, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & I, + Eigen::PlainObjectBase & X); +} + +#ifndef IGL_STATIC_LIBRARY +# include "barycentric_interpolation.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/basename.cpp b/vendor/libigl/include/igl/basename.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae4fb118e5329e7732bf8b4f6bcd1e0e2b9cecc2 --- /dev/null +++ b/vendor/libigl/include/igl/basename.cpp @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "basename.h" + +#include + +IGL_INLINE std::string igl::basename(const std::string & path) +{ + if(path == "") + { + return std::string(""); + } + // http://stackoverflow.com/questions/5077693/dirnamephp-similar-function-in-c + std::string::const_reverse_iterator last_slash = + std::find( + path.rbegin(), + path.rend(), '/'); + if( last_slash == path.rend() ) + { + // No slashes found + return path; + }else if(1 == (last_slash.base() - path.begin())) + { + // Slash is first char + return std::string(path.begin()+1,path.end()); + }else if(path.end() == last_slash.base() ) + { + // Slash is last char + std::string redo = std::string(path.begin(),path.end()-1); + return igl::basename(redo); + } + return std::string(last_slash.base(),path.end()); +} diff --git a/vendor/libigl/include/igl/bbw.cpp b/vendor/libigl/include/igl/bbw.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5896a3092f786cfdeca891afe254bd7747b0b5c6 --- /dev/null +++ b/vendor/libigl/include/igl/bbw.cpp @@ -0,0 +1,144 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "bbw.h" +#include "min_quad_with_fixed.h" +#include "harmonic.h" +#include "parallel_for.h" +#include +#include +#include +#include + +igl::BBWData::BBWData(): + partition_unity(false), + W0(), + active_set_params(), + verbosity(0) +{ + // We know that the Bilaplacian is positive semi-definite + active_set_params.Auu_pd = true; +} + +void igl::BBWData::print() +{ + using namespace std; + cout<<"partition_unity: "< +IGL_INLINE bool igl::bbw( + const Eigen::PlainObjectBase & V, + const Eigen::PlainObjectBase & Ele, + const Eigen::PlainObjectBase & b, + const Eigen::PlainObjectBase & bc, + igl::BBWData & data, + Eigen::PlainObjectBase & W + ) +{ + using namespace std; + using namespace Eigen; + assert(!data.partition_unity && "partition_unity not implemented yet"); + // number of domain vertices + int n = V.rows(); + // number of handles + int m = bc.cols(); + // Build biharmonic operator + Eigen::SparseMatrix Q; + harmonic(V,Ele,2,Q); + W.derived().resize(n,m); + // No linear terms + VectorXd c = VectorXd::Zero(n); + // No linear constraints + SparseMatrix A(0,n),Aeq(0,n),Aieq(0,n); + VectorXd Beq(0,1),Bieq(0,1); + // Upper and lower box constraints (Constant bounds) + VectorXd ux = VectorXd::Ones(n); + VectorXd lx = VectorXd::Zero(n); + active_set_params eff_params = data.active_set_params; + if(data.verbosity >= 1) + { + cout<<"BBW: max_iter: "<= 1) + { + cout<<"BBW: Computing initial weights for "< mqwf; + min_quad_with_fixed_precompute(Q,b,Aeq,true,mqwf); + min_quad_with_fixed_solve(mqwf,c,bc,Beq,W); + // decrement + eff_params.max_iter--; + bool error = false; + // Loop over handles + std::mutex critical; + const auto & optimize_weight = [&](const int i) + { + // Quicker exit for paralle_for + if(error) + { + return; + } + if(data.verbosity >= 1) + { + std::lock_guard lock(critical); + cout<<"BBW: Computing weight for handle "<, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, igl::BBWData&, Eigen::PlainObjectBase >&); +#endif + diff --git a/vendor/libigl/include/igl/bezier.h b/vendor/libigl/include/igl/bezier.h new file mode 100644 index 0000000000000000000000000000000000000000..4e0dbbbb27b7e535b6c8a6750eb2adb4059f4e04 --- /dev/null +++ b/vendor/libigl/include/igl/bezier.h @@ -0,0 +1,51 @@ +#ifndef BEZIER_H +#define BEZIER_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Evaluate a polynomial Bezier Curve. + // + // Inputs: + // V #V by dim list of Bezier control points + // t evaluation parameter within [0,1] + // Outputs: + // P 1 by dim output point + template + IGL_INLINE void bezier( + const Eigen::MatrixBase & V, + const typename DerivedV::Scalar t, + Eigen::PlainObjectBase & P); + // Evaluate a polynomial Bezier Curve. + // + // Inputs: + // V #V by dim list of Bezier control points + // T #T evaluation parameters within [0,1] + // Outputs: + // P #T by dim output points + template + IGL_INLINE void bezier( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & T, + Eigen::PlainObjectBase & P); + // Evaluate a polynomial Bezier spline with a fixed parameter set for each + // sub-curve + // + // Inputs: + // spline #curves list of lists of Bezier control points + // T #T evaluation parameters within [0,1] to use for each spline + // Outputs: + // P #curves*#T by dim output points + template + IGL_INLINE void bezier( + const std::vector & spline, + const Eigen::MatrixBase & T, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "bezier.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/bfs.h b/vendor/libigl/include/igl/bfs.h new file mode 100644 index 0000000000000000000000000000000000000000..e1c761b38667fdc1391e2267d3849a34b6e3e207 --- /dev/null +++ b/vendor/libigl/include/igl/bfs.h @@ -0,0 +1,54 @@ +#ifndef IGL_BFS_H +#define IGL_BFS_H +#include "igl_inline.h" +#include +#include +#include +namespace igl +{ + // Traverse a **directed** graph represented by an adjacency list using + // breadth first search + // + // Inputs: + // A #V list of adjacency lists or #V by #V adjacency matrix + // s starting node (index into A) + // Outputs: + // D #V list of indices into rows of A in the order in which graph nodes + // are discovered. + // P #V list of indices into rows of A of predecessor in resulting + // spanning tree {-1 indicates root/not discovered), order corresponds to + // V **not** D. + template < + typename AType, + typename DerivedD, + typename DerivedP> + IGL_INLINE void bfs( + const AType & A, + const size_t s, + Eigen::PlainObjectBase & D, + Eigen::PlainObjectBase & P); + + template < + typename AType, + typename DType, + typename PType> + IGL_INLINE void bfs( + const std::vector > & A, + const size_t s, + std::vector & D, + std::vector & P); + template < + typename AType, + typename DType, + typename PType> + IGL_INLINE void bfs( + const Eigen::SparseCompressedBase & A, + const size_t s, + std::vector & D, + std::vector & P); +} +#ifndef IGL_STATIC_LIBRARY +# include "bfs.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/bfs_orient.cpp b/vendor/libigl/include/igl/bfs_orient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a8c6f083ba57aa8c4a4f169286e06fd08c6407b --- /dev/null +++ b/vendor/libigl/include/igl/bfs_orient.cpp @@ -0,0 +1,100 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "bfs_orient.h" +#include "orientable_patches.h" +#include +#include + +template +IGL_INLINE void igl::bfs_orient( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & FF, + Eigen::PlainObjectBase & C) +{ + using namespace Eigen; + using namespace std; + SparseMatrix A; + orientable_patches(F,C,A); + + // number of faces + const int m = F.rows(); + // number of patches + const int num_cc = C.maxCoeff()+1; + VectorXi seen = VectorXi::Zero(m); + + // Edge sets + const int ES[3][2] = {{1,2},{2,0},{0,1}}; + + if(((void*)&FF) != ((void*)&F)) + { + FF = F; + } + // loop over patches +#pragma omp parallel for + for(int c = 0;c Q; + // find first member of patch c + for(int f = 0;f 0) + { + continue; + } + seen(f)++; + // loop over neighbors of f + for(typename SparseMatrix::InnerIterator it (A,f); it; ++it) + { + // might be some lingering zeros, and skip self-adjacency + if(it.value() != 0 && it.row() != f) + { + const int n = it.row(); + assert(n != f); + // loop over edges of f + for(int efi = 0;efi<3;efi++) + { + // efi'th edge of face f + Vector2i ef(FF(f,ES[efi][0]),FF(f,ES[efi][1])); + // loop over edges of n + for(int eni = 0;eni<3;eni++) + { + // eni'th edge of face n + Vector2i en(FF(n,ES[eni][0]),FF(n,ES[eni][1])); + // Match (half-edges go same direction) + if(ef(0) == en(0) && ef(1) == en(1)) + { + // flip face n + FF.row(n) = FF.row(n).reverse().eval(); + } + } + } + // add neighbor to queue + Q.push(n); + } + } + } + } + + // make sure flip is OK if &FF = &F +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::bfs_orient, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/bijective_composite_harmonic_mapping.cpp b/vendor/libigl/include/igl/bijective_composite_harmonic_mapping.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7336182190620e361fae07a2ad4baf53c74ee5cf --- /dev/null +++ b/vendor/libigl/include/igl/bijective_composite_harmonic_mapping.cpp @@ -0,0 +1,115 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "bijective_composite_harmonic_mapping.h" + +#include "slice.h" +#include "doublearea.h" +#include "harmonic.h" +//#include "matlab/MatlabWorkspace.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename Derivedb, + typename Derivedbc, + typename DerivedU> +IGL_INLINE bool igl::bijective_composite_harmonic_mapping( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + Eigen::PlainObjectBase & U) +{ + return bijective_composite_harmonic_mapping(V,F,b,bc,1,200,20,true,U); +} + +template < + typename DerivedV, + typename DerivedF, + typename Derivedb, + typename Derivedbc, + typename DerivedU> +IGL_INLINE bool igl::bijective_composite_harmonic_mapping( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + const int min_steps, + const int max_steps, + const int num_inner_iters, + const bool test_for_flips, + Eigen::PlainObjectBase & U) +{ + typedef typename Derivedbc::Scalar Scalar; + assert(V.cols() == 2 && bc.cols() == 2 && "Input should be 2D"); + assert(F.cols() == 3 && "F should contain triangles"); + int tries = 0; + int nsteps = min_steps; + Eigen::Matrix bc0; + slice(V,b,1,bc0); + + // It's difficult to check for flips "robustly" in the sense that the input + // mesh might not have positive/consistent sign to begin with. + + while(nsteps<=max_steps) + { + U = V; + int flipped = 0; + int nans = 0; + int step = 0; + for(;step<=nsteps;step++) + { + const Scalar t = ((Scalar)step)/((Scalar)nsteps); + // linearly interpolate boundary conditions + // TODO: replace this with something that guarantees a homotopic "morph" + // of the boundary conditions. Something like "Homotopic Morphing of + // Planar Curves" [Dym et al. 2015] but also handling multiple connected + // components. + Eigen::Matrix bct = bc0 + t * (bc - bc0); + // Compute dsicrete harmonic map using metric of previous step + for(int iter = 0;iter(U), F, b, bct, 1, U); + igl::slice(U,b,1,bct); + nans = (U.array() != U.array()).count(); + if(test_for_flips) + { + Eigen::Matrix A; + doublearea(U,F,A); + flipped = (A.array() < 0 ).count(); + //std::cout<<" "< 0 || nans>0) break; + } + if(flipped == 0 && nans == 0) + { + return step == nsteps+1; + } + nsteps *= 2; + } + //std::cout<<"failed to finish in "<, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::bijective_composite_harmonic_mapping, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, int, bool, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/bijective_composite_harmonic_mapping.h b/vendor/libigl/include/igl/bijective_composite_harmonic_mapping.h new file mode 100644 index 0000000000000000000000000000000000000000..f055e5293c91a728801cf59386faae6288736af1 --- /dev/null +++ b/vendor/libigl/include/igl/bijective_composite_harmonic_mapping.h @@ -0,0 +1,79 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BIJECTIVE_COMPOSITE_HARMONIC_MAPPING_H +#define IGL_BIJECTIVE_COMPOSITE_HARMONIC_MAPPING_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Compute a planar mapping of a triangulated polygon (V,F) subjected to + // boundary conditions (b,bc). The mapping should be bijective in the sense + // that no triangles' areas become negative (this assumes they started + // positive). This mapping is computed by "composing" harmonic mappings + // between incremental morphs of the boundary conditions. This is a bit like + // a discrete version of "Bijective Composite Mean Value Mappings" [Schneider + // et al. 2013] but with a discrete harmonic map (cf. harmonic coordinates) + // instead of mean value coordinates. This is inspired by "Embedding a + // triangular graph within a given boundary" [Xu et al. 2011]. + // + // Inputs: + // V #V by 2 list of triangle mesh vertex positions + // F #F by 3 list of triangle indices into V + // b #b list of boundary indices into V + // bc #b by 2 list of boundary conditions corresponding to b + // Outputs: + // U #V by 2 list of output mesh vertex locations + // Returns true if and only if U contains a successful bijectie mapping + // + // + template < + typename DerivedV, + typename DerivedF, + typename Derivedb, + typename Derivedbc, + typename DerivedU> + IGL_INLINE bool bijective_composite_harmonic_mapping( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + Eigen::PlainObjectBase & U); + // + // Inputs: + // min_steps minimum number of steps to take from V(b,:) to bc + // max_steps minimum number of steps to take from V(b,:) to bc (if + // max_steps == min_steps then no further number of steps will be tried) + // num_inner_iters number of iterations of harmonic solves to run after + // for each morph step (to try to push flips back in) + // test_for_flips whether to check if flips occurred (and trigger more + // steps). if test_for_flips = false then this function always returns + // true + // + template < + typename DerivedV, + typename DerivedF, + typename Derivedb, + typename Derivedbc, + typename DerivedU> + IGL_INLINE bool bijective_composite_harmonic_mapping( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + const int min_steps, + const int max_steps, + const int num_inner_iters, + const bool test_for_flips, + Eigen::PlainObjectBase & U); +} + +#ifndef IGL_STATIC_LIBRARY +# include "bijective_composite_harmonic_mapping.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/blkdiag.cpp b/vendor/libigl/include/igl/blkdiag.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a53ea85952a4583ff9a2b959caaea58b0afc5361 --- /dev/null +++ b/vendor/libigl/include/igl/blkdiag.cpp @@ -0,0 +1,71 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "blkdiag.h" + +template +IGL_INLINE void igl::blkdiag( + const std::vector> & L, + Eigen::SparseMatrix & Y) +{ + int nr = 0; + int nc = 0; + int nnz = 0; + for(const auto & A : L) + { + nr += A.rows(); + nc += A.cols(); + } + Y.resize(nr,nc); + { + int i = 0; + int j = 0; + for(const auto & A : L) + { + for(int k = 0;k::InnerIterator it(A,k);it;++it) + { + Y.insert(i+it.row(),j+k) = it.value(); + } + } + i += A.rows(); + j += A.cols(); + } + } +} + +template +IGL_INLINE void igl::blkdiag( + const std::vector & L, + Eigen::PlainObjectBase & Y) +{ + int nr = 0; + int nc = 0; + for(const auto & A : L) + { + nr += A.rows(); + nc += A.cols(); + } + Y.setZero(nr,nc); + { + int i = 0; + int j = 0; + for(const auto & A : L) + { + Y.block(i,j,A.rows(),A.cols()) = A; + i += A.rows(); + j += A.cols(); + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// explicit template instantiations +template void igl::blkdiag >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::blkdiag(std::vector, std::allocator > > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/blkdiag.h b/vendor/libigl/include/igl/blkdiag.h new file mode 100644 index 0000000000000000000000000000000000000000..bc0ee190e70fcaac6062d4e16d063a16aaf21fdb --- /dev/null +++ b/vendor/libigl/include/igl/blkdiag.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BLKDIAG_H +#define IGL_BLKDIAG_H +#include "igl_inline.h" +#include +#include +#include + +namespace igl +{ + // Given a list of matrices place them along the diagonal as blocks of the + // output matrix. Like matlab's blkdiag. + // + // Inputs: + // L list of matrices {A,B, ...} + // Outputs: + // Y A.rows()+B.rows()+... by A.cols()+B.cols()+... block diagonal + // + // See also: cat, repdiag + template + IGL_INLINE void blkdiag( + const std::vector> & L, + Eigen::SparseMatrix & Y); + template + IGL_INLINE void blkdiag( + const std::vector & L, + Eigen::PlainObjectBase & Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "blkdiag.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/blue_noise.h b/vendor/libigl/include/igl/blue_noise.h new file mode 100644 index 0000000000000000000000000000000000000000..45f3bfcc3754d9735b7a7c30321ff344c1318033 --- /dev/null +++ b/vendor/libigl/include/igl/blue_noise.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BLUE_NOISE_H +#define IGL_BLUE_NOISE_H +#include "igl_inline.h" +#include +namespace igl +{ + // "Fast Poisson Disk Sampling in Arbitrary Dimensions" [Bridson 2007] + // + // For very dense samplings this is faster than (up to 2x) cyCodeBase's + // implementation of "Sample Elimination for Generating Poisson Disk Sample + // Sets" [Yuksel 2015]. YMMV + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by 3 list of mesh triangle indices into rows of V + // r Poisson disk radius (evaluated according to Euclidean distance on V) + // Outputs: + // B #P by 3 list of barycentric coordinates, ith row are coordinates of + // ith sampled point in face FI(i) + // FI #P list of indices into F + // P #P by dim list of sample positions. + // See also: random_points_on_mesh + template < + typename DerivedV, + typename DerivedF, + typename DerivedB, + typename DerivedFI, + typename DerivedP> + IGL_INLINE void blue_noise( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const typename DerivedV::Scalar r, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & FI, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "blue_noise.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/boundary_conditions.cpp b/vendor/libigl/include/igl/boundary_conditions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f7146cd70be5ec9922c667797a32478335715ace --- /dev/null +++ b/vendor/libigl/include/igl/boundary_conditions.cpp @@ -0,0 +1,192 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "boundary_conditions.h" + +#include "verbose.h" +#include "EPS.h" +#include "project_to_line.h" + +#include +#include +#include + +IGL_INLINE bool igl::boundary_conditions( + const Eigen::MatrixXd & V , + const Eigen::MatrixXi & /*Ele*/, + const Eigen::MatrixXd & C , + const Eigen::VectorXi & P , + const Eigen::MatrixXi & BE , + const Eigen::MatrixXi & CE , + Eigen::VectorXi & b , + Eigen::MatrixXd & bc ) +{ + using namespace Eigen; + using namespace std; + + if(P.size()+BE.rows() == 0) + { + verbose("^%s: Error: no handles found\n",__FUNCTION__); + return false; + } + + vector bci; + vector bcj; + vector bcv; + + // loop over points + for(int p = 0;p FLOAT_EPS) + { + verbose("^%s: Error: handle %d does not receive 0 weight\n",__FUNCTION__,i); + return false; + } + if(max_c< (1-FLOAT_EPS)) + { + verbose("^%s: Error: handle %d does not receive 1 weight\n",__FUNCTION__,i); + return false; + } + } + + return true; +} diff --git a/vendor/libigl/include/igl/boundary_facets.cpp b/vendor/libigl/include/igl/boundary_facets.cpp new file mode 100644 index 0000000000000000000000000000000000000000..232a303d8f493846058ccbfe361455cee4a6745c --- /dev/null +++ b/vendor/libigl/include/igl/boundary_facets.cpp @@ -0,0 +1,222 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "boundary_facets.h" +#include "face_occurrences.h" +#include "list_to_matrix.h" +#include "matrix_to_list.h" +#include "sort.h" +#include "unique_rows.h" +#include "accumarray.h" +#include "slice_mask.h" + +#include + +#include +#include + +template < + typename DerivedT, + typename DerivedF, + typename DerivedJ, + typename DerivedK> +IGL_INLINE void igl::boundary_facets( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& F, + Eigen::PlainObjectBase& J, + Eigen::PlainObjectBase& K) +{ + const int simplex_size = T.cols(); + // Handle boring base case + if(T.rows() == 0) + { + F.resize(0,simplex_size-1); + J.resize(0,1); + K.resize(0,1); + return; + } + // Get a list of all facets + DerivedF allF(T.rows()*simplex_size,simplex_size-1); + // Gather faces (e.g., loop over tets) + for(int i = 0; i< (int)T.rows();i++) + { + switch(simplex_size) + { + case 4: + // get face in correct order + allF(i*simplex_size+0,0) = T(i,1); + allF(i*simplex_size+0,1) = T(i,3); + allF(i*simplex_size+0,2) = T(i,2); + // get face in correct order + allF(i*simplex_size+1,0) = T(i,0); + allF(i*simplex_size+1,1) = T(i,2); + allF(i*simplex_size+1,2) = T(i,3); + // get face in correct order + allF(i*simplex_size+2,0) = T(i,0); + allF(i*simplex_size+2,1) = T(i,3); + allF(i*simplex_size+2,2) = T(i,1); + // get face in correct order + allF(i*simplex_size+3,0) = T(i,0); + allF(i*simplex_size+3,1) = T(i,1); + allF(i*simplex_size+3,2) = T(i,2); + break; + case 3: + allF(i*simplex_size+0,0) = T(i,1); + allF(i*simplex_size+0,1) = T(i,2); + allF(i*simplex_size+1,0) = T(i,2); + allF(i*simplex_size+1,1) = T(i,0); + allF(i*simplex_size+2,0) = T(i,0); + allF(i*simplex_size+2,1) = T(i,1); + break; + } + } + DerivedF sortedF; + igl::sort(allF,2,true,sortedF); + Eigen::VectorXi m,n; + { + DerivedF _1; + igl::unique_rows(sortedF,_1,m,n); + } + Eigen::VectorXi C; + igl::accumarray(n,1,C); + const int ones = (C.array()==1).count(); + // Resize output to fit number of non-twos + F.resize(ones, allF.cols()); + J.resize(F.rows(),1); + K.resize(F.rows(),1); + int k = 0; + for(int c = 0;c< (int)C.size();c++) + { + if(C(c) == 1) + { + const int i = m(c); + assert(k<(int)F.rows()); + F.row(k) = allF.row(i); + J(k) = i/simplex_size; + K(k) = i%simplex_size; + k++; + } + } + assert(k==(int)F.rows()); +} + +template +IGL_INLINE void igl::boundary_facets( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& F) +{ + Eigen::VectorXi J,K; + return boundary_facets(T,F,J,K); +} + +template +Ret igl::boundary_facets( + const Eigen::MatrixBase& T) +{ + Ret F; + igl::boundary_facets(T,F); + return F; +} + +template +IGL_INLINE void igl::boundary_facets( + const std::vector > & T, + std::vector > & F) +{ + // Kept for legacy reasons. Could probably just delete. + using namespace std; + + if(T.size() == 0) + { + F.clear(); + return; + } + + int simplex_size = T[0].size(); + // Get a list of all faces + vector > allF( + T.size()*simplex_size, + vector(simplex_size-1)); + + // Gather faces, loop over tets + for(int i = 0; i< (int)T.size();i++) + { + assert((int)T[i].size() == simplex_size); + switch(simplex_size) + { + case 4: + // get face in correct order + allF[i*simplex_size+0][0] = T[i][1]; + allF[i*simplex_size+0][1] = T[i][3]; + allF[i*simplex_size+0][2] = T[i][2]; + // get face in correct order + allF[i*simplex_size+1][0] = T[i][0]; + allF[i*simplex_size+1][1] = T[i][2]; + allF[i*simplex_size+1][2] = T[i][3]; + // get face in correct order + allF[i*simplex_size+2][0] = T[i][0]; + allF[i*simplex_size+2][1] = T[i][3]; + allF[i*simplex_size+2][2] = T[i][1]; + // get face in correct order + allF[i*simplex_size+3][0] = T[i][0]; + allF[i*simplex_size+3][1] = T[i][1]; + allF[i*simplex_size+3][2] = T[i][2]; + break; + case 3: + allF[i*simplex_size+0][0] = T[i][1]; + allF[i*simplex_size+0][1] = T[i][2]; + allF[i*simplex_size+1][0] = T[i][2]; + allF[i*simplex_size+1][1] = T[i][0]; + allF[i*simplex_size+2][0] = T[i][0]; + allF[i*simplex_size+2][1] = T[i][1]; + break; + } + } + + // Counts + vector C; + face_occurrences(allF,C); + + // Q: Why not just count the number of ones? + // A: because we are including non-manifold edges as boundary edges + int twos = (int) count(C.begin(),C.end(),2); + //int ones = (int) count(C.begin(),C.end(),1); + // Resize output to fit number of ones + F.resize(allF.size() - twos); + //F.resize(ones); + int k = 0; + for(int i = 0;i< (int)allF.size();i++) + { + if(C[i] != 2) + { + assert(k<(int)F.size()); + F[k] = allF[i]; + k++; + } + } + assert(k==(int)F.size()); + //if(k != F.size()) + //{ + // printf("%d =? %d\n",k,F.size()); + //} + +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::boundary_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::boundary_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::boundary_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::boundary_facets(std::vector >, std::allocator > > > const&, std::vector >, std::allocator > > >&); +//template Eigen::MatrixBase > igl::boundary_facets(Eigen::PlainObjectBase > const&); +template Eigen::Matrix igl::boundary_facets, Eigen::Matrix >(Eigen::MatrixBase > const&); +template void igl::boundary_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/boundary_loop.h b/vendor/libigl/include/igl/boundary_loop.h new file mode 100644 index 0000000000000000000000000000000000000000..f60ff70984d23131aa011f0abd8c6e74f2ba87c5 --- /dev/null +++ b/vendor/libigl/include/igl/boundary_loop.h @@ -0,0 +1,66 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Stefan Brugger +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_BOUNDARY_LOOP_H +#define IGL_BOUNDARY_LOOP_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Compute list of ordered boundary loops for a manifold mesh. + // + // Templates: + // Index index type + // Inputs: + // F #V by dim list of mesh faces + // Outputs: + // L list of loops where L[i] = ordered list of boundary vertices in loop i + // + template + IGL_INLINE void boundary_loop( + const Eigen::MatrixBase& F, + std::vector >& L); + + + // Compute ordered boundary loops for a manifold mesh and return the + // longest loop in terms of vertices. + // + // Templates: + // Index index type + // Inputs: + // F #V by dim list of mesh faces + // Outputs: + // L ordered list of boundary vertices of longest boundary loop + // + template + IGL_INLINE void boundary_loop( + const Eigen::MatrixBase& F, + std::vector& L); + + // Compute ordered boundary loops for a manifold mesh and return the + // longest loop in terms of vertices. + // + // Templates: + // Index index type + // Inputs: + // F #V by dim list of mesh faces + // Outputs: + // L ordered list of boundary vertices of longest boundary loop + // + template + IGL_INLINE void boundary_loop( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& L); +} + +#ifndef IGL_STATIC_LIBRARY +# include "boundary_loop.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/bounding_box_diagonal.cpp b/vendor/libigl/include/igl/bounding_box_diagonal.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1023abb50689f23ef454a05e76158e75d3c19e4c --- /dev/null +++ b/vendor/libigl/include/igl/bounding_box_diagonal.cpp @@ -0,0 +1,26 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "bounding_box_diagonal.h" +#include "mat_max.h" +#include "mat_min.h" +#include + +IGL_INLINE double igl::bounding_box_diagonal( + const Eigen::MatrixXd & V) +{ + using namespace Eigen; + VectorXd maxV,minV; + VectorXi maxVI,minVI; + mat_max(V,1,maxV,maxVI); + mat_min(V,1,minV,minVI); + return sqrt((maxV-minV).array().square().sum()); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/canonical_quaternions.h b/vendor/libigl/include/igl/canonical_quaternions.h new file mode 100644 index 0000000000000000000000000000000000000000..86d90112ddd32b757c39e030083775d9df84182f --- /dev/null +++ b/vendor/libigl/include/igl/canonical_quaternions.h @@ -0,0 +1,129 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CANONICAL_QUATERNIONS_H +#define IGL_CANONICAL_QUATERNIONS_H +#include "igl_inline.h" +// Define some canonical quaternions for floats and doubles +// A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), +// such that q = x*i + y*j + z*k + w +namespace igl +{ + // Float versions +#define SQRT_2_OVER_2 0.707106781f + // Identity + const float IDENTITY_QUAT_F[4] = {0,0,0,1}; + // The following match the Matlab canonical views + // X point right, Y pointing up and Z point out + const float XY_PLANE_QUAT_F[4] = {0,0,0,1}; + // X points right, Y points *in* and Z points up + const float XZ_PLANE_QUAT_F[4] = {-SQRT_2_OVER_2,0,0,SQRT_2_OVER_2}; + // X points out, Y points right, and Z points up + const float YZ_PLANE_QUAT_F[4] = {-0.5,-0.5,-0.5,0.5}; + const float CANONICAL_VIEW_QUAT_F[][4] = + { + { 0, 0, 0, 1}, // 0 + { 0, 0, SQRT_2_OVER_2, SQRT_2_OVER_2}, // 1 + { 0, 0, 1, 0}, // 2 + { 0, 0, SQRT_2_OVER_2,-SQRT_2_OVER_2}, // 3 + + { 0, -1, 0, 0}, // 4 + {-SQRT_2_OVER_2, SQRT_2_OVER_2, 0, 0}, // 5 + { -1, 0, 0, 0}, // 6 + {-SQRT_2_OVER_2,-SQRT_2_OVER_2, 0, 0}, // 7 + + { -0.5, -0.5, -0.5, 0.5}, // 8 + { 0,-SQRT_2_OVER_2, 0, SQRT_2_OVER_2}, // 9 + { 0.5, -0.5, 0.5, 0.5}, // 10 + { SQRT_2_OVER_2, 0, SQRT_2_OVER_2, 0}, // 11 + + { SQRT_2_OVER_2, 0,-SQRT_2_OVER_2, 0}, // 12 + { 0.5, 0.5, -0.5, 0.5}, // 13 + { 0, SQRT_2_OVER_2, 0, SQRT_2_OVER_2}, // 14 + { -0.5, 0.5, 0.5, 0.5}, // 15 + + { 0, SQRT_2_OVER_2, SQRT_2_OVER_2, 0}, // 16 + { -0.5, 0.5, 0.5, -0.5}, // 17 + {-SQRT_2_OVER_2, 0, 0,-SQRT_2_OVER_2}, // 18 + { -0.5, -0.5, -0.5, -0.5}, // 19 + + {-SQRT_2_OVER_2, 0, 0, SQRT_2_OVER_2}, // 20 + { -0.5, -0.5, 0.5, 0.5}, // 21 + { 0,-SQRT_2_OVER_2, SQRT_2_OVER_2, 0}, // 22 + { 0.5, -0.5, 0.5, -0.5} // 23 + }; +#undef SQRT_2_OVER_2 + // Double versions +#define SQRT_2_OVER_2 0.70710678118654757 + // Identity + const double IDENTITY_QUAT_D[4] = {0,0,0,1}; + // The following match the Matlab canonical views + // X point right, Y pointing up and Z point out + const double XY_PLANE_QUAT_D[4] = {0,0,0,1}; + // X points right, Y points *in* and Z points up + const double XZ_PLANE_QUAT_D[4] = {-SQRT_2_OVER_2,0,0,SQRT_2_OVER_2}; + // X points out, Y points right, and Z points up + const double YZ_PLANE_QUAT_D[4] = {-0.5,-0.5,-0.5,0.5}; + const double CANONICAL_VIEW_QUAT_D[][4] = + { + { 0, 0, 0, 1}, + { 0, 0, SQRT_2_OVER_2, SQRT_2_OVER_2}, + { 0, 0, 1, 0}, + { 0, 0, SQRT_2_OVER_2,-SQRT_2_OVER_2}, + + { 0, -1, 0, 0}, + {-SQRT_2_OVER_2, SQRT_2_OVER_2, 0, 0}, + { -1, 0, 0, 0}, + {-SQRT_2_OVER_2,-SQRT_2_OVER_2, 0, 0}, + + { -0.5, -0.5, -0.5, 0.5}, + { 0,-SQRT_2_OVER_2, 0, SQRT_2_OVER_2}, + { 0.5, -0.5, 0.5, 0.5}, + { SQRT_2_OVER_2, 0, SQRT_2_OVER_2, 0}, + + { SQRT_2_OVER_2, 0,-SQRT_2_OVER_2, 0}, + { 0.5, 0.5, -0.5, 0.5}, + { 0, SQRT_2_OVER_2, 0, SQRT_2_OVER_2}, + { -0.5, 0.5, 0.5, 0.5}, + + { 0, SQRT_2_OVER_2, SQRT_2_OVER_2, 0}, + { -0.5, 0.5, 0.5, -0.5}, + {-SQRT_2_OVER_2, 0, 0,-SQRT_2_OVER_2}, + { -0.5, -0.5, -0.5, -0.5}, + + {-SQRT_2_OVER_2, 0, 0, SQRT_2_OVER_2}, + { -0.5, -0.5, 0.5, 0.5}, + { 0,-SQRT_2_OVER_2, SQRT_2_OVER_2, 0}, + { 0.5, -0.5, 0.5, -0.5} + }; +#undef SQRT_2_OVER_2 +#define NUM_CANONICAL_VIEW_QUAT 24 + + // NOTE: I want to rather be able to return a Q_type[][] but C++ is not + // making it easy. So instead I've written a per-element accessor + + // Return element [i][j] of the corresponding CANONICAL_VIEW_QUAT_* of the + // given templated type + // Inputs: + // i index of quaternion + // j index of coordinate in quaternion i + // Returns values of CANONICAL_VIEW_QUAT_*[i][j] + template + IGL_INLINE Q_type CANONICAL_VIEW_QUAT(int i, int j); + // Template specializations for float and double + template <> + IGL_INLINE float CANONICAL_VIEW_QUAT(int i, int j); + template <> + IGL_INLINE double CANONICAL_VIEW_QUAT(int i, int j); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "canonical_quaternions.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cat.cpp b/vendor/libigl/include/igl/cat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5bc206715df5a72dabd3f585e58e31002457a1f --- /dev/null +++ b/vendor/libigl/include/igl/cat.cpp @@ -0,0 +1,340 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cat.h" + +#include + +// Bug in unsupported/Eigen/SparseExtra needs iostream first +#include +#include + + +// Sparse matrices need to be handled carefully. Because C++ does not +// Template: +// Scalar sparse matrix scalar type, e.g. double +template +IGL_INLINE void igl::cat( + const int dim, + const Eigen::SparseMatrix & A, + const Eigen::SparseMatrix & B, + Eigen::SparseMatrix & C) +{ + + assert(dim == 1 || dim == 2); + using namespace Eigen; + // Special case if B or A is empty + if(A.size() == 0) + { + C = B; + return; + } + if(B.size() == 0) + { + C = A; + return; + } + +#if false + // This **must** be DynamicSparseMatrix, otherwise this implementation is + // insanely slow + DynamicSparseMatrix dyn_C; + if(dim == 1) + { + assert(A.cols() == B.cols()); + dyn_C.resize(A.rows()+B.rows(),A.cols()); + }else if(dim == 2) + { + assert(A.rows() == B.rows()); + dyn_C.resize(A.rows(),A.cols()+B.cols()); + }else + { + fprintf(stderr,"cat.h: Error: Unsupported dimension %d\n",dim); + } + + dyn_C.reserve(A.nonZeros()+B.nonZeros()); + + // Iterate over outside of A + for(int k=0; k::InnerIterator it (A,k); it; ++it) + { + dyn_C.coeffRef(it.row(),it.col()) += it.value(); + } + } + + // Iterate over outside of B + for(int k=0; k::InnerIterator it (B,k); it; ++it) + { + int r = (dim == 1 ? A.rows()+it.row() : it.row()); + int c = (dim == 2 ? A.cols()+it.col() : it.col()); + dyn_C.coeffRef(r,c) += it.value(); + } + } + + C = SparseMatrix(dyn_C); +#elif false + std::vector > CIJV; + CIJV.reserve(A.nonZeros() + B.nonZeros()); + { + // Iterate over outside of A + for(int k=0; k::InnerIterator it (A,k); it; ++it) + { + CIJV.emplace_back(it.row(),it.col(),it.value()); + } + } + // Iterate over outside of B + for(int k=0; k::InnerIterator it (B,k); it; ++it) + { + int r = (dim == 1 ? A.rows()+it.row() : it.row()); + int c = (dim == 2 ? A.cols()+it.col() : it.col()); + CIJV.emplace_back(r,c,it.value()); + } + } + + } + + C = SparseMatrix( + dim == 1 ? A.rows()+B.rows() : A.rows(), + dim == 1 ? A.cols() : A.cols()+B.cols()); + C.reserve(A.nonZeros() + B.nonZeros()); + C.setFromTriplets(CIJV.begin(),CIJV.end()); +#else + C = SparseMatrix( + dim == 1 ? A.rows()+B.rows() : A.rows(), + dim == 1 ? A.cols() : A.cols()+B.cols()); + Eigen::VectorXi per_col = Eigen::VectorXi::Zero(C.cols()); + if(dim == 1) + { + assert(A.outerSize() == B.outerSize()); + for(int k = 0;k::InnerIterator it (A,k); it; ++it) + { + per_col(k)++; + } + for(typename SparseMatrix::InnerIterator it (B,k); it; ++it) + { + per_col(k)++; + } + } + }else + { + for(int k = 0;k::InnerIterator it (A,k); it; ++it) + { + per_col(k)++; + } + } + for(int k = 0;k::InnerIterator it (B,k); it; ++it) + { + per_col(A.cols() + k)++; + } + } + } + C.reserve(per_col); + if(dim == 1) + { + for(int k = 0;k::InnerIterator it (A,k); it; ++it) + { + C.insert(it.row(),k) = it.value(); + } + for(typename SparseMatrix::InnerIterator it (B,k); it; ++it) + { + C.insert(A.rows()+it.row(),k) = it.value(); + } + } + }else + { + for(int k = 0;k::InnerIterator it (A,k); it; ++it) + { + C.insert(it.row(),k) = it.value(); + } + } + for(int k = 0;k::InnerIterator it (B,k); it; ++it) + { + C.insert(it.row(),A.cols()+k) = it.value(); + } + } + } + C.makeCompressed(); + +#endif + +} + +template +IGL_INLINE void igl::cat( + const int dim, + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + MatC & C) +{ + assert(dim == 1 || dim == 2); + // Special case if B or A is empty + if(A.size() == 0) + { + C = B; + return; + } + if(B.size() == 0) + { + C = A; + return; + } + + if(dim == 1) + { + assert(A.cols() == B.cols()); + C.resize(A.rows()+B.rows(),A.cols()); + C << A,B; + }else if(dim == 2) + { + assert(A.rows() == B.rows()); + C.resize(A.rows(),A.cols()+B.cols()); + C << A,B; + }else + { + fprintf(stderr,"cat.h: Error: Unsupported dimension %d\n",dim); + } +} + +template +IGL_INLINE Mat igl::cat(const int dim, const Mat & A, const Mat & B) +{ + assert(dim == 1 || dim == 2); + Mat C; + igl::cat(dim,A,B,C); + return C; +} + +template +IGL_INLINE void igl::cat(const std::vector > & A, Mat & C) +{ + using namespace std; + // Start with empty matrix + C.resize(0,0); + for(const auto & row_vec : A) + { + // Concatenate each row horizontally + // Start with empty matrix + Mat row(0,0); + for(const auto & element : row_vec) + { + row = cat(2,row,element); + } + // Concatenate rows vertically + C = cat(1,C,row); + } +} + +template +IGL_INLINE void igl::cat(const int dim, const std::vector & A, Eigen::PlainObjectBase & C) +{ + assert(dim == 1 || dim == 2); + using namespace Eigen; + + const int num_mat = A.size(); + if(num_mat == 0) + { + C.resize(0,0); + return; + } + + if(dim == 1) + { + const int A_cols = A[0].cols(); + + int tot_rows = 0; + for(const auto & m : A) + { + tot_rows += m.rows(); + } + + C.resize(tot_rows, A_cols); + + int cur_row = 0; + for(int i = 0; i < num_mat; i++) + { + assert(A_cols == A[i].cols()); + C.block(cur_row,0,A[i].rows(),A_cols) = A[i]; + cur_row += A[i].rows(); + } + } + else if(dim == 2) + { + const int A_rows = A[0].rows(); + + int tot_cols = 0; + for(const auto & m : A) + { + tot_cols += m.cols(); + } + + C.resize(A_rows,tot_cols); + + int cur_col = 0; + for(int i = 0; i < num_mat; i++) + { + assert(A_rows == A[i].rows()); + C.block(0,cur_col,A_rows,A[i].cols()) = A[i]; + cur_col += A[i].cols(); + } + } + else + { + fprintf(stderr,"cat.h: Error: Unsupported dimension %d\n",dim); + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template Eigen::Matrix igl::cat >(int, Eigen::Matrix const&, Eigen::Matrix const&); +// generated by autoexplicit.sh +template Eigen::SparseMatrix igl::cat >(int, Eigen::SparseMatrix const&, Eigen::SparseMatrix const&); +// generated by autoexplicit.sh +template Eigen::Matrix igl::cat >(int, Eigen::Matrix const&, Eigen::Matrix const&); +template void igl::cat, Eigen::Matrix >(int, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix&); +template Eigen::Matrix igl::cat >(int, Eigen::Matrix const&, Eigen::Matrix const&); +template Eigen::Matrix igl::cat >(int, Eigen::Matrix const&, Eigen::Matrix const&); +template void igl::cat, Eigen::Matrix >(int, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix&); +template void igl::cat, Eigen::Matrix >(int, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix&); +template void igl::cat, Eigen::Matrix >(int, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template void igl::cat, Eigen::Matrix >(int, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/cat.h b/vendor/libigl/include/igl/cat.h new file mode 100644 index 0000000000000000000000000000000000000000..7a2bcff7d4e7ac5e318696316178e40eaf8d06fc --- /dev/null +++ b/vendor/libigl/include/igl/cat.h @@ -0,0 +1,82 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CAT_H +#define IGL_CAT_H +#include "igl_inline.h" + +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +#include + +namespace igl +{ + // If you're using Dense matrices you might be better off using the << operator + + // This is an attempt to act like matlab's cat function. + + // Perform concatenation of a two matrices along a single dimension + // If dim == 1, then C = [A;B]. If dim == 2 then C = [A B] + // + // Template: + // Scalar scalar data type for sparse matrices like double or int + // Mat matrix type for all matrices (e.g. MatrixXd, SparseMatrix) + // MatC matrix type for output matrix (e.g. MatrixXd) needs to support + // resize + // Inputs: + // A first input matrix + // B second input matrix + // dim dimension along which to concatenate, 1 or 2 + // Outputs: + // C output matrix + // + template + IGL_INLINE void cat( + const int dim, + const Eigen::SparseMatrix & A, + const Eigen::SparseMatrix & B, + Eigen::SparseMatrix & C); + template + IGL_INLINE void cat( + const int dim, + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + MatC & C); + // Wrapper that returns C + template + IGL_INLINE Mat cat(const int dim, const Mat & A, const Mat & B); + + // Note: Maybe we can autogenerate a bunch of overloads D = cat(int,A,B,C), + // E = cat(int,A,B,C,D), etc. + + // Concatenate a "matrix" of blocks + // C = [A0;A1;A2;...;An] where Ai = [A[i][0] A[i][1] ... A[i][m]]; + // + // Inputs: + // A a matrix (vector of row vectors) + // Output: + // C + template + IGL_INLINE void cat(const std::vector > & A, Mat & C); + + // Concatenate a std::vector of matrices along the specified dimension + // + // Inputs: + // dim dimension along which to concatenate, 1 or 2 + // A std::vector of eigen matrices. Must have identical # cols if dim == 1 or rows if dim == 2 + // Outputs: + // C output matrix + template + IGL_INLINE void cat(const int dim, const std::vector & A, Eigen::PlainObjectBase & C); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cat.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/ceil.cpp b/vendor/libigl/include/igl/ceil.cpp new file mode 100644 index 0000000000000000000000000000000000000000..278269ab23dfb5cdbf499c6e7f4d3691c08a6222 --- /dev/null +++ b/vendor/libigl/include/igl/ceil.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ceil.h" +#include + +template < typename DerivedX, typename DerivedY> +IGL_INLINE void igl::ceil( + const Eigen::PlainObjectBase& X, + Eigen::PlainObjectBase& Y) +{ + using namespace std; + //Y = DerivedY::Zero(m,n); +//#pragma omp parallel for + //for(int i = 0;iScalar{return std::ceil(x);}).template cast(); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::ceil, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/centroid.cpp b/vendor/libigl/include/igl/centroid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..588f0665e09db447fa57e92913b6d1bdf85d4e42 --- /dev/null +++ b/vendor/libigl/include/igl/centroid.cpp @@ -0,0 +1,72 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "centroid.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename Derivedc, + typename Derivedvol> +IGL_INLINE void igl::centroid( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& cen, + Derivedvol & vol) +{ + using namespace Eigen; + assert(F.cols() == 3 && "F should contain triangles."); + assert(V.cols() == 3 && "V should contain 3d points."); + const int m = F.rows(); + cen.setZero(); + vol = 0; + // loop over faces + for(int f = 0;f RowVector3S; + const RowVector3S & a = V.row(F(f,0)); + const RowVector3S & b = V.row(F(f,1)); + const RowVector3S & c = V.row(F(f,2)); + // un-normalized normal + const RowVector3S & n = (b-a).cross(c-a); + // total volume via divergence theorem: ∫ 1 + vol += n.dot(a)/6.; + // centroid via divergence theorem and midpoint quadrature: ∫ x + cen.array() += (1./24.*n.array()*((a+b).array().square() + (b+c).array().square() + + (c+a).array().square()).array()); + } + cen *= 1./(2.*vol); +} + +template < + typename DerivedV, + typename DerivedF, + typename Derivedc> +IGL_INLINE void igl::centroid( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& c) +{ + typename Derivedc::Scalar vol; + return centroid(V,F,c,vol); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::centroid, Eigen::Matrix, Eigen::Matrix, float>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, float&); +// generated by autoexplicit.sh +template void igl::centroid, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::centroid, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::centroid, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::centroid, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/centroid.h b/vendor/libigl/include/igl/centroid.h new file mode 100644 index 0000000000000000000000000000000000000000..31fa7ae6ba1c07f7a552b97501fc5abcb848a560 --- /dev/null +++ b/vendor/libigl/include/igl/centroid.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CENTROID_H +#define IGL_CENTROID_H +#include "igl_inline.h" +#include +namespace igl +{ + // CENTROID Computes the centroid of a closed mesh using a surface integral. + // + // Inputs: + // V #V by dim list of rest domain positions + // F #F by 3 list of triangle indices into V + // Outputs: + // c dim vector of centroid coordinates + // vol total volume of solid. + // + template < + typename DerivedV, + typename DerivedF, + typename Derivedc, + typename Derivedvol> + IGL_INLINE void centroid( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& c, + Derivedvol & vol); + template < + typename DerivedV, + typename DerivedF, + typename Derivedc> + IGL_INLINE void centroid( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& c); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "centroid.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/circumradius.cpp b/vendor/libigl/include/igl/circumradius.cpp new file mode 100644 index 0000000000000000000000000000000000000000..88fcbf39a8366a13fd1a0cd2f8314684d26915f9 --- /dev/null +++ b/vendor/libigl/include/igl/circumradius.cpp @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "circumradius.h" +#include "edge_lengths.h" +#include "doublearea.h" +template < + typename DerivedV, + typename DerivedF, + typename DerivedR> +IGL_INLINE void igl::circumradius( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & R) +{ + Eigen::Matrix l; + igl::edge_lengths(V,F,l); + DerivedR A; + igl::doublearea(l,0.,A); + // use formula: R=abc/(4*area) to compute the circum radius + R = l.col(0).array() * l.col(1).array() * l.col(2).array() / (2.0*A.array()); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::circumradius, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/circumradius.h b/vendor/libigl/include/igl/circumradius.h new file mode 100644 index 0000000000000000000000000000000000000000..e8187cb045835e69c04f2c707317c542b34fa006 --- /dev/null +++ b/vendor/libigl/include/igl/circumradius.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CIRCUMRADIUS_H +#define IGL_CIRCUMRADIUS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute the circumradius of each triangle in a mesh (V,F) + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by 3 list of triangle indices into V + // Outputs: + // R #F list of circumradius + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedR> + IGL_INLINE void circumradius( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & R); +} +#ifndef IGL_STATIC_LIBRARY +# include "circumradius.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/collapse_edge.cpp b/vendor/libigl/include/igl/collapse_edge.cpp new file mode 100644 index 0000000000000000000000000000000000000000..268a1046af1eba376ad31c8d29dfbc241c52f6a0 --- /dev/null +++ b/vendor/libigl/include/igl/collapse_edge.cpp @@ -0,0 +1,373 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "collapse_edge.h" +#include "circulation.h" +#include "edge_collapse_is_valid.h" +#include "decimate_trivial_callbacks.h" +#include + +IGL_INLINE bool igl::collapse_edge( + const int e, + const Eigen::RowVectorXd & p, + Eigen::MatrixXd & V, + Eigen::MatrixXi & F, + Eigen::MatrixXi & E, + Eigen::VectorXi & EMAP, + Eigen::MatrixXi & EF, + Eigen::MatrixXi & EI, + int & e1, + int & e2, + int & f1, + int & f2) +{ + std::vector /*Nse,*/Nsf,Nsv; + circulation(e, true,F,EMAP,EF,EI,/*Nse,*/Nsv,Nsf); + std::vector /*Nde,*/Ndf,Ndv; + circulation(e, false,F,EMAP,EF,EI,/*Nde,*/Ndv,Ndf); + return collapse_edge( + e,p,Nsv,Nsf,Ndv,Ndf,V,F,E,EMAP,EF,EI,e1,e2,f1,f2); +} + +IGL_INLINE bool igl::collapse_edge( + const int e, + const Eigen::RowVectorXd & p, + /*const*/ std::vector & Nsv, + const std::vector & Nsf, + /*const*/ std::vector & Ndv, + const std::vector & Ndf, + Eigen::MatrixXd & V, + Eigen::MatrixXi & F, + Eigen::MatrixXi & E, + Eigen::VectorXi & EMAP, + Eigen::MatrixXi & EF, + Eigen::MatrixXi & EI, + int & a_e1, + int & a_e2, + int & a_f1, + int & a_f2) +{ + // Assign this to 0 rather than, say, -1 so that deleted elements will get + // draw as degenerate elements at vertex 0 (which should always exist and + // never get collapsed to anything else since it is the smallest index) + using namespace Eigen; + using namespace std; + const int eflip = E(e,0)>E(e,1); + // source and destination + const int s = eflip?E(e,1):E(e,0); + const int d = eflip?E(e,0):E(e,1); + + if(!edge_collapse_is_valid(Nsv,Ndv)) + { + return false; + } + + // OVERLOAD: caller may have just computed this + // + // Important to grab neighbors of d before monkeying with edges + const std::vector & nV2Fd = (!eflip ? Nsf : Ndf); + + // The following implementation strongly relies on s > & Q, + Eigen::VectorXi & EQ, + Eigen::MatrixXd & C) +{ + int e,e1,e2,f1,f2; + decimate_pre_collapse_callback always_try; + decimate_post_collapse_callback never_care; + decimate_trivial_callbacks(always_try,never_care); + return + collapse_edge( + cost_and_placement,always_try,never_care, + V,F,E,EMAP,EF,EI,Q,EQ,C,e,e1,e2,f1,f2); +} + +IGL_INLINE bool igl::collapse_edge( + const decimate_cost_and_placement_callback & cost_and_placement, + const decimate_pre_collapse_callback & pre_collapse, + const decimate_post_collapse_callback & post_collapse, + Eigen::MatrixXd & V, + Eigen::MatrixXi & F, + Eigen::MatrixXi & E, + Eigen::VectorXi & EMAP, + Eigen::MatrixXi & EF, + Eigen::MatrixXi & EI, + igl::min_heap< std::tuple > & Q, + Eigen::VectorXi & EQ, + Eigen::MatrixXd & C) +{ + int e,e1,e2,f1,f2; + return + collapse_edge( + cost_and_placement,pre_collapse,post_collapse, + V,F,E,EMAP,EF,EI,Q,EQ,C,e,e1,e2,f1,f2); +} + + +IGL_INLINE bool igl::collapse_edge( + const decimate_cost_and_placement_callback & cost_and_placement, + const decimate_pre_collapse_callback & pre_collapse, + const decimate_post_collapse_callback & post_collapse, + Eigen::MatrixXd & V, + Eigen::MatrixXi & F, + Eigen::MatrixXi & E, + Eigen::VectorXi & EMAP, + Eigen::MatrixXi & EF, + Eigen::MatrixXi & EI, + igl::min_heap< std::tuple > & Q, + Eigen::VectorXi & EQ, + Eigen::MatrixXd & C, + int & e, + int & e1, + int & e2, + int & f1, + int & f2) +{ + using namespace Eigen; + using namespace igl; + std::tuple p; + while(true) + { + // Check if Q is empty + if(Q.empty()) + { + // no edges to collapse + e = -1; + return false; + } + // pop from Q + p = Q.top(); + if(std::get<0>(p) == std::numeric_limits::infinity()) + { + e = -1; + // min cost edge is infinite cost + return false; + } + Q.pop(); + e = std::get<1>(p); + // Check if matches timestamp + if(std::get<2>(p) == EQ(e)) + { + break; + } + // must be stale or dead. + assert(std::get<2>(p) < EQ(e) || EQ(e) == -1); + // try again. + } + + // Why is this computed up here? + // If we just need original face neighbors of edge, could we gather that more + // directly than gathering face neighbors of each vertex? + std::vector /*Nse,*/Nsf,Nsv; + circulation(e, true,F,EMAP,EF,EI,/*Nse,*/Nsv,Nsf); + std::vector /*Nde,*/Ndf,Ndv; + circulation(e, false,F,EMAP,EF,EI,/*Nde,*/Ndv,Ndf); + + + bool collapsed = true; + if(pre_collapse(V,F,E,EMAP,EF,EI,Q,EQ,C,e)) + { + collapsed = collapse_edge( + e,C.row(e), + Nsv,Nsf,Ndv,Ndf, + V,F,E,EMAP,EF,EI,e1,e2,f1,f2); + }else + { + // Aborted by pre collapse callback + collapsed = false; + } + post_collapse(V,F,E,EMAP,EF,EI,Q,EQ,C,e,e1,e2,f1,f2,collapsed); + if(collapsed) + { + // Erase the two, other collapsed edges by marking their timestamps as -1 + EQ(e1) = -1; + EQ(e2) = -1; + // TODO: visits edges multiple times, ~150% more updates than should + // + // update local neighbors + // loop over original face neighbors + // + // Can't use previous computed Nse and Nde because those refer to EMAP + // before it was changed... + std::vector Nf; + Nf.reserve( Nsf.size() + Ndf.size() ); // preallocate memory + Nf.insert( Nf.end(), Nsf.begin(), Nsf.end() ); + Nf.insert( Nf.end(), Ndf.begin(), Ndf.end() ); + // https://stackoverflow.com/a/1041939/148668 + std::sort( Nf.begin(), Nf.end() ); + Nf.erase( std::unique( Nf.begin(), Nf.end() ), Nf.end() ); + // Collect all edges that must be updated + std::vector Ne; + Ne.reserve(3*Nf.size()); + for(auto & n : Nf) + { + if(F(n,0) != IGL_COLLAPSE_EDGE_NULL || + F(n,1) != IGL_COLLAPSE_EDGE_NULL || + F(n,2) != IGL_COLLAPSE_EDGE_NULL) + { + for(int v = 0;v<3;v++) + { + // get edge id + const int ei = EMAP(v*F.rows()+n); + Ne.push_back(ei); + } + } + } + // Only process edge once + std::sort( Ne.begin(), Ne.end() ); + Ne.erase( std::unique( Ne.begin(), Ne.end() ), Ne.end() ); + for(auto & ei : Ne) + { + // compute cost and potential placement + double cost; + RowVectorXd place; + cost_and_placement(ei,V,F,E,EMAP,EF,EI,cost,place); + // Increment timestamp + EQ(ei)++; + // Replace in queue + Q.emplace(cost,ei,EQ(ei)); + C.row(ei) = place; + } + }else + { + // reinsert with infinite weight (the provided cost function must **not** + // have given this un-collapsable edge inf cost already) + // Increment timestamp + EQ(e)++; + // Replace in queue + Q.emplace(std::numeric_limits::infinity(),e,EQ(e)); + } + return collapsed; +} diff --git a/vendor/libigl/include/igl/collapse_small_triangles.cpp b/vendor/libigl/include/igl/collapse_small_triangles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5177c584f084dbb53a097e9e45f9aee00c9afcae --- /dev/null +++ b/vendor/libigl/include/igl/collapse_small_triangles.cpp @@ -0,0 +1,139 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "collapse_small_triangles.h" + +#include "bounding_box_diagonal.h" +#include "doublearea.h" +#include "edge_lengths.h" +#include "colon.h" +#include "faces_first.h" + +#include + +#include + +void igl::collapse_small_triangles( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const double eps, + Eigen::MatrixXi & FF) +{ + using namespace Eigen; + using namespace std; + + // Compute bounding box diagonal length + double bbd = bounding_box_diagonal(V); + MatrixXd l; + edge_lengths(V,F,l); + VectorXd dblA; + doublearea(l,0.,dblA); + + // Minimum area tolerance + const double min_dblarea = 2.0*eps*bbd*bbd; + + Eigen::VectorXi FIM = colon(0,V.rows()-1); + int num_edge_collapses = 0; + // Loop over triangles + for(int f = 0;fmaxl) + { + maxli = e; + maxl = l(f,e); + } + } + // Be sure that min and max aren't the same + maxli = (minli==maxli?(minli+1)%3:maxli); + + // Collapse min edge maintaining max edge: i-->j + // Q: Why this direction? + int i = maxli; + int j = ((minli+1)%3 == maxli ? (minli+2)%3: (minli+1)%3); + assert(i != minli); + assert(j != minli); + assert(i != j); + FIM(F(f,i)) = FIM(F(f,j)); + num_edge_collapses++; + } + } + + // Reindex faces + MatrixXi rF = F; + // Loop over triangles + for(int f = 0;f +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "colon.h" +#include "LinSpaced.h" + +#include + +template +IGL_INLINE void igl::colon( + const L low, + const S step, + const H hi, + Eigen::Matrix & I) +{ + const H size = ((hi-low)/step)+1; + I = igl::LinSpaced >(size,low,low+step*(size-1)); +} + +template +IGL_INLINE void igl::colon( + const L low, + const H hi, + Eigen::Matrix & I) +{ + return igl::colon(low,(T)1,hi,I); +} + +template +IGL_INLINE Eigen::Matrix igl::colon( + const L low, + const H hi) +{ + Eigen::Matrix I; + igl::colon(low,hi,I); + return I; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template Eigen::Matrix igl::colon(int, int); +template Eigen::Matrix igl::colon(int, long); +template Eigen::Matrix igl::colon(int, long long int); +template Eigen::Matrix igl::colon(double, double); +template void igl::colon(int, long, Eigen::Matrix &); +// generated by autoexplicit.sh +template void igl::colon(int, long, int, Eigen::Matrix &); +template void igl::colon(int, int, long, Eigen::Matrix &); +template void igl::colon(int, long, Eigen::Matrix &); +template void igl::colon(int, int, Eigen::Matrix &); +template void igl::colon(int, long long int, Eigen::Matrix &); +template void igl::colon(int, int, int, Eigen::Matrix &); +template void igl::colon(int, long, Eigen::Matrix &); +template void igl::colon(int, double, double, Eigen::Matrix &); +template void igl::colon(double, double, Eigen::Matrix &); +template void igl::colon(double, double, double, Eigen::Matrix &); +template void igl::colon(int, int, Eigen::Matrix &); +template void igl::colon(int, int, Eigen::Matrix &); +#ifdef WIN32 +template void igl::colon(int, __int64, class Eigen::Matrix &); +template void igl::colon(int, long long, class Eigen::Matrix &); +template void igl::colon(int, __int64, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1> &); +#endif +#endif \ No newline at end of file diff --git a/vendor/libigl/include/igl/colon.h b/vendor/libigl/include/igl/colon.h new file mode 100644 index 0000000000000000000000000000000000000000..1f2b9bf6f47540673c8c12a8149e1aff3b4f9efe --- /dev/null +++ b/vendor/libigl/include/igl/colon.h @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COLON_H +#define IGL_COLON_H +#include "igl_inline.h" +#include +namespace igl +{ + // Note: + // This should be potentially replaced with eigen's LinSpaced() function + // + // If step = 1, it's about 5 times faster to use: + // X = Eigen::VectorXi::LinSpaced(n,0,n-1); + // than + // X = igl::colon(0,n-1); + // + + // Colon operator like matlab's colon operator. Enumerats values between low + // and hi with step step. + // Templates: + // L should be a eigen matrix primitive type like int or double + // S should be a eigen matrix primitive type like int or double + // H should be a eigen matrix primitive type like int or double + // T should be a eigen matrix primitive type like int or double + // Inputs: + // low starting value if step is valid then this is *always* the first + // element of I + // step step difference between sequential elements returned in I, + // remember this will be cast to template T at compile time. If lowhi then step must be negative. + // Otherwise I will be set to empty. + // hi ending value, if (hi-low)%step is zero then this will be the last + // element in I. If step is positive there will be no elements greater + // than hi, vice versa if hi + IGL_INLINE void colon( + const L low, + const S step, + const H hi, + Eigen::Matrix & I); + // Same as above but step == (T)1 + template + IGL_INLINE void colon( + const L low, + const H hi, + Eigen::Matrix & I); + // Return output rather than set in reference + template + IGL_INLINE Eigen::Matrix colon( + const L low, + const H hi); +} + +#ifndef IGL_STATIC_LIBRARY +# include "colon.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/colormap.cpp b/vendor/libigl/include/igl/colormap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff9e433e4ae2ff70778ae07bca113354fc86de4d --- /dev/null +++ b/vendor/libigl/include/igl/colormap.cpp @@ -0,0 +1,1697 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Joe Graus , Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "colormap.h" +#include + +// One of the new matplotlib colormaps by Nathaniel J.Smith, Stefan van der Walt, and (in the case of viridis) Eric Firing. +// Released under the CC0 license / public domain dedication + +namespace igl +{ + +static double turbo_cm[256][3] = { + {0.18995,0.07176,0.23217}, + {0.19483,0.08339,0.26149}, + {0.19956,0.09498,0.29024}, + {0.20415,0.10652,0.31844}, + {0.20860,0.11802,0.34607}, + {0.21291,0.12947,0.37314}, + {0.21708,0.14087,0.39964}, + {0.22111,0.15223,0.42558}, + {0.22500,0.16354,0.45096}, + {0.22875,0.17481,0.47578}, + {0.23236,0.18603,0.50004}, + {0.23582,0.19720,0.52373}, + {0.23915,0.20833,0.54686}, + {0.24234,0.21941,0.56942}, + {0.24539,0.23044,0.59142}, + {0.24830,0.24143,0.61286}, + {0.25107,0.25237,0.63374}, + {0.25369,0.26327,0.65406}, + {0.25618,0.27412,0.67381}, + {0.25853,0.28492,0.69300}, + {0.26074,0.29568,0.71162}, + {0.26280,0.30639,0.72968}, + {0.26473,0.31706,0.74718}, + {0.26652,0.32768,0.76412}, + {0.26816,0.33825,0.78050}, + {0.26967,0.34878,0.79631}, + {0.27103,0.35926,0.81156}, + {0.27226,0.36970,0.82624}, + {0.27334,0.38008,0.84037}, + {0.27429,0.39043,0.85393}, + {0.27509,0.40072,0.86692}, + {0.27576,0.41097,0.87936}, + {0.27628,0.42118,0.89123}, + {0.27667,0.43134,0.90254}, + {0.27691,0.44145,0.91328}, + {0.27701,0.45152,0.92347}, + {0.27698,0.46153,0.93309}, + {0.27680,0.47151,0.94214}, + {0.27648,0.48144,0.95064}, + {0.27603,0.49132,0.95857}, + {0.27543,0.50115,0.96594}, + {0.27469,0.51094,0.97275}, + {0.27381,0.52069,0.97899}, + {0.27273,0.53040,0.98461}, + {0.27106,0.54015,0.98930}, + {0.26878,0.54995,0.99303}, + {0.26592,0.55979,0.99583}, + {0.26252,0.56967,0.99773}, + {0.25862,0.57958,0.99876}, + {0.25425,0.58950,0.99896}, + {0.24946,0.59943,0.99835}, + {0.24427,0.60937,0.99697}, + {0.23874,0.61931,0.99485}, + {0.23288,0.62923,0.99202}, + {0.22676,0.63913,0.98851}, + {0.22039,0.64901,0.98436}, + {0.21382,0.65886,0.97959}, + {0.20708,0.66866,0.97423}, + {0.20021,0.67842,0.96833}, + {0.19326,0.68812,0.96190}, + {0.18625,0.69775,0.95498}, + {0.17923,0.70732,0.94761}, + {0.17223,0.71680,0.93981}, + {0.16529,0.72620,0.93161}, + {0.15844,0.73551,0.92305}, + {0.15173,0.74472,0.91416}, + {0.14519,0.75381,0.90496}, + {0.13886,0.76279,0.89550}, + {0.13278,0.77165,0.88580}, + {0.12698,0.78037,0.87590}, + {0.12151,0.78896,0.86581}, + {0.11639,0.79740,0.85559}, + {0.11167,0.80569,0.84525}, + {0.10738,0.81381,0.83484}, + {0.10357,0.82177,0.82437}, + {0.10026,0.82955,0.81389}, + {0.09750,0.83714,0.80342}, + {0.09532,0.84455,0.79299}, + {0.09377,0.85175,0.78264}, + {0.09287,0.85875,0.77240}, + {0.09267,0.86554,0.76230}, + {0.09320,0.87211,0.75237}, + {0.09451,0.87844,0.74265}, + {0.09662,0.88454,0.73316}, + {0.09958,0.89040,0.72393}, + {0.10342,0.89600,0.71500}, + {0.10815,0.90142,0.70599}, + {0.11374,0.90673,0.69651}, + {0.12014,0.91193,0.68660}, + {0.12733,0.91701,0.67627}, + {0.13526,0.92197,0.66556}, + {0.14391,0.92680,0.65448}, + {0.15323,0.93151,0.64308}, + {0.16319,0.93609,0.63137}, + {0.17377,0.94053,0.61938}, + {0.18491,0.94484,0.60713}, + {0.19659,0.94901,0.59466}, + {0.20877,0.95304,0.58199}, + {0.22142,0.95692,0.56914}, + {0.23449,0.96065,0.55614}, + {0.24797,0.96423,0.54303}, + {0.26180,0.96765,0.52981}, + {0.27597,0.97092,0.51653}, + {0.29042,0.97403,0.50321}, + {0.30513,0.97697,0.48987}, + {0.32006,0.97974,0.47654}, + {0.33517,0.98234,0.46325}, + {0.35043,0.98477,0.45002}, + {0.36581,0.98702,0.43688}, + {0.38127,0.98909,0.42386}, + {0.39678,0.99098,0.41098}, + {0.41229,0.99268,0.39826}, + {0.42778,0.99419,0.38575}, + {0.44321,0.99551,0.37345}, + {0.45854,0.99663,0.36140}, + {0.47375,0.99755,0.34963}, + {0.48879,0.99828,0.33816}, + {0.50362,0.99879,0.32701}, + {0.51822,0.99910,0.31622}, + {0.53255,0.99919,0.30581}, + {0.54658,0.99907,0.29581}, + {0.56026,0.99873,0.28623}, + {0.57357,0.99817,0.27712}, + {0.58646,0.99739,0.26849}, + {0.59891,0.99638,0.26038}, + {0.61088,0.99514,0.25280}, + {0.62233,0.99366,0.24579}, + {0.63323,0.99195,0.23937}, + {0.64362,0.98999,0.23356}, + {0.65394,0.98775,0.22835}, + {0.66428,0.98524,0.22370}, + {0.67462,0.98246,0.21960}, + {0.68494,0.97941,0.21602}, + {0.69525,0.97610,0.21294}, + {0.70553,0.97255,0.21032}, + {0.71577,0.96875,0.20815}, + {0.72596,0.96470,0.20640}, + {0.73610,0.96043,0.20504}, + {0.74617,0.95593,0.20406}, + {0.75617,0.95121,0.20343}, + {0.76608,0.94627,0.20311}, + {0.77591,0.94113,0.20310}, + {0.78563,0.93579,0.20336}, + {0.79524,0.93025,0.20386}, + {0.80473,0.92452,0.20459}, + {0.81410,0.91861,0.20552}, + {0.82333,0.91253,0.20663}, + {0.83241,0.90627,0.20788}, + {0.84133,0.89986,0.20926}, + {0.85010,0.89328,0.21074}, + {0.85868,0.88655,0.21230}, + {0.86709,0.87968,0.21391}, + {0.87530,0.87267,0.21555}, + {0.88331,0.86553,0.21719}, + {0.89112,0.85826,0.21880}, + {0.89870,0.85087,0.22038}, + {0.90605,0.84337,0.22188}, + {0.91317,0.83576,0.22328}, + {0.92004,0.82806,0.22456}, + {0.92666,0.82025,0.22570}, + {0.93301,0.81236,0.22667}, + {0.93909,0.80439,0.22744}, + {0.94489,0.79634,0.22800}, + {0.95039,0.78823,0.22831}, + {0.95560,0.78005,0.22836}, + {0.96049,0.77181,0.22811}, + {0.96507,0.76352,0.22754}, + {0.96931,0.75519,0.22663}, + {0.97323,0.74682,0.22536}, + {0.97679,0.73842,0.22369}, + {0.98000,0.73000,0.22161}, + {0.98289,0.72140,0.21918}, + {0.98549,0.71250,0.21650}, + {0.98781,0.70330,0.21358}, + {0.98986,0.69382,0.21043}, + {0.99163,0.68408,0.20706}, + {0.99314,0.67408,0.20348}, + {0.99438,0.66386,0.19971}, + {0.99535,0.65341,0.19577}, + {0.99607,0.64277,0.19165}, + {0.99654,0.63193,0.18738}, + {0.99675,0.62093,0.18297}, + {0.99672,0.60977,0.17842}, + {0.99644,0.59846,0.17376}, + {0.99593,0.58703,0.16899}, + {0.99517,0.57549,0.16412}, + {0.99419,0.56386,0.15918}, + {0.99297,0.55214,0.15417}, + {0.99153,0.54036,0.14910}, + {0.98987,0.52854,0.14398}, + {0.98799,0.51667,0.13883}, + {0.98590,0.50479,0.13367}, + {0.98360,0.49291,0.12849}, + {0.98108,0.48104,0.12332}, + {0.97837,0.46920,0.11817}, + {0.97545,0.45740,0.11305}, + {0.97234,0.44565,0.10797}, + {0.96904,0.43399,0.10294}, + {0.96555,0.42241,0.09798}, + {0.96187,0.41093,0.09310}, + {0.95801,0.39958,0.08831}, + {0.95398,0.38836,0.08362}, + {0.94977,0.37729,0.07905}, + {0.94538,0.36638,0.07461}, + {0.94084,0.35566,0.07031}, + {0.93612,0.34513,0.06616}, + {0.93125,0.33482,0.06218}, + {0.92623,0.32473,0.05837}, + {0.92105,0.31489,0.05475}, + {0.91572,0.30530,0.05134}, + {0.91024,0.29599,0.04814}, + {0.90463,0.28696,0.04516}, + {0.89888,0.27824,0.04243}, + {0.89298,0.26981,0.03993}, + {0.88691,0.26152,0.03753}, + {0.88066,0.25334,0.03521}, + {0.87422,0.24526,0.03297}, + {0.86760,0.23730,0.03082}, + {0.86079,0.22945,0.02875}, + {0.85380,0.22170,0.02677}, + {0.84662,0.21407,0.02487}, + {0.83926,0.20654,0.02305}, + {0.83172,0.19912,0.02131}, + {0.82399,0.19182,0.01966}, + {0.81608,0.18462,0.01809}, + {0.80799,0.17753,0.01660}, + {0.79971,0.17055,0.01520}, + {0.79125,0.16368,0.01387}, + {0.78260,0.15693,0.01264}, + {0.77377,0.15028,0.01148}, + {0.76476,0.14374,0.01041}, + {0.75556,0.13731,0.00942}, + {0.74617,0.13098,0.00851}, + {0.73661,0.12477,0.00769}, + {0.72686,0.11867,0.00695}, + {0.71692,0.11268,0.00629}, + {0.70680,0.10680,0.00571}, + {0.69650,0.10102,0.00522}, + {0.68602,0.09536,0.00481}, + {0.67535,0.08980,0.00449}, + {0.66449,0.08436,0.00424}, + {0.65345,0.07902,0.00408}, + {0.64223,0.07380,0.00401}, + {0.63082,0.06868,0.00401}, + {0.61923,0.06367,0.00410}, + {0.60746,0.05878,0.00427}, + {0.59550,0.05399,0.00453}, + {0.58336,0.04931,0.00486}, + {0.57103,0.04474,0.00529}, + {0.55852,0.04028,0.00579}, + {0.54583,0.03593,0.00638}, + {0.53295,0.03169,0.00705}, + {0.51989,0.02756,0.00780}, + {0.50664,0.02354,0.00863}, + {0.49321,0.01963,0.00955}, + {0.47960,0.01583,0.01055} +}; + +static double inferno_cm[256][3] = { + { 0.001462, 0.000466, 0.013866 }, + { 0.002267, 0.001270, 0.018570 }, + { 0.003299, 0.002249, 0.024239 }, + { 0.004547, 0.003392, 0.030909 }, + { 0.006006, 0.004692, 0.038558 }, + { 0.007676, 0.006136, 0.046836 }, + { 0.009561, 0.007713, 0.055143 }, + { 0.011663, 0.009417, 0.063460 }, + { 0.013995, 0.011225, 0.071862 }, + { 0.016561, 0.013136, 0.080282 }, + { 0.019373, 0.015133, 0.088767 }, + { 0.022447, 0.017199, 0.097327 }, + { 0.025793, 0.019331, 0.105930 }, + { 0.029432, 0.021503, 0.114621 }, + { 0.033385, 0.023702, 0.123397 }, + { 0.037668, 0.025921, 0.132232 }, + { 0.042253, 0.028139, 0.141141 }, + { 0.046915, 0.030324, 0.150164 }, + { 0.051644, 0.032474, 0.159254 }, + { 0.056449, 0.034569, 0.168414 }, + { 0.061340, 0.036590, 0.177642 }, + { 0.066331, 0.038504, 0.186962 }, + { 0.071429, 0.040294, 0.196354 }, + { 0.076637, 0.041905, 0.205799 }, + { 0.081962, 0.043328, 0.215289 }, + { 0.087411, 0.044556, 0.224813 }, + { 0.092990, 0.045583, 0.234358 }, + { 0.098702, 0.046402, 0.243904 }, + { 0.104551, 0.047008, 0.253430 }, + { 0.110536, 0.047399, 0.262912 }, + { 0.116656, 0.047574, 0.272321 }, + { 0.122908, 0.047536, 0.281624 }, + { 0.129285, 0.047293, 0.290788 }, + { 0.135778, 0.046856, 0.299776 }, + { 0.142378, 0.046242, 0.308553 }, + { 0.149073, 0.045468, 0.317085 }, + { 0.155850, 0.044559, 0.325338 }, + { 0.162689, 0.043554, 0.333277 }, + { 0.169575, 0.042489, 0.340874 }, + { 0.176493, 0.041402, 0.348111 }, + { 0.183429, 0.040329, 0.354971 }, + { 0.190367, 0.039309, 0.361447 }, + { 0.197297, 0.038400, 0.367535 }, + { 0.204209, 0.037632, 0.373238 }, + { 0.211095, 0.037030, 0.378563 }, + { 0.217949, 0.036615, 0.383522 }, + { 0.224763, 0.036405, 0.388129 }, + { 0.231538, 0.036405, 0.392400 }, + { 0.238273, 0.036621, 0.396353 }, + { 0.244967, 0.037055, 0.400007 }, + { 0.251620, 0.037705, 0.403378 }, + { 0.258234, 0.038571, 0.406485 }, + { 0.264810, 0.039647, 0.409345 }, + { 0.271347, 0.040922, 0.411976 }, + { 0.277850, 0.042353, 0.414392 }, + { 0.284321, 0.043933, 0.416608 }, + { 0.290763, 0.045644, 0.418637 }, + { 0.297178, 0.047470, 0.420491 }, + { 0.303568, 0.049396, 0.422182 }, + { 0.309935, 0.051407, 0.423721 }, + { 0.316282, 0.053490, 0.425116 }, + { 0.322610, 0.055634, 0.426377 }, + { 0.328921, 0.057827, 0.427511 }, + { 0.335217, 0.060060, 0.428524 }, + { 0.341500, 0.062325, 0.429425 }, + { 0.347771, 0.064616, 0.430217 }, + { 0.354032, 0.066925, 0.430906 }, + { 0.360284, 0.069247, 0.431497 }, + { 0.366529, 0.071579, 0.431994 }, + { 0.372768, 0.073915, 0.432400 }, + { 0.379001, 0.076253, 0.432719 }, + { 0.385228, 0.078591, 0.432955 }, + { 0.391453, 0.080927, 0.433109 }, + { 0.397674, 0.083257, 0.433183 }, + { 0.403894, 0.085580, 0.433179 }, + { 0.410113, 0.087896, 0.433098 }, + { 0.416331, 0.090203, 0.432943 }, + { 0.422549, 0.092501, 0.432714 }, + { 0.428768, 0.094790, 0.432412 }, + { 0.434987, 0.097069, 0.432039 }, + { 0.441207, 0.099338, 0.431594 }, + { 0.447428, 0.101597, 0.431080 }, + { 0.453651, 0.103848, 0.430498 }, + { 0.459875, 0.106089, 0.429846 }, + { 0.466100, 0.108322, 0.429125 }, + { 0.472328, 0.110547, 0.428334 }, + { 0.478558, 0.112764, 0.427475 }, + { 0.484789, 0.114974, 0.426548 }, + { 0.491022, 0.117179, 0.425552 }, + { 0.497257, 0.119379, 0.424488 }, + { 0.503493, 0.121575, 0.423356 }, + { 0.509730, 0.123769, 0.422156 }, + { 0.515967, 0.125960, 0.420887 }, + { 0.522206, 0.128150, 0.419549 }, + { 0.528444, 0.130341, 0.418142 }, + { 0.534683, 0.132534, 0.416667 }, + { 0.540920, 0.134729, 0.415123 }, + { 0.547157, 0.136929, 0.413511 }, + { 0.553392, 0.139134, 0.411829 }, + { 0.559624, 0.141346, 0.410078 }, + { 0.565854, 0.143567, 0.408258 }, + { 0.572081, 0.145797, 0.406369 }, + { 0.578304, 0.148039, 0.404411 }, + { 0.584521, 0.150294, 0.402385 }, + { 0.590734, 0.152563, 0.400290 }, + { 0.596940, 0.154848, 0.398125 }, + { 0.603139, 0.157151, 0.395891 }, + { 0.609330, 0.159474, 0.393589 }, + { 0.615513, 0.161817, 0.391219 }, + { 0.621685, 0.164184, 0.388781 }, + { 0.627847, 0.166575, 0.386276 }, + { 0.633998, 0.168992, 0.383704 }, + { 0.640135, 0.171438, 0.381065 }, + { 0.646260, 0.173914, 0.378359 }, + { 0.652369, 0.176421, 0.375586 }, + { 0.658463, 0.178962, 0.372748 }, + { 0.664540, 0.181539, 0.369846 }, + { 0.670599, 0.184153, 0.366879 }, + { 0.676638, 0.186807, 0.363849 }, + { 0.682656, 0.189501, 0.360757 }, + { 0.688653, 0.192239, 0.357603 }, + { 0.694627, 0.195021, 0.354388 }, + { 0.700576, 0.197851, 0.351113 }, + { 0.706500, 0.200728, 0.347777 }, + { 0.712396, 0.203656, 0.344383 }, + { 0.718264, 0.206636, 0.340931 }, + { 0.724103, 0.209670, 0.337424 }, + { 0.729909, 0.212759, 0.333861 }, + { 0.735683, 0.215906, 0.330245 }, + { 0.741423, 0.219112, 0.326576 }, + { 0.747127, 0.222378, 0.322856 }, + { 0.752794, 0.225706, 0.319085 }, + { 0.758422, 0.229097, 0.315266 }, + { 0.764010, 0.232554, 0.311399 }, + { 0.769556, 0.236077, 0.307485 }, + { 0.775059, 0.239667, 0.303526 }, + { 0.780517, 0.243327, 0.299523 }, + { 0.785929, 0.247056, 0.295477 }, + { 0.791293, 0.250856, 0.291390 }, + { 0.796607, 0.254728, 0.287264 }, + { 0.801871, 0.258674, 0.283099 }, + { 0.807082, 0.262692, 0.278898 }, + { 0.812239, 0.266786, 0.274661 }, + { 0.817341, 0.270954, 0.270390 }, + { 0.822386, 0.275197, 0.266085 }, + { 0.827372, 0.279517, 0.261750 }, + { 0.832299, 0.283913, 0.257383 }, + { 0.837165, 0.288385, 0.252988 }, + { 0.841969, 0.292933, 0.248564 }, + { 0.846709, 0.297559, 0.244113 }, + { 0.851384, 0.302260, 0.239636 }, + { 0.855992, 0.307038, 0.235133 }, + { 0.860533, 0.311892, 0.230606 }, + { 0.865006, 0.316822, 0.226055 }, + { 0.869409, 0.321827, 0.221482 }, + { 0.873741, 0.326906, 0.216886 }, + { 0.878001, 0.332060, 0.212268 }, + { 0.882188, 0.337287, 0.207628 }, + { 0.886302, 0.342586, 0.202968 }, + { 0.890341, 0.347957, 0.198286 }, + { 0.894305, 0.353399, 0.193584 }, + { 0.898192, 0.358911, 0.188860 }, + { 0.902003, 0.364492, 0.184116 }, + { 0.905735, 0.370140, 0.179350 }, + { 0.909390, 0.375856, 0.174563 }, + { 0.912966, 0.381636, 0.169755 }, + { 0.916462, 0.387481, 0.164924 }, + { 0.919879, 0.393389, 0.160070 }, + { 0.923215, 0.399359, 0.155193 }, + { 0.926470, 0.405389, 0.150292 }, + { 0.929644, 0.411479, 0.145367 }, + { 0.932737, 0.417627, 0.140417 }, + { 0.935747, 0.423831, 0.135440 }, + { 0.938675, 0.430091, 0.130438 }, + { 0.941521, 0.436405, 0.125409 }, + { 0.944285, 0.442772, 0.120354 }, + { 0.946965, 0.449191, 0.115272 }, + { 0.949562, 0.455660, 0.110164 }, + { 0.952075, 0.462178, 0.105031 }, + { 0.954506, 0.468744, 0.099874 }, + { 0.956852, 0.475356, 0.094695 }, + { 0.959114, 0.482014, 0.089499 }, + { 0.961293, 0.488716, 0.084289 }, + { 0.963387, 0.495462, 0.079073 }, + { 0.965397, 0.502249, 0.073859 }, + { 0.967322, 0.509078, 0.068659 }, + { 0.969163, 0.515946, 0.063488 }, + { 0.970919, 0.522853, 0.058367 }, + { 0.972590, 0.529798, 0.053324 }, + { 0.974176, 0.536780, 0.048392 }, + { 0.975677, 0.543798, 0.043618 }, + { 0.977092, 0.550850, 0.039050 }, + { 0.978422, 0.557937, 0.034931 }, + { 0.979666, 0.565057, 0.031409 }, + { 0.980824, 0.572209, 0.028508 }, + { 0.981895, 0.579392, 0.026250 }, + { 0.982881, 0.586606, 0.024661 }, + { 0.983779, 0.593849, 0.023770 }, + { 0.984591, 0.601122, 0.023606 }, + { 0.985315, 0.608422, 0.024202 }, + { 0.985952, 0.615750, 0.025592 }, + { 0.986502, 0.623105, 0.027814 }, + { 0.986964, 0.630485, 0.030908 }, + { 0.987337, 0.637890, 0.034916 }, + { 0.987622, 0.645320, 0.039886 }, + { 0.987819, 0.652773, 0.045581 }, + { 0.987926, 0.660250, 0.051750 }, + { 0.987945, 0.667748, 0.058329 }, + { 0.987874, 0.675267, 0.065257 }, + { 0.987714, 0.682807, 0.072489 }, + { 0.987464, 0.690366, 0.079990 }, + { 0.987124, 0.697944, 0.087731 }, + { 0.986694, 0.705540, 0.095694 }, + { 0.986175, 0.713153, 0.103863 }, + { 0.985566, 0.720782, 0.112229 }, + { 0.984865, 0.728427, 0.120785 }, + { 0.984075, 0.736087, 0.129527 }, + { 0.983196, 0.743758, 0.138453 }, + { 0.982228, 0.751442, 0.147565 }, + { 0.981173, 0.759135, 0.156863 }, + { 0.980032, 0.766837, 0.166353 }, + { 0.978806, 0.774545, 0.176037 }, + { 0.977497, 0.782258, 0.185923 }, + { 0.976108, 0.789974, 0.196018 }, + { 0.974638, 0.797692, 0.206332 }, + { 0.973088, 0.805409, 0.216877 }, + { 0.971468, 0.813122, 0.227658 }, + { 0.969783, 0.820825, 0.238686 }, + { 0.968041, 0.828515, 0.249972 }, + { 0.966243, 0.836191, 0.261534 }, + { 0.964394, 0.843848, 0.273391 }, + { 0.962517, 0.851476, 0.285546 }, + { 0.960626, 0.859069, 0.298010 }, + { 0.958720, 0.866624, 0.310820 }, + { 0.956834, 0.874129, 0.323974 }, + { 0.954997, 0.881569, 0.337475 }, + { 0.953215, 0.888942, 0.351369 }, + { 0.951546, 0.896226, 0.365627 }, + { 0.950018, 0.903409, 0.380271 }, + { 0.948683, 0.910473, 0.395289 }, + { 0.947594, 0.917399, 0.410665 }, + { 0.946809, 0.924168, 0.426373 }, + { 0.946392, 0.930761, 0.442367 }, + { 0.946403, 0.937159, 0.458592 }, + { 0.946903, 0.943348, 0.474970 }, + { 0.947937, 0.949318, 0.491426 }, + { 0.949545, 0.955063, 0.507860 }, + { 0.951740, 0.960587, 0.524203 }, + { 0.954529, 0.965896, 0.540361 }, + { 0.957896, 0.971003, 0.556275 }, + { 0.961812, 0.975924, 0.571925 }, + { 0.966249, 0.980678, 0.587206 }, + { 0.971162, 0.985282, 0.602154 }, + { 0.976511, 0.989753, 0.616760 }, + { 0.982257, 0.994109, 0.631017 }, + { 0.988362, 0.998364, 0.644924 } +}; + +static double magma_cm[256][3] = { + { 0.001462, 0.000466, 0.013866 }, + { 0.002258, 0.001295, 0.018331 }, + { 0.003279, 0.002305, 0.023708 }, + { 0.004512, 0.003490, 0.029965 }, + { 0.005950, 0.004843, 0.037130 }, + { 0.007588, 0.006356, 0.044973 }, + { 0.009426, 0.008022, 0.052844 }, + { 0.011465, 0.009828, 0.060750 }, + { 0.013708, 0.011771, 0.068667 }, + { 0.016156, 0.013840, 0.076603 }, + { 0.018815, 0.016026, 0.084584 }, + { 0.021692, 0.018320, 0.092610 }, + { 0.024792, 0.020715, 0.100676 }, + { 0.028123, 0.023201, 0.108787 }, + { 0.031696, 0.025765, 0.116965 }, + { 0.035520, 0.028397, 0.125209 }, + { 0.039608, 0.031090, 0.133515 }, + { 0.043830, 0.033830, 0.141886 }, + { 0.048062, 0.036607, 0.150327 }, + { 0.052320, 0.039407, 0.158841 }, + { 0.056615, 0.042160, 0.167446 }, + { 0.060949, 0.044794, 0.176129 }, + { 0.065330, 0.047318, 0.184892 }, + { 0.069764, 0.049726, 0.193735 }, + { 0.074257, 0.052017, 0.202660 }, + { 0.078815, 0.054184, 0.211667 }, + { 0.083446, 0.056225, 0.220755 }, + { 0.088155, 0.058133, 0.229922 }, + { 0.092949, 0.059904, 0.239164 }, + { 0.097833, 0.061531, 0.248477 }, + { 0.102815, 0.063010, 0.257854 }, + { 0.107899, 0.064335, 0.267289 }, + { 0.113094, 0.065492, 0.276784 }, + { 0.118405, 0.066479, 0.286321 }, + { 0.123833, 0.067295, 0.295879 }, + { 0.129380, 0.067935, 0.305443 }, + { 0.135053, 0.068391, 0.315000 }, + { 0.140858, 0.068654, 0.324538 }, + { 0.146785, 0.068738, 0.334011 }, + { 0.152839, 0.068637, 0.343404 }, + { 0.159018, 0.068354, 0.352688 }, + { 0.165308, 0.067911, 0.361816 }, + { 0.171713, 0.067305, 0.370771 }, + { 0.178212, 0.066576, 0.379497 }, + { 0.184801, 0.065732, 0.387973 }, + { 0.191460, 0.064818, 0.396152 }, + { 0.198177, 0.063862, 0.404009 }, + { 0.204935, 0.062907, 0.411514 }, + { 0.211718, 0.061992, 0.418647 }, + { 0.218512, 0.061158, 0.425392 }, + { 0.225302, 0.060445, 0.431742 }, + { 0.232077, 0.059889, 0.437695 }, + { 0.238826, 0.059517, 0.443256 }, + { 0.245543, 0.059352, 0.448436 }, + { 0.252220, 0.059415, 0.453248 }, + { 0.258857, 0.059706, 0.457710 }, + { 0.265447, 0.060237, 0.461840 }, + { 0.271994, 0.060994, 0.465660 }, + { 0.278493, 0.061978, 0.469190 }, + { 0.284951, 0.063168, 0.472451 }, + { 0.291366, 0.064553, 0.475462 }, + { 0.297740, 0.066117, 0.478243 }, + { 0.304081, 0.067835, 0.480812 }, + { 0.310382, 0.069702, 0.483186 }, + { 0.316654, 0.071690, 0.485380 }, + { 0.322899, 0.073782, 0.487408 }, + { 0.329114, 0.075972, 0.489287 }, + { 0.335308, 0.078236, 0.491024 }, + { 0.341482, 0.080564, 0.492631 }, + { 0.347636, 0.082946, 0.494121 }, + { 0.353773, 0.085373, 0.495501 }, + { 0.359898, 0.087831, 0.496778 }, + { 0.366012, 0.090314, 0.497960 }, + { 0.372116, 0.092816, 0.499053 }, + { 0.378211, 0.095332, 0.500067 }, + { 0.384299, 0.097855, 0.501002 }, + { 0.390384, 0.100379, 0.501864 }, + { 0.396467, 0.102902, 0.502658 }, + { 0.402548, 0.105420, 0.503386 }, + { 0.408629, 0.107930, 0.504052 }, + { 0.414709, 0.110431, 0.504662 }, + { 0.420791, 0.112920, 0.505215 }, + { 0.426877, 0.115395, 0.505714 }, + { 0.432967, 0.117855, 0.506160 }, + { 0.439062, 0.120298, 0.506555 }, + { 0.445163, 0.122724, 0.506901 }, + { 0.451271, 0.125132, 0.507198 }, + { 0.457386, 0.127522, 0.507448 }, + { 0.463508, 0.129893, 0.507652 }, + { 0.469640, 0.132245, 0.507809 }, + { 0.475780, 0.134577, 0.507921 }, + { 0.481929, 0.136891, 0.507989 }, + { 0.488088, 0.139186, 0.508011 }, + { 0.494258, 0.141462, 0.507988 }, + { 0.500438, 0.143719, 0.507920 }, + { 0.506629, 0.145958, 0.507806 }, + { 0.512831, 0.148179, 0.507648 }, + { 0.519045, 0.150383, 0.507443 }, + { 0.525270, 0.152569, 0.507192 }, + { 0.531507, 0.154739, 0.506895 }, + { 0.537755, 0.156894, 0.506551 }, + { 0.544015, 0.159033, 0.506159 }, + { 0.550287, 0.161158, 0.505719 }, + { 0.556571, 0.163269, 0.505230 }, + { 0.562866, 0.165368, 0.504692 }, + { 0.569172, 0.167454, 0.504105 }, + { 0.575490, 0.169530, 0.503466 }, + { 0.581819, 0.171596, 0.502777 }, + { 0.588158, 0.173652, 0.502035 }, + { 0.594508, 0.175701, 0.501241 }, + { 0.600868, 0.177743, 0.500394 }, + { 0.607238, 0.179779, 0.499492 }, + { 0.613617, 0.181811, 0.498536 }, + { 0.620005, 0.183840, 0.497524 }, + { 0.626401, 0.185867, 0.496456 }, + { 0.632805, 0.187893, 0.495332 }, + { 0.639216, 0.189921, 0.494150 }, + { 0.645633, 0.191952, 0.492910 }, + { 0.652056, 0.193986, 0.491611 }, + { 0.658483, 0.196027, 0.490253 }, + { 0.664915, 0.198075, 0.488836 }, + { 0.671349, 0.200133, 0.487358 }, + { 0.677786, 0.202203, 0.485819 }, + { 0.684224, 0.204286, 0.484219 }, + { 0.690661, 0.206384, 0.482558 }, + { 0.697098, 0.208501, 0.480835 }, + { 0.703532, 0.210638, 0.479049 }, + { 0.709962, 0.212797, 0.477201 }, + { 0.716387, 0.214982, 0.475290 }, + { 0.722805, 0.217194, 0.473316 }, + { 0.729216, 0.219437, 0.471279 }, + { 0.735616, 0.221713, 0.469180 }, + { 0.742004, 0.224025, 0.467018 }, + { 0.748378, 0.226377, 0.464794 }, + { 0.754737, 0.228772, 0.462509 }, + { 0.761077, 0.231214, 0.460162 }, + { 0.767398, 0.233705, 0.457755 }, + { 0.773695, 0.236249, 0.455289 }, + { 0.779968, 0.238851, 0.452765 }, + { 0.786212, 0.241514, 0.450184 }, + { 0.792427, 0.244242, 0.447543 }, + { 0.798608, 0.247040, 0.444848 }, + { 0.804752, 0.249911, 0.442102 }, + { 0.810855, 0.252861, 0.439305 }, + { 0.816914, 0.255895, 0.436461 }, + { 0.822926, 0.259016, 0.433573 }, + { 0.828886, 0.262229, 0.430644 }, + { 0.834791, 0.265540, 0.427671 }, + { 0.840636, 0.268953, 0.424666 }, + { 0.846416, 0.272473, 0.421631 }, + { 0.852126, 0.276106, 0.418573 }, + { 0.857763, 0.279857, 0.415496 }, + { 0.863320, 0.283729, 0.412403 }, + { 0.868793, 0.287728, 0.409303 }, + { 0.874176, 0.291859, 0.406205 }, + { 0.879464, 0.296125, 0.403118 }, + { 0.884651, 0.300530, 0.400047 }, + { 0.889731, 0.305079, 0.397002 }, + { 0.894700, 0.309773, 0.393995 }, + { 0.899552, 0.314616, 0.391037 }, + { 0.904281, 0.319610, 0.388137 }, + { 0.908884, 0.324755, 0.385308 }, + { 0.913354, 0.330052, 0.382563 }, + { 0.917689, 0.335500, 0.379915 }, + { 0.921884, 0.341098, 0.377376 }, + { 0.925937, 0.346844, 0.374959 }, + { 0.929845, 0.352734, 0.372677 }, + { 0.933606, 0.358764, 0.370541 }, + { 0.937221, 0.364929, 0.368567 }, + { 0.940687, 0.371224, 0.366762 }, + { 0.944006, 0.377643, 0.365136 }, + { 0.947180, 0.384178, 0.363701 }, + { 0.950210, 0.390820, 0.362468 }, + { 0.953099, 0.397563, 0.361438 }, + { 0.955849, 0.404400, 0.360619 }, + { 0.958464, 0.411324, 0.360014 }, + { 0.960949, 0.418323, 0.359630 }, + { 0.963310, 0.425390, 0.359469 }, + { 0.965549, 0.432519, 0.359529 }, + { 0.967671, 0.439703, 0.359810 }, + { 0.969680, 0.446936, 0.360311 }, + { 0.971582, 0.454210, 0.361030 }, + { 0.973381, 0.461520, 0.361965 }, + { 0.975082, 0.468861, 0.363111 }, + { 0.976690, 0.476226, 0.364466 }, + { 0.978210, 0.483612, 0.366025 }, + { 0.979645, 0.491014, 0.367783 }, + { 0.981000, 0.498428, 0.369734 }, + { 0.982279, 0.505851, 0.371874 }, + { 0.983485, 0.513280, 0.374198 }, + { 0.984622, 0.520713, 0.376698 }, + { 0.985693, 0.528148, 0.379371 }, + { 0.986700, 0.535582, 0.382210 }, + { 0.987646, 0.543015, 0.385210 }, + { 0.988533, 0.550446, 0.388365 }, + { 0.989363, 0.557873, 0.391671 }, + { 0.990138, 0.565296, 0.395122 }, + { 0.990871, 0.572706, 0.398714 }, + { 0.991558, 0.580107, 0.402441 }, + { 0.992196, 0.587502, 0.406299 }, + { 0.992785, 0.594891, 0.410283 }, + { 0.993326, 0.602275, 0.414390 }, + { 0.993834, 0.609644, 0.418613 }, + { 0.994309, 0.616999, 0.422950 }, + { 0.994738, 0.624350, 0.427397 }, + { 0.995122, 0.631696, 0.431951 }, + { 0.995480, 0.639027, 0.436607 }, + { 0.995810, 0.646344, 0.441361 }, + { 0.996096, 0.653659, 0.446213 }, + { 0.996341, 0.660969, 0.451160 }, + { 0.996580, 0.668256, 0.456192 }, + { 0.996775, 0.675541, 0.461314 }, + { 0.996925, 0.682828, 0.466526 }, + { 0.997077, 0.690088, 0.471811 }, + { 0.997186, 0.697349, 0.477182 }, + { 0.997254, 0.704611, 0.482635 }, + { 0.997325, 0.711848, 0.488154 }, + { 0.997351, 0.719089, 0.493755 }, + { 0.997351, 0.726324, 0.499428 }, + { 0.997341, 0.733545, 0.505167 }, + { 0.997285, 0.740772, 0.510983 }, + { 0.997228, 0.747981, 0.516859 }, + { 0.997138, 0.755190, 0.522806 }, + { 0.997019, 0.762398, 0.528821 }, + { 0.996898, 0.769591, 0.534892 }, + { 0.996727, 0.776795, 0.541039 }, + { 0.996571, 0.783977, 0.547233 }, + { 0.996369, 0.791167, 0.553499 }, + { 0.996162, 0.798348, 0.559820 }, + { 0.995932, 0.805527, 0.566202 }, + { 0.995680, 0.812706, 0.572645 }, + { 0.995424, 0.819875, 0.579140 }, + { 0.995131, 0.827052, 0.585701 }, + { 0.994851, 0.834213, 0.592307 }, + { 0.994524, 0.841387, 0.598983 }, + { 0.994222, 0.848540, 0.605696 }, + { 0.993866, 0.855711, 0.612482 }, + { 0.993545, 0.862859, 0.619299 }, + { 0.993170, 0.870024, 0.626189 }, + { 0.992831, 0.877168, 0.633109 }, + { 0.992440, 0.884330, 0.640099 }, + { 0.992089, 0.891470, 0.647116 }, + { 0.991688, 0.898627, 0.654202 }, + { 0.991332, 0.905763, 0.661309 }, + { 0.990930, 0.912915, 0.668481 }, + { 0.990570, 0.920049, 0.675675 }, + { 0.990175, 0.927196, 0.682926 }, + { 0.989815, 0.934329, 0.690198 }, + { 0.989434, 0.941470, 0.697519 }, + { 0.989077, 0.948604, 0.704863 }, + { 0.988717, 0.955742, 0.712242 }, + { 0.988367, 0.962878, 0.719649 }, + { 0.988033, 0.970012, 0.727077 }, + { 0.987691, 0.977154, 0.734536 }, + { 0.987387, 0.984288, 0.742002 }, + { 0.987053, 0.991438, 0.749504 } +}; + +static double plasma_cm[256][3] = { + { 0.050383, 0.029803, 0.527975 }, + { 0.063536, 0.028426, 0.533124 }, + { 0.075353, 0.027206, 0.538007 }, + { 0.086222, 0.026125, 0.542658 }, + { 0.096379, 0.025165, 0.547103 }, + { 0.105980, 0.024309, 0.551368 }, + { 0.115124, 0.023556, 0.555468 }, + { 0.123903, 0.022878, 0.559423 }, + { 0.132381, 0.022258, 0.563250 }, + { 0.140603, 0.021687, 0.566959 }, + { 0.148607, 0.021154, 0.570562 }, + { 0.156421, 0.020651, 0.574065 }, + { 0.164070, 0.020171, 0.577478 }, + { 0.171574, 0.019706, 0.580806 }, + { 0.178950, 0.019252, 0.584054 }, + { 0.186213, 0.018803, 0.587228 }, + { 0.193374, 0.018354, 0.590330 }, + { 0.200445, 0.017902, 0.593364 }, + { 0.207435, 0.017442, 0.596333 }, + { 0.214350, 0.016973, 0.599239 }, + { 0.221197, 0.016497, 0.602083 }, + { 0.227983, 0.016007, 0.604867 }, + { 0.234715, 0.015502, 0.607592 }, + { 0.241396, 0.014979, 0.610259 }, + { 0.248032, 0.014439, 0.612868 }, + { 0.254627, 0.013882, 0.615419 }, + { 0.261183, 0.013308, 0.617911 }, + { 0.267703, 0.012716, 0.620346 }, + { 0.274191, 0.012109, 0.622722 }, + { 0.280648, 0.011488, 0.625038 }, + { 0.287076, 0.010855, 0.627295 }, + { 0.293478, 0.010213, 0.629490 }, + { 0.299855, 0.009561, 0.631624 }, + { 0.306210, 0.008902, 0.633694 }, + { 0.312543, 0.008239, 0.635700 }, + { 0.318856, 0.007576, 0.637640 }, + { 0.325150, 0.006915, 0.639512 }, + { 0.331426, 0.006261, 0.641316 }, + { 0.337683, 0.005618, 0.643049 }, + { 0.343925, 0.004991, 0.644710 }, + { 0.350150, 0.004382, 0.646298 }, + { 0.356359, 0.003798, 0.647810 }, + { 0.362553, 0.003243, 0.649245 }, + { 0.368733, 0.002724, 0.650601 }, + { 0.374897, 0.002245, 0.651876 }, + { 0.381047, 0.001814, 0.653068 }, + { 0.387183, 0.001434, 0.654177 }, + { 0.393304, 0.001114, 0.655199 }, + { 0.399411, 0.000859, 0.656133 }, + { 0.405503, 0.000678, 0.656977 }, + { 0.411580, 0.000577, 0.657730 }, + { 0.417642, 0.000564, 0.658390 }, + { 0.423689, 0.000646, 0.658956 }, + { 0.429719, 0.000831, 0.659425 }, + { 0.435734, 0.001127, 0.659797 }, + { 0.441732, 0.001540, 0.660069 }, + { 0.447714, 0.002080, 0.660240 }, + { 0.453677, 0.002755, 0.660310 }, + { 0.459623, 0.003574, 0.660277 }, + { 0.465550, 0.004545, 0.660139 }, + { 0.471457, 0.005678, 0.659897 }, + { 0.477344, 0.006980, 0.659549 }, + { 0.483210, 0.008460, 0.659095 }, + { 0.489055, 0.010127, 0.658534 }, + { 0.494877, 0.011990, 0.657865 }, + { 0.500678, 0.014055, 0.657088 }, + { 0.506454, 0.016333, 0.656202 }, + { 0.512206, 0.018833, 0.655209 }, + { 0.517933, 0.021563, 0.654109 }, + { 0.523633, 0.024532, 0.652901 }, + { 0.529306, 0.027747, 0.651586 }, + { 0.534952, 0.031217, 0.650165 }, + { 0.540570, 0.034950, 0.648640 }, + { 0.546157, 0.038954, 0.647010 }, + { 0.551715, 0.043136, 0.645277 }, + { 0.557243, 0.047331, 0.643443 }, + { 0.562738, 0.051545, 0.641509 }, + { 0.568201, 0.055778, 0.639477 }, + { 0.573632, 0.060028, 0.637349 }, + { 0.579029, 0.064296, 0.635126 }, + { 0.584391, 0.068579, 0.632812 }, + { 0.589719, 0.072878, 0.630408 }, + { 0.595011, 0.077190, 0.627917 }, + { 0.600266, 0.081516, 0.625342 }, + { 0.605485, 0.085854, 0.622686 }, + { 0.610667, 0.090204, 0.619951 }, + { 0.615812, 0.094564, 0.617140 }, + { 0.620919, 0.098934, 0.614257 }, + { 0.625987, 0.103312, 0.611305 }, + { 0.631017, 0.107699, 0.608287 }, + { 0.636008, 0.112092, 0.605205 }, + { 0.640959, 0.116492, 0.602065 }, + { 0.645872, 0.120898, 0.598867 }, + { 0.650746, 0.125309, 0.595617 }, + { 0.655580, 0.129725, 0.592317 }, + { 0.660374, 0.134144, 0.588971 }, + { 0.665129, 0.138566, 0.585582 }, + { 0.669845, 0.142992, 0.582154 }, + { 0.674522, 0.147419, 0.578688 }, + { 0.679160, 0.151848, 0.575189 }, + { 0.683758, 0.156278, 0.571660 }, + { 0.688318, 0.160709, 0.568103 }, + { 0.692840, 0.165141, 0.564522 }, + { 0.697324, 0.169573, 0.560919 }, + { 0.701769, 0.174005, 0.557296 }, + { 0.706178, 0.178437, 0.553657 }, + { 0.710549, 0.182868, 0.550004 }, + { 0.714883, 0.187299, 0.546338 }, + { 0.719181, 0.191729, 0.542663 }, + { 0.723444, 0.196158, 0.538981 }, + { 0.727670, 0.200586, 0.535293 }, + { 0.731862, 0.205013, 0.531601 }, + { 0.736019, 0.209439, 0.527908 }, + { 0.740143, 0.213864, 0.524216 }, + { 0.744232, 0.218288, 0.520524 }, + { 0.748289, 0.222711, 0.516834 }, + { 0.752312, 0.227133, 0.513149 }, + { 0.756304, 0.231555, 0.509468 }, + { 0.760264, 0.235976, 0.505794 }, + { 0.764193, 0.240396, 0.502126 }, + { 0.768090, 0.244817, 0.498465 }, + { 0.771958, 0.249237, 0.494813 }, + { 0.775796, 0.253658, 0.491171 }, + { 0.779604, 0.258078, 0.487539 }, + { 0.783383, 0.262500, 0.483918 }, + { 0.787133, 0.266922, 0.480307 }, + { 0.790855, 0.271345, 0.476706 }, + { 0.794549, 0.275770, 0.473117 }, + { 0.798216, 0.280197, 0.469538 }, + { 0.801855, 0.284626, 0.465971 }, + { 0.805467, 0.289057, 0.462415 }, + { 0.809052, 0.293491, 0.458870 }, + { 0.812612, 0.297928, 0.455338 }, + { 0.816144, 0.302368, 0.451816 }, + { 0.819651, 0.306812, 0.448306 }, + { 0.823132, 0.311261, 0.444806 }, + { 0.826588, 0.315714, 0.441316 }, + { 0.830018, 0.320172, 0.437836 }, + { 0.833422, 0.324635, 0.434366 }, + { 0.836801, 0.329105, 0.430905 }, + { 0.840155, 0.333580, 0.427455 }, + { 0.843484, 0.338062, 0.424013 }, + { 0.846788, 0.342551, 0.420579 }, + { 0.850066, 0.347048, 0.417153 }, + { 0.853319, 0.351553, 0.413734 }, + { 0.856547, 0.356066, 0.410322 }, + { 0.859750, 0.360588, 0.406917 }, + { 0.862927, 0.365119, 0.403519 }, + { 0.866078, 0.369660, 0.400126 }, + { 0.869203, 0.374212, 0.396738 }, + { 0.872303, 0.378774, 0.393355 }, + { 0.875376, 0.383347, 0.389976 }, + { 0.878423, 0.387932, 0.386600 }, + { 0.881443, 0.392529, 0.383229 }, + { 0.884436, 0.397139, 0.379860 }, + { 0.887402, 0.401762, 0.376494 }, + { 0.890340, 0.406398, 0.373130 }, + { 0.893250, 0.411048, 0.369768 }, + { 0.896131, 0.415712, 0.366407 }, + { 0.898984, 0.420392, 0.363047 }, + { 0.901807, 0.425087, 0.359688 }, + { 0.904601, 0.429797, 0.356329 }, + { 0.907365, 0.434524, 0.352970 }, + { 0.910098, 0.439268, 0.349610 }, + { 0.912800, 0.444029, 0.346251 }, + { 0.915471, 0.448807, 0.342890 }, + { 0.918109, 0.453603, 0.339529 }, + { 0.920714, 0.458417, 0.336166 }, + { 0.923287, 0.463251, 0.332801 }, + { 0.925825, 0.468103, 0.329435 }, + { 0.928329, 0.472975, 0.326067 }, + { 0.930798, 0.477867, 0.322697 }, + { 0.933232, 0.482780, 0.319325 }, + { 0.935630, 0.487712, 0.315952 }, + { 0.937990, 0.492667, 0.312575 }, + { 0.940313, 0.497642, 0.309197 }, + { 0.942598, 0.502639, 0.305816 }, + { 0.944844, 0.507658, 0.302433 }, + { 0.947051, 0.512699, 0.299049 }, + { 0.949217, 0.517763, 0.295662 }, + { 0.951344, 0.522850, 0.292275 }, + { 0.953428, 0.527960, 0.288883 }, + { 0.955470, 0.533093, 0.285490 }, + { 0.957469, 0.538250, 0.282096 }, + { 0.959424, 0.543431, 0.278701 }, + { 0.961336, 0.548636, 0.275305 }, + { 0.963203, 0.553865, 0.271909 }, + { 0.965024, 0.559118, 0.268513 }, + { 0.966798, 0.564396, 0.265118 }, + { 0.968526, 0.569700, 0.261721 }, + { 0.970205, 0.575028, 0.258325 }, + { 0.971835, 0.580382, 0.254931 }, + { 0.973416, 0.585761, 0.251540 }, + { 0.974947, 0.591165, 0.248151 }, + { 0.976428, 0.596595, 0.244767 }, + { 0.977856, 0.602051, 0.241387 }, + { 0.979233, 0.607532, 0.238013 }, + { 0.980556, 0.613039, 0.234646 }, + { 0.981826, 0.618572, 0.231287 }, + { 0.983041, 0.624131, 0.227937 }, + { 0.984199, 0.629718, 0.224595 }, + { 0.985301, 0.635330, 0.221265 }, + { 0.986345, 0.640969, 0.217948 }, + { 0.987332, 0.646633, 0.214648 }, + { 0.988260, 0.652325, 0.211364 }, + { 0.989128, 0.658043, 0.208100 }, + { 0.989935, 0.663787, 0.204859 }, + { 0.990681, 0.669558, 0.201642 }, + { 0.991365, 0.675355, 0.198453 }, + { 0.991985, 0.681179, 0.195295 }, + { 0.992541, 0.687030, 0.192170 }, + { 0.993032, 0.692907, 0.189084 }, + { 0.993456, 0.698810, 0.186041 }, + { 0.993814, 0.704741, 0.183043 }, + { 0.994103, 0.710698, 0.180097 }, + { 0.994324, 0.716681, 0.177208 }, + { 0.994474, 0.722691, 0.174381 }, + { 0.994553, 0.728728, 0.171622 }, + { 0.994561, 0.734791, 0.168938 }, + { 0.994495, 0.740880, 0.166335 }, + { 0.994355, 0.746995, 0.163821 }, + { 0.994141, 0.753137, 0.161404 }, + { 0.993851, 0.759304, 0.159092 }, + { 0.993482, 0.765499, 0.156891 }, + { 0.993033, 0.771720, 0.154808 }, + { 0.992505, 0.777967, 0.152855 }, + { 0.991897, 0.784239, 0.151042 }, + { 0.991209, 0.790537, 0.149377 }, + { 0.990439, 0.796859, 0.147870 }, + { 0.989587, 0.803205, 0.146529 }, + { 0.988648, 0.809579, 0.145357 }, + { 0.987621, 0.815978, 0.144363 }, + { 0.986509, 0.822401, 0.143557 }, + { 0.985314, 0.828846, 0.142945 }, + { 0.984031, 0.835315, 0.142528 }, + { 0.982653, 0.841812, 0.142303 }, + { 0.981190, 0.848329, 0.142279 }, + { 0.979644, 0.854866, 0.142453 }, + { 0.977995, 0.861432, 0.142808 }, + { 0.976265, 0.868016, 0.143351 }, + { 0.974443, 0.874622, 0.144061 }, + { 0.972530, 0.881250, 0.144923 }, + { 0.970533, 0.887896, 0.145919 }, + { 0.968443, 0.894564, 0.147014 }, + { 0.966271, 0.901249, 0.148180 }, + { 0.964021, 0.907950, 0.149370 }, + { 0.961681, 0.914672, 0.150520 }, + { 0.959276, 0.921407, 0.151566 }, + { 0.956808, 0.928152, 0.152409 }, + { 0.954287, 0.934908, 0.152921 }, + { 0.951726, 0.941671, 0.152925 }, + { 0.949151, 0.948435, 0.152178 }, + { 0.946602, 0.955190, 0.150328 }, + { 0.944152, 0.961916, 0.146861 }, + { 0.941896, 0.968590, 0.140956 }, + { 0.940015, 0.975158, 0.131326 } +}; + +static double viridis_cm[256][3] = { + { 0.267004, 0.004874, 0.329415 }, + { 0.268510, 0.009605, 0.335427 }, + { 0.269944, 0.014625, 0.341379 }, + { 0.271305, 0.019942, 0.347269 }, + { 0.272594, 0.025563, 0.353093 }, + { 0.273809, 0.031497, 0.358853 }, + { 0.274952, 0.037752, 0.364543 }, + { 0.276022, 0.044167, 0.370164 }, + { 0.277018, 0.050344, 0.375715 }, + { 0.277941, 0.056324, 0.381191 }, + { 0.278791, 0.062145, 0.386592 }, + { 0.279566, 0.067836, 0.391917 }, + { 0.280267, 0.073417, 0.397163 }, + { 0.280894, 0.078907, 0.402329 }, + { 0.281446, 0.084320, 0.407414 }, + { 0.281924, 0.089666, 0.412415 }, + { 0.282327, 0.094955, 0.417331 }, + { 0.282656, 0.100196, 0.422160 }, + { 0.282910, 0.105393, 0.426902 }, + { 0.283091, 0.110553, 0.431554 }, + { 0.283197, 0.115680, 0.436115 }, + { 0.283229, 0.120777, 0.440584 }, + { 0.283187, 0.125848, 0.444960 }, + { 0.283072, 0.130895, 0.449241 }, + { 0.282884, 0.135920, 0.453427 }, + { 0.282623, 0.140926, 0.457517 }, + { 0.282290, 0.145912, 0.461510 }, + { 0.281887, 0.150881, 0.465405 }, + { 0.281412, 0.155834, 0.469201 }, + { 0.280868, 0.160771, 0.472899 }, + { 0.280255, 0.165693, 0.476498 }, + { 0.279574, 0.170599, 0.479997 }, + { 0.278826, 0.175490, 0.483397 }, + { 0.278012, 0.180367, 0.486697 }, + { 0.277134, 0.185228, 0.489898 }, + { 0.276194, 0.190074, 0.493001 }, + { 0.275191, 0.194905, 0.496005 }, + { 0.274128, 0.199721, 0.498911 }, + { 0.273006, 0.204520, 0.501721 }, + { 0.271828, 0.209303, 0.504434 }, + { 0.270595, 0.214069, 0.507052 }, + { 0.269308, 0.218818, 0.509577 }, + { 0.267968, 0.223549, 0.512008 }, + { 0.266580, 0.228262, 0.514349 }, + { 0.265145, 0.232956, 0.516599 }, + { 0.263663, 0.237631, 0.518762 }, + { 0.262138, 0.242286, 0.520837 }, + { 0.260571, 0.246922, 0.522828 }, + { 0.258965, 0.251537, 0.524736 }, + { 0.257322, 0.256130, 0.526563 }, + { 0.255645, 0.260703, 0.528312 }, + { 0.253935, 0.265254, 0.529983 }, + { 0.252194, 0.269783, 0.531579 }, + { 0.250425, 0.274290, 0.533103 }, + { 0.248629, 0.278775, 0.534556 }, + { 0.246811, 0.283237, 0.535941 }, + { 0.244972, 0.287675, 0.537260 }, + { 0.243113, 0.292092, 0.538516 }, + { 0.241237, 0.296485, 0.539709 }, + { 0.239346, 0.300855, 0.540844 }, + { 0.237441, 0.305202, 0.541921 }, + { 0.235526, 0.309527, 0.542944 }, + { 0.233603, 0.313828, 0.543914 }, + { 0.231674, 0.318106, 0.544834 }, + { 0.229739, 0.322361, 0.545706 }, + { 0.227802, 0.326594, 0.546532 }, + { 0.225863, 0.330805, 0.547314 }, + { 0.223925, 0.334994, 0.548053 }, + { 0.221989, 0.339161, 0.548752 }, + { 0.220057, 0.343307, 0.549413 }, + { 0.218130, 0.347432, 0.550038 }, + { 0.216210, 0.351535, 0.550627 }, + { 0.214298, 0.355619, 0.551184 }, + { 0.212395, 0.359683, 0.551710 }, + { 0.210503, 0.363727, 0.552206 }, + { 0.208623, 0.367752, 0.552675 }, + { 0.206756, 0.371758, 0.553117 }, + { 0.204903, 0.375746, 0.553533 }, + { 0.203063, 0.379716, 0.553925 }, + { 0.201239, 0.383670, 0.554294 }, + { 0.199430, 0.387607, 0.554642 }, + { 0.197636, 0.391528, 0.554969 }, + { 0.195860, 0.395433, 0.555276 }, + { 0.194100, 0.399323, 0.555565 }, + { 0.192357, 0.403199, 0.555836 }, + { 0.190631, 0.407061, 0.556089 }, + { 0.188923, 0.410910, 0.556326 }, + { 0.187231, 0.414746, 0.556547 }, + { 0.185556, 0.418570, 0.556753 }, + { 0.183898, 0.422383, 0.556944 }, + { 0.182256, 0.426184, 0.557120 }, + { 0.180629, 0.429975, 0.557282 }, + { 0.179019, 0.433756, 0.557430 }, + { 0.177423, 0.437527, 0.557565 }, + { 0.175841, 0.441290, 0.557685 }, + { 0.174274, 0.445044, 0.557792 }, + { 0.172719, 0.448791, 0.557885 }, + { 0.171176, 0.452530, 0.557965 }, + { 0.169646, 0.456262, 0.558030 }, + { 0.168126, 0.459988, 0.558082 }, + { 0.166617, 0.463708, 0.558119 }, + { 0.165117, 0.467423, 0.558141 }, + { 0.163625, 0.471133, 0.558148 }, + { 0.162142, 0.474838, 0.558140 }, + { 0.160665, 0.478540, 0.558115 }, + { 0.159194, 0.482237, 0.558073 }, + { 0.157729, 0.485932, 0.558013 }, + { 0.156270, 0.489624, 0.557936 }, + { 0.154815, 0.493313, 0.557840 }, + { 0.153364, 0.497000, 0.557724 }, + { 0.151918, 0.500685, 0.557587 }, + { 0.150476, 0.504369, 0.557430 }, + { 0.149039, 0.508051, 0.557250 }, + { 0.147607, 0.511733, 0.557049 }, + { 0.146180, 0.515413, 0.556823 }, + { 0.144759, 0.519093, 0.556572 }, + { 0.143343, 0.522773, 0.556295 }, + { 0.141935, 0.526453, 0.555991 }, + { 0.140536, 0.530132, 0.555659 }, + { 0.139147, 0.533812, 0.555298 }, + { 0.137770, 0.537492, 0.554906 }, + { 0.136408, 0.541173, 0.554483 }, + { 0.135066, 0.544853, 0.554029 }, + { 0.133743, 0.548535, 0.553541 }, + { 0.132444, 0.552216, 0.553018 }, + { 0.131172, 0.555899, 0.552459 }, + { 0.129933, 0.559582, 0.551864 }, + { 0.128729, 0.563265, 0.551229 }, + { 0.127568, 0.566949, 0.550556 }, + { 0.126453, 0.570633, 0.549841 }, + { 0.125394, 0.574318, 0.549086 }, + { 0.124395, 0.578002, 0.548287 }, + { 0.123463, 0.581687, 0.547445 }, + { 0.122606, 0.585371, 0.546557 }, + { 0.121831, 0.589055, 0.545623 }, + { 0.121148, 0.592739, 0.544641 }, + { 0.120565, 0.596422, 0.543611 }, + { 0.120092, 0.600104, 0.542530 }, + { 0.119738, 0.603785, 0.541400 }, + { 0.119512, 0.607464, 0.540218 }, + { 0.119423, 0.611141, 0.538982 }, + { 0.119483, 0.614817, 0.537692 }, + { 0.119699, 0.618490, 0.536347 }, + { 0.120081, 0.622161, 0.534946 }, + { 0.120638, 0.625828, 0.533488 }, + { 0.121380, 0.629492, 0.531973 }, + { 0.122312, 0.633153, 0.530398 }, + { 0.123444, 0.636809, 0.528763 }, + { 0.124780, 0.640461, 0.527068 }, + { 0.126326, 0.644107, 0.525311 }, + { 0.128087, 0.647749, 0.523491 }, + { 0.130067, 0.651384, 0.521608 }, + { 0.132268, 0.655014, 0.519661 }, + { 0.134692, 0.658636, 0.517649 }, + { 0.137339, 0.662252, 0.515571 }, + { 0.140210, 0.665859, 0.513427 }, + { 0.143303, 0.669459, 0.511215 }, + { 0.146616, 0.673050, 0.508936 }, + { 0.150148, 0.676631, 0.506589 }, + { 0.153894, 0.680203, 0.504172 }, + { 0.157851, 0.683765, 0.501686 }, + { 0.162016, 0.687316, 0.499129 }, + { 0.166383, 0.690856, 0.496502 }, + { 0.170948, 0.694384, 0.493803 }, + { 0.175707, 0.697900, 0.491033 }, + { 0.180653, 0.701402, 0.488189 }, + { 0.185783, 0.704891, 0.485273 }, + { 0.191090, 0.708366, 0.482284 }, + { 0.196571, 0.711827, 0.479221 }, + { 0.202219, 0.715272, 0.476084 }, + { 0.208030, 0.718701, 0.472873 }, + { 0.214000, 0.722114, 0.469588 }, + { 0.220124, 0.725509, 0.466226 }, + { 0.226397, 0.728888, 0.462789 }, + { 0.232815, 0.732247, 0.459277 }, + { 0.239374, 0.735588, 0.455688 }, + { 0.246070, 0.738910, 0.452024 }, + { 0.252899, 0.742211, 0.448284 }, + { 0.259857, 0.745492, 0.444467 }, + { 0.266941, 0.748751, 0.440573 }, + { 0.274149, 0.751988, 0.436601 }, + { 0.281477, 0.755203, 0.432552 }, + { 0.288921, 0.758394, 0.428426 }, + { 0.296479, 0.761561, 0.424223 }, + { 0.304148, 0.764704, 0.419943 }, + { 0.311925, 0.767822, 0.415586 }, + { 0.319809, 0.770914, 0.411152 }, + { 0.327796, 0.773980, 0.406640 }, + { 0.335885, 0.777018, 0.402049 }, + { 0.344074, 0.780029, 0.397381 }, + { 0.352360, 0.783011, 0.392636 }, + { 0.360741, 0.785964, 0.387814 }, + { 0.369214, 0.788888, 0.382914 }, + { 0.377779, 0.791781, 0.377939 }, + { 0.386433, 0.794644, 0.372886 }, + { 0.395174, 0.797475, 0.367757 }, + { 0.404001, 0.800275, 0.362552 }, + { 0.412913, 0.803041, 0.357269 }, + { 0.421908, 0.805774, 0.351910 }, + { 0.430983, 0.808473, 0.346476 }, + { 0.440137, 0.811138, 0.340967 }, + { 0.449368, 0.813768, 0.335384 }, + { 0.458674, 0.816363, 0.329727 }, + { 0.468053, 0.818921, 0.323998 }, + { 0.477504, 0.821444, 0.318195 }, + { 0.487026, 0.823929, 0.312321 }, + { 0.496615, 0.826376, 0.306377 }, + { 0.506271, 0.828786, 0.300362 }, + { 0.515992, 0.831158, 0.294279 }, + { 0.525776, 0.833491, 0.288127 }, + { 0.535621, 0.835785, 0.281908 }, + { 0.545524, 0.838039, 0.275626 }, + { 0.555484, 0.840254, 0.269281 }, + { 0.565498, 0.842430, 0.262877 }, + { 0.575563, 0.844566, 0.256415 }, + { 0.585678, 0.846661, 0.249897 }, + { 0.595839, 0.848717, 0.243329 }, + { 0.606045, 0.850733, 0.236712 }, + { 0.616293, 0.852709, 0.230052 }, + { 0.626579, 0.854645, 0.223353 }, + { 0.636902, 0.856542, 0.216620 }, + { 0.647257, 0.858400, 0.209861 }, + { 0.657642, 0.860219, 0.203082 }, + { 0.668054, 0.861999, 0.196293 }, + { 0.678489, 0.863742, 0.189503 }, + { 0.688944, 0.865448, 0.182725 }, + { 0.699415, 0.867117, 0.175971 }, + { 0.709898, 0.868751, 0.169257 }, + { 0.720391, 0.870350, 0.162603 }, + { 0.730889, 0.871916, 0.156029 }, + { 0.741388, 0.873449, 0.149561 }, + { 0.751884, 0.874951, 0.143228 }, + { 0.762373, 0.876424, 0.137064 }, + { 0.772852, 0.877868, 0.131109 }, + { 0.783315, 0.879285, 0.125405 }, + { 0.793760, 0.880678, 0.120005 }, + { 0.804182, 0.882046, 0.114965 }, + { 0.814576, 0.883393, 0.110347 }, + { 0.824940, 0.884720, 0.106217 }, + { 0.835270, 0.886029, 0.102646 }, + { 0.845561, 0.887322, 0.099702 }, + { 0.855810, 0.888601, 0.097452 }, + { 0.866013, 0.889868, 0.095953 }, + { 0.876168, 0.891125, 0.095250 }, + { 0.886271, 0.892374, 0.095374 }, + { 0.896320, 0.893616, 0.096335 }, + { 0.906311, 0.894855, 0.098125 }, + { 0.916242, 0.896091, 0.100717 }, + { 0.926106, 0.897330, 0.104071 }, + { 0.935904, 0.898570, 0.108131 }, + { 0.945636, 0.899815, 0.112838 }, + { 0.955300, 0.901065, 0.118128 }, + { 0.964894, 0.902323, 0.123941 }, + { 0.974417, 0.903590, 0.130215 }, + { 0.983868, 0.904867, 0.136897 }, + { 0.993248, 0.906157, 0.143936 } +}; + +static double parula_cm[256][3] = { + { 0.2081, 0.1663, 0.5292 }, + { 0.2091, 0.1721, 0.5411 }, + { 0.2101, 0.1779, 0.553 }, + { 0.2109, 0.1837, 0.565 }, + { 0.2116, 0.1895, 0.5771 }, + { 0.2121, 0.1954, 0.5892 }, + { 0.2124, 0.2013, 0.6013 }, + { 0.2125, 0.2072, 0.6135 }, + { 0.2123, 0.2132, 0.6258 }, + { 0.2118, 0.2192, 0.6381 }, + { 0.2111, 0.2253, 0.6505 }, + { 0.2099, 0.2315, 0.6629 }, + { 0.2084, 0.2377, 0.6753 }, + { 0.2063, 0.244, 0.6878 }, + { 0.2038, 0.2503, 0.7003 }, + { 0.2006, 0.2568, 0.7129 }, + { 0.1968, 0.2632, 0.7255 }, + { 0.1921, 0.2698, 0.7381 }, + { 0.1867, 0.2764, 0.7507 }, + { 0.1802, 0.2832, 0.7634 }, + { 0.1728, 0.2902, 0.7762 }, + { 0.1641, 0.2975, 0.789 }, + { 0.1541, 0.3052, 0.8017 }, + { 0.1427, 0.3132, 0.8145 }, + { 0.1295, 0.3217, 0.8269 }, + { 0.1147, 0.3306, 0.8387 }, + { 0.0986, 0.3397, 0.8495 }, + { 0.0816, 0.3486, 0.8588 }, + { 0.0646, 0.3572, 0.8664 }, + { 0.0482, 0.3651, 0.8722 }, + { 0.0329, 0.3724, 0.8765 }, + { 0.0213, 0.3792, 0.8796 }, + { 0.0136, 0.3853, 0.8815 }, + { 0.0086, 0.3911, 0.8827 }, + { 0.006, 0.3965, 0.8833 }, + { 0.0051, 0.4017, 0.8834 }, + { 0.0054, 0.4066, 0.8831 }, + { 0.0067, 0.4113, 0.8825 }, + { 0.0089, 0.4159, 0.8816 }, + { 0.0116, 0.4203, 0.8805 }, + { 0.0148, 0.4246, 0.8793 }, + { 0.0184, 0.4288, 0.8779 }, + { 0.0223, 0.4329, 0.8763 }, + { 0.0264, 0.437, 0.8747 }, + { 0.0306, 0.441, 0.8729 }, + { 0.0349, 0.4449, 0.8711 }, + { 0.0394, 0.4488, 0.8692 }, + { 0.0437, 0.4526, 0.8672 }, + { 0.0477, 0.4564, 0.8652 }, + { 0.0514, 0.4602, 0.8632 }, + { 0.0549, 0.464, 0.8611 }, + { 0.0582, 0.4677, 0.8589 }, + { 0.0612, 0.4714, 0.8568 }, + { 0.064, 0.4751, 0.8546 }, + { 0.0666, 0.4788, 0.8525 }, + { 0.0689, 0.4825, 0.8503 }, + { 0.071, 0.4862, 0.8481 }, + { 0.0729, 0.4899, 0.846 }, + { 0.0746, 0.4937, 0.8439 }, + { 0.0761, 0.4974, 0.8418 }, + { 0.0773, 0.5012, 0.8398 }, + { 0.0782, 0.5051, 0.8378 }, + { 0.0789, 0.5089, 0.8359 }, + { 0.0794, 0.5129, 0.8341 }, + { 0.0795, 0.5169, 0.8324 }, + { 0.0793, 0.521, 0.8308 }, + { 0.0788, 0.5251, 0.8293 }, + { 0.0778, 0.5295, 0.828 }, + { 0.0764, 0.5339, 0.827 }, + { 0.0746, 0.5384, 0.8261 }, + { 0.0724, 0.5431, 0.8253 }, + { 0.0698, 0.5479, 0.8247 }, + { 0.0668, 0.5527, 0.8243 }, + { 0.0636, 0.5577, 0.8239 }, + { 0.06, 0.5627, 0.8237 }, + { 0.0562, 0.5677, 0.8234 }, + { 0.0523, 0.5727, 0.8231 }, + { 0.0484, 0.5777, 0.8228 }, + { 0.0445, 0.5826, 0.8223 }, + { 0.0408, 0.5874, 0.8217 }, + { 0.0372, 0.5922, 0.8209 }, + { 0.0342, 0.5968, 0.8198 }, + { 0.0317, 0.6012, 0.8186 }, + { 0.0296, 0.6055, 0.8171 }, + { 0.0279, 0.6097, 0.8154 }, + { 0.0265, 0.6137, 0.8135 }, + { 0.0255, 0.6176, 0.8114 }, + { 0.0248, 0.6214, 0.8091 }, + { 0.0243, 0.625, 0.8066 }, + { 0.0239, 0.6285, 0.8039 }, + { 0.0237, 0.6319, 0.801 }, + { 0.0235, 0.6352, 0.798 }, + { 0.0233, 0.6384, 0.7948 }, + { 0.0231, 0.6415, 0.7916 }, + { 0.023, 0.6445, 0.7881 }, + { 0.0229, 0.6474, 0.7846 }, + { 0.0227, 0.6503, 0.781, }, + { 0.0227, 0.6531, 0.7773 }, + { 0.0232, 0.6558, 0.7735 }, + { 0.0238, 0.6585, 0.7696 }, + { 0.0246, 0.6611, 0.7656 }, + { 0.0263, 0.6637, 0.7615 }, + { 0.0282, 0.6663, 0.7574 }, + { 0.0306, 0.6688, 0.7532 }, + { 0.0338, 0.6712, 0.749 }, + { 0.0373, 0.6737, 0.7446 }, + { 0.0418, 0.6761, 0.7402 }, + { 0.0467, 0.6784, 0.7358 }, + { 0.0516, 0.6808, 0.7313 }, + { 0.0574, 0.6831, 0.7267 }, + { 0.0629, 0.6854, 0.7221 }, + { 0.0692, 0.6877, 0.7173 }, + { 0.0755, 0.6899, 0.7126 }, + { 0.082, 0.6921, 0.7078 }, + { 0.0889, 0.6943, 0.7029 }, + { 0.0956, 0.6965, 0.6979 }, + { 0.1031, 0.6986, 0.6929 }, + { 0.1104, 0.7007, 0.6878 }, + { 0.118, 0.7028, 0.6827 }, + { 0.1258, 0.7049, 0.6775 }, + { 0.1335, 0.7069, 0.6723 }, + { 0.1418, 0.7089, 0.6669 }, + { 0.1499, 0.7109, 0.6616 }, + { 0.1585, 0.7129, 0.6561 }, + { 0.1671, 0.7148, 0.6507 }, + { 0.1758, 0.7168, 0.6451 }, + { 0.1849, 0.7186, 0.6395 }, + { 0.1938, 0.7205, 0.6338 }, + { 0.2033, 0.7223, 0.6281 }, + { 0.2128, 0.7241, 0.6223 }, + { 0.2224, 0.7259, 0.6165 }, + { 0.2324, 0.7275, 0.6107 }, + { 0.2423, 0.7292, 0.6048 }, + { 0.2527, 0.7308, 0.5988 }, + { 0.2631, 0.7324, 0.5929 }, + { 0.2735, 0.7339, 0.5869 }, + { 0.2845, 0.7354, 0.5809 }, + { 0.2953, 0.7368, 0.5749 }, + { 0.3064, 0.7381, 0.5689 }, + { 0.3177, 0.7394, 0.563 }, + { 0.3289, 0.7406, 0.557 }, + { 0.3405, 0.7417, 0.5512 }, + { 0.352, 0.7428, 0.5453 }, + { 0.3635, 0.7438, 0.5396 }, + { 0.3753, 0.7446, 0.5339 }, + { 0.3869, 0.7454, 0.5283 }, + { 0.3986, 0.7461, 0.5229 }, + { 0.4103, 0.7467, 0.5175 }, + { 0.4218, 0.7473, 0.5123 }, + { 0.4334, 0.7477, 0.5072 }, + { 0.4447, 0.7482, 0.5021 }, + { 0.4561, 0.7485, 0.4972 }, + { 0.4672, 0.7487, 0.4924 }, + { 0.4783, 0.7489, 0.4877 }, + { 0.4892, 0.7491, 0.4831 }, + { 0.5, 0.7491, 0.4786 }, + { 0.5106, 0.7492, 0.4741 }, + { 0.5212, 0.7492, 0.4698 }, + { 0.5315, 0.7491, 0.4655 }, + { 0.5418, 0.749, 0.4613 }, + { 0.5519, 0.7489, 0.4571 }, + { 0.5619, 0.7487, 0.4531 }, + { 0.5718, 0.7485, 0.449 }, + { 0.5816, 0.7482, 0.4451 }, + { 0.5913, 0.7479, 0.4412 }, + { 0.6009, 0.7476, 0.4374 }, + { 0.6103, 0.7473, 0.4335 }, + { 0.6197, 0.7469, 0.4298 }, + { 0.629, 0.7465, 0.4261 }, + { 0.6382, 0.746, 0.4224 }, + { 0.6473, 0.7456, 0.4188 }, + { 0.6564, 0.7451, 0.4152 }, + { 0.6653, 0.7446, 0.4116 }, + { 0.6742, 0.7441, 0.4081 }, + { 0.683, 0.7435, 0.4046 }, + { 0.6918, 0.743, 0.4011 }, + { 0.7004, 0.7424, 0.3976 }, + { 0.7091, 0.7418, 0.3942 }, + { 0.7176, 0.7412, 0.3908 }, + { 0.7261, 0.7405, 0.3874 }, + { 0.7346, 0.7399, 0.384 }, + { 0.743, 0.7392, 0.3806 }, + { 0.7513, 0.7385, 0.3773 }, + { 0.7596, 0.7378, 0.3739 }, + { 0.7679, 0.7372, 0.3706 }, + { 0.7761, 0.7364, 0.3673 }, + { 0.7843, 0.7357, 0.3639 }, + { 0.7924, 0.735, 0.3606 }, + { 0.8005, 0.7343, 0.3573 }, + { 0.8085, 0.7336, 0.3539 }, + { 0.8166, 0.7329, 0.3506 }, + { 0.8246, 0.7322, 0.3472 }, + { 0.8325, 0.7315, 0.3438 }, + { 0.8405, 0.7308, 0.3404 }, + { 0.8484, 0.7301, 0.337 }, + { 0.8563, 0.7294, 0.3336 }, + { 0.8642, 0.7288, 0.33 }, + { 0.872, 0.7282, 0.3265 }, + { 0.8798, 0.7276, 0.3229 }, + { 0.8877, 0.7271, 0.3193 }, + { 0.8954, 0.7266, 0.3156 }, + { 0.9032, 0.7262, 0.3117 }, + { 0.911, 0.7259, 0.3078 }, + { 0.9187, 0.7256, 0.3038 }, + { 0.9264, 0.7256, 0.2996 }, + { 0.9341, 0.7256, 0.2953 }, + { 0.9417, 0.7259, 0.2907 }, + { 0.9493, 0.7264, 0.2859 }, + { 0.9567, 0.7273, 0.2808 }, + { 0.9639, 0.7285, 0.2754 }, + { 0.9708, 0.7303, 0.2696 }, + { 0.9773, 0.7326, 0.2634 }, + { 0.9831, 0.7355, 0.257 }, + { 0.9882, 0.739, 0.2504 }, + { 0.9922, 0.7431, 0.2437 }, + { 0.9952, 0.7476, 0.2373 }, + { 0.9973, 0.7524, 0.231 }, + { 0.9986, 0.7573, 0.2251 }, + { 0.9991, 0.7624, 0.2195 }, + { 0.999, 0.7675, 0.2141 }, + { 0.9985, 0.7726, 0.209 }, + { 0.9976, 0.7778, 0.2042 }, + { 0.9964, 0.7829, 0.1995 }, + { 0.995, 0.788, 0.1949 }, + { 0.9933, 0.7931, 0.1905 }, + { 0.9914, 0.7981, 0.1863 }, + { 0.9894, 0.8032, 0.1821 }, + { 0.9873, 0.8083, 0.178 }, + { 0.9851, 0.8133, 0.174 }, + { 0.9828, 0.8184, 0.17 }, + { 0.9805, 0.8235, 0.1661 }, + { 0.9782, 0.8286, 0.1622 }, + { 0.9759, 0.8337, 0.1583 }, + { 0.9736, 0.8389, 0.1544 }, + { 0.9713, 0.8441, 0.1505 }, + { 0.9692, 0.8494, 0.1465 }, + { 0.9672, 0.8548, 0.1425 }, + { 0.9654, 0.8603, 0.1385 }, + { 0.9638, 0.8659, 0.1343 }, + { 0.9623, 0.8716, 0.1301 }, + { 0.9611, 0.8774, 0.1258 }, + { 0.96, 0.8834, 0.1215 }, + { 0.9593, 0.8895, 0.1171 }, + { 0.9588, 0.8958, 0.1126 }, + { 0.9586, 0.9022, 0.1082 }, + { 0.9587, 0.9088, 0.1036 }, + { 0.9591, 0.9155, 0.099 }, + { 0.9599, 0.9225, 0.0944 }, + { 0.961, 0.9296, 0.0897 }, + { 0.9624, 0.9368, 0.085 }, + { 0.9641, 0.9443, 0.0802 }, + { 0.9662, 0.9518, 0.0753 }, + { 0.9685, 0.9595, 0.0703 }, + { 0.971, 0.9673, 0.0651 }, + { 0.9736, 0.9752, 0.0597 }, + { 0.9763, 0.9831, 0.0538 } +}; +} + +template +IGL_INLINE void igl::colormap(const ColorMapType cm, const T x, T * rgb) +{ + return colormap(cm,x,rgb[0],rgb[1],rgb[2]); +} + +template +IGL_INLINE void igl::colormap( + const ColorMapType cm, const T x_in, T & r, T & g, T & b) +{ + switch (cm) + { + case COLOR_MAP_TYPE_INFERNO: + colormap(inferno_cm, x_in, r, g, b); + break; + case COLOR_MAP_TYPE_JET: + // jet is bad so we use turbo instead + // https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html + case COLOR_MAP_TYPE_TURBO: + colormap(turbo_cm, x_in, r, g, b); + break; + case COLOR_MAP_TYPE_MAGMA: + colormap(magma_cm, x_in, r, g, b); + break; + case COLOR_MAP_TYPE_PARULA: + colormap(parula_cm, x_in, r, g, b); + break; + case COLOR_MAP_TYPE_PLASMA: + colormap(plasma_cm, x_in, r, g, b); + break; + case COLOR_MAP_TYPE_VIRIDIS: + colormap(viridis_cm, x_in, r, g, b); + break; + default: + throw std::invalid_argument("igl::colormap(): Selected colormap is unsupported!"); + break; + } +} + +template +IGL_INLINE void igl::colormap( + const double palette[256][3], const T x_in, T & r, T & g, T & b) +{ + static const unsigned int pal = 256; + const T zero = 0.0; + const T one = 1.0; + T x_in_clamped = static_cast(std::max(zero, std::min(one, x_in))); + + // simple rgb lerp from palette + unsigned int least = std::floor(x_in_clamped * static_cast(pal - 1)); + unsigned int most = std::ceil(x_in_clamped * static_cast(pal - 1)); + + T _r[2] = { static_cast(palette[least][0]), static_cast(palette[most][0]) }; + T _g[2] = { static_cast(palette[least][1]), static_cast(palette[most][1]) }; + T _b[2] = { static_cast(palette[least][2]), static_cast(palette[most][2]) }; + + T t = std::max(zero, std::min(one, static_cast(fmod(x_in_clamped * static_cast(pal), one)))); + + r = std::max(zero, std::min(one, (one - t) * _r[0] + t * _r[1])); + g = std::max(zero, std::min(one, (one - t) * _g[0] + t * _g[1])); + b = std::max(zero, std::min(one, (one - t) * _b[0] + t * _b[1])); +} + +template +IGL_INLINE void igl::colormap( + const ColorMapType cm, + const Eigen::MatrixBase & Z, + const bool normalize, + Eigen::PlainObjectBase & C) +{ + const double min_z = normalize ? Z.minCoeff() : 0; + const double max_z = normalize ? Z.maxCoeff() : 1; + return colormap(cm, Z, min_z, max_z, C); +} + +template +IGL_INLINE void igl::colormap( + const ColorMapType cm, + const Eigen::MatrixBase & Z, + const double min_z, + const double max_z, + Eigen::PlainObjectBase & C) +{ + C.resize(Z.rows(),3); + double denom = (max_z - min_z); + denom = (denom == 0) ? 1 : denom; + for(int r = 0; r < Z.rows(); ++r) { + colormap( + cm, + (typename DerivedC::Scalar)((-min_z + Z(r,0)) / denom), + C(r,0), + C(r,1), + C(r,2)); + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::colormap(igl::ColorMapType, float, float*); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap(igl::ColorMapType, double, double&, double&, double&); +// generated by autoexplicit.sh +template void igl::colormap(igl::ColorMapType, double, double*); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); + +template void igl::colormap, Eigen::Matrix >(igl::ColorMapType, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::colormap(igl::ColorMapType, float, float&, float&, float&); +#endif diff --git a/vendor/libigl/include/igl/colormap.h b/vendor/libigl/include/igl/colormap.h new file mode 100644 index 0000000000000000000000000000000000000000..9ec1aa876e21c8a1acddf05d9fc50cabf9eed5a5 --- /dev/null +++ b/vendor/libigl/include/igl/colormap.h @@ -0,0 +1,77 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Joe Graus , Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_COLORMAP_H +#define IGL_COLORMAP_H +#include "igl_inline.h" + +#include + +namespace igl { + + enum ColorMapType + { + COLOR_MAP_TYPE_INFERNO = 0, + COLOR_MAP_TYPE_JET = 1, + COLOR_MAP_TYPE_MAGMA = 2, + COLOR_MAP_TYPE_PARULA = 3, + COLOR_MAP_TYPE_PLASMA = 4, + COLOR_MAP_TYPE_VIRIDIS = 5, + COLOR_MAP_TYPE_TURBO = 6, + NUM_COLOR_MAP_TYPES = 7 + }; + // Comput [r,g,b] values of the selected colormap for + // a given factor f between 0 and 1 + // + // Inputs: + // c colormap enum + // f factor determining color value as if 0 was min and 1 was max + // Outputs: + // rgb red, green, blue value + template + IGL_INLINE void colormap(const ColorMapType cm, const T f, T * rgb); + // Outputs: + // r red value + // g green value + // b blue value + template + IGL_INLINE void colormap(const ColorMapType cm, const T f, T & r, T & g, T & b); + // Inputs: + // palette 256 by 3 array of color values + template + IGL_INLINE void colormap( + const double palette[256][3], const T x_in, T & r, T & g, T & b); + // Inputs: + // cm selected colormap palette to interpolate from + // Z #Z list of factors + // normalize whether to normalize Z to be tightly between [0,1] + // Outputs: + // C #C by 3 list of rgb colors + template + IGL_INLINE void colormap( + const ColorMapType cm, + const Eigen::MatrixBase & Z, + const bool normalize, + Eigen::PlainObjectBase & C); + // Inputs: + // min_z value at "0" + // max_z value at "1" + template + IGL_INLINE void colormap( + const ColorMapType cm, + const Eigen::MatrixBase & Z, + const double min_Z, + const double max_Z, + Eigen::PlainObjectBase & C); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "colormap.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/column_to_quats.h b/vendor/libigl/include/igl/column_to_quats.h new file mode 100644 index 0000000000000000000000000000000000000000..0be12c250d0e51faca6784d15c91084ace08adfc --- /dev/null +++ b/vendor/libigl/include/igl/column_to_quats.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COLUMN_TO_QUATS_H +#define IGL_COLUMN_TO_QUATS_H +#include "igl_inline.h" +#include +#include +#include +#include +namespace igl +{ + // "Columnize" a list of quaternions (q1x,q1y,q1z,q1w,q2x,q2y,q2z,q2w,...) + // + // Inputs: + // Q n*4-long list of coefficients + // Outputs: + // vQ n-long list of quaternions + // Returns false if n%4!=0 + IGL_INLINE bool column_to_quats( + const Eigen::VectorXd & Q, + std::vector< + Eigen::Quaterniond,Eigen::aligned_allocator > & vQ); +} + +#ifndef IGL_STATIC_LIBRARY +# include "column_to_quats.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/columnize.cpp b/vendor/libigl/include/igl/columnize.cpp new file mode 100644 index 0000000000000000000000000000000000000000..29e91c6694b4b71957812eab67e32b241d5c2c53 --- /dev/null +++ b/vendor/libigl/include/igl/columnize.cpp @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "columnize.h" +#include + +template +IGL_INLINE void igl::columnize( + const Eigen::PlainObjectBase & A, + const int k, + const int dim, + Eigen::PlainObjectBase & B) +{ + // Eigen matrices must be 2d so dim must be only 1 or 2 + assert(dim == 1 || dim == 2); + + // block height, width, and number of blocks + int m,n; + if(dim == 1) + { + m = A.rows()/k; + assert(m*(int)k == (int)A.rows()); + n = A.cols(); + }else// dim == 2 + { + m = A.rows(); + n = A.cols()/k; + assert(n*(int)k == (int)A.cols()); + } + + // resize output + B.resize(A.rows()*A.cols(),1); + + for(int b = 0;b<(int)k;b++) + { + for(int i = 0;i, Eigen::Matrix >(Eigen::PlainObjectBase > const&, int, int, Eigen::PlainObjectBase >&); +template void igl::columnize, Eigen::Matrix >(Eigen::PlainObjectBase > const&, int, int, Eigen::PlainObjectBase >&); +template void igl::columnize, Eigen::Matrix >(Eigen::PlainObjectBase > const&, int, int, Eigen::PlainObjectBase >&); +template void igl::columnize, Eigen::Matrix >(Eigen::PlainObjectBase > const&, int, int, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/comb_cross_field.h b/vendor/libigl/include/igl/comb_cross_field.h new file mode 100644 index 0000000000000000000000000000000000000000..0cbacb7ab5df1e7d6ab39c691519a5ca762f5010 --- /dev/null +++ b/vendor/libigl/include/igl/comb_cross_field.h @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_COMB_CROSS_FIELD_H +#define IGL_COMB_CROSS_FIELD_H +#include "igl_inline.h" +#include +namespace igl +{ + // Computes principal matchings of the vectors of a cross field across face edges, + // and generates a combed cross field defined on the mesh faces + + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 4 eigen Matrix of face (quad) indices + // PD1in #F by 3 eigen Matrix of the first per face cross field vector + // PD2in #F by 3 eigen Matrix of the second per face cross field vector + // Output: + // PD1out #F by 3 eigen Matrix of the first combed cross field vector + // PD2out #F by 3 eigen Matrix of the second combed cross field vector + // + + + template + IGL_INLINE void comb_cross_field(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &PD1in, + const Eigen::MatrixBase &PD2in, + Eigen::PlainObjectBase &PD1out, + Eigen::PlainObjectBase &PD2out); +} +#ifndef IGL_STATIC_LIBRARY +#include "comb_cross_field.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/comb_frame_field.h b/vendor/libigl/include/igl/comb_frame_field.h new file mode 100644 index 0000000000000000000000000000000000000000..ab5a9e7e97e5455be74a74bd9a952c32a68f2ebd --- /dev/null +++ b/vendor/libigl/include/igl/comb_frame_field.h @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_COMB_FRAME_FIELD_H +#define IGL_COMB_FRAME_FIELD_H +#include "igl_inline.h" +#include +namespace igl +{ + // Computes principal matchings of the vectors of a frame field across face edges, + // and generates a combed frame field defined on the mesh faces. This makes use of a + // combed cross field generated by combing the field created by the bisectors of the + // frame field. + + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 4 eigen Matrix of face (quad) indices + // PD1 #F by 3 eigen Matrix of the first per face cross field vector + // PD2 #F by 3 eigen Matrix of the second per face cross field vector + // BIS1_combed #F by 3 eigen Matrix of the first combed bisector field vector + // BIS2_combed #F by 3 eigen Matrix of the second combed bisector field vector + // Output: + // PD1_combed #F by 3 eigen Matrix of the first combed cross field vector + // PD2_combed #F by 3 eigen Matrix of the second combed cross field vector + // + + + template + IGL_INLINE void comb_frame_field(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &PD1, + const Eigen::MatrixBase &PD2, + const Eigen::MatrixBase &BIS1_combed, + const Eigen::MatrixBase &BIS2_combed, + Eigen::PlainObjectBase &PD1_combed, + Eigen::PlainObjectBase &PD2_combed); +} +#ifndef IGL_STATIC_LIBRARY +#include "comb_frame_field.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/combine.cpp b/vendor/libigl/include/igl/combine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d77bf3f54727aedb957f62accd1a302e7a5f3a24 --- /dev/null +++ b/vendor/libigl/include/igl/combine.cpp @@ -0,0 +1,99 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "combine.h" +#include + +template < + typename DerivedVV, + typename DerivedFF, + typename DerivedV, + typename DerivedF, + typename DerivedVsizes, + typename DerivedFsizes> +IGL_INLINE void igl::combine( + const std::vector & VV, + const std::vector & FF, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & Vsizes, + Eigen::PlainObjectBase & Fsizes) +{ + assert(VV.size() == FF.size() && + "Lists of verex lists and face lists should be same size"); + Vsizes.resize(VV.size()); + Fsizes.resize(FF.size()); + // Dimension of vertex positions + const int dim = VV.size() > 0 ? VV[0].cols() : 0; + // Simplex/element size + const int ss = FF.size() > 0 ? FF[0].cols() : 0; + int n = 0; + int m = 0; + for(int i = 0;i0) + { + F.block(kf,0,mi,ss) = Fi.array()+kv; + } + kf+=mi; + if(Vi.size() >0) + { + V.block(kv,0,ni,dim) = Vi; + } + kv+=ni; + } + assert(kv == V.rows()); + assert(kf == F.rows()); + } +} + +template < + typename DerivedVV, + typename DerivedFF, + typename DerivedV, + typename DerivedF> +IGL_INLINE void igl::combine( + const std::vector & VV, + const std::vector & FF, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F) +{ + Eigen::VectorXi Vsizes,Fsizes; + return igl::combine(VV,FF,V,F,Vsizes,Fsizes); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::combine, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::vector, std::allocator > > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::combine, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::vector, std::allocator > > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::combine, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::vector, std::allocator > > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::combine, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::vector, std::allocator > > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template void igl::combine, Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(class std::vector,class std::allocator > > const &,class std::vector,class std::allocator > > const &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/combine.h b/vendor/libigl/include/igl/combine.h new file mode 100644 index 0000000000000000000000000000000000000000..ff5e1ae34c3b21fbaa9ca6cf1fb7e4c529ea4c3b --- /dev/null +++ b/vendor/libigl/include/igl/combine.h @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COMBINE_H +#define IGL_COMBINE_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Concatenate k meshes into a single >=k connected component mesh with a + // single vertex list and face list. Similar to Maya's Combine operation. + // + // Inputs: + // VV k-long list of lists of mesh vertex positions + // FF k-long list of lists of mesh face indices so that FF[i] indexes + // VV[i] + // Outputs: + // V VV[0].rows()+...+VV[k-1].rows() by VV[0].cols() list of mesh + // vertex positions + // F FF[0].rows()+...+FF[k-1].rows() by FF[0].cols() list of mesh faces + // indices into V + // Vsizes k list so that Vsizes(i) is the #vertices in the ith input + // Fsizes k list so that Fsizes(i) is the #faces in the ith input + // Example: + // // Suppose you have mesh A (VA,FA) and mesh B (VB,FB) + // igl::combine({VA,VB},{FA,FB},V,F); + // + // + template < + typename DerivedVV, + typename DerivedFF, + typename DerivedV, + typename DerivedF, + typename DerivedVsizes, + typename DerivedFsizes> + IGL_INLINE void combine( + const std::vector & VV, + const std::vector & FF, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & Vsizes, + Eigen::PlainObjectBase & Fsizes); + template < + typename DerivedVV, + typename DerivedFF, + typename DerivedV, + typename DerivedF> + IGL_INLINE void combine( + const std::vector & VV, + const std::vector & FF, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F); +} + +#ifndef IGL_STATIC_LIBRARY +# include "combine.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/compute_frame_field_bisectors.h b/vendor/libigl/include/igl/compute_frame_field_bisectors.h new file mode 100644 index 0000000000000000000000000000000000000000..f5cef3a11416482b092c477ebc12207f8bf0f85a --- /dev/null +++ b/vendor/libigl/include/igl/compute_frame_field_bisectors.h @@ -0,0 +1,53 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_COMPUTE_FRAME_FIELD_BISECTORS_H +#define IGL_COMPUTE_FRAME_FIELD_BISECTORS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute bisectors of a frame field defined on mesh faces + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 3 eigen Matrix of face (triangle) indices + // B1 #F by 3 eigen Matrix of face (triangle) base vector 1 + // B2 #F by 3 eigen Matrix of face (triangle) base vector 2 + // PD1 #F by 3 eigen Matrix of the first per face frame field vector + // PD2 #F by 3 eigen Matrix of the second per face frame field vector + // Output: + // BIS1 #F by 3 eigen Matrix of the first per face frame field bisector + // BIS2 #F by 3 eigen Matrix of the second per face frame field bisector + // + template + IGL_INLINE void compute_frame_field_bisectors( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& B1, + const Eigen::MatrixBase& B2, + const Eigen::MatrixBase& PD1, + const Eigen::MatrixBase& PD2, + Eigen::PlainObjectBase& BIS1, + Eigen::PlainObjectBase& BIS2); + + // Wrapper without given basis vectors. + template + IGL_INLINE void compute_frame_field_bisectors( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& PD1, + const Eigen::MatrixBase& PD2, + Eigen::PlainObjectBase& BIS1, + Eigen::PlainObjectBase& BIS2); +} + +#ifndef IGL_STATIC_LIBRARY +# include "compute_frame_field_bisectors.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/connect_boundary_to_infinity.cpp b/vendor/libigl/include/igl/connect_boundary_to_infinity.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0b7aec3720f0352844d5531d8bab0907be3392a --- /dev/null +++ b/vendor/libigl/include/igl/connect_boundary_to_infinity.cpp @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "connect_boundary_to_infinity.h" +#include "boundary_facets.h" + +template +IGL_INLINE void igl::connect_boundary_to_infinity( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & FO) +{ + return connect_boundary_to_infinity(F,F.maxCoeff(),FO); +} +template +IGL_INLINE void igl::connect_boundary_to_infinity( + const Eigen::MatrixBase & F, + const typename DerivedF::Scalar inf_index, + Eigen::PlainObjectBase & FO) +{ + // Determine boundary edges + Eigen::Matrix O; + boundary_facets(F,O); + FO.resize(F.rows()+O.rows(),F.cols()); + typedef Eigen::Matrix VectorXI; + FO.topLeftCorner(F.rows(),F.cols()) = F; + FO.bottomLeftCorner(O.rows(),O.cols()) = O.rowwise().reverse(); + FO.bottomRightCorner(O.rows(),1).setConstant(inf_index); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedVO, + typename DerivedFO> +IGL_INLINE void igl::connect_boundary_to_infinity( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & VO, + Eigen::PlainObjectBase & FO) +{ + typename DerivedV::Index inf_index = V.rows(); + connect_boundary_to_infinity(F,inf_index,FO); + VO.resize(V.rows()+1,V.cols()); + VO.topLeftCorner(V.rows(),V.cols()) = V; + auto inf = std::numeric_limits::infinity(); + VO.row(V.rows()).setConstant(inf); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::connect_boundary_to_infinity, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/connect_boundary_to_infinity.h b/vendor/libigl/include/igl/connect_boundary_to_infinity.h new file mode 100644 index 0000000000000000000000000000000000000000..3109fc95291212ce2fd45bb6342af105703e6e72 --- /dev/null +++ b/vendor/libigl/include/igl/connect_boundary_to_infinity.h @@ -0,0 +1,56 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CONNECT_BOUNDARY_TO_INFINITY_H +#define IGL_CONNECT_BOUNDARY_TO_INFINITY_H +#include "igl_inline.h" +#include +namespace igl +{ + // Connect all boundary edges to a fictitious point at infinity. + // + // Inputs: + // F #F by 3 list of face indices into some V + // Outputs: + // FO #F+#O by 3 list of face indices into [V;inf inf inf], original F are + // guaranteed to come first. If (V,F) was a manifold mesh, now it is + // closed with a possibly non-manifold vertex at infinity (but it will be + // edge-manifold). + template + IGL_INLINE void connect_boundary_to_infinity( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & FO); + // Inputs: + // inf_index index of point at infinity (usually V.rows() or F.maxCoeff()) + template + IGL_INLINE void connect_boundary_to_infinity( + const Eigen::MatrixBase & F, + const typename DerivedF::Scalar inf_index, + Eigen::PlainObjectBase & FO); + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of face indices into some V + // Outputs: + // VO #V+1 by 3 list of vertex positions, original V are guaranteed to + // come first. Last point is inf, inf, inf + // FO #F+#O by 3 list of face indices into VO + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedVO, + typename DerivedFO> + IGL_INLINE void connect_boundary_to_infinity( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & VO, + Eigen::PlainObjectBase & FO); +} +#ifndef IGL_STATIC_LIBRARY +# include "connect_boundary_to_infinity.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/connected_components.cpp b/vendor/libigl/include/igl/connected_components.cpp new file mode 100644 index 0000000000000000000000000000000000000000..263b3f7a84b8b54d82ffdc4687e667dd0dfbee7e --- /dev/null +++ b/vendor/libigl/include/igl/connected_components.cpp @@ -0,0 +1,61 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "connected_components.h" +#include + +template < typename Atype, typename DerivedC, typename DerivedK> +IGL_INLINE int igl::connected_components( + const Eigen::SparseMatrix & A, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & K) +{ + typedef typename Eigen::SparseMatrix::Index Index; + const auto m = A.rows(); + assert(A.cols() == A.rows() && "A should be square"); + // 1.1 sec + // m means not yet visited + C.setConstant(m,1,m); + // Could use amortized dynamic array but didn't see real win. + K.setZero(m,1); + typename DerivedC::Scalar c = 0; + for(Eigen::Index f = 0;f Q; + Q.push(f); + while(!Q.empty()) + { + const Index g = Q.front(); + Q.pop(); + // already seen + if(C(g)::InnerIterator it (A,g); it; ++it) + { + const Index n = it.index(); + // already seen + if(C(n), Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/connected_components.h b/vendor/libigl/include/igl/connected_components.h new file mode 100644 index 0000000000000000000000000000000000000000..81fe9dbd2fe3e0cad69664cdd72181ffd3cef9da --- /dev/null +++ b/vendor/libigl/include/igl/connected_components.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CONNECTED_COMPONENTS_H +#define IGL_CONNECTED_COMPONENTS_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Determine the connected components of a graph described by the input + // adjacency matrix (similar to MATLAB's graphconncomp). + // + // Inputs: + // A #A by #A adjacency matrix (treated as describing an undirected graph) + // Outputs: + // C #A list of component indices into [0,#K-1] + // K #K list of sizes of each component + // Returns number of connected components + template < typename Atype, typename DerivedC, typename DerivedK> + IGL_INLINE int connected_components( + const Eigen::SparseMatrix & A, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & K); +} + +#ifndef IGL_STATIC_LIBRARY +# include "connected_components.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cotmatrix.cpp b/vendor/libigl/include/igl/cotmatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe168cc8a652b782ca2ca620d73863bc5f5c8234 --- /dev/null +++ b/vendor/libigl/include/igl/cotmatrix.cpp @@ -0,0 +1,232 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cotmatrix.h" +#include + +// For error printing +#include +#include "cotmatrix_entries.h" + +// Bug in unsupported/Eigen/SparseExtra needs iostream first +#include + +template +IGL_INLINE void igl::cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& L) +{ + using namespace Eigen; + using namespace std; + + L.resize(V.rows(),V.rows()); + Matrix edges; + int simplex_size = F.cols(); + // 3 for triangles, 4 for tets + assert(simplex_size == 3 || simplex_size == 4); + if(simplex_size == 3) + { + // This is important! it could decrease the comptuation time by a factor of 2 + // Laplacian for a closed 2d manifold mesh will have on average 7 entries per + // row + L.reserve(10*V.rows()); + edges.resize(3,2); + edges << + 1,2, + 2,0, + 0,1; + }else if(simplex_size == 4) + { + L.reserve(17*V.rows()); + edges.resize(6,2); + edges << + 1,2, + 2,0, + 0,1, + 3,0, + 3,1, + 3,2; + }else + { + return; + } + // Gather cotangents + Matrix C; + cotmatrix_entries(V,F,C); + + vector > IJV; + IJV.reserve(F.rows()*edges.rows()*4); + // Loop over triangles + for(int i = 0; i < F.rows(); i++) + { + // loop over edges of element + for(int e = 0;e(source,dest,C(i,e))); + IJV.push_back(Triplet(dest,source,C(i,e))); + IJV.push_back(Triplet(source,source,-C(i,e))); + IJV.push_back(Triplet(dest,dest,-C(i,e))); + } + } + L.setFromTriplets(IJV.begin(),IJV.end()); +} + +#include "massmatrix.h" +#include "pinv.h" +#include "cotmatrix_entries.h" +#include "diag.h" +#include "massmatrix.h" +#include +#include + +template < + typename DerivedV, + typename DerivedI, + typename DerivedC, + typename Scalar> +IGL_INLINE void igl::cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::SparseMatrix& L, + Eigen::SparseMatrix& M, + Eigen::SparseMatrix& P) +{ + typedef Eigen::Matrix RowVector3S; + typedef Eigen::Matrix MatrixXS; + typedef Eigen::Matrix VectorXS; + typedef Eigen::Index Index; + // number of vertices + const Index n = V.rows(); + // number of polyfaces + const Index m = C.size()-1; + assert(V.cols() == 2 || V.cols() == 3); + std::vector > Lfijv; + std::vector > Mfijv; + std::vector > Pijv; + // loop over vertices; set identity for original vertices + for(Index i = 0;i X = decltype(X)::Zero(np+1,3); + for(Index i = 0;i(A).solve(b); + X.row(np) = w.transpose()*X.topRows(np); + // scatter w into new row of P + for(Index i = 0;i M; + igl::massmatrix(X,F,igl::MASSMATRIX_TYPE_DEFAULT,M); + Mp = M.diagonal(); + } + // Scatter into fine Laplacian and mass matrices + const auto J = [&n,&np,&p,&I,&C](Index i)->Index{return i==np?n+p:I(C(p)+i);}; + // Should just build Mf as a vector... + for(Index i = 0;i Lf(n+m,n+m); + Lf.setFromTriplets(Lfijv.begin(),Lfijv.end()); + Eigen::SparseMatrix Mf(n+m,n+m); + Mf.setFromTriplets(Mfijv.begin(),Mfijv.end()); + L = P.transpose() * Lf * P; + // "unlumped" M + const Eigen::SparseMatrix PTMP = P.transpose() * Mf * P; + // Lump M + const VectorXS Mdiag = PTMP * VectorXS::Ones(n,1); + igl::diag(Mdiag,M); + + MatrixXS Vf = P*V; + Eigen::MatrixXi Ff(I.size(),3); + { + Index f = 0; + for(Index p = 0;p, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&, Eigen::SparseMatrix&, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::cotmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/cotmatrix.h b/vendor/libigl/include/igl/cotmatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..c1483ebcbb013100c557276e60c75daa2edf3554 --- /dev/null +++ b/vendor/libigl/include/igl/cotmatrix.h @@ -0,0 +1,82 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COTMATRIX_H +#define IGL_COTMATRIX_H +#include "igl_inline.h" + +#include +#include + +// History: +// Used const references rather than copying the entire mesh +// Alec 9 October 2011 +// removed cotan (uniform weights) optional parameter it was building a buggy +// half of the uniform laplacian, please see adjacency_matrix instead +// Alec 9 October 2011 + +namespace igl +{ + // Constructs the cotangent stiffness matrix (discrete laplacian) for a given + // mesh (V,F). + // + // Templates: + // DerivedV derived type of eigen matrix for V (e.g. derived from + // MatrixXd) + // DerivedF derived type of eigen matrix for F (e.g. derived from + // MatrixXi) + // Scalar scalar type for eigen sparse matrix (e.g. double) + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by simplex_size list of mesh elements (triangles or tetrahedra) + // Outputs: + // L #V by #V cotangent matrix, each row i corresponding to V(i,:) + // + // See also: adjacency_matrix + // + // Note: This Laplacian uses the convention that diagonal entries are + // **minus** the sum of off-diagonal entries. The diagonal entries are + // therefore in general negative and the matrix is **negative** semi-definite + // (immediately, -L is **positive** semi-definite) + // + template + IGL_INLINE void cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& L); + // Cotangent Laplacian (and mass matrix) for polygon meshes according to + // "Polygon Laplacian Made Simple" [Bunge et al. 2020] + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // I #I vectorized list of polygon corner indices into rows of some matrix V + // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = size of + // the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the indices of + // the ith polygon + // Outputs: + // L #V by #V polygon Laplacian made simple matrix + // M #V by #V mass matrix + // P #V+#polygons by #V prolongation operator + template < + typename DerivedV, + typename DerivedI, + typename DerivedC, + typename Scalar> + IGL_INLINE void cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::SparseMatrix& L, + Eigen::SparseMatrix& M, + Eigen::SparseMatrix& P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cotmatrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cotmatrix_entries.cpp b/vendor/libigl/include/igl/cotmatrix_entries.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af750a939fa1868b76d2124f4bdbf036730b9104 --- /dev/null +++ b/vendor/libigl/include/igl/cotmatrix_entries.cpp @@ -0,0 +1,149 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cotmatrix_entries.h" +#include "doublearea.h" +#include "squared_edge_lengths.h" +#include "edge_lengths.h" +#include "face_areas.h" +#include "volume.h" +#include "dihedral_angles.h" + +#include "verbose.h" + + +template +IGL_INLINE void igl::cotmatrix_entries( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& C) +{ + using namespace std; + using namespace Eigen; + // simplex size (3: triangles, 4: tetrahedra) + int simplex_size = F.cols(); + // Number of elements + int m = F.rows(); + + // Law of cosines + law of sines + switch(simplex_size) + { + case 3: + { + // Triangles + //Compute Squared Edge lengths + Matrix l2; + igl::squared_edge_lengths(V,F,l2); + //Compute Edge lengths + Matrix l; + l = l2.array().sqrt(); + + // double area + Matrix dblA; + doublearea(l,0.,dblA); + // cotangents and diagonal entries for element matrices + // correctly divided by 4 (alec 2010) + C.resize(m,3); + for(int i = 0;i l; + edge_lengths(V,F,l); + Matrix s; + face_areas(l,s); + Matrix cos_theta,theta; + dihedral_angles_intrinsic(l,s,theta,cos_theta); + + // volume + Matrix vol; + volume(l,vol); + + + // Law of sines + // http://mathworld.wolfram.com/Tetrahedron.html + Matrix sin_theta(m,6); + sin_theta.col(0) = vol.array() / ((2./(3.*l.col(0).array())).array() * s.col(1).array() * s.col(2).array()); + sin_theta.col(1) = vol.array() / ((2./(3.*l.col(1).array())).array() * s.col(2).array() * s.col(0).array()); + sin_theta.col(2) = vol.array() / ((2./(3.*l.col(2).array())).array() * s.col(0).array() * s.col(1).array()); + sin_theta.col(3) = vol.array() / ((2./(3.*l.col(3).array())).array() * s.col(3).array() * s.col(0).array()); + sin_theta.col(4) = vol.array() / ((2./(3.*l.col(4).array())).array() * s.col(3).array() * s.col(1).array()); + sin_theta.col(5) = vol.array() / ((2./(3.*l.col(5).array())).array() * s.col(3).array() * s.col(2).array()); + + + // http://arxiv.org/pdf/1208.0354.pdf Page 18 + C = (1./6.) * l.array() * cos_theta.array() / sin_theta.array(); + + break; + } + default: + { + fprintf(stderr, + "cotmatrix_entries.h: Error: Simplex size (%d) not supported\n", simplex_size); + assert(false); + } + } +} + +template +IGL_INLINE void igl::cotmatrix_entries( + const Eigen::MatrixBase& l, + Eigen::PlainObjectBase& C) +{ + using namespace Eigen; + const int m = l.rows(); + assert(l.cols() == 3 && "Only triangles accepted"); + //Compute squared Edge lengths + Matrix l2; + l2 = l.array().square(); + // Alec: It's a little annoying that there's duplicate code here. The + // "extrinic" version above is first computing squared edge lengths, taking + // the square root and calling this. We can't have a cotmatrix_entries(l,l2,C) + // overload because it will confuse Eigen with the cotmatrix_entries(V,F,C) + // overload. In the end, I'd like to be convinced that using l2 directly above + // is actually better numerically (or significantly faster) than just calling + // edge_lengths and this cotmatrix_entries(l,C); + // + // double area + Matrix dblA; + doublearea(l,0.,dblA); + // cotangents and diagonal entries for element matrices + // correctly divided by 4 (alec 2010) + C.resize(m,3); + for(int i = 0;i, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::cotmatrix_entries, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::cotmatrix_entries, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cotmatrix_entries, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cotmatrix_entries, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cotmatrix_entries, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cotmatrix_entries, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cotmatrix_entries, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/cotmatrix_entries.h b/vendor/libigl/include/igl/cotmatrix_entries.h new file mode 100644 index 0000000000000000000000000000000000000000..5847fd517a3d1f108742730ebb859a2f3890b87d --- /dev/null +++ b/vendor/libigl/include/igl/cotmatrix_entries.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COTMATRIX_ENTRIES_H +#define IGL_COTMATRIX_ENTRIES_H +#include "igl_inline.h" +#include +namespace igl +{ + // COTMATRIX_ENTRIES compute the cotangents of each angle in mesh (V,F) + // + // Inputs: + // V #V by dim list of rest domain positions + // F #F by {3|4} list of {triangle|tetrahedra} indices into V + // Outputs: + // C #F by 3 list of 1/2*cotangents corresponding angles + // for triangles, columns correspond to edges [1,2],[2,0],[0,1] + // OR + // C #F by 6 list of 1/6*cotangents of dihedral angles*edge lengths + // for tets, columns along edges [1,2],[2,0],[0,1],[3,0],[3,1],[3,2] + // + template + IGL_INLINE void cotmatrix_entries( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& C); + // Intrinsic version. + // + // Inputs: + // l #F by 3 list of triangle edge lengths (see edge_lengths) + // Outputs: + // C #F by 3 list of 1/2*cotangents corresponding angles + // for triangles, columns correspond to edges [1,2],[2,0],[0,1] + template + IGL_INLINE void cotmatrix_entries( + const Eigen::MatrixBase& l, + Eigen::PlainObjectBase& C); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cotmatrix_entries.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cotmatrix_intrinsic.cpp b/vendor/libigl/include/igl/cotmatrix_intrinsic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1504db5a4a3c92141381a3e6a57ad78e9c33aceb --- /dev/null +++ b/vendor/libigl/include/igl/cotmatrix_intrinsic.cpp @@ -0,0 +1,67 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cotmatrix_intrinsic.h" +#include "cotmatrix_entries.h" +#include + +template +IGL_INLINE void igl::cotmatrix_intrinsic( + const Eigen::MatrixBase & l, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& L) +{ + using namespace Eigen; + using namespace std; + // Cribbed from cotmatrix + + const int nverts = F.maxCoeff()+1; + L.resize(nverts,nverts); + Matrix edges; + int simplex_size = F.cols(); + // 3 for triangles, 4 for tets + assert(simplex_size == 3); + // This is important! it could decrease the comptuation time by a factor of 2 + // Laplacian for a closed 2d manifold mesh will have on average 7 entries per + // row + L.reserve(10*nverts); + edges.resize(3,2); + edges << + 1,2, + 2,0, + 0,1; + // Gather cotangents + Matrix C; + cotmatrix_entries(l,C); + + vector > IJV; + IJV.reserve(F.rows()*edges.rows()*4); + // Loop over triangles + for(int i = 0; i < F.rows(); i++) + { + // loop over edges of element + for(int e = 0;e(source,dest,C(i,e))); + IJV.push_back(Triplet(dest,source,C(i,e))); + IJV.push_back(Triplet(source,source,-C(i,e))); + IJV.push_back(Triplet(dest,dest,-C(i,e))); + } + } + L.setFromTriplets(IJV.begin(),IJV.end()); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::cotmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cotmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/cotmatrix_intrinsic.h b/vendor/libigl/include/igl/cotmatrix_intrinsic.h new file mode 100644 index 0000000000000000000000000000000000000000..2a4f58be6e6856d779820ba829af2a810325fd4d --- /dev/null +++ b/vendor/libigl/include/igl/cotmatrix_intrinsic.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COTMATRIX_INTRINSIC_H +#define IGL_COTMATRIX_INTRINSIC_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Constructs the cotangent stiffness matrix (discrete laplacian) for a given + // mesh with faces F and edge lengths l. + // + // Inputs: + // l #F by 3 list of (half-)edge lengths + // F #F by 3 list of face indices into some (not necessarily + // determined/embedable) list of vertex positions V. It is assumed #V == + // F.maxCoeff()+1 + // Outputs: + // L #V by #V sparse Laplacian matrix + // + // See also: cotmatrix, intrinsic_delaunay_cotmatrix + template + IGL_INLINE void cotmatrix_intrinsic( + const Eigen::MatrixBase & l, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& L); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cotmatrix_intrinsic.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/count.h b/vendor/libigl/include/igl/count.h new file mode 100644 index 0000000000000000000000000000000000000000..61aeb94e8a6cf6a4fdd61fb1d19b093b8cb62e68 --- /dev/null +++ b/vendor/libigl/include/igl/count.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COUNT_H +#define IGL_COUNT_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Note: If your looking for dense matrix matlab like sum for eigen matrics + // just use: + // M.colwise().count() or M.rowwise().count() + // + + // Count the number of non-zeros in the columns or rows of a sparse matrix + // + // Inputs: + // X m by n sparse matrix + // dim dimension along which to sum (1 or 2) + // Output: + // S n-long sparse vector (if dim == 1) + // or + // S m-long sparse vector (if dim == 2) + template + IGL_INLINE void count( + const Eigen::SparseMatrix& X, + const int dim, + Eigen::SparseVector& S); + template + IGL_INLINE void count( + const Eigen::SparseMatrix& X, + const int dim, + Eigen::PlainObjectBase& S); +} + +#ifndef IGL_STATIC_LIBRARY +# include "count.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/covariance_scatter_matrix.cpp b/vendor/libigl/include/igl/covariance_scatter_matrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24fe9f7600de810ca9b7e008cf8ab4043d21919b --- /dev/null +++ b/vendor/libigl/include/igl/covariance_scatter_matrix.cpp @@ -0,0 +1,76 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "covariance_scatter_matrix.h" +#include "arap_linear_block.h" +#include "cotmatrix.h" +#include "diag.h" +#include "sum.h" +#include "edges.h" +#include "verbose.h" +#include "cat.h" +#include "PI.h" + +IGL_INLINE void igl::covariance_scatter_matrix( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const ARAPEnergyType energy, + Eigen::SparseMatrix& CSM) +{ + using namespace Eigen; + // number of mesh vertices + int n = V.rows(); + assert(n > F.maxCoeff()); + // dimension of mesh + int dim = V.cols(); + // Number of mesh elements + int m = F.rows(); + + // number of rotations + int nr; + switch(energy) + { + case ARAP_ENERGY_TYPE_SPOKES: + nr = n; + break; + case ARAP_ENERGY_TYPE_SPOKES_AND_RIMS: + nr = n; + break; + case ARAP_ENERGY_TYPE_ELEMENTS: + nr = m; + break; + default: + fprintf( + stderr, + "covariance_scatter_matrix.h: Error: Unsupported arap energy %d\n", + energy); + return; + } + + SparseMatrix KX,KY,KZ; + arap_linear_block(V,F,0,energy,KX); + arap_linear_block(V,F,1,energy,KY); + SparseMatrix Z(n,nr); + if(dim == 2) + { + CSM = cat(1,cat(2,KX,Z),cat(2,Z,KY)).transpose(); + }else if(dim == 3) + { + arap_linear_block(V,F,2,energy,KZ); + SparseMatrixZZ(n,nr*2); + CSM = + cat(1,cat(1,cat(2,KX,ZZ),cat(2,cat(2,Z,KY),Z)),cat(2,ZZ,KZ)).transpose(); + }else + { + fprintf( + stderr, + "covariance_scatter_matrix.h: Error: Unsupported dimension %d\n", + dim); + return; + } + +} diff --git a/vendor/libigl/include/igl/covariance_scatter_matrix.h b/vendor/libigl/include/igl/covariance_scatter_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..e70c77ab13ed68f2244c72d4dd12e8b3cafa1c3c --- /dev/null +++ b/vendor/libigl/include/igl/covariance_scatter_matrix.h @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COVARIANCE_SCATTER_MATRIX_H +#define IGL_COVARIANCE_SCATTER_MATRIX_H + +#include "igl_inline.h" +#include "ARAPEnergyType.h" +#include +#include + +namespace igl +{ + // Construct the covariance scatter matrix for a given arap energy + // Inputs: + // V #V by Vdim list of initial domain positions + // F #F by 3 list of triangle indices into V + // energy ARAPEnergyType enum value defining which energy is being used. + // See ARAPEnergyType.h for valid options and explanations. + // Outputs: + // CSM dim*#V/#F by dim*#V sparse matrix containing special laplacians along + // the diagonal so that when multiplied by V gives covariance matrix + // elements, can be used to speed up covariance matrix computation + IGL_INLINE void covariance_scatter_matrix( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const ARAPEnergyType energy, + Eigen::SparseMatrix& CSM); +} + +#ifndef IGL_STATIC_LIBRARY +#include "covariance_scatter_matrix.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/cr_vector_curvature_correction.cpp b/vendor/libigl/include/igl/cr_vector_curvature_correction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd7f5103b47b643b7f7e35872604009cdad71dd0 --- /dev/null +++ b/vendor/libigl/include/igl/cr_vector_curvature_correction.cpp @@ -0,0 +1,189 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "cr_vector_curvature_correction.h" + +#include "orient_halfedges.h" +#include "gaussian_curvature.h" + +#include "squared_edge_lengths.h" +#include "doublearea.h" +#include "boundary_loop.h" +#include "internal_angles.h" + +#include "PI.h" + + +template +IGL_INLINE void +igl::cr_vector_curvature_correction( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K) +{ + Eigen::Matrix + l_sq; + squared_edge_lengths(V, F, l_sq); + cr_vector_curvature_correction_intrinsic(F, l_sq, E, oE, K); +} + + +template +IGL_INLINE void +igl::cr_vector_curvature_correction( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& K) +{ + if(E.rows()!=F.rows() || E.cols()!=F.cols() || oE.rows()!=F.rows() || + oE.cols()!=F.cols()) { + orient_halfedges(F, E, oE); + } + + const Eigen::PlainObjectBase& cE = E; + const Eigen::PlainObjectBase& coE = oE; + cr_vector_curvature_correction(V, F, cE, coE, K); +} + + +template +IGL_INLINE void +igl::cr_vector_curvature_correction_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K) +{ + Eigen::Matrix + theta; + internal_angles_using_squared_edge_lengths(l_sq, theta); + + cr_vector_curvature_correction_intrinsic(F, l_sq, theta, E, oE, K); +} + + +template +IGL_INLINE void +igl::cr_vector_curvature_correction_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& theta, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K) +{ + // Compute the angle defect kappa, set it to 0 at the boundary + const typename DerivedF::Scalar n = F.maxCoeff() + 1; + Eigen::Matrix kappa(n); + kappa.setZero(); + for(Eigen::Index i=0; i > b; + boundary_loop(F, b); + for(const auto& loop : b) { + for(auto v : loop) { + kappa(v) = 0; + } + } + + cr_vector_curvature_correction_intrinsic(F, l_sq, theta, kappa, E, oE, K); +} + + +template +IGL_INLINE void +igl::cr_vector_curvature_correction_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& theta, + const Eigen::MatrixBase& kappa, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K) +{ + assert(F.cols()==3 && "Faces have three vertices"); + assert(E.rows()==F.rows() && E.cols()==F.cols() && oE.rows()==F.rows() && + theta.rows()==F.rows() && theta.cols()==F.cols() && + oE.cols()==F.cols() && "Wrong dimension in edge vectors"); + assert(kappa.rows()==F.maxCoeff()+1 && + "Wrong dimension in theta or kappa"); + + const Eigen::Index m = F.rows(); + const typename DerivedE::Scalar nE = E.maxCoeff() + 1; + + //Divide kappa by the actual angle sum to weigh consistently. + Derivedtheta angleSum = Derivedtheta::Zero(kappa.rows(), 1); + for(Eigen::Index i=0; i + scaledKappa = kappa.array() / angleSum.array(); + + std::vector > tripletList; + tripletList.reserve(10*3*m); + for(Eigen::Index f=0; f, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::cr_vector_curvature_correction, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/cr_vector_curvature_correction.h b/vendor/libigl/include/igl/cr_vector_curvature_correction.h new file mode 100644 index 0000000000000000000000000000000000000000..8e00004c8f5e98b3da387580f66f30b5aca8fa21 --- /dev/null +++ b/vendor/libigl/include/igl/cr_vector_curvature_correction.h @@ -0,0 +1,115 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CR_VECTOR_CURVATURE_CORRECTION_H +#define IGL_CR_VECTOR_CURVATURE_CORRECTION_H + +#include "igl_inline.h" + +#include +#include + + +namespace igl +{ + // Computes the vector Crouzeix-Raviart curvature correction + // term of Oded Stein, Alec Jacobson, Max Wardetzky, Eitan + // Grinspun, 2020. "A Smoothness Energy without Boundary Distortion for + // Curved Surfaces", but using the basis functions by Oded Stein, + // Max Wardetzky, Alec Jacobson, Eitan Grinspun, 2020. + // "A Simple Discretization of the Vector Dirichlet Energy" + // + // Inputs: + // V, F: input mesh + // E: a mapping from each halfedge to each edge, as computed with + // orient_halfedges. + // will be computed if not provided. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge, as computed with orient_halfedges. + // will be computed if not provided. + // + // Outputs: + // K: computed curvature correction matrix + // E, oE: these are computed if they are not present, as described above + + template + IGL_INLINE void + cr_vector_curvature_correction( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K); + + template + IGL_INLINE void + cr_vector_curvature_correction( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& K); + + + // Version that uses intrinsic quantities as input + // + // Inputs: + // F: input mesh connectivity + // l_sq: squared edge lengths of each halfedge + // theta: the tip angles at each halfedge + // kappa: the Gaussian curvature at each vertex + // E: a mapping from each halfedge to each edge. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge. + // + // Outputs: + // K: computed curvature correction matrix + + template + IGL_INLINE void + cr_vector_curvature_correction_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K); + + template + IGL_INLINE void + cr_vector_curvature_correction_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& theta, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K); + + template + IGL_INLINE void + cr_vector_curvature_correction_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& theta, + const Eigen::MatrixBase& kappa, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& K); +} + + +#ifndef IGL_STATIC_LIBRARY +# include "cr_vector_curvature_correction.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cr_vector_laplacian.cpp b/vendor/libigl/include/igl/cr_vector_laplacian.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5bf539e6631d96ae87c5c61123ef9be85385341b --- /dev/null +++ b/vendor/libigl/include/igl/cr_vector_laplacian.cpp @@ -0,0 +1,128 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cr_vector_laplacian.h" + +#include + +#include "orient_halfedges.h" + +#include "doublearea.h" +#include "squared_edge_lengths.h" + + +template +IGL_INLINE void +igl::cr_vector_laplacian( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& L) +{ + Eigen::Matrix + l_sq; + squared_edge_lengths(V, F, l_sq); + cr_vector_laplacian_intrinsic(F, l_sq, E, oE, L); +} + + +template +IGL_INLINE void +igl::cr_vector_laplacian( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& L) +{ + if(E.rows()!=F.rows() || E.cols()!=F.cols() || oE.rows()!=F.rows() || + oE.cols()!=F.cols()) { + orient_halfedges(F, E, oE); + } + + const Eigen::PlainObjectBase& cE = E; + const Eigen::PlainObjectBase& coE = oE; + cr_vector_laplacian(V, F, cE, coE, L); +} + + +template +IGL_INLINE void +igl::cr_vector_laplacian_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& L) +{ + Eigen::Matrix + dA; + DerivedL_sq l_sqrt = l_sq.array().sqrt().matrix(); + doublearea(l_sqrt, dA); + cr_vector_laplacian_intrinsic(F, l_sq, dA, E, oE, L); +} + + +template +IGL_INLINE void +igl::cr_vector_laplacian_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& dA, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& L) +{ + assert(F.cols()==3 && "Faces have three vertices"); + assert(E.rows()==F.rows() && E.cols()==F.cols() && oE.rows()==F.rows() && + oE.cols()==F.cols() && "Wrong dimension in edge vectors"); + assert(l_sq.rows()==F.rows() && l_sq.cols()==3 && "l_sq dimensions wrong"); + assert(dA.size()==F.rows() && "dA dimensions wrong"); + + const Eigen::Index m = F.rows(); + const typename DerivedE::Scalar nE = E.maxCoeff() + 1; + + std::vector > tripletList; + tripletList.reserve(10*3*m); + for(Eigen::Index f=0; f, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&); +template void igl::cr_vector_laplacian_intrinsic, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/cr_vector_laplacian.h b/vendor/libigl/include/igl/cr_vector_laplacian.h new file mode 100644 index 0000000000000000000000000000000000000000..87f04278278efc7a584be89680bb414e11ecc26b --- /dev/null +++ b/vendor/libigl/include/igl/cr_vector_laplacian.h @@ -0,0 +1,99 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CR_VECTOR_LAPLACIAN_H +#define IGL_CR_VECTOR_LAPLACIAN_H + +#include "igl_inline.h" + +#include +#include + + +namespace igl +{ + // Computes the CR vector Laplacian matrix. + // See Oded Stein, Max Wardetzky, Alec Jacobson, Eitan Grinspun, 2020. + // "A Simple Discretization of the Vector Dirichlet Energy" + // + // Inputs: + // V, F: input mesh + // E: a mapping from each halfedge to each edge, as computed with + // orient_halfedges. + // will be computed if not provided. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge, as computed with orient_halfedges. + // will be computed if not provided. + // + // Outputs: + // L: computed Laplacian matrix + // E, oE: these are computed if they are not present, as described above + + template + IGL_INLINE void + cr_vector_laplacian( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& L); + + template + IGL_INLINE void + cr_vector_laplacian( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& L); + + + // Version that uses intrinsic quantities as input + // + // Inputs: + // F: input mesh connectivity + // l_sq: squared edge lengths of each halfedge + // dA: double area of each face + // E: a mapping from each halfedge to each edge. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge. + // + // Outputs: + // L: computed Laplacian matrix + + template + IGL_INLINE void + cr_vector_laplacian_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& L); + + template + IGL_INLINE void + cr_vector_laplacian_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& dA, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& L); + + +} + + +#ifndef IGL_STATIC_LIBRARY +# include "cr_vector_laplacian.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cr_vector_mass.cpp b/vendor/libigl/include/igl/cr_vector_mass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a5e45c8de7dee363a7f3f23a1f9b53ce92e3c18 --- /dev/null +++ b/vendor/libigl/include/igl/cr_vector_mass.cpp @@ -0,0 +1,112 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cr_vector_mass.h" + +#include + +#include "orient_halfedges.h" + +#include "doublearea.h" +#include "squared_edge_lengths.h" + + +template +IGL_INLINE void +igl::cr_vector_mass( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& M) +{ + Eigen::Matrix + l_sq; + squared_edge_lengths(V, F, l_sq); + cr_vector_mass_intrinsic(F, l_sq, E, oE, M); +} + + +template +IGL_INLINE void +igl::cr_vector_mass( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& M) +{ + if(E.rows()!=F.rows() || E.cols()!=F.cols() || oE.rows()!=F.rows() || + oE.cols()!=F.cols()) { + orient_halfedges(F, E, oE); + } + + const Eigen::PlainObjectBase& cE = E; + const Eigen::PlainObjectBase& coE = oE; + cr_vector_mass(V, F, cE, coE, M); +} + + +template +IGL_INLINE void +igl::cr_vector_mass_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& M) +{ + Eigen::Matrix + dA; + DerivedL_sq l_sqrt = l_sq.array().sqrt().matrix(); + doublearea(l_sqrt, dA); + cr_vector_mass_intrinsic(F, l_sq, dA, E, oE, M); +} + + +template +IGL_INLINE void +igl::cr_vector_mass_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& dA, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& M) +{ + assert(F.cols()==3 && "Faces have three vertices"); + assert(E.rows()==F.rows() && E.cols()==F.cols() && oE.rows()==F.rows() && + oE.cols()==F.cols() && "Wrong dimension in edge vectors"); + + const Eigen::Index m = F.rows(); + const typename DerivedE::Scalar nE = E.maxCoeff() + 1; + + std::vector > tripletList; + tripletList.reserve(2*3*m); + for(Eigen::Index f=0; f, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&); +template void igl::cr_vector_mass_intrinsic, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/cross.h b/vendor/libigl/include/igl/cross.h new file mode 100644 index 0000000000000000000000000000000000000000..cfbe563ed159961c5c18e18b817b4fc5f06b1480 --- /dev/null +++ b/vendor/libigl/include/igl/cross.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CROSS_H +#define IGL_CROSS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Computes out = cross(a,b) + // Inputs: + // a left 3d vector + // b right 3d vector + // Outputs: + // out result 3d vector + IGL_INLINE void cross( const double *a, const double *b, double *out); + // Computes C = cross(A,B,2); + // + // Inputs: + // A #A by 3 list of row-vectors + // B #A by 3 list of row-vectors + // Outputs: + // C #A by 3 list of row-vectors + template < + typename DerivedA, + typename DerivedB, + typename DerivedC> + IGL_INLINE void cross( + const Eigen::PlainObjectBase & A, + const Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & C); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cross.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cross_field_mismatch.cpp b/vendor/libigl/include/igl/cross_field_mismatch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa4df32affcb345ec99370873d32c6b4eeb217f1 --- /dev/null +++ b/vendor/libigl/include/igl/cross_field_mismatch.cpp @@ -0,0 +1,132 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "cross_field_mismatch.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace igl { + template + class MismatchCalculator + { + public: + + const Eigen::MatrixBase &V; + const Eigen::MatrixBase &F; + const Eigen::MatrixBase &PD1; + const Eigen::MatrixBase &PD2; + + DerivedV N; + + private: + // internal + std::vector V_border; // bool + std::vector > VF; + std::vector > VFi; + + DerivedF TT; + DerivedF TTi; + + + private: + ///compute the mismatch between 2 faces + inline int mismatchByCross(const int f0, + const int f1) + { + Eigen::Matrix dir0 = PD1.row(f0); + Eigen::Matrix dir1 = PD1.row(f1); + Eigen::Matrix n0 = N.row(f0); + Eigen::Matrix n1 = N.row(f1); + + Eigen::Matrix dir1Rot = igl::rotation_matrix_from_directions(n1,n0)*dir1; + dir1Rot.normalize(); + + double angle_diff = atan2(dir1Rot.dot(PD2.row(f0)),dir1Rot.dot(PD1.row(f0))); + + double step=igl::PI/2.0; + int i=(int)std::floor((angle_diff/step)+0.5); + int k=0; + if (i>=0) + k=i%4; + else + k=(-(3*i))%4; + return k; + } + + +public: + inline MismatchCalculator(const Eigen::MatrixBase &_V, + const Eigen::MatrixBase &_F, + const Eigen::MatrixBase &_PD1, + const Eigen::MatrixBase &_PD2): + V(_V), + F(_F), + PD1(_PD1), + PD2(_PD2) + { + igl::per_face_normals(V,F,N); + V_border = igl::is_border_vertex(F); + igl::vertex_triangle_adjacency(V,F,VF,VFi); + igl::triangle_triangle_adjacency(F,TT,TTi); + } + + inline void calculateMismatch(Eigen::PlainObjectBase &Handle_MMatch) + { + Handle_MMatch.setConstant(F.rows(),3,-1); + for (size_t i=0;i +IGL_INLINE void igl::cross_field_mismatch(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &PD1, + const Eigen::MatrixBase &PD2, + const bool isCombed, + Eigen::PlainObjectBase &mismatch) +{ + DerivedV PD1_combed; + DerivedV PD2_combed; + + if (!isCombed) + igl::comb_cross_field(V,F,PD1,PD2,PD1_combed,PD2_combed); + else + { + PD1_combed = PD1; + PD2_combed = PD2; + } + igl::MismatchCalculator sf(V, F, PD1_combed, PD2_combed); + sf.calculateMismatch(mismatch); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::cross_field_mismatch, Eigen::Matrix >(Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, const bool, Eigen::PlainObjectBase > &); +template void igl::cross_field_mismatch, Eigen::Matrix >( Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, const bool, Eigen::PlainObjectBase > &); +template void igl::cross_field_mismatch, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, Eigen::MatrixBase > const &, const bool, Eigen::PlainObjectBase > &); + +#endif diff --git a/vendor/libigl/include/igl/crouzeix_raviart_cotmatrix.cpp b/vendor/libigl/include/igl/crouzeix_raviart_cotmatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b89bd55869f6234dda1d5bc2354d0cb3c378b72a --- /dev/null +++ b/vendor/libigl/include/igl/crouzeix_raviart_cotmatrix.cpp @@ -0,0 +1,101 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "crouzeix_raviart_cotmatrix.h" +#include "unique_simplices.h" +#include "oriented_facets.h" +#include "is_edge_manifold.h" +#include "cotmatrix_entries.h" + +template +void igl::crouzeix_raviart_cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix & L, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & EMAP) +{ + // All occurrences of directed "facets" + Eigen::Matrix allE; + oriented_facets(F,allE); + Eigen::VectorXi _1; + unique_simplices(allE,E,_1,EMAP); + return crouzeix_raviart_cotmatrix(V,F,E,EMAP,L); +} + +template +void igl::crouzeix_raviart_cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EMAP, + Eigen::SparseMatrix & L) +{ + // number of rows + const int m = F.rows(); + // Element simplex size + const int ss = F.cols(); + // Mesh should be edge-manifold + assert(F.cols() != 3 || is_edge_manifold(F)); + typedef Eigen::Matrix MatrixXS; + MatrixXS C; + cotmatrix_entries(V,F,C); + Eigen::MatrixXi F2E(m,ss); + { + int k =0; + for(int c = 0;c > LIJV;LIJV.reserve(k*m); + Eigen::VectorXi LI(k),LJ(k),LV(k); + // Compensation factor to match scales in matlab version + double factor = 2.0; + + switch(ss) + { + default: assert(false && "unsupported simplex size"); + case 3: + factor = 4.0; + LI<<0,1,2,1,2,0,0,1,2,1,2,0; + LJ<<1,2,0,0,1,2,0,1,2,1,2,0; + LV<<2,0,1,2,0,1,2,0,1,2,0,1; + break; + case 4: + factor *= -1.0; + LI<<0,3,3,3,1,2,1,0,1,2,2,0,0,3,3,3,1,2,1,0,1,2,2,0; + LJ<<1,0,1,2,2,0,0,3,3,3,1,2,0,3,3,3,1,2,1,0,1,2,2,0; + LV<<2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5,0,1; + break; + } + + for(int f=0;f, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::crouzeix_raviart_cotmatrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/crouzeix_raviart_massmatrix.cpp b/vendor/libigl/include/igl/crouzeix_raviart_massmatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b73d943b0e194a100052176be7d97ba1bb94b079 --- /dev/null +++ b/vendor/libigl/include/igl/crouzeix_raviart_massmatrix.cpp @@ -0,0 +1,86 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "crouzeix_raviart_massmatrix.h" +#include "unique_simplices.h" +#include "oriented_facets.h" + +#include "is_edge_manifold.h" +#include "doublearea.h" +#include "volume.h" + +#include +#include + +template +void igl::crouzeix_raviart_massmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix & M, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & EMAP) +{ + // All occurrences of directed "facets" + Eigen::Matrix allE; + oriented_facets(F,allE); + Eigen::Matrix _1; + unique_simplices(allE,E,_1,EMAP); + return crouzeix_raviart_massmatrix(V,F,E,EMAP,M); +} + +template +void igl::crouzeix_raviart_massmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EMAP, + Eigen::SparseMatrix & M) +{ + using namespace Eigen; + using namespace std; + // Mesh should be edge-manifold (TODO: replace `is_edge_manifold` with + // `is_facet_manifold`) + assert(F.cols() != 3 || is_edge_manifold(F)); + // number of elements (triangles) + const int m = F.rows(); + // Get triangle areas/volumes + VectorXd TA; + // Element simplex size + const int ss = F.cols(); + switch(ss) + { + default: + assert(false && "Unsupported simplex size"); + case 3: + doublearea(V,F,TA); + TA *= 0.5; + break; + case 4: + volume(V,F,TA); + break; + } + vector > MIJV(ss*m); + assert(EMAP.size() == m*ss); + for(int f = 0;f(EMAP(f+m*c, 0),EMAP(f+m*c, 0),TA(f)/(double)(ss)); + } + } + M.resize(E.rows(),E.rows()); + M.setFromTriplets(MIJV.begin(),MIJV.end()); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::crouzeix_raviart_massmatrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::crouzeix_raviart_massmatrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::crouzeix_raviart_massmatrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::crouzeix_raviart_massmatrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/crouzeix_raviart_massmatrix.h b/vendor/libigl/include/igl/crouzeix_raviart_massmatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..256aa20676358208015226facfdb8531532500ee --- /dev/null +++ b/vendor/libigl/include/igl/crouzeix_raviart_massmatrix.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef CROUZEIX_RAVIART_MASSMATRIX_H +#define CROUZEIX_RAVIART_MASSMATRIX_H +#include +#include + +namespace igl +{ + // CROUZEIX_RAVIART_MASSMATRIX Compute the Crouzeix-Raviart mass matrix where + // M(e,e) is just the sum of the areas of the triangles on either side of an + // edge e. + // + // See for example "Discrete Quadratic Curvature Energies" [Wardetzky, Bergou, + // Harmon, Zorin, Grinspun 2007] + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3/4 list of triangle/tetrahedron indices + // Outputs: + // M #E by #E edge/face-based diagonal mass matrix + // E #E by 2/3 list of edges/faces + // EMAP #F*3/4 list of indices mapping allE to E + // + // See also: crouzeix_raviart_cotmatrix + template + void crouzeix_raviart_massmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix & M, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & EMAP); + // wrapper if E and EMAP are already computed (better match!) + template + void crouzeix_raviart_massmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EMAP, + Eigen::SparseMatrix & M); +} +#ifndef IGL_STATIC_LIBRARY +# include "crouzeix_raviart_massmatrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cumprod.h b/vendor/libigl/include/igl/cumprod.h new file mode 100644 index 0000000000000000000000000000000000000000..d8fa73b48292fdb5ec94e9450f3530fc375777e6 --- /dev/null +++ b/vendor/libigl/include/igl/cumprod.h @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CUMPROD_H +#define IGL_CUMPROD_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // Computes a cumulative product of the columns of X, like matlab's `cumprod`. + // + // Templates: + // DerivedX Type of matrix X + // DerivedY Type of matrix Y + // Inputs: + // X m by n Matrix to be cumulatively multiplied. + // dim dimension to take cumulative product (1 or 2) + // Output: + // Y m by n Matrix containing cumulative product. + // + template + IGL_INLINE void cumprod( + const Eigen::MatrixBase & X, + const int dim, + Eigen::PlainObjectBase & Y); + //template + //IGL_INLINE void cumprod( + // const Eigen::MatrixBase & X, + // Eigen::PlainObjectBase & Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cumprod.cpp" +#endif + +#endif + + diff --git a/vendor/libigl/include/igl/cumsum.h b/vendor/libigl/include/igl/cumsum.h new file mode 100644 index 0000000000000000000000000000000000000000..d9a674851e1166ac81d9b024e7830f1bc4548a92 --- /dev/null +++ b/vendor/libigl/include/igl/cumsum.h @@ -0,0 +1,62 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CUMSUM_H +#define IGL_CUMSUM_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // Computes a cumulative sum of the columns of X, like matlab's `cumsum`. + // + // Templates: + // DerivedX Type of matrix X + // DerivedY Type of matrix Y + // Inputs: + // X m by n Matrix to be cumulatively summed. + // dim dimension to take cumulative sum (1 or 2) + // Output: + // Y m by n Matrix containing cumulative sum. + // + template + IGL_INLINE void cumsum( + const Eigen::MatrixBase & X, + const int dim, + Eigen::PlainObjectBase & Y); + // Computes a cumulative sum of the columns of [0;X] + // + // Inputs: + // X m by n Matrix to be cumulatively summed. + // dim dimension to take cumulative sum (1 or 2) + // zero_prefix whe + // Output: + // if zero_prefix == false + // Y m by n Matrix containing cumulative sum + // else + // Y m+1 by n Matrix containing cumulative sum if dim=1 + // or + // Y m by n+1 Matrix containing cumulative sum if dim=2 + template + IGL_INLINE void cumsum( + const Eigen::MatrixBase & X, + const int dim, + const bool zero_prefix, + Eigen::PlainObjectBase & Y); + //template + //IGL_INLINE void cumsum( + // const Eigen::MatrixBase & X, + // Eigen::PlainObjectBase & Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "cumsum.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/curved_hessian_energy.cpp b/vendor/libigl/include/igl/curved_hessian_energy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c57407d324f5bc9b377fc07f90e491575db56de --- /dev/null +++ b/vendor/libigl/include/igl/curved_hessian_energy.cpp @@ -0,0 +1,127 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "curved_hessian_energy.h" + +#include "orient_halfedges.h" +#include "doublearea.h" +#include "squared_edge_lengths.h" +#include "cr_vector_laplacian.h" +#include "cr_vector_mass.h" +#include "cr_vector_curvature_correction.h" +#include "scalar_to_cr_vector_gradient.h" + + +template +IGL_INLINE void +igl::curved_hessian_energy( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::SparseMatrix& Q) +{ + Eigen::MatrixXi E, oE; + curved_hessian_energy(V, F, E, oE, Q); +} + + +template +IGL_INLINE void +igl::curved_hessian_energy( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& Q) +{ + Eigen::Matrix + l_sq; + squared_edge_lengths(V, F, l_sq); + curved_hessian_energy_intrinsic(F, l_sq, E, oE, Q); +} + + +template +IGL_INLINE void +igl::curved_hessian_energy( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& Q) +{ + if(E.rows()!=F.rows() || E.cols()!=F.cols() || oE.rows()!=F.rows() || + oE.cols()!=F.cols()) { + orient_halfedges(F, E, oE); + } + + const Eigen::PlainObjectBase& cE = E; + const Eigen::PlainObjectBase& coE = oE; + curved_hessian_energy(V, F, cE, coE, Q); +} + + +template +IGL_INLINE void +igl::curved_hessian_energy_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& Q) +{ + Eigen::Matrix + dA; + Eigen::Matrix + l_sqrt = l_sq.array().sqrt().matrix(); + doublearea(l_sqrt, dA); + curved_hessian_energy_intrinsic(F, l_sq, dA, E, oE, Q); +} + + +template +IGL_INLINE void +igl::curved_hessian_energy_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& dA, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& Q) +{ + //Matrices that need to be combined + Eigen::SparseMatrix M, D, L, K; + cr_vector_mass_intrinsic(F, l_sq, dA, E, oE, M); + scalar_to_cr_vector_gradient_intrinsic(F, l_sq, dA, E, oE, D); + cr_vector_laplacian_intrinsic(F, l_sq, dA, E, oE, L); + cr_vector_curvature_correction_intrinsic(F, l_sq, E, oE, K); + + //Invert M + std::vector > tripletListMi; + for(Eigen::Index k=0; k::InnerIterator it(M,k); + it; ++it) { + if(it.value() > 0) { + tripletListMi.emplace_back(it.row(), it.col(), 1./it.value()); + } + } + } + Eigen::SparseMatrix Mi(M.rows(), M.cols()); + Mi.setFromTriplets(tripletListMi.begin(), tripletListMi.end()); + + //Hessian energy matrix + Q = D.transpose()*Mi*(L + K)*Mi*D; +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::curved_hessian_energy, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/curved_hessian_energy.h b/vendor/libigl/include/igl/curved_hessian_energy.h new file mode 100644 index 0000000000000000000000000000000000000000..4aeee5e6f5979c2a89ab2f0c374259275f701821 --- /dev/null +++ b/vendor/libigl/include/igl/curved_hessian_energy.h @@ -0,0 +1,114 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CURVED_HESSIAN_ENERGY_H +#define IGL_CURVED_HESSIAN_ENERGY_H + +#include "igl_inline.h" + +#include +#include + + +namespace igl +{ + // Computes the curved Hessian energy using the Crouzeix-Raviart + // discretization. + // See Oded Stein, Alec Jacobson, Max Wardetzky, Eitan Grinspun, 2020. + // "A Smoothness Energy without Boundary Distortion for Curved Surfaces" + // + // Inputs: + // V, F: input mesh + // + // Outputs: + // Q: computed Hessian energy matrix + + template + IGL_INLINE void + curved_hessian_energy( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::SparseMatrix& Q); + + // Version that exposes the edge orientation used. + // + // Inputs: + // V, F: input mesh + // E: a mapping from each halfedge to each edge, as computed with + // orient_halfedges. + // will be computed if not provided. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge, as computed with orient_halfedges. + // will be computed if not provided. + // + // Outputs: + // Q: computed Hessian energy matrix + // E, oE: these are computed if they are not present, as described above + template + IGL_INLINE void + curved_hessian_energy( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& Q); + + template + IGL_INLINE void + curved_hessian_energy( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& Q); + + + // Version that uses intrinsic quantities as input + // + // Inputs: + // F: input mesh connectivity + // l_sq: squared edge lengths of each halfedge + // dA: double area of each face + // E: a mapping from each halfedge to each edge. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge. + // + // Outputs: + // Q: computed Hessian energy matrix + + template + IGL_INLINE void + curved_hessian_energy_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& Q); + + template + IGL_INLINE void + curved_hessian_energy_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& dA, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& Q); + + +} + + +#ifndef IGL_STATIC_LIBRARY +# include "curved_hessian_energy.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cut_mesh.cpp b/vendor/libigl/include/igl/cut_mesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa35c3c24cb829fdd8557e276ecfef31c6bad225 --- /dev/null +++ b/vendor/libigl/include/igl/cut_mesh.cpp @@ -0,0 +1,149 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2019 Hanxiao Shen +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include +#include +#include +#include + +// wrapper for input/output style +template +IGL_INLINE void igl::cut_mesh( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& C, + Eigen::PlainObjectBase& Vn, + Eigen::PlainObjectBase& Fn +){ + Vn = V; + Fn = F; + typedef typename DerivedF::Scalar Index; + Eigen::Matrix _I; + cut_mesh(Vn,Fn,C,_I); +} + +template +IGL_INLINE void igl::cut_mesh( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& C, + Eigen::PlainObjectBase& Vn, + Eigen::PlainObjectBase& Fn, + Eigen::PlainObjectBase& I +){ + Vn = V; + Fn = F; + cut_mesh(Vn,Fn,C,I); +} + +template +IGL_INLINE void igl::cut_mesh( + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + const Eigen::MatrixBase& C, + Eigen::PlainObjectBase& I +){ + typedef typename DerivedF::Scalar Index; + DerivedF FF, FFi; + igl::triangle_triangle_adjacency(F,FF,FFi); + igl::cut_mesh(V,F,FF,FFi,C,I); +} + +template +IGL_INLINE void igl::cut_mesh( + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + Eigen::MatrixBase& FF, + Eigen::MatrixBase& FFi, + const Eigen::MatrixBase& C, + Eigen::PlainObjectBase& I +){ + + typedef typename DerivedF::Scalar Index; + + // store current number of occurance of each vertex as the alg proceed + Eigen::Matrix occurence(V.rows()); + occurence.setConstant(1); + + // set eventual number of occurance of each vertex expected + Eigen::Matrix eventual(V.rows()); + eventual.setZero(); + for(Index i=0;i 0) ? eventual(i)-1 : 0); + V.conservativeResize(n_v+n_new,Eigen::NoChange); + I = DerivedI::LinSpaced(V.rows(),0,V.rows()); + + // pointing to the current bottom of V + Index pos = n_v; + for(Index f=0;f= n_v) continue; // ignore new vertices + if(C(f,k) == 1 && occurence(v0) != eventual(v0)){ + igl::HalfEdgeIterator he(F,FF,FFi,f,k); + + // rotate clock-wise around v0 until hit another cut + std::vector fan; + Index fi = he.Fi(); + Index ei = he.Ei(); + do{ + fan.push_back(fi); + he.flipE(); + he.flipF(); + fi = he.Fi(); + ei = he.Ei(); + }while(C(fi,ei) == 0 && !he.isBorder()); + + // make a copy + V.row(pos) << V.row(v0); + I(pos) = v0; + // add one occurance to v0 + occurence(v0) += 1; + + // replace old v0 + for(Index f0: fan) + for(Index j=0;j<3;j++) + if(F(f0,j) == v0) + F(f0,j) = pos; + + // mark cuts as boundary + FF(f,k) = -1; + FF(fi,ei) = -1; + + pos++; + } + } + } + +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::cut_mesh, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/cut_mesh.h b/vendor/libigl/include/igl/cut_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..1b175c8aec9a8a972c2c946b6dbdf0145c358630 --- /dev/null +++ b/vendor/libigl/include/igl/cut_mesh.h @@ -0,0 +1,84 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2019 Hanxiao Shen +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CUT_MESH_H +#define IGL_CUT_MESH_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Given a mesh and a list of edges that are to be cut, the function + // generates a new disk-topology mesh that has the cuts at its boundary. + // + // + // Known issues: Assumes mesh is edge-manifold. + // + // Inputs: + // V #V by 3 list of the vertex positions + // F #F by 3 list of the faces + // cuts #F by 3 list of boolean flags, indicating the edges that need to + // be cut (has 1 at the face edges that are to be cut, 0 otherwise) + // Outputs: + // Vn #V by 3 list of the vertex positions of the cut mesh. This matrix + // will be similar to the original vertices except some rows will be + // duplicated. + // Fn #F by 3 list of the faces of the cut mesh(must be triangles). This + // matrix will be similar to the original face matrix except some indices + // will be redirected to point to the newly duplicated vertices. + // I #V by 1 list of the map between Vn to original V index. + + // In place mesh cut + template + IGL_INLINE void cut_mesh( + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + const Eigen::MatrixBase& cuts, + Eigen::PlainObjectBase& I + ); + + template + IGL_INLINE void cut_mesh( + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + Eigen::MatrixBase& FF, + Eigen::MatrixBase& FFi, + const Eigen::MatrixBase& C, + Eigen::PlainObjectBase& I + ); + + template + IGL_INLINE void cut_mesh( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& cuts, + Eigen::PlainObjectBase& Vn, + Eigen::PlainObjectBase& Fn + ); + + template + IGL_INLINE void cut_mesh( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& cuts, + Eigen::PlainObjectBase& Vn, + Eigen::PlainObjectBase& Fn, + Eigen::PlainObjectBase& I + ); + + + +} + + +#ifndef IGL_STATIC_LIBRARY +#include "cut_mesh.cpp" +#endif + + +#endif diff --git a/vendor/libigl/include/igl/cut_mesh_from_singularities.cpp b/vendor/libigl/include/igl/cut_mesh_from_singularities.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f6150da5aa00d5431a68c20af8aef0c12382226 --- /dev/null +++ b/vendor/libigl/include/igl/cut_mesh_from_singularities.cpp @@ -0,0 +1,205 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "cut_mesh_from_singularities.h" + +#include +#include + +#include +#include + + +namespace igl { + template < + typename DerivedV, + typename DerivedF, + typename DerivedM, + typename DerivedO + > + class MeshCutter + { + protected: + const Eigen::MatrixBase &V; + const Eigen::MatrixBase &F; + const Eigen::MatrixBase &Handle_MMatch; + + Eigen::VectorXi F_visited; + DerivedF TT; + DerivedF TTi; + + Eigen::MatrixXi E, F2E, E2F; + protected: + + inline bool IsRotSeam(const int f0,const int edge) + { + unsigned char MM = Handle_MMatch(f0,edge); + return (MM!=0); + } + + inline void FloodFill(const int start, Eigen::PlainObjectBase &Handle_Seams) + { + std::deque d; + ///clean the visited flag + F_visited(start) = true; + d.push_back(start); + + while (!d.empty()) + { + int f = d.at(0); d.pop_front(); + for (int s = 0; s<3; s++) + { + int g = TT(f,s); // f->FFp(s); + int j = TTi(f,s); // f->FFi(s); + + if (j == -1) + { + g = f; + j = s; + } + + if ((!(IsRotSeam(f,s))) && (!(IsRotSeam(g,j))) && (!F_visited(g)) ) + { + Handle_Seams(f,s)=false; + Handle_Seams(g,j)=false; + F_visited(g) = true; + d.push_back(g); + } + } + } + } + + inline void Retract(Eigen::PlainObjectBase &Handle_Seams) + { + std::vector e(V.rows(),0); // number of edges per vert + // for (unsigned f=0; fIsD()) + { + for (int s = 0; s<3; s++) + { + if (Handle_Seams(f,s)) + if (!(IsRotSeam(f,s))) // never retract rot seams + { + if (e[ F(f,s) ] == 1) { + // dissolve seam + Handle_Seams(f,s)=false; + if (TT(f,s) != -1) + Handle_Seams(TT(f,s),TTi(f,s))=false; + + e[ F(f,s)] --; + e[ F(f,(s+1)%3) ] --; + over = false; + } + } + } + } + + if (guard++>10000) + over = true; + + } while (!over); + } + + public: + + inline MeshCutter(const Eigen::MatrixBase &V_, + const Eigen::MatrixBase &F_, + const Eigen::MatrixBase &Handle_MMatch_): + V(V_), + F(F_), + Handle_MMatch(Handle_MMatch_) + { + triangle_triangle_adjacency(F,TT,TTi); + edge_topology(V,F,E,F2E,E2F); + }; + + inline void cut(Eigen::PlainObjectBase &Handle_Seams) + { + F_visited.setConstant(F.rows(),0); + Handle_Seams.setConstant(F.rows(),3,1); + + int index=0; + for (unsigned f = 0; f +IGL_INLINE void igl::cut_mesh_from_singularities(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &Handle_MMatch, + Eigen::PlainObjectBase &Handle_Seams) +{ + igl::MeshCutter< DerivedV, DerivedF, DerivedM, DerivedO> mc(V, F, Handle_MMatch); + mc.cut(Handle_Seams); + +} +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::cut_mesh_from_singularities, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/cut_mesh_from_singularities.h b/vendor/libigl/include/igl/cut_mesh_from_singularities.h new file mode 100644 index 0000000000000000000000000000000000000000..c95adaadec6062c9e760bdd359ed8eae8f95bce4 --- /dev/null +++ b/vendor/libigl/include/igl/cut_mesh_from_singularities.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_CUT_MESH_FROM_SINGULARITIES_H +#define IGL_CUT_MESH_FROM_SINGULARITIES_H +#include "igl_inline.h" +#include +namespace igl +{ + // Given a mesh (V,F) and the integer mismatch of a cross field per edge + // (mismatch), finds the cut_graph connecting the singularities (seams) and the + // degree of the singularities singularity_index + // + // Input: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of faces + // mismatch #F by 3 list of per corner integer mismatch + // Outputs: + // seams #F by 3 list of per corner booleans that denotes if an edge is a + // seam or not + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedM, + typename DerivedO> + IGL_INLINE void cut_mesh_from_singularities( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &MMatch, + Eigen::PlainObjectBase &seams); +} +#ifndef IGL_STATIC_LIBRARY +#include "cut_mesh_from_singularities.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cut_to_disk.h b/vendor/libigl/include/igl/cut_to_disk.h new file mode 100644 index 0000000000000000000000000000000000000000..cc6ae32663f1215f51904a7c6fa024b9d8f0c8cf --- /dev/null +++ b/vendor/libigl/include/igl/cut_to_disk.h @@ -0,0 +1,52 @@ +#ifndef IGL_CUT_TO_DISK_H +#define IGL_CUT_TO_DISK_H +#include "igl_inline.h" + +#include + +#include + +namespace igl +{ + // Given a triangle mesh, computes a set of edge cuts sufficient to carve the + // mesh into a topological disk, without disconnecting any connected components. + // Nothing else about the cuts (including number, total length, or smoothness) + // is guaranteed to be optimal. + // + // Simply-connected components without boundary (topological spheres) are left + // untouched (delete any edge if you really want a disk). + // All other connected components are cut into disks. Meshes with boundary are + // supported; boundary edges will be included as cuts. + // + // The cut mesh itself can be materialized using cut_mesh(). + // + // Implements the triangle-deletion approach described by Gu et al's + // "Geometry Images." + // + // Template Parameters: + // Index Integrable type large enough to represent the total number of faces + // and edges in the surface represented by F, and all entries of F. + // + // Inputs: + // F #F by 3 list of the faces (must be triangles) + // + // Outputs: + // cuts List of cuts. Each cut is a sequence of vertex indices (where + // pairs of consecutive vertices share a face), is simple, and is either + // a closed loop (in which the first and last indices are identical) or + // an open curve. Cuts are edge-disjoint. + // + + template < + typename DerivedF, + typename Index> + IGL_INLINE void cut_to_disk( + const Eigen::MatrixBase &F, + std::vector > &cuts); +}; + +#ifndef IGL_STATIC_LIBRARY +#include "cut_to_disk.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/cylinder.cpp b/vendor/libigl/include/igl/cylinder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ab0fd4d3df3fabd6d017492261cbf904fc40a2ba --- /dev/null +++ b/vendor/libigl/include/igl/cylinder.cpp @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "cylinder.h" +#include "PI.h" +#include +#include + +template +IGL_INLINE void igl::cylinder( + const int axis_devisions, + const int height_devisions, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F) +{ + V.resize(axis_devisions*height_devisions,3); + F.resize(2*(axis_devisions*(height_devisions-1)),3); + int f = 0; + typedef typename DerivedV::Scalar Scalar; + for(int th = 0;th 0) + { + F(f,0) = ((th+0)%axis_devisions)+(h-1)*axis_devisions; + F(f,1) = ((th+1)%axis_devisions)+(h-1)*axis_devisions; + F(f,2) = ((th+0)%axis_devisions)+(h+0)*axis_devisions; + f++; + F(f,0) = ((th+1)%axis_devisions)+(h-1)*axis_devisions; + F(f,1) = ((th+1)%axis_devisions)+(h+0)*axis_devisions; + F(f,2) = ((th+0)%axis_devisions)+(h+0)*axis_devisions; + f++; + } + } + } + assert(f == F.rows()); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::cylinder, Eigen::Matrix >(int, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/cylinder.h b/vendor/libigl/include/igl/cylinder.h new file mode 100644 index 0000000000000000000000000000000000000000..4c5ab7e2261991addf96315e340dafb5c370ee07 --- /dev/null +++ b/vendor/libigl/include/igl/cylinder.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_CYLINDER_H +#define IGL_CYLINDER_H +#include "igl_inline.h" +#include +namespace igl +{ + // Construct a triangle mesh of a cylinder (without caps) + // + // Inputs: + // axis_devisions number of vertices _around the cylinder_ + // height_devisions number of vertices _up the cylinder_ + // Outputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of triangle indices into V + // + template + IGL_INLINE void cylinder( + const int axis_devisions, + const int height_devisions, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F); +} +#ifndef IGL_STATIC_LIBRARY +# include "cylinder.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/dated_copy.cpp b/vendor/libigl/include/igl/dated_copy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..735de6fc4ceec06c8174f7a0f3b9866aaef6e79b --- /dev/null +++ b/vendor/libigl/include/igl/dated_copy.cpp @@ -0,0 +1,91 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "dated_copy.h" +#include "dirname.h" +#include "basename.h" + +#include +#include +#include +#include +#include + +#if !defined(_WIN32) +#include + +IGL_INLINE bool igl::dated_copy(const std::string & src_path, const std::string & dir) +{ + using namespace std; + // Get time and date as string + char buffer[80]; + time_t rawtime; + struct tm * timeinfo; + time (&rawtime); + timeinfo = localtime (&rawtime); + // ISO 8601 format with hyphens instead of colons and no timezone offset + strftime (buffer,80,"%Y-%m-%dT%H-%M-%S",timeinfo); + string src_basename = basename(src_path); + string dst_basename = src_basename+"-"+buffer; + string dst_path = dir+"/"+dst_basename; + cerr<<"Saving binary to "< +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +// Known issues: This function does not work under windows + +#ifndef IGL_DATED_COPY_H +#define IGL_DATED_COPY_H +#include "igl_inline.h" +#include +namespace igl +{ + // Copy the given file to a new file with the same basename in `dir` + // directory with the current date and time as a suffix. + // + // Inputs: + // src_path path to source file + // dir directory of destination file + // Example: + // dated_copy("/path/to/foo","/bar/"); + // // copies /path/to/foo to /bar/foo-2013-12-12T18-10-56 + IGL_INLINE bool dated_copy(const std::string & src_path, const std::string & dir); + // Wrapper using directory of source file + IGL_INLINE bool dated_copy(const std::string & src_path); +} +#ifndef IGL_STATIC_LIBRARY +# include "dated_copy.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/decimate.cpp b/vendor/libigl/include/igl/decimate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5c6cf7f6b8705c07c770a348798460b4dccd826 --- /dev/null +++ b/vendor/libigl/include/igl/decimate.cpp @@ -0,0 +1,251 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "decimate.h" +#include "collapse_edge.h" +#include "edge_flaps.h" +#include "decimate_trivial_callbacks.h" +#include "is_edge_manifold.h" +#include "remove_unreferenced.h" +#include "slice_mask.h" +#include "slice.h" +#include "connect_boundary_to_infinity.h" +#include "parallel_for.h" +#include "max_faces_stopping_condition.h" +#include "shortest_edge_and_midpoint.h" + +IGL_INLINE bool igl::decimate( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const size_t max_m, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J, + Eigen::VectorXi & I) +{ + // Original number of faces + const int orig_m = F.rows(); + // Tracking number of faces + int m = F.rows(); + typedef Eigen::MatrixXd DerivedV; + typedef Eigen::MatrixXi DerivedF; + DerivedV VO; + DerivedF FO; + igl::connect_boundary_to_infinity(V,F,VO,FO); + Eigen::VectorXi EMAP; + Eigen::MatrixXi E,EF,EI; + edge_flaps(FO,E,EMAP,EF,EI); + // decimate will not work correctly on non-edge-manifold meshes. By extension + // this includes meshes with non-manifold vertices on the boundary since these + // will create a non-manifold edge when connected to infinity. + { + Eigen::Array BF; + Eigen::Array BE; + if(!is_edge_manifold(FO,E.rows(),EMAP,BF,BE)) + { + return false; + } + } + decimate_pre_collapse_callback always_try; + decimate_post_collapse_callback never_care; + decimate_trivial_callbacks(always_try,never_care); + bool ret = decimate( + VO, + FO, + shortest_edge_and_midpoint, + max_faces_stopping_condition(m,orig_m,max_m), + always_try, + never_care, + E, + EMAP, + EF, + EI, + U, + G, + J, + I); + const Eigen::Array keep = (J.array() BF; + Eigen::Array BE; + if(!is_edge_manifold(F,E.rows(),EMAP,BF,BE)) + { + return false; + } + } + + igl::min_heap > Q; + // Could reserve with https://stackoverflow.com/a/29236236/148668 + Eigen::VectorXi EQ = Eigen::VectorXi::Zero(E.rows()); + // If an edge were collapsed, we'd collapse it to these points: + MatrixXd C(E.rows(),V.cols()); + // Pushing into a vector then using constructor was slower. Maybe using + // std::move + make_heap would squeeze out something? + + // Separating the cost/placement evaluation from the Q filling is a + // performance hit for serial but faster if we can parallelize the + // cost/placement. + { + Eigen::VectorXd costs(E.rows()); + igl::parallel_for(E.rows(),[&](const int e) + { + double cost = e; + RowVectorXd p(1,3); + cost_and_placement(e,V,F,E,EMAP,EF,EI,cost,p); + C.row(e) = p; + costs(e) = cost; + }, + 10000 + ); + for(int e = 0;e +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DECIMATE_H +#define IGL_DECIMATE_H +#include "igl_inline.h" +#include "decimate_callback_types.h" +#include +namespace igl +{ + // Assumes (V,F) is a manifold mesh (possibly with boundary) Collapses edges + // until desired number of faces is achieved. This uses default edge cost and + // merged vertex placement functions {edge length, edge midpoint}. + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3 list of face indices into V. + // max_m desired number of output faces + // Outputs: + // U #U by dim list of output vertex posistions (can be same ref as V) + // G #G by 3 list of output face indices into U (can be same ref as G) + // J #G list of indices into F of birth face + // I #U list of indices into V of birth vertices + // Returns true if m was reached (otherwise #G > m) + IGL_INLINE bool decimate( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const size_t max_m, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J, + Eigen::VectorXi & I); + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3 list of face indices into V. + // max_m desired number of output faces + // Outputs: + // U #U by dim list of output vertex posistions (can be same ref as V) + // G #G by 3 list of output face indices into U (can be same ref as G) + // J #G list of indices into F of birth face + // Returns true if m was reached (otherwise #G > m) + IGL_INLINE bool decimate( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const size_t max_m, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J); + // Assumes a **closed** manifold mesh. See igl::connect_boundary_to_infinity + // and igl::decimate in decimate.cpp + // is handling meshes with boundary by connecting all boundary edges with + // dummy facets to infinity **and** modifying the stopping criteria. + // + // Inputs: + // cost_and_placement function computing cost of collapsing an edge and 3d + // position where it should be placed: + // cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement); + // stopping_condition function returning whether to stop collapsing edges + // based on current state. Guaranteed to be called after _successfully_ + // collapsing edge e removing edges (e,e1,e2) and faces (f1,f2): + // bool should_stop = + // stopping_condition(V,F,E,EMAP,EF,EI,Q,Qit,C,e,e1,e2,f1,f2); + IGL_INLINE bool decimate( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const decimate_cost_and_placement_callback & cost_and_placement, + const decimate_stopping_condition_callback & stopping_condition, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J, + Eigen::VectorXi & I); + // Inputs: + // pre_collapse callback called with index of edge whose collapse is about + // to be attempted (see collapse_edge) + // post_collapse callback called with index of edge whose collapse was + // just attempted and a flag revealing whether this was successful (see + // collapse_edge) + IGL_INLINE bool decimate( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const decimate_cost_and_placement_callback & cost_and_placement, + const decimate_stopping_condition_callback & stopping_condition, + const decimate_pre_collapse_callback & pre_collapse, + const decimate_post_collapse_callback & post_collapse, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J, + Eigen::VectorXi & I); + // Inputs: + // EMAP #F*3 list of indices into E, mapping each directed edge to unique + // unique edge in E + // EF #E by 2 list of edge flaps, EF(e,0)=f means e=(i-->j) is the edge of + // F(f,:) opposite the vth corner, where EI(e,0)=v. Similarly EF(e,1) " + // e=(j->i) + // EI #E by 2 list of edge flap corners (see above). + IGL_INLINE bool decimate( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const decimate_cost_and_placement_callback & cost_and_placement, + const decimate_stopping_condition_callback & stopping_condition, + const decimate_pre_collapse_callback & pre_collapse, + const decimate_post_collapse_callback & post_collapse, + const Eigen::MatrixXi & E, + const Eigen::VectorXi & EMAP, + const Eigen::MatrixXi & EF, + const Eigen::MatrixXi & EI, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J, + Eigen::VectorXi & I); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "decimate.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/decimate_callback_types.h b/vendor/libigl/include/igl/decimate_callback_types.h new file mode 100644 index 0000000000000000000000000000000000000000..c622342a50ec0af4d719e14a3fea1e12aae8d7d6 --- /dev/null +++ b/vendor/libigl/include/igl/decimate_callback_types.h @@ -0,0 +1,76 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DECIMATE_CALLBACK_TYPES_H +#define IGL_DECIMATE_CALLBACK_TYPES_H +#include +#include "min_heap.h" +namespace igl +{ + // Function handles used to customize the `igl::decimate` command. + using decimate_cost_and_placement_callback = + std::function; + using decimate_stopping_condition_callback = + std::function > & ,/*Q*/ + const Eigen::VectorXi & ,/*EQ*/ + const Eigen::MatrixXd & ,/*C*/ + const int ,/*e*/ + const int ,/*e1*/ + const int ,/*e2*/ + const int ,/*f1*/ + const int /*f2*/ + )>; + using decimate_pre_collapse_callback = + std::function > & ,/*Q*/ + const Eigen::VectorXi & ,/*EQ*/ + const Eigen::MatrixXd & ,/*C*/ + const int /*e*/ + )>; + using decimate_post_collapse_callback = + std::function > & ,/*Q*/ + const Eigen::VectorXi & ,/*EQ*/ + const Eigen::MatrixXd & ,/*C*/ + const int ,/*e*/ + const int ,/*e1*/ + const int ,/*e2*/ + const int ,/*f1*/ + const int ,/*f2*/ + const bool /*collapsed*/ + )>; +} +#endif diff --git a/vendor/libigl/include/igl/decimate_trivial_callbacks.h b/vendor/libigl/include/igl/decimate_trivial_callbacks.h new file mode 100644 index 0000000000000000000000000000000000000000..ea16dd55515173b40fe00df96ffee681cb402ebe --- /dev/null +++ b/vendor/libigl/include/igl/decimate_trivial_callbacks.h @@ -0,0 +1,31 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DECIMATE_TRIVIAL_CALLBACKS_H +#define IGL_DECIMATE_TRIVIAL_CALLBACKS_H +#include "igl_inline.h" +#include "decimate_callback_types.h" +namespace igl +{ + // Function to build trivial pre and post collapse actions. + // + // Outputs: + // always_try function that always returns true (always attempt the next + // edge collapse) + // never_care fuction that is always a no-op (never have a post collapse + // response) + IGL_INLINE void decimate_trivial_callbacks( + decimate_pre_collapse_callback & always_try, + decimate_post_collapse_callback & never_care); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "decimate_trivial_callbacks.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/default_num_threads.cpp b/vendor/libigl/include/igl/default_num_threads.cpp new file mode 100644 index 0000000000000000000000000000000000000000..21bffa92a57ab82c2f782d3cb4c50e671be59b5b --- /dev/null +++ b/vendor/libigl/include/igl/default_num_threads.cpp @@ -0,0 +1,66 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2021 Jérémie Dumas +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "default_num_threads.h" + +#include +#include + +IGL_INLINE unsigned int igl::default_num_threads(unsigned int user_num_threads) { + // Thread-safe initialization using Meyers' singleton + class MySingleton { + public: + static MySingleton &instance(unsigned int force_num_threads) { + static MySingleton instance(force_num_threads); + return instance; + } + + unsigned int get_num_threads() const { return m_num_threads; } + + private: + static const char* getenv_nowarning(const char* env_var) + { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4996) +#endif + return std::getenv(env_var); +#ifdef _MSC_VER +#pragma warning(pop) +#endif + } + + MySingleton(unsigned int force_num_threads) { + // User-defined default + if (force_num_threads) { + m_num_threads = force_num_threads; + return; + } + // Set from env var + if (const char *env_str = getenv_nowarning("IGL_NUM_THREADS")) { + const int env_num_thread = atoi(env_str); + if (env_num_thread > 0) { + m_num_threads = static_cast(env_num_thread); + return; + } + } + // Guess from hardware + const unsigned int hw_num_threads = std::thread::hardware_concurrency(); + if (hw_num_threads) { + m_num_threads = hw_num_threads; + return; + } + // Fallback when std::thread::hardware_concurrency doesn't work + m_num_threads = 8u; + } + + unsigned int m_num_threads = 0; + }; + + return MySingleton::instance(user_num_threads).get_num_threads(); +} diff --git a/vendor/libigl/include/igl/delaunay_triangulation.cpp b/vendor/libigl/include/igl/delaunay_triangulation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d09cc6425c22909887c487bfc460a1b48ed4fcc --- /dev/null +++ b/vendor/libigl/include/igl/delaunay_triangulation.cpp @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Qingnan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "delaunay_triangulation.h" +#include "flip_edge.h" +#include "lexicographic_triangulation.h" +#include "unique_edge_map.h" +#include "is_delaunay.h" + +#include +#include + +template< + typename DerivedV, + typename Orient2D, + typename InCircle, + typename DerivedF> +IGL_INLINE void igl::delaunay_triangulation( + const Eigen::MatrixBase& V, + Orient2D orient2D, + InCircle incircle, + Eigen::PlainObjectBase& F) +{ + assert(V.cols() == 2); + typedef typename DerivedF::Scalar Index; + typedef typename DerivedV::Scalar Scalar; + igl::lexicographic_triangulation(V, orient2D, F); + const size_t num_faces = F.rows(); + if (num_faces == 0) { + // Input points are degenerate. No faces will be generated. + return; + } + assert(F.cols() == 3); + + typedef Eigen::Matrix MatrixX2I; + MatrixX2I E,uE; + Eigen::VectorXi EMAP; + std::vector > uE2E; + igl::unique_edge_map(F, E, uE, EMAP, uE2E); + + bool all_delaunay = false; + while(!all_delaunay) { + all_delaunay = true; + for (size_t i=0; i, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::Matrix >(Eigen::MatrixBase > const&, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/delaunay_triangulation.h b/vendor/libigl/include/igl/delaunay_triangulation.h new file mode 100644 index 0000000000000000000000000000000000000000..ed3938a6e1e2d7d7910d315bb102f230a0002bbd --- /dev/null +++ b/vendor/libigl/include/igl/delaunay_triangulation.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Qingan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_DELAUNAY_TRIANGULATION_H +#define IGL_DELAUNAY_TRIANGULATION_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // Given a set of points in 2D, return a Delaunay triangulation of these + // points. + // + // Inputs: + // V #V by 2 list of vertex positions + // orient2D A functor such that orient2D(pa, pb, pc) returns + // 1 if pa,pb,pc forms a conterclockwise triangle. + // -1 if pa,pb,pc forms a clockwise triangle. + // 0 if pa,pb,pc are collinear. + // where the argument pa,pb,pc are of type Scalar[2]. + // incircle A functor such that incircle(pa, pb, pc, pd) returns + // 1 if pd is on the positive size of circumcirle of (pa,pb,pc) + // -1 if pd is on the positive size of circumcirle of (pa,pb,pc) + // 0 if pd is cocircular with pa, pb, pc. + // Outputs: + // F #F by 3 of faces in Delaunay triangulation. + template< + typename DerivedV, + typename Orient2D, + typename InCircle, + typename DerivedF + > + IGL_INLINE void delaunay_triangulation( + const Eigen::MatrixBase& V, + Orient2D orient2D, + InCircle incircle, + Eigen::PlainObjectBase& F); +} + +#ifndef IGL_STATIC_LIBRARY +# include "delaunay_triangulation.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/dfs.cpp b/vendor/libigl/include/igl/dfs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..627fbc26df7c5b945ac78e510ba30859f2791d27 --- /dev/null +++ b/vendor/libigl/include/igl/dfs.cpp @@ -0,0 +1,60 @@ +#include "dfs.h" +#include "list_to_matrix.h" +#include + +template < + typename AType, + typename DerivedD, + typename DerivedP, + typename DerivedC> +IGL_INLINE void igl::dfs( + const std::vector > & A, + const size_t s, + Eigen::PlainObjectBase & D, + Eigen::PlainObjectBase & P, + Eigen::PlainObjectBase & C) +{ + std::vector vD; + std::vector vP; + std::vector vC; + dfs(A,s,vD,vP,vC); + list_to_matrix(vD,D); + list_to_matrix(vP,P); + list_to_matrix(vC,C); +} + +template < + typename AType, + typename DType, + typename PType, + typename CType> +IGL_INLINE void igl::dfs( + const std::vector > & A, + const size_t s, + std::vector & D, + std::vector & P, + std::vector & C) +{ + // number of nodes + int N = s+1; + for(const auto & Ai : A) for(const auto & a : Ai) N = std::max(N,a+1); + std::vector seen(N,false); + P.resize(N,-1); + std::function dfs_helper; + dfs_helper = [&D,&P,&C,&dfs_helper,&seen,&A](const size_t s, const size_t p) + { + if(seen[s]) return; + seen[s] = true; + D.push_back(s); + P[s] = p; + for(const auto n : A[s]) dfs_helper(n,s); + C.push_back(s); + }; + dfs_helper(s,-1); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::dfs, Eigen::Matrix, Eigen::Matrix >(std::vector >, std::allocator > > > const&, const size_t, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/dfs.h b/vendor/libigl/include/igl/dfs.h new file mode 100644 index 0000000000000000000000000000000000000000..5f3bf2ce6334fba282aa325233e314e2c8491a56 --- /dev/null +++ b/vendor/libigl/include/igl/dfs.h @@ -0,0 +1,49 @@ +#ifndef IGL_DFS_H +#define IGL_DFS_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Traverse a **directed** graph represented by an adjacency list using + // depth first search + // + // Inputs: + // A #V list of adjacency lists + // s starting node (index into A) + // Outputs: + // D #V list of indices into rows of A in the order in which graph nodes + // are discovered. + // P #V list of indices into rows of A of predecessor in resulting + // spanning tree {-1 indicates root/not discovered), order corresponds to + // V **not** D. + // C #V list of indices into rows of A in order that nodes are "closed" + // (all descendants have been discovered) + template < + typename AType, + typename DerivedD, + typename DerivedP, + typename DerivedC> + IGL_INLINE void dfs( + const std::vector > & A, + const size_t s, + Eigen::PlainObjectBase & D, + Eigen::PlainObjectBase & P, + Eigen::PlainObjectBase & C); + template < + typename AType, + typename DType, + typename PType, + typename CType> + IGL_INLINE void dfs( + const std::vector > & A, + const size_t s, + std::vector & D, + std::vector & P, + std::vector & C); + +} +#ifndef IGL_STATIC_LIBRARY +# include "dfs.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/diag.cpp b/vendor/libigl/include/igl/diag.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d29382695e0f07af8521e030ade1068316d44226 --- /dev/null +++ b/vendor/libigl/include/igl/diag.cpp @@ -0,0 +1,108 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "diag.h" + +#include "verbose.h" + +// Bug in unsupported/Eigen/SparseExtra needs iostream first +#include +#include + +template +IGL_INLINE void igl::diag( + const Eigen::SparseMatrix& X, + Eigen::SparseVector& V) +{ + assert(false && "Just call X.diagonal().sparseView() directly"); + V = X.diagonal().sparseView(); + //// Get size of input + //int m = X.rows(); + //int n = X.cols(); + //V = Eigen::SparseVector((m>n?n:m)); + //V.reserve(V.size()); + + //// Iterate over outside + //for(int k=0; k::InnerIterator it (X,k); it; ++it) + // { + // if(it.col() == it.row()) + // { + // V.coeffRef(it.col()) += it.value(); + // } + // } + //} +} + +template +IGL_INLINE void igl::diag( + const Eigen::SparseMatrix& X, + Eigen::MatrixBase & V) +{ + assert(false && "Just call X.diagonal() directly"); + V = X.diagonal(); + //// Get size of input + //int m = X.rows(); + //int n = X.cols(); + //V.derived().resize((m>n?n:m),1); + + //// Iterate over outside + //for(int k=0; k::InnerIterator it (X,k); it; ++it) + // { + // if(it.col() == it.row()) + // { + // V(it.col()) = it.value(); + // } + // } + //} +} + +template +IGL_INLINE void igl::diag( + const Eigen::SparseVector& V, + Eigen::SparseMatrix& X) +{ + // clear and resize output + Eigen::DynamicSparseMatrix dyn_X(V.size(),V.size()); + dyn_X.reserve(V.size()); + // loop over non-zeros + for(typename Eigen::SparseVector::InnerIterator it(V); it; ++it) + { + dyn_X.coeffRef(it.index(),it.index()) += it.value(); + } + X = Eigen::SparseMatrix(dyn_X); +} + +template +IGL_INLINE void igl::diag( + const Eigen::MatrixBase & V, + Eigen::SparseMatrix& X) +{ + assert(V.rows() == 1 || V.cols() == 1); + // clear and resize output + Eigen::DynamicSparseMatrix dyn_X(V.size(),V.size()); + dyn_X.reserve(V.size()); + // loop over non-zeros + for(int i = 0;i(dyn_X); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::diag >(Eigen::SparseMatrix const&, Eigen::MatrixBase >&); +template void igl::diag(Eigen::SparseMatrix const&, Eigen::SparseVector&); +template void igl::diag >(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::diag(Eigen::SparseVector const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/dihedral_angles.cpp b/vendor/libigl/include/igl/dihedral_angles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68427fdc0a7128f685aa4069cec6c8b8b3e43f0b --- /dev/null +++ b/vendor/libigl/include/igl/dihedral_angles.cpp @@ -0,0 +1,98 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "dihedral_angles.h" +#include "edge_lengths.h" +#include "face_areas.h" + +#include + +template < + typename DerivedV, + typename DerivedT, + typename Derivedtheta, + typename Derivedcos_theta> +IGL_INLINE void igl::dihedral_angles( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& theta, + Eigen::PlainObjectBase& cos_theta) +{ + using namespace Eigen; + assert(T.cols() == 4); + Matrix l; + edge_lengths(V,T,l); + Matrix s; + face_areas(l,s); + return dihedral_angles_intrinsic(l,s,theta,cos_theta); +} + +template < + typename DerivedL, + typename DerivedA, + typename Derivedtheta, + typename Derivedcos_theta> +IGL_INLINE void igl::dihedral_angles_intrinsic( + const Eigen::MatrixBase& L, + const Eigen::MatrixBase& A, + Eigen::PlainObjectBase& theta, + Eigen::PlainObjectBase& cos_theta) +{ + using namespace Eigen; + const int m = L.rows(); + assert(m == A.rows()); + // Law of cosines + // http://math.stackexchange.com/a/49340/35376 + Matrix H_sqr(m,6); + H_sqr.col(0) = (1./16.) * (4. * L.col(3).array().square() * L.col(0).array().square() - + ((L.col(1).array().square() + L.col(4).array().square()) - + (L.col(2).array().square() + L.col(5).array().square())).square()); + H_sqr.col(1) = (1./16.) * (4. * L.col(4).array().square() * L.col(1).array().square() - + ((L.col(2).array().square() + L.col(5).array().square()) - + (L.col(3).array().square() + L.col(0).array().square())).square()); + H_sqr.col(2) = (1./16.) * (4. * L.col(5).array().square() * L.col(2).array().square() - + ((L.col(3).array().square() + L.col(0).array().square()) - + (L.col(4).array().square() + L.col(1).array().square())).square()); + H_sqr.col(3) = (1./16.) * (4. * L.col(0).array().square() * L.col(3).array().square() - + ((L.col(4).array().square() + L.col(1).array().square()) - + (L.col(5).array().square() + L.col(2).array().square())).square()); + H_sqr.col(4) = (1./16.) * (4. * L.col(1).array().square() * L.col(4).array().square() - + ((L.col(5).array().square() + L.col(2).array().square()) - + (L.col(0).array().square() + L.col(3).array().square())).square()); + H_sqr.col(5) = (1./16.) * (4. * L.col(2).array().square() * L.col(5).array().square() - + ((L.col(0).array().square() + L.col(3).array().square()) - + (L.col(1).array().square() + L.col(4).array().square())).square()); + cos_theta.resize(m,6); + cos_theta.col(0) = (H_sqr.col(0).array() - + A.col(1).array().square() - A.col(2).array().square()).array() / + (-2.*A.col(1).array() * A.col(2).array()); + cos_theta.col(1) = (H_sqr.col(1).array() - + A.col(2).array().square() - A.col(0).array().square()).array() / + (-2.*A.col(2).array() * A.col(0).array()); + cos_theta.col(2) = (H_sqr.col(2).array() - + A.col(0).array().square() - A.col(1).array().square()).array() / + (-2.*A.col(0).array() * A.col(1).array()); + cos_theta.col(3) = (H_sqr.col(3).array() - + A.col(3).array().square() - A.col(0).array().square()).array() / + (-2.*A.col(3).array() * A.col(0).array()); + cos_theta.col(4) = (H_sqr.col(4).array() - + A.col(3).array().square() - A.col(1).array().square()).array() / + (-2.*A.col(3).array() * A.col(1).array()); + cos_theta.col(5) = (H_sqr.col(5).array() - + A.col(3).array().square() - A.col(2).array().square()).array() / + (-2.*A.col(3).array() * A.col(2).array()); + + theta = cos_theta.array().acos(); + + cos_theta.resize(m,6); + +} +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::dihedral_angles_intrinsic< Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(const Eigen::MatrixBase >&, const Eigen::MatrixBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::dihedral_angles, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/dihedral_angles.h b/vendor/libigl/include/igl/dihedral_angles.h new file mode 100644 index 0000000000000000000000000000000000000000..c4fc3bc190a65311ed93b82f48c84942bc99c81c --- /dev/null +++ b/vendor/libigl/include/igl/dihedral_angles.h @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DIHEDRAL_ANGLES_H +#define IGL_DIHEDRAL_ANGLES_H +#include "igl_inline.h" +#include +namespace igl +{ + // DIHEDRAL_ANGLES Compute dihedral angles for all tets of a given tet mesh + // (V,T) + // + // theta = dihedral_angles(V,T) + // theta = dihedral_angles(V,T,'ParameterName',parameter_value,...) + // + // Inputs: + // V #V by dim list of vertex positions + // T #V by 4 list of tet indices + // Outputs: + // theta #T by 6 list of dihedral angles (in radians) + // cos_theta #T by 6 list of cosine of dihedral angles (in radians) + // + template < + typename DerivedV, + typename DerivedT, + typename Derivedtheta, + typename Derivedcos_theta> + IGL_INLINE void dihedral_angles( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& theta, + Eigen::PlainObjectBase& cos_theta); + template < + typename DerivedL, + typename DerivedA, + typename Derivedtheta, + typename Derivedcos_theta> + IGL_INLINE void dihedral_angles_intrinsic( + const Eigen::MatrixBase& L, + const Eigen::MatrixBase& A, + Eigen::PlainObjectBase& theta, + Eigen::PlainObjectBase& cos_theta); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "dihedral_angles.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/dijkstra.cpp b/vendor/libigl/include/igl/dijkstra.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ef4e2f630bc1fc5e7c79d1eaeacce87f826e8da --- /dev/null +++ b/vendor/libigl/include/igl/dijkstra.cpp @@ -0,0 +1,138 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "dijkstra.h" + +template +IGL_INLINE int igl::dijkstra( + const IndexType &source, + const std::set &targets, + const std::vector >& VV, + const std::vector& weights, + Eigen::PlainObjectBase &min_distance, + Eigen::PlainObjectBase &previous) +{ + int numV = VV.size(); + min_distance.setConstant(numV, 1, std::numeric_limits::max()); + min_distance[source] = 0; + previous.setConstant(numV, 1, -1); + std::set > vertex_queue; + vertex_queue.insert(std::make_pair(min_distance[source], source)); + + while (!vertex_queue.empty()) + { + typename DerivedD::Scalar dist = vertex_queue.begin()->first; + IndexType u = vertex_queue.begin()->second; + vertex_queue.erase(vertex_queue.begin()); + + if (targets.find(u)!= targets.end()) + return u; + + // Visit each edge exiting u + const std::vector &neighbors = VV[u]; + for (std::vector::const_iterator neighbor_iter = neighbors.begin(); + neighbor_iter != neighbors.end(); + neighbor_iter++) + { + IndexType v = *neighbor_iter; + typename DerivedD::Scalar distance_through_u = dist + weights[u]; + if (distance_through_u < min_distance[v]) { + vertex_queue.erase(std::make_pair(min_distance[v], v)); + + min_distance[v] = distance_through_u; + previous[v] = u; + vertex_queue.insert(std::make_pair(min_distance[v], v)); + + } + + } + } + //we should never get here + return -1; +} + +template +IGL_INLINE int igl::dijkstra( + const IndexType &source, + const std::set &targets, + const std::vector >& VV, + Eigen::PlainObjectBase &min_distance, + Eigen::PlainObjectBase &previous) +{ + std::vector weights(VV.size(), 1.0); + return dijkstra(source, targets, VV, weights, min_distance, previous); +} + +template +IGL_INLINE void igl::dijkstra( + const IndexType &vertex, + const Eigen::MatrixBase &previous, + std::vector &path) +{ + IndexType source = vertex; + path.clear(); + for ( ; source != -1; source = previous[source]) + path.push_back(source); +} + + +template +IGL_INLINE int igl::dijkstra( + const Eigen::MatrixBase &V, + const std::vector >& VV, + const IndexType &source, + const std::set &targets, + Eigen::PlainObjectBase &min_distance, + Eigen::PlainObjectBase &previous) +{ + int numV = VV.size(); + + min_distance.setConstant(numV, 1, std::numeric_limits::infinity()); + min_distance[source] = 0; + previous.setConstant(numV, 1, -1); + std::set > vertex_queue; + vertex_queue.insert(std::make_pair(min_distance[source], source)); + + while (!vertex_queue.empty()) + { + typename DerivedD::Scalar dist = vertex_queue.begin()->first; + IndexType u = vertex_queue.begin()->second; + vertex_queue.erase(vertex_queue.begin()); + + if (targets.find(u)!= targets.end()) + return u; + + // Visit each edge exiting u + const std::vector &neighbors = VV[u]; + for (std::vector::const_iterator neighbor_iter = neighbors.begin(); + neighbor_iter != neighbors.end(); + neighbor_iter++) + { + IndexType v = *neighbor_iter; + typename DerivedD::Scalar distance_through_u = dist + (V.row(u) - V.row(v)).norm(); + if (distance_through_u < min_distance[v]) { + vertex_queue.erase(std::make_pair(min_distance[v], v)); + + min_distance[v] = distance_through_u; + previous[v] = u; + vertex_queue.insert(std::make_pair(min_distance[v], v)); + + } + + } + } + return -1; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template int igl::dijkstra, Eigen::Matrix >(int const&, std::set, std::allocator > const&, std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template int igl::dijkstra, Eigen::Matrix >(int const&, std::set, std::allocator > const&, std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::dijkstra >(int const&, Eigen::MatrixBase > const&, std::vector >&); +template int igl::dijkstra, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, int const&, std::set, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/dijkstra.h b/vendor/libigl/include/igl/dijkstra.h new file mode 100644 index 0000000000000000000000000000000000000000..f2fd0c0e16d10f7ec2150efe30bef88b3ca252e9 --- /dev/null +++ b/vendor/libigl/include/igl/dijkstra.h @@ -0,0 +1,109 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_DIJKSTRA +#define IGL_DIJKSTRA +#include "igl_inline.h" + +#include +#include +#include + +namespace igl { + + // Dijkstra's algorithm for vertex-weighted shortest paths, with multiple targets. + // Adapted from http://rosettacode.org/wiki/Dijkstra%27s_algorithm . + // + // Inputs: + // source index of source vertex + // targets target vector set + // VV #V list of lists of incident vertices (adjacency list), e.g. + // as returned by igl::adjacency_list + // weights #V list of scalar vertex weights + // + // Output: + // min_distance #V by 1 list of the minimum distances from source to all vertices + // previous #V by 1 list of the previous visited vertices (for each vertex) - used for backtracking + // + template + IGL_INLINE int dijkstra( + const IndexType &source, + const std::set &targets, + const std::vector >& VV, + const std::vector& weights, + Eigen::PlainObjectBase &min_distance, + Eigen::PlainObjectBase &previous); + + // Dijkstra's algorithm for shortest paths, with multiple targets. + // Adapted from http://rosettacode.org/wiki/Dijkstra%27s_algorithm . + // + // Inputs: + // source index of source vertex + // targets target vector set + // VV #V list of lists of incident vertices (adjacency list), e.g. + // as returned by igl::adjacency_list + // + // Output: + // min_distance #V by 1 list of the minimum distances from source to all vertices + // previous #V by 1 list of the previous visited vertices (for each vertex) - used for backtracking + // + template + IGL_INLINE int dijkstra( + const IndexType &source, + const std::set &targets, + const std::vector >& VV, + Eigen::PlainObjectBase &min_distance, + Eigen::PlainObjectBase &previous); + + // Backtracking after Dijkstra's algorithm, to find shortest path. + // + // Inputs: + // vertex vertex to which we want the shortest path (from same source as above) + // previous #V by 1 list of the previous visited vertices (for each vertex) - result of Dijkstra's algorithm + // + // Output: + // path #P by 1 list of vertex indices in the shortest path from vertex to source + // + template + IGL_INLINE void dijkstra( + const IndexType &vertex, + const Eigen::MatrixBase &previous, + std::vector &path); + + + // Dijkstra's algorithm for shortest paths on a mesh, with multiple targets, using edge length + // + // Inputs: + // V #V by 3 list of vertex positions + // VV #V list of lists of incident vertices (adjacency list), e.g. + // as returned by igl::adjacency_list, will be generated if empty. + // source index of source vertex + // targets target vector set + // + // Output: + // min_distance #V by 1 list of the minimum distances from source to all vertices + // previous #V by 1 list of the previous visited vertices (for each vertex) - used for backtracking + // + template + IGL_INLINE int dijkstra( + const Eigen::MatrixBase &V, + const std::vector >& VV, + const IndexType &source, + const std::set &targets, + Eigen::PlainObjectBase &min_distance, + Eigen::PlainObjectBase &previous); + +} + +#ifndef IGL_STATIC_LIBRARY +#include "dijkstra.cpp" +#endif + + +#endif /* defined(IGL_DIJKSTRA) */ diff --git a/vendor/libigl/include/igl/direct_delta_mush.cpp b/vendor/libigl/include/igl/direct_delta_mush.cpp new file mode 100644 index 0000000000000000000000000000000000000000..206927a03cade8da2507f3ebb311801b0885f86b --- /dev/null +++ b/vendor/libigl/include/igl/direct_delta_mush.cpp @@ -0,0 +1,268 @@ +// This file is part of libigl, a simple C++ geometry processing library. +// +// Copyright (C) 2020 Xiangyu Kong +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "direct_delta_mush.h" +#include "cotmatrix.h" + +template < + typename DerivedV, + typename DerivedOmega, + typename DerivedU> +IGL_INLINE void igl::direct_delta_mush( + const Eigen::MatrixBase & V, + const std::vector > & T, + const Eigen::MatrixBase & Omega, + Eigen::PlainObjectBase & U) +{ + using namespace Eigen; + + // Shape checks + assert(V.cols() == 3 && "V should contain 3D positions."); + assert(Omega.rows() == V.rows() && "Omega contain the same number of rows as V."); + assert(Omega.cols() == T.size() * 10 && "Omega should have #T*10 columns."); + + typedef typename DerivedV::Scalar Scalar; + + int n = V.rows(); + int m = T.size(); + + // V_homogeneous: #V by 4, homogeneous version of V + // Note: + // In the paper, the rest pose vertices are represented in U \in R^{4 x #V} + // Thus the formulae involving U would differ from the paper by a transpose. + Matrix V_homogeneous(n, 4); + V_homogeneous << V, Matrix::Ones(n, 1); + U.resize(n, 3); + + for (int i = 0; i < n; ++i) + { + // Construct Q matrix using Omega and Transformations + Matrix Q_mat(4, 4); + Q_mat = Matrix::Zero(4, 4); + for (int j = 0; j < m; ++j) + { + Matrix Omega_curr(4, 4); + Matrix curr = Omega.block(i, j * 10, 1, 10).transpose(); + Omega_curr << curr(0), curr(1), curr(2), curr(3), + curr(1), curr(4), curr(5), curr(6), + curr(2), curr(5), curr(7), curr(8), + curr(3), curr(6), curr(8), curr(9); + + Affine3d M_curr = T[j]; + Q_mat += M_curr.matrix() * Omega_curr; + } + // Normalize so that the last element is 1 + Q_mat /= Q_mat(Q_mat.rows() - 1, Q_mat.cols() - 1); + + Matrix Q_i = Q_mat.block(0, 0, 3, 3); + Matrix q_i = Q_mat.block(0, 3, 3, 1); + Matrix p_i = Q_mat.block(3, 0, 1, 3).transpose(); + + // Get rotation and translation matrices using SVD + Matrix SVD_i = Q_i - q_i * p_i.transpose(); + JacobiSVD> svd; + svd.compute(SVD_i, ComputeFullU | ComputeFullV); + Matrix R_i = svd.matrixU() * svd.matrixV().transpose(); + Matrix t_i = q_i - R_i * p_i; + + // Gamma final transformation matrix + Matrix Gamma_i(3, 4); + Gamma_i.block(0, 0, 3, 3) = R_i; + Gamma_i.block(0, 3, 3, 1) = t_i; + + // Final deformed position + Matrix v_i = V_homogeneous.row(i); + U.row(i) = Gamma_i * v_i; + } +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedW, + typename DerivedOmega> +IGL_INLINE void igl::direct_delta_mush_precomputation( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & W, + const int p, + const typename DerivedV::Scalar lambda, + const typename DerivedV::Scalar kappa, + const typename DerivedV::Scalar alpha, + Eigen::PlainObjectBase & Omega) +{ + using namespace Eigen; + + // Shape checks + assert(V.cols() == 3 && "V should contain 3D positions."); + assert(F.cols() == 3 && "F should contain triangles."); + assert(W.rows() == V.rows() && "W.rows() should be equal to V.rows()."); + + // Parameter checks + assert(p > 0 && "Laplacian iteration p should be positive."); + assert(lambda > 0 && "lambda should be positive."); + assert(kappa > 0 && kappa < lambda && "kappa should be positive and less than lambda."); + assert(alpha >= 0 && alpha < 1 && "alpha should be non-negative and less than 1."); + + typedef typename DerivedV::Scalar Scalar; + + // lambda helper + // Given a square matrix, extract the upper triangle (including diagonal) to an array. + // E.g. 1 2 3 4 + // 5 6 7 8 -> [1, 2, 3, 4, 6, 7, 8, 11, 12, 16] + // 9 10 11 12 0 1 2 3 4 5 6 7 8 9 + // 13 14 15 16 + auto extract_upper_triangle = []( + const Matrix & full) -> Matrix + { + int dims = full.rows(); + Matrix upper_triangle((dims * (dims + 1)) / 2); + int vector_idx = 0; + for (int i = 0; i < dims; ++i) + { + for (int j = i; j < dims; ++j) + { + upper_triangle(vector_idx) = full(i, j); + vector_idx++; + } + } + return upper_triangle; + }; + + const int n = V.rows(); + const int m = W.cols(); + + // V_homogeneous: #V by 4, homogeneous version of V + // Note: + // in the paper, the rest pose vertices are represented in U \in R^{4 \times #V} + // Thus the formulae involving U would differ from the paper by a transpose. + Matrix V_homogeneous(n, 4); + V_homogeneous << V, Matrix::Ones(n); + + // Identity matrix of #V by #V + SparseMatrix I(n, n); + I.setIdentity(); + + // Laplacian matrix of #V by #V + // L_bar = L \times D_L^{-1} + SparseMatrix L; + igl::cotmatrix(V, F, L); + L = -L; + // Inverse of diagonal matrix = reciprocal elements in diagonal + Matrix D_L = L.diagonal(); + // D_L = D_L.array().pow(-1); // Not using this since not sure if diagonal contains 0 + for (int i = 0; i < D_L.size(); ++i) + { + if (D_L(i) != 0) + { + D_L(i) = 1 / D_L(i); + } + } + SparseMatrix D_L_inv = D_L.asDiagonal().toDenseMatrix().sparseView(); + SparseMatrix L_bar = L * D_L_inv; + + // Implicitly and iteratively solve for W' + // w'_{ij} = \sum_{k=1}^{n}{C_{ki} w_{kj}} where C = (I + kappa L_bar)^{-p}: + // W' = C^T \times W => c^T W_k = W_{k-1} where c = (I + kappa L_bar) + // C positive semi-definite => ldlt solver + SimplicialLDLT> ldlt_W_prime; + SparseMatrix c(I + kappa * L_bar); + // working copy + DerivedW W_prime(W); + ldlt_W_prime.compute(c.transpose()); + for (int iter = 0; iter < p; ++iter) + { + W_prime = ldlt_W_prime.solve(W_prime); + } + + // U_precomputed: #V by 10 + // Cache u_i^T \dot u_i \in R^{4 x 4} to reduce computation time. + Matrix U_precomputed(n, 10); + for (int k = 0; k < n; ++k) + { + Matrix u_full = V_homogeneous.row(k).transpose() * V_homogeneous.row(k); + U_precomputed.row(k) = extract_upper_triangle(u_full); + } + + // U_prime: #V by #T*10 of u_{jx} + // Each column of U_prime (u_{jx}) is the element-wise product of + // W_j and U_precomputed_x where j \in {1...m}, x \in {1...10} + Matrix U_prime(n, m * 10); + for (int j = 0; j < m; ++j) + { + Matrix w_j = W.col(j); + for (int x = 0; x < 10; ++x) + { + Matrix u_x = U_precomputed.col(x); + U_prime.col(10 * j + x) = w_j.array() * u_x.array(); + } + } + + // Implicitly and iteratively solve for Psi: #V by #T*10 of \Psi_{ij}s. + // Note: Using dense matrices to solve for Psi will cause the program to hang. + // The following won't work + // Matrix Psi(U_prime); + // Matrix b((I + lambda * L_bar).transpose()); + // for (int iter = 0; iter < p; ++iter) + // { + // Psi = b.ldlt().solve(Psi); // hangs here + // } + // Convert to sparse matrices and compute + Matrix Psi = U_prime.sparseView(); + SparseMatrix b = (I + lambda * L_bar).transpose(); + SimplicialLDLT> ldlt_Psi; + ldlt_Psi.compute(b); + for (int iter = 0; iter < p; ++iter) + { + Psi = ldlt_Psi.solve(Psi); + } + + // P: #V by 10 precomputed upper triangle of + // p_i p_i^T , p_i + // p_i^T , 1 + // where p_i = (\sum_{j=1}^{n} Psi_{ij})'s top right 3 by 1 column + Matrix P(n, 10); + for (int i = 0; i < n; ++i) + { + Matrix p_i = Matrix::Zero(3); + Scalar last = 0; + for (int j = 0; j < m; ++j) + { + Matrix p_i_curr(3); + p_i_curr << Psi(i, j * 10 + 3), Psi(i, j * 10 + 6), Psi(i, j * 10 + 8); + p_i += p_i_curr; + last += Psi(i, j * 10 + 9); + } + p_i /= last; // normalize + Matrix p_matrix(4, 4); + p_matrix.block(0, 0, 3, 3) = p_i * p_i.transpose(); + p_matrix.block(0, 3, 3, 1) = p_i; + p_matrix.block(3, 0, 1, 3) = p_i.transpose(); + p_matrix(3, 3) = 1; + P.row(i) = extract_upper_triangle(p_matrix); + } + + // Omega + Omega.resize(n, m * 10); + for (int i = 0; i < n; ++i) + { + Matrix p_vector = P.row(i); + for (int j = 0; j < m; ++j) + { + Matrix Omega_curr(10); + Matrix Psi_curr = Psi.block(i, j * 10, 1, 10).transpose(); + Omega_curr = (1. - alpha) * Psi_curr + alpha * W_prime(i, j) * p_vector; + Omega.block(i, j * 10, 1, 10) = Omega_curr.transpose(); + } + } +} + +#ifdef IGL_STATIC_LIBRARY + +// Explicit template instantiation +template void igl::direct_delta_mush, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, std::vector, Eigen::aligned_allocator > > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); template void igl::direct_delta_mush_precomputation, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/directed_edge_orientations.h b/vendor/libigl/include/igl/directed_edge_orientations.h new file mode 100644 index 0000000000000000000000000000000000000000..9a8ce05bde8f05c1c97a720e34c92563e51dfed8 --- /dev/null +++ b/vendor/libigl/include/igl/directed_edge_orientations.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DIRECTED_EDGE_ORIENTATIONS_H +#define IGL_DIRECTED_EDGE_ORIENTATIONS_H +#include "igl_inline.h" + +#include +#include +#include +#include + +namespace igl +{ + // Determine rotations that take each edge from the x-axis to its given rest + // orientation. + // + // Inputs: + // C #C by 3 list of edge vertex positions + // E #E by 2 list of directed edges + // Outputs: + // Q #E list of quaternions + // + template + IGL_INLINE void directed_edge_orientations( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & E, + std::vector< + Eigen::Quaterniond,Eigen::aligned_allocator > & Q); +} + +#ifndef IGL_STATIC_LIBRARY +# include "directed_edge_orientations.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/directed_edge_parents.cpp b/vendor/libigl/include/igl/directed_edge_parents.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b8180023c42a8a9022205305e79f7bae5cb64d50 --- /dev/null +++ b/vendor/libigl/include/igl/directed_edge_parents.cpp @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "directed_edge_parents.h" +#include "slice_into.h" +#include "slice.h" +#include "colon.h" +#include "setdiff.h" +#include + +template +IGL_INLINE void igl::directed_edge_parents( + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & P) +{ + using namespace Eigen; + using namespace std; + typedef Eigen::Matrix VectorT; + + VectorT I = VectorT::Constant(E.maxCoeff()+1,1,-1); + //I(E.col(1)) = 0:E.rows()-1 + slice_into(colon(0, E.rows()-1), E.col(1).eval(), I); + VectorT roots,_; + setdiff(E.col(0).eval(),E.col(1).eval(),roots,_); + std::for_each(roots.data(),roots.data()+roots.size(),[&](typename VectorT::Scalar r){I(r)=-1;}); + slice(I,E.col(0).eval(),P); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::directed_edge_parents, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/directed_edge_parents.h b/vendor/libigl/include/igl/directed_edge_parents.h new file mode 100644 index 0000000000000000000000000000000000000000..5edc9dc32a4a348f11768f4b0a3eb45a91148deb --- /dev/null +++ b/vendor/libigl/include/igl/directed_edge_parents.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DIRECTED_EDGE_PARENTS_H +#define IGL_DIRECTED_EDGE_PARENTS_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Recover "parents" (preceding edges) in a tree given just directed edges. + // + // Inputs: + // E #E by 2 list of directed edges + // Outputs: + // P #E list of parent indices into E (-1) means root + // + template + IGL_INLINE void directed_edge_parents( + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "directed_edge_parents.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/dirname.cpp b/vendor/libigl/include/igl/dirname.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dad96526a25f201b680a97e69a4a6d55dce4905f --- /dev/null +++ b/vendor/libigl/include/igl/dirname.cpp @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "dirname.h" + +#include +#include "verbose.h" + +IGL_INLINE std::string igl::dirname(const std::string & path) +{ + if(path == "") + { + return std::string(""); + } + // https://stackoverflow.com/a/3071694/148668 + size_t found = path.find_last_of("/\\"); + if(found == std::string::npos) + { + // No slashes found + return std::string("."); + }else if(found == 0) + { + // Slash is first char + return std::string(path.begin(),path.begin()+1); + }else if(found == path.length()-1) + { + // Slash is last char + std::string redo = std::string(path.begin(),path.end()-1); + return igl::dirname(redo); + } + // Return everything up to but not including last slash + return std::string(path.begin(),path.begin()+found); +} + + diff --git a/vendor/libigl/include/igl/dirname.h b/vendor/libigl/include/igl/dirname.h new file mode 100644 index 0000000000000000000000000000000000000000..800d492abdf74cd7e1a96a66df0ec4ed7cfe0dd4 --- /dev/null +++ b/vendor/libigl/include/igl/dirname.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DIRNAME_H +#define IGL_DIRNAME_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Function like PHP's dirname: /etc/passwd --> /etc, + // Input: + // path string containing input path + // Returns string containing dirname (see php's dirname) + // + // See also: basename, pathinfo + // + // **Note:** This function will have undefined behavior if **file names** in + // the path contain \ and / characters. This function interprets \ and / as + // file path separators. + IGL_INLINE std::string dirname(const std::string & path); +} + +#ifndef IGL_STATIC_LIBRARY +# include "dirname.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/dot.cpp b/vendor/libigl/include/igl/dot.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38f191546aa484983a9fa81d1a5a8392e1e52098 --- /dev/null +++ b/vendor/libigl/include/igl/dot.cpp @@ -0,0 +1,16 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "dot.h" + +// http://www.antisphere.com/Wiki/tools:anttweakbar +IGL_INLINE double igl::dot( + const double *a, + const double *b) +{ + return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; +} diff --git a/vendor/libigl/include/igl/dot.h b/vendor/libigl/include/igl/dot.h new file mode 100644 index 0000000000000000000000000000000000000000..9494eac7b68205b4514906273e62d115c2378823 --- /dev/null +++ b/vendor/libigl/include/igl/dot.h @@ -0,0 +1,27 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DOT_H +#define IGL_DOT_H +#include "igl_inline.h" +namespace igl +{ + // Computes out = dot(a,b) + // Inputs: + // a left 3d vector + // b right 3d vector + // Returns scalar dot product + IGL_INLINE double dot( + const double *a, + const double *b); +} + +#ifndef IGL_STATIC_LIBRARY +# include "dot.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/dot_row.cpp b/vendor/libigl/include/igl/dot_row.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f6d57e06a2ee5e80c6be0898097d261160db15e --- /dev/null +++ b/vendor/libigl/include/igl/dot_row.cpp @@ -0,0 +1,26 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "igl/dot_row.h" + +template +IGL_INLINE DerivedV igl::dot_row( + const Eigen::PlainObjectBase& A, + const Eigen::PlainObjectBase& B + ) +{ + assert(A.rows() == B.rows()); + assert(A.cols() == B.cols()); + + return (A.array() * B.array()).rowwise().sum(); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template Eigen::Matrix igl::dot_row >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&); +#endif diff --git a/vendor/libigl/include/igl/doublearea.cpp b/vendor/libigl/include/igl/doublearea.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e2d0bacf4a8aae97ae2587944e6c4373ed1f645 --- /dev/null +++ b/vendor/libigl/include/igl/doublearea.cpp @@ -0,0 +1,264 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "doublearea.h" +#include "edge_lengths.h" +#include "parallel_for.h" +#include "sort.h" +#include +#include +#include + +template +IGL_INLINE void igl::doublearea( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & dblA) +{ + // quads are handled by a specialized function + if (F.cols() == 4) return doublearea_quad(V,F,dblA); + + const int dim = V.cols(); + // Only support triangles + assert(F.cols() == 3); + const size_t m = F.rows(); + // Compute edge lengths + Eigen::Matrix l; + + // Projected area helper + const auto & proj_doublearea = + [&V,&F](const int x, const int y, const int f) + ->typename DerivedV::Scalar + { + auto rx = V(F(f,0),x)-V(F(f,2),x); + auto sx = V(F(f,1),x)-V(F(f,2),x); + auto ry = V(F(f,0),y)-V(F(f,2),y); + auto sy = V(F(f,1),y)-V(F(f,2),y); + return rx*sy - ry*sx; + }; + + switch(dim) + { + case 3: + { + dblA = DeriveddblA::Zero(m,1); + for(size_t f = 0;f +IGL_INLINE void igl::doublearea( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & D) +{ + assert((B.cols() == A.cols()) && "dimensions of A and B should match"); + assert((C.cols() == A.cols()) && "dimensions of A and C should match"); + assert(A.rows() == B.rows() && "corners should have same length"); + assert(A.rows() == C.rows() && "corners should have same length"); + switch(A.cols()) + { + case 2: + { + // For 2d compute signed area + const auto & R = A-C; + const auto & S = B-C; + D = (R.col(0).array()*S.col(1).array() - + R.col(1).array()*S.col(0).array()).template cast< + typename DerivedD::Scalar>(); + break; + } + default: + { + Eigen::Matrix + uL(A.rows(),3); + uL.col(0) = ((B-C).rowwise().norm()).template cast(); + uL.col(1) = ((C-A).rowwise().norm()).template cast(); + uL.col(2) = ((A-B).rowwise().norm()).template cast(); + doublearea(uL,D); + } + } +} + +template < + typename DerivedA, + typename DerivedB, + typename DerivedC> +IGL_INLINE typename DerivedA::Scalar igl::doublearea_single( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C) +{ + assert(A.size() == 2 && "Vertices should be 2D"); + assert(B.size() == 2 && "Vertices should be 2D"); + assert(C.size() == 2 && "Vertices should be 2D"); + auto r = A-C; + auto s = B-C; + return r(0)*s(1) - r(1)*s(0); +} + +template +IGL_INLINE void igl::doublearea( + const Eigen::MatrixBase & ul, + Eigen::PlainObjectBase & dblA) +{ + // Default is to leave NaNs and fire asserts in debug mode + return doublearea( + ul,std::numeric_limits::quiet_NaN(),dblA); +} + +template +IGL_INLINE void igl::doublearea( + const Eigen::MatrixBase & ul, + const typename Derivedl::Scalar nan_replacement, + Eigen::PlainObjectBase & dblA) +{ + using namespace Eigen; + using namespace std; + typedef typename Derivedl::Index Index; + // Only support triangles + assert(ul.cols() == 3); + // Number of triangles + const Index m = ul.rows(); + Eigen::Matrix l; + MatrixXi _; + // + // "Miscalculating Area and Angles of a Needle-like Triangle" + // https://people.eecs.berkeley.edu/~wkahan/Triangle.pdf + igl::sort(ul,2,false,l,_); + // semiperimeters + //Matrix s = l.rowwise().sum()*0.5; + //assert((Index)s.rows() == m); + // resize output + dblA.resize(l.rows(),1); + parallel_for( + m, + [&l,&dblA,&nan_replacement](const int i) + { + // Kahan's Heron's formula + typedef typename Derivedl::Scalar Scalar; + const Scalar arg = + (l(i,0)+(l(i,1)+l(i,2)))* + (l(i,2)-(l(i,0)-l(i,1)))* + (l(i,2)+(l(i,0)-l(i,1)))* + (l(i,0)+(l(i,1)-l(i,2))); + dblA(i) = 2.0*0.25*sqrt(arg); + // Alec: If the input edge lengths were computed from floating point + // vertex positions then there's no guarantee that they fulfill the + // triangle inequality (in their floating point approximations). For + // nearly degenerate triangles the round-off error during side-length + // computation may be larger than (or rather smaller) than the height of + // the triangle. In "Lecture Notes on Geometric Robustness" Shewchuck 09, + // Section 3.1 http://www.cs.berkeley.edu/~jrs/meshpapers/robnotes.pdf, + // he recommends computing the triangle areas for 2D and 3D using 2D + // signed areas computed with determinants. + assert( + (nan_replacement == nan_replacement || + (l(i,2) - (l(i,0)-l(i,1)))>=0) + && "Side lengths do not obey the triangle inequality."); + if(dblA(i) != dblA(i)) + { + dblA(i) = nan_replacement; + } + assert(dblA(i) == dblA(i) && "DOUBLEAREA() PRODUCED NaN"); + }, + 1000l); +} + +template +IGL_INLINE void igl::doublearea_quad( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & dblA) +{ + assert(V.cols() == 3); // Only supports points in 3D + assert(F.cols() == 4); // Only support quads + const size_t m = F.rows(); + + // Split the quads into triangles + Eigen::MatrixXi Ft(F.rows()*2,3); + + for(size_t i=0; i doublearea_tri; + igl::doublearea(V,Ft,doublearea_tri); + + dblA.resize(F.rows(),1); + for(unsigned i=0; i, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::doublearea, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template Eigen::Matrix::Scalar igl::doublearea_single, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template Eigen::Matrix::Scalar igl::doublearea_single, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/doublearea.h b/vendor/libigl/include/igl/doublearea.h new file mode 100644 index 0000000000000000000000000000000000000000..95c1515082ac13ccb7f08e5d68264c3018769f8b --- /dev/null +++ b/vendor/libigl/include/igl/doublearea.h @@ -0,0 +1,104 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DOUBLEAREA_H +#define IGL_DOUBLEAREA_H +#include "igl_inline.h" +#include +namespace igl +{ + // DOUBLEAREA computes twice the area for each input triangle[quad] + // + // Templates: + // DerivedV derived type of eigen matrix for V (e.g. derived from + // MatrixXd) + // DerivedF derived type of eigen matrix for F (e.g. derived from + // MatrixXi) + // DeriveddblA derived type of eigen matrix for dblA (e.g. derived from + // MatrixXd) + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by simplex_size list of mesh faces (must be triangles or quads) + // Outputs: + // dblA #F list of triangle[quad] double areas (SIGNED only for 2D input) + // + // Known bug: For dim==3 complexity is O(#V + #F)!! Not just O(#F). This is a big deal + // if you have 1million unreferenced vertices and 1 face + template + IGL_INLINE void doublearea( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & dblA); + // Stream of triangles, computes signed area... + template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedD> + IGL_INLINE void doublearea( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & D); + // Single triangle in 2D! + // + // This should handle streams of corners not just single corners + template < + typename DerivedA, + typename DerivedB, + typename DerivedC> + IGL_INLINE typename DerivedA::Scalar doublearea_single( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C); + // Same as above but use instrinsic edge lengths rather than (V,F) mesh. This + // + // Inputs: + // l #F by dim list of edge lengths using + // for triangles, columns correspond to edges 23,31,12 + // nan_replacement what value should be used for triangles whose given + // edge lengths do not obey the triangle inequality. These may be very + // wrong (e.g., [100 1 1]) or may be nearly degenerate triangles whose + // floating point side length computation leads to breach of the triangle + // inequality. One may wish to set this parameter to 0 if side lengths l + // are _known_ to come from a valid embedding (e.g., some mesh (V,F)). In + // that case, the only circumstance the triangle inequality is broken is + // when the triangle is nearly degenerate and floating point error + // dominates: hence replacing with zero is reasonable. + // Outputs: + // dblA #F list of triangle double areas + template + IGL_INLINE void doublearea( + const Eigen::MatrixBase & l, + const typename Derivedl::Scalar nan_replacement, + Eigen::PlainObjectBase & dblA); + // default behavior is to assert on NaNs and leave them in place + template + IGL_INLINE void doublearea( + const Eigen::MatrixBase & l, + Eigen::PlainObjectBase & dblA); + // DOUBLEAREA_QUAD computes twice the area for each input quadrilateral + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by simplex_size list of mesh faces (must be quadrilaterals) + // Outputs: + // dblA #F list of quadrilateral double areas + // + template + IGL_INLINE void doublearea_quad( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & dblA); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "doublearea.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/dqs.cpp b/vendor/libigl/include/igl/dqs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..56090ef47593af208697e3849fafa6f3c80ecec7 --- /dev/null +++ b/vendor/libigl/include/igl/dqs.cpp @@ -0,0 +1,74 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "dqs.h" +#include +template < + typename DerivedV, + typename DerivedW, + typename Q, + typename QAlloc, + typename T, + typename DerivedU> +IGL_INLINE void igl::dqs( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & W, + const std::vector & vQ, + const std::vector & vT, + Eigen::PlainObjectBase & U) +{ + using namespace std; + assert(V.rows() <= W.rows()); + assert(W.cols() == (int)vQ.size()); + assert(W.cols() == (int)vT.size()); + // resize output + U.resizeLike(V); + + // Convert quats + trans into dual parts + vector vD(vQ.size()); + for(int c = 0;c10000) + for(int i = 0;i, Eigen::Matrix, Eigen::Quaternion, Eigen::aligned_allocator >, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector, Eigen::aligned_allocator > > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/dqs.h b/vendor/libigl/include/igl/dqs.h new file mode 100644 index 0000000000000000000000000000000000000000..288d308fd1593ada6e8a64c94ff43511f51b658f --- /dev/null +++ b/vendor/libigl/include/igl/dqs.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_DQS_H +#define IGL_DQS_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Dual quaternion skinning + // + // Inputs: + // V #V by 3 list of rest positions + // W #W by #C list of weights + // vQ #C list of rotation quaternions + // vT #C list of translation vectors + // Outputs: + // U #V by 3 list of new positions + template < + typename DerivedV, + typename DerivedW, + typename Q, + typename QAlloc, + typename T, + typename DerivedU> + IGL_INLINE void dqs( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & W, + const std::vector & vQ, + const std::vector & vT, + Eigen::PlainObjectBase & U); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "dqs.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/dual_contouring.cpp b/vendor/libigl/include/igl/dual_contouring.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a08aa1bf8593f8e45607b9b0dcaf439b9360a28 --- /dev/null +++ b/vendor/libigl/include/igl/dual_contouring.cpp @@ -0,0 +1,566 @@ +#include "dual_contouring.h" +#include "quadprog.h" +#include "parallel_for.h" +#include +#include +#include +#include +#include + +namespace igl +{ + // These classes not intended to be used directly + class Hash + { + public: + // https://stackoverflow.com/a/26348708/148668 + uint64_t operator()(const std::tuple & key) const + { + // Check that conversion is safe. Could use int16_t directly everywhere + // below but it's an uncommon type to expose and grid indices should + // never be more than 2¹⁵-1 in the first place. + assert( std::get<0>(key) == (int)(int16_t)std::get<0>(key)); + assert( std::get<1>(key) == (int)(int16_t)std::get<1>(key)); + assert( std::get<2>(key) == (int)(int16_t)std::get<2>(key)); + uint64_t result = uint16_t(std::get<0>(key)); + result = (result << 16) + uint16_t(std::get<1>(key)); + result = (result << 16) + uint16_t(std::get<2>(key)); + return result; + }; + }; + template + class DualContouring + { + // Types + public: + using RowVector3S = Eigen::Matrix; + using RowVector4S = Eigen::Matrix; + using Matrix4S = Eigen::Matrix; + using Matrix3S = Eigen::Matrix; + using Vector3S = Eigen::Matrix; + using KeyTriplet = std::tuple; + public: + // Working variables + // see dual_contouring.h + // f(x) returns >0 outside, <0 inside, and =0 on the surface + std::function f; + // f_grad(x) returns (df/dx)/‖df/dx‖ (normalization only important when + // f(x) = 0). + std::function f_grad; + bool constrained; + bool triangles; + bool root_finding; + RowVector3S min_corner; + RowVector3S step; + Eigen::Matrix V; + // Internal variables + // Running number of vertices added during contouring + typename decltype(V)::Index n; + // map from cell subscript to index in V + std::unordered_map< KeyTriplet, typename decltype(V)::Index, Hash > C2V; + // running list of aggregate vertex positions (used for spring + // regularization term) + std::vector> vV; + // running list of subscripts corresponding to vertices + std::vector> vI; + // running list of quadric matrices corresponding to inserted vertices + std::vector> vH; + // running list of number of faces incident on this vertex (used to + // normalize spring regulatization term) + std::vector vcount; + // running list of output quad faces + Eigen::Matrix Q; + // running number of real quads in Q (used for dynamic array allocation) + typename decltype(Q)::Index m; + // mutexes used to insert into Q and (vV,vI,vH,vcount) + std::mutex Qmut; + std::mutex Vmut; + public: + DualContouring( + const std::function & _f, + const std::function & _f_grad, + const bool _constrained = false, + const bool _triangles = false, + const bool _root_finding = true): + f(_f), + f_grad(_f_grad), + constrained(_constrained), + triangles(_triangles), + root_finding(_root_finding), + n(0), + C2V(0), + vV(),vI(),vH(),vcount(), + m(0) + { } + // Side effects: new entry in vV,vI,vH,vcount, increment n + // Returns index of new vertex + typename decltype(V)::Index new_vertex() + { + const auto v = n; + n++; + vcount.resize(n); + vV.resize(n); + vI.resize(n); + vH.resize(n); + vcount[v] = 0; + vV[v].setZero(); + vH[v].setZero(); + return v; + }; + // Inputs: + // kc 3-long vector of {x,y,z} index of primal grid **cell** + // Returns index to corresponding dual vertex + // Side effects: if vertex for this cell does not yet exist, creates it + typename decltype(V)::Index sub2dual(const Eigen::RowVector3i & kc) + { + const KeyTriplet key = {kc(0),kc(1),kc(2)}; + const auto it = C2V.find(key); + typename decltype(V)::Index v = -1; + if(it == C2V.end()) + { + v = new_vertex(); + C2V[key] = v; + vI[v] = kc; + }else + { + v = it->second; + } + return v; + }; + RowVector3S primal(const Eigen::RowVector3i & ic) const + { + return min_corner + (ic.cast().array() * step.array()).matrix(); + } + Eigen::RowVector3i inverse_primal(const RowVector3S & x) const + { + // x = min_corner + (ic.cast().array() * step.array()).matrix(); + // x-min_corner = (ic.cast().array() * step.array()) + // (x-min_corner).array() / step.array() = ic.cast().array() + // ((x-min_corner).array() / step.array()).round() = ic + return + ((x-min_corner).array()/step.array()).round().template cast(); + } + // Inputs: + // x x-index of vertex on primal grid + // y y-index of vertex on primal grid + // z z-index of vertex on primal grid + // o which edge are we looking back on? o=0->x,o=1->y,o=2->z + // Side effects: may insert new vertices into vV,vI,vH,vcount, new faces + // into Q + bool single_edge(const int & x, const int & y, const int & z, const int & o) + { + const RowVector3S e0 = primal(Eigen::RowVector3i(x,y,z)); + const Scalar f0 = f(e0); + return single_edge(x,y,z,o,e0,f0); + } + bool single_edge( + const int & x, + const int & y, + const int & z, + const int & o, + const RowVector3S & e0, + const Scalar & f0) + { + //e1 computed here needs to precisely agree with e0 when called with + //correspond x,y,z. So, don't do this: + //Eigen::RowVector3d e1 = e0; + //e1(o) -= step(o); + Eigen::RowVector3i jc(x,y,z); + jc(o) -= 1; + const RowVector3S e1 = primal(jc); + const Scalar f1 = f(e1); + return single_edge(x,y,z,o,e0,f0,e1,f1); + } + bool single_edge( + const int & x, + const int & y, + const int & z, + const int & o, + const RowVector3S & e0, + const Scalar & f0, + const RowVector3S & e1, + const Scalar & f1) + { + const Scalar isovalue = 0; + if((f0>isovalue) == (f1>isovalue)) { return false; } + // Position of crossing point along edge + RowVector3S p; + Scalar t = -1; + if(root_finding) + { + Scalar tl = 0; + bool gl = f0>0; + Scalar tu = 1; + bool gu = f1>0; + assert(gu ^ gl); + int riter = 0; + const int max_riter = 7; + while(true) + { + t = 0.5*(tu + tl); + p = e0+t*(e1-e0); + riter++; + if(riter > max_riter) { break;} + const Scalar ft = f(p); + if( (ft>0) == gu) { tu = t; } + else if( (ft>0) == gl){ tl = t; } + else { break; } + } + }else + { + // inverse lerp + const Scalar delta = f1-f0; + if(delta == 0) { t = 0.5; } + t = (isovalue - f0)/delta; + p = e0+t*(e1-e0); + } + // insert vertex at this point to triangulate quad face + const typename decltype(V)::Index ev = triangles ? new_vertex() : -1; + if(triangles) + { + const std::lock_guard lock(Vmut); + vV[ev] = p; + vcount[ev] = 1; + vI[ev] = Eigen::RowVector3i(-1,-1,-1); + } + // edge normal from function handle (could use grid finite + // differences/interpolation gradients) + const RowVector3S dfdx = f_grad(p); + // homogenous plane equation + const RowVector4S P = (RowVector4S()< lock(Vmut); + const typename decltype(V)::Index v = sub2dual(kc); + vV[v] += p; + vcount[v]++; + vH[v] += H; + face(k++) = v; + } + } + { + const std::lock_guard lock(Qmut); + if(triangles) + { + if(m+4 >= Q.rows()){ Q.conservativeResize(2*m+4,Q.cols()); } + if(f0>f1) + { + Q.row(m+0)<< ev,face(3),face(1) ; + Q.row(m+1)<< ev,face(1),face(0); + Q.row(m+2)<< face(2), ev,face(0); + Q.row(m+3)<< face(2),face(3), ev; + }else + { + Q.row(m+0)<< ev,face(1),face(3) ; + Q.row(m+1)<< ev,face(3),face(2); + Q.row(m+2)<< face(0), ev,face(2); + Q.row(m+3)<< face(0),face(1), ev; + } + m+=4; + }else + { + if(m+1 >= Q.rows()){ Q.conservativeResize(2*m+1,Q.cols()); } + if(f0>f1) + { + Q.row(m)<< face(2),face(3),face(1),face(0); + }else + { + Q.row(m)<< face(0),face(1),face(3),face(2); + } + m++; + } + } + return true; + } + // Side effects: Q resized to fit m, V constructed to fit n and + // reconstruct data in vH,vI,vV,vcount + void dual_vertex_positions() + { + Q.conservativeResize(m,Q.cols()); + V.resize(n,3); + igl::parallel_for(n,[&](const Eigen::Index v) + { + RowVector3S mid = vV[v] / Scalar(vcount[v]); + if(triangles && vI[v](0)<0 ){ V.row(v) = mid; return; } + const Scalar w = 1e-2*(0.01+vcount[v]); + Matrix3S A = vH[v].block(0,0,3,3) + w*Matrix3S::Identity(); + RowVector3S b = -vH[v].block(3,0,1,3) + w*mid; + // Replace with solver + //RowVector3S p = b * A.inverse(); + // + // min_p ½ pᵀ A p - pᵀb + // + // let p = p₀ + x + // + // min ½ (p₀ + x )ᵀ A (p₀ + x ) - (p₀ + x )ᵀb + // step≥x≥0 + const RowVector3S p0 = + min_corner + ((vI[v].template cast().array()) * step.array()).matrix(); + const RowVector3S x = + constrained ? + igl::quadprog(A,(p0*A-b).transpose(),Vector3S(0,0,0),step.transpose()) : + Eigen::LLT(A).solve(-(p0*A-b).transpose()); + V.row(v) = p0+x; + },1000ul); + } + // Inputs: + // _min_corner minimum (bottomLeftBack) corner of primal grid + // max_corner maximum (topRightFront) corner of primal grid + // nx number of primal grid vertices along x-axis + // ny number of primal grid vertices along y-ayis + // nz number of primal grid vertices along z-azis + // Side effects: prepares vV,vI,vH,vcount, Q for vertex_positions() + void dense( + const RowVector3S & _min_corner, + const RowVector3S & max_corner, + const int nx, + const int ny, + const int nz) + { + min_corner = _min_corner; + step = + (max_corner-min_corner).array()/(RowVector3S(nx,ny,nz).array()-1); + // Should do some reasonable reserves for C2V,vV,vI,vH,vcount + Q.resize(std::pow(nx*ny*nz,2./3.),triangles?3:4); + // loop over grid + igl::parallel_for(nx,[&](const int x) + { + for(int y = 0;y + void dense( + const Eigen::MatrixBase & Gf, + const Eigen::MatrixBase & GV, + const int nx, + const int ny, + const int nz) + { + min_corner = GV.colwise().minCoeff(); + const RowVector3S max_corner = GV.colwise().maxCoeff(); + step = + (max_corner-min_corner).array()/(RowVector3S(nx,ny,nz).array()-1); + + // Should do some reasonable reserves for C2V,vV,vI,vH,vcount + Q.resize(std::pow(nx*ny*nz,2./3.),triangles?3:4); + + const auto xyz2i = [&nx,&ny,&nz] + (const int & x, const int & y, const int & z)->Eigen::Index + { + return x+nx*(y+ny*(z)); + }; + + // loop over grid + igl::parallel_for(nz,[&](const int z) + { + for(int y = 0;y & Gf, + const Eigen::Matrix & GV, + const Eigen::Matrix & GI) + { + step = _step; + Q.resize((triangles?4:1)*GI.rows(),triangles?3:4); + // in perfect world doesn't matter where min_corner is so long as it is + // _on_ the grid. For models very far from origin, centering grid near + // model avoids possible rounding error in hash()/inverse_primal() + // [still very unlikely, but let's be safe] + min_corner = GV.colwise().minCoeff(); + // igl::parallel_for here made things worse. Probably need to do proper + // map-reduce rather than locks on mutexes. + for(Eigen::Index i = 0;i=0 && "Edges should differ in just one coordinate"); + // i0 is the larger subscript location and ic1 is backward in the o + // direction. + for(int j = 0;j<3;j++){ assert(ic0(j) == ic1(j)+(o==j)); } + const int x = ic0(0); + const int y = ic0(1); + const int z = ic0(2); + single_edge(x,y,z,o,e0,f0,e1,f1); + } + dual_vertex_positions(); + } + }; +} + +template < + typename DerivedV, + typename DerivedQ> +IGL_INLINE void igl::dual_contouring( + const std::function< + typename DerivedV::Scalar(const Eigen::Matrix &)> & f, + const std::function< + Eigen::Matrix( + const Eigen::Matrix &)> & f_grad, + const Eigen::Matrix & min_corner, + const Eigen::Matrix & max_corner, + const int nx, + const int ny, + const int nz, + const bool constrained, + const bool triangles, + const bool root_finding, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q) +{ + typedef typename DerivedV::Scalar Scalar; + DualContouring DC(f,f_grad,constrained,triangles,root_finding); + DC.dense(min_corner,max_corner,nx,ny,nz); + V = DC.V; + Q = DC.Q.template cast(); +} + +template < + typename DerivedGf, + typename DerivedGV, + typename DerivedV, + typename DerivedQ> +IGL_INLINE void igl::dual_contouring( + const std::function< + typename DerivedV::Scalar(const Eigen::Matrix &)> & f, + const std::function< + Eigen::Matrix( + const Eigen::Matrix &)> & f_grad, + const Eigen::MatrixBase & Gf, + const Eigen::MatrixBase & GV, + const int nx, + const int ny, + const int nz, + const bool constrained, + const bool triangles, + const bool root_finding, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q) +{ + typedef typename DerivedV::Scalar Scalar; + DualContouring DC(f,f_grad,constrained,triangles,root_finding); + DC.dense(Gf,GV,nx,ny,nz); + V = DC.V; + Q = DC.Q.template cast(); +} + +template < + typename DerivedGf, + typename DerivedGV, + typename DerivedGI, + typename DerivedV, + typename DerivedQ> +IGL_INLINE void igl::dual_contouring( + const std::function &)> & f, + const std::function(const Eigen::Matrix &)> & f_grad, + const Eigen::Matrix & step, + const Eigen::MatrixBase & Gf, + const Eigen::MatrixBase & GV, + const Eigen::MatrixBase & GI, + const bool constrained, + const bool triangles, + const bool root_finding, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q) +{ + if(GI.rows() == 0){ return;} + assert(GI.cols() == 2); + typedef typename DerivedV::Scalar Scalar; + DualContouring DC(f,f_grad,constrained,triangles,root_finding); + DC.sparse(step,Gf,GV,GI); + V = DC.V; + Q = DC.Q.template cast(); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::dual_contouring, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::function::Scalar (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, std::function::Scalar, 1, 3, 1, 1, 3> (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, int, bool, bool, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::dual_contouring, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::function::Scalar (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, std::function::Scalar, 1, 3, 1, 1, 3> (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, int, int, bool, bool, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::dual_contouring, Eigen::Matrix >(std::function::Scalar (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, std::function::Scalar, 1, 3, 1, 1, 3> (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&, Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&, int, int, int, bool, bool, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::dual_contouring, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::function::Scalar (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, std::function::Scalar, 1, 3, 1, 1, 3> (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, bool, bool, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::dual_contouring, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::function::Scalar (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, std::function::Scalar, 1, 3, 1, 1, 3> (Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&)> const&, Eigen::Matrix::Scalar, 1, 3, 1, 1, 3> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, bool, bool, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/dual_contouring.h b/vendor/libigl/include/igl/dual_contouring.h new file mode 100644 index 0000000000000000000000000000000000000000..24c645457322881d0916e0ef7b30bb5988ce1d2d --- /dev/null +++ b/vendor/libigl/include/igl/dual_contouring.h @@ -0,0 +1,103 @@ +#ifndef IGL_DUAL_CONTOURING_H +#define IGL_DUAL_CONTOURING_H +#include "igl_inline.h" +#include +#include +#include +namespace igl +{ + // Dual contouring to extract a pure quad mesh from differentiable implicit + // function using a dense grid. + // + // Inputs: + // f function returning >0 outside, <0 inside and =0 on the surface + // f_grad function returning ∇f/‖∇f‖ + // min_corner position of primal grid vertex at minimum corner + // max_corner position of primal grid vertex at maximum corner + // nx number of vertices on x side of primal grid + // ny number of vertices on y side of primal grid + // nz number of vertices on z side of primal grid + // constrained whether to force dual vertices to lie strictly inside + // corresponding primal cell (prevents self-intersections at cost of + // surface quality; marginally slower) + // triangles whether to output four triangles instead of one quad per + // crossing edge (quad mesh usually looks fine) + // root_finding whether to use root finding to identify crossing point on + // each edge (improves quality a lot at cost of performance). If false, + // use linear interpolation. + // Outputs: + // V #V by 3 list of outputs vertex positions + // Q #Q by 4 (or 3 if triangles=true) face indices into rows of V + template < + typename DerivedV, + typename DerivedQ> + IGL_INLINE void dual_contouring( + const std::function< + typename DerivedV::Scalar(const Eigen::Matrix &)> & f, + const std::function< + Eigen::Matrix( + const Eigen::Matrix &)> & f_grad, + const Eigen::Matrix & min_corner, + const Eigen::Matrix & max_corner, + const int nx, + const int ny, + const int nz, + const bool constrained, + const bool triangles, + const bool root_finding, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q); + // Inputs: + // Gf nx*ny*nz list of function values so that Gf(k) = f(GV.row(k)) (only + // needs to be accurate near f=0 and correct sign elsewhere) + // GV nx*ny*nz list of grid positions so that the x,y,z grid position is at + // GV.row(x+nx*(y+z*ny)) + template < + typename DerivedGf, + typename DerivedGV, + typename DerivedV, + typename DerivedQ> + IGL_INLINE void dual_contouring( + const std::function< + typename DerivedV::Scalar(const Eigen::Matrix &)> & f, + const std::function< + Eigen::Matrix( + const Eigen::Matrix &)> & f_grad, + const Eigen::MatrixBase & Gf, + const Eigen::MatrixBase & GV, + const int nx, + const int ny, + const int nz, + const bool constrained, + const bool triangles, + const bool root_finding, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q); + // Sparse voxel grid + // + // Gf #GV list of corresponding f values. If using root finding then only the + // sign needs to be correct. + template < + typename DerivedGf, + typename DerivedGV, + typename DerivedGI, + typename DerivedV, + typename DerivedQ> + IGL_INLINE void dual_contouring( + const std::function &)> & f, + const std::function(const Eigen::Matrix &)> & f_grad, + const Eigen::Matrix & step, + const Eigen::MatrixBase & Gf, + const Eigen::MatrixBase & GV, + const Eigen::MatrixBase & GI, + const bool constrained, + const bool triangles, + const bool root_finding, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q); +} + +#ifndef IGL_STATIC_LIBRARY +# include "dual_contouring.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/ears.cpp b/vendor/libigl/include/igl/ears.cpp new file mode 100644 index 0000000000000000000000000000000000000000..428ba161b18aae8974223ec5526d4b68a1468be5 --- /dev/null +++ b/vendor/libigl/include/igl/ears.cpp @@ -0,0 +1,34 @@ +#include "ears.h" +#include "on_boundary.h" +#include "find.h" +#include "slice.h" +#include "mat_min.h" +#include + +template < + typename DerivedF, + typename Derivedear, + typename Derivedear_opp> +IGL_INLINE void igl::ears( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & ear, + Eigen::PlainObjectBase & ear_opp) +{ + assert(F.cols() == 3 && "F should contain triangles"); + Eigen::Array B; + { + Eigen::Array I; + on_boundary(F,I,B); + } + find(B.rowwise().count() == 2, ear); + Eigen::Array Bear; + slice(B, ear, 1, Bear); + Eigen::Array M; + mat_min(Bear,2,M,ear_opp); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::ears, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/ears.h b/vendor/libigl/include/igl/ears.h new file mode 100644 index 0000000000000000000000000000000000000000..b7c51ec66b878296da2f1f617e39649f0e7b5ca9 --- /dev/null +++ b/vendor/libigl/include/igl/ears.h @@ -0,0 +1,30 @@ +#ifndef IGL_EARS_H +#define IGL_EARS_H +#include "igl_inline.h" +#include +namespace igl +{ + // FIND_EARS Find all ears (faces with two boundary edges) in a given mesh + // + // [ears,ear_opp] = find_ears(F) + // + // Inputs: + // F #F by 3 list of triangle mesh indices + // Outputs: + // ears #ears list of indices into F of ears + // ear_opp #ears list of indices indicating which edge is non-boundary + // (connecting to flops) + // + template < + typename DerivedF, + typename Derivedear, + typename Derivedear_opp> + IGL_INLINE void ears( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & ear, + Eigen::PlainObjectBase & ear_opp); +} +#ifndef IGL_STATIC_LIBRARY +# include "ears.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/edge_collapse_is_valid.cpp b/vendor/libigl/include/igl/edge_collapse_is_valid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e631800e381bfd8da7ed9dcac88b2a7f710563cb --- /dev/null +++ b/vendor/libigl/include/igl/edge_collapse_is_valid.cpp @@ -0,0 +1,124 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "edge_collapse_is_valid.h" +#include "collapse_edge.h" +#include "circulation.h" +#include "intersect.h" +#include "unique.h" +#include "list_to_matrix.h" +#include + +IGL_INLINE bool igl::edge_collapse_is_valid( + const int e, + const Eigen::MatrixXi & F, + const Eigen::MatrixXi & E, + const Eigen::VectorXi & EMAP, + const Eigen::MatrixXi & EF, + const Eigen::MatrixXi & EI) +{ + using namespace Eigen; + using namespace std; + // For consistency with collapse_edge.cpp, let's determine edge flipness + // (though not needed to check validity) + const int eflip = E(e,0)>E(e,1); + // source and destination + const int s = eflip?E(e,1):E(e,0); + const int d = eflip?E(e,0):E(e,1); + + if(s == IGL_COLLAPSE_EDGE_NULL && d==IGL_COLLAPSE_EDGE_NULL) + { + return false; + } + // check if edge collapse is valid: intersection of vertex neighbors of s and + // d should be exactly 2+(s,d) = 4 + // http://stackoverflow.com/a/27049418/148668 + { + // all vertex neighbors around edge, including the two vertices of the edge + const auto neighbors = []( + const int e, + const bool ccw, + const Eigen::MatrixXi & F, + const Eigen::MatrixXi & E, + const Eigen::VectorXi & EMAP, + const Eigen::MatrixXi & EF, + const Eigen::MatrixXi & EI) + { + vector N,uN; + vector V2Fe = circulation(e, ccw,EMAP,EF,EI); + for(auto f : V2Fe) + { + N.push_back(F(f,0)); + N.push_back(F(f,1)); + N.push_back(F(f,2)); + } + vector _1,_2; + igl::unique(N,uN,_1,_2); + VectorXi uNm; + list_to_matrix(uN,uNm); + return uNm; + }; + VectorXi Ns = neighbors(e, eflip,F,E,EMAP,EF,EI); + VectorXi Nd = neighbors(e,!eflip,F,E,EMAP,EF,EI); + VectorXi Nint = igl::intersect(Ns,Nd); + if(Nint.size() != 4) + { + return false; + } + if(Ns.size() == 4 && Nd.size() == 4) + { + VectorXi NsNd(8); + NsNd< & Nsv, + std::vector & Ndv) +{ + // Do we really need to check if edge is IGL_COLLAPSE_EDGE_NULL ? + + if(Nsv.size()<2 || Ndv.size()<2) + { + // Bogus data + assert(false); + return false; + } + // determine if the first two vertices are the same before reordering. + // If they are and there are 3 each, then (I claim) this is an edge on a + // single tet. + const bool first_two_same = (Nsv[0] == Ndv[0]) && (Nsv[1] == Ndv[1]); + if(Nsv.size() == 3 && Ndv.size() == 3 && first_two_same) + { + // single tet + return false; + } + // https://stackoverflow.com/a/19483741/148668 + std::sort(Nsv.begin(), Nsv.end()); + std::sort(Ndv.begin(), Ndv.end()); + std::vector Nint; + std::set_intersection( + Nsv.begin(), Nsv.end(), Ndv.begin(), Ndv.end(), std::back_inserter(Nint)); + // check if edge collapse is valid: intersection of vertex neighbors of s and + // d should be exactly 2+(s,d) = 4 + // http://stackoverflow.com/a/27049418/148668 + if(Nint.size() != 2) + { + return false; + } + + return true; +} diff --git a/vendor/libigl/include/igl/edge_collapse_is_valid.h b/vendor/libigl/include/igl/edge_collapse_is_valid.h new file mode 100644 index 0000000000000000000000000000000000000000..3b7375566f72f4c64cd6cb865df5fec2e7377b92 --- /dev/null +++ b/vendor/libigl/include/igl/edge_collapse_is_valid.h @@ -0,0 +1,59 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EDGE_COLLAPSE_IS_VALID_H +#define IGL_EDGE_COLLAPSE_IS_VALID_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Assumes (V,F) is a closed manifold mesh (except for previouslly collapsed + // faces which should be set to: + // [IGL_COLLAPSE_EDGE_NULL IGL_COLLAPSE_EDGE_NULL IGL_COLLAPSE_EDGE_NULL]. + // Tests whether collapsing exactly two faces and exactly 3 edges from E (e + // and one side of each face gets collapsed to the other) will result in a + // mesh with the same topology. + // + // Inputs: + // e index into E of edge to try to collapse. E(e,:) = [s d] or [d s] so + // that sj) is the edge of + // F(f,:) opposite the vth corner, where EI(e,0)=v. Similarly EF(e,1) " + // e=(j->i) + // EI #E by 2 list of edge flap corners (see above). + // Returns true if edge collapse is valid + IGL_INLINE bool edge_collapse_is_valid( + const int e, + const Eigen::MatrixXi & F, + const Eigen::MatrixXi & E, + const Eigen::VectorXi & EMAP, + const Eigen::MatrixXi & EF, + const Eigen::MatrixXi & EI); + // Inputs: + // Nsv #Nsv list of "next" vertices circulating around starting vertex of + // edge + // Ndv #Ndv list of "next" vertices circulating around destination vertex of + // edge + // Outputs: + // Nsv (side-effect: sorted by value) + // Ndv (side-effect: sorted by value) + // Returns true iff edge collapse is valid + // + // See also: circulation + IGL_INLINE bool edge_collapse_is_valid( + /*const*/ std::vector & Nsv, + /*const*/ std::vector & Ndv); +} +#ifndef IGL_STATIC_LIBRARY +# include "edge_collapse_is_valid.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/edge_exists_near.h b/vendor/libigl/include/igl/edge_exists_near.h new file mode 100644 index 0000000000000000000000000000000000000000..6acfb8f80b9ebc4f33220bbfbf0264fed2dd7222 --- /dev/null +++ b/vendor/libigl/include/igl/edge_exists_near.h @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EDGE_EXISTS_NEAR_H +#define IGL_EDGE_EXISTS_NEAR_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Does edge (a,b) exist in the edges of all faces incident on + // existing unique edge uei. + // + // Inputs: + // uE #uE by 2 list of unique undirected edges + // EMAP #F*3 list of indices into uE, mapping each directed edge to unique + // undirected edge + // uE2E #uE list of lists of indices into E of coexisting edges + // E #F*3 by 2 list of half-edges + // a 1st end-point of query edge + // b 2nd end-point of query edge + // uei index into uE/uE2E of unique edge + // Returns true if edge exists near uei. + // + // See also: unique_edge_map + template < + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType, + typename Index> + IGL_INLINE bool edge_exists_near( + const Eigen::MatrixBase & uE, + const Eigen::MatrixBase & EMAP, + const std::vector > & uE2E, + const Index & a, + const Index & b, + const Index & uei); +} +#ifndef IGL_STATIC_LIBRARY +# include "edge_exists_near.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/edge_flaps.cpp b/vendor/libigl/include/igl/edge_flaps.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2beadd2e21f701e4ffcb14bf3d907aab050be4c --- /dev/null +++ b/vendor/libigl/include/igl/edge_flaps.cpp @@ -0,0 +1,59 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "edge_flaps.h" +#include "unique_edge_map.h" +#include +#include + +IGL_INLINE void igl::edge_flaps( + const Eigen::MatrixXi & F, + const Eigen::MatrixXi & uE, + const Eigen::VectorXi & EMAP, + Eigen::MatrixXi & EF, + Eigen::MatrixXi & EI) +{ + // Initialize to boundary value + EF.setConstant(uE.rows(),2,-1); + EI.setConstant(uE.rows(),2,-1); + // loop over all faces + for(int f = 0;f +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "edge_lengths.h" +#include "squared_edge_lengths.h" + +template +IGL_INLINE void igl::edge_lengths( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& L) + { + igl::squared_edge_lengths(V,F,L); + L=L.array().sqrt().eval(); + } + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edge_lengths, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/edge_lengths.h b/vendor/libigl/include/igl/edge_lengths.h new file mode 100644 index 0000000000000000000000000000000000000000..30dc3474b0b51c540e05cde56dbcadc6e37d6990 --- /dev/null +++ b/vendor/libigl/include/igl/edge_lengths.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EDGE_LENGTHS_H +#define IGL_EDGE_LENGTHS_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Constructs a list of lengths of edges opposite each index in a face + // (triangle/tet) list + // + // Templates: + // DerivedV derived from vertex positions matrix type: i.e. MatrixXd + // DerivedF derived from face indices matrix type: i.e. MatrixXi + // DerivedL derived from edge lengths matrix type: i.e. MatrixXd + // Inputs: + // V eigen matrix #V by 3 + // F #F by 2 list of mesh edges + // or + // F #F by 3 list of mesh faces (must be triangles) + // or + // T #T by 4 list of mesh elements (must be tets) + // Outputs: + // L #F by {1|3|6} list of edge lengths + // for edges, column of lengths + // for triangles, columns correspond to edges [1,2],[2,0],[0,1] + // for tets, columns correspond to edges + // [3 0],[3 1],[3 2],[1 2],[2 0],[0 1] + // + template + IGL_INLINE void edge_lengths( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& L); +} + +#ifndef IGL_STATIC_LIBRARY +# include "edge_lengths.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/edge_midpoints.h b/vendor/libigl/include/igl/edge_midpoints.h new file mode 100644 index 0000000000000000000000000000000000000000..b17711a39a8e0dc89184bbf3254fd1f2653b6222 --- /dev/null +++ b/vendor/libigl/include/igl/edge_midpoints.h @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EDGE_MIDPOINTS_H +#define IGL_EDGE_MIDPOINTS_H +#include "igl_inline.h" + +#include +namespace igl +{ + // Computes the midpoints of edges in a triangle mesh. + // + // Input: + // V, F: triangle mesh + // E, oE: mapping from halfedges to edges and orientation as generated by + // orient_halfedges + // + // Output: + // mps: edge midpoints, one per edge in E + template + IGL_INLINE void edge_midpoints( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &E, + const Eigen::MatrixBase &oE, + Eigen::PlainObjectBase &mps); +} + +#ifndef IGL_STATIC_LIBRARY +# include "edge_midpoints.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/edge_topology.cpp b/vendor/libigl/include/igl/edge_topology.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1f2f66639d31f0723caf84b77fca6652178f9851 --- /dev/null +++ b/vendor/libigl/include/igl/edge_topology.cpp @@ -0,0 +1,110 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "edge_topology.h" +#include "is_edge_manifold.h" +#include + +template +IGL_INLINE void igl::edge_topology( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& EV, + Eigen::PlainObjectBase& FE, + Eigen::PlainObjectBase& EF) +{ + // Only needs to be edge-manifold + if (V.rows() ==0 || F.rows()==0) + { + EV = Eigen::PlainObjectBase::Constant(0,2,-1); + FE = Eigen::PlainObjectBase::Constant(0,3,-1); + EF = Eigen::PlainObjectBase::Constant(0,2,-1); + return; + } + assert(igl::is_edge_manifold(F)); + std::vector > ETT; + for(int f=0;f v2) std::swap(v1,v2); + std::vector r(4); + r[0] = v1; r[1] = v2; + r[2] = f; r[3] = i; + ETT.push_back(r); + } + std::sort(ETT.begin(),ETT.end()); + + // count the number of edges (assume manifoldness) + int En = 1; // the last is always counted + for(int i=0;i& r1 = ETT[i]; + EV(En,0) = r1[0]; + EV(En,1) = r1[1]; + EF(En,0) = r1[2]; + FE(r1[2],r1[3]) = En; + } + else + { + std::vector& r1 = ETT[i]; + std::vector& r2 = ETT[i+1]; + EV(En,0) = r1[0]; + EV(En,1) = r1[1]; + EF(En,0) = r1[2]; + EF(En,1) = r2[2]; + FE(r1[2],r1[3]) = En; + FE(r2[2],r2[3]) = En; + ++i; // skip the next one + } + ++En; + } + + // Sort the relation EF, accordingly to EV + // the first one is the face on the left of the edge + for(unsigned i=0; i, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase>&, Eigen::PlainObjectBase>&, Eigen::PlainObjectBase>&); +template void igl::edge_topology, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase>&, Eigen::PlainObjectBase>&, Eigen::PlainObjectBase>&); +#endif diff --git a/vendor/libigl/include/igl/edge_topology.h b/vendor/libigl/include/igl/edge_topology.h new file mode 100644 index 0000000000000000000000000000000000000000..eab31aa8abe5815a918d273e75f39f4166c1aece --- /dev/null +++ b/vendor/libigl/include/igl/edge_topology.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EDGE_TOPOLOGY_H +#define IGL_EDGE_TOPOLOGY_H + +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Initialize Edges and their topological relations (assumes an edge-manifold + // mesh) + // + // Inputs: + // V #V by dim list of mesh vertex positions (unused) + // F #F by 3 list of triangle indices into V + // Outputs: + // EV #Ex2 matrix storing the edge description as pair of indices to + // vertices + // FE #Fx3 matrix storing the Triangle-Edge relation + // EF #Ex2 matrix storing the Edge-Triangle relation + // + // TODO: This seems to be a inferior duplicate of edge_flaps.h: + // - unused input parameter V + // - roughly 2x slower than edge_flaps + // - outputs less information: edge_flaps reveals corner opposite edge + // - FE uses non-standard and ambiguous order: FE(f,c) is merely an edge + // incident on corner c of face f. In contrast, edge_flaps's EMAP(f,c) + // reveals the edge _opposite_ corner c of face f +template + IGL_INLINE void edge_topology( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& EV, + Eigen::PlainObjectBase& FE, + Eigen::PlainObjectBase& EF); +} + +#ifndef IGL_STATIC_LIBRARY +# include "edge_topology.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/edge_vectors.cpp b/vendor/libigl/include/igl/edge_vectors.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3807e52ee3f06a135702c40e024770b72a2c88e6 --- /dev/null +++ b/vendor/libigl/include/igl/edge_vectors.cpp @@ -0,0 +1,94 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "edge_vectors.h" + +#include +#include "per_face_normals.h" + +#include "PI.h" + + +template +IGL_INLINE void +igl::edge_vectors( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &E, + const Eigen::MatrixBase &oE, + Eigen::PlainObjectBase &vec) +{ + Eigen::Matrix + dummy; + edge_vectors(V, F, E, oE, vec, dummy); +} + + +template +IGL_INLINE void +igl::edge_vectors( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &E, + const Eigen::MatrixBase &oE, + Eigen::PlainObjectBase &vecParallel, + Eigen::PlainObjectBase &vecPerpendicular) +{ + using Scalar = typename DerivedvecParallel::Scalar; + using MatX = Eigen::Matrix; + + assert(E.rows()==F.rows() && "E does not match dimensions of F."); + assert(oE.rows()==F.rows() && "oE does not match dimensions of F."); + assert(E.cols()==3 && F.cols()==3 && oE.cols()==3 && + "This method is for triangle meshes."); + assert(F.maxCoeff()(0.5*PI, edgeN.row(e)) * + vecParallel.row(e).transpose(); + } + } + } +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::edge_vectors, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/edges.cpp b/vendor/libigl/include/igl/edges.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d8ca5847dcde7bd495605dacf5258739fac2161 --- /dev/null +++ b/vendor/libigl/include/igl/edges.cpp @@ -0,0 +1,71 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "edges.h" +#include "adjacency_matrix.h" +#include + +template +IGL_INLINE void igl::edges( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E) +{ + // build adjacency matrix + typedef typename DerivedF::Scalar Index; + Eigen::SparseMatrix A; + igl::adjacency_matrix(F,A); + igl::edges(A,E); +} + +template +IGL_INLINE void igl::edges( + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & E) +{ + typedef typename DerivedE::Scalar Index; + Eigen::SparseMatrix A; + igl::adjacency_matrix(I,C,A); + igl::edges(A,E); +} + +template +IGL_INLINE void igl::edges( + const Eigen::SparseMatrix & A, + Eigen::PlainObjectBase & E) +{ + // Number of non zeros should be twice number of edges + assert(A.nonZeros()%2 == 0); + // Resize to fit edges + E.resize(A.nonZeros()/2,2); + int i = 0; + // Iterate over outside + for(int k=0; k::InnerIterator it (A,k); it; ++it) + { + // only add edge in one direction + if(it.row(), Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edges, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edges, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::edges, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/edges.h b/vendor/libigl/include/igl/edges.h new file mode 100644 index 0000000000000000000000000000000000000000..72ba75d2bf1dce0f7b6c97929c94fc59a2f3eecb --- /dev/null +++ b/vendor/libigl/include/igl/edges.h @@ -0,0 +1,59 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EDGES_H +#define IGL_EDGES_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Constructs a list of unique edges represented in a given mesh (V,F) + // + // Inputs: + // F #F by 3 list of mesh faces (must be triangles) + // or + // T #T x 4 matrix of indices of tet corners + // Outputs: + // E #E by 2 list of edges in no particular order + // + // See also: adjacency_matrix + template + IGL_INLINE void edges( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E); + // Constructs a list of unique edges represented in a given polygon mesh. + // + // Inputs: + // I #I vectorized list of polygon corner indices into rows of some matrix V + // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = + // size of the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the + // indices of the ith polygon + // Outputs: + // E #E by 2 list of edges in no particular order + template + IGL_INLINE void edges( + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & E); + // Inputs: + // A #V by #V symmetric adjacency matrix + // Outputs: + // E #E by 2 list of edges in no particular order + template + IGL_INLINE void edges( + const Eigen::SparseMatrix & A, + Eigen::PlainObjectBase & E); +} + +#ifndef IGL_STATIC_LIBRARY +# include "edges.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/edges_to_path.cpp b/vendor/libigl/include/igl/edges_to_path.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14cd895bc49e09357d817a2929430b0bf76cba35 --- /dev/null +++ b/vendor/libigl/include/igl/edges_to_path.cpp @@ -0,0 +1,103 @@ +#include "edges_to_path.h" +#include "dfs.h" +#include "sort.h" +#include "slice.h" +#include "ismember.h" +#include "unique.h" +#include "adjacency_list.h" + +template < + typename DerivedE, + typename DerivedI, + typename DerivedJ, + typename DerivedK> +IGL_INLINE void igl::edges_to_path( + const Eigen::MatrixBase & OE, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & J, + Eigen::PlainObjectBase & K) +{ + assert(OE.rows()>=1); + if(OE.rows() == 1) + { + I.resize(2); + I(0) = OE(0); + I(1) = OE(1); + J.resize(1); + J(0) = 0; + K.resize(1); + K(0) = 0; + } + + // Compute on reduced graph + DerivedI U; + Eigen::VectorXi vE; + { + Eigen::VectorXi IA; + unique(OE,U,IA,vE); + } + + Eigen::VectorXi V = Eigen::VectorXi::Zero(vE.maxCoeff()+1); + for(int e = 0;e(vE.data(),OE.rows(),OE.cols()).eval(); + { + std::vector > A; + igl::adjacency_list(E,A); + Eigen::VectorXi P,C; + dfs(A,s,I,P,C); + } + if(c == 2) + { + I.conservativeResize(I.size()+1); + I(I.size()-1) = I(0); + } + + DerivedE sE; + Eigen::Matrix sEI; + { + Eigen::MatrixXi _; + sort(E,2,true,sE,_); + Eigen::Matrix EI(I.size()-1,2); + EI.col(0) = I.head(I.size()-1); + EI.col(1) = I.tail(I.size()-1); + sort(EI,2,true,sEI,_); + } + { + Eigen::Array F; + ismember_rows(sEI,sE,F,J); + } + K.resize(I.size()-1); + for(int k = 0;k, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/eigs.cpp b/vendor/libigl/include/igl/eigs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..766242694d9a57dfbae04f038615bcc7a2a72d9f --- /dev/null +++ b/vendor/libigl/include/igl/eigs.cpp @@ -0,0 +1,173 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "eigs.h" + +#include "cotmatrix.h" +#include "sort.h" +#include "slice.h" +#include "massmatrix.h" +#include + +template < + typename Atype, + typename Btype, + typename DerivedU, + typename DerivedS> +IGL_INLINE bool igl::eigs( + const Eigen::SparseMatrix & A, + const Eigen::SparseMatrix & iB, + const size_t k, + const EigsType type, + Eigen::PlainObjectBase & sU, + Eigen::PlainObjectBase & sS) +{ + using namespace Eigen; + using namespace std; + const size_t n = A.rows(); + assert(A.cols() == n && "A should be square."); + assert(iB.rows() == n && "B should be match A's dims."); + assert(iB.cols() == n && "B should be square."); + assert(type == EIGS_TYPE_SM && "Only low frequencies are supported"); + DerivedU U(n,k); + DerivedS S(k,1); + typedef Atype Scalar; + typedef Eigen::Matrix VectorXS; + // Rescale B for better numerics + const Scalar rescale = std::abs(iB.diagonal().maxCoeff()); + const Eigen::SparseMatrix B = iB/rescale; + + Scalar tol = 1e-4; + Scalar conv = 1e-14; + int max_iter = 100; + int i = 0; + //std::cout<<"start"<0) + { + eff_sigma = 1e-8+std::abs(S(i-1)); + } + // whether to use rayleigh quotient method + bool ray = false; + Scalar err = std::numeric_limits::infinity(); + int iter; + Scalar sigma = std::numeric_limits::infinity(); + VectorXS x; + for(iter = 0;iter0 && !ray) + { + // project-out existing modes + for(int j = 0;j0?1.:-1.; + + Scalar err_prev = err; + err = (A*x-sigma*B*x).array().abs().maxCoeff(); + if(err > solver; + const SparseMatrix C = A-eff_sigma*B+tikhonov*B; + //mw.save(C,"C"); + //mw.save(eff_sigma,"eff_sigma"); + //mw.save(tikhonov,"tikhonov"); + solver.compute(C); + switch(solver.info()) + { + case Eigen::Success: + break; + case Eigen::NumericalIssue: + cerr<<"Error: Numerical issue."<1e-14 || + ((U.leftCols(i).transpose()*B*x).array().abs()<=1e-7).all() + ) + { + //cout<<"Found "<, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::SparseMatrix const&, const size_t, igl::EigsType, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/eigs.h b/vendor/libigl/include/igl/eigs.h new file mode 100644 index 0000000000000000000000000000000000000000..3b376379c1f08acd051f52398aba57a779138177 --- /dev/null +++ b/vendor/libigl/include/igl/eigs.h @@ -0,0 +1,61 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EIGS_H +#define IGL_EIGS_H +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Act like MATLAB's eigs function. Compute the first/last k eigen pairs of + // the generalized eigen value problem: + // + // A u = s B u + // + // Solutions are approximate and sorted. + // + // Ideally one should use ARPACK and the Eigen unsupported ARPACK module. + // This implementation does simple, naive power iterations. + // + // Inputs: + // A #A by #A symmetric matrix + // B #A by #A symmetric positive-definite matrix + // k number of eigen pairs to compute + // type whether to extract from the high or low end + // Outputs: + // sU #A by k list of sorted eigen vectors (descending) + // sS k list of sorted eigen values (descending) + // + // Known issues: + // - only the 'sm' small magnitude eigen values are well supported + // + enum EigsType + { + EIGS_TYPE_SM = 0, + EIGS_TYPE_LM = 1, + NUM_EIGS_TYPES = 2 + }; + template < + typename Atype, + typename Btype, + typename DerivedU, + typename DerivedS> + IGL_INLINE bool eigs( + const Eigen::SparseMatrix & A, + const Eigen::SparseMatrix & B, + const size_t k, + const EigsType type, + Eigen::PlainObjectBase & sU, + Eigen::PlainObjectBase & sS); +} + +#ifndef IGL_STATIC_LIBRARY +#include "eigs.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/euler_characteristic.cpp b/vendor/libigl/include/igl/euler_characteristic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3ca6303b27de5766c8c6a8fae0ac9867d5aa620 --- /dev/null +++ b/vendor/libigl/include/igl/euler_characteristic.cpp @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "euler_characteristic.h" + +#include "edge_topology.h" +#include "edges.h" + +template +IGL_INLINE int igl::euler_characteristic( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F) +{ + + int euler_v = V.rows(); + Eigen::MatrixXi EV, FE, EF; + igl::edge_topology(V, F, EV, FE, EF); + int euler_e = EV.rows(); + int euler_f = F.rows(); + + int euler_char = euler_v - euler_e + euler_f; + return euler_char; + +} + +template +IGL_INLINE int igl::euler_characteristic( + const Eigen::MatrixBase & F) +{ + const int nf = F.rows(); + const int nv = F.maxCoeff()+1; + Eigen::Matrix E; + edges(F,E); + const int ne = E.rows(); + return nv - ne + nf; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template int igl::euler_characteristic, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template int igl::euler_characteristic >(Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/example_fun.cpp b/vendor/libigl/include/igl/example_fun.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9796c68e35741d3049ad62bc6c3bfe284890cbc2 --- /dev/null +++ b/vendor/libigl/include/igl/example_fun.cpp @@ -0,0 +1,23 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "example_fun.h" +#include + +template +IGL_INLINE bool igl::example_fun(const Printable & input) +{ + using namespace std; + cout<<"example_fun: "<(const double& input); +template bool igl::example_fun(const int& input); +#endif diff --git a/vendor/libigl/include/igl/exploded_view.cpp b/vendor/libigl/include/igl/exploded_view.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d23b6162c1c50e1fe98525c3f8668948f180cc70 --- /dev/null +++ b/vendor/libigl/include/igl/exploded_view.cpp @@ -0,0 +1,70 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "exploded_view.h" +#include "barycenter.h" +#include "volume.h" + +template < + typename DerivedV, + typename DerivedT, + typename DerivedEV, + typename DerivedEF, + typename DerivedI, + typename DerivedJ> +IGL_INLINE void igl::exploded_view( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & T, + const typename DerivedV::Scalar s, + const typename DerivedV::Scalar t, + Eigen::PlainObjectBase & EV, + Eigen::PlainObjectBase & EF, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & J) +{ + assert(T.cols() == 4 && "T should be a tet mesh"); + EV.resize(4*T.rows(),3); + EF.resize(4*T.rows(),3); + I.resize(EV.rows()); + J.resize(EF.rows()); + Eigen::MatrixXd BC; + igl::barycenter(V,T,BC); + Eigen::VectorXd vol; + igl::volume(V,T,vol); + const Eigen::RowVectorXd c = vol.transpose()*BC/vol.array().sum(); + for(int i = 0;i, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/exploded_view.h b/vendor/libigl/include/igl/exploded_view.h new file mode 100644 index 0000000000000000000000000000000000000000..e925404bb4ef3fd7347f7d2edb6aa629fe50db28 --- /dev/null +++ b/vendor/libigl/include/igl/exploded_view.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EXPLODED_VIEW_H +#define IGL_EXPLODED_VIEW_H +#include "igl_inline.h" +#include +namespace igl +{ + // Given a tet-mesh, create a trivial surface mesh (4 triangles per tet) with + // each tet scaled individually and translated outward from the mesh's + // centroid, creating an exploded-view visualization. + // + // Inputs: + // V #V by 3 list of tet mesh vertex positions + // T #T by 4 list of tet mesh indices into rows of V + // s amount to scale each tet indvidually, typically (0,1] + // t amount to scale away from mesh's centroid, typically >=1 + // Outputs: + // EV #T*4 by 3 list of output mesh vertex positions + // EF #T*4 by 3 list of output triangle indices into rows of EV + // I #EV list of indices into V revealing birth parent + // J #EF list of indices into F revealing birth parent + template < + typename DerivedV, + typename DerivedT, + typename DerivedEV, + typename DerivedEF, + typename DerivedI, + typename DerivedJ> + IGL_INLINE void exploded_view( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & T, + const typename DerivedV::Scalar s, + const typename DerivedV::Scalar t, + Eigen::PlainObjectBase & EV, + Eigen::PlainObjectBase & EF, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & J); +} + +#ifndef IGL_STATIC_LIBRARY +# include "exploded_view.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/exterior_edges.cpp b/vendor/libigl/include/igl/exterior_edges.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04c1e9b8adc6591d62ba1116a40db3f8419741c5 --- /dev/null +++ b/vendor/libigl/include/igl/exterior_edges.cpp @@ -0,0 +1,106 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "exterior_edges.h" +#include "oriented_facets.h" +#include "sort.h" +#include "unique_rows.h" + +#include +#include +#include +#include + +//template inline int sgn(T val) { +// return (T(0) < val) - (val < T(0)); +//} + +//static void mod2(std::pair, int>& p) +//{ +// using namespace std; +// // Be sure that sign of mod matches sign of argument +// p.second = p.second%2 ? sgn(p.second) : 0; +//} + +//// http://stackoverflow.com/a/5517869/148668 +//struct Compare +//{ +// int i; +// Compare(const int& i) : i(i) {} +//}; +//bool operator==(const std::pair,int>&p, const Compare& c) +//{ +// return c.i == p.second; +//} +//bool operator==(const Compare& c, const std::pair, int> &p) +//{ +// return c.i == p.second; +//} + +IGL_INLINE void igl::exterior_edges( + const Eigen::MatrixXi & F, + Eigen::MatrixXi & E) +{ + using namespace Eigen; + using namespace std; + assert(F.cols() == 3); + const size_t m = F.rows(); + MatrixXi all_E,sall_E,sort_order; + // Sort each edge by index + oriented_facets(F,all_E); + sort(all_E,2,true,sall_E,sort_order); + // Find unique edges + MatrixXi uE; + VectorXi IA,EMAP; + unique_rows(sall_E,uE,IA,EMAP); + VectorXi counts = VectorXi::Zero(uE.rows()); + for(size_t a = 0;a<3*m;a++) + { + counts(EMAP(a)) += (sort_order(a)==0?1:-1); + } + + E.resize(all_E.rows(),2); + { + int e = 0; + const size_t nue = uE.rows(); + // Append each unique edge with a non-zero amount of signed occurrences + for(size_t ue = 0; ue 0) + { + i = uE(ue,0); + j = uE(ue,1); + } + // Append edge for every repeated entry + const int abs_count = abs(count); + for(int k = 0;k +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EXTERIOR_EDGES_H +#define IGL_EXTERIOR_EDGES_H +#include "igl_inline.h" +#include +namespace igl +{ + // EXTERIOR_EDGES Determines boundary "edges" and also edges with an + // odd number of occurrences where seeing edge (i,j) counts as +1 and seeing + // the opposite edge (j,i) counts as -1 + // + // Inputs: + // F #F by simplex_size list of "faces" + // Outputs: + // E #E by simplex_size-1 list of exterior edges + // + IGL_INLINE void exterior_edges( + const Eigen::MatrixXi & F, + Eigen::MatrixXi & E); + // Inline version + IGL_INLINE Eigen::MatrixXi exterior_edges( const Eigen::MatrixXi & F); +} +#ifndef IGL_STATIC_LIBRARY +# include "exterior_edges.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/extract_manifold_patches.cpp b/vendor/libigl/include/igl/extract_manifold_patches.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10763f8d59b7d032bc7fbfb8ab4488b492f30c93 --- /dev/null +++ b/vendor/libigl/include/igl/extract_manifold_patches.cpp @@ -0,0 +1,103 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "extract_manifold_patches.h" +#include "unique_edge_map.h" +#include +#include +#include + +template< + typename DerivedF, + typename DerivedEMAP, + typename uE2EType, + typename DerivedP> +IGL_INLINE size_t igl::extract_manifold_patches( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& EMAP, + const std::vector >& uE2E, + Eigen::PlainObjectBase& P) +{ + assert(F.cols() == 3); + const size_t num_faces = F.rows(); + + auto edge_index_to_face_index = [&](size_t ei) { return ei % num_faces; }; + auto face_and_corner_index_to_edge_index = [&](size_t fi, size_t ci) { + return ci*num_faces + fi; + }; + auto is_manifold_edge = [&](size_t fi, size_t ci) -> bool { + const size_t ei = face_and_corner_index_to_edge_index(fi, ci); + return uE2E[EMAP(ei, 0)].size() == 2; + }; + auto get_adj_face_index = [&](size_t fi, size_t ci) -> size_t { + const size_t ei = face_and_corner_index_to_edge_index(fi, ci); + const auto& adj_faces = uE2E[EMAP(ei, 0)]; + assert(adj_faces.size() == 2); + if (adj_faces[0] == ei) { + return edge_index_to_face_index(adj_faces[1]); + } else { + assert(adj_faces[1] == ei); + return edge_index_to_face_index(adj_faces[0]); + } + }; + + typedef typename DerivedP::Scalar Scalar; + const Scalar INVALID = std::numeric_limits::max(); + P.resize(num_faces,1); + P.setConstant(INVALID); + size_t num_patches = 0; + for (size_t i=0; i Q; + Q.push(i); + P(i,0) = num_patches; + while (!Q.empty()) { + const size_t fid = Q.front(); + Q.pop(); + for (size_t j=0; j<3; j++) { + if (is_manifold_edge(fid, j)) { + const size_t adj_fid = get_adj_face_index(fid, j); + if (P(adj_fid,0) == INVALID) { + Q.push(adj_fid); + P(adj_fid,0) = num_patches; + } + } + } + } + num_patches++; + } + assert((P.array() != INVALID).all()); + + return num_patches; +} + +template < + typename DerivedF, + typename DerivedP> +IGL_INLINE size_t igl::extract_manifold_patches( + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &P) +{ + Eigen::MatrixXi E, uE; + Eigen::VectorXi EMAP; + std::vector > uE2E; + igl::unique_edge_map(F, E, uE, EMAP, uE2E); + return igl::extract_manifold_patches(F, EMAP, uE2E, P); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template size_t igl::extract_manifold_patches, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template size_t igl::extract_manifold_patches, Eigen::Matrix, unsigned long, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template size_t igl::extract_manifold_patches, Eigen::Matrix, unsigned long, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template unsigned __int64 igl::extract_manifold_patches, class Eigen::Matrix, unsigned __int64, class Eigen::Matrix>(class Eigen::MatrixBase> const &, class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>> const &, class Eigen::PlainObjectBase> &); +template unsigned __int64 igl::extract_manifold_patches, class Eigen::Matrix, unsigned __int64, class Eigen::Matrix>(class Eigen::MatrixBase> const &, class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>> const &, class Eigen::PlainObjectBase> &); +#endif +#endif diff --git a/vendor/libigl/include/igl/extract_manifold_patches.h b/vendor/libigl/include/igl/extract_manifold_patches.h new file mode 100644 index 0000000000000000000000000000000000000000..c9467014bd3a4fe6dec1346071e575473bb6c95f --- /dev/null +++ b/vendor/libigl/include/igl/extract_manifold_patches.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_EXTRACT_MANIFOLD_PATCHES +#define IGL_EXTRACT_MANIFOLD_PATCHES + +#include "igl_inline.h" +#include +#include + +namespace igl { + // Extract a set of maximal patches from a given mesh. + // A maximal patch is a subset of the input faces that are connected via + // manifold edges; a patch is as large as possible. + // + // Inputs: + // F #F by 3 list representing triangles. + // EMAP #F*3 list of indices of unique undirected edges. + // uE2E #uE list of lists of indices into E of coexisting edges. + // + // Output: + // P #F list of patch incides. + // + // Returns: + // number of manifold patches. + template < + typename DerivedF, + typename DerivedEMAP, + typename uE2EType, + typename DerivedP> + IGL_INLINE size_t extract_manifold_patches( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& EMAP, + const std::vector >& uE2E, + Eigen::PlainObjectBase& P); + template < + typename DerivedF, + typename DerivedP> + IGL_INLINE size_t extract_manifold_patches( + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &P); +} +#ifndef IGL_STATIC_LIBRARY +# include "extract_manifold_patches.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/extract_non_manifold_edge_curves.cpp b/vendor/libigl/include/igl/extract_non_manifold_edge_curves.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4bcbed470c28f324648c0610c2daf08d780ed8f1 --- /dev/null +++ b/vendor/libigl/include/igl/extract_non_manifold_edge_curves.cpp @@ -0,0 +1,123 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "extract_non_manifold_edge_curves.h" +#include +#include +#include +#include +#include + +template< +typename DerivedF, +typename DerivedEMAP, +typename uE2EType > +IGL_INLINE void igl::extract_non_manifold_edge_curves( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& /*EMAP*/, + const std::vector >& uE2E, + std::vector >& curves) { + const size_t num_faces = F.rows(); + assert(F.cols() == 3); + //typedef std::pair Edge; + auto edge_index_to_face_index = [&](size_t ei) { return ei % num_faces; }; + auto edge_index_to_corner_index = [&](size_t ei) { return ei / num_faces; }; + auto get_edge_end_points = [&](size_t ei, size_t& s, size_t& d) { + const size_t fi = edge_index_to_face_index(ei); + const size_t ci = edge_index_to_corner_index(ei); + s = F(fi, (ci+1)%3); + d = F(fi, (ci+2)%3); + }; + + curves.clear(); + const size_t num_unique_edges = uE2E.size(); + std::unordered_multimap vertex_edge_adjacency; + std::vector non_manifold_edges; + for (size_t i=0; i 0); + assert(vertex_edge_adjacency.count(d) > 0); + } + + auto expand_forward = [&](std::list& edge_curve, + size_t& front_vertex, size_t& end_vertex) { + while(vertex_edge_adjacency.count(front_vertex) == 2 && + front_vertex != end_vertex) { + auto adj_edges = vertex_edge_adjacency.equal_range(front_vertex); + for (auto itr = adj_edges.first; itr!=adj_edges.second; itr++) { + const size_t uei = itr->second; + assert(uE2E.at(uei).size() != 2); + const size_t ei = uE2E[uei][0]; + if (uei == edge_curve.back()) continue; + size_t s,d; + get_edge_end_points(ei, s, d); + edge_curve.push_back(uei); + if (s == front_vertex) { + front_vertex = d; + } else if (d == front_vertex) { + front_vertex = s; + } else { + throw "Invalid vertex/edge adjacency!"; + } + break; + } + } + }; + + auto expand_backward = [&](std::list& edge_curve, + size_t& front_vertex, size_t& end_vertex) { + while(vertex_edge_adjacency.count(front_vertex) == 2 && + front_vertex != end_vertex) { + auto adj_edges = vertex_edge_adjacency.equal_range(front_vertex); + for (auto itr = adj_edges.first; itr!=adj_edges.second; itr++) { + const size_t uei = itr->second; + assert(uE2E.at(uei).size() != 2); + const size_t ei = uE2E[uei][0]; + if (uei == edge_curve.front()) continue; + size_t s,d; + get_edge_end_points(ei, s, d); + edge_curve.push_front(uei); + if (s == front_vertex) { + front_vertex = d; + } else if (d == front_vertex) { + front_vertex = s; + } else { + throw "Invalid vertex/edge adjcency!"; + } + break; + } + } + }; + + std::vector visited(num_unique_edges, false); + for (const size_t i : non_manifold_edges) { + if (visited[i]) continue; + std::list edge_curve; + edge_curve.push_back(i); + + const auto& adj_edges = uE2E[i]; + assert(adj_edges.size() != 2); + const size_t ei = adj_edges[0]; + size_t s,d; + get_edge_end_points(ei, s, d); + + expand_forward(edge_curve, d, s); + expand_backward(edge_curve, s, d); + curves.emplace_back(edge_curve.begin(), edge_curve.end()); + for (auto itr = edge_curve.begin(); itr!=edge_curve.end(); itr++) { + visited[*itr] = true; + } + } + +} diff --git a/vendor/libigl/include/igl/extract_non_manifold_edge_curves.h b/vendor/libigl/include/igl/extract_non_manifold_edge_curves.h new file mode 100644 index 0000000000000000000000000000000000000000..c8ddbec72cc475c5ea68d87563f6004217e00b55 --- /dev/null +++ b/vendor/libigl/include/igl/extract_non_manifold_edge_curves.h @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_NON_MANIFOLD_EDGE_CURVES +#define IGL_NON_MANIFOLD_EDGE_CURVES + +#include "igl_inline.h" +#include +#include + +namespace igl { + // Extract non-manifold curves from a given mesh. + // A non-manifold curves are a set of connected non-manifold edges that + // does not touch other non-manifold edges except at the end points. + // They are also maximal in the sense that they cannot be expanded by + // including more edges. + // + // Assumes the input mesh have all self-intersection resolved. See + // ``igl::cgal::remesh_self_intersection`` for more details. + // + // Inputs: + // F #F by 3 list representing triangles. + // EMAP #F*3 list of indices of unique undirected edges. + // uE2E #uE list of lists of indices into E of coexisting edges. + // + // Output: + // curves An array of arries of unique edge indices. + template< + typename DerivedF, + typename DerivedEMAP, + typename uE2EType> + IGL_INLINE void extract_non_manifold_edge_curves( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& EMAP, + const std::vector >& uE2E, + std::vector >& curves); +} + +#ifndef IGL_STATIC_LIBRARY +# include "extract_non_manifold_edge_curves.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/face_areas.cpp b/vendor/libigl/include/igl/face_areas.cpp new file mode 100644 index 0000000000000000000000000000000000000000..74bf7fce049a7c293fb19d1371c96e2216b9e9bb --- /dev/null +++ b/vendor/libigl/include/igl/face_areas.cpp @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "face_areas.h" +#include "edge_lengths.h" +#include "doublearea.h" + +template +IGL_INLINE void igl::face_areas( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& A) +{ + assert(T.cols() == 4); + DerivedA L; + edge_lengths(V,T,L); + return face_areas(L,A); +} + +template +IGL_INLINE void igl::face_areas( + const Eigen::MatrixBase& L, + Eigen::PlainObjectBase& A) +{ + return face_areas( + L,std::numeric_limits::quiet_NaN(),A); +} + +template +IGL_INLINE void igl::face_areas( + const Eigen::MatrixBase& L, + const typename DerivedL::Scalar doublearea_nan_replacement, + Eigen::PlainObjectBase& A) +{ + using namespace Eigen; + assert(L.cols() == 6); + const int m = L.rows(); + // (unsigned) face Areas (opposite vertices: 1 2 3 4) + Matrix + A0(m,1), A1(m,1), A2(m,1), A3(m,1); + Matrix + L0(m,3), L1(m,3), L2(m,3), L3(m,3); + L0<, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/face_areas.h b/vendor/libigl/include/igl/face_areas.h new file mode 100644 index 0000000000000000000000000000000000000000..9676deadc4235e774814a15cfa231eb40f3b6a61 --- /dev/null +++ b/vendor/libigl/include/igl/face_areas.h @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FACE_AREAS_H +#define IGL_FACE_AREAS_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Constructs a list of face areas of faces opposite each index in a tet list + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // T #T by 3 list of tet mesh indices into V + // Outputs: + // A #T by 4 list of face areas corresponding to faces opposite vertices + // 0,1,2,3 + // + template + IGL_INLINE void face_areas( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& A); + // Compute tet-mesh face areas from edge lengths. + // + // Inputs: + // L #T by 6 list of tet-mesh edge lengths corresponding to edges + // [3 0],[3 1],[3 2],[1 2],[2 0],[0 1] + // Outputs: + // A #T by 4 list of face areas corresponding to faces opposite vertices + // 0,1,2,3: i.e. made of edges [123],[024],[015],[345] + // + // + template + IGL_INLINE void face_areas( + const Eigen::MatrixBase& L, + Eigen::PlainObjectBase& A); + // doublearea_nan_replacement See doublearea.h + template + IGL_INLINE void face_areas( + const Eigen::MatrixBase& L, + const typename DerivedL::Scalar doublearea_nan_replacement, + Eigen::PlainObjectBase& A); +} + +#ifndef IGL_STATIC_LIBRARY +# include "face_areas.cpp" +#endif + +#endif + + diff --git a/vendor/libigl/include/igl/faces_first.cpp b/vendor/libigl/include/igl/faces_first.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c0fa0d0b7a12a962ba821bfcc56d5fa6ef3a358 --- /dev/null +++ b/vendor/libigl/include/igl/faces_first.cpp @@ -0,0 +1,103 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "faces_first.h" + +#include +#include + +template +IGL_INLINE void igl::faces_first( + const MatV & V, + const MatF & F, + MatV & RV, + MatF & RF, + VecI & IM) +{ + assert(&V != &RV); + assert(&F != &RF); + using namespace std; + using namespace Eigen; + vector in_face(V.rows()); + for(int i = 0; i +IGL_INLINE void igl::faces_first( + MatV & V, + MatF & F, + VecI & IM) +{ + MatV RV; + // Copying F may not be needed, seems RF = F is safe (whereas RV = V is not) + MatF RF; + igl::faces_first(V,F,RV,RF,IM); + V = RV; + F = RF; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::faces_first, Eigen::Matrix, Eigen::Matrix >(Eigen::Matrix&, Eigen::Matrix&, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/faces_first.h b/vendor/libigl/include/igl/faces_first.h new file mode 100644 index 0000000000000000000000000000000000000000..92d1d5565dd83f2b10669a68c4305ce08b519f4b --- /dev/null +++ b/vendor/libigl/include/igl/faces_first.h @@ -0,0 +1,60 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FACES_FIRST_H +#define IGL_FACES_FIRST_H +#include "igl_inline.h" +namespace igl +{ + // FACES_FIRST Reorder vertices so that vertices in face list come before + // vertices that don't appear in the face list. This is especially useful if + // the face list contains only surface faces and you want surface vertices + // listed before internal vertices + // + // [RV,RT,RF,IM] = faces_first(V,T,F); + // + // Templates: + // MatV matrix for vertex positions, e.g. MatrixXd + // MatF matrix for face indices, e.g. MatrixXi + // VecI vector for index map, e.g. VectorXi + // Input: + // V # vertices by 3 vertex positions + // F # faces by 3 list of face indices + // Output: + // RV # vertices by 3 vertex positions, order such that if the jth vertex is + // some face in F, and the kth vertex is not then j comes before k + // RF # faces by 3 list of face indices, reindexed to use RV + // IM #V by 1 list of indices such that: RF = IM(F) and RT = IM(T) + // and RV(IM,:) = V + // + // + // Example: + // // Tet mesh in (V,T,F) + // faces_first(V,F,IM); + // T = T.unaryExpr(bind1st(mem_fun( static_cast(&VectorXi::operator())), + // &IM)).eval(); + template + IGL_INLINE void faces_first( + const MatV & V, + const MatF & F, + MatV & RV, + MatF & RF, + VecI & IM); + // Virtual "in place" wrapper + template + IGL_INLINE void faces_first( + MatV & V, + MatF & F, + VecI & IM); +} + +#ifndef IGL_STATIC_LIBRARY +# include "faces_first.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/facet_adjacency_matrix.h b/vendor/libigl/include/igl/facet_adjacency_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..4f258ccd583f1284c72041ad42f2439f99e4bf93 --- /dev/null +++ b/vendor/libigl/include/igl/facet_adjacency_matrix.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FACET_ADJACENCY_MATRIX_H +#define IGL_FACET_ADJACENCY_MATRIX_H +#include +#include +#include "igl_inline.h" + +namespace igl +{ + // Construct a #F×#F adjacency matrix with A(i,j)>0 indicating that faces i and j + // share an edge. + // + // Inputs: + // F #F by 3 list of facets + // Outputs: + // A #F by #F adjacency matrix + template + IGL_INLINE void facet_adjacency_matrix( + const Eigen::MatrixBase & F, + Eigen::SparseMatrix & A); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "facet_adjacency_matrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/facet_components.cpp b/vendor/libigl/include/igl/facet_components.cpp new file mode 100644 index 0000000000000000000000000000000000000000..922a330f860e61e8d9a9811e5e2e9b974a67ccc8 --- /dev/null +++ b/vendor/libigl/include/igl/facet_components.cpp @@ -0,0 +1,98 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "facet_components.h" +#include "triangle_triangle_adjacency.h" +#include "facet_adjacency_matrix.h" +#include "connected_components.h" +#include +#include + +template +IGL_INLINE int igl::facet_components( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & C) +{ + typedef typename DerivedF::Scalar Index; + Eigen::SparseMatrix A; + igl::facet_adjacency_matrix(F,A); + Eigen::Matrix counts; + C = DerivedC::Zero(1,1); + return connected_components(A,C,counts); +} + +template < + typename TTIndex, + typename DerivedC, + typename Derivedcounts> +IGL_INLINE void igl::facet_components( + const std::vector > > & TT, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & counts) +{ + using namespace std; + typedef TTIndex Index; + const Index m = TT.size(); + C.resize(m,1); + vector seen(m,false); + Index id = 0; + vector vcounts; + for(Index g = 0;g Q; + Q.push(g); + while(!Q.empty()) + { + const Index f = Q.front(); + Q.pop(); + if(seen[f]) + { + continue; + } + seen[f] = true; + vcounts[id]++; + C(f,0) = id; + // Face f's neighbor lists opposite opposite each corner + for(const auto & c : TT[f]) + { + // Each neighbor + for(const auto & n : c) + { + if(!seen[n]) + { + Q.push(n); + } + } + } + } + id++; + } + assert((size_t) id == vcounts.size()); + const size_t ncc = vcounts.size(); + assert((size_t)C.maxCoeff()+1 == ncc); + counts.resize(ncc,1); + for(size_t i = 0;i, Eigen::Matrix >(std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::facet_components, Eigen::Matrix >(std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template int igl::facet_components, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template void igl::facet_components<__int64,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class std::vector >,class std::allocator > > >,class std::allocator >,class std::allocator > > > > > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/false_barycentric_subdivision.cpp b/vendor/libigl/include/igl/false_barycentric_subdivision.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ea807a505d5a1496effa175a63a0fb11f79bece --- /dev/null +++ b/vendor/libigl/include/igl/false_barycentric_subdivision.cpp @@ -0,0 +1,59 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "false_barycentric_subdivision.h" + +#include "verbose.h" +#include +#include + +template +IGL_INLINE void igl::false_barycentric_subdivision( + const Eigen::PlainObjectBase & V, + const Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & VD, + Eigen::PlainObjectBase & FD) +{ + using namespace Eigen; + // Compute face barycenter + Eigen::MatrixXd BC; + igl::barycenter(V,F,BC); + + // Add the barycenters to the vertices + VD.resize(V.rows()+F.rows(),3); + VD.block(0,0,V.rows(),3) = V; + VD.block(V.rows(),0,F.rows(),3) = BC; + + // Each face is split four ways + FD.resize(F.rows()*3,3); + + for (unsigned i=0; i, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::false_barycentric_subdivision, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/false_barycentric_subdivision.h b/vendor/libigl/include/igl/false_barycentric_subdivision.h new file mode 100644 index 0000000000000000000000000000000000000000..98426b57253363add5fcfddde3b2d0e133caff4d --- /dev/null +++ b/vendor/libigl/include/igl/false_barycentric_subdivision.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ADD_BARYCENTER_H +#define IGL_ADD_BARYCENTER_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Refine the mesh by adding the barycenter of each face + // Inputs: + // V #V by 3 coordinates of the vertices + // F #F by 3 list of mesh faces (must be triangles) + // Outputs: + // VD #V + #F by 3 coordinate of the vertices of the dual mesh + // The added vertices are added at the end of VD (should not be + // same references as (V,F) + // FD #F*3 by 3 faces of the dual mesh + // + template + IGL_INLINE void false_barycentric_subdivision( + const Eigen::PlainObjectBase & V, + const Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & VD, + Eigen::PlainObjectBase & FD); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "false_barycentric_subdivision.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/fast_winding_number.cpp b/vendor/libigl/include/igl/fast_winding_number.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d23489b04a1c67cd524a5e7208027dd8074d043 --- /dev/null +++ b/vendor/libigl/include/igl/fast_winding_number.cpp @@ -0,0 +1,483 @@ +#include "fast_winding_number.h" +#include "octree.h" +#include "parallel_for.h" +#include "PI.h" +#include +#include + +template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename Index, + typename DerivedCH, + typename DerivedCM, + typename DerivedR, + typename DerivedEC> +IGL_INLINE void igl::fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const std::vector > & point_indices, + const Eigen::MatrixBase& CH, + const int expansion_order, + Eigen::PlainObjectBase& CM, + Eigen::PlainObjectBase& R, + Eigen::PlainObjectBase& EC) +{ + typedef typename DerivedP::Scalar real_p; + typedef typename DerivedN::Scalar real_n; + typedef typename DerivedA::Scalar real_a; + typedef typename DerivedCM::Scalar real_cm; + typedef typename DerivedR::Scalar real_r; + typedef typename DerivedEC::Scalar real_ec; + + typedef Eigen::Matrix RowVec3p; + + int m = CH.size(); + int num_terms; + + assert(expansion_order < 3 && expansion_order >= 0 && "m must be less than n"); + if(expansion_order == 0){ + num_terms = 3; + } else if(expansion_order ==1){ + num_terms = 3 + 9; + } else if(expansion_order == 2){ + num_terms = 3 + 9 + 27; + } + + R.resize(m); + CM.resize(m,3); + EC.resize(m,num_terms); + EC.setZero(m,num_terms); + std::function< void(const int) > helper; + helper = [&helper, + &P,&N,&A,&expansion_order,&point_indices,&CH,&EC,&R,&CM] + (const int index)-> void + { + Eigen::Matrix masscenter; + masscenter << 0,0,0; + Eigen::Matrix zeroth_expansion; + zeroth_expansion << 0,0,0; + real_p areatotal = 0.0; + for(int j = 0; j < point_indices[index].size(); j++){ + int curr_point_index = point_indices[index][j]; + + areatotal += A(curr_point_index); + masscenter += A(curr_point_index)*P.row(curr_point_index); + zeroth_expansion += A(curr_point_index)*N.row(curr_point_index); + } + + masscenter = masscenter/areatotal; + CM.row(index) = masscenter; + EC.block(index,0,1,3) = zeroth_expansion; + + real_r max_norm = 0; + real_r curr_norm; + + for(int i = 0; i < point_indices[index].size(); i++){ + //Get max distance from center of mass: + int curr_point_index = point_indices[index][i]; + Eigen::Matrix point = + P.row(curr_point_index)-masscenter; + curr_norm = point.norm(); + if(curr_norm > max_norm){ + max_norm = curr_norm; + } + + //Calculate higher order terms if necessary + Eigen::Matrix TempCoeffs; + if(EC.cols() >= (3+9)){ + TempCoeffs = A(curr_point_index)*point.transpose()* + N.row(curr_point_index); + EC.block(index,3,1,9) += + Eigen::Map >(TempCoeffs.data(), + TempCoeffs.size()); + } + + if(EC.cols() == (3+9+27)){ + for(int k = 0; k < 3; k++){ + TempCoeffs = 0.5 * point(k) * (A(curr_point_index)* + point.transpose()*N.row(curr_point_index)); + EC.block(index,12+9*k,1,9) += Eigen::Map< + Eigen::Matrix >(TempCoeffs.data(), + TempCoeffs.size()); + } + } + } + + R(index) = max_norm; + if(CH(index,0) != -1) + { + for(int i = 0; i < 8; i++){ + int child = CH(index,i); + helper(child); + } + } + }; + helper(0); +} + +template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename Index, + typename DerivedCH, + typename DerivedCM, + typename DerivedR, + typename DerivedEC, + typename DerivedQ, + typename BetaType, + typename DerivedWN> +IGL_INLINE void igl::fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const std::vector > & point_indices, + const Eigen::MatrixBase& CH, + const Eigen::MatrixBase& CM, + const Eigen::MatrixBase& R, + const Eigen::MatrixBase& EC, + const Eigen::MatrixBase& Q, + const BetaType beta, + Eigen::PlainObjectBase& WN) +{ + + typedef typename DerivedP::Scalar real_p; + typedef typename DerivedN::Scalar real_n; + typedef typename DerivedA::Scalar real_a; + typedef typename DerivedCM::Scalar real_cm; + typedef typename DerivedR::Scalar real_r; + typedef typename DerivedEC::Scalar real_ec; + typedef typename DerivedQ::Scalar real_q; + typedef typename DerivedWN::Scalar real_wn; + const real_wn PI_4 = 4.0*igl::PI; + + typedef Eigen::Matrix< + typename DerivedEC::Scalar, + 1, + DerivedEC::ColsAtCompileTime> ECRow; + + typedef Eigen::Matrix RowVec; + typedef Eigen::Matrix EC_3by3; + + auto direct_eval = [&PI_4]( + const RowVec & loc, + const Eigen::Matrix & anorm)->real_wn + { + const typename RowVec::Scalar loc_norm = loc.norm(); + if(loc_norm == 0) + { + return 0.5; + }else + { + return (loc(0)*anorm(0)+loc(1)*anorm(1)+loc(2)*anorm(2)) + /(PI_4*(loc_norm*loc_norm*loc_norm)); + } + }; + + auto expansion_eval = + [&direct_eval,&EC,&PI_4]( + const RowVec & loc, + const int & child_index)->real_wn + { + real_wn wn; + wn = direct_eval(loc,EC.row(child_index).template head<3>()); + real_wn r = loc.norm(); + real_wn PI_4_r3; + real_wn PI_4_r5; + real_wn PI_4_r7; + if(EC.row(child_index).size()>3) + { + PI_4_r3 = PI_4*r*r*r; + PI_4_r5 = PI_4_r3*r*r; + const real_ec d = 1.0/(PI_4_r3); + Eigen::Matrix SecondDerivative = + loc.transpose()*loc*(-3.0/(PI_4_r5)); + SecondDerivative(0,0) += d; + SecondDerivative(1,1) += d; + SecondDerivative(2,2) += d; + wn += + Eigen::Map >( + SecondDerivative.data(), + SecondDerivative.size()).dot( + EC.row(child_index).template segment<9>(3)); + } + if(EC.row(child_index).size()>3+9) + { + PI_4_r7 = PI_4_r5*r*r; + const Eigen::Matrix locTloc = loc.transpose()*(loc/(PI_4_r7)); + for(int i = 0; i < 3; i++) + { + Eigen::Matrix RowCol_Diagonal = + Eigen::Matrix::Zero(3,3); + for(int u = 0;u<3;u++) + { + for(int v = 0;v<3;v++) + { + if(u==v) RowCol_Diagonal(u,v) += loc(i); + if(u==i) RowCol_Diagonal(u,v) += loc(v); + if(v==i) RowCol_Diagonal(u,v) += loc(u); + } + } + Eigen::Matrix ThirdDerivative = + 15.0*loc(i)*locTloc + (-3.0/(PI_4_r5))*(RowCol_Diagonal); + + wn += Eigen::Map >( + ThirdDerivative.data(), + ThirdDerivative.size()).dot( + EC.row(child_index).template segment<9>(12 + i*9)); + } + } + return wn; + }; + + int m = Q.rows(); + WN.resize(m,1); + + std::function< real_wn(const RowVec & , const std::vector &) > helper; + helper = [&helper, + &P,&N,&A, + &point_indices,&CH, + &CM,&R,&EC,&beta, + &direct_eval,&expansion_eval] + (const RowVec & query, const std::vector & near_indices)-> real_wn + { + real_wn wn = 0; + std::vector new_near_indices; + new_near_indices.reserve(8); + for(int i = 0; i < near_indices.size(); i++) + { + int index = near_indices[i]; + //Leaf Case, Brute force + if(CH(index,0) == -1) + { + for(int j = 0; j < point_indices[index].size(); j++) + { + int curr_row = point_indices[index][j]; + wn += direct_eval(P.row(curr_row)-query, + N.row(curr_row)*A(curr_row)); + } + } + //Non-Leaf Case + else + { + for(int child = 0; child < 8; child++) + { + int child_index = CH(index,child); + if(point_indices[child_index].size() > 0) + { + const RowVec CMciq = (CM.row(child_index)-query); + if(CMciq.norm() > beta*R(child_index)) + { + if(CH(child_index,0) == -1) + { + for(int j=0;j 0) + { + wn += helper(query,new_near_indices); + } + return wn; + }; + + if(beta > 0) + { + const std::vector near_indices_start = {0}; + igl::parallel_for(m,[&](int iter){ + WN(iter) = helper(Q.row(iter).eval(),near_indices_start); + },1000); + } else + { + igl::parallel_for(m,[&](int iter){ + double wn = 0; + for(int j = 0; j +IGL_INLINE void igl::fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const Eigen::MatrixBase& Q, + const int expansion_order, + const BetaType beta, + Eigen::PlainObjectBase& WN) +{ + typedef typename DerivedWN::Scalar real; + + std::vector > point_indices; + Eigen::Matrix CH; + Eigen::Matrix CN; + Eigen::Matrix W; + + octree(P,point_indices,CH,CN,W); + + Eigen::Matrix EC; + Eigen::Matrix CM; + Eigen::Matrix R; + + fast_winding_number(P,N,A,point_indices,CH,expansion_order,CM,R,EC); + fast_winding_number(P,N,A,point_indices,CH,CM,R,EC,Q,beta,WN); +} + +template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename DerivedQ, + typename DerivedWN> +IGL_INLINE void igl::fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const Eigen::MatrixBase& Q, + Eigen::PlainObjectBase& WN) +{ + fast_winding_number(P,N,A,Q,2,2.0,WN); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedQ, + typename DerivedW> +IGL_INLINE void igl::fast_winding_number( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & Q, + Eigen::PlainObjectBase & W) +{ + igl::FastWindingNumberBVH fwn_bvh; + int order = 2; + igl::fast_winding_number(V,F,order,fwn_bvh); + float accuracy_scale = 2; + igl::fast_winding_number(fwn_bvh,accuracy_scale,Q,W); +} + +template < + typename DerivedV, + typename DerivedF> +IGL_INLINE void igl::fast_winding_number( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const int order, + FastWindingNumberBVH & fwn_bvh) +{ + assert(V.cols() == 3 && "V should be 3D"); + assert(F.cols() == 3 && "F should contain triangles"); + // Extra copies. Usuually this won't be the bottleneck. + fwn_bvh.U.resize(V.rows()); + for(int i = 0;i +IGL_INLINE void igl::fast_winding_number( + const FastWindingNumberBVH & fwn_bvh, + const float accuracy_scale, + const Eigen::MatrixBase & Q, + Eigen::PlainObjectBase & W) +{ + assert(Q.cols() == 3 && "Q should be 3D"); + W.resize(Q.rows(),1); + igl::parallel_for(Q.rows(),[&](int p) + { + FastWindingNumber::HDK_Sample::UT_Vector3TQp; + Qp[0] = Q(p,0); + Qp[1] = Q(p,1); + Qp[2] = Q(p,2); + W(p) = fwn_bvh.ut_solid_angle.computeSolidAngle(Qp,accuracy_scale) / (4.0*igl::PI); + },1000); +} + +template +IGL_INLINE typename Derivedp::Scalar igl::fast_winding_number( + const FastWindingNumberBVH & fwn_bvh, + const float accuracy_scale, + const Eigen::MatrixBase & p) +{ + assert(p.cols() == 3 && "p should be 3D"); + + FastWindingNumber::HDK_Sample::UT_Vector3TQp; + Qp[0] = p(0,0); + Qp[1] = p(0,1); + Qp[2] = p(0,2); + + typename Derivedp::Scalar w = fwn_bvh.ut_solid_angle.computeSolidAngle(Qp,accuracy_scale) / (4.0*igl::PI); + + return w; +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::fast_winding_number, Eigen::Matrix >(igl::FastWindingNumberBVH const&, float, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template Eigen::Matrix::Scalar igl::fast_winding_number >(igl::FastWindingNumberBVH const&, float, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template void igl::fast_winding_number, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::fast_winding_number, Eigen::Matrix, Eigen::Matrix, int, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::fast_winding_number, Eigen::Matrix, Eigen::Matrix, int, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::fast_winding_number, Eigen::Matrix >(igl::FastWindingNumberBVH const&, float, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::fast_winding_number, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, igl::FastWindingNumberBVH&); +template void igl::fast_winding_number, Eigen::Matrix >(igl::FastWindingNumberBVH const&, float, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::fast_winding_number, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, igl::FastWindingNumberBVH&); + +// tom did this manually. Unsure how to generate otherwise... sorry. +template Eigen::Matrix::Scalar igl::fast_winding_number >(igl::FastWindingNumberBVH const&, float, Eigen::MatrixBase > const&); +template void igl::fast_winding_number, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, igl::FastWindingNumberBVH&); +template void igl::fast_winding_number, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, igl::FastWindingNumberBVH&); +template Eigen::CwiseUnaryOp, Eigen::Matrix const>::Scalar igl::fast_winding_number, Eigen::Matrix const> >(igl::FastWindingNumberBVH const&, float, Eigen::MatrixBase, Eigen::Matrix const> > const&); +#endif diff --git a/vendor/libigl/include/igl/fast_winding_number.h b/vendor/libigl/include/igl/fast_winding_number.h new file mode 100644 index 0000000000000000000000000000000000000000..0b742d350509d6d5de748295ca89542be5dad4c1 --- /dev/null +++ b/vendor/libigl/include/igl/fast_winding_number.h @@ -0,0 +1,228 @@ +#ifndef IGL_FAST_WINDING_NUMBER +#define IGL_FAST_WINDING_NUMBER +#include "igl_inline.h" +#include "FastWindingNumberForSoups.h" +#include +#include +namespace igl +{ + // Generate the precomputation for the fast winding number for point data + // [Barill et. al 2018]. + // + // Given a set of 3D points P, with normals N, areas A, along with octree + // data, and an expansion order, we define a taylor series expansion at each + // octree cell. + // + // The octree data is designed to come from igl::octree, and the areas (if not + // obtained at scan time), may be calculated using + // igl::copyleft::cgal::point_areas. + // + // Inputs: + // P #P by 3 list of point locations + // N #P by 3 list of point normals + // A #P by 1 list of point areas + // point_indices a vector of vectors, where the ith entry is a vector of + // the indices into P that are the ith octree cell's points + // CH #OctreeCells by 8, where the ith row is the indices of + // the ith octree cell's children + // expansion_order the order of the taylor expansion. We support 0,1,2. + // Outputs: + // CM #OctreeCells by 3 list of each cell's center of mass + // R #OctreeCells by 1 list of each cell's maximum distance of any point + // to the center of mass + // EC #OctreeCells by #TaylorCoefficients list of expansion coefficients. + // (Note that #TaylorCoefficients = ∑_{i=1}^{expansion_order} 3^i) + // + // See also: igl::copyleft::cgal::point_areas, igl::knn + template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename Index, + typename DerivedCH, + typename DerivedCM, + typename DerivedR, + typename DerivedEC> + IGL_INLINE void fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const std::vector > & point_indices, + const Eigen::MatrixBase& CH, + const int expansion_order, + Eigen::PlainObjectBase& CM, + Eigen::PlainObjectBase& R, + Eigen::PlainObjectBase& EC); + // Evaluate the fast winding number for point data, having already done the + // the precomputation + // + // Inputs: + // P #P by 3 list of point locations + // N #P by 3 list of point normals + // A #P by 1 list of point areas + // point_indices a vector of vectors, where the ith entry is a vector of + // the indices into P that are the ith octree cell's points + // CH #OctreeCells by 8, where the ith row is the indices of + // the ith octree cell's children + // CM #OctreeCells by 3 list of each cell's center of mass + // R #OctreeCells by 1 list of each cell's maximum distance of any point + // to the center of mass + // EC #OctreeCells by #TaylorCoefficients list of expansion coefficients. + // (Note that #TaylorCoefficients = ∑_{i=1}^{expansion_order} 3^i) + // Q #Q by 3 list of query points for the winding number + // beta This is a Barnes-Hut style accuracy term that separates near feild + // from far field. The higher the beta, the more accurate and slower + // the evaluation. We reccommend using a beta value of 2. Note that + // for a beta value ≤ 0, we use the direct evaluation, rather than + // the fast approximation + // Outputs: + // WN #Q by 1 list of windinng number values at each query point + // + template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename Index, + typename DerivedCH, + typename DerivedCM, + typename DerivedR, + typename DerivedEC, + typename DerivedQ, + typename BetaType, + typename DerivedWN> + IGL_INLINE void fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const std::vector > & point_indices, + const Eigen::MatrixBase& CH, + const Eigen::MatrixBase& CM, + const Eigen::MatrixBase& R, + const Eigen::MatrixBase& EC, + const Eigen::MatrixBase& Q, + const BetaType beta, + Eigen::PlainObjectBase& WN); + template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename DerivedQ, + typename BetaType, + typename DerivedWN> + IGL_INLINE void fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const Eigen::MatrixBase& Q, + const int expansion_order, + const BetaType beta, + Eigen::PlainObjectBase& WN); + // Evaluate the fast winding number for point data, with default expansion + // order and beta (both are set to 2). + // + // This function performes the precomputation and evaluation all in one. + // If you need to acess the precomuptation for repeated evaluations, use the + // two functions designed for exposed precomputation (described above). + // + // Inputs: + // P #P by 3 list of point locations + // N #P by 3 list of point normals + // A #P by 1 list of point areas + // Q #Q by 3 list of query points for the winding number + // Outputs: + // WN #Q by 1 list of windinng number values at each query point + // + template < + typename DerivedP, + typename DerivedA, + typename DerivedN, + typename DerivedQ, + typename DerivedWN> + IGL_INLINE void fast_winding_number( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& N, + const Eigen::MatrixBase& A, + const Eigen::MatrixBase& Q, + Eigen::PlainObjectBase& WN); + // Class declaration + namespace FastWindingNumber { namespace HDK_Sample{ template class UT_SolidAngle;} } + struct FastWindingNumberBVH { + FastWindingNumber::HDK_Sample::UT_SolidAngle ut_solid_angle; + // Need copies of these so they stay alive between calls. + std::vector > U; + std::vector F; + }; + // Compute approximate winding number of a triangle soup mesh according to + // "Fast Winding Numbers for Soups and Clouds" [Barill et al. 2018]. + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of triangle mesh indices into rows of V + // Q #Q by 3 list of query positions + // Outputs: + // W #Q list of winding number values + template < + typename DerivedV, + typename DerivedF, + typename DerivedQ, + typename DerivedW> + IGL_INLINE void fast_winding_number( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & Q, + Eigen::PlainObjectBase & W); + // Precomputation for computing approximate winding numbers of a triangle + // soup. + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of triangle mesh indices into rows of V + // order Taylor series expansion order to use (e.g., 2) + // Outputs: + // fwn_bvh Precomputed bounding volume hierarchy + // + template < + typename DerivedV, + typename DerivedF> + IGL_INLINE void fast_winding_number( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const int order, + FastWindingNumberBVH & fwn_bvh); + // After precomputation, compute winding number at a each of many points in a + // list. + // + // Inputs: + // fwn_bvh Precomputed bounding volume hierarchy + // accuracy_scale parameter controlling accuracy (e.g., 2) + // Q #Q by 3 list of query positions + // Outputs: + // W #Q list of winding number values + template < + typename DerivedQ, + typename DerivedW> + IGL_INLINE void fast_winding_number( + const FastWindingNumberBVH & fwn_bvh, + const float accuracy_scale, + const Eigen::MatrixBase & Q, + Eigen::PlainObjectBase & W); + // After precomputation, compute winding number at a a single point + // + // Inputs: + // fwn_bvh Precomputed bounding volume hierarchy + // accuracy_scale parameter controlling accuracy (e.g., 2) + // p single position + // Outputs: + // w winding number of this point + template + IGL_INLINE typename Derivedp::Scalar fast_winding_number( + const FastWindingNumberBVH & fwn_bvh, + const float accuracy_scale, + const Eigen::MatrixBase & p); +} +#ifndef IGL_STATIC_LIBRARY +# include "fast_winding_number.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/file_contents_as_string.cpp b/vendor/libigl/include/igl/file_contents_as_string.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd945dff2ccea950efbd50904c741bd0d0b756cf --- /dev/null +++ b/vendor/libigl/include/igl/file_contents_as_string.cpp @@ -0,0 +1,45 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "file_contents_as_string.h" + +#include +#include +#include + +IGL_INLINE bool igl::file_contents_as_string( + const std::string file_name, + std::string & content) +{ + std::ifstream ifs(file_name.c_str()); + // Check that opening the stream worked successfully + if(!ifs.good()) + { + fprintf( + stderr, + "IOError: file_contents_as_string() cannot open %s\n", + file_name.c_str()); + return false; + } + // Stream file contents into string + content = std::string( + (std::istreambuf_iterator(ifs)), + (std::istreambuf_iterator())); + return true; +} + +IGL_INLINE std::string igl::file_contents_as_string( + const std::string file_name) +{ + std::string content; +#ifndef NDEBUG + bool ret = +#endif + file_contents_as_string(file_name,content); + assert(ret && "file_contents_as_string failed to read string from file"); + return content; +} diff --git a/vendor/libigl/include/igl/file_contents_as_string.h b/vendor/libigl/include/igl/file_contents_as_string.h new file mode 100644 index 0000000000000000000000000000000000000000..22ce1fc53447313afcdec0fcc140732e36c253d3 --- /dev/null +++ b/vendor/libigl/include/igl/file_contents_as_string.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FILE_CONTENTS_AS_STRING_H +#define IGL_FILE_CONTENTS_AS_STRING_H +#include "igl_inline.h" + +#include +namespace igl +{ + // Read a files contents as plain text into a given string + // Inputs: + // file_name path to file to be read + // Outputs: + // content output string containing contents of the given file + // Returns true on succes, false on error + IGL_INLINE bool file_contents_as_string( + const std::string file_name, + std::string & content); + IGL_INLINE std::string file_contents_as_string( + const std::string file_name); +} + +#ifndef IGL_STATIC_LIBRARY +# include "file_contents_as_string.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/file_dialog_save.cpp b/vendor/libigl/include/igl/file_dialog_save.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe871524904239b222ec8034b6bc748bd22177eb --- /dev/null +++ b/vendor/libigl/include/igl/file_dialog_save.cpp @@ -0,0 +1,113 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "file_dialog_save.h" +#include +#include + +#ifdef _WIN32 + #include + #include +#endif + +IGL_INLINE std::string igl::file_dialog_save() +{ + const int FILE_DIALOG_MAX_BUFFER = 1024; + char buffer[FILE_DIALOG_MAX_BUFFER]; + buffer[0] = '\0'; + buffer[FILE_DIALOG_MAX_BUFFER - 1] = 'x'; // Initialize last character with a char != '\0' + +#ifdef __APPLE__ + // For apple use applescript hack + // There is currently a bug in Applescript that strips extensions off + // of chosen existing files in the "choose file name" dialog + // I'm assuming that will be fixed soon + FILE * output = popen( + "osascript -e \"" + " tell application \\\"System Events\\\"\n" + " activate\n" + " set existing_file to choose file name\n" + " end tell\n" + " set existing_file_path to (POSIX path of (existing_file))\n" + "\" 2>/dev/null | tr -d '\n' ","r"); + if (output) + { + auto ret = fgets(buffer, FILE_DIALOG_MAX_BUFFER, output); + if (ret == NULL || ferror(output)) + { + // I/O error + buffer[0] = '\0'; + } + if (buffer[FILE_DIALOG_MAX_BUFFER - 1] == '\0') + { + // File name too long, buffer has been filled, so we return empty string instead + buffer[0] = '\0'; + } + } +#elif defined _WIN32 + + // Use native windows file dialog box + // (code contributed by Tino Weinkauf) + + OPENFILENAME ofn; // common dialog box structure + char szFile[260]; // buffer for file name + + // Initialize OPENFILENAME + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = NULL;//hwnd; + ofn.lpstrFile = szFile; + // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // use the contents of szFile to initialize itself. + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = ""; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + + // Display the Open dialog box. + int pos = 0; + if (GetSaveFileName(&ofn)==TRUE) + { + while(ofn.lpstrFile[pos] != '\0') + { + buffer[pos] = (char)ofn.lpstrFile[pos]; + pos++; + } + buffer[pos] = 0; + } + +#else + // For every other machine type use zenity + FILE * output = popen("/usr/bin/zenity --file-selection --save","r"); + if (output) + { + auto ret = fgets(buffer, FILE_DIALOG_MAX_BUFFER, output); + if (ret == NULL || ferror(output)) + { + // I/O error + buffer[0] = '\0'; + } + if (buffer[FILE_DIALOG_MAX_BUFFER - 1] == '\0') + { + // File name too long, buffer has been filled, so we return empty string instead + buffer[0] = '\0'; + } + } + + // Replace last '\n' by '\0' + if(strlen(buffer) > 0) + { + buffer[strlen(buffer)-1] = '\0'; + } + +#endif + return std::string(buffer); +} diff --git a/vendor/libigl/include/igl/file_exists.h b/vendor/libigl/include/igl/file_exists.h new file mode 100644 index 0000000000000000000000000000000000000000..e011d977ebaf006d058e030376f7ed3d2ad2a10f --- /dev/null +++ b/vendor/libigl/include/igl/file_exists.h @@ -0,0 +1,27 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FILE_EXISTS_H +#define IGL_FILE_EXISTS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Check if a file or directory exists like PHP's file_exists function: + // http://php.net/manual/en/function.file-exists.php + // Input: + // filename path to file + // Returns true if file exists and is readable and false if file doesn't + // exist or *is not readable* + IGL_INLINE bool file_exists(const std::string filename); +} + +#ifndef IGL_STATIC_LIBRARY +# include "file_exists.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/find.h b/vendor/libigl/include/igl/find.h new file mode 100644 index 0000000000000000000000000000000000000000..85eb65770c483b61a9878c3599bce26ce6fac9fb --- /dev/null +++ b/vendor/libigl/include/igl/find.h @@ -0,0 +1,77 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FIND_H +#define IGL_FIND_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +namespace igl +{ + // Find the non-zero entries and there respective indices in a sparse matrix. + // Like matlab's [I,J,V] = find(X) + // + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Input: + // X m by n matrix whose entries are to be found + // Outputs: + // I nnz vector of row indices of non zeros entries in X + // J nnz vector of column indices of non zeros entries in X + // V nnz vector of type T non-zeros entries in X + // + template < + typename T, + typename DerivedI, + typename DerivedJ, + typename DerivedV> + IGL_INLINE void find( + const Eigen::SparseMatrix& X, + Eigen::DenseBase & I, + Eigen::DenseBase & J, + Eigen::DenseBase & V); + template < + typename DerivedX, + typename DerivedI, + typename DerivedJ, + typename DerivedV> + IGL_INLINE void find( + const Eigen::DenseBase& X, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & J, + Eigen::PlainObjectBase & V); + template < + typename DerivedX, + typename DerivedI> + IGL_INLINE void find( + const Eigen::DenseBase& X, + Eigen::PlainObjectBase & I); + // Find the non-zero entries and there respective indices in a sparse vector. + // Similar to matlab's [I,J,V] = find(X), but instead of [I,J] being + // subscripts into X, since X is a vector we just return I, a list of indices + // into X + // + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Input: + // X vector whose entries are to be found + // Outputs: + // I nnz vector of indices of non zeros entries in X + // V nnz vector of type T non-zeros entries in X + template + IGL_INLINE void find( + const Eigen::SparseVector& X, + Eigen::Matrix & I, + Eigen::Matrix & V); +} + +#ifndef IGL_STATIC_LIBRARY +# include "find.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/find_cross_field_singularities.h b/vendor/libigl/include/igl/find_cross_field_singularities.h new file mode 100644 index 0000000000000000000000000000000000000000..94581d30eebf7e7d927bf94d59964b76df63665d --- /dev/null +++ b/vendor/libigl/include/igl/find_cross_field_singularities.h @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo , Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_FIND_CROSS_FIELD_SINGULARITIES_H +#define IGL_FIND_CROSS_FIELD_SINGULARITIES_H +#include "igl_inline.h" +#include +namespace igl +{ + // Computes singularities of a cross field, assumed combed + + + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 3 eigen Matrix of face (quad) indices + // mismatch #F by 3 eigen Matrix containing the integer mismatch of the cross field + // across all face edges + // Output: + // isSingularity #V by 1 boolean eigen Vector indicating the presence of a singularity on a vertex + // singularityIndex #V by 1 integer eigen Vector containing the singularity indices + // + template + IGL_INLINE void find_cross_field_singularities(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &mismatch, + Eigen::PlainObjectBase &isSingularity, + Eigen::PlainObjectBase &singularityIndex); + + // Wrapper that calculates the mismatch if it is not provided. + // Note that the field in PD1 and PD2 MUST BE combed (see igl::comb_cross_field). + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 3 eigen Matrix of face (quad) indices + // PD1 #F by 3 eigen Matrix of the first per face cross field vector + // PD2 #F by 3 eigen Matrix of the second per face cross field vector + // Output: + // isSingularity #V by 1 boolean eigen Vector indicating the presence of a singularity on a vertex + // singularityIndex #V by 1 integer eigen Vector containing the singularity indices + // + template + IGL_INLINE void find_cross_field_singularities(const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + const Eigen::MatrixBase &PD1, + const Eigen::MatrixBase &PD2, + Eigen::PlainObjectBase &isSingularity, + Eigen::PlainObjectBase &singularityIndex, + bool isCombed = false); +} +#ifndef IGL_STATIC_LIBRARY +#include "find_cross_field_singularities.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/find_zero.cpp b/vendor/libigl/include/igl/find_zero.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d0a7b35e6d4657dfc4172bbc26e03fdde3fa97f2 --- /dev/null +++ b/vendor/libigl/include/igl/find_zero.cpp @@ -0,0 +1,48 @@ +#include "find_zero.h" +#include "for_each.h" +#include "any.h" + +template +IGL_INLINE void igl::find_zero( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase & I) +{ + assert((dim == 1 || dim == 2) && "dim must be 2 or 1"); + // Get size of input + int m = A.rows(); + int n = A.cols(); + // I starts by containing guess where 0 might be + I = DerivedI::Zero(dim==1?n:m); + Eigen::Array found = + Eigen::Array::Zero(dim==1?n:m); + const auto func = [&I,&found,&dim](int i, int j, const int v) + { + if(dim == 2) + { + std::swap(i,j); + } + // Coded as if dim == 1, assuming swap for dim == 2 + // Have we already found a zero? + if(!found(j)) + { + if(I(j) != i || v == 0) + { + // either there was an implicit zero between the last element and this + // one, or this one is zero + found(j) = true; + }else + { + // If not found, then guess that next element will be zero + I(j) = I(j)+1; + } + } + }; + for_each(A,func); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::find_zero >(Eigen::SparseMatrix const&, int, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/fit_cubic_bezier.cpp b/vendor/libigl/include/igl/fit_cubic_bezier.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad77658b116b356d086809cf19a57e11929a5510 --- /dev/null +++ b/vendor/libigl/include/igl/fit_cubic_bezier.cpp @@ -0,0 +1,308 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "fit_cubic_bezier.h" +#include "bezier.h" +#include "EPS.h" + +// Adapted from main.c accompanying +// An Algorithm for Automatically Fitting Digitized Curves +// by Philip J. Schneider +// from "Graphics Gems", Academic Press, 1990 +IGL_INLINE void igl::fit_cubic_bezier( + const Eigen::MatrixXd & d, + const double error, + std::vector & cubics) +{ + const int nPts = d.rows(); + // Don't attempt to fit curve to single point + if(nPts==1) { return; } + // Avoid using zero tangent + const static auto tangent = []( + const Eigen::MatrixXd & d, + const int i,const int dir)->Eigen::RowVectorXd + { + int j = i; + const int nPts = d.rows(); + Eigen::RowVectorXd t; + while(true) + { + // look at next point + j += dir; + if(j < 0 || j>=nPts) + { + // All points are coincident? + // give up and use zero tangent... + return Eigen::RowVectorXd::Zero(1,d.cols()); + } + t = d.row(j)-d.row(i); + if(t.squaredNorm() > igl::DOUBLE_EPS) + { + break; + } + } + return t.normalized(); + }; + Eigen::RowVectorXd tHat1 = tangent(d,0,+1); + Eigen::RowVectorXd tHat2 = tangent(d,nPts-1,-1); + // If first and last points are identically equal, then consider closed + const bool closed = (d.row(0) - d.row(d.rows()-1)).squaredNorm() == 0; + // If closed loop make tangents match + if(closed) + { + tHat1 = (tHat1 - tHat2).eval().normalized(); + tHat2 = -tHat1; + } + cubics.clear(); + fit_cubic_bezier_substring(d,0,nPts-1,tHat1,tHat2,error,closed,cubics); +}; + +IGL_INLINE void igl::fit_cubic_bezier_substring( + const Eigen::MatrixXd & d, + const int first, + const int last, + const Eigen::RowVectorXd & tHat1, + const Eigen::RowVectorXd & tHat2, + const double error, + const bool force_split, + std::vector & cubics) +{ + // Helper functions + // Evaluate a Bezier curve at a particular parameter value + const static auto bezier_eval = [](const Eigen::MatrixXd & V, const double t) + { Eigen::RowVectorXd P; bezier(V,t,P); return P; }; + // + // Use Newton-Raphson iteration to find better root. + const static auto NewtonRaphsonRootFind = []( + const Eigen::MatrixXd & Q, + const Eigen::RowVectorXd & P, + const double u)->double + { + /* Compute Q(u) */ + Eigen::RowVectorXd Q_u = bezier_eval(Q, u); + Eigen::MatrixXd Q1(3,Q.cols()); + Eigen::MatrixXd Q2(2,Q.cols()); + /* Generate control vertices for Q' */ + for (int i = 0; i <= 2; i++) + { + Q1.row(i) = (Q.row(i+1) - Q.row(i)) * 3.0; + } + /* Generate control vertices for Q'' */ + for (int i = 0; i <= 1; i++) + { + Q2.row(i) = (Q1.row(i+1) - Q1.row(i)) * 2.0; + } + /* Compute Q'(u) and Q''(u) */ + const Eigen::RowVectorXd Q1_u = bezier_eval(Q1, u); + const Eigen::RowVectorXd Q2_u = bezier_eval(Q2, u); + /* Compute f(u)/f'(u) */ + const double numerator = ((Q_u-P).array() * Q1_u.array()).array().sum(); + const double denominator = + Q1_u.squaredNorm() + ((Q_u-P).array() * Q2_u.array()).array().sum(); + /* u = u - f(u)/f'(u) */ + return u - (numerator/denominator); + }; + const static auto ComputeMaxError = []( + const Eigen::MatrixXd & d, + const int first, + const int last, + const Eigen::MatrixXd & bezCurve, + const Eigen::VectorXd & u, + int & splitPoint)->double + { + Eigen::VectorXd E(last - (first+1)); + splitPoint = (last-first + 1)/2; + double maxDist = 0.0; + for (int i = first + 1; i < last; i++) + { + Eigen::RowVectorXd P = bezier_eval(bezCurve, u(i-first)); + const double dist = (P-d.row(i)).squaredNorm(); + E(i-(first+1)) = dist; + if (dist >= maxDist) + { + maxDist = dist; + // Worst offender + splitPoint = i; + } + } + //const double half_total = E.array().sum()/2; + //double run = 0; + //for (int i = first + 1; i < last; i++) + //{ + // run += E(i-(first+1)); + // if(run>half_total) + // { + // // When accumulated ½ the error --> more symmetric, but requires more + // // curves + // splitPoint = i; + // break; + // } + //} + return maxDist; + }; + const static auto Straight = []( + const Eigen::MatrixXd & d, + const int first, + const int last, + const Eigen::RowVectorXd & tHat1, + const Eigen::RowVectorXd & tHat2, + Eigen::MatrixXd & bezCurve) + { + bezCurve.resize(4,d.cols()); + const double dist = (d.row(last)-d.row(first)).norm()/3.0; + bezCurve.row(0) = d.row(first); + bezCurve.row(1) = d.row(first) + tHat1*dist; + bezCurve.row(2) = d.row(last) + tHat2*dist; + bezCurve.row(3) = d.row(last); + }; + const static auto GenerateBezier = []( + const Eigen::MatrixXd & d, + const int first, + const int last, + const Eigen::VectorXd & uPrime, + const Eigen::RowVectorXd & tHat1, + const Eigen::RowVectorXd & tHat2, + Eigen::MatrixXd & bezCurve) + { + bezCurve.resize(4,d.cols()); + const int nPts = last - first + 1; + const static auto B0 = [](const double u)->double + { double tmp = 1.0 - u; return (tmp * tmp * tmp);}; + const static auto B1 = [](const double u)->double + { double tmp = 1.0 - u; return (3 * u * (tmp * tmp));}; + const static auto B2 = [](const double u)->double + { double tmp = 1.0 - u; return (3 * u * u * tmp); }; + const static auto B3 = [](const double u)->double + { return (u * u * u); }; + /* Compute the A's */ + std::vector > A(nPts); + for (int i = 0; i < nPts; i++) + { + Eigen::RowVectorXd v1 = tHat1*B1(uPrime(i)); + Eigen::RowVectorXd v2 = tHat2*B2(uPrime(i)); + A[i] = {v1,v2}; + } + /* Create the C and X matrices */ + Eigen::MatrixXd C(2,2); + Eigen::VectorXd X(2); + C(0,0) = 0.0; + C(0,1) = 0.0; + C(1,0) = 0.0; + C(1,1) = 0.0; + X(0) = 0.0; + X(1) = 0.0; + for( int i = 0; i < nPts; i++) + { + C(0,0) += A[i][0].dot(A[i][0]); + C(0,1) += A[i][0].dot(A[i][1]); + C(1,0) = C(0,1); + C(1,1) += A[i][1].dot(A[i][1]); + const Eigen::RowVectorXd tmp = + d.row(first+i)-( + d.row(first)*B0(uPrime(i))+ + d.row(first)*B1(uPrime(i))+ + d.row(last)*B2(uPrime(i))+ + d.row(last)*B3(uPrime(i))); + X(0) += A[i][0].dot(tmp); + X(1) += A[i][1].dot(tmp); + } + /* Compute the determinants of C and X */ + double det_C0_C1 = C(0,0) * C(1,1) - C(1,0) * C(0,1); + const double det_C0_X = C(0,0) * X(1) - C(0,1) * X(0); + const double det_X_C1 = X(0) * C(1,1) - X(1) * C(0,1); + /* Finally, derive alpha values */ + if (det_C0_C1 == 0.0) + { + det_C0_C1 = (C(0,0) * C(1,1)) * 10e-12; + } + const double alpha_l = det_X_C1 / det_C0_C1; + const double alpha_r = det_C0_X / det_C0_C1; + /* If alpha negative, use the Wu/Barsky heuristic (see text) */ + /* (if alpha is 0, you get coincident control points that lead to + * divide by zero in any subsequent NewtonRaphsonRootFind() call. */ + if (alpha_l < 1.0e-6 || alpha_r < 1.0e-6) + { + return Straight(d,first,last,tHat1,tHat2,bezCurve); + } + bezCurve.row(0) = d.row(first); + bezCurve.row(1) = d.row(first) + tHat1*alpha_l; + bezCurve.row(2) = d.row(last) + tHat2*alpha_r; + bezCurve.row(3) = d.row(last); + }; + + const int maxIterations = 4; + // This is a bad idea if error<1 ... + //const double iterationError = error * error; + const double iterationError = 100 * error; + const int nPts = last - first + 1; + /* Use heuristic if region only has two points in it */ + if(nPts == 2) + { + Eigen::MatrixXd bezCurve; + Straight(d,first,last,tHat1,tHat2,bezCurve); + cubics.push_back(bezCurve); + return; + } + // ChordLengthParameterize + Eigen::VectorXd u(last-first+1); + u(0) = 0; + for (int i = first+1; i <= last; i++) + { + u(i-first) = u(i-first-1) + (d.row(i)-d.row(i-1)).norm(); + } + for (int i = first + 1; i <= last; i++) + { + u(i-first) = u(i-first) / u(last-first); + } + Eigen::MatrixXd bezCurve; + GenerateBezier(d, first, last, u, tHat1, tHat2, bezCurve); + + + int splitPoint; + double maxError = ComputeMaxError(d, first, last, bezCurve, u, splitPoint); + if (!force_split && maxError < error) + { + cubics.push_back(bezCurve); + return; + } + /* If error not too large, try some reparameterization */ + /* and iteration */ + if (maxError < iterationError) + { + for (int i = 0; i < maxIterations; i++) + { + Eigen::VectorXd uPrime; + // Reparameterize + uPrime.resize(last-first+1); + for (int i = first; i <= last; i++) + { + uPrime(i-first) = NewtonRaphsonRootFind(bezCurve, d.row(i), u(i- first)); + } + GenerateBezier(d, first, last, uPrime, tHat1, tHat2, bezCurve); + maxError = ComputeMaxError(d, first, last, bezCurve, uPrime, splitPoint); + if (!force_split && maxError < error) { + cubics.push_back(bezCurve); + return; + } + u = uPrime; + } + } + + /* Fitting failed -- split at max error point and fit recursively */ + const Eigen::RowVectorXd tHatCenter = + (d.row(splitPoint-1)-d.row(splitPoint+1)).normalized(); + //foobar + fit_cubic_bezier_substring( + d,first,splitPoint,tHat1,tHatCenter,error,false,cubics); + fit_cubic_bezier_substring( + d,splitPoint,last,(-tHatCenter).eval(),tHat2,error,false,cubics); +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/fit_plane.cpp b/vendor/libigl/include/igl/fit_plane.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83f11738f2837ff77c7b124f480ca0fa5b9c31df --- /dev/null +++ b/vendor/libigl/include/igl/fit_plane.cpp @@ -0,0 +1,56 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "fit_plane.h" +#include + +IGL_INLINE void igl::fit_plane( + const Eigen::MatrixXd & V, + Eigen::RowVector3d & N, + Eigen::RowVector3d & C) +{ + assert(V.rows()>0); + + Eigen::Vector3d sum = V.colwise().sum(); + + Eigen::Vector3d center = sum.array()/(double(V.rows())); + + C = center; + + double sumXX=0.0f,sumXY=0.0f,sumXZ=0.0f; + double sumYY=0.0f,sumYZ=0.0f; + double sumZZ=0.0f; + + for(int i=0;i es(m); + + N = es.eigenvectors().col(0); +} + +#ifdef IGL_STATIC_LIBRARY +#endif + + + diff --git a/vendor/libigl/include/igl/fit_plane.h b/vendor/libigl/include/igl/fit_plane.h new file mode 100644 index 0000000000000000000000000000000000000000..f69ce811b4f55e4535d08ff150bbb3056c512c99 --- /dev/null +++ b/vendor/libigl/include/igl/fit_plane.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FIT_PLANE_H +#define IGL_FIT_PLANE_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // This function fits a plane to a point cloud. + // + // Input: + // V #Vx3 matrix. The 3D point cloud, one row for each vertex. + // Output: + // N 1x3 Vector. The normal of the fitted plane. + // C 1x3 Vector. A point that lies in the fitted plane. + // From http://missingbytes.blogspot.com/2012/06/fitting-plane-to-point-cloud.html + + IGL_INLINE void fit_plane( + const Eigen::MatrixXd & V, + Eigen::RowVector3d & N, + Eigen::RowVector3d & C); +} + +#ifndef IGL_STATIC_LIBRARY +# include "fit_plane.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/fit_rotations.cpp b/vendor/libigl/include/igl/fit_rotations.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bff77900fcba4ebef35a2c9b0e68c0a7b0d4ac3d --- /dev/null +++ b/vendor/libigl/include/igl/fit_rotations.cpp @@ -0,0 +1,226 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "fit_rotations.h" +#include "polar_svd3x3.h" +#include "repmat.h" +#include "verbose.h" +#include "polar_dec.h" +#include "polar_svd.h" +#include "C_STR.h" +#include + +template +IGL_INLINE void igl::fit_rotations( + const Eigen::PlainObjectBase & S, + const bool single_precision, + Eigen::PlainObjectBase & R) +{ + using namespace std; + const int dim = S.cols(); + const int nr = S.rows()/dim; + assert(nr * dim == S.rows()); + assert(dim == 3); + + // resize output + R.resize(dim,dim*nr); // hopefully no op (should be already allocated) + + //std::cout<<"S=["< si;// = Eigen::Matrix3d::Identity(); + // loop over number of rotations we're computing + for(int r = 0;r Mat3; + typedef Eigen::Matrix Vec3; + Mat3 ri; + if(single_precision) + { + polar_svd3x3(si, ri); + }else + { + Mat3 ti,ui,vi; + Vec3 _; + igl::polar_svd(si,ri,ti,ui,_,vi); + } + assert(ri.determinant() >= 0); + R.block(0,r*dim,dim,dim) = ri.block(0,0,dim,dim).transpose(); + //cout< +IGL_INLINE void igl::fit_rotations_planar( + const Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & R) +{ + using namespace std; + const int dim = S.cols(); + const int nr = S.rows()/dim; + //assert(dim == 2 && "_planar input should be 2D"); + assert(nr * dim == S.rows()); + + // resize output + R.resize(dim,dim*nr); // hopefully no op (should be already allocated) + + Eigen::Matrix si; + // loop over number of rotations we're computing + for(int r = 0;r Mat2; + typedef Eigen::Matrix Vec2; + Mat2 ri,ti,ui,vi; + Vec2 _; + igl::polar_svd(si,ri,ti,ui,_,vi); +#ifndef FIT_ROTATIONS_ALLOW_FLIPS + // Check for reflection + if(ri.determinant() < 0) + { + vi.col(1) *= -1.; + ri = ui * vi.transpose(); + } + assert(ri.determinant() >= 0); +#endif + + // Not sure why polar_dec computes transpose... + R.block(0,r*dim,dim,dim).setIdentity(); + R.block(0,r*dim,2,2) = ri.transpose(); + } +} + + +#ifdef __SSE__ +IGL_INLINE void igl::fit_rotations_SSE( + const Eigen::MatrixXf & S, + Eigen::MatrixXf & R) +{ + const int cStep = 4; + + assert(S.cols() == 3); + const int dim = 3; //S.cols(); + const int nr = S.rows()/dim; + assert(nr * dim == S.rows()); + + // resize output + R.resize(dim,dim*nr); // hopefully no op (should be already allocated) + + Eigen::Matrix siBig; + // using SSE decompose cStep matrices at a time: + int r = 0; + for( ; r= nr) numMats = nr - r; + // build siBig: + for (int k=0; k ri; + polar_svd3x3_sse(siBig, ri); + + for (int k=0; k= 0); + + // Not sure why polar_dec computes transpose... + for (int k=0; k(); + Eigen::MatrixXf Rf; + fit_rotations_SSE(Sf,Rf); + R = Rf.cast(); +} +#endif + +#ifdef __AVX__ +IGL_INLINE void igl::fit_rotations_AVX( + const Eigen::MatrixXf & S, + Eigen::MatrixXf & R) +{ + const int cStep = 8; + + assert(S.cols() == 3); + const int dim = 3; //S.cols(); + const int nr = S.rows()/dim; + assert(nr * dim == S.rows()); + + // resize output + R.resize(dim,dim*nr); // hopefully no op (should be already allocated) + + Eigen::Matrix siBig; + // using SSE decompose cStep matrices at a time: + int r = 0; + for( ; r= nr) numMats = nr - r; + // build siBig: + for (int k=0; k ri; + polar_svd3x3_avx(siBig, ri); + + for (int k=0; k= 0); + + // Not sure why polar_dec computes transpose... + for (int k=0; k, Eigen::Matrix >(Eigen::PlainObjectBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::fit_rotations_planar, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::fit_rotations_planar, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::fit_rotations,Eigen::Matrix >(Eigen::PlainObjectBase > const &,bool,Eigen::PlainObjectBase > &); +template void igl::fit_rotations_planar, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/fit_rotations.h b/vendor/libigl/include/igl/fit_rotations.h new file mode 100644 index 0000000000000000000000000000000000000000..1a18fd322a47794dd8cd99a0b91920980080f4e1 --- /dev/null +++ b/vendor/libigl/include/igl/fit_rotations.h @@ -0,0 +1,60 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FIT_ROTATIONS_H +#define IGL_FIT_ROTATIONS_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Known issues: This seems to be implemented in Eigen/Geometry: + // Eigen::umeyama + // + // FIT_ROTATIONS Given an input mesh and new positions find rotations for + // every covariance matrix in a stack of covariance matrices + // + // Inputs: + // S nr*dim by dim stack of covariance matrices + // single_precision whether to use single precision (faster) + // Outputs: + // R dim by dim * nr list of rotations + // + template + IGL_INLINE void fit_rotations( + const Eigen::PlainObjectBase & S, + const bool single_precision, + Eigen::PlainObjectBase & R); + + // FIT_ROTATIONS Given an input mesh and new positions find 2D rotations for + // every vertex that best maps its one ring to the new one ring + // + // Inputs: + // S nr*dim by dim stack of covariance matrices, third column and every + // third row will be ignored + // Outputs: + // R dim by dim * nr list of rotations, third row and third column of each + // rotation will just be identity + // + template + IGL_INLINE void fit_rotations_planar( + const Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & R); +#ifdef __SSE__ + IGL_INLINE void fit_rotations_SSE( const Eigen::MatrixXf & S, Eigen::MatrixXf & R); + IGL_INLINE void fit_rotations_SSE( const Eigen::MatrixXd & S, Eigen::MatrixXd & R); +#endif +#ifdef __AVX__ + IGL_INLINE void fit_rotations_AVX( const Eigen::MatrixXf & S, Eigen::MatrixXf & R); +#endif +} + +#ifndef IGL_STATIC_LIBRARY +# include "fit_rotations.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/flip_avoiding_line_search.cpp b/vendor/libigl/include/igl/flip_avoiding_line_search.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6103f6eb8e235878cc6b55f50790c0ae81f9d85f --- /dev/null +++ b/vendor/libigl/include/igl/flip_avoiding_line_search.cpp @@ -0,0 +1,320 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "flip_avoiding_line_search.h" +#include "line_search.h" +#include "PI.h" + +#include +#include + +namespace igl +{ + namespace flip_avoiding + { + //--------------------------------------------------------------------------- + // x - array of size 3 + // In case 3 real roots: => x[0], x[1], x[2], return 3 + // 2 real roots: x[0], x[1], return 2 + // 1 real root : x[0], x[1] ± i*x[2], return 1 + // http://math.ivanovo.ac.ru/dalgebra/Khashin/poly/index.html + IGL_INLINE int SolveP3(std::vector& x,double a,double b,double c) + { // solve cubic equation x^3 + a*x^2 + b*x + c + using namespace std; + double a2 = a*a; + double q = (a2 - 3*b)/9; + double r = (a*(2*a2-9*b) + 27*c)/54; + double r2 = r*r; + double q3 = q*q*q; + double A,B; + if(r2 1) t= 1; + t=acos(t); + a/=3; q=-2*sqrt(q); + x[0]=q*cos(t/3)-a; + x[1]=q*cos((t+(2*igl::PI))/3)-a; + x[2]=q*cos((t-(2*igl::PI))/3)-a; + return(3); + } + else + { + A =-pow(fabs(r)+sqrt(r2-q3),1./3); + if( r<0 ) A=-A; + B = A==0? 0 : q/A; + + a/=3; + x[0] =(A+B)-a; + x[1] =-0.5*(A+B)-a; + x[2] = 0.5*sqrt(3.)*(A-B); + if(fabs(x[2])<1e-14) + { + x[2]=x[1]; return(2); + } + return(1); + } + } + + IGL_INLINE double get_smallest_pos_quad_zero(double a,double b, double c) + { + using namespace std; + double t1, t2; + if(std::abs(a) > 1.0e-10) + { + double delta_in = pow(b, 2) - 4 * a * c; + if(delta_in <= 0) + { + return INFINITY; + } + + double delta = sqrt(delta_in); // delta >= 0 + if(b >= 0) // avoid subtracting two similar numbers + { + double bd = - b - delta; + t1 = 2 * c / bd; + t2 = bd / (2 * a); + } + else + { + double bd = - b + delta; + t1 = bd / (2 * a); + t2 = (2 * c) / bd; + } + + assert (std::isfinite(t1)); + assert (std::isfinite(t2)); + + if(a < 0) std::swap(t1, t2); // make t1 > t2 + // return the smaller positive root if it exists, otherwise return infinity + if(t1 > 0) + { + return t2 > 0 ? t2 : t1; + } + else + { + return INFINITY; + } + } + else + { + if(b == 0) return INFINITY; // just to avoid divide-by-zero + t1 = -c / b; + return t1 > 0 ? t1 : INFINITY; + } + } + + IGL_INLINE double get_min_pos_root_2D(const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F, + Eigen::MatrixXd& d, + int f) + { + using namespace std; + /* + Finding the smallest timestep t s.t a triangle get degenerated (<=> det = 0) + The following code can be derived by a symbolic expression in matlab: + + Symbolic matlab: + U11 = sym('U11'); + U12 = sym('U12'); + U21 = sym('U21'); + U22 = sym('U22'); + U31 = sym('U31'); + U32 = sym('U32'); + + V11 = sym('V11'); + V12 = sym('V12'); + V21 = sym('V21'); + V22 = sym('V22'); + V31 = sym('V31'); + V32 = sym('V32'); + + t = sym('t'); + + U1 = [U11,U12]; + U2 = [U21,U22]; + U3 = [U31,U32]; + + V1 = [V11,V12]; + V2 = [V21,V22]; + V3 = [V31,V32]; + + A = [(U2+V2*t) - (U1+ V1*t)]; + B = [(U3+V3*t) - (U1+ V1*t)]; + C = [A;B]; + + solve(det(C), t); + cf = coeffs(det(C),t); % Now cf(1),cf(2),cf(3) holds the coefficients for the polynom. at order c,b,a + */ + + int v1 = F(f,0); int v2 = F(f,1); int v3 = F(f,2); + // get quadratic coefficients (ax^2 + b^x + c) + const double& U11 = uv(v1,0); + const double& U12 = uv(v1,1); + const double& U21 = uv(v2,0); + const double& U22 = uv(v2,1); + const double& U31 = uv(v3,0); + const double& U32 = uv(v3,1); + + const double& V11 = d(v1,0); + const double& V12 = d(v1,1); + const double& V21 = d(v2,0); + const double& V22 = d(v2,1); + const double& V31 = d(v3,0); + const double& V32 = d(v3,1); + + double a = V11*V22 - V12*V21 - V11*V32 + V12*V31 + V21*V32 - V22*V31; + double b = U11*V22 - U12*V21 - U21*V12 + U22*V11 - U11*V32 + U12*V31 + U31*V12 - U32*V11 + U21*V32 - U22*V31 - U31*V22 + U32*V21; + double c = U11*U22 - U12*U21 - U11*U32 + U12*U31 + U21*U32 - U22*U31; + + return get_smallest_pos_quad_zero(a,b,c); + } + + IGL_INLINE double get_min_pos_root_3D(const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F, + Eigen::MatrixXd& direc, + int f) + { + using namespace std; + /* + Searching for the roots of: + +-1/6 * |ax ay az 1| + |bx by bz 1| + |cx cy cz 1| + |dx dy dz 1| + Every point ax,ay,az has a search direction a_dx,a_dy,a_dz, and so we add those to the matrix, and solve the cubic to find the step size t for a 0 volume + Symbolic matlab: + syms a_x a_y a_z a_dx a_dy a_dz % tetrahedera point and search direction + syms b_x b_y b_z b_dx b_dy b_dz + syms c_x c_y c_z c_dx c_dy c_dz + syms d_x d_y d_z d_dx d_dy d_dz + syms t % Timestep var, this is what we're looking for + + + a_plus_t = [a_x,a_y,a_z] + t*[a_dx,a_dy,a_dz]; + b_plus_t = [b_x,b_y,b_z] + t*[b_dx,b_dy,b_dz]; + c_plus_t = [c_x,c_y,c_z] + t*[c_dx,c_dy,c_dz]; + d_plus_t = [d_x,d_y,d_z] + t*[d_dx,d_dy,d_dz]; + + vol_mat = [a_plus_t,1;b_plus_t,1;c_plus_t,1;d_plus_t,1] + //cf = coeffs(det(vol_det),t); % Now cf(1),cf(2),cf(3),cf(4) holds the coefficients for the polynom + [coefficients,terms] = coeffs(det(vol_det),t); % terms = [ t^3, t^2, t, 1], Coefficients hold the coeff we seek + */ + int v1 = F(f,0); int v2 = F(f,1); int v3 = F(f,2); int v4 = F(f,3); + const double& a_x = uv(v1,0); + const double& a_y = uv(v1,1); + const double& a_z = uv(v1,2); + const double& b_x = uv(v2,0); + const double& b_y = uv(v2,1); + const double& b_z = uv(v2,2); + const double& c_x = uv(v3,0); + const double& c_y = uv(v3,1); + const double& c_z = uv(v3,2); + const double& d_x = uv(v4,0); + const double& d_y = uv(v4,1); + const double& d_z = uv(v4,2); + + const double& a_dx = direc(v1,0); + const double& a_dy = direc(v1,1); + const double& a_dz = direc(v1,2); + const double& b_dx = direc(v2,0); + const double& b_dy = direc(v2,1); + const double& b_dz = direc(v2,2); + const double& c_dx = direc(v3,0); + const double& c_dy = direc(v3,1); + const double& c_dz = direc(v3,2); + const double& d_dx = direc(v4,0); + const double& d_dy = direc(v4,1); + const double& d_dz = direc(v4,2); + + // Find solution for: a*t^3 + b*t^2 + c*d +d = 0 + double a = a_dx*b_dy*c_dz - a_dx*b_dz*c_dy - a_dy*b_dx*c_dz + a_dy*b_dz*c_dx + a_dz*b_dx*c_dy - a_dz*b_dy*c_dx - a_dx*b_dy*d_dz + a_dx*b_dz*d_dy + a_dy*b_dx*d_dz - a_dy*b_dz*d_dx - a_dz*b_dx*d_dy + a_dz*b_dy*d_dx + a_dx*c_dy*d_dz - a_dx*c_dz*d_dy - a_dy*c_dx*d_dz + a_dy*c_dz*d_dx + a_dz*c_dx*d_dy - a_dz*c_dy*d_dx - b_dx*c_dy*d_dz + b_dx*c_dz*d_dy + b_dy*c_dx*d_dz - b_dy*c_dz*d_dx - b_dz*c_dx*d_dy + b_dz*c_dy*d_dx; + + double b = a_dy*b_dz*c_x - a_dy*b_x*c_dz - a_dz*b_dy*c_x + a_dz*b_x*c_dy + a_x*b_dy*c_dz - a_x*b_dz*c_dy - a_dx*b_dz*c_y + a_dx*b_y*c_dz + a_dz*b_dx*c_y - a_dz*b_y*c_dx - a_y*b_dx*c_dz + a_y*b_dz*c_dx + a_dx*b_dy*c_z - a_dx*b_z*c_dy - a_dy*b_dx*c_z + a_dy*b_z*c_dx + a_z*b_dx*c_dy - a_z*b_dy*c_dx - a_dy*b_dz*d_x + a_dy*b_x*d_dz + a_dz*b_dy*d_x - a_dz*b_x*d_dy - a_x*b_dy*d_dz + a_x*b_dz*d_dy + a_dx*b_dz*d_y - a_dx*b_y*d_dz - a_dz*b_dx*d_y + a_dz*b_y*d_dx + a_y*b_dx*d_dz - a_y*b_dz*d_dx - a_dx*b_dy*d_z + a_dx*b_z*d_dy + a_dy*b_dx*d_z - a_dy*b_z*d_dx - a_z*b_dx*d_dy + a_z*b_dy*d_dx + a_dy*c_dz*d_x - a_dy*c_x*d_dz - a_dz*c_dy*d_x + a_dz*c_x*d_dy + a_x*c_dy*d_dz - a_x*c_dz*d_dy - a_dx*c_dz*d_y + a_dx*c_y*d_dz + a_dz*c_dx*d_y - a_dz*c_y*d_dx - a_y*c_dx*d_dz + a_y*c_dz*d_dx + a_dx*c_dy*d_z - a_dx*c_z*d_dy - a_dy*c_dx*d_z + a_dy*c_z*d_dx + a_z*c_dx*d_dy - a_z*c_dy*d_dx - b_dy*c_dz*d_x + b_dy*c_x*d_dz + b_dz*c_dy*d_x - b_dz*c_x*d_dy - b_x*c_dy*d_dz + b_x*c_dz*d_dy + b_dx*c_dz*d_y - b_dx*c_y*d_dz - b_dz*c_dx*d_y + b_dz*c_y*d_dx + b_y*c_dx*d_dz - b_y*c_dz*d_dx - b_dx*c_dy*d_z + b_dx*c_z*d_dy + b_dy*c_dx*d_z - b_dy*c_z*d_dx - b_z*c_dx*d_dy + b_z*c_dy*d_dx; + + double c = a_dz*b_x*c_y - a_dz*b_y*c_x - a_x*b_dz*c_y + a_x*b_y*c_dz + a_y*b_dz*c_x - a_y*b_x*c_dz - a_dy*b_x*c_z + a_dy*b_z*c_x + a_x*b_dy*c_z - a_x*b_z*c_dy - a_z*b_dy*c_x + a_z*b_x*c_dy + a_dx*b_y*c_z - a_dx*b_z*c_y - a_y*b_dx*c_z + a_y*b_z*c_dx + a_z*b_dx*c_y - a_z*b_y*c_dx - a_dz*b_x*d_y + a_dz*b_y*d_x + a_x*b_dz*d_y - a_x*b_y*d_dz - a_y*b_dz*d_x + a_y*b_x*d_dz + a_dy*b_x*d_z - a_dy*b_z*d_x - a_x*b_dy*d_z + a_x*b_z*d_dy + a_z*b_dy*d_x - a_z*b_x*d_dy - a_dx*b_y*d_z + a_dx*b_z*d_y + a_y*b_dx*d_z - a_y*b_z*d_dx - a_z*b_dx*d_y + a_z*b_y*d_dx + a_dz*c_x*d_y - a_dz*c_y*d_x - a_x*c_dz*d_y + a_x*c_y*d_dz + a_y*c_dz*d_x - a_y*c_x*d_dz - a_dy*c_x*d_z + a_dy*c_z*d_x + a_x*c_dy*d_z - a_x*c_z*d_dy - a_z*c_dy*d_x + a_z*c_x*d_dy + a_dx*c_y*d_z - a_dx*c_z*d_y - a_y*c_dx*d_z + a_y*c_z*d_dx + a_z*c_dx*d_y - a_z*c_y*d_dx - b_dz*c_x*d_y + b_dz*c_y*d_x + b_x*c_dz*d_y - b_x*c_y*d_dz - b_y*c_dz*d_x + b_y*c_x*d_dz + b_dy*c_x*d_z - b_dy*c_z*d_x - b_x*c_dy*d_z + b_x*c_z*d_dy + b_z*c_dy*d_x - b_z*c_x*d_dy - b_dx*c_y*d_z + b_dx*c_z*d_y + b_y*c_dx*d_z - b_y*c_z*d_dx - b_z*c_dx*d_y + b_z*c_y*d_dx; + + double d = a_x*b_y*c_z - a_x*b_z*c_y - a_y*b_x*c_z + a_y*b_z*c_x + a_z*b_x*c_y - a_z*b_y*c_x - a_x*b_y*d_z + a_x*b_z*d_y + a_y*b_x*d_z - a_y*b_z*d_x - a_z*b_x*d_y + a_z*b_y*d_x + a_x*c_y*d_z - a_x*c_z*d_y - a_y*c_x*d_z + a_y*c_z*d_x + a_z*c_x*d_y - a_z*c_y*d_x - b_x*c_y*d_z + b_x*c_z*d_y + b_y*c_x*d_z - b_y*c_z*d_x - b_z*c_x*d_y + b_z*c_y*d_x; + + if (std::abs(a)<=1.e-10) + { + return get_smallest_pos_quad_zero(b,c,d); + } + b/=a; c/=a; d/=a; // normalize it all + std::vector res(3); + int real_roots_num = SolveP3(res,b,c,d); + switch (real_roots_num) + { + case 1: + return (res[0] >= 0) ? res[0]:INFINITY; + case 2: + { + double max_root = std::max(res[0],res[1]); double min_root = std::min(res[0],res[1]); + if (min_root > 0) return min_root; + if (max_root > 0) return max_root; + return INFINITY; + } + case 3: + default: + { + std::sort(res.begin(),res.end()); + if (res[0] > 0) return res[0]; + if (res[1] > 0) return res[1]; + if (res[2] > 0) return res[2]; + return INFINITY; + } + } + } + + IGL_INLINE double compute_max_step_from_singularities(const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F, + Eigen::MatrixXd& d) + { + using namespace std; + double max_step = INFINITY; + + // The if statement is outside the for loops to avoid branching/ease parallelizing + if (uv.cols() == 2) + { + for (int f = 0; f < F.rows(); f++) + { + double min_positive_root = get_min_pos_root_2D(uv,F,d,f); + max_step = std::min(max_step, min_positive_root); + } + } + else + { // volumetric deformation + for (int f = 0; f < F.rows(); f++) + { + double min_positive_root = get_min_pos_root_3D(uv,F,d,f); + max_step = std::min(max_step, min_positive_root); + } + } + return max_step; + } + } +} + +IGL_INLINE double igl::flip_avoiding_line_search( + const Eigen::MatrixXi & F, + Eigen::MatrixXd& cur_v, + const Eigen::MatrixXd& dst_v, + std::function & energy, + double cur_energy) +{ + using namespace std; + Eigen::MatrixXd d = dst_v - cur_v; + + double min_step_to_singularity = igl::flip_avoiding::compute_max_step_from_singularities(cur_v,F,d); + double max_step_size = std::min(1., min_step_to_singularity*0.8); + + return igl::line_search(cur_v,d,max_step_size, energy, cur_energy); +} + +#ifdef IGL_STATIC_LIBRARY +#endif diff --git a/vendor/libigl/include/igl/flip_avoiding_line_search.h b/vendor/libigl/include/igl/flip_avoiding_line_search.h new file mode 100644 index 0000000000000000000000000000000000000000..c3a94dcec6710ae367d6ec83dd4a29deab0c2281 --- /dev/null +++ b/vendor/libigl/include/igl/flip_avoiding_line_search.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FLIP_AVOIDING_LINE_SEARCH_H +#define IGL_FLIP_AVOIDING_LINE_SEARCH_H +#include "igl_inline.h" +#include "PI.h" + +#include + +namespace igl +{ + // A bisection line search for a mesh based energy that avoids triangle flips as suggested in + // "Bijective Parameterization with Free Boundaries" (Smith J. and Schaefer S., 2015). + // + // The user specifies an initial vertices position (that has no flips) and target one (that my have flipped triangles). + // This method first computes the largest step in direction of the destination vertices that does not incur flips, + // and then minimizes a given energy using this maximal step and a bisection linesearch (see igl::line_search). + // + // Supports both triangle and tet meshes. + // + // Inputs: + // F #F by 3/4 list of mesh faces or tets + // cur_v #V by dim list of variables + // dst_v #V by dim list of target vertices. This mesh may have flipped triangles + // energy A function to compute the mesh-based energy (return an energy that is bigger than 0) + // cur_energy(OPTIONAL) The energy at the given point. Helps save redundant computations. + // This is optional. If not specified, the function will compute it. + // Outputs: + // cur_v #V by dim list of variables at the new location + // Returns the energy at the new point + IGL_INLINE double flip_avoiding_line_search( + const Eigen::MatrixXi & F, + Eigen::MatrixXd& cur_v, + const Eigen::MatrixXd& dst_v, + std::function & energy, + double cur_energy = -1); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "flip_avoiding_line_search.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/flip_edge.cpp b/vendor/libigl/include/igl/flip_edge.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7542a564b4fe99483d70db3538fe4a4665956514 --- /dev/null +++ b/vendor/libigl/include/igl/flip_edge.cpp @@ -0,0 +1,168 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Qingan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "flip_edge.h" + +template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType> +IGL_INLINE void igl::flip_edge( + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E, + const size_t uei) +{ + typedef typename DerivedF::Scalar Index; + const size_t num_faces = F.rows(); + assert(F.cols() == 3); + // Edge to flip [v1,v2] --> [v3,v4] + // Before: + // F(f1,:) = [v1,v2,v4] // in some cyclic order + // F(f2,:) = [v1,v3,v2] // in some cyclic order + // After: + // F(f1,:) = [v1,v3,v4] // in *this* order + // F(f2,:) = [v2,v4,v3] // in *this* order + // + // v1 v1 + // /|\ / \ + // / | \ /f1 \ + // v3 /f2|f1\ v4 => v3 /_____\ v4 + // \ | / \ f2 / + // \ | / \ / + // \|/ \ / + // v2 v2 + auto& half_edges = uE2E[uei]; + if (half_edges.size() != 2) { + throw "Cannot flip non-manifold or boundary edge"; + } + + const size_t f1 = half_edges[0] % num_faces; + const size_t f2 = half_edges[1] % num_faces; + const size_t c1 = half_edges[0] / num_faces; + const size_t c2 = half_edges[1] / num_faces; + assert(c1 < 3); + assert(c2 < 3); + + assert(f1 != f2); + const size_t v1 = F(f1, (c1+1)%3); + const size_t v2 = F(f1, (c1+2)%3); + const size_t v4 = F(f1, c1); + const size_t v3 = F(f2, c2); + assert(F(f2, (c2+2)%3) == v1); + assert(F(f2, (c2+1)%3) == v2); + + const size_t e_12 = half_edges[0]; + const size_t e_24 = f1 + ((c1 + 1) % 3) * num_faces; + const size_t e_41 = f1 + ((c1 + 2) % 3) * num_faces; + const size_t e_21 = half_edges[1]; + const size_t e_13 = f2 + ((c2 + 1) % 3) * num_faces; + const size_t e_32 = f2 + ((c2 + 2) % 3) * num_faces; + assert(E(e_12, 0) == v1); + assert(E(e_12, 1) == v2); + assert(E(e_24, 0) == v2); + assert(E(e_24, 1) == v4); + assert(E(e_41, 0) == v4); + assert(E(e_41, 1) == v1); + assert(E(e_21, 0) == v2); + assert(E(e_21, 1) == v1); + assert(E(e_13, 0) == v1); + assert(E(e_13, 1) == v3); + assert(E(e_32, 0) == v3); + assert(E(e_32, 1) == v2); + + const size_t ue_24 = EMAP(e_24); + const size_t ue_41 = EMAP(e_41); + const size_t ue_13 = EMAP(e_13); + const size_t ue_32 = EMAP(e_32); + + F(f1, 0) = v1; + F(f1, 1) = v3; + F(f1, 2) = v4; + F(f2, 0) = v2; + F(f2, 1) = v4; + F(f2, 2) = v3; + + uE(uei, 0) = v3; + uE(uei, 1) = v4; + + const size_t new_e_34 = f1; + const size_t new_e_41 = f1 + num_faces; + const size_t new_e_13 = f1 + num_faces*2; + const size_t new_e_43 = f2; + const size_t new_e_32 = f2 + num_faces; + const size_t new_e_24 = f2 + num_faces*2; + + E(new_e_34, 0) = v3; + E(new_e_34, 1) = v4; + E(new_e_41, 0) = v4; + E(new_e_41, 1) = v1; + E(new_e_13, 0) = v1; + E(new_e_13, 1) = v3; + E(new_e_43, 0) = v4; + E(new_e_43, 1) = v3; + E(new_e_32, 0) = v3; + E(new_e_32, 1) = v2; + E(new_e_24, 0) = v2; + E(new_e_24, 1) = v4; + + EMAP(new_e_34) = uei; + EMAP(new_e_43) = uei; + EMAP(new_e_41) = ue_41; + EMAP(new_e_13) = ue_13; + EMAP(new_e_32) = ue_32; + EMAP(new_e_24) = ue_24; + + auto replace = [](std::vector& array, Index old_v, Index new_v) { + std::replace(array.begin(), array.end(), old_v, new_v); + }; + replace(uE2E[uei], e_12, new_e_34); + replace(uE2E[uei], e_21, new_e_43); + replace(uE2E[ue_13], e_13, new_e_13); + replace(uE2E[ue_32], e_32, new_e_32); + replace(uE2E[ue_24], e_24, new_e_24); + replace(uE2E[ue_41], e_41, new_e_41); + +#ifndef NDEBUG + auto sanity_check = [&](size_t ue) { + const auto& adj_faces = uE2E[ue]; + if (adj_faces.size() == 2) { + const size_t first_f = adj_faces[0] % num_faces; + const size_t first_c = adj_faces[0] / num_faces; + const size_t second_f = adj_faces[1] % num_faces; + const size_t second_c = adj_faces[1] / num_faces; + const size_t vertex_0 = F(first_f, (first_c+1) % 3); + const size_t vertex_1 = F(first_f, (first_c+2) % 3); + assert(vertex_0 == F(second_f, (second_c+2) % 3)); + assert(vertex_1 == F(second_f, (second_c+1) % 3)); + } + }; + + sanity_check(uei); + sanity_check(ue_13); + sanity_check(ue_32); + sanity_check(ue_24); + sanity_check(ue_41); +#endif +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::flip_edge, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&, unsigned long); +template void igl::flip_edge, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&, const size_t); +#ifdef WIN32 +template void igl::flip_edge, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&, unsigned __int64); +template void igl::flip_edge,class Eigen::Matrix,class Eigen::Matrix,class Eigen::Matrix,int>(class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class std::vector >,class std::allocator > > > &,unsigned __int64); +#endif +#endif diff --git a/vendor/libigl/include/igl/flip_edge.h b/vendor/libigl/include/igl/flip_edge.h new file mode 100644 index 0000000000000000000000000000000000000000..3c43198a6e65afb43d9fc251dacb2b63d21875ed --- /dev/null +++ b/vendor/libigl/include/igl/flip_edge.h @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Qingan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_FLIP_EDGE_H +#define IGL_FLIP_EDGE_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Flip an edge in a triangle mesh. The edge specified by uei must have + // exactly **two** adjacent faces. Violation will result in exception. + // Another warning: edge flipping could convert manifold mesh into + // non-manifold. + // + // Inputs: + // F #F by 3 list of triangles. + // E #F*3 by 2 list of all of directed edges + // uE #uE by 2 list of unique undirected edges + // EMAP #F*3 list of indices into uE, mapping each directed edge to unique + // undirected edge + // uE2E #uE list of lists of indices into E of coexisting edges + // ue index into uE the edge to be flipped. + // + // Output: + // Updated F, E, uE, EMAP and uE2E. + template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType> + IGL_INLINE void flip_edge( + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E, + const size_t uei); +} + +#ifndef IGL_STATIC_LIBRARY +# include "flip_edge.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/flipped_triangles.cpp b/vendor/libigl/include/igl/flipped_triangles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..775366e79805f9a7f5380a62f7f3982e56100d8a --- /dev/null +++ b/vendor/libigl/include/igl/flipped_triangles.cpp @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "flipped_triangles.h" + +#include "list_to_matrix.h" +#include +template +IGL_INLINE void igl::flipped_triangles( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & X) +{ + assert(V.cols() == 2 && "V should contain 2D positions"); + std::vector flip_idx; + for (int i = 0; i < F.rows(); i++) + { + // https://www.cs.cmu.edu/~quake/robust.html + typedef Eigen::Matrix RowVector2S; + RowVector2S v1_n = V.row(F(i,0)); + RowVector2S v2_n = V.row(F(i,1)); + RowVector2S v3_n = V.row(F(i,2)); + Eigen::Matrix T2_Homo; + T2_Homo.col(0) << v1_n(0),v1_n(1),1.; + T2_Homo.col(1) << v2_n(0),v2_n(1),1.; + T2_Homo.col(2) << v3_n(0),v3_n(1),1.; + double det = T2_Homo.determinant(); + assert(det == det && "det should not be NaN"); + if (det < 0) + { + flip_idx.push_back(i); + } + } + igl::list_to_matrix(flip_idx,X); +} + +template +IGL_INLINE Eigen::VectorXi igl::flipped_triangles( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F) +{ + Eigen::VectorXi X; + flipped_triangles(V,F,X); + return X; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::flipped_triangles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template Eigen::Matrix igl::flipped_triangles, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/flipped_triangles.h b/vendor/libigl/include/igl/flipped_triangles.h new file mode 100644 index 0000000000000000000000000000000000000000..2d119921fc156fd651554764832af72b99311cb5 --- /dev/null +++ b/vendor/libigl/include/igl/flipped_triangles.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FLIPPED_TRIANGLES_H +#define IGL_FLIPPED_TRIANGLES_H +#include "igl_inline.h" + +#include +namespace igl +{ + // Finds the ids of the flipped triangles of the mesh V,F in the UV mapping uv + // + // Inputs: + // V #V by 2 list of mesh vertex positions + // F #F by 3 list of mesh faces (must be triangles) + // Outputs: + // X #flipped list of containing the indices into F of the flipped triangles + // Wrapper with return type + template + IGL_INLINE void flipped_triangles( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & X); + template + IGL_INLINE Eigen::VectorXi flipped_triangles( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "flipped_triangles.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/floor.cpp b/vendor/libigl/include/igl/floor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7538b7e01d1d263ac261a9cfb82bb4a791779f7b --- /dev/null +++ b/vendor/libigl/include/igl/floor.cpp @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "floor.h" +#include +#include + +template < typename DerivedX, typename DerivedY> +IGL_INLINE void igl::floor( + const Eigen::PlainObjectBase& X, + Eigen::PlainObjectBase& Y) +{ + using namespace std; + //Y = DerivedY::Zero(m,n); +//#pragma omp parallel for + //for(int i = 0;iScalar{return std::floor(x);}).template cast(); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::floor, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::floor, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::floor, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/floor.h b/vendor/libigl/include/igl/floor.h new file mode 100644 index 0000000000000000000000000000000000000000..a84d52068a19c5058798a2b754ea96d825882e3d --- /dev/null +++ b/vendor/libigl/include/igl/floor.h @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FLOOR_H +#define IGL_FLOOR_H +#include "igl_inline.h" +#include +namespace igl +{ + // Floor a given matrix to nearest integers + // + // Inputs: + // X m by n matrix of scalars + // Outputs: + // Y m by n matrix of floored integers + template < typename DerivedX, typename DerivedY> + IGL_INLINE void floor( + const Eigen::PlainObjectBase& X, + Eigen::PlainObjectBase& Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "floor.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/for_each.h b/vendor/libigl/include/igl/for_each.h new file mode 100644 index 0000000000000000000000000000000000000000..6ba03ba1c19ce4800a28db61f2c3cbe5ea9fb096 --- /dev/null +++ b/vendor/libigl/include/igl/for_each.h @@ -0,0 +1,78 @@ +#ifndef IGL_FOR_EACH_H +#define IGL_FOR_EACH_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // FOR_EACH Call a given function for each non-zero (i.e., explicit value + // might actually be ==0) in a Sparse Matrix A _in order (of storage)_. This is + // useless unless func has _side-effects_. + // + // Inputs: + // A m by n SparseMatrix + // func function handle with prototype "compatible with" `void (Index i, + // Index j, Scalar & v)`. Return values will be ignored. + // + // See also: std::for_each + template + inline void for_each( + const Eigen::SparseMatrix & A, + const Func & func); + template + inline void for_each( + const Eigen::DenseBase & A, + const Func & func); +} + +// Implementation + +template +inline void igl::for_each( + const Eigen::SparseMatrix & A, + const Func & func) +{ + // Can **not** use parallel for because this must be _in order_ + // Iterate over outside + for(int k=0; k::InnerIterator it (A,k); it; ++it) + { + func(it.row(),it.col(),it.value()); + } + } +} + +template +inline void igl::for_each( + const Eigen::DenseBase & A, + const Func & func) +{ + // Can **not** use parallel for because this must be _in order_ + if(A.IsRowMajor) + { + for(typename DerivedA::Index i = 0;i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "frame_to_cross_field.h" +#include +#include + +IGL_INLINE void igl::frame_to_cross_field( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& FF1, + const Eigen::MatrixXd& FF2, + Eigen::MatrixXd& X) +{ + using namespace Eigen; + + // Generate local basis + MatrixXd B1, B2, B3; + + igl::local_basis(V,F,B1,B2,B3); + + // Project the frame fields in the local basis + MatrixXd d1, d2; + d1.resize(F.rows(),2); + d2.resize(F.rows(),2); + + d1 << igl::dot_row(B1,FF1), igl::dot_row(B2,FF1); + d2 << igl::dot_row(B1,FF2), igl::dot_row(B2,FF2); + + X.resize(F.rows(), 3); + + for (int i=0;i > svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV ); + Matrix2d C = svd.matrixU() * svd.matrixV().transpose(); + + Vector2d v = C.col(0); + X.row(i) = v(0) * B1.row(i) + v(1) * B2.row(i); + } +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/frame_to_cross_field.h b/vendor/libigl/include/igl/frame_to_cross_field.h new file mode 100644 index 0000000000000000000000000000000000000000..f9bdd3d5f252f028449d28b42663d1e0662e1d10 --- /dev/null +++ b/vendor/libigl/include/igl/frame_to_cross_field.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FRAME_TO_CROSS_FIELD_H +#define IGL_FRAME_TO_CROSS_FIELD_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Convert a frame field into its closest cross field + // Inputs: + // V #V by 3 coordinates of the vertices + // F #F by 3 list of mesh faces (must be triangles) + // FF1 #F by 3 the first representative vector of the frame field (up to permutation and sign) + // FF2 #F by 3 the second representative vector of the frame field (up to permutation and sign) + // + // Outputs: + // X #F by 3 representative vector of the closest cross field + // + IGL_INLINE void frame_to_cross_field( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& FF1, + const Eigen::MatrixXd& FF2, + Eigen::MatrixXd& X); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "frame_to_cross_field.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/frustum.cpp b/vendor/libigl/include/igl/frustum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2926106e63a488b99d3f75b83185c4aa9a8e7fb1 --- /dev/null +++ b/vendor/libigl/include/igl/frustum.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "frustum.h" +template < typename DerivedP> +IGL_INLINE void igl::frustum( + const typename DerivedP::Scalar left, + const typename DerivedP::Scalar right, + const typename DerivedP::Scalar bottom, + const typename DerivedP::Scalar top, + const typename DerivedP::Scalar nearVal, + const typename DerivedP::Scalar farVal, + Eigen::PlainObjectBase & P) +{ + P.setConstant(4,4,0.); + P(0,0) = (2.0 * nearVal) / (right - left); + P(1,1) = (2.0 * nearVal) / (top - bottom); + P(0,2) = (right + left) / (right - left); + P(1,2) = (top + bottom) / (top - bottom); + P(2,2) = -(farVal + nearVal) / (farVal - nearVal); + P(3,2) = -1.0; + P(2,3) = -(2.0 * farVal * nearVal) / (farVal - nearVal); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::frustum >(Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/frustum.h b/vendor/libigl/include/igl/frustum.h new file mode 100644 index 0000000000000000000000000000000000000000..4a92e1a8197f188ad664a546cf13847bad7535b5 --- /dev/null +++ b/vendor/libigl/include/igl/frustum.h @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_FRUSTUM_H +#define IGL_FRUSTUM_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Implementation of the deprecated glFrustum function. + // + // Inputs: + // left coordinate of left vertical clipping plane + // right coordinate of right vertical clipping plane + // bottom coordinate of bottom vertical clipping plane + // top coordinate of top vertical clipping plane + // nearVal distance to near plane + // farVal distance to far plane + // Outputs: + // P 4x4 perspective matrix + template < typename DerivedP> + IGL_INLINE void frustum( + const typename DerivedP::Scalar left, + const typename DerivedP::Scalar right, + const typename DerivedP::Scalar bottom, + const typename DerivedP::Scalar top, + const typename DerivedP::Scalar nearVal, + const typename DerivedP::Scalar farVal, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "frustum.cpp" +#endif + +#endif + + diff --git a/vendor/libigl/include/igl/gaussian_curvature.cpp b/vendor/libigl/include/igl/gaussian_curvature.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a0a1f8714b6047789f2594e7872e0b5c607448b --- /dev/null +++ b/vendor/libigl/include/igl/gaussian_curvature.cpp @@ -0,0 +1,56 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "gaussian_curvature.h" +#include "internal_angles.h" +#include "PI.h" +#include +template +IGL_INLINE void igl::gaussian_curvature( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & K) +{ + using namespace Eigen; + using namespace std; + // internal corner angles + Matrix< + typename DerivedV::Scalar, + DerivedF::RowsAtCompileTime, + DerivedF::ColsAtCompileTime> A; + internal_angles(V,F,A); + K.resize(V.rows(),1); + K.setConstant(V.rows(),1,2.*PI); + assert(A.rows() == F.rows()); + assert(A.cols() == F.cols()); + assert(K.rows() == V.rows()); + assert(F.maxCoeff() < V.rows()); + assert(K.cols() == 1); + const int Frows = F.rows(); + //K_G(x_i) = (2π - ∑θj) +//#ifndef IGL_GAUSSIAN_CURVATURE_OMP_MIN_VALUE +//# define IGL_GAUSSIAN_CURVATURE_OMP_MIN_VALUE 1000 +//#endif +//#pragma omp parallel for if (Frows>IGL_GAUSSIAN_CURVATURE_OMP_MIN_VALUE) + for(int f = 0;f, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::gaussian_curvature, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/get_seconds.cpp b/vendor/libigl/include/igl/get_seconds.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fac4a3a691893b16f807f10dac8c26c004642d46 --- /dev/null +++ b/vendor/libigl/include/igl/get_seconds.cpp @@ -0,0 +1,15 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "get_seconds.h" +#include +IGL_INLINE double igl::get_seconds() +{ + return + std::chrono::duration( + std::chrono::system_clock::now().time_since_epoch()).count(); +} diff --git a/vendor/libigl/include/igl/get_seconds.h b/vendor/libigl/include/igl/get_seconds.h new file mode 100644 index 0000000000000000000000000000000000000000..411d6e41de60779d9bef58860e1ec3a16fd181a7 --- /dev/null +++ b/vendor/libigl/include/igl/get_seconds.h @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_GET_SECONDS_H +#define IGL_GET_SECONDS_H +#include "igl_inline.h" + +namespace igl +{ + // Return the current time in seconds since program start + // + // Example: + // const auto & tictoc = []() + // { + // static double t_start = igl::get_seconds(); + // double diff = igl::get_seconds()-t_start; + // t_start += diff; + // return diff; + // }; + // tictoc(); + // ... // part 1 + // cout<<"part 1: "< +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_GRAD_H +#define IGL_GRAD_H +#include "igl_inline.h" + +#include +#include + +namespace igl { + // GRAD + // G = grad(V,F) + // + // Compute the numerical gradient operator + // + // Inputs: + // V #vertices by 3 list of mesh vertex positions + // F #faces by 3 list of mesh face indices [or a #faces by 4 list of tetrahedral indices] + // uniform boolean (default false) - Use a uniform mesh instead of the vertices V + // Outputs: + // G #faces*dim by #V Gradient operator + // + + // Gradient of a scalar function defined on piecewise linear elements (mesh) + // is constant on each triangle [tetrahedron] i,j,k: + // grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A + // where Xi is the scalar value at vertex i, Vi is the 3D position of vertex + // i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of + // 90 degrees + // + template + IGL_INLINE void grad( + const Eigen::MatrixBase&V, + const Eigen::MatrixBase&F, + Eigen::SparseMatrix &G, + bool uniform = false); +} +#ifndef IGL_STATIC_LIBRARY +# include "grad.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/grad_intrinsic.cpp b/vendor/libigl/include/igl/grad_intrinsic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..001b2d2f3e255bcaadd984c926ee97ea0c62f827 --- /dev/null +++ b/vendor/libigl/include/igl/grad_intrinsic.cpp @@ -0,0 +1,78 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "grad_intrinsic.h" +#include "grad.h" + +template +IGL_INLINE void igl::grad_intrinsic( + const Eigen::MatrixBase&l, + const Eigen::MatrixBase&F, + Eigen::SparseMatrix &G) +{ + assert(F.cols() ==3 && "Only triangles supported"); + // number of vertices + const int n = F.maxCoeff()+1; + // number of faces + const int m = F.rows(); + // JD: There is a pretty subtle bug when using a fixed column size for this matrix. + // When calling igl::grad(V, ...), the two code paths `grad_tet` and `grad_tri` + // will be compiled. It turns out that `igl::grad_tet` calls `igl::volume`, which + // reads the coordinates of the `V` matrix into `RowVector3d`. If the matrix `V` + // has a known compile-time size of 2, this produces a compilation error when + // libigl is compiled in header-only mode. In static mode this doesn't happen + // because the matrix `V` is probably implicitly copied into a `Eigen::MatrixXd`. + // This is a situation that could be solved using `if constexpr` in C++17. + // In C++11, the alternative is to use SFINAE and `std::enable_if` (ugh). + typedef Eigen::Matrix MatrixX2S; + MatrixX2S V2 = MatrixX2S::Zero(3*m,2); + // 1=[x,y] + // /\ + // l3 / \ l2 + // / \ + // / \ + // 2-----------3 + // l1 + // + // x = (l2²-l1²-l3²)/(-2*l1) + // y = sqrt(l3² - x²) + // + // + // Place 3rd vertex at [l(:,1) 0] + V2.block(2*m,0,m,1) = l.col(0); + // Place second vertex at [0 0] + // Place third vertex at [x y] + V2.block(0,0,m,1) = + (l.col(1).cwiseAbs2()-l.col(0).cwiseAbs2()-l.col(2).cwiseAbs2()).array()/ + (-2.*l.col(0)).array(); + V2.block(0,1,m,1) = + (l.col(2).cwiseAbs2() - V2.block(0,0,m,1).cwiseAbs2()).array().sqrt(); + DerivedF F2(F.rows(),F.cols()); + std::vector > Pijv; + Pijv.reserve(F.size()); + for(int f = 0;f P(m*3,n); + P.setFromTriplets(Pijv.begin(),Pijv.end()); + Eigen::SparseMatrix G2; + grad(V2,F2,G2); + G = G2*P; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::grad_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::grad_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/grad_intrinsic.h b/vendor/libigl/include/igl/grad_intrinsic.h new file mode 100644 index 0000000000000000000000000000000000000000..9633b8803bcbd8c248e7e6522d5250fbb7a2101f --- /dev/null +++ b/vendor/libigl/include/igl/grad_intrinsic.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_GRAD_INTRINSIC_H +#define IGL_GRAD_INTRINSIC_H +#include "igl_inline.h" + +#include +#include + +namespace igl { + // GRAD_INTRINSIC Construct an intrinsic gradient operator. + // + // Inputs: + // l #F by 3 list of edge lengths + // F #F by 3 list of triangle indices into some vertex list V + // Outputs: + // G #F*2 by #V gradient matrix: G=[Gx;Gy] where x runs along the 23 edge and + // y runs in the counter-clockwise 90° rotation. + template + IGL_INLINE void grad_intrinsic( + const Eigen::MatrixBase&l, + const Eigen::MatrixBase&F, + Eigen::SparseMatrix &G); +} +#ifndef IGL_STATIC_LIBRARY +# include "grad_intrinsic.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/grid.cpp b/vendor/libigl/include/igl/grid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83fb0bf3797ca423c56b981400edb16a35914d24 --- /dev/null +++ b/vendor/libigl/include/igl/grid.cpp @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "grid.h" +#include + +template < + typename Derivedres, + typename DerivedGV> +IGL_INLINE void igl::grid( + const Eigen::MatrixBase & res, + Eigen::PlainObjectBase & GV) +{ + using namespace Eigen; + typedef typename DerivedGV::Scalar Scalar; + GV.resize(res.array().prod(),res.size()); + const auto lerp = + [&res](const Scalar di, const int d)->Scalar{return di/(Scalar)(res(d)-1);}; + int gi = 0; + Derivedres sub; + sub.resizeLike(res); + sub.setConstant(0); + for(int gi = 0;gi=res(c)) + { + sub(c) = 0; + // roll over + sub(c+1)++; + } + } + for(int c = 0;c, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::grid, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/grid_search.cpp b/vendor/libigl/include/igl/grid_search.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93cbc0ddea3aca190845020ac0fcf1041abe55c9 --- /dev/null +++ b/vendor/libigl/include/igl/grid_search.cpp @@ -0,0 +1,64 @@ +#include "grid_search.h" +#include +#include + +template < + typename Scalar, + typename DerivedX, + typename DerivedLB, + typename DerivedUB, + typename DerivedI> +IGL_INLINE Scalar igl::grid_search( + const std::function< Scalar (DerivedX &) > f, + const Eigen::MatrixBase & LB, + const Eigen::MatrixBase & UB, + const Eigen::MatrixBase & I, + DerivedX & X) +{ + Scalar fval = std::numeric_limits::max(); + const int dim = LB.size(); + assert(UB.size() == dim && "UB should match LB size"); + assert(I.size() == dim && "I should match LB size"); + X.resize(dim); + + // Working X value + DerivedX Xrun(dim); + std::function looper; + int calls = 0; + looper = [&]( + const int d, + DerivedX & Xrun) + { + assert(d < dim); + Eigen::Matrix vals = + Eigen::Matrix::LinSpaced(I(d),LB(d),UB(d)); + for(int c = 0;c, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::function&)>, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix&); +template float igl::grid_search, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::function&)>, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/grid_search.h b/vendor/libigl/include/igl/grid_search.h new file mode 100644 index 0000000000000000000000000000000000000000..83a86663e81560ee30a6f759a86ba273d9ffd0e7 --- /dev/null +++ b/vendor/libigl/include/igl/grid_search.h @@ -0,0 +1,42 @@ +#ifndef IGL_GRID_SEARCH_H +#define IGL_GRID_SEARCH_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Solve the problem: + // + // minimize f(x) + // subject to lb ≤ x ≤ ub + // + // by exhaustive grid search. + // + // Inputs: + // f function to minimize + // LB #X vector of finite lower bounds + // UB #X vector of finite upper bounds + // I #X vector of number of steps for each variable + // Outputs: + // X #X optimal parameter vector + // Returns f(X) + // + template < + typename Scalar, + typename DerivedX, + typename DerivedLB, + typename DerivedUB, + typename DerivedI> + IGL_INLINE Scalar grid_search( + const std::function< Scalar (DerivedX &) > f, + const Eigen::MatrixBase & LB, + const Eigen::MatrixBase & UB, + const Eigen::MatrixBase & I, + DerivedX & X); +} + +#ifndef IGL_STATIC_LIBRARY +# include "grid_search.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/guess_extension.cpp b/vendor/libigl/include/igl/guess_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc9b663750c830f844f05842ba522c63c122a75d --- /dev/null +++ b/vendor/libigl/include/igl/guess_extension.cpp @@ -0,0 +1,100 @@ +#include "guess_extension.h" + +#include + +#include "is_stl.h" + +IGL_INLINE void igl::guess_extension(FILE * fp, std::string & guess) +{ + const auto is_off = [](FILE * fp)-> bool + { + char header[1000]; + const std::string OFF("OFF"); + const std::string NOFF("NOFF"); + const std::string COFF("COFF"); + bool f = (fscanf(fp,"%s\n",header)==1 && ( + std::string(header).compare(0, OFF.length(), OFF)==0 || + std::string(header).compare(0, COFF.length(), COFF)==0 || + std::string(header).compare(0,NOFF.length(),NOFF)==0)); + rewind(fp); + return f; + }; + const auto is_ply = [](FILE * fp) -> bool + { + char header[1000]; + const std::string PLY("ply"); + bool f = (fscanf(fp,"%s\n",header)==1 && (std::string(header).compare(0, PLY.length(), PLY)==0 )); + rewind(fp); + return f; + }; + const auto is_wrl = [](FILE * wrl_file)->bool + { + bool still_comments = true; + char line[1000]; + std::string needle("point ["); + std::string haystack; + while(still_comments) + { + if(fgets(line,1000,wrl_file) == NULL) + { + rewind(wrl_file); + return false; + } + haystack = std::string(line); + still_comments = std::string::npos == haystack.find(needle); + } + rewind(wrl_file); + return true; + }; + const auto is_mesh = [](FILE * mesh_file )->bool + { + char line[2048]; + // eat comments at beginning of file + bool still_comments= true; + while(still_comments) + { + if(fgets(line,2048,mesh_file) == NULL) + { + rewind(mesh_file); + return false; + } + still_comments = (line[0] == '#' || line[0] == '\n'); + } + char str[2048]; + sscanf(line," %s",str); + // check that first word is MeshVersionFormatted + if(0!=strcmp(str,"MeshVersionFormatted")) + { + rewind(mesh_file); + return false; + } + rewind(mesh_file); + return true; + }; + guess = "obj"; + if(is_mesh(fp)) + { + guess = "mesh"; + }else if(is_off(fp)) + { + guess = "off"; + }else if(is_ply(fp)) + { + guess = "ply"; + }else if(igl::is_stl(fp)) + { + guess = "stl"; + }else if(is_wrl(fp)) + { + guess = "wrl"; + } + // else obj + rewind(fp); +} + +IGL_INLINE std::string igl::guess_extension(FILE * fp) +{ + std::string guess; + guess_extension(fp,guess); + return guess; +} diff --git a/vendor/libigl/include/igl/guess_extension.h b/vendor/libigl/include/igl/guess_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..77df6f523b7f75e721031866295f28f3d1eb8263 --- /dev/null +++ b/vendor/libigl/include/igl/guess_extension.h @@ -0,0 +1,25 @@ +#ifndef IGL_GUESS_EXTENSION_H +#define IGL_GUESS_EXTENSION_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Given a file pointer at the beginning of a "mesh" file, try to guess the + // extension of the file format it comes from. The file pointer is rewound on + // return. + // + // Inputs: + // fp file pointer (see output) + // Outputs: + // fp file pointer rewound + // guess extension as string. One of "mesh",{"obj"},"off","ply","stl", or + // "wrl" + // + IGL_INLINE void guess_extension(FILE * fp, std::string & guess); + IGL_INLINE std::string guess_extension(FILE * fp); +} +#ifndef IGL_STATIC_LIBRARY +# include "guess_extension.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/harmonic.h b/vendor/libigl/include/igl/harmonic.h new file mode 100644 index 0000000000000000000000000000000000000000..76d699efc89ea9406cebc2208a5aacb0c4643775 --- /dev/null +++ b/vendor/libigl/include/igl/harmonic.h @@ -0,0 +1,122 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_HARMONIC_H +#define IGL_HARMONIC_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Compute k-harmonic weight functions "coordinates". + // + // + // Inputs: + // V #V by dim vertex positions + // F #F by simplex-size list of element indices + // b #b boundary indices into V + // bc #b by #W list of boundary values + // k power of harmonic operation (1: harmonic, 2: biharmonic, etc) + // Outputs: + // W #V by #W list of weights + // + template < + typename DerivedV, + typename DerivedF, + typename Derivedb, + typename Derivedbc, + typename DerivedW> + IGL_INLINE bool harmonic( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + const int k, + Eigen::PlainObjectBase & W); + // Compute harmonic map using uniform laplacian operator + // + // Inputs: + // F #F by simplex-size list of element indices + // b #b boundary indices into V + // bc #b by #W list of boundary values + // k power of harmonic operation (1: harmonic, 2: biharmonic, etc) + // Outputs: + // W #V by #W list of weights + // + template < + typename DerivedF, + typename Derivedb, + typename Derivedbc, + typename DerivedW> + IGL_INLINE bool harmonic( + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + const int k, + Eigen::PlainObjectBase & W); + // Compute a harmonic map using a given Laplacian and mass matrix + // + // Inputs: + // L #V by #V discrete (integrated) Laplacian + // M #V by #V mass matrix + // b #b boundary indices into V + // bc #b by #W list of boundary values + // k power of harmonic operation (1: harmonic, 2: biharmonic, etc) + // Outputs: + // W #V by #V list of weights + template < + typename DerivedL, + typename DerivedM, + typename Derivedb, + typename Derivedbc, + typename DerivedW> + IGL_INLINE bool harmonic( + const Eigen::SparseCompressedBase & L, + const Eigen::SparseCompressedBase & M, + const Eigen::MatrixBase & b, + const Eigen::MatrixBase & bc, + const int k, + Eigen::PlainObjectBase & W); + // Build the discrete k-harmonic operator (computing integrated quantities). + // That is, if the k-harmonic PDE is Q x = 0, then this minimizes x' Q x + // + // Inputs: + // L #V by #V discrete (integrated) Laplacian + // M #V by #V mass matrix + // k power of harmonic operation (1: harmonic, 2: biharmonic, etc) + // Outputs: + // Q #V by #V discrete (integrated) k-Laplacian + template < + typename DerivedL, + typename DerivedM, + typename DerivedQ> + IGL_INLINE void harmonic( + const Eigen::SparseCompressedBase & L, + const Eigen::SparseCompressedBase & M, + const int k, + DerivedQ & Q); + // Inputs: + // V #V by dim vertex positions + // F #F by simplex-size list of element indices + // k power of harmonic operation (1: harmonic, 2: biharmonic, etc) + // Outputs: + // Q #V by #V discrete (integrated) k-Laplacian + template < + typename DerivedV, + typename DerivedF, + typename DerivedQ> + IGL_INLINE void harmonic( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const int k, + DerivedQ & Q); +}; + +#ifndef IGL_STATIC_LIBRARY +#include "harmonic.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/harwell_boeing.cpp b/vendor/libigl/include/igl/harwell_boeing.cpp new file mode 100644 index 0000000000000000000000000000000000000000..895416510cdd2182be5cef864cb8c40b483706c6 --- /dev/null +++ b/vendor/libigl/include/igl/harwell_boeing.cpp @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "harwell_boeing.h" + +template +IGL_INLINE void igl::harwell_boeing( + const Eigen::SparseMatrix & A, + int & num_rows, + std::vector & V, + std::vector & R, + std::vector & C) +{ + num_rows = A.rows(); + int num_cols = A.cols(); + int nnz = A.nonZeros(); + V.resize(nnz); + R.resize(nnz); + C.resize(num_cols+1); + + // Assumes outersize is columns + assert(A.cols() == A.outerSize()); + int column_pointer = 0; + int i = 0; + int k = 0; + // Iterate over outside + for(; k::InnerIterator it (A,k); it; ++it) + { + V[i] = it.value(); + R[i] = it.row(); + i++; + // Also increment column pointer + column_pointer++; + } + } + // by convention C[num_cols] = nnz + C[k] = column_pointer; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::harwell_boeing(Eigen::SparseMatrix const&, int&, std::vector >&, std::vector >&, std::vector >&); +#endif diff --git a/vendor/libigl/include/igl/hausdorff.cpp b/vendor/libigl/include/igl/hausdorff.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a6058cb75bf1c79f056925c19fec9aa101dab79 --- /dev/null +++ b/vendor/libigl/include/igl/hausdorff.cpp @@ -0,0 +1,90 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "hausdorff.h" +#include "point_mesh_squared_distance.h" + +template < + typename DerivedVA, + typename DerivedFA, + typename DerivedVB, + typename DerivedFB, + typename Scalar> +IGL_INLINE void igl::hausdorff( + const Eigen::MatrixBase & VA, + const Eigen::MatrixBase & FA, + const Eigen::MatrixBase & VB, + const Eigen::MatrixBase & FB, + Scalar & d) +{ + using namespace Eigen; + assert(VA.cols() == 3 && "VA should contain 3d points"); + assert(FA.cols() == 3 && "FA should contain triangles"); + assert(VB.cols() == 3 && "VB should contain 3d points"); + assert(FB.cols() == 3 && "FB should contain triangles"); + Matrix sqr_DBA, sqr_DAB; + Matrix I; + Matrix C; + point_mesh_squared_distance(VB,VA,FA,sqr_DBA,I,C); + point_mesh_squared_distance(VA,VB,FB,sqr_DAB,I,C); + const Scalar dba = sqr_DBA.maxCoeff(); + const Scalar dab = sqr_DAB.maxCoeff(); + d = sqrt(std::max(dba,dab)); +} + +template < + typename DerivedV, + typename Scalar> +IGL_INLINE void igl::hausdorff( + const Eigen::MatrixBase& V, + const std::function & dist_to_B, + Scalar & l, + Scalar & u) +{ + // e 3-long vector of opposite edge lengths + Eigen::Matrix e; + // Maximum edge length + Scalar e_max = 0; + for(int i=0;i<3;i++) + { + e(i) = (V.row((i+1)%3)-V.row((i+2)%3)).norm(); + e_max = std::max(e_max,e(i)); + } + // Semiperimeter + const Scalar s = (e(0)+e(1)+e(2))*0.5; + // Area + const Scalar A = sqrt(s*(s-e(0))*(s-e(1))*(s-e(2))); + // Circumradius + const Scalar R = e(0)*e(1)*e(2)/(4.*A); + // inradius + const Scalar r = A/s; + // Initialize lower bound to ∞ + l = std::numeric_limits::infinity(); + // d 3-long vector of distance from each corner to B + Eigen::Matrix d; + Scalar u1 = std::numeric_limits::infinity(); + Scalar u2 = 0; + for(int i=0;i<3;i++) + { + d(i) = dist_to_B(V(i,0),V(i,1),V(i,2)); + // Lower bound is simply the max over vertex distances + l = std::max(d(i),l); + // u1 is the minimum of corner distances + maximum adjacent edge + u1 = std::min(u1,d(i) + std::max(e((i+1)%3),e((i+2)%3))); + // u2 first takes the maximum over corner distances + u2 = std::max(u2,d(i)); + } + // u2 is the distance from the circumcenter/midpoint of obtuse edge plus the + // largest corner distance + u2 += (s-r>2.*R ? R : 0.5*e_max); + u = std::min(u1,u2); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::hausdorff, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double&); +template void igl::hausdorff, double>(Eigen::MatrixBase > const&, std::function const&, double&, double&); +#endif diff --git a/vendor/libigl/include/igl/hausdorff.h b/vendor/libigl/include/igl/hausdorff.h new file mode 100644 index 0000000000000000000000000000000000000000..7672f33f95aae549ae6ba84603a1d28107193f70 --- /dev/null +++ b/vendor/libigl/include/igl/hausdorff.h @@ -0,0 +1,86 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_HAUSDORFF_H +#define IGL_HAUSDORFF_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // HAUSDORFF compute the Hausdorff distance between mesh (VA,FA) and mesh + // (VB,FB). This is the + // + // d(A,B) = max ( max min d(a,b) , max min d(b,a) ) + // a∈A b∈B b∈B a∈A + // + // Known issue: This is only computing max(min(va,B),min(vb,A)). This is + // better than max(min(va,Vb),min(vb,Va)). This (at least) is missing + // "edge-edge" cases like the distance between the two different + // triangulations of a non-planar quad in 3D. Even simpler, consider the + // Hausdorff distance between the non-convex, block letter V polygon (with 7 + // vertices) in 2D and its convex hull. The Hausdorff distance is defined by + // the midpoint in the middle of the segment across the concavity and some + // non-vertex point _on the edge_ of the V. + // Known issue: due to the issue above, this also means that unreferenced + // vertices can give unexpected results. Therefore, we assume the inputs have + // no unreferenced vertices. + // + // Inputs: + // VA #VA by 3 list of vertex positions + // FA #FA by 3 list of face indices into VA + // VB #VB by 3 list of vertex positions + // FB #FB by 3 list of face indices into VB + // Outputs: + // d hausdorff distance + // //pair 2 by 3 list of "determiner points" so that pair(1,:) is from A + // // and pair(2,:) is from B + // + template < + typename DerivedVA, + typename DerivedFA, + typename DerivedVB, + typename DerivedFB, + typename Scalar> + IGL_INLINE void hausdorff( + const Eigen::MatrixBase & VA, + const Eigen::MatrixBase & FA, + const Eigen::MatrixBase & VB, + const Eigen::MatrixBase & FB, + Scalar & d); + // Compute lower and upper bounds (l,u) on the Hausdorff distance between a triangle + // (V) and a pointset (e.g., mesh, triangle soup) given by a distance function + // handle (dist_to_B). + // + // Inputs: + // V 3 by 3 list of corner positions so that V.row(i) is the position of the + // ith corner + // dist_to_B function taking the x,y,z coordinate of a query position and + // outputting the closest-point distance to some point-set B + // Outputs: + // l lower bound on Hausdorff distance + // u upper bound on Hausdorff distance + // + template < + typename DerivedV, + typename Scalar> + IGL_INLINE void hausdorff( + const Eigen::MatrixBase& V, + const std::function< + Scalar(const Scalar &,const Scalar &, const Scalar &)> & dist_to_B, + Scalar & l, + Scalar & u); +} + +#ifndef IGL_STATIC_LIBRARY +# include "hausdorff.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/heat_geodesics.cpp b/vendor/libigl/include/igl/heat_geodesics.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9a2a5af22b56db4c328d55d4c4cf1623df48f5a --- /dev/null +++ b/vendor/libigl/include/igl/heat_geodesics.cpp @@ -0,0 +1,170 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "heat_geodesics.h" +#include "grad.h" +#include "doublearea.h" +#include "cotmatrix.h" +#include "intrinsic_delaunay_cotmatrix.h" +#include "massmatrix.h" +#include "massmatrix_intrinsic.h" +#include "grad_intrinsic.h" +#include "boundary_facets.h" +#include "unique.h" +#include "slice.h" +#include "avg_edge_length.h" + + +template < typename DerivedV, typename DerivedF, typename Scalar > +IGL_INLINE bool igl::heat_geodesics_precompute( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + HeatGeodesicsData & data) +{ + // default t value + const Scalar h = avg_edge_length(V,F); + const Scalar t = h*h; + return heat_geodesics_precompute(V,F,t,data); +} + +template < typename DerivedV, typename DerivedF, typename Scalar > +IGL_INLINE bool igl::heat_geodesics_precompute( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Scalar t, + HeatGeodesicsData & data) +{ + typedef Eigen::Matrix VectorXS; + typedef Eigen::Matrix MatrixXS; + Eigen::SparseMatrix L,M; + Eigen::Matrix l_intrinsic; + DerivedF F_intrinsic; + VectorXS dblA; + if(data.use_intrinsic_delaunay) + { + igl::intrinsic_delaunay_cotmatrix(V,F,L,l_intrinsic,F_intrinsic); + igl::massmatrix_intrinsic(l_intrinsic,F_intrinsic,MASSMATRIX_TYPE_DEFAULT,M); + igl::doublearea(l_intrinsic,0,dblA); + igl::grad_intrinsic(l_intrinsic,F_intrinsic,data.Grad); + }else + { + igl::cotmatrix(V,F,L); + igl::massmatrix(V,F,MASSMATRIX_TYPE_DEFAULT,M); + igl::doublearea(V,F,dblA); + igl::grad(V,F,data.Grad); + } + // div + assert(F.cols() == 3 && "Only triangles are supported"); + // number of gradient components + data.ng = data.Grad.rows() / F.rows(); + assert(data.ng == 3 || data.ng == 2); + data.Div = -0.25*data.Grad.transpose()*dblA.colwise().replicate(data.ng).asDiagonal(); + + Eigen::SparseMatrix Q = M - t*L; + Eigen::MatrixXi O; + igl::boundary_facets(F,O); + igl::unique(O,data.b); + { + Eigen::SparseMatrix _; + if(!igl::min_quad_with_fixed_precompute( + Q,Eigen::VectorXi(),_,true,data.Neumann)) + { + return false; + } + // Only need if there's a boundary + if(data.b.size()>0) + { + if(!igl::min_quad_with_fixed_precompute(Q,data.b,_,true,data.Dirichlet)) + { + return false; + } + } + const DerivedV M_diag_tr = M.diagonal().transpose(); + const Eigen::SparseMatrix Aeq = M_diag_tr.sparseView(); + L *= -0.5; + if(!igl::min_quad_with_fixed_precompute( + L,Eigen::VectorXi(),Aeq,true,data.Poisson)) + { + return false; + } + } + return true; +} + +template < typename Scalar, typename Derivedgamma, typename DerivedD> +IGL_INLINE void igl::heat_geodesics_solve( + const HeatGeodesicsData & data, + const Eigen::MatrixBase & gamma, + Eigen::PlainObjectBase & D) +{ + // number of mesh vertices + const int n = data.Grad.cols(); + // Set up delta at gamma + DerivedD u0 = DerivedD::Zero(n,1); + for(int g = 0;g0) + { + // Average Dirichelt and Neumann solutions + DerivedD uD; + igl::min_quad_with_fixed_solve( + data.Dirichlet,u0,DerivedD::Zero(data.b.size()).eval(),DerivedD(),uD); + u += uD; + u *= 0.5; + } + DerivedD grad_u = data.Grad*u; + const int m = data.Grad.rows()/data.ng; + for(int i = 0;i, Eigen::Matrix >(igl::HeatGeodesicsData const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template bool igl::heat_geodesics_precompute, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, igl::HeatGeodesicsData&); +template bool igl::heat_geodesics_precompute, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::HeatGeodesicsData&); +#endif diff --git a/vendor/libigl/include/igl/heat_geodesics.h b/vendor/libigl/include/igl/heat_geodesics.h new file mode 100644 index 0000000000000000000000000000000000000000..6189c346e16bff67a895b795ffcd11540c91ac07 --- /dev/null +++ b/vendor/libigl/include/igl/heat_geodesics.h @@ -0,0 +1,69 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_HEAT_GEODESICS_H +#define IGL_HEAT_GEODESICS_H +#include "igl_inline.h" +#include "min_quad_with_fixed.h" +#include +#include +namespace igl +{ + template + struct HeatGeodesicsData + { + // Gradient and Divergence operators + Eigen::SparseMatrix Grad,Div; + // Number of gradient components + int ng; + // List of boundary vertex indices + Eigen::VectorXi b; + // Solvers for Dirichet, Neumann problems + min_quad_with_fixed_data Dirichlet,Neumann,Poisson; + bool use_intrinsic_delaunay = false; + }; + // Precompute factorized solvers for computing a fast approximation of + // geodesic distances on a mesh (V,F). [Crane et al. 2013] + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by 3 list of mesh face indices into V + // Outputs: + // data precomputation data (see heat_geodesics_solve) + template < typename DerivedV, typename DerivedF, typename Scalar > + IGL_INLINE bool heat_geodesics_precompute( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + HeatGeodesicsData & data); + // Inputs: + // t "heat" parameter (smaller --> more accurate, less stable) + template < typename DerivedV, typename DerivedF, typename Scalar > + IGL_INLINE bool heat_geodesics_precompute( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Scalar t, + HeatGeodesicsData & data); + // Compute fast approximate geodesic distances using precomputed data from a + // set of selected source vertices (gamma) + // + // Inputs: + // data precomputation data (see heat_geodesics_precompute) + // gamma #gamma list of indices into V of source vertices + // Outputs: + // D #V list of distances to gamma + template < typename Scalar, typename Derivedgamma, typename DerivedD> + IGL_INLINE void heat_geodesics_solve( + const HeatGeodesicsData & data, + const Eigen::MatrixBase & gamma, + Eigen::PlainObjectBase & D); +} + +#ifndef IGL_STATIC_LIBRARY +#include "heat_geodesics.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/hessian.cpp b/vendor/libigl/include/igl/hessian.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b53babf26090be0dd3c517585a6771d3f8989469 --- /dev/null +++ b/vendor/libigl/include/igl/hessian.cpp @@ -0,0 +1,60 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// and Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "hessian.h" +#include + +#include "grad.h" +#include "igl/doublearea.h" +#include "igl/repdiag.h" + + + +template +IGL_INLINE void igl::hessian( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& H) +{ + typedef typename DerivedV::Scalar denseScalar; + typedef typename Eigen::Matrix VecXd; + typedef typename Eigen::SparseMatrix SparseMat; + typedef typename Eigen::DiagonalMatrix + DiagMat; + + int dim = V.cols(); + assert((dim==2 || dim==3) && + "The dimension of the vertices should be 2 or 3"); + + //Construct the combined gradient matric + SparseMat G; + igl::grad(V, + F, + G, false); + SparseMat GG(F.rows(), dim*V.rows()); + GG.reserve(G.nonZeros()); + for(int i=0; i, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/hessian.h b/vendor/libigl/include/igl/hessian.h new file mode 100644 index 0000000000000000000000000000000000000000..360750d2cb6861edf8d3f4c73a6b1217b490a1de --- /dev/null +++ b/vendor/libigl/include/igl/hessian.h @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// and Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_FEM_HESSIAN_H +#define IGL_FEM_HESSIAN_H +#include "igl_inline.h" + +#include +#include + + +namespace igl +{ + // Constructs the finite element Hessian matrix + // as described in https://arxiv.org/abs/1707.04348, + // Natural Boundary Conditions for Smoothing in Geometry Processing + // (Oded Stein, Eitan Grinspun, Max Wardetzky, Alec Jacobson) + // The interior vertices are NOT set to zero yet. + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by 3 list of mesh faces (must be triangles) + // Outputs: + // H #V by #V Hessian energy matrix, each column i + // corresponding to V(i,:) + // + // + // + template + IGL_INLINE void hessian( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& H); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "hessian.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/histc.cpp b/vendor/libigl/include/igl/histc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b33ea3e6c546b40ff0f02abe565367011bb173d --- /dev/null +++ b/vendor/libigl/include/igl/histc.cpp @@ -0,0 +1,115 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "histc.h" +#include +#include + +template +IGL_INLINE void igl::histc( + const Eigen::MatrixBase & X, + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & B) +{ + histc(X,E,B); + const int n = E.size(); + const int m = X.size(); + assert(m == B.size()); + N.resize(n,1); + N.setConstant(0); +#pragma omp parallel for + for(int j = 0;j= 0) + { +#pragma omp atomic + N(int(B(j)))++; + } + } +} + +template +IGL_INLINE void igl::histc( + const Eigen::MatrixBase & X, + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & B) +{ + const int m = X.size(); + using namespace std; + assert( + (E.bottomRightCorner(E.size()-1,1) - + E.topLeftCorner(E.size()-1,1)).maxCoeff() >= 0 && + "E should be monotonically increasing"); + B.resize(m,1); +#pragma omp parallel for + for(int j = 0;j E(E.size()-1)) + { + B(j) = -1; + continue; + } + // Find x in E + int l = 0; + int h = E.size()-1; + int k = l; + while((h-l)>1) + { + assert(x >= E(l)); + assert(x <= E(h)); + k = (h+l)/2; + if(x < E(k)) + { + h = k; + }else + { + l = k; + } + } + if(x == E(h)) + { + k = h; + }else + { + k = l; + } + B(j) = k; + } +} + +template +IGL_INLINE void igl::histc( + const typename DerivedE::Scalar & x, + const Eigen::MatrixBase & E, + typename DerivedE::Index & b) +{ + Eigen::Matrix X; + X(0) = x; + Eigen::Matrix B; + hist(X,E,B); + b = B(0); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::histc, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::histc, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#if EIGEN_VERSION_AT_LEAST(3,3,0) +#else +template void igl::histc, Eigen::Matrix >, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase, Eigen::Matrix > > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif + +#endif diff --git a/vendor/libigl/include/igl/histc.h b/vendor/libigl/include/igl/histc.h new file mode 100644 index 0000000000000000000000000000000000000000..2f0ed9135d344ce1f8e363da3bf1d3e689492b10 --- /dev/null +++ b/vendor/libigl/include/igl/histc.h @@ -0,0 +1,56 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_HISTC_H +#define IGL_HISTC_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // Like matlab's histc. Count occurrences of values in X between consecutive + // entries in E + // + // Inputs: + // X m-long Vector of values + // E n-long Monotonically increasing vector of edges + // Outputs: + // N n-long vector where N(k) reveals how many values in X fall between + // E(k) <= X < E(k+1) + // B m-long vector of bin ids so that B(j) = k if E(k) <= X(j) < E(k+1). + // B(j) = -1 if X(j) is outside of E. + // + // O(n+m*log(n)) + template + IGL_INLINE void histc( + const Eigen::MatrixBase & X, + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & B); + // Truly O(m*log(n)) + template + IGL_INLINE void histc( + const Eigen::MatrixBase & X, + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & B); + // Scalar search wrapper + template + IGL_INLINE void histc( + const typename DerivedE::Scalar & x, + const Eigen::MatrixBase & E, + typename DerivedE::Index & b); +} + +#ifndef IGL_STATIC_LIBRARY +# include "histc.cpp" +#endif + +#endif + + + diff --git a/vendor/libigl/include/igl/hsv_to_rgb.cpp b/vendor/libigl/include/igl/hsv_to_rgb.cpp new file mode 100644 index 0000000000000000000000000000000000000000..62d4f5a8443aeff2afe39c42aaf9316fe37a9e36 --- /dev/null +++ b/vendor/libigl/include/igl/hsv_to_rgb.cpp @@ -0,0 +1,73 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "hsv_to_rgb.h" +#include + + +template +IGL_INLINE void igl::hsv_to_rgb(const T * hsv, T * rgb) +{ + igl::hsv_to_rgb( + hsv[0],hsv[1],hsv[2], + rgb[0],rgb[1],rgb[2]); +} + +template +IGL_INLINE void igl::hsv_to_rgb( + const T & h, const T & s, const T & v, + T & r, T & g, T & b) +{ + // From medit + double f,p,q,t,hh; + int i; + // shift the hue to the range [0, 360] before performing calculations + hh = ((360 + ((int)h % 360)) % 360) / 60.; + i = (int)std::floor(hh); /* largest int <= h */ + f = hh - i; /* fractional part of h */ + p = v * (1.0 - s); + q = v * (1.0 - (s * f)); + t = v * (1.0 - (s * (1.0 - f))); + + switch(i) { + case 0: r = v; g = t; b = p; break; + case 1: r = q; g = v; b = p; break; + case 2: r = p; g = v; b = t; break; + case 3: r = p; g = q; b = v; break; + case 4: r = t; g = p; b = v; break; + case 5: r = v; g = p; b = q; break; + } +} + +template +void igl::hsv_to_rgb( + const Eigen::PlainObjectBase & H, + Eigen::PlainObjectBase & R) +{ + assert(H.cols() == 3); + R.resizeLike(H); + for(typename DerivedH::Index r = 0;r, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::hsv_to_rgb, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::hsv_to_rgb, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::hsv_to_rgb, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::hsv_to_rgb(double const*, double*); +#endif diff --git a/vendor/libigl/include/igl/hsv_to_rgb.h b/vendor/libigl/include/igl/hsv_to_rgb.h new file mode 100644 index 0000000000000000000000000000000000000000..2abc07a92cc43279dc067c9ea3f4a6fcf267bd1e --- /dev/null +++ b/vendor/libigl/include/igl/hsv_to_rgb.h @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_HSV_TO_RGB_H +#define IGL_HSV_TO_RGB_H +#include "igl_inline.h" +#include +namespace igl +{ + // Convert RGB to HSV + // + // Inputs: + // h hue value (degrees: [0,360]. Values outside this range will be mapped periodically to [0,360].) + // s saturation value ([0,1]) + // v value value ([0,1]) + // Outputs: + // r red value ([0,1]) + // g green value ([0,1]) + // b blue value ([0,1]) + template + IGL_INLINE void hsv_to_rgb(const T * hsv, T * rgb); + template + IGL_INLINE void hsv_to_rgb( + const T & h, const T & s, const T & v, + T & r, T & g, T & b); + template + void hsv_to_rgb( + const Eigen::PlainObjectBase & H, + Eigen::PlainObjectBase & R); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "hsv_to_rgb.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/igl_inline.h b/vendor/libigl/include/igl/igl_inline.h new file mode 100644 index 0000000000000000000000000000000000000000..20c9630e4f02f8b65da1d92b83af10639e864c19 --- /dev/null +++ b/vendor/libigl/include/igl/igl_inline.h @@ -0,0 +1,18 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +// This should *NOT* be contained in a IGL_*_H ifdef, since it may be defined +// differently based on when it is included +#ifdef IGL_INLINE +#undef IGL_INLINE +#endif + +#ifndef IGL_STATIC_LIBRARY +# define IGL_INLINE inline +#else +# define IGL_INLINE +#endif diff --git a/vendor/libigl/include/igl/in_element.cpp b/vendor/libigl/include/igl/in_element.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea7638d01b65b12081e2739042be1765cb009c2c --- /dev/null +++ b/vendor/libigl/include/igl/in_element.cpp @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "in_element.h" + +template +IGL_INLINE void igl::in_element( + const Eigen::MatrixBase & V, + const Eigen::MatrixXi & Ele, + const Eigen::MatrixBase & Q, + const AABB & aabb, + Eigen::VectorXi & I) +{ + using namespace std; + using namespace Eigen; + const int Qr = Q.rows(); + I.setConstant(Qr,1,-1); +#pragma omp parallel for if (Qr>10000) + for(int e = 0;e +IGL_INLINE void igl::in_element( + const Eigen::MatrixBase & V, + const Eigen::MatrixXi & Ele, + const Eigen::MatrixBase & Q, + const AABB & aabb, + Eigen::SparseMatrix & I) +{ + using namespace std; + using namespace Eigen; + const int Qr = Q.rows(); + std::vector > IJV; + IJV.reserve(Qr); +#pragma omp parallel for if (Qr>10000) + for(int e = 0;e(e,r,1)); + } + } + I.resize(Qr,Ele.rows()); + I.setFromTriplets(IJV.begin(),IJV.end()); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::in_element, Eigen::Matrix, 2>(Eigen::MatrixBase > const&, Eigen::Matrix const&, Eigen::MatrixBase > const&, igl::AABB, 2> const&, Eigen::Matrix&); +template void igl::in_element, Eigen::Matrix, 3>(Eigen::MatrixBase > const&, Eigen::Matrix const&, Eigen::MatrixBase > const&, igl::AABB, 3> const&, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/infinite_cost_stopping_condition.h b/vendor/libigl/include/igl/infinite_cost_stopping_condition.h new file mode 100644 index 0000000000000000000000000000000000000000..dad15521da0a2aeb8dfe4157106f0059ce7feb47 --- /dev/null +++ b/vendor/libigl/include/igl/infinite_cost_stopping_condition.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_INFINITE_COST_STOPPING_CONDITION_H +#define IGL_INFINITE_COST_STOPPING_CONDITION_H +#include "igl_inline.h" +#include "decimate_callback_types.h" +#include +#include +#include +#include +namespace igl +{ + // Stopping condition function compatible with igl::decimate. The output + // function handle will return true if cost of next edge is infinite. + // + // Inputs: + // cost_and_placement handle being used by igl::collapse_edge + // Outputs: + // stopping_condition + // + IGL_INLINE void infinite_cost_stopping_condition( + const decimate_cost_and_placement_callback & cost_and_placement, + decimate_stopping_condition_callback & stopping_condition); + IGL_INLINE decimate_stopping_condition_callback + infinite_cost_stopping_condition( + const decimate_cost_and_placement_callback & cost_and_placement); +} + +#ifndef IGL_STATIC_LIBRARY +# include "infinite_cost_stopping_condition.cpp" +#endif +#endif + + diff --git a/vendor/libigl/include/igl/inradius.cpp b/vendor/libigl/include/igl/inradius.cpp new file mode 100644 index 0000000000000000000000000000000000000000..947b16409260ce91383b858c6d7800b7ab01f780 --- /dev/null +++ b/vendor/libigl/include/igl/inradius.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "inradius.h" +#include "edge_lengths.h" +#include "doublearea.h" + +template < + typename DerivedV, + typename DerivedF, + typename DerivedR> +IGL_INLINE void igl::inradius( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & r) +{ + Eigen::Matrix l; + Eigen::Matrix R; + igl::edge_lengths(V,F,l); + // If R is the circumradius, + // R*r = (abc)/(2*(a+b+c)) + // R = abc/(4*area) + // r(abc/(4*area)) = (abc)/(2*(a+b+c)) + // r/(4*area) = 1/(2*(a+b+c)) + // r = (2*area)/(a+b+c) + DerivedR A; + igl::doublearea(l,0.,A); + r = A.array() /l.array().rowwise().sum(); +} diff --git a/vendor/libigl/include/igl/inradius.h b/vendor/libigl/include/igl/inradius.h new file mode 100644 index 0000000000000000000000000000000000000000..e831f7de3d756d5f9f9531d90ddf93814b1e125a --- /dev/null +++ b/vendor/libigl/include/igl/inradius.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_INRADIUS_H +#define IGL_INRADIUS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute the inradius of each triangle in a mesh (V,F) + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by 3 list of triangle indices into V + // Outputs: + // R #F list of inradii + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedR> + IGL_INLINE void inradius( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & R); +} +#ifndef IGL_STATIC_LIBRARY +# include "inradius.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/internal_angles.cpp b/vendor/libigl/include/igl/internal_angles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23bc7b8345a46213398c2be31745e9b214e82d3a --- /dev/null +++ b/vendor/libigl/include/igl/internal_angles.cpp @@ -0,0 +1,103 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// Copyright (C) 2015 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "internal_angles.h" +#include "squared_edge_lengths.h" +#include "parallel_for.h" +#include "get_seconds.h" + +template +IGL_INLINE void igl::internal_angles( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & K) +{ + typedef typename DerivedV::Scalar Scalar; + if(F.cols() == 3) + { + // Edge lengths + Eigen::Matrix< + Scalar, + DerivedF::RowsAtCompileTime, + DerivedF::ColsAtCompileTime> L_sq; + igl::squared_edge_lengths(V,F,L_sq); + + assert(F.cols() == 3 && "F should contain triangles"); + igl::internal_angles_using_squared_edge_lengths(L_sq,K); + }else + { + assert(V.cols() == 3 && "If F contains non-triangle facets, V must be 3D"); + K.resizeLike(F); + auto corner = []( + const typename DerivedV::ConstRowXpr & x, + const typename DerivedV::ConstRowXpr & y, + const typename DerivedV::ConstRowXpr & z) + { + typedef Eigen::Matrix RowVector3S; + RowVector3S v1 = (x-y).normalized(); + RowVector3S v2 = (z-y).normalized(); + // http://stackoverflow.com/questions/10133957/signed-angle-between-two-vectors-without-a-reference-plane + Scalar s = v1.cross(v2).norm(); + Scalar c = v1.dot(v2); + return atan2(s, c); + }; + for(unsigned i=0; i +IGL_INLINE void igl::internal_angles_using_squared_edge_lengths( + const Eigen::MatrixBase& L_sq, + Eigen::PlainObjectBase & K) +{ + typedef typename DerivedL::Index Index; + assert(L_sq.cols() == 3 && "Edge-lengths should come from triangles"); + const Index m = L_sq.rows(); + K.resize(m,3); + parallel_for( + m, + [&L_sq,&K](const Index f) + { + for(size_t d = 0;d<3;d++) + { + const auto & s1 = L_sq(f,d); + const auto & s2 = L_sq(f,(d+1)%3); + const auto & s3 = L_sq(f,(d+2)%3); + K(f,d) = acos((s3 + s2 - s1)/(2.*sqrt(s3*s2))); + } + }, + 1000l); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles_using_squared_edge_lengths, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::internal_angles_using_squared_edge_lengths, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/intersect.cpp b/vendor/libigl/include/igl/intersect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f930fc0be0c78faced3e3c56583d32d27085168d --- /dev/null +++ b/vendor/libigl/include/igl/intersect.cpp @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "intersect.h" +template +IGL_INLINE void igl::intersect(const M & A, const M & B, M & C) +{ + // Stupid O(size(A) * size(B)) to do it + // Alec: This should be implemented by using unique and sort like `setdiff` + M dyn_C(A.size() > B.size() ? A.size() : B.size(),1); + // count of intersects + int c = 0; + // Loop over A + for(int i = 0;i +IGL_INLINE M igl::intersect(const M & A, const M & B) +{ + M C; + intersect(A,B,C); + return C; +} +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template Eigen::Matrix igl::intersect >(Eigen::Matrix const&, Eigen::Matrix const&); +#endif diff --git a/vendor/libigl/include/igl/intersect.h b/vendor/libigl/include/igl/intersect.h new file mode 100644 index 0000000000000000000000000000000000000000..be4da91e5a36e1f7658b4aa82b283a81ad91742c --- /dev/null +++ b/vendor/libigl/include/igl/intersect.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_INTERSECT_H +#define IGL_INTERSECT_H +#include "igl_inline.h" +#include +namespace igl +{ + // Determine the intersect between two sets of coefficients using == + // Templates: + // M matrix type that implements indexing by global index M(i) + // Inputs: + // A matrix of coefficients + // B matrix of coefficients + // Output: + // C matrix of elements appearing in both A and B, C is always resized to + // have a single column + template + IGL_INLINE void intersect(const M & A, const M & B, M & C); + // Last argument as return + template + IGL_INLINE M intersect(const M & A, const M & B); +} +#ifndef IGL_STATIC_LIBRARY +#include "intersect.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/intrinsic_delaunay_cotmatrix.cpp b/vendor/libigl/include/igl/intrinsic_delaunay_cotmatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7116060114a949723a1ffcbb7d4266b1f0d21895 --- /dev/null +++ b/vendor/libigl/include/igl/intrinsic_delaunay_cotmatrix.cpp @@ -0,0 +1,54 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "intrinsic_delaunay_cotmatrix.h" +#include "edge_lengths.h" +#include "intrinsic_delaunay_triangulation.h" +#include "cotmatrix_intrinsic.h" +#include + +template +IGL_INLINE void igl::intrinsic_delaunay_cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& L) +{ + Eigen::Matrix l_intrinsic; + DerivedF F_intrinsic; + return igl::intrinsic_delaunay_cotmatrix(V,F,L,l_intrinsic,F_intrinsic); +} + +template < + typename DerivedV, + typename DerivedF, + typename Scalar, + typename Derivedl_intrinsic, + typename DerivedF_intrinsic> +IGL_INLINE void igl::intrinsic_delaunay_cotmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& L, + Eigen::PlainObjectBase & l_intrinsic, + Eigen::PlainObjectBase & F_intrinsic) +{ + assert(F.cols() == 3 && "Only triangles are supported"); + Eigen::Matrix l; + igl::edge_lengths(V,F,l); + igl::intrinsic_delaunay_triangulation(l,F,l_intrinsic,F_intrinsic); + igl::cotmatrix_intrinsic(l_intrinsic,F_intrinsic,L); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_cotmatrix, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_cotmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_cotmatrix, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +#endif diff --git a/vendor/libigl/include/igl/intrinsic_delaunay_triangulation.cpp b/vendor/libigl/include/igl/intrinsic_delaunay_triangulation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9ed886359fd6ec2f6c49ff4807cf8066697f2219 --- /dev/null +++ b/vendor/libigl/include/igl/intrinsic_delaunay_triangulation.cpp @@ -0,0 +1,198 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "intrinsic_delaunay_triangulation.h" +#include "is_intrinsic_delaunay.h" +#include "tan_half_angle.h" +#include "unique_edge_map.h" +#include "flip_edge.h" +#include "EPS.h" +#include +#include +#include + +template < + typename Derivedl_in, + typename DerivedF_in, + typename Derivedl, + typename DerivedF> +IGL_INLINE void igl::intrinsic_delaunay_triangulation( + const Eigen::MatrixBase & l_in, + const Eigen::MatrixBase & F_in, + Eigen::PlainObjectBase & l, + Eigen::PlainObjectBase & F) +{ + typedef Eigen::Matrix MatrixX2I; + typedef Eigen::Matrix VectorXI; + MatrixX2I E,uE; + VectorXI EMAP; + std::vector > uE2E; + return intrinsic_delaunay_triangulation(l_in,F_in,l,F,E,uE,EMAP,uE2E); +} + +template < + typename Derivedl_in, + typename DerivedF_in, + typename Derivedl, + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType> +IGL_INLINE void igl::intrinsic_delaunay_triangulation( + const Eigen::MatrixBase & l_in, + const Eigen::MatrixBase & F_in, + Eigen::PlainObjectBase & l, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E) +{ + igl::unique_edge_map(F_in, E, uE, EMAP, uE2E); + // We're going to work in place + l = l_in; + F = F_in; + typedef typename DerivedF::Scalar Index; + typedef typename Derivedl::Scalar Scalar; + const Index num_faces = F.rows(); + + // Vector is faster than queue... + std::vector Q; + Q.reserve(uE2E.size()); + for (size_t uei=0; uei inQ(uE2E.size(),1); + inQ.setConstant(false); + for(const auto uei : Q) + { + inQ(uei) = true; + } + for (Index uei=0; uei [v3,v4] + // Before: + // F(f1,:) = [v1,v2,v4] // in some cyclic order + // F(f2,:) = [v1,v3,v2] // in some cyclic order + // After: + // F(f1,:) = [v1,v3,v4] // in *this* order + // F(f2,:) = [v2,v4,v3] // in *this* order + // + // v1 v1 + // /|\ / \ + // c/ | \b c/f1 \b + // v3 /f2|f1\ v4 => v3 /__f__\ v4 + // \ e / \ f2 / + // d\ | /a d\ /a + // \|/ \ / + // v2 v2 + // + // Compute intrinsic length of oppposite edge + assert(uE2E[uei].size() == 2 && "edge should have 2 incident faces"); + const Index f1 = uE2E[uei][0]%num_faces; + const Index f2 = uE2E[uei][1]%num_faces; + const Index c1 = uE2E[uei][0]/num_faces; + const Index c2 = uE2E[uei][1]/num_faces; + assert(c1 < 3); + assert(c2 < 3); + assert(f1 != f2); + const Index v1 = F(f1, (c1+1)%3); + const Index v2 = F(f1, (c1+2)%3); + const Index v4 = F(f1, c1); + const Index v3 = F(f2, c2); + assert(F(f2, (c2+2)%3) == v1); + assert(F(f2, (c2+1)%3) == v2); + assert( std::abs(l(f1,c1)-l(f2,c2)) < igl::EPS() ); + const Scalar e = l(f1,c1); + const Scalar a = l(f1,(c1+1)%3); + const Scalar b = l(f1,(c1+2)%3); + const Scalar c = l(f2,(c2+1)%3); + const Scalar d = l(f2,(c2+2)%3); + // tan(α/2) + const Scalar tan_a_2= tan_half_angle(a,b,e); + // tan(δ/2) + const Scalar tan_d_2 = tan_half_angle(d,e,c); + // tan((α+δ)/2) + const Scalar tan_a_d_2 = (tan_a_2 + tan_d_2)/(1.0-tan_a_2*tan_d_2); + // cos(α+δ) + const Scalar cos_a_d = + (1.0 - tan_a_d_2*tan_a_d_2)/(1.0+tan_a_d_2*tan_a_d_2); + const Scalar f = sqrt(b*b + c*c - 2.0*b*c*cos_a_d); + l(f1,0) = f; + l(f1,1) = b; + l(f1,2) = c; + l(f2,0) = f; + l(f2,1) = d; + l(f2,2) = a; + // Important to grab these indices _before_ calling flip_edges (they + // will be correct after) + const size_t e_24 = f1 + ((c1 + 1) % 3) * num_faces; + const size_t e_41 = f1 + ((c1 + 2) % 3) * num_faces; + const size_t e_13 = f2 + ((c2 + 1) % 3) * num_faces; + const size_t e_32 = f2 + ((c2 + 2) % 3) * num_faces; + const size_t ue_24 = EMAP(e_24); + const size_t ue_41 = EMAP(e_41); + const size_t ue_13 = EMAP(e_13); + const size_t ue_32 = EMAP(e_32); + flip_edge(F, E, uE, EMAP, uE2E, uei); + Q.push_back(ue_24); + Q.push_back(ue_41); + Q.push_back(ue_13); + Q.push_back(ue_32); + } + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_triangulation, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_triangulation, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_triangulation, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +// generated by autoexplicit.sh +template void igl::intrinsic_delaunay_triangulation, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/intrinsic_delaunay_triangulation.h b/vendor/libigl/include/igl/intrinsic_delaunay_triangulation.h new file mode 100644 index 0000000000000000000000000000000000000000..b80d539bc6890dd2db9ea851c70e3f2f2dd0c5b9 --- /dev/null +++ b/vendor/libigl/include/igl/intrinsic_delaunay_triangulation.h @@ -0,0 +1,79 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_INTRINSIC_DELAUNAY_TRIANGULATION_H +#define IGL_INTRINSIC_DELAUNAY_TRIANGULATION_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // INTRINSIC_DELAUNAY_TRIANGULATION Flip edges _intrinsically_ until all are + // "intrinsic Delaunay". See "An algorithm for the construction of intrinsic + // delaunay triangulations with applications to digital geometry processing" + // [Fisher et al. 2007]. + // + // Inputs: + // l_in #F_in by 3 list of edge lengths (see edge_lengths) + // F_in #F_in by 3 list of face indices into some unspecified vertex list V + // Outputs: + // l #F by 3 list of edge lengths + // F #F by 3 list of new face indices. Note: Combinatorially F may contain + // non-manifold edges, duplicate faces and self-loops (e.g., an edge [1,1] + // or a face [1,1,1]). However, the *intrinsic geometry* is still + // well-defined and correct. See [Fisher et al. 2007] Figure 3 and 2nd to + // last paragraph of 1st page. Since F may be "non-eddge-manifold" in the + // usual combinatorial sense, it may be useful to call the more verbose + // overload below if disentangling edges will be necessary later on. + // Calling unique_edge_map on this F will give a _different_ result than + // those outputs. + // + // See also: is_intrinsic_delaunay + template < + typename Derivedl_in, + typename DerivedF_in, + typename Derivedl, + typename DerivedF> + IGL_INLINE void intrinsic_delaunay_triangulation( + const Eigen::MatrixBase & l_in, + const Eigen::MatrixBase & F_in, + Eigen::PlainObjectBase & l, + Eigen::PlainObjectBase & F); + // Outputs: + // E #F*3 by 2 list of all directed edges, such that E.row(f+#F*c) is the + // edge opposite F(f,c) + // uE #uE by 2 list of unique undirected edges + // EMAP #F*3 list of indices into uE, mapping each directed edge to unique + // undirected edge + // uE2E #uE list of lists of indices into E of coexisting edges + // + // See also: unique_edge_map + template < + typename Derivedl_in, + typename DerivedF_in, + typename Derivedl, + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType> + IGL_INLINE void intrinsic_delaunay_triangulation( + const Eigen::MatrixBase & l_in, + const Eigen::MatrixBase & F_in, + Eigen::PlainObjectBase & l, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E); +} + +#ifndef IGL_STATIC_LIBRARY +# include "intrinsic_delaunay_triangulation.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/invert_diag.cpp b/vendor/libigl/include/igl/invert_diag.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6be06786ae00d1a2d7963425cca6149a088f01e5 --- /dev/null +++ b/vendor/libigl/include/igl/invert_diag.cpp @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "invert_diag.h" + +template +IGL_INLINE void igl::invert_diag( + const Eigen::SparseCompressedBase& X, + MatY& Y) +{ + typedef typename DerivedX::Scalar Scalar; +#ifndef NDEBUG + Eigen::SparseMatrix tmp = X; + Eigen::SparseVector dX = tmp.diagonal().sparseView(); + // Check that there are no zeros along the diagonal + assert(dX.nonZeros() == dX.size()); +#endif + // http://www.alecjacobson.com/weblog/?p=2552 + + + if((void *)&Y != (void *)&X) + { + Y = X; + } + // Iterate over outside + for(int k=0; k, Eigen::SparseMatrix >(Eigen::SparseCompressedBase> const&, Eigen::SparseMatrix&); +template void igl::invert_diag, Eigen::SparseMatrix >(Eigen::SparseCompressedBase> const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/invert_diag.h b/vendor/libigl/include/igl/invert_diag.h new file mode 100644 index 0000000000000000000000000000000000000000..4dd5b73896c538ec7911b96f381b1514e31b4ba2 --- /dev/null +++ b/vendor/libigl/include/igl/invert_diag.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_INVERT_DIAG_H +#define IGL_INVERT_DIAG_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include + +namespace igl +{ + // Invert the diagonal entries of a matrix (if the matrix is a diagonal + // matrix then this amounts to inverting the matrix) + + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Inputs: + // X an m by n sparse matrix + // Outputs: + // Y an m by n sparse matrix + template + IGL_INLINE void invert_diag( + const Eigen::SparseCompressedBase& X, + MatY& Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "invert_diag.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/is_border_vertex.h b/vendor/libigl/include/igl/is_border_vertex.h new file mode 100644 index 0000000000000000000000000000000000000000..87c6e992d3d4b14309ad60602978cf055963ce24 --- /dev/null +++ b/vendor/libigl/include/igl/is_border_vertex.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_BORDER_VERTEX_H +#define IGL_IS_BORDER_VERTEX_H +#include "igl_inline.h" +#include "deprecated.h" +#include +#include + +namespace igl +{ + // Determine vertices on open boundary of a (manifold) mesh with triangle + // faces F + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3 list of triangle indices + // Returns #V vector of bools revealing whether vertices are on boundary + // + // Known Bugs: - assumes mesh is edge manifold + // + template + IGL_INLINE std::vector is_border_vertex( + const Eigen::MatrixBase &F); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_border_vertex.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_boundary_edge.cpp b/vendor/libigl/include/igl/is_boundary_edge.cpp new file mode 100644 index 0000000000000000000000000000000000000000..679214bbce09aaa7ec698b31fe0c225402833393 --- /dev/null +++ b/vendor/libigl/include/igl/is_boundary_edge.cpp @@ -0,0 +1,122 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_boundary_edge.h" +#include "unique_rows.h" +#include "sort.h" + +template < + typename DerivedF, + typename DerivedE, + typename DerivedB> +void igl::is_boundary_edge( + const Eigen::PlainObjectBase & E, + const Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & B) +{ + using namespace Eigen; + using namespace std; + // Should be triangles + assert(F.cols() == 3); + // Should be edges + assert(E.cols() == 2); + // number of faces + const int m = F.rows(); + // Collect all directed edges after E + MatrixXi EallE(E.rows()+3*m,2); + EallE.block(0,0,E.rows(),E.cols()) = E; + for(int e = 0;e<3;e++) + { + for(int f = 0;f +void igl::is_boundary_edge( + const Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & EMAP) +{ + using namespace Eigen; + using namespace std; + // Should be triangles + assert(F.cols() == 3); + // number of faces + const int m = F.rows(); + // Collect all directed edges after E + MatrixXi allE(3*m,2); + for(int e = 0;e<3;e++) + { + for(int f = 0;f, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::is_boundary_edge, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::is_boundary_edge, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::is_boundary_edge, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::is_boundary_edge, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::is_boundary_edge, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/is_boundary_edge.h b/vendor/libigl/include/igl/is_boundary_edge.h new file mode 100644 index 0000000000000000000000000000000000000000..f68ebb7e499ad7e9c936bbd0773bc5d9dd387135 --- /dev/null +++ b/vendor/libigl/include/igl/is_boundary_edge.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IS_BOUNDARY_EDGE_H +#define IS_BOUNDARY_EDGE_H +#include + +namespace igl +{ + // IS_BOUNDARY_EDGE Determine for each edge E if it is a "boundary edge" in F. + // Boundary edges are undirected edges which occur only once. + // + // Inputs: + // E #E by 2 list of edges + // F #F by 3 list of triangles + // Outputs: + // B #E list bools. true iff unoriented edge occurs exactly once in F + // (non-manifold and non-existant edges will be false) + // + template < + typename DerivedF, + typename DerivedE, + typename DerivedB> + void is_boundary_edge( + const Eigen::PlainObjectBase & E, + const Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & B); + // Wrapper where Edges should also be computed from F + // E #E by 2 list of edges + // EMAP #F*3 list of indices mapping allE to E + template < + typename DerivedF, + typename DerivedE, + typename DerivedB, + typename DerivedEMAP> + void is_boundary_edge( + const Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & EMAP); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_boundary_edge.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_delaunay.cpp b/vendor/libigl/include/igl/is_delaunay.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7628336a28f0207826fffec8c71d63cea035e8be --- /dev/null +++ b/vendor/libigl/include/igl/is_delaunay.cpp @@ -0,0 +1,108 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_delaunay.h" +#include "unique_edge_map.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedD> +IGL_INLINE void igl::is_delaunay( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & D) +{ + typedef typename DerivedV::Scalar Scalar; + // Should use Shewchuk's predicates instead. + const auto float_incircle = []( + const Scalar pa[2], + const Scalar pb[2], + const Scalar pc[2], + const Scalar pd[2])->short + { + // I acknowledge that I am cating to double + const Eigen::Matrix3d A = (Eigen::Matrix3d(3,3)<< + pa[0]-pd[0], pa[1]-pd[1],(pa[0]-pd[0])*(pa[0]-pd[0])+(pa[1]-pd[1])*(pa[1]-pd[1]), + pb[0]-pd[0], pb[1]-pd[1],(pb[0]-pd[0])*(pb[0]-pd[0])+(pb[1]-pd[1])*(pb[1]-pd[1]), + pc[0]-pd[0], pc[1]-pd[1],(pc[0]-pd[0])*(pc[0]-pd[0])+(pc[1]-pd[1])*(pc[1]-pd[1]) + ).finished(); + const Scalar detA = A.determinant(); + return (Scalar(0) < detA) - (detA < Scalar(0)); + }; + + typedef Eigen::Matrix MatrixX2I; + typedef Eigen::Matrix VectorXI; + MatrixX2I E,uE; + VectorXI EMAP; + std::vector > uE2E; + igl::unique_edge_map(F, E, uE, EMAP, uE2E); + const int num_faces = F.rows(); + D.setConstant(F.rows(),F.cols(),false); + // loop over all unique edges + for(int ue = 0;ue < uE2E.size(); ue++) + { + const bool ue_is_d = is_delaunay(V,F,uE2E,float_incircle,ue); + // Set for all instances + for(int e = 0;e +IGL_INLINE bool igl::is_delaunay( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const std::vector > & uE2E, + const InCircle incircle, + const ueiType uei) +{ + if(uE2E[uei].size() == 1) return true; + if(uE2E[uei].size() > 2) return false; + const int num_faces = F.rows(); + typedef typename DerivedV::Scalar Scalar; + const auto& half_edges = uE2E[uei]; + assert((half_edges.size() == 2) && "uE2E[uei].size() should be 2"); + const size_t f1 = half_edges[0] % num_faces; + const size_t f2 = half_edges[1] % num_faces; + const size_t c1 = half_edges[0] / num_faces; + const size_t c2 = half_edges[1] / num_faces; + assert(c1 < 3); + assert(c2 < 3); + assert(f1 != f2); + const size_t v1 = F(f1, (c1+1)%3); + const size_t v2 = F(f1, (c1+2)%3); + const size_t v4 = F(f1, c1); + const size_t v3 = F(f2, c2); + const Scalar p1[] = {V(v1, 0), V(v1, 1)}; + const Scalar p2[] = {V(v2, 0), V(v2, 1)}; + const Scalar p3[] = {V(v3, 0), V(v3, 1)}; + const Scalar p4[] = {V(v4, 0), V(v4, 1)}; + auto orientation = incircle(p1, p2, p4, p3); + return orientation <= 0; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::is_delaunay, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::is_delaunay, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::is_delaunay, Eigen::Matrix, int, short (*)(double const*, double const*, double const*, double const*), unsigned long>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, short (*)(double const*, double const*, double const*, double const*), unsigned long); +#ifdef WIN32 +template bool igl::is_delaunay, class Eigen::Matrix, int, short(*)(double const *, double const *, double const *, double const *), unsigned __int64>(class Eigen::MatrixBase> const &, class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>> const &, short(*const)(double const *, double const *, double const *, double const *), unsigned __int64); +#endif +#endif diff --git a/vendor/libigl/include/igl/is_delaunay.h b/vendor/libigl/include/igl/is_delaunay.h new file mode 100644 index 0000000000000000000000000000000000000000..e6aa5bb1873d1eb31418238bfc33ad25b4d9fca3 --- /dev/null +++ b/vendor/libigl/include/igl/is_delaunay.h @@ -0,0 +1,64 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_DELAUNAY_H +#define IGL_IS_DELAUNAY_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // IS_DELAUNAY Determine if each edge in the mesh (V,F) is Delaunay. + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3 list of triangles indices + // Outputs: + // D #F by 3 list of bools revealing whether edges corresponding 23 31 12 + // are locally Delaunay. Boundary edges are by definition Delaunay. + // Non-Manifold edges are by definition not Delaunay. + template < + typename DerivedV, + typename DerivedF, + typename DerivedD> + IGL_INLINE void is_delaunay( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & D); + // Determine whether a single edge is Delaunay using a provided (extrinsic) incirle + // test. + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3 list of triangles indices + // uE2E #uE list of lists of indices into E of coexisting edges (see + // unique_edge_map) + // incircle A functor such that incircle(pa, pb, pc, pd) returns + // 1 if pd is on the positive size of circumcirle of (pa,pb,pc) + // -1 if pd is on the positive size of circumcirle of (pa,pb,pc) + // 0 if pd is cocircular with pa, pb, pc. + // (see delaunay_triangulation) + // uei index into uE2E of edge to check + // Returns true iff edge is Delaunay + template < + typename DerivedV, + typename DerivedF, + typename uE2EType, + typename InCircle, + typename ueiType> + IGL_INLINE bool is_delaunay( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const std::vector > & uE2E, + const InCircle incircle, + const ueiType uei); + +} +#ifndef IGL_STATIC_LIBRARY +#include "is_delaunay.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/is_dir.cpp b/vendor/libigl/include/igl/is_dir.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7346c1dda12cbe42e387b9910cdfdd4c781fa48 --- /dev/null +++ b/vendor/libigl/include/igl/is_dir.cpp @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_dir.h" + +#include + +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif + +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif + +IGL_INLINE bool igl::is_dir(const char * filename) +{ + struct stat status; + if(stat(filename,&status)!=0) + { + // path does not exist + return false; + } + // Tests whether existing path is a directory + return S_ISDIR(status.st_mode); +} diff --git a/vendor/libigl/include/igl/is_edge_manifold.cpp b/vendor/libigl/include/igl/is_edge_manifold.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0d5fa36af01b0d192bc9714cf9bfaaf4ceffa56 --- /dev/null +++ b/vendor/libigl/include/igl/is_edge_manifold.cpp @@ -0,0 +1,84 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_edge_manifold.h" +#include "oriented_facets.h" +#include "unique_simplices.h" +#include "unique_edge_map.h" + +#include +#include + +template < + typename DerivedF, + typename DerivedEMAP, + typename DerivedBF, + typename DerivedBE> +IGL_INLINE bool igl::is_edge_manifold( + const Eigen::MatrixBase& F, + const typename DerivedF::Index ne, + const Eigen::MatrixBase& EMAP, + Eigen::PlainObjectBase& BF, + Eigen::PlainObjectBase& BE) +{ + typedef typename DerivedF::Index Index; + std::vector count(ne,0); + for(Index e = 0;e +IGL_INLINE bool igl::is_edge_manifold( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& BF, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& EMAP, + Eigen::PlainObjectBase& BE) +{ + using namespace Eigen; + typedef Matrix MatrixXF2; + MatrixXF2 allE; + unique_edge_map(F,allE,E,EMAP); + return is_edge_manifold(F,E.rows(),EMAP,BF,BE); +} + +template +IGL_INLINE bool igl::is_edge_manifold( + const Eigen::MatrixBase& F) +{ + Eigen::Array BF; + Eigen::Array BE; + Eigen::MatrixXi E; + Eigen::VectorXi EMAP; + return is_edge_manifold(F,BF,E,EMAP,BE); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template bool igl::is_edge_manifold >(Eigen::MatrixBase > const&); +template bool igl::is_edge_manifold >(Eigen::MatrixBase > const&); +template bool igl::is_edge_manifold >(Eigen::MatrixBase > const&); +template bool igl::is_edge_manifold, Eigen::Matrix, Eigen::Array, Eigen::Array >(Eigen::MatrixBase > const&, Eigen::Matrix::Index, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/is_file.h b/vendor/libigl/include/igl/is_file.h new file mode 100644 index 0000000000000000000000000000000000000000..5610c7ff33a084bb72cb645db7d5a81a6a040a8a --- /dev/null +++ b/vendor/libigl/include/igl/is_file.h @@ -0,0 +1,29 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_FILE_H +#define IGL_IS_FILE_H +#include "igl_inline.h" +namespace igl +{ + // Act like php's is_file function + // http://php.net/manual/en/function.is-file.php + // Tells whether the given filename is a regular file. + // Input: + // filename Path to the file. If filename is a relative filename, it will + // be checked relative to the current working directory. + // Returns TRUE if the filename exists and is a regular file, FALSE + // otherwise. + IGL_INLINE bool is_file(const char * filename); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_file.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_irregular_vertex.cpp b/vendor/libigl/include/igl/is_irregular_vertex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edd91b057e000711a333537c8c23adbaf914770c --- /dev/null +++ b/vendor/libigl/include/igl/is_irregular_vertex.cpp @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_irregular_vertex.h" +#include + +#include "is_border_vertex.h" + +template +IGL_INLINE std::vector igl::is_irregular_vertex(const Eigen::MatrixBase &V, const Eigen::MatrixBase &F) +{ + Eigen::VectorXi count = Eigen::VectorXi::Zero(F.maxCoeff()+1); + + for(unsigned i=0; i border = is_border_vertex(F); + + std::vector res(count.size()); + + for (unsigned i=0; i > igl::is_irregular_vertex, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template std::vector > igl::is_irregular_vertex, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/is_irregular_vertex.h b/vendor/libigl/include/igl/is_irregular_vertex.h new file mode 100644 index 0000000000000000000000000000000000000000..d46fe07a909f081fa42de3c3a39161edbffb2cf0 --- /dev/null +++ b/vendor/libigl/include/igl/is_irregular_vertex.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_IRREGULAR_VERTEX_H +#define IGL_IS_IRREGULAR_VERTEX_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Determine if a vertex is irregular, i.e. it has more than 6 (triangles) + // or 4 (quads) incident edges. Vertices on the boundary are ignored. + // + // Inputs: + // V #V by dim list of vertex positions + // F #F by 3[4] list of triangle[quads] indices + // Returns #V vector of bools revealing whether vertices are singular + // + template + IGL_INLINE std::vector is_irregular_vertex(const Eigen::MatrixBase &V, const Eigen::MatrixBase &F); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_irregular_vertex.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_planar.h b/vendor/libigl/include/igl/is_planar.h new file mode 100644 index 0000000000000000000000000000000000000000..645403da5bcea205b404dcde9138f0dd0c53f8b8 --- /dev/null +++ b/vendor/libigl/include/igl/is_planar.h @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_PLANAR_H +#define IGL_IS_PLANAR_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Determine if a set of points lies on the XY plane + // + // Inputs: + // V #V by dim list of vertex positions + // Return true if a mesh has constant value of 0 in z coordinate + // + // Known bugs: Doesn't determine if vertex is flat if it doesn't lie on the + // XY plane. + IGL_INLINE bool is_planar(const Eigen::MatrixXd & V); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_planar.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/is_readable.cpp b/vendor/libigl/include/igl/is_readable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb5e9534710192602c7b2d46e0374660f4e096b7 --- /dev/null +++ b/vendor/libigl/include/igl/is_readable.cpp @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_readable.h" + +#ifdef _WIN32 +# include +IGL_INLINE bool igl::is_readable(const char* filename) +{ + FILE * f = fopen(filename,"r"); + if(f == NULL) + { + return false; + } + fclose(f); + return true; +} +#else +# include +# include +# include +IGL_INLINE bool igl::is_readable(const char* filename) +{ + // Check if file already exists + struct stat status; + if(stat(filename,&status)!=0) + { + return false; + } + + // Get current users uid and gid + uid_t this_uid = getuid(); + gid_t this_gid = getgid(); + + // Dealing with owner + if( this_uid == status.st_uid ) + { + return S_IRUSR & status.st_mode; + } + + // Dealing with group member + if( this_gid == status.st_gid ) + { + return S_IRGRP & status.st_mode; + } + + // Dealing with other + return S_IROTH & status.st_mode; + +} +#endif diff --git a/vendor/libigl/include/igl/is_readable.h b/vendor/libigl/include/igl/is_readable.h new file mode 100644 index 0000000000000000000000000000000000000000..6897012853960f6e772b8322602cc28eec194580 --- /dev/null +++ b/vendor/libigl/include/igl/is_readable.h @@ -0,0 +1,28 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_READABLE_H +#define IGL_IS_READABLE_H +#include "igl_inline.h" +namespace igl +{ + // Check if a file is reabable like PHP's is_readable function: + // http://www.php.net/manual/en/function.is-readable.php + // Input: + // filename path to file + // Returns true if file exists and is readable and false if file doesn't + // exist or *is not readable* + // + // Note: Windows version will not check user or group ids + IGL_INLINE bool is_readable(const char * filename); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_readable.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_stl.h b/vendor/libigl/include/igl/is_stl.h new file mode 100644 index 0000000000000000000000000000000000000000..e8f78df1a93fea33eeca55667f01fef83ea0d04a --- /dev/null +++ b/vendor/libigl/include/igl/is_stl.h @@ -0,0 +1,21 @@ +#ifndef IGL_IS_STL_H +#define IGL_IS_STL_H +#include "igl_inline.h" +#include +namespace igl +{ + // Given a file pointer, determine if it contains an .stl file and then + // rewind it. + // + // Inputs: + // stl_file pointer to file + // Outputs: + // is_ascii flag whether stl is ascii + // Returns whether stl_file is an .stl file + IGL_INLINE bool is_stl(FILE * stl_file, bool & is_ascii); + IGL_INLINE bool is_stl(FILE * stl_file); +}; +#ifndef IGL_STATIC_LIBRARY +# include "is_stl.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/is_symmetric.cpp b/vendor/libigl/include/igl/is_symmetric.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f40473b66c59d942aee23835b2ca1d939f03f830 --- /dev/null +++ b/vendor/libigl/include/igl/is_symmetric.cpp @@ -0,0 +1,73 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_symmetric.h" +#include "find.h" + +template +IGL_INLINE bool igl::is_symmetric(const Eigen::SparseMatrix& A) +{ + if(A.rows() != A.cols()) + { + return false; + } + assert(A.size() != 0); + Eigen::SparseMatrix AT = A.transpose(); + Eigen::SparseMatrix AmAT = A-AT; + //// Eigen screws up something with LLT if you try to do + //SparseMatrix AmAT = A-A.transpose(); + //// Eigen crashes at runtime if you try to do + // return (A-A.transpose()).nonZeros() == 0; + return AmAT.nonZeros() == 0; +} + +template +IGL_INLINE bool igl::is_symmetric( + const Eigen::PlainObjectBase& A) +{ + if(A.rows() != A.cols()) + { + return false; + } + assert(A.size() != 0); + return (A-A.transpose()).eval().nonZeros() == 0; +} + +template +IGL_INLINE bool igl::is_symmetric( + const Eigen::SparseMatrix& A, + const epsilonT epsilon) +{ + using namespace Eigen; + using namespace std; + if(A.rows() != A.cols()) + { + return false; + } + assert(A.size() != 0); + SparseMatrix AT = A.transpose(); + SparseMatrix AmAT = A-AT; + VectorXi AmATI,AmATJ; + Matrix AmATV; + find(AmAT,AmATI,AmATJ,AmATV); + if(AmATI.size() == 0) + { + return true; + } + + return AmATV.maxCoeff() < epsilon && AmATV.minCoeff() > -epsilon; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::is_symmetric >(Eigen::PlainObjectBase > const&); +// generated by autoexplicit.sh +template bool igl::is_symmetric(Eigen::SparseMatrix const&); +template bool igl::is_symmetric(Eigen::SparseMatrix const&, double); +template bool igl::is_symmetric(Eigen::SparseMatrix const&, int); +#endif diff --git a/vendor/libigl/include/igl/is_symmetric.h b/vendor/libigl/include/igl/is_symmetric.h new file mode 100644 index 0000000000000000000000000000000000000000..31725298e6dbf3d225c88d4c10608a6ec01dd76f --- /dev/null +++ b/vendor/libigl/include/igl/is_symmetric.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_SYMMETRIC_H +#define IGL_IS_SYMMETRIC_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +namespace igl +{ + // Returns true if the given matrix is symmetric + // Inputs: + // A m by m matrix + // Returns true if the matrix is square and symmetric + template + IGL_INLINE bool is_symmetric(const Eigen::SparseMatrix& A); + // Inputs: + // epsilon threshold on L1 difference between A and A' + template + IGL_INLINE bool is_symmetric(const Eigen::SparseMatrix& A, const epsilonT epsilon); + template + IGL_INLINE bool is_symmetric( + const Eigen::PlainObjectBase& A); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_symmetric.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_vertex_manifold.h b/vendor/libigl/include/igl/is_vertex_manifold.h new file mode 100644 index 0000000000000000000000000000000000000000..bf9caded6ba477dfce1e151904130360b34f8c4e --- /dev/null +++ b/vendor/libigl/include/igl/is_vertex_manifold.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_VERTEX_MANIFOLD_H +#define IGL_IS_VERTEX_MANIFOLD_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Check if a mesh is vertex-manifold. This only checks whether the faces + // incident on each vertex form exactly one connected component. Vertices + // incident on non-manifold edges are not consider non-manifold by this + // function (see is_edge_manifold.h). Unreferenced verties are considered + // non-manifold (zero components). + // + // Inputs: + // F #F by 3 list of triangle indices + // Outputs: + // B #V list indicate whether each vertex is locally manifold. + // Returns whether mesh is vertex manifold. + // + // See also: is_edge_manifold + template + IGL_INLINE bool is_vertex_manifold( + const Eigen::PlainObjectBase& F, + Eigen::PlainObjectBase& B); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_vertex_manifold.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/is_writable.cpp b/vendor/libigl/include/igl/is_writable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f266b00783bef2bb5225ce5f39f8a1d2d912cfa9 --- /dev/null +++ b/vendor/libigl/include/igl/is_writable.cpp @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "is_writable.h" + +#ifdef _WIN32 +#include +#ifndef S_IWUSR +# define S_IWUSR S_IWRITE +#endif +IGL_INLINE bool is_writable(const char* filename) +{ + // Check if file already exists + struct stat status; + if(stat(filename,&status)!=0) + { + return false; + } + + return S_IWUSR & status.st_mode; +} +#else +#include +#include + +IGL_INLINE bool igl::is_writable(const char* filename) +{ + // Check if file already exists + struct stat status; + if(stat(filename,&status)!=0) + { + return false; + } + + // Get current users uid and gid + uid_t this_uid = getuid(); + gid_t this_gid = getgid(); + + // Dealing with owner + if( this_uid == status.st_uid ) + { + return S_IWUSR & status.st_mode; + } + + // Dealing with group member + if( this_gid == status.st_gid ) + { + return S_IWGRP & status.st_mode; + } + + // Dealing with other + return S_IWOTH & status.st_mode; +} +#endif diff --git a/vendor/libigl/include/igl/is_writable.h b/vendor/libigl/include/igl/is_writable.h new file mode 100644 index 0000000000000000000000000000000000000000..8834e8afbbe5945e4ce05b3bd36ece5c7dc1dba9 --- /dev/null +++ b/vendor/libigl/include/igl/is_writable.h @@ -0,0 +1,28 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_IS_WRITABLE_H +#define IGL_IS_WRITABLE_H +#include "igl_inline.h" +namespace igl +{ + // Check if a file exists *and* is writable like PHP's is_writable function: + // http://www.php.net/manual/en/function.is-writable.php + // Input: + // filename path to file + // Returns true if file exists and is writable and false if file doesn't + // exist or *is not writable* + // + // Note: Windows version will not test group and user id + IGL_INLINE bool is_writable(const char * filename); +} + +#ifndef IGL_STATIC_LIBRARY +# include "is_writable.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/ismember.cpp b/vendor/libigl/include/igl/ismember.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e3c3fd4924f0e306b622be8801e0fe174024171b --- /dev/null +++ b/vendor/libigl/include/igl/ismember.cpp @@ -0,0 +1,185 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ismember.h" +#include "colon.h" +#include "list_to_matrix.h" +#include "sort.h" +#include "sortrows.h" +#include "unique.h" +#include "unique_rows.h" +#include + +template < + typename DerivedA, + typename DerivedB, + typename DerivedIA, + typename DerivedLOCB> +IGL_INLINE void igl::ismember( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + Eigen::PlainObjectBase & IA, + Eigen::PlainObjectBase & LOCB) +{ + using namespace Eigen; + using namespace std; + IA.resizeLike(A); + IA.setConstant(false); + LOCB.resizeLike(A); + LOCB.setConstant(-1); + // boring base cases + if(A.size() == 0) + { + return; + } + if(B.size() == 0) + { + return; + } + + // Get rid of any duplicates + typedef Matrix VectorA; + typedef Matrix VectorB; + const VectorA vA(Eigen::Map(DerivedA(A).data(), A.cols()*A.rows(),1)); + const VectorB vB(Eigen::Map(DerivedB(B).data(), B.cols()*B.rows(),1)); + VectorA uA; + VectorB uB; + Eigen::Matrix uIA,uIuA,uIB,uIuB; + unique(vA,uA,uIA,uIuA); + unique(vB,uB,uIB,uIuB); + // Sort both + VectorA sA; + VectorB sB; + Eigen::Matrix sIA,sIB; + sort(uA,1,true,sA,sIA); + sort(uB,1,true,sB,sIB); + + Eigen::Matrix uF = + Eigen::Matrix::Zero(sA.size(),1); + Eigen::Matrix uLOCB = + Eigen::Matrix:: + Constant(sA.size(),1,-1); + { + int bi = 0; + // loop over sA + bool past = false; + for(int a = 0;asB(bi)) + { + bi++; + past = bi>=sB.size(); + } + if(!past && sA(a)==sB(bi)) + { + uF(sIA(a)) = true; + uLOCB(sIA(a)) = uIB(sIB(bi)); + } + } + } + + Map< Matrix > + vIA(IA.data(),IA.cols()*IA.rows(),1); + Map< Matrix > + vLOCB(LOCB.data(),LOCB.cols()*LOCB.rows(),1); + for(int a = 0;a +IGL_INLINE void igl::ismember_rows( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + Eigen::PlainObjectBase & IA, + Eigen::PlainObjectBase & LOCB) +{ + using namespace Eigen; + using namespace std; + assert(A.cols() == B.cols() && "number of columns must match"); + IA.resize(A.rows(),1); + IA.setConstant(false); + LOCB.resize(A.rows(),1); + LOCB.setConstant(-1); + // boring base cases + if(A.size() == 0) + { + return; + } + if(B.size() == 0) + { + return; + } + + // Get rid of any duplicates + DerivedA uA; + DerivedB uB; + Eigen::Matrix uIA,uIuA,uIB,uIuB; + unique_rows(A,uA,uIA,uIuA); + unique_rows(B,uB,uIB,uIuB); + // Sort both + DerivedA sA; + DerivedB sB; + Eigen::Matrix sIA,sIB; + sortrows(uA,true,sA,sIA); + sortrows(uB,true,sB,sIB); + + Eigen::Matrix uF = + Eigen::Matrix::Zero(sA.size(),1); + Eigen::Matrix uLOCB = + Eigen::Matrix:: + Constant(sA.size(),1,-1); + const auto & row_greater_than = [&sA,&sB](const int a, const int b) + { + for(int c = 0;c sB(b,c)) return true; + if(sA(a,c) < sB(b,c)) return false; + } + return false; + }; + { + int bi = 0; + // loop over sA + bool past = false; + for(int a = 0;a=sB.rows(); + } + if(!past && (sA.row(a).array()==sB.row(bi).array()).all() ) + { + uF(sIA(a)) = true; + uLOCB(sIA(a)) = uIB(sIB(bi)); + } + } + } + + for(int a = 0;a, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::ismember_rows, Eigen::Matrix, Eigen::Array, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::ismember_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::ismember_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::ismember_rows, Eigen::Matrix, Eigen::Array, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/isolines.cpp b/vendor/libigl/include/igl/isolines.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e2fd698736643c3e1e60680c25a28217f14116e5 --- /dev/null +++ b/vendor/libigl/include/igl/isolines.cpp @@ -0,0 +1,116 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + + +#include "isolines.h" + +#include +#include +#include + +#include "remove_duplicate_vertices.h" + + +template +IGL_INLINE void igl::isolines( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& z, + const int n, + Eigen::PlainObjectBase& isoV, + Eigen::PlainObjectBase& isoE) +{ + //Constants + const int dim = V.cols(); + assert(dim==2 || dim==3); + const int nVerts = V.rows(); + assert(z.rows() == nVerts && + "There must be as many function entries as vertices"); + const int nFaces = F.rows(); + const int np1 = n+1; + const double min = z.minCoeff(), max = z.maxCoeff(); + + + //Following http://www.alecjacobson.com/weblog/?p=2529 + typedef typename DerivedZ::Scalar Scalar; + typedef Eigen::Matrix Vec; + Vec iso(np1); + for(int i=0; i Matrix; + std::array t{{Matrix(nFaces, np1), + Matrix(nFaces, np1), Matrix(nFaces, np1)}}; + for(int i=0; i1) + t[k](i,j) = std::numeric_limits::quiet_NaN(); + } + } + } + + std::array,3> Fij, Iij; + for(int i=0; i LIVec; + typedef Eigen::Matrix LMat; + typedef Eigen::Matrix LIMat; + LIVec dummy1, dummy2; + igl::remove_duplicate_vertices(LMat(isoV), LIMat(isoE), + 2.2204e-15, isoV, dummy1, dummy2, isoE); + +} + + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::isolines, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int const, Eigen::PlainObjectBase > &, Eigen::PlainObjectBase > &); +#endif + diff --git a/vendor/libigl/include/igl/isolines.h b/vendor/libigl/include/igl/isolines.h new file mode 100644 index 0000000000000000000000000000000000000000..3b5199b6add08200ca9b05c98940acaf05a60141 --- /dev/null +++ b/vendor/libigl/include/igl/isolines.h @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + + +#ifndef IGL_ISOLINES_H +#define IGL_ISOLINES_H +#include "igl_inline.h" + +#include +#include + + +namespace igl +{ + // Constructs isolines for a function z given on a mesh (V,F) + // + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by 3 list of mesh faces (must be triangles) + // z #V by 1 list of function values evaluated at vertices + // n the number of desired isolines + // Outputs: + // isoV #isoV by dim list of isoline vertex positions + // isoE #isoE by 2 list of isoline edge positions + // + // + + template + IGL_INLINE void isolines( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& z, + const int n, + Eigen::PlainObjectBase& isoV, + Eigen::PlainObjectBase& isoE); +} + +#ifndef IGL_STATIC_LIBRARY +# include "isolines.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/isolines_map.cpp b/vendor/libigl/include/igl/isolines_map.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a14cf361febbe4a2c9151f0ae70773e45e4143b7 --- /dev/null +++ b/vendor/libigl/include/igl/isolines_map.cpp @@ -0,0 +1,52 @@ +#include "isolines_map.h" +#include + +template < + typename DerivedCM, + typename Derivediso_color, + typename DerivedICM + > +IGL_INLINE void igl::isolines_map( + const Eigen::MatrixBase & CM, + const Eigen::MatrixBase & iso_color, + const int interval_thickness, + const int iso_thickness, + Eigen::PlainObjectBase & ICM) +{ + ICM.resize(CM.rows()*interval_thickness+(CM.rows()-1)*iso_thickness,3); + { + int k = 0; + for(int c = 0;c +IGL_INLINE void igl::isolines_map( + const Eigen::MatrixBase & CM, + Eigen::PlainObjectBase & ICM) +{ + return isolines_map( + CM, Eigen::Matrix(0,0,0), 10, 1, ICM); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::isolines_map, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/isolines_map.h b/vendor/libigl/include/igl/isolines_map.h new file mode 100644 index 0000000000000000000000000000000000000000..2b6f1ac7c00396ffc8bcaed6ea4fdc653de45603 --- /dev/null +++ b/vendor/libigl/include/igl/isolines_map.h @@ -0,0 +1,41 @@ +#ifndef IGL_ISOLINES_MAP_H +#define IGL_ISOLINES_MAP_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Inject a given colormap with evenly spaced isolines. + // + // Inputs: + // CM #CM by 3 list of colors + // ico_color 1 by 3 isoline color + // interval_thickness number of times to repeat intervals (original colors) + // iso_thickness number of times to repeat isoline color (in between + // intervals) + // Outputs: + // ICM #CM*interval_thickness + (#CM-1)*iso_thickness by 3 list of outputs + // colors + template < + typename DerivedCM, + typename Derivediso_color, + typename DerivedICM > + IGL_INLINE void isolines_map( + const Eigen::MatrixBase & CM, + const Eigen::MatrixBase & iso_color, + const int interval_thickness, + const int iso_thickness, + Eigen::PlainObjectBase & ICM); + template < + typename DerivedCM, + typename DerivedICM> + IGL_INLINE void isolines_map( + const Eigen::MatrixBase & CM, + Eigen::PlainObjectBase & ICM); +} + +#ifndef IGL_STATIC_LIBRARY +# include "isolines_map.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/iterative_closest_point.h b/vendor/libigl/include/igl/iterative_closest_point.h new file mode 100644 index 0000000000000000000000000000000000000000..0065c89231df43c439fc29003d65c704050a42f1 --- /dev/null +++ b/vendor/libigl/include/igl/iterative_closest_point.h @@ -0,0 +1,83 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2019 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ITERATIVE_CLOSEST_POINT_H +#define IGL_ITERATIVE_CLOSEST_POINT_H +#include "igl_inline.h" +#include +#include "AABB.h" + +namespace igl +{ + // Solve for the rigid transformation that places mesh X onto mesh Y using the + // iterative closest point method. In particular, optimize: + // + // min ∫_X inf ‖x*R+t - y‖² dx + // R∈SO(3) y∈Y + // t∈R³ + // + // Typically optimization strategies include using Gauss Newton + // ("point-to-plane" linearization) and stochastic descent (sparse random + // sampling each iteration). + // + // Inputs: + // VX #VX by 3 list of mesh X vertices + // FX #FX by 3 list of mesh X triangle indices into rows of VX + // VY #VY by 3 list of mesh Y vertices + // FY #FY by 3 list of mesh Y triangle indices into rows of VY + // num_samples number of random samples to use (larger --> more accurate, + // but also more suceptible to sticking to local minimum) + // Outputs: + // R 3x3 rotation matrix so that (VX*R+t,FX) ~~ (VY,FY) + // t 1x3 translation row vector + template < + typename DerivedVX, + typename DerivedFX, + typename DerivedVY, + typename DerivedFY, + typename DerivedR, + typename Derivedt + > + IGL_INLINE void iterative_closest_point( + const Eigen::MatrixBase & VX, + const Eigen::MatrixBase & FX, + const Eigen::MatrixBase & VY, + const Eigen::MatrixBase & FY, + const int num_samples, + const int max_iters, + Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & t); + // Inputs: + // Ytree precomputed AABB tree for accelerating closest point queries + // NY #FY by 3 list of precomputed unit face normals + template < + typename DerivedVX, + typename DerivedFX, + typename DerivedVY, + typename DerivedFY, + typename DerivedNY, + typename DerivedR, + typename Derivedt + > + IGL_INLINE void iterative_closest_point( + const Eigen::MatrixBase & VX, + const Eigen::MatrixBase & FX, + const Eigen::MatrixBase & VY, + const Eigen::MatrixBase & FY, + const igl::AABB & Ytree, + const Eigen::MatrixBase & NY, + const int num_samples, + const int max_iters, + Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & t); +} + +#ifndef IGL_STATIC_LIBRARY +# include "iterative_closest_point.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/jet.cpp b/vendor/libigl/include/igl/jet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec74bcd7939e076d4fa5dc6f5bc7cb54424fede1 --- /dev/null +++ b/vendor/libigl/include/igl/jet.cpp @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "jet.h" +#include "colormap.h" + +template +IGL_INLINE void igl::jet(const T x, T * rgb) +{ + igl::colormap(igl::COLOR_MAP_TYPE_JET,x, rgb); +} + +template +IGL_INLINE void igl::jet(const T f, T & r, T & g, T & b) +{ + igl::colormap(igl::COLOR_MAP_TYPE_JET, f, r, g, b); +} + +template +IGL_INLINE void igl::jet( + const Eigen::MatrixBase & Z, + const bool normalize, + Eigen::PlainObjectBase & C) +{ + igl::colormap(igl::COLOR_MAP_TYPE_JET,Z, normalize, C); +} + +template +IGL_INLINE void igl::jet( + const Eigen::MatrixBase & Z, + const double min_z, + const double max_z, + Eigen::PlainObjectBase & C) +{ + igl::colormap(igl::COLOR_MAP_TYPE_JET, Z, min_z, max_z, C); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::jet(double, double*); +template void igl::jet(double, double&, double&, double&); +template void igl::jet(float, float*); +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::jet(float, float&, float&, float&); +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); + +template void igl::jet, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/jet.h b/vendor/libigl/include/igl/jet.h new file mode 100644 index 0000000000000000000000000000000000000000..a681ca295703419c61b1fd879113b13ddc7a7e08 --- /dev/null +++ b/vendor/libigl/include/igl/jet.h @@ -0,0 +1,67 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_JET_H +#define IGL_JET_H +#include "igl_inline.h" +//#ifndef IGL_NO_EIGEN +# include +//#endif +namespace igl +{ + // JET like MATLAB's jet. + // + // Note that we actually use the Turbo colormap instead, since jet is a bad colormap: + // https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html + // + // Inputs: + // m number of colors + // Outputs: + // J m by list of RGB colors between 0 and 1 + // +//#ifndef IGL_NO_EIGEN +// void jet(const int m, Eigen::MatrixXd & J); +//#endif + // Wrapper for directly computing [r,g,b] values for a given factor f between + // 0 and 1 + // + // Inputs: + // f factor determining color value as if 0 was min and 1 was max + // Outputs: + // r red value + // g green value + // b blue value + template + IGL_INLINE void jet(const T f, T * rgb); + template + IGL_INLINE void jet(const T f, T & r, T & g, T & b); + // Inputs: + // Z #Z list of factors + // normalize whether to normalize Z to be tightly between [0,1] + // Outputs: + // C #C by 3 list of rgb colors + template + IGL_INLINE void jet( + const Eigen::MatrixBase & Z, + const bool normalize, + Eigen::PlainObjectBase & C); + // Inputs: + // min_z value at blue + // max_z value at red + template + IGL_INLINE void jet( + const Eigen::MatrixBase & Z, + const double min_Z, + const double max_Z, + Eigen::PlainObjectBase & C); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "jet.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/kelvinlets.h b/vendor/libigl/include/igl/kelvinlets.h new file mode 100644 index 0000000000000000000000000000000000000000..3a1bd24f8aa85781989869319cdcbffc378fa620 --- /dev/null +++ b/vendor/libigl/include/igl/kelvinlets.h @@ -0,0 +1,76 @@ +#ifndef IGL_KELVINLETS_H +#define IGL_KELVINLETS_H + +#include +#include +#include + +namespace igl { + +enum class BrushType : int +{ + GRAB, + SCALE, + TWIST, + PINCH, +}; + +template +struct KelvinletParams +{ + const Scalar epsilon; + const int scale; + const BrushType brushType; + std::array ep{}, w{}; + + KelvinletParams(const Scalar& epsilon, + const int falloff, + const BrushType& type) + : epsilon(epsilon) + , scale(falloff) + , brushType(type) + { + static constexpr std::array brush_scaling_params{ 1.0f, + 1.1f, + 1.21f }; + for (int i = 0; i < 3; i++) { + ep[i] = epsilon * brush_scaling_params[i]; + } + w[0] = 1; + w[1] = -((ep[2] * ep[2] - ep[0] * ep[0]) / (ep[2] * ep[2] - ep[1] * ep[1])); + w[2] = (ep[1] * ep[1] - ep[0] * ep[0]) / (ep[2] * ep[2] - ep[1] * ep[1]); + } +}; + +// Implements Pixar's Regularized Kelvinlets (Pixar Technical Memo #17-03): +// Sculpting Brushes based on Fundamental Solutions of Elasticity, a technique +// for real-time physically based volume sculpting of virtual elastic materials +// +// Inputs: +// V #V by dim list of input points in space +// x0 dim-vector of brush tip +// f dim-vector of brush force (translation) +// F dim by dim matrix of brush force matrix (linear) +// params parameters for the kelvinlet brush like brush radius, scale etc +// Outputs: +// X #V by dim list of output points in space +template +IGL_INLINE void kelvinlets( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& x0, + const Eigen::MatrixBase& f, + const Eigen::MatrixBase& F, + const KelvinletParams& params, + Eigen::PlainObjectBase& U); + +} + +#ifndef IGL_STATIC_LIBRARY + +#include "kelvinlets.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/kkt_inverse.cpp b/vendor/libigl/include/igl/kkt_inverse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3c3c8b574f73586da85636e20e15519abd42401 --- /dev/null +++ b/vendor/libigl/include/igl/kkt_inverse.cpp @@ -0,0 +1,97 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "kkt_inverse.h" + +#include +#include +#include "EPS.h" +#include + +template +IGL_INLINE void igl::kkt_inverse( + const Eigen::Matrix& A, + const Eigen::Matrix& Aeq, + const bool use_lu_decomposition, + Eigen::Matrix& S) +{ + typedef Eigen::Matrix Mat; + // This threshold seems to matter a lot but I'm not sure how to + // set it + const T treshold = igl::FLOAT_EPS; + //const T treshold = igl::DOUBLE_EPS; + + const int n = A.rows(); + assert(A.cols() == n); + const int m = Aeq.rows(); + assert(Aeq.cols() == n); + + // Lagrange multipliers method: + Eigen::Matrix LM(n + m, n + m); + LM.block(0, 0, n, n) = A; + LM.block(0, n, n, m) = Aeq.transpose(); + LM.block(n, 0, m, n) = Aeq; + LM.block(n, n, m, m).setZero(); + + Mat LMpinv; + if(use_lu_decomposition) + { + // if LM is close to singular, use at your own risk :) + LMpinv = LM.inverse(); + }else + { + // use SVD + typedef Eigen::Matrix Vec; + Vec singValues; + Eigen::JacobiSVD svd; + svd.compute(LM, Eigen::ComputeFullU | Eigen::ComputeFullV ); + const Mat& u = svd.matrixU(); + const Mat& v = svd.matrixV(); + const Vec& singVals = svd.singularValues(); + + Vec pi_singVals(n + m); + int zeroed = 0; + for (int i=0; i= 0); + // printf("sv: %lg ? %lg\n",(double) sv,(double)treshold); + if (sv > treshold) pi_singVals(i, 0) = T(1) / sv; + else + { + pi_singVals(i, 0) = T(0); + zeroed++; + } + } + + printf("kkt_inverse : %i singular values zeroed (threshold = %e)\n", zeroed, treshold); + Eigen::DiagonalMatrix pi_diag(pi_singVals); + + LMpinv = v * pi_diag * u.transpose(); + } + S = LMpinv.block(0, 0, n, n + m); + + //// debug: + //mlinit(&g_pEngine); + // + //mlsetmatrix(&g_pEngine, "A", A); + //mlsetmatrix(&g_pEngine, "Aeq", Aeq); + //mlsetmatrix(&g_pEngine, "LM", LM); + //mlsetmatrix(&g_pEngine, "u", u); + //mlsetmatrix(&g_pEngine, "v", v); + //MatrixXd svMat = singVals; + //mlsetmatrix(&g_pEngine, "singVals", svMat); + //mlsetmatrix(&g_pEngine, "LMpinv", LMpinv); + //mlsetmatrix(&g_pEngine, "S", S); + + //int hu = 1; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::kkt_inverse(Eigen::Matrix const&, Eigen::Matrix const&, bool, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/kkt_inverse.h b/vendor/libigl/include/igl/kkt_inverse.h new file mode 100644 index 0000000000000000000000000000000000000000..40f208a709d87597d73637de464b14f5e051d040 --- /dev/null +++ b/vendor/libigl/include/igl/kkt_inverse.h @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_KKT_INVERSE_H +#define IGL_KKT_INVERSE_H +#include "igl_inline.h" + +#include + +//// debug +//#include +//Engine *g_pEngine; + + +namespace igl +{ + // Systems of the form: + // + // / A Aeqᵀ \ / x \ = / b \ + // \ Aeq 0 / \ λ / \ beq / + // \_____.______/\__.__/ \___.___/ + // M z c + // + // Arise, for example, when solve convex, linear equality constrained + // quadratic minimization problems: + // + // min ½ xᵀ A x - xᵀb subject to Aeq x = beq + // + // This function constructs a matrix S such that x = S c solves the system + // above. That is: + // + // S = [In 0] M⁻¹ + // + // so that + // + // x = S c + // + // Templates: + // T should be a eigen matrix primitive type like float or double + // Inputs: + // A n by n matrix of quadratic coefficients + // B n by 1 column of linear coefficients + // Aeq m by n list of linear equality constraint coefficients + // Beq m by 1 list of linear equality constraint constant values + // use_lu_decomposition use lu rather than SVD + // Outputs: + // S n by (n + m) "solve" matrix, such that S*[B', Beq'] is a solution + // Returns true on success, false on error + template + IGL_INLINE void kkt_inverse( + const Eigen::Matrix& A, + const Eigen::Matrix& Aeq, + const bool use_lu_decomposition, + Eigen::Matrix& S); +} + +#ifndef IGL_STATIC_LIBRARY +# include "kkt_inverse.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/knn.h b/vendor/libigl/include/igl/knn.h new file mode 100644 index 0000000000000000000000000000000000000000..5d295902f047f4d01fdc45351868e4442dbe675d --- /dev/null +++ b/vendor/libigl/include/igl/knn.h @@ -0,0 +1,88 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Gavin Barill +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/ + +#ifndef IGL_KNN_H +#define IGL_KNN_H +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Given a 3D set of points P, an whole number k, and an octree + // find the indicies of the k nearest neighbors for each point in P. + // Note that each point is its own neighbor. + // + // The octree data structures used in this function are intended to be the + // same ones output from igl::octree + // + // Inputs: + // P #P by 3 list of point locations + // k number of neighbors to find + // point_indices a vector of vectors, where the ith entry is a vector of + // the indices into P that are the ith octree cell's points + // CH #OctreeCells by 8, where the ith row is the indices of + // the ith octree cell's children + // CN #OctreeCells by 3, where the ith row is a 3d row vector + // representing the position of the ith cell's center + // W #OctreeCells, a vector where the ith entry is the width + // of the ith octree cell + // Outputs: + // I #P by k list of k-nearest-neighbor indices into P + template < + typename DerivedP, + typename IndexType, + typename DerivedCH, + typename DerivedCN, + typename DerivedW, + typename DerivedI> + IGL_INLINE void knn( + const Eigen::MatrixBase& P, + size_t k, + const std::vector > & point_indices, + const Eigen::MatrixBase& CH, + const Eigen::MatrixBase& CN, + const Eigen::MatrixBase& W, + Eigen::PlainObjectBase & I); + // Inputs: + // P #P by 3 list of point locations for which which we want the neighbors of + // V #V by 3 list of point locations for which may be neighbors + // k number of neighbors to find + // point_indices a vector of vectors, where the ith entry is a vector of + // the indices into P that are the ith octree cell's points + // CH #OctreeCells by 8, where the ith row is the indices of + // the ith octree cell's children + // CN #OctreeCells by 3, where the ith row is a 3d row vector + // representing the position of the ith cell's center + // W #OctreeCells, a vector where the ith entry is the width + // of the ith octree cell + // Outputs: + // I #P by k list of k-nearest-neighbor indices into V + template < + typename DerivedP, + typename DerivedV, + typename IndexType, + typename DerivedCH, + typename DerivedCN, + typename DerivedW, + typename DerivedI> + IGL_INLINE void knn( + const Eigen::MatrixBase& P, + const Eigen::MatrixBase& V, + size_t k, + const std::vector > & point_indices, + const Eigen::MatrixBase& CH, + const Eigen::MatrixBase& CN, + const Eigen::MatrixBase& W, + Eigen::PlainObjectBase & I); +} +#ifndef IGL_STATIC_LIBRARY +# include "knn.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/launch_medit.cpp b/vendor/libigl/include/igl/launch_medit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f336dd7d012c3895fa506372d07c749ea3f89687 --- /dev/null +++ b/vendor/libigl/include/igl/launch_medit.cpp @@ -0,0 +1,70 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "launch_medit.h" +#include "writeMESH.h" +#include +#include +#include +#include + +#define MEDIT_PATH "/opt/local/bin/medit" +#define TEMP_MESH_FILE "/var/tmp/temp.mesh" +#define TEMP_MEDIT_FILE "/var/tmp/temp.medit" + +template +IGL_INLINE int igl::launch_medit( + const Eigen::PlainObjectBase & V, + const Eigen::PlainObjectBase & T, + const Eigen::PlainObjectBase & F, + const bool wait) +{ + using namespace std; + // Build medit command, end with & so command returns without waiting + stringstream command; + command<, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, bool); +#endif + diff --git a/vendor/libigl/include/igl/lbs_matrix.h b/vendor/libigl/include/igl/lbs_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..307273d2096e3070d9cd7cf9847c0f16e080b8b6 --- /dev/null +++ b/vendor/libigl/include/igl/lbs_matrix.h @@ -0,0 +1,94 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_LBS_MATRIX_H +#define IGL_LBS_MATRIX_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // LBS_MATRIX Linear blend skinning can be expressed by V' = M * T where V' is + // a #V by dim matrix of deformed vertex positions (one vertex per row), M is a + // #V by (dim+1)*#T (composed of weights and rest positions) and T is a + // #T*(dim+1) by dim matrix of #T stacked transposed transformation matrices. + // See equations (1) and (2) in "Fast Automatic Skinning Transformations" + // [Jacobson et al 2012] + // + // Inputs: + // V #V by dim list of rest positions + // W #V+ by #T list of weights + // Outputs: + // M #V by #T*(dim+1) + // + // In MATLAB: + // kron(ones(1,size(W,2)),[V ones(size(V,1),1)]).*kron(W,ones(1,size(V,2)+1)) + IGL_INLINE void lbs_matrix( + const Eigen::MatrixXd & V, + const Eigen::MatrixXd & W, + Eigen::MatrixXd & M); + // LBS_MATRIX construct a matrix that when multiplied against a column of + // affine transformation entries computes new coordinates of the vertices + // + // I'm not sure it makes since that the result is stored as a sparse matrix. + // The number of non-zeros per row *is* dependent on the number of mesh + // vertices and handles. + // + // Inputs: + // V #V by dim list of vertex rest positions + // W #V by #handles list of correspondence weights + // Output: + // M #V * dim by #handles * dim * (dim+1) matrix such that + // new_V(:) = LBS(V,W,A) = reshape(M * A,size(V)), where A is a column + // vectors formed by the entries in each handle's dim by dim+1 + // transformation matrix. Specifcally, A = + // reshape(permute(Astack,[3 1 2]),n*dim*(dim+1),1) + // or A = [Lxx;Lyx;Lxy;Lyy;tx;ty], and likewise for other dim + // if Astack(:,:,i) is the dim by (dim+1) transformation at handle i + IGL_INLINE void lbs_matrix_column( + const Eigen::MatrixXd & V, + const Eigen::MatrixXd & W, + Eigen::SparseMatrix& M); + IGL_INLINE void lbs_matrix_column( + const Eigen::MatrixXd & V, + const Eigen::MatrixXd & W, + Eigen::MatrixXd & M); + // Same as LBS_MATRIX above but instead of giving W as a full matrix of weights + // (each vertex has #handles weights), a constant number of weights are given + // for each vertex. + // + // Inputs: + // V #V by dim list of vertex rest positions + // W #V by k list of k correspondence weights per vertex + // WI #V by k list of k correspondence weight indices per vertex. Such that + // W(j,WI(i)) gives the ith most significant correspondence weight on vertex j + // Output: + // M #V * dim by #handles * dim * (dim+1) matrix such that + // new_V(:) = LBS(V,W,A) = reshape(M * A,size(V)), where A is a column + // vectors formed by the entries in each handle's dim by dim+1 + // transformation matrix. Specifcally, A = + // reshape(permute(Astack,[3 1 2]),n*dim*(dim+1),1) + // or A = [Lxx;Lyx;Lxy;Lyy;tx;ty], and likewise for other dim + // if Astack(:,:,i) is the dim by (dim+1) transformation at handle i + // + IGL_INLINE void lbs_matrix_column( + const Eigen::MatrixXd & V, + const Eigen::MatrixXd & W, + const Eigen::MatrixXi & WI, + Eigen::SparseMatrix& M); + IGL_INLINE void lbs_matrix_column( + const Eigen::MatrixXd & V, + const Eigen::MatrixXd & W, + const Eigen::MatrixXi & WI, + Eigen::MatrixXd & M); +} +#ifndef IGL_STATIC_LIBRARY +#include "lbs_matrix.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/lexicographic_triangulation.cpp b/vendor/libigl/include/igl/lexicographic_triangulation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ceb07de97c59f982fbdb60454dfcac07c50d4308 --- /dev/null +++ b/vendor/libigl/include/igl/lexicographic_triangulation.cpp @@ -0,0 +1,131 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// Qingan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "lexicographic_triangulation.h" +#include "sortrows.h" + +#include +#include + +template< + typename DerivedP, + typename Orient2D, + typename DerivedF + > +IGL_INLINE void igl::lexicographic_triangulation( + const Eigen::MatrixBase& P, + Orient2D orient2D, + Eigen::PlainObjectBase& F) +{ + typedef typename DerivedP::Scalar Scalar; + const size_t num_pts = P.rows(); + if (num_pts < 3) { + throw "At least 3 points are required for triangulation!"; + } + + // Sort points in lexicographic order. + DerivedP ordered_P; + Eigen::VectorXi order; + igl::sortrows(P, true, ordered_P, order); + + std::vector faces; + std::list boundary; + const Scalar p0[] = {ordered_P(0, 0), ordered_P(0, 1)}; + const Scalar p1[] = {ordered_P(1, 0), ordered_P(1, 1)}; + for (size_t i=2; i 0) { + for (size_t j=0; j<=i-2; j++) { + faces.push_back({order[j], order[j+1], order[i]}); + } + } else if (orientation < 0) { + for (size_t j=0; j<=i-2; j++) { + faces.push_back({order[j+1], order[j], order[i]}); + } + } + // Initialize current boundary. + boundary.insert(boundary.end(), order.data(), order.data()+i+1); + if (orientation < 0) { + boundary.reverse(); + } + } + } else { + const size_t bd_size = boundary.size(); + assert(bd_size >= 3); + std::vector orientations; + for (auto itr=boundary.begin(); itr!=boundary.end(); itr++) { + auto next_itr = std::next(itr, 1); + if (next_itr == boundary.end()) { + next_itr = boundary.begin(); + } + const Scalar bd_p0[] = {P(*itr, 0), P(*itr, 1)}; + const Scalar bd_p1[] = {P(*next_itr, 0), P(*next_itr, 1)}; + auto orientation = orient2D(bd_p0, bd_p1, curr_p); + if (orientation < 0) { + faces.push_back({*next_itr, *itr, order[i]}); + } + orientations.push_back(orientation); + } + + auto left_itr = boundary.begin(); + auto right_itr = boundary.begin(); + auto curr_itr = boundary.begin(); + for (size_t j=0; j= 0 && orientations[prev] < 0) { + right_itr = curr_itr; + } else if (orientations[j] < 0 && orientations[prev] >= 0) { + left_itr = curr_itr; + } + } + assert(left_itr != right_itr); + + for (auto itr=left_itr; itr!=right_itr; itr++) { + if (itr == boundary.end()) itr = boundary.begin(); + if (itr == right_itr) break; + if (itr == left_itr) continue; + itr = boundary.erase(itr); + if (itr == boundary.begin()) { + itr = boundary.end(); + } + itr--; + } + + if (right_itr == boundary.begin()) { + assert(std::next(left_itr, 1) == boundary.end()); + boundary.insert(boundary.end(), order[i]); + } else { + assert(std::next(left_itr, 1) == right_itr); + boundary.insert(right_itr, order[i]); + } + } + } + + const size_t num_faces = faces.size(); + if (num_faces == 0) { + // All input points are collinear. + // Do nothing here. + } else { + F.resize(num_faces, 3); + for (size_t i=0; i, short (*)(double const*, double const*, double const*), Eigen::Matrix >(Eigen::MatrixBase > const&, short (*)(double const*, double const*, double const*), Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/limit_faces.cpp b/vendor/libigl/include/igl/limit_faces.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e54c40b455d34dcce84ab6e9e36893bbf715bb43 --- /dev/null +++ b/vendor/libigl/include/igl/limit_faces.cpp @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "limit_faces.h" + +#include +#include + +template +IGL_INLINE void igl::limit_faces( + const MatF & F, + const VecL & L, + const bool exclusive, + MatF & LF) +{ + using namespace std; + using namespace Eigen; + vector in(F.rows(),false); + int num_in = 0; + // loop over faces + for(int i = 0;i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_LIMIT_FACES_H +#define IGL_LIMIT_FACES_H +#include "igl_inline.h" +namespace igl +{ + // LIMIT_FACES limit given faces F to those which contain (only) indices found + // in L. + // + // [LF] = limit_faces(F,L,exclusive); + // [LF,in] = limit_faces(F,L,exclusive); + // + // Templates: + // MatF matrix type of faces, matrixXi + // VecL matrix type of vertex indices, VectorXi + // Inputs: + // F #F by 3 list of face indices + // L #L by 1 list of allowed indices + // exclusive flag specifying whether a face is included only if all its + // indices are in L, default is false + // Outputs: + // LF #LF by 3 list of remaining faces after limiting + // in #F list of whether given face was included + // + template + IGL_INLINE void limit_faces( + const MatF & F, + const VecL & L, + const bool exclusive, + MatF & LF); +} + +#ifndef IGL_STATIC_LIBRARY +# include "limit_faces.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/line_field_mismatch.cpp b/vendor/libigl/include/igl/line_field_mismatch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27a2dd2e6e39826b15d8ee697ad772dc1a512164 --- /dev/null +++ b/vendor/libigl/include/igl/line_field_mismatch.cpp @@ -0,0 +1,144 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Nico Pietroni +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "line_field_mismatch.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace igl { +template +class MismatchCalculatorLine +{ +public: + + const Eigen::PlainObjectBase &V; + const Eigen::PlainObjectBase &F; + const Eigen::PlainObjectBase &PD1; + const Eigen::PlainObjectBase &PD2; + DerivedV N; + +private: + // internal + std::vector V_border; // bool + std::vector > VF; + std::vector > VFi; + DerivedF TT; + DerivedF TTi; + + +private: + + //compute the mismatch between 2 faces + inline int mismatchByLine(const int f0, + const int f1) + { + Eigen::Matrix dir0 = PD1.row(f0); + Eigen::Matrix dir1 = PD1.row(f1); + Eigen::Matrix n0 = N.row(f0); + Eigen::Matrix n1 = N.row(f1); + + Eigen::Matrix dir1Rot = igl::rotation_matrix_from_directions(n1,n0)*dir1; + dir1Rot.normalize(); + + // TODO: this should be equivalent to the other code below, to check! + // Compute the angle between the two vectors + // double a0 = atan2(dir0.dot(B2.row(f0)),dir0.dot(B1.row(f0))); + // double a1 = atan2(dir1Rot.dot(B2.row(f0)),dir1Rot.dot(B1.row(f0))); + // + // double angle_diff = a1-a0; //VectToAngle(f0,dir1Rot); + + double angle_diff = atan2(dir1Rot.dot(PD2.row(f0)),dir1Rot.dot(PD1.row(f0))); + + double step=igl::PI; + int i=(int)std::floor((angle_diff/step)+0.5); + assert((i>=-2)&&(i<=2)); + int k=0; + if (i>=0) + k=i%2; + else + k=(2+i)%2; + + assert((k==0)||(k==1)); + return (k*2); + } + +public: + + inline MismatchCalculatorLine(const Eigen::PlainObjectBase &_V, + const Eigen::PlainObjectBase &_F, + const Eigen::PlainObjectBase &_PD1, + const Eigen::PlainObjectBase &_PD2 + ): + V(_V), + F(_F), + PD1(_PD1), + PD2(_PD2) + { + igl::per_face_normals(V,F,N); + V_border = igl::is_border_vertex(F); + igl::vertex_triangle_adjacency(V,F,VF,VFi); + igl::triangle_triangle_adjacency(F,TT,TTi); + } + + inline void calculateMismatchLine(Eigen::PlainObjectBase &Handle_MMatch) + { + Handle_MMatch.setConstant(F.rows(),3,-1); + for (unsigned int i=0;i +IGL_INLINE void igl::line_field_mismatch(const Eigen::PlainObjectBase &V, + const Eigen::PlainObjectBase &F, + const Eigen::PlainObjectBase &PD1, + const bool isCombed, + Eigen::PlainObjectBase &mismatch) +{ + DerivedV PD1_combed; + DerivedV PD2_combed; + + if (!isCombed) + igl::comb_line_field(V,F,PD1,PD1_combed); + else + { + PD1_combed = PD1; + } + Eigen::MatrixXd B1,B2,B3; + igl::local_basis(V,F,B1,B2,B3); + PD2_combed = igl::rotate_vectors(PD1_combed, Eigen::VectorXd::Constant(1,igl::PI/2), B1, B2); + igl::MismatchCalculatorLine sf(V, F, PD1_combed, PD2_combed); + sf.calculateMismatchLine(mismatch); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/line_field_mismatch.h b/vendor/libigl/include/igl/line_field_mismatch.h new file mode 100644 index 0000000000000000000000000000000000000000..694272dd775e0f28260032c4e53436a74fddde06 --- /dev/null +++ b/vendor/libigl/include/igl/line_field_mismatch.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Nico Pietroni +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_LINE_FIELD_MISSMATCH_H +#define IGL_LINE_FIELD_MISSMATCH_H +#include "igl_inline.h" +#include +namespace igl +{ + // Calculates the mismatch (integer), at each face edge, of a cross field defined on the mesh faces. + // The integer mismatch is a multiple of pi/2 that transforms the cross on one side of the edge to + // the cross on the other side. It represents the deviation from a Lie connection across the edge. + + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 3 eigen Matrix of face (quad) indices + // PD1 #F by 3 eigen Matrix of the first per face cross field vector + // PD2 #F by 3 eigen Matrix of the second per face cross field vector + // isCombed boolean, specifying whether the field is combed (i.e. matching has been precomputed. + // If not, the field is combed first. + // Output: + // mismatch #F by 3 eigen Matrix containing the integer mismatch of the cross field + // across all face edges + // + + template + IGL_INLINE void line_field_mismatch(const Eigen::PlainObjectBase &V, + const Eigen::PlainObjectBase &F, + const Eigen::PlainObjectBase &PD1, + const bool isCombed, + Eigen::PlainObjectBase &mismatch); +} +#ifndef IGL_STATIC_LIBRARY +#include "line_field_mismatch.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/line_search.cpp b/vendor/libigl/include/igl/line_search.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c94eeaa529557dde031ba036d033cabfcb0b247e --- /dev/null +++ b/vendor/libigl/include/igl/line_search.cpp @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "line_search.h" + +IGL_INLINE double igl::line_search( + Eigen::MatrixXd& x, + const Eigen::MatrixXd& d, + double step_size, + std::function energy, + double cur_energy) +{ + double old_energy; + if (cur_energy > 0) + { + old_energy = cur_energy; + } + else + { + old_energy = energy(x); // no energy was given -> need to compute the current energy + } + double new_energy = old_energy; + int cur_iter = 0; int MAX_STEP_SIZE_ITER = 12; + + while (new_energy >= old_energy && cur_iter < MAX_STEP_SIZE_ITER) + { + Eigen::MatrixXd new_x = x + step_size * d; + + double cur_e = energy(new_x); + if ( cur_e >= old_energy) + { + step_size /= 2; + } + else + { + x = new_x; + new_energy = cur_e; + } + cur_iter++; + } + return new_energy; +} + + +#ifdef IGL_STATIC_LIBRARY +#endif diff --git a/vendor/libigl/include/igl/line_search.h b/vendor/libigl/include/igl/line_search.h new file mode 100644 index 0000000000000000000000000000000000000000..057c6a43f21838ab7fa75c1043270347ac222905 --- /dev/null +++ b/vendor/libigl/include/igl/line_search.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_LINE_SEARCH_H +#define IGL_LINE_SEARCH_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Implement a bisection linesearch to minimize a mesh-based energy on vertices given at 'x' at a search direction 'd', + // with initial step size. Stops when a point with lower energy is found, or after maximal iterations have been reached. + // + // Inputs: + // x #X by dim list of variables + // d #X by dim list of a given search direction + // i_step_size initial step size + // energy A function to compute the mesh-based energy (return an energy that is bigger than 0) + // cur_energy(OPTIONAL) The energy at the given point. Helps save redundant computations. + // This is optional. If not specified, the function will compute it. + // Outputs: + // x #X by dim list of variables at the new location + // Returns the energy at the new point 'x' + IGL_INLINE double line_search( + Eigen::MatrixXd& x, + const Eigen::MatrixXd& d, + double i_step_size, + std::function energy, + double cur_energy = -1); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "line_search.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/line_segment_in_rectangle.cpp b/vendor/libigl/include/igl/line_segment_in_rectangle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f47c7d4c7a67798d5ffc8ee20a2bdfc5e704c6b --- /dev/null +++ b/vendor/libigl/include/igl/line_segment_in_rectangle.cpp @@ -0,0 +1,103 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "line_segment_in_rectangle.h" + +IGL_INLINE bool igl::line_segment_in_rectangle( + const Eigen::Vector2d & s, + const Eigen::Vector2d & d, + const Eigen::Vector2d & A, + const Eigen::Vector2d & B) +{ + using namespace std; + using namespace Eigen; + // http://stackoverflow.com/a/100165/148668 + const auto SegmentIntersectRectangle = [](double a_rectangleMinX, + double a_rectangleMinY, + double a_rectangleMaxX, + double a_rectangleMaxY, + double a_p1x, + double a_p1y, + double a_p2x, + double a_p2y)->bool + { + // Find min and max X for the segment + + double minX = a_p1x; + double maxX = a_p2x; + + if(a_p1x > a_p2x) + { + minX = a_p2x; + maxX = a_p1x; + } + + // Find the intersection of the segment's and rectangle's x-projections + + if(maxX > a_rectangleMaxX) + { + maxX = a_rectangleMaxX; + } + + if(minX < a_rectangleMinX) + { + minX = a_rectangleMinX; + } + + if(minX > maxX) // If their projections do not intersect return false + { + return false; + } + + // Find corresponding min and max Y for min and max X we found before + + double minY = a_p1y; + double maxY = a_p2y; + + double dx = a_p2x - a_p1x; + + if(fabs(dx) > 0.0000001) + { + double a = (a_p2y - a_p1y) / dx; + double b = a_p1y - a * a_p1x; + minY = a * minX + b; + maxY = a * maxX + b; + } + + if(minY > maxY) + { + double tmp = maxY; + maxY = minY; + minY = tmp; + } + + // Find the intersection of the segment's and rectangle's y-projections + + if(maxY > a_rectangleMaxY) + { + maxY = a_rectangleMaxY; + } + + if(minY < a_rectangleMinY) + { + minY = a_rectangleMinY; + } + + if(minY > maxY) // If Y-projections do not intersect return false + { + return false; + } + + return true; + }; + const double minX = std::min(A(0),B(0)); + const double minY = std::min(A(1),B(1)); + const double maxX = std::max(A(0),B(0)); + const double maxY = std::max(A(1),B(1)); + bool ret = SegmentIntersectRectangle(minX,minY,maxX,maxY,s(0),s(1),d(0),d(1)); + return ret; +} diff --git a/vendor/libigl/include/igl/linprog.cpp b/vendor/libigl/include/igl/linprog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f84b64f7f53c7f6dad70ea7fb6e069eb1b330e6 --- /dev/null +++ b/vendor/libigl/include/igl/linprog.cpp @@ -0,0 +1,321 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "linprog.h" +#include "slice.h" +#include "slice_into.h" +#include "find.h" +#include "colon.h" + +//#define IGL_LINPROG_VERBOSE +IGL_INLINE bool igl::linprog( + const Eigen::VectorXd & c, + const Eigen::MatrixXd & _A, + const Eigen::VectorXd & b, + const int k, + Eigen::VectorXd & x) +{ + // This is a very literal translation of + // http://www.mathworks.com/matlabcentral/fileexchange/2166-introduction-to-linear-algebra/content/strang/linprog.m + using namespace Eigen; + using namespace std; + bool success = true; + // number of constraints + const int m = _A.rows(); + // number of original variables + const int n = _A.cols(); + // number of iterations + int it = 0; + // maximum number of iterations + //const int MAXIT = 10*m; + const int MAXIT = 100*m; + // residual tolerance + const double tol = 1e-10; + const auto & sign = [](const Eigen::VectorXd & B) -> Eigen::VectorXd + { + Eigen::VectorXd Bsign(B.size()); + for(int i = 0;i0?1:(B(i)<0?-1:0); + } + return Bsign; + }; + // initial (inverse) basis matrix + VectorXd Dv = sign(sign(b).array()+0.5); + Dv.head(k).setConstant(1.); + MatrixXd D = Dv.asDiagonal(); + // Incorporate slack variables + MatrixXd A(_A.rows(),_A.cols()+D.cols()); + A<<_A,D; + // Initial basis + VectorXi B = igl::colon(n,n+m-1); + // non-basis, may turn out that vector<> would be better here + VectorXi N = igl::colon(0,n-1); + int j; + double bmin = b.minCoeff(&j); + int phase; + VectorXd xb; + VectorXd s; + VectorXi J; + if(k>0 && bmin<0) + { + phase = 1; + xb = VectorXd::Ones(m); + // super cost + s.resize(n+m+1); + s<(0,n-1),B(j); + J.resize(B.size()-1); + // [0 1 2 3 4] + // ^ + // [0 1] + // [3 4] + J.head(j) = B.head(j); + J.tail(B.size()-j-1) = B.tail(B.size()-j-1); + B(j) = n+m; + MatrixXd AJ; + igl::slice(A,J,2,AJ); + const VectorXd a = b - AJ.rowwise().sum(); + { + MatrixXd old_A = A; + A.resize(A.rows(),A.cols()+a.cols()); + A<=0 + { + phase = 1; + xb = b.array().abs(); + s.resize(n+m); + // super cost + s<::max(); + // Lagrange mutipliers fro Ax=b + VectorXd yb = D.transpose() * igl::slice(s,B); + while(true) + { + if(MAXIT>0 && it>=MAXIT) + { +#ifdef IGL_LINPROG_VERBOSE + cerr<<"linprog: warning! maximum iterations without convergence."<=-tol*(sN.array().abs().maxCoeff()+1)) + { + break; + } + // increment iteration count + it++; + // apply Bland's rule to avoid cycling + if(df>=0) + { + if(MAXIT == -1) + { +#ifdef IGL_LINPROG_VERBOSE + cerr<<"linprog: warning! degenerate vertex"<().maxCoeff(&q); + } + VectorXd d = D*A.col(N(q)); + VectorXi I; + igl::find((d.array()>tol).eval(),I); + if(I.size() == 0) + { +#ifdef IGL_LINPROG_VERBOSE + cerr<<"linprog: warning! solution is unbounded"<=0) + { + igl::find((xbd.array()==r).eval(),J); + double Bp = igl::slice(B,igl::slice(I,J)).minCoeff(); + // idiotic way of finding index in B of Bp + // code down the line seems to assume p is a scalar though the matlab + // code could find a vector of matches) + (B.array()==Bp).cast().maxCoeff(&p); + } + // update x + xb -= r*d; + xb(p) = r; + // change in f + df = r*rmin; + } + // row vector + RowVectorXd v = D.row(p)/d(p); + yb += v.transpose() * (s(N(q)) - d.transpose()*igl::slice(s,B)); + d(p)-=1; + // update inverse basis matrix + D = D - d*v; + t = B(p); + B(p) = N(q); + if(t>(n+k-1)) + { + // remove qth entry from N + VectorXi old_N = N; + N.resize(N.size()-1); + N.head(q) = old_N.head(q); + N.head(q) = old_N.head(q); + N.tail(old_N.size()-q-1) = old_N.tail(old_N.size()-q-1); + }else + { + N(q) = t; + } + } + // iterative refinement + xb = (xb+D*(b-igl::slice(A,B,2)*xb)).eval(); + // must be due to rounding + VectorXi I; + igl::find((xb.array()<0).eval(),I); + if(I.size()>0) + { + // so correct + VectorXd Z = VectorXd::Zero(I.size(),1); + igl::slice_into(Z,I,xb); + } + // B, xb,n,m,res=A(:,B)*xb-b + if(phase == 2 || it<0) + { + break; + } + if(xb.transpose()*igl::slice(s,B) > tol) + { + it = -it; +#ifdef IGL_LINPROG_VERBOSE + cerr<<"linprog: warning, no feasible solution"<double + { + return (x<0?-1:(x>0?1:0)); + }; + AS.row(i) *= sign(b(i)); + } + MatrixXd In = MatrixXd::Identity(n,n); + MatrixXd P(n+m,2*n+m); + P<< In, -In, MatrixXd::Zero(n,m), + MatrixXd::Zero(m,2*n), Im; + MatrixXd ASP = AS*P; + MatrixXd BSP(0,2*n+m); + if(p>0) + { + // B ∈ ℝ^(p × n) + MatrixXd BS(p,n+m); + BS< +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_LINPROG_H +#define IGL_LINPROG_H +#include "igl_inline.h" +#include +namespace igl +{ + // Solve a linear program given in "standard form" + // + // min c'x + // s.t. A( 1:k,:) x <= b(1:k) + // A(k+1:end,:) x = b(k+1:end) + // ** x >= 0 ** + // + // In contrast to other APIs the entries in b may be negative. + // + // Inputs: + // c #x list of linear coefficients + // A #A by #x matrix of linear constraint coefficients + // b #A list of linear constraint right-hand sides + // k number of inequality constraints as first rows of A,b + // Outputs: + // x #x solution vector + // + IGL_INLINE bool linprog( + const Eigen::VectorXd & c, + const Eigen::MatrixXd & A, + const Eigen::VectorXd & b, + const int k, + Eigen::VectorXd & x); + + // Wrapper in friendlier general form (no implicit bounds on x) + // + // min f'x + // s.t. A x <= b + // B x = c + // + // Inputs: + // f #x list of linear coefficients + // A #A by #x matrix of linear inequality constraint coefficients + // b #A list of linear constraint right-hand sides + // B #B by #x matrix of linear equality constraint coefficients + // c #B list of linear constraint right-hand sides + // Outputs: + // x #x solution vector + // + IGL_INLINE bool linprog( + const Eigen::VectorXd & f, + const Eigen::MatrixXd & A, + const Eigen::VectorXd & b, + const Eigen::MatrixXd & B, + const Eigen::VectorXd & c, + Eigen::VectorXd & x); +} + +#ifndef IGL_STATIC_LIBRARY +# include "linprog.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/list_to_matrix.cpp b/vendor/libigl/include/igl/list_to_matrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2459d9372c26e1648bb783f56e51a29c55aca401 --- /dev/null +++ b/vendor/libigl/include/igl/list_to_matrix.cpp @@ -0,0 +1,232 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "list_to_matrix.h" + +#include +#include + +#include + +#include "max_size.h" +#include "min_size.h" + +template +IGL_INLINE bool igl::list_to_matrix(const std::vector > & V,Eigen::PlainObjectBase& M) +{ + // number of rows + int m = V.size(); + if(m == 0) + { + M.resize( + Derived::RowsAtCompileTime>=0?Derived::RowsAtCompileTime:0 + , + Derived::ColsAtCompileTime>=0?Derived::ColsAtCompileTime:0 + ); + return true; + } + // number of columns + int n = igl::min_size(V); + if(n != igl::max_size(V)) + { + return false; + } + assert(n != -1); + // Resize output + M.resize(m,n); + + // Loop over rows + for(int i = 0;i +IGL_INLINE bool igl::list_to_matrix(const std::vector > & V,Eigen::PlainObjectBase& M) +{ + // number of rows + int m = V.size(); + if(m == 0) + { + M.resize( + Derived::RowsAtCompileTime>=0?Derived::RowsAtCompileTime:0 + , + Derived::ColsAtCompileTime>=0?Derived::ColsAtCompileTime:0 + ); + return true; + } + // number of columns + int n = static_cast(N); + assert(n != -1); + // Resize output + M.resize(m,n); + + // Loop over rows + for(int i = 0;i +IGL_INLINE bool igl::list_to_matrix( + const std::vector > & V, + const int n, + const T & padding, + Eigen::PlainObjectBase& M) +{ + const int m = V.size(); + M.resize(m,n); + for(int i = 0;in) + { + return false; + } + int j = 0; + for(;j +IGL_INLINE bool igl::list_to_matrix(const std::vector & V,Eigen::PlainObjectBase& M) +{ + // number of rows + int m = V.size(); + if(m == 0) + { + //fprintf(stderr,"Error: list_to_matrix() list is empty()\n"); + //return false; + if(Derived::ColsAtCompileTime == 1) + { + M.resize(0,1); + }else if(Derived::RowsAtCompileTime == 1) + { + M.resize(1,0); + }else + { + M.resize(0,0); + } + return true; + } + // Resize output + if(Derived::RowsAtCompileTime == 1) + { + M.resize(1,m); + }else + { + M.resize(m,1); + } + + // Loop over rows + for(int i = 0;i >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +// generated by autoexplicit.sh +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); + +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); + +#ifdef WIN32 +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix >(class std::vector > const &, class Eigen::PlainObjectBase > &); +template bool igl::list_to_matrix >(class std::vector > const &,class Eigen::PlainObjectBase > &); +template bool igl::list_to_matrix >(class std::vector > const &,class Eigen::PlainObjectBase > &); +template bool igl::list_to_matrix >(class std::vector > const &,class Eigen::PlainObjectBase > &); +template bool igl::list_to_matrix >(std::vector > const&, Eigen::PlainObjectBase >&); +template bool igl::list_to_matrix<__int64,class Eigen::Matrix >(class std::vector >,class std::allocator > > > const &,class Eigen::PlainObjectBase > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/list_to_matrix.h b/vendor/libigl/include/igl/list_to_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..34981b2578b46e8428d068a80cce0667fb99e5d5 --- /dev/null +++ b/vendor/libigl/include/igl/list_to_matrix.h @@ -0,0 +1,62 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_LIST_TO_MATRIX_H +#define IGL_LIST_TO_MATRIX_H +#include "igl_inline.h" +#include +#include +#include + +namespace igl +{ + // Convert a list (std::vector) of row vectors of the same length to a matrix + // Template: + // T type that can be safely cast to type in Mat via '=' + // Mat Matrix type, must implement: + // .resize(m,n) + // .row(i) = Row + // Inputs: + // V a m-long list of vectors of size n + // Outputs: + // M an m by n matrix + // Returns true on success, false on errors + template + IGL_INLINE bool list_to_matrix( + const std::vector > & V, + Eigen::PlainObjectBase& M); + + template + IGL_INLINE bool list_to_matrix( + const std::vector > & V, + Eigen::PlainObjectBase& M); + + // Convert a list of row vectors of `n` or less to a matrix and pad on + // the right with `padding`: + // + // Inputs: + // V a m-long list of vectors of size <=n + // n number of columns + // padding value to fill in from right for short rows + // Outputs: + // M an m by n matrix + template + IGL_INLINE bool list_to_matrix( + const std::vector > & V, + const int n, + const T & padding, + Eigen::PlainObjectBase& M); + // Vector wrapper + template + IGL_INLINE bool list_to_matrix(const std::vector & V,Eigen::PlainObjectBase& M); +} + +#ifndef IGL_STATIC_LIBRARY +# include "list_to_matrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/local_basis.cpp b/vendor/libigl/include/igl/local_basis.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b40ba0dce86cfe6c6d2898ac02586c7596b795a --- /dev/null +++ b/vendor/libigl/include/igl/local_basis.cpp @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "local_basis.h" + +#include +#include +#include + +#include +#include + + +template +IGL_INLINE void igl::local_basis( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& B1, + Eigen::PlainObjectBase& B2, + Eigen::PlainObjectBase& B3 + ) +{ + using namespace Eigen; + using namespace std; + B1.resize(F.rows(),3); + B2.resize(F.rows(),3); + B3.resize(F.rows(),3); + + for (unsigned i=0;i v1 = (V.row(F(i,1)) - V.row(F(i,0))).normalized(); + Eigen::Matrix t = V.row(F(i,2)) - V.row(F(i,0)); + Eigen::Matrix v3 = v1.cross(t).normalized(); + Eigen::Matrix v2 = v1.cross(v3).normalized(); + + B1.row(i) = v1; + B2.row(i) = -v2; + B3.row(i) = v3; + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::local_basis, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::local_basis, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/local_basis.h b/vendor/libigl/include/igl/local_basis.h new file mode 100644 index 0000000000000000000000000000000000000000..5eb2cabafb5e895ebb701fc639817aa5731f9794 --- /dev/null +++ b/vendor/libigl/include/igl/local_basis.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_LOCALBASIS_H +#define IGL_LOCALBASIS_H + +#include "igl_inline.h" +#include +#include +#include + +namespace igl +{ + // Compute a local orthogonal reference system for each triangle in the given mesh + // Templates: + // DerivedV derived from vertex positions matrix type: i.e. MatrixXd + // DerivedF derived from face indices matrix type: i.e. MatrixXi + // Inputs: + // V eigen matrix #V by 3 + // F #F by 3 list of mesh faces (must be triangles) + // Outputs: + // B1 eigen matrix #F by 3, each vector is tangent to the triangle + // B2 eigen matrix #F by 3, each vector is tangent to the triangle and perpendicular to B1 + // B3 eigen matrix #F by 3, normal of the triangle + // + // See also: adjacency_matrix + template + IGL_INLINE void local_basis( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& B1, + Eigen::PlainObjectBase& B2, + Eigen::PlainObjectBase& B3 + ); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "local_basis.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/look_at.cpp b/vendor/libigl/include/igl/look_at.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c55c9b2ec56ebf87126a3c5265468e1cc7ee0d89 --- /dev/null +++ b/vendor/libigl/include/igl/look_at.cpp @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "look_at.h" + +template < + typename Derivedeye, + typename Derivedcenter, + typename Derivedup, + typename DerivedR> +IGL_INLINE void igl::look_at( + const Eigen::PlainObjectBase & eye, + const Eigen::PlainObjectBase & center, + const Eigen::PlainObjectBase & up, + Eigen::PlainObjectBase & R) +{ + typedef Eigen::Matrix Vector3S; + Vector3S f = (center - eye).normalized(); + Vector3S s = f.cross(up).normalized(); + Vector3S u = s.cross(f); + R = Eigen::Matrix::Identity(); + R(0,0) = s(0); + R(0,1) = s(1); + R(0,2) = s(2); + R(1,0) = u(0); + R(1,1) = u(1); + R(1,2) = u(2); + R(2,0) =-f(0); + R(2,1) =-f(1); + R(2,2) =-f(2); + R(0,3) =-s.transpose() * eye; + R(1,3) =-u.transpose() * eye; + R(2,3) = f.transpose() * eye; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::look_at, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/map_vertices_to_circle.cpp b/vendor/libigl/include/igl/map_vertices_to_circle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2336139369cf533951088db09fe4106a803925e2 --- /dev/null +++ b/vendor/libigl/include/igl/map_vertices_to_circle.cpp @@ -0,0 +1,54 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Stefan Brugger +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "map_vertices_to_circle.h" +#include "PI.h" + +IGL_INLINE void igl::map_vertices_to_circle( + const Eigen::MatrixXd& V, + const Eigen::VectorXi& bnd, + Eigen::MatrixXd& UV) +{ + // Get sorted list of boundary vertices + std::vector interior,map_ij; + map_ij.resize(V.rows()); + + std::vector isOnBnd(V.rows(),false); + for (int i = 0; i < bnd.size(); i++) + { + isOnBnd[bnd[i]] = true; + map_ij[bnd[i]] = i; + } + + for (int i = 0; i < (int)isOnBnd.size(); i++) + { + if (!isOnBnd[i]) + { + map_ij[i] = interior.size(); + interior.push_back(i); + } + } + + // Map boundary to unit circle + std::vector len(bnd.size()); + len[0] = 0.; + + for (int i = 1; i < bnd.size(); i++) + { + len[i] = len[i-1] + (V.row(bnd[i-1]) - V.row(bnd[i])).norm(); + } + double total_len = len[len.size()-1] + (V.row(bnd[0]) - V.row(bnd[bnd.size()-1])).norm(); + + UV.resize(bnd.size(),2); + for (int i = 0; i < bnd.size(); i++) + { + double frac = len[i] * 2. * igl::PI / total_len; + UV.row(map_ij[bnd[i]]) << cos(frac), sin(frac); + } + +} diff --git a/vendor/libigl/include/igl/map_vertices_to_circle.h b/vendor/libigl/include/igl/map_vertices_to_circle.h new file mode 100644 index 0000000000000000000000000000000000000000..54743717f3f7828ba67ae6c1b527ed02ee319844 --- /dev/null +++ b/vendor/libigl/include/igl/map_vertices_to_circle.h @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Stefan Brugger +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MAP_VERTICES_TO_CIRCLE_H +#define IGL_MAP_VERTICES_TO_CIRCLE_H +#include "igl_inline.h" +#include "PI.h" + +#include +#include + +namespace igl +{ + + // Map the vertices whose indices are in a given boundary loop (bnd) on the + // unit circle with spacing proportional to the original boundary edge + // lengths. + // + // Inputs: + // V #V by dim list of mesh vertex positions + // b #W list of vertex ids + // Outputs: + // UV #W by 2 list of 2D position on the unit circle for the vertices in b + IGL_INLINE void map_vertices_to_circle( + const Eigen::MatrixXd& V, + const Eigen::VectorXi& bnd, + Eigen::MatrixXd& UV); +} + +#ifndef IGL_STATIC_LIBRARY +# include "map_vertices_to_circle.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/mapping_energy_with_jacobians.cpp b/vendor/libigl/include/igl/mapping_energy_with_jacobians.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6331dbe4173b38c708beba30108e09d1ec9fa801 --- /dev/null +++ b/vendor/libigl/include/igl/mapping_energy_with_jacobians.cpp @@ -0,0 +1,143 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Zhongshi Jiang +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "mapping_energy_with_jacobians.h" +#include "polar_svd.h" + +IGL_INLINE double igl::mapping_energy_with_jacobians( + const Eigen::MatrixXd &Ji, + const Eigen::VectorXd &areas, + igl::MappingEnergyType slim_energy, + double exp_factor){ + + double energy = 0; + if (Ji.cols() == 4) + { + Eigen::Matrix ji; + for (int i = 0; i < Ji.rows(); i++) + { + ji(0, 0) = Ji(i, 0); + ji(0, 1) = Ji(i, 1); + ji(1, 0) = Ji(i, 2); + ji(1, 1) = Ji(i, 3); + + typedef Eigen::Matrix Mat2; + typedef Eigen::Matrix Vec2; + Mat2 ri, ti, ui, vi; + Vec2 sing; + igl::polar_svd(ji, ri, ti, ui, sing, vi); + double s1 = sing(0); + double s2 = sing(1); + + switch (slim_energy) + { + case igl::MappingEnergyType::ARAP: + { + energy += areas(i) * (pow(s1 - 1, 2) + pow(s2 - 1, 2)); + break; + } + case igl::MappingEnergyType::SYMMETRIC_DIRICHLET: + { + energy += areas(i) * (pow(s1, 2) + pow(s1, -2) + pow(s2, 2) + pow(s2, -2)); + break; + } + case igl::MappingEnergyType::EXP_SYMMETRIC_DIRICHLET: + { + energy += areas(i) * exp(exp_factor * (pow(s1, 2) + pow(s1, -2) + pow(s2, 2) + pow(s2, -2))); + break; + } + case igl::MappingEnergyType::LOG_ARAP: + { + energy += areas(i) * (pow(log(s1), 2) + pow(log(s2), 2)); + break; + } + case igl::MappingEnergyType::CONFORMAL: + { + energy += areas(i) * ((pow(s1, 2) + pow(s2, 2)) / (2 * s1 * s2)); + break; + } + case igl::MappingEnergyType::EXP_CONFORMAL: + { + energy += areas(i) * exp(exp_factor * ((pow(s1, 2) + pow(s2, 2)) / (2 * s1 * s2))); + break; + } + default: assert(false); + + } + + } + } + else + { + Eigen::Matrix ji; + for (int i = 0; i < Ji.rows(); i++) + { + ji(0, 0) = Ji(i, 0); + ji(0, 1) = Ji(i, 1); + ji(0, 2) = Ji(i, 2); + ji(1, 0) = Ji(i, 3); + ji(1, 1) = Ji(i, 4); + ji(1, 2) = Ji(i, 5); + ji(2, 0) = Ji(i, 6); + ji(2, 1) = Ji(i, 7); + ji(2, 2) = Ji(i, 8); + + typedef Eigen::Matrix Mat3; + typedef Eigen::Matrix Vec3; + Mat3 ri, ti, ui, vi; + Vec3 sing; + igl::polar_svd(ji, ri, ti, ui, sing, vi); + double s1 = sing(0); + double s2 = sing(1); + double s3 = sing(2); + + switch (slim_energy) + { + case igl::MappingEnergyType::ARAP: + { + energy += areas(i) * (pow(s1 - 1, 2) + pow(s2 - 1, 2) + pow(s3 - 1, 2)); + break; + } + case igl::MappingEnergyType::SYMMETRIC_DIRICHLET: + { + energy += areas(i) * (pow(s1, 2) + pow(s1, -2) + pow(s2, 2) + pow(s2, -2) + pow(s3, 2) + pow(s3, -2)); + break; + } + case igl::MappingEnergyType::EXP_SYMMETRIC_DIRICHLET: + { + energy += areas(i) * exp(exp_factor * + (pow(s1, 2) + pow(s1, -2) + pow(s2, 2) + pow(s2, -2) + pow(s3, 2) + pow(s3, -2))); + break; + } + case igl::MappingEnergyType::LOG_ARAP: + { + energy += areas(i) * (pow(log(s1), 2) + pow(log(std::abs(s2)), 2) + pow(log(std::abs(s3)), 2)); + break; + } + case igl::MappingEnergyType::CONFORMAL: + { + energy += areas(i) * ((pow(s1, 2) + pow(s2, 2) + pow(s3, 2)) / (3 * pow(s1 * s2 * s3, 2. / 3.))); + break; + } + case igl::MappingEnergyType::EXP_CONFORMAL: + { + energy += areas(i) * exp(exp_factor * (pow(s1, 2) + pow(s2, 2) + pow(s3, 2)) / (3 * pow(s1 * s2 * s3, 2. / 3.))); + break; + } + default: assert(false); + } + } + } + + return energy; +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/mapping_energy_with_jacobians.h b/vendor/libigl/include/igl/mapping_energy_with_jacobians.h new file mode 100644 index 0000000000000000000000000000000000000000..2952db60d28d46f42e5fedabfecf4914101f4dfd --- /dev/null +++ b/vendor/libigl/include/igl/mapping_energy_with_jacobians.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Zhongshi Jiang +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MAPPING_ENERGY_WITH_JACOBIANS_H +#define IGL_MAPPING_ENERGY_WITH_JACOBIANS_H + +#include "igl_inline.h" +#include +#include "MappingEnergyType.h" + +namespace igl +{ + // compute the rotation-invariant energy of a mapping (represented in Jacobians and areas) + // Input: + // Ji: #F by 4 (9 if 3D) entries of jacobians + // areas: #F by 1 face areas + // slim_energy: energy type as in igl::MappingEnergyType + // exp_factor: see igl::MappingEnergyType + // + // Output: + // energy value + IGL_INLINE double mapping_energy_with_jacobians(const Eigen::MatrixXd &Ji, + const Eigen::VectorXd &areas, + igl::MappingEnergyType slim_energy, + double exp_factor); + +} +#ifndef IGL_STATIC_LIBRARY +# include "mapping_energy_with_jacobians.cpp" +#endif + +#endif \ No newline at end of file diff --git a/vendor/libigl/include/igl/march_cube.cpp b/vendor/libigl/include/igl/march_cube.cpp new file mode 100644 index 0000000000000000000000000000000000000000..86736ab7d0e01a85bffb8dbe62184175c6ec1073 --- /dev/null +++ b/vendor/libigl/include/igl/march_cube.cpp @@ -0,0 +1,136 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2021 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "march_cube.h" + +// Something bad is happening when I made this a function. Maybe +// something is not inlining? It ends up 1.25× slower than if the code is pasted +// into the respective functions in igl::marching_cubes +// +// Even if I make it a lambda with no arguments (all capture by reference [&]) +// and call it immediately I get a 1.25× slow-down. +// +// Maybe keeping it out of a function allows the compiler to optimize with the +// loop? But then I guess that measn this function is not getting inlined? Or +// that it's not getting optimized after inlining? +// +template < + typename DerivedGV, + typename Scalar, + typename Index, + typename DerivedV, + typename DerivedF> +IGL_INLINE void igl::march_cube( + const DerivedGV & GV, + const Eigen::Matrix & cS, + const Eigen::Matrix & cI, + const Scalar & isovalue, + Eigen::PlainObjectBase &V, + Index & n, + Eigen::PlainObjectBase &F, + Index & m, + std::unordered_map & E2V) +{ + +// These consts get stored reasonably +#include "marching_cubes_tables.h" + + // Seems this is also successfully inlined + const auto ij2vertex = + [&E2V,&V,&n,&GV] + (const Index & i, const Index & j, const Scalar & t)->Index + { + // Seems this is successfully inlined. + const auto ij2key = [](int32_t i,int32_t j) + { + if(i>j){ std::swap(i,j); } + std::int64_t ret = 0; + ret |= i; + ret |= static_cast(j) << 32; + return ret; + }; + const auto key = ij2key(i,j); + const auto it = E2V.find(key); + int v = -1; + if(it == E2V.end()) + { + // new vertex + if(n==V.rows()){ V.conservativeResize(V.rows()*2+1,V.cols()); } + V.row(n) = GV.row(i) + t*(GV.row(j) - GV.row(i)); + v = n; + E2V[key] = v; + n++; + }else + { + v = it->second; + } + return v; + }; + + int c_flags = 0; + for(int c = 0; c < 8; c++) + { + if(cS(c) > isovalue){ c_flags |= 1< edge_vertices; + for(int e = 0; e < 12; e++) + { +#ifndef NDEBUG + edge_vertices[e] = -1; +#endif + //if there is an intersection on this edge + if(e_flags & (1<= 0); + assert(edge_vertices[e] < n); + } + } + // Insert the triangles that were found. There can be up to five per cube + for(int f = 0; f < 5; f++) + { + if(a2fConnectionTable[c_flags][3*f] < 0) break; + if(m==F.rows()){ F.conservativeResize(F.rows()*2+1,F.cols()); } + assert(edge_vertices[a2fConnectionTable[c_flags][3*f+0]]>=0); + assert(edge_vertices[a2fConnectionTable[c_flags][3*f+1]]>=0); + assert(edge_vertices[a2fConnectionTable[c_flags][3*f+2]]>=0); + F.row(m) << + edge_vertices[a2fConnectionTable[c_flags][3*f+0]], + edge_vertices[a2fConnectionTable[c_flags][3*f+1]], + edge_vertices[a2fConnectionTable[c_flags][3*f+2]]; + m++; + } +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::march_cube >, float, unsigned int, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, float const&, Eigen::PlainObjectBase >&, unsigned int&, Eigen::PlainObjectBase >&, unsigned int&, std::unordered_map, std::equal_to, std::allocator > >&); +template void igl::march_cube >, double, unsigned int, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, double const&, Eigen::PlainObjectBase >&, unsigned int&, Eigen::PlainObjectBase >&, unsigned int&, std::unordered_map, std::equal_to, std::allocator > >&); +template void igl::march_cube >, double, long, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, double const&, Eigen::PlainObjectBase >&, long&, Eigen::PlainObjectBase >&, long&, std::unordered_map, std::equal_to, std::allocator > >&); +template void igl::march_cube >, double, unsigned int, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, double const&, Eigen::PlainObjectBase >&, unsigned int&, Eigen::PlainObjectBase >&, unsigned int&, std::unordered_map, std::equal_to, std::allocator > >&); +#ifdef WIN32 +template void __cdecl igl::march_cube >,double,__int64,class Eigen::Matrix,class Eigen::Matrix >(class Eigen::MatrixBase > const &,class Eigen::Matrix const &,class Eigen::Matrix<__int64,8,1,0,8,1> const &,double const &,class Eigen::PlainObjectBase > &,__int64 &,class Eigen::PlainObjectBase > &,__int64 &,class std::unordered_map<__int64,int,struct std::hash<__int64>,struct std::equal_to<__int64>,class std::allocator > > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/march_cube.h b/vendor/libigl/include/igl/march_cube.h new file mode 100644 index 0000000000000000000000000000000000000000..75f0e0e07ece10a864e322f0ab2bc9ecf41aace2 --- /dev/null +++ b/vendor/libigl/include/igl/march_cube.h @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2021 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MARCH_CUBE_H +#define IGL_MARCH_CUBE_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Process a single cube of a marching cubes grid. + // + // Inputs: + // GV #GV by 3 list of grid vertex positions + // cS list of 8 scalar field values at grid corners + // cI list of 8 indices of corners into rows of GV + // isovalue level-set value being extracted (often 0) + // V #V by 3 current list of output mesh vertex positions + // n current number of mesh vertices (i.e., occupied rows in V) + // F #F by 3 current list of output mesh triangle indices into rows of V + // m current number of mesh triangles (i.e., occupied rows in F) + // E2V current edge (GV_i,GV_j) to vertex (V_k) map + // Side-effects: V,n,F,m,E2V are updated to contain new vertices and faces of + // any constructed mesh elements + // + template < + typename DerivedGV, + typename Scalar, + typename Index, + typename DerivedV, + typename DerivedF> + IGL_INLINE void march_cube( + const DerivedGV & GV, + const Eigen::Matrix & cS, + const Eigen::Matrix & cI, + const Scalar & isovalue, + Eigen::PlainObjectBase &V, + Index & n, + Eigen::PlainObjectBase &F, + Index & m, + std::unordered_map & E2V); +} + +#ifndef IGL_STATIC_LIBRARY +# include "march_cube.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/marching_cubes.cpp b/vendor/libigl/include/igl/marching_cubes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d6c388680421819533791d7f725f59085c02551c --- /dev/null +++ b/vendor/libigl/include/igl/marching_cubes.cpp @@ -0,0 +1,139 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2021 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "marching_cubes.h" +#include "march_cube.h" + +// Adapted from public domain code at +// http://paulbourke.net/geometry/polygonise/marchingsource.cpp + +#include +#include + +template +IGL_INLINE void igl::marching_cubes( + const Eigen::MatrixBase &S, + const Eigen::MatrixBase &GV, + const unsigned nx, + const unsigned ny, + const unsigned nz, + const typename DerivedS::Scalar isovalue, + Eigen::PlainObjectBase &V, + Eigen::PlainObjectBase &F) +{ + typedef typename DerivedS::Scalar Scalar; + typedef unsigned Index; + // use same order as a2fVertexOffset + const unsigned ioffset[8] = {0,1,1+nx,nx,nx*ny,1+nx*ny,1+nx+nx*ny,nx+nx*ny}; + + + std::unordered_map E2V; + V.resize(std::pow(nx*ny*nz,2./3.),3); + F.resize(std::pow(nx*ny*nz,2./3.),3); + Index n = 0; + Index m = 0; + + const auto xyz2i = [&nx,&ny,&nz] + (const int & x, const int & y, const int & z)->unsigned + { + return x+nx*(y+ny*(z)); + }; + const auto cube = + [ + &GV,&S,&V,&n,&F,&m,&isovalue, + &E2V,&xyz2i,&ioffset + ] + (const int x, const int y, const int z) + { + const unsigned i = xyz2i(x,y,z); + + //Make a local copy of the values at the cube's corners + Eigen::Matrix cS; + Eigen::Matrix cI; + //Find which vertices are inside of the surface and which are outside + for(int c = 0; c < 8; c++) + { + const unsigned ic = i + ioffset[c]; + cI(c) = ic; + cS(c) = S(ic); + } + + march_cube(GV,cS,cI,isovalue,V,n,F,m,E2V); + + }; + + // march over all cubes (loop order chosen to match memory) + // + // Should be possible to parallelize safely if threads are "well separated". + // Like red-black Gauss Seidel. Probably each thread need's their own E2V,V,F, + // and then merge at the end. Annoying part are the edges lying on the + // interface between chunks. + for(int z=0;z +IGL_INLINE void igl::marching_cubes( + const Eigen::MatrixBase & S, + const Eigen::MatrixBase & GV, + const Eigen::MatrixBase & GI, + const typename DerivedS::Scalar isovalue, + Eigen::PlainObjectBase &V, + Eigen::PlainObjectBase &F) +{ + typedef Eigen::Index Index; + typedef typename DerivedV::Scalar Scalar; + + std::unordered_map E2V; + V.resize(4*GV.rows(),3); + F.resize(4*GV.rows(),3); + Index n = 0; + Index m = 0; + + // march over cubes + + //Make a local copy of the values at the cube's corners + Eigen::Matrix cS; + Eigen::Matrix cI; + for(Index c = 0;c, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, unsigned int, unsigned int, unsigned int, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::marching_cubes, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, unsigned int, unsigned int, unsigned int, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::marching_cubes, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, unsigned int, unsigned int, unsigned int, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::marching_cubes, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/marching_cubes_tables.h b/vendor/libigl/include/igl/marching_cubes_tables.h new file mode 100644 index 0000000000000000000000000000000000000000..84fb909ac6c833e0548ef5131f9a91de985b72ef --- /dev/null +++ b/vendor/libigl/include/igl/marching_cubes_tables.h @@ -0,0 +1,293 @@ + const int aiCubeEdgeFlags[256]= + { + 0x000, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, + 0x190, 0x099, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, + 0x230, 0x339, 0x033, 0x13a, 0x636, 0x73f, 0x435, 0x53c, 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, + 0x3a0, 0x2a9, 0x1a3, 0x0aa, 0x7a6, 0x6af, 0x5a5, 0x4ac, 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, + 0x460, 0x569, 0x663, 0x76a, 0x066, 0x16f, 0x265, 0x36c, 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, + 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0x0ff, 0x3f5, 0x2fc, 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, + 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x055, 0x15c, 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950, + 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0x0cc, 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, + 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, 0x0cc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, + 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x15c, 0x055, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, + 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, 0x2fc, 0x3f5, 0x0ff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, + 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, 0x36c, 0x265, 0x16f, 0x066, 0x76a, 0x663, 0x569, 0x460, + 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, 0x4ac, 0x5a5, 0x6af, 0x7a6, 0x0aa, 0x1a3, 0x2a9, 0x3a0, + 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x033, 0x339, 0x230, + 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x099, 0x190, + 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x000 + }; + //a2eConnection lists the index of the endpoint vertices for each of the 12 edges of the cube + const int a2eConnection[12][2] = + { + {0,1}, {1,2}, {2,3}, {3,0}, + {4,5}, {5,6}, {6,7}, {7,4}, + {0,4}, {1,5}, {2,6}, {3,7} + }; + // For each of the possible vertex states listed in aiCubeEdgeFlags there is a specific triangulation + // of the edge intersection points. a2fConnectionTable lists all of them in the form of + // 0-5 edge triples with the list terminated by the invalid value -1. + // For example: a2fConnectionTable[3] list the 2 triangles formed when corner[0] + // and corner[1] are inside of the surface, but the rest of the cube is not. + // + // I found this table in an example program someone wrote long ago. It was probably generated by hand + const int a2fConnectionTable[256][16] = + { + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1}, + {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1}, + {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1}, + {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1}, + {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1}, + {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, + {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1}, + {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1}, + {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, + {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1}, + {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1}, + {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1}, + {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1}, + {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, + {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1}, + {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1}, + {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, + {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, + {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1}, + {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1}, + {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1}, + {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1}, + {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1}, + {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1}, + {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1}, + {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1}, + {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1}, + {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1}, + {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1}, + {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1}, + {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1}, + {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1}, + {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1}, + {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, + {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1}, + {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1}, + {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1}, + {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, + {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1}, + {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1}, + {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1}, + {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1}, + {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1}, + {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, + {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1}, + {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1}, + {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1}, + {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1}, + {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, + {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1}, + {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1}, + {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1}, + {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1}, + {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1}, + {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1}, + {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1}, + {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1}, + {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1}, + {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1}, + {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1}, + {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1}, + {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1}, + {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1}, + {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1}, + {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1}, + {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1}, + {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1}, + {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1}, + {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1}, + {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1}, + {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1}, + {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1}, + {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1}, + {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1}, + {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1}, + {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1}, + {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1}, + {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1}, + {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1}, + {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, + {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, + {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, + {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1}, + {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1}, + {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1}, + {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1}, + {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1}, + {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1}, + {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1}, + {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1}, + {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1}, + {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1}, + {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1}, + {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1}, + {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1}, + {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1}, + {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1}, + {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1}, + {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1}, + {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1}, + {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1}, + {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1}, + {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, + {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, + {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1}, + {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, + {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1}, + {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1}, + {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1}, + {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1}, + {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1}, + {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1}, + {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1}, + {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1}, + {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1}, + {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1}, + {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1}, + {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1}, + {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1}, + {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1}, + {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1}, + {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1}, + {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1}, + {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1}, + {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1}, + {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1}, + {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1}, + {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1}, + {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1}, + {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1}, + {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1}, + {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1}, + {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1}, + {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1}, + {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1}, + {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1}, + {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1}, + {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1}, + {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1}, + {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1}, + {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1}, + {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1}, + {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1}, + {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1}, + {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1}, + {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1}, + {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1}, + {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1}, + {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1}, + {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1}, + {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1}, + {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1}, + {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1}, + {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1}, + {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1}, + {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1}, + {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1}, + {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1}, + {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1}, + {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1}, + {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1}, + {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1}, + {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1}, + {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1}, + {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1}, + {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1}, + {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1}, + {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1}, + {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} + }; + diff --git a/vendor/libigl/include/igl/marching_tets.h b/vendor/libigl/include/igl/marching_tets.h new file mode 100644 index 0000000000000000000000000000000000000000..19df54482b4f66a08de34ff59d079f4c5c945a90 --- /dev/null +++ b/vendor/libigl/include/igl/marching_tets.h @@ -0,0 +1,196 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Francis Williams +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_MARCHING_TETS_H +#define IGL_MARCHING_TETS_H + +#include "igl_inline.h" +#include +#include + +namespace igl { + // marching_tets( TV, TT, S, isovalue, SV, SF, J, BC) + // + // performs the marching tetrahedra algorithm on a tet mesh defined by TV and + // TT with scalar values defined at each vertex in TV. The output is a + // triangle mesh approximating the isosurface coresponding to the value + // isovalue. + // + // Input: + // TV #tet_vertices x 3 array -- The vertices of the tetrahedral mesh + // TT #tets x 4 array -- The indexes of each tet in the tetrahedral mesh + // S #tet_vertices x 1 array -- The values defined on each tet vertex + // isovalue scalar -- The isovalue of the level set we want to compute + // + // Output: + // SV #SV x 3 array -- The vertices of the output level surface mesh + // SF #SF x 3 array -- The face indexes of the output level surface mesh + // J #SF list of indices into TT revealing which tet each face comes from + // BC #SV x #TV list of barycentric coordinates so that SV = BC*TV + template + IGL_INLINE void marching_tets( + const Eigen::MatrixBase& TV, + const Eigen::MatrixBase& TT, + const Eigen::MatrixBase& S, + double isovalue, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SF, + Eigen::PlainObjectBase& J, + Eigen::SparseMatrix& BC); + + // marching_tets( TV, TT, S, SV, SF, J, BC) + // + // Performs the marching tetrahedra algorithm on a tet mesh defined by TV and + // TT with scalar values defined at each vertex in TV. The output is a + // triangle mesh approximating the isosurface coresponding to an isovalue of 0. + // + // Input: + // TV #tet_vertices x 3 array -- The vertices of the tetrahedral mesh + // TT #tets x 4 array -- The indexes of each tet in the tetrahedral mesh + // S #tet_vertices x 1 array -- The values defined on each tet vertex + // isovalue scalar -- The isovalue of the level set we want to compute + // + // Output: + // SV #SV x 3 array -- The vertices of the output level surface mesh + // SF #SF x 3 array -- The face indexes of the output level surface mesh + // J #SF list of indices into TT revealing which tet each face comes from + // BC #SV x #TV list of barycentric coordinates so that SV = BC*TV + template + IGL_INLINE void marching_tets( + const Eigen::MatrixBase& TV, + const Eigen::MatrixBase& TT, + const Eigen::MatrixBase& S, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SF, + Eigen::PlainObjectBase& J, + Eigen::SparseMatrix& BC) { + return igl::marching_tets(TV, TT, S, 0.0, SV, SF, J, BC); + } + + // marching_tets( TV, TT, S, isovalue, SV, SF, J) + // + // performs the marching tetrahedra algorithm on a tet mesh defined by TV and + // TT with scalar values defined at each vertex in TV. The output is a + // triangle mesh approximating the isosurface coresponding to the value + // isovalue. + // + // Input: + // TV #tet_vertices x 3 array -- The vertices of the tetrahedral mesh + // TT #tets x 4 array -- The indexes of each tet in the tetrahedral mesh + // S #tet_vertices x 1 array -- The values defined on each tet vertex + // isovalue scalar -- The isovalue of the level set we want to compute + // + // Output: + // SV #SV x 3 array -- The vertices of the output level surface mesh + // SF #SF x 3 array -- The face indexes of the output level surface mesh + // J #SF list of indices into TT revealing which tet each face comes from + template + IGL_INLINE void marching_tets( + const Eigen::MatrixBase& TV, + const Eigen::MatrixBase& TT, + const Eigen::MatrixBase& S, + double isovalue, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SF, + Eigen::PlainObjectBase& J) { + Eigen::SparseMatrix _BC; + return igl::marching_tets(TV, TT, S, isovalue, SV, SF, J, _BC); + } + + // marching_tets( TV, TT, S, isovalue, SV, SF, BC) + // + // performs the marching tetrahedra algorithm on a tet mesh defined by TV and + // TT with scalar values defined at each vertex in TV. The output is a + // triangle mesh approximating the isosurface coresponding to the value + // isovalue. + // + // Input: + // TV #tet_vertices x 3 array -- The vertices of the tetrahedral mesh + // TT #tets x 4 array -- The indexes of each tet in the tetrahedral mesh + // S #tet_vertices x 1 array -- The values defined on each tet vertex + // isovalue scalar -- The isovalue of the level set we want to compute + // + // Output: + // SV #SV x 3 array -- The vertices of the output level surface mesh + // SF #SF x 3 array -- The face indexes of the output level surface mesh + // BC #SV x #TV list of barycentric coordinates so that SV = BC*TV + template + IGL_INLINE void marching_tets( + const Eigen::MatrixBase& TV, + const Eigen::MatrixBase& TT, + const Eigen::MatrixBase& S, + double isovalue, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SF, + Eigen::SparseMatrix& BC) { + Eigen::VectorXi _J; + return igl::marching_tets(TV, TT, S, isovalue, SV, SF, _J, BC); + } + + // marching_tets( TV, TT, S, isovalue, SV, SF) + // + // performs the marching tetrahedra algorithm on a tet mesh defined by TV and + // TT with scalar values defined at each vertex in TV. The output is a + // triangle mesh approximating the isosurface coresponding to the value + // isovalue. + // + // Input: + // TV #tet_vertices x 3 array -- The vertices of the tetrahedral mesh + // TT #tets x 4 array -- The indexes of each tet in the tetrahedral mesh + // S #tet_vertices x 1 array -- The values defined on each tet vertex + // isovalue scalar -- The isovalue of the level set we want to compute + // + // Output: + // SV #SV x 3 array -- The vertices of the output level surface mesh + // SF #SF x 3 array -- The face indexes of the output level surface mesh + template + IGL_INLINE void marching_tets( + const Eigen::MatrixBase& TV, + const Eigen::MatrixBase& TT, + const Eigen::MatrixBase& S, + double isovalue, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SF) { + Eigen::VectorXi _J; + Eigen::SparseMatrix _BC; + return igl::marching_tets(TV, TT, S, isovalue, SV, SF, _J, _BC); + } + +} + +#ifndef IGL_STATIC_LIBRARY +# include "marching_tets.cpp" +#endif + +#endif // IGL_MARCHING_TETS_H diff --git a/vendor/libigl/include/igl/massmatrix.cpp b/vendor/libigl/include/igl/massmatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e89c00f5a3a53a79c1befa4ce451d8be61ec7915 --- /dev/null +++ b/vendor/libigl/include/igl/massmatrix.cpp @@ -0,0 +1,96 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "massmatrix.h" +#include "massmatrix_intrinsic.h" +#include "edge_lengths.h" +#include "normalize_row_sums.h" +#include "sparse.h" +#include "doublearea.h" +#include "repmat.h" +#include +#include + +template +IGL_INLINE void igl::massmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const MassMatrixType type, + Eigen::SparseMatrix& M) +{ + using namespace Eigen; + using namespace std; + + const int n = V.rows(); + const int m = F.rows(); + const int simplex_size = F.cols(); + + MassMatrixType eff_type = type; + // Use voronoi of for triangles by default, otherwise barycentric + if(type == MASSMATRIX_TYPE_DEFAULT) + { + eff_type = (simplex_size == 3?MASSMATRIX_TYPE_VORONOI:MASSMATRIX_TYPE_BARYCENTRIC); + } + + // Not yet supported + assert(type!=MASSMATRIX_TYPE_FULL); + + if(simplex_size == 3) + { + // Triangles + // edge lengths numbered same as opposite vertices + Matrix l; + igl::edge_lengths(V,F,l); + return massmatrix_intrinsic(l,F,type,M); + }else if(simplex_size == 4) + { + Matrix MI; + Matrix MJ; + Matrix MV; + assert(V.cols() == 3); + assert(eff_type == MASSMATRIX_TYPE_BARYCENTRIC); + MI.resize(m*4,1); MJ.resize(m*4,1); MV.resize(m*4,1); + MI.block(0*m,0,m,1) = F.col(0); + MI.block(1*m,0,m,1) = F.col(1); + MI.block(2*m,0,m,1) = F.col(2); + MI.block(3*m,0,m,1) = F.col(3); + MJ = MI; + // loop over tets + for(int i = 0;i v0m3,v1m3,v2m3; + v0m3.head(V.cols()) = V.row(F(i,0)) - V.row(F(i,3)); + v1m3.head(V.cols()) = V.row(F(i,1)) - V.row(F(i,3)); + v2m3.head(V.cols()) = V.row(F(i,2)) - V.row(F(i,3)); + Scalar v = fabs(v0m3.dot(v1m3.cross(v2m3)))/6.0; + MV(i+0*m) = v/4.0; + MV(i+1*m) = v/4.0; + MV(i+2*m) = v/4.0; + MV(i+3*m) = v/4.0; + } + sparse(MI,MJ,MV,n,n,M); + }else + { + // Unsupported simplex size + assert(false && "Unsupported simplex size"); + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/massmatrix.h b/vendor/libigl/include/igl/massmatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..b8a6fe486c4618c651de28ddf62045e7fd8549c5 --- /dev/null +++ b/vendor/libigl/include/igl/massmatrix.h @@ -0,0 +1,60 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MASSMATRIX_H +#define IGL_MASSMATRIX_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + + enum MassMatrixType + { + MASSMATRIX_TYPE_BARYCENTRIC = 0, + MASSMATRIX_TYPE_VORONOI = 1, + MASSMATRIX_TYPE_FULL = 2, + MASSMATRIX_TYPE_DEFAULT = 3, + NUM_MASSMATRIX_TYPE = 4 + }; + + // Constructs the mass (area) matrix for a given mesh (V,F). + // + // Templates: + // DerivedV derived type of eigen matrix for V (e.g. derived from + // MatrixXd) + // DerivedF derived type of eigen matrix for F (e.g. derived from + // MatrixXi) + // Scalar scalar type for eigen sparse matrix (e.g. double) + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by simplex_size list of mesh elements (triangles or tetrahedra) + // type one of the following ints: + // MASSMATRIX_TYPE_BARYCENTRIC barycentric + // MASSMATRIX_TYPE_VORONOI voronoi-hybrid {default} + // MASSMATRIX_TYPE_FULL full {not implemented} + // Outputs: + // M #V by #V mass matrix + // + // See also: adjacency_matrix + // + template + IGL_INLINE void massmatrix( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const MassMatrixType type, + Eigen::SparseMatrix& M); +} + +#ifndef IGL_STATIC_LIBRARY +# include "massmatrix.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/massmatrix_intrinsic.cpp b/vendor/libigl/include/igl/massmatrix_intrinsic.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe34873ab03ba5e0536fcec0f252af75fc5ae30f --- /dev/null +++ b/vendor/libigl/include/igl/massmatrix_intrinsic.cpp @@ -0,0 +1,128 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "massmatrix_intrinsic.h" +#include "edge_lengths.h" +#include "normalize_row_sums.h" +#include "sparse.h" +#include "doublearea.h" +#include "repmat.h" +#include +#include +#include + +template +IGL_INLINE void igl::massmatrix_intrinsic( + const Eigen::MatrixBase & l, + const Eigen::MatrixBase & F, + const MassMatrixType type, + Eigen::SparseMatrix& M) +{ + const int n = F.maxCoeff()+1; + return massmatrix_intrinsic(l,F,type,n,M); +} + +template +IGL_INLINE void igl::massmatrix_intrinsic( + const Eigen::MatrixBase & l, + const Eigen::MatrixBase & F, + const MassMatrixType type, + const int n, + Eigen::SparseMatrix& M) +{ + using namespace Eigen; + using namespace std; + MassMatrixType eff_type = type; + const int m = F.rows(); + const int simplex_size = F.cols(); + // Use voronoi of for triangles by default, otherwise barycentric + if(type == MASSMATRIX_TYPE_DEFAULT) + { + eff_type = (simplex_size == 3?MASSMATRIX_TYPE_VORONOI:MASSMATRIX_TYPE_BARYCENTRIC); + } + assert(F.cols() == 3 && "only triangles supported"); + Matrix dblA; + doublearea(l,0.,dblA); + Matrix MI; + Matrix MJ; + Matrix MV; + + switch(eff_type) + { + case MASSMATRIX_TYPE_BARYCENTRIC: + // diagonal entries for each face corner + MI.resize(m*3,1); MJ.resize(m*3,1); MV.resize(m*3,1); + MI.block(0*m,0,m,1) = F.col(0); + MI.block(1*m,0,m,1) = F.col(1); + MI.block(2*m,0,m,1) = F.col(2); + MJ = MI; + repmat(dblA,3,1,MV); + MV.array() /= 6.0; + break; + case MASSMATRIX_TYPE_VORONOI: + { + // diagonal entries for each face corner + // http://www.alecjacobson.com/weblog/?p=874 + MI.resize(m*3,1); MJ.resize(m*3,1); MV.resize(m*3,1); + MI.block(0*m,0,m,1) = F.col(0); + MI.block(1*m,0,m,1) = F.col(1); + MI.block(2*m,0,m,1) = F.col(2); + MJ = MI; + + // Holy shit this needs to be cleaned up and optimized + Matrix cosines(m,3); + cosines.col(0) = + (l.col(2).array().pow(2)+l.col(1).array().pow(2)-l.col(0).array().pow(2))/(l.col(1).array()*l.col(2).array()*2.0); + cosines.col(1) = + (l.col(0).array().pow(2)+l.col(2).array().pow(2)-l.col(1).array().pow(2))/(l.col(2).array()*l.col(0).array()*2.0); + cosines.col(2) = + (l.col(1).array().pow(2)+l.col(0).array().pow(2)-l.col(2).array().pow(2))/(l.col(0).array()*l.col(1).array()*2.0); + Matrix barycentric = cosines.array() * l.array(); + normalize_row_sums(barycentric,barycentric); + Matrix partial = barycentric; + partial.col(0).array() *= dblA.array() * 0.5; + partial.col(1).array() *= dblA.array() * 0.5; + partial.col(2).array() *= dblA.array() * 0.5; + Matrix quads(partial.rows(),partial.cols()); + quads.col(0) = (partial.col(1)+partial.col(2))*0.5; + quads.col(1) = (partial.col(2)+partial.col(0))*0.5; + quads.col(2) = (partial.col(0)+partial.col(1))*0.5; + + quads.col(0) = (cosines.col(0).array()<0).select( 0.25*dblA,quads.col(0)); + quads.col(1) = (cosines.col(0).array()<0).select(0.125*dblA,quads.col(1)); + quads.col(2) = (cosines.col(0).array()<0).select(0.125*dblA,quads.col(2)); + + quads.col(0) = (cosines.col(1).array()<0).select(0.125*dblA,quads.col(0)); + quads.col(1) = (cosines.col(1).array()<0).select(0.25*dblA,quads.col(1)); + quads.col(2) = (cosines.col(1).array()<0).select(0.125*dblA,quads.col(2)); + + quads.col(0) = (cosines.col(2).array()<0).select(0.125*dblA,quads.col(0)); + quads.col(1) = (cosines.col(2).array()<0).select(0.125*dblA,quads.col(1)); + quads.col(2) = (cosines.col(2).array()<0).select( 0.25*dblA,quads.col(2)); + + MV.block(0*m,0,m,1) = quads.col(0); + MV.block(1*m,0,m,1) = quads.col(1); + MV.block(2*m,0,m,1) = quads.col(2); + + break; + } + case MASSMATRIX_TYPE_FULL: + assert(false && "Implementation incomplete"); + break; + default: + assert(false && "Unknown Mass matrix eff_type"); + } + sparse(MI,MJ,MV,n,n,M); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::massmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +template void igl::massmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +template void igl::massmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +template void igl::massmatrix_intrinsic, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/mat_min.cpp b/vendor/libigl/include/igl/mat_min.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c34e993fe5ce6bc8c566f96906c276dc19f746b2 --- /dev/null +++ b/vendor/libigl/include/igl/mat_min.cpp @@ -0,0 +1,59 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "mat_min.h" + +template +IGL_INLINE void igl::mat_min( + const Eigen::DenseBase & X, + const int dim, + Eigen::PlainObjectBase & Y, + Eigen::PlainObjectBase & I) +{ + assert(dim==1||dim==2); + + // output size + int n = (dim==1?X.cols():X.rows()); + // resize output + Y.resize(n,1); + I.resize(n,1); + + // loop over dimension opposite of dim + for(int j = 0;j +//IGL_INLINE Eigen::Matrix igl::mat_min( +// const Eigen::Matrix & X, +// const int dim) +//{ +// Eigen::Matrix Y; +// Eigen::Matrix I; +// mat_min(X,dim,Y,I); +// return Y; +//} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::mat_min, Eigen::Array, Eigen::Matrix >(Eigen::DenseBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::mat_min, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/mat_to_quat.h b/vendor/libigl/include/igl/mat_to_quat.h new file mode 100644 index 0000000000000000000000000000000000000000..acea683f7717467c8aae39350a5672512ec99ffd --- /dev/null +++ b/vendor/libigl/include/igl/mat_to_quat.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MAT_TO_QUAT_H +#define IGL_MAT_TO_QUAT_H +#include "igl_inline.h" +namespace igl +{ + // Convert a OpenGL (rotation) matrix to a quaternion + // + // Input: + // m 16-element opengl rotation matrix + // Output: + // q 4-element quaternion (not normalized) + template + IGL_INLINE void mat4_to_quat(const Q_type * m, Q_type * q); + // Input: + // m 9-element opengl rotation matrix + template + IGL_INLINE void mat3_to_quat(const Q_type * m, Q_type * q); +} + +#ifndef IGL_STATIC_LIBRARY +# include "mat_to_quat.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/material_colors.h b/vendor/libigl/include/igl/material_colors.h new file mode 100644 index 0000000000000000000000000000000000000000..1927fa42dbf0388b830d78f79cacda8d6babf031 --- /dev/null +++ b/vendor/libigl/include/igl/material_colors.h @@ -0,0 +1,57 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MATERIAL_COLORS_H +#define IGL_MATERIAL_COLORS_H +#include +// Define constant material colors for use with opengl glMaterialfv +// Most of these colors come from IGL publications +namespace igl +{ + // Gold/Silver used in BBW/MONO/STBS/FAST + const float GOLD_AMBIENT[4] = { 51.0/255.0, 43.0/255.0,33.3/255.0,1.0f }; + const float GOLD_DIFFUSE[4] = { 255.0/255.0,228.0/255.0,58.0/255.0,1.0f }; + const float GOLD_SPECULAR[4] = { 255.0/255.0,235.0/255.0,80.0/255.0,1.0f }; + const float SILVER_AMBIENT[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; + const float SILVER_DIFFUSE[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + const float SILVER_SPECULAR[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + // Blue/Cyan more similar to Jovan Popovic's blue than to Mario Botsch's blue + const float CYAN_AMBIENT[4] = { 59.0/255.0, 68.0/255.0,255.0/255.0,1.0f }; + const float CYAN_DIFFUSE[4] = { 94.0/255.0,185.0/255.0,238.0/255.0,1.0f }; + const float CYAN_SPECULAR[4] = { 163.0/255.0,221.0/255.0,255.0/255.0,1.0f }; + const float DENIS_PURPLE_DIFFUSE[4] = { 80.0/255.0,64.0/255.0,255.0/255.0,1.0f }; + const float LADISLAV_ORANGE_DIFFUSE[4] = {1.0f, 125.0f / 255.0f, 19.0f / 255.0f, 0.0f}; + // FAST armadillos colors + const float FAST_GREEN_DIFFUSE[4] = { 113.0f/255.0f, 239.0f/255.0f, 46.0f/255.0f, 1.0f}; + const float FAST_RED_DIFFUSE[4] = { 255.0f/255.0f, 65.0f/255.0f, 46.0f/255.0f, 1.0f}; + const float FAST_BLUE_DIFFUSE[4] = { 106.0f/255.0f, 106.0f/255.0f, 255.0f/255.0f, 1.0f}; + const float FAST_GRAY_DIFFUSE[4] = { 150.0f/255.0f, 150.0f/255.0f, 150.0f/255.0f, 1.0f}; + // Basic colors + const float WHITE[4] = { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f }; + const float BLACK[4] = { 0.0/255.0,0.0/255.0,0.0/255.0,1.0f }; + const float WHITE_AMBIENT[4] = { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f }; + const float WHITE_DIFFUSE[4] = { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f }; + const float WHITE_SPECULAR[4] = { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f }; + const float BBW_POINT_COLOR[4] = {239./255.,213./255.,46./255.,255.0/255.0}; + const float BBW_LINE_COLOR[4] = {106./255.,106./255.,255./255.,255./255.}; + const float MIDNIGHT_BLUE_DIFFUSE[4] = { 21.0f/255.0f, 27.0f/255.0f, 84.0f/255.0f, 1.0f}; + // Winding number colors + const float EASTER_RED_DIFFUSE[4] = {0.603922,0.494118f,0.603922f,1.0f}; + const float WN_OPEN_BOUNDARY_COLOR[4] = {154./255.,0./255.,0./255.,1.0f}; + const float WN_NON_MANIFOLD_EDGE_COLOR[4] = {201./255., 51./255.,255./255.,1.0f}; + const Eigen::Vector4f + MAYA_GREEN(128./255.,242./255.,0./255.,1.), + MAYA_YELLOW(255./255.,247./255.,50./255.,1.), + MAYA_RED(234./255.,63./255.,52./255.,1.), + MAYA_BLUE(0./255.,73./255.,252./255.,1.), + MAYA_PURPLE(180./255.,73./255.,200./255.,1.), + MAYA_VIOLET(31./255.,15./255.,66./255.,1.), + MAYA_GREY(0.5,0.5,0.5,1.0), + MAYA_CYAN(131./255.,219./255.,252./255.,1.), + MAYA_SEA_GREEN(70./255.,252./255.,167./255.,1.); +} +#endif diff --git a/vendor/libigl/include/igl/matlab_format.cpp b/vendor/libigl/include/igl/matlab_format.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0dbaf49906d8056b5b389d4093d19c8ae39b9229 --- /dev/null +++ b/vendor/libigl/include/igl/matlab_format.cpp @@ -0,0 +1,298 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "matlab_format.h" +#include "STR.h" +#include "find.h" + +template +IGL_INLINE const Eigen::WithFormat< DerivedM > igl::matlab_format( + const Eigen::DenseBase & M, + const std::string name) +{ + using namespace std; + string prefix = ""; + if(!name.empty()) + { + prefix = name + " = "; + } + + return M.format(Eigen::IOFormat( + Eigen::FullPrecision, + 0, + " ", + "\n", + "", + "", + // This seems like a bit of a hack since I would expect the rows to align + // with out this extra spacing on the first line + prefix + "[\n ", + "\n];")); +} + +template +IGL_INLINE std::string igl::matlab_format_index( + const Eigen::MatrixBase & M, + const std::string name) +{ + // can't return WithFormat since that uses a pointer to matrix + return STR(igl::matlab_format((M.array()+1).eval(),name)); +} + +template +IGL_INLINE const std::string +igl::matlab_format( + const Eigen::SparseMatrix & S, + const std::string name) +{ + using namespace Eigen; + using namespace std; + Matrix::Scalar,Dynamic,1> I,J,V; + Matrix SIJV; + find(S,I,J,V); + I.array() += 1; + J.array() += 1; + SIJV.resize(V.rows(),3); + SIJV << I,J,V; + string prefix = ""; + string suffix = ""; + if(!name.empty()) + { + prefix = name + "IJV = "; + suffix = "\n"+name + " = sparse("+name+"IJV(:,1),"+name+"IJV(:,2),"+name+"IJV(:,3),"+std::to_string(S.rows())+","+std::to_string(S.cols())+" );"; + } + return STR(""<< + SIJV.format(Eigen::IOFormat( + Eigen::FullPrecision, + 0, + " ", + "\n", + "", + "", + // This seems like a bit of a hack since I would expect the rows to align + // with out this extra spacing on the first line + prefix + "[\n ", + "\n];"))< > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +// generated by autoexplicit.sh +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template std::basic_string, std::allocator > igl::matlab_format_index >(Eigen::MatrixBase > const&, std::basic_string, std::allocator >); +template std::basic_string, std::allocator > igl::matlab_format_index >(Eigen::MatrixBase > const&, std::basic_string, std::allocator >); +/////////////////////////////////////////////////// +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +#if EIGEN_VERSION_AT_LEAST(3,3,0) +#else +template Eigen::WithFormat, Eigen::Matrix const> > const igl::matlab_format, Eigen::Matrix const> >(Eigen::DenseBase, Eigen::Matrix const> > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat, Eigen::ArrayWrapper const> const> > const igl::matlab_format, Eigen::ArrayWrapper const> const> >(Eigen::DenseBase, Eigen::ArrayWrapper const> const> > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat, Eigen::ArrayWrapper > const> > const igl::matlab_format, Eigen::ArrayWrapper > const> >(Eigen::DenseBase, Eigen::ArrayWrapper > const> > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat, Eigen::ArrayWrapper > const> > const igl::matlab_format, Eigen::ArrayWrapper > const> >(Eigen::DenseBase, Eigen::ArrayWrapper > const> > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat, -1, -1, false> > > const igl::matlab_format, -1, -1, false> > >(Eigen::DenseBase, -1, -1, false> > > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > > const igl::matlab_format > >(Eigen::DenseBase > > const&, std::basic_string, std::allocator >); +#endif +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template std::basic_string, std::allocator > const igl::matlab_format(Eigen::SparseMatrix const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::string); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +template Eigen::WithFormat > const igl::matlab_format >(Eigen::DenseBase > const&, std::basic_string, std::allocator >); +#endif diff --git a/vendor/libigl/include/igl/matrix_to_list.cpp b/vendor/libigl/include/igl/matrix_to_list.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eadc3bd85ccd0524937f749e86e0d100d39fc777 --- /dev/null +++ b/vendor/libigl/include/igl/matrix_to_list.cpp @@ -0,0 +1,79 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "matrix_to_list.h" + +#include + +template +IGL_INLINE void igl::matrix_to_list( + const Eigen::MatrixBase & M, + std::vector > & V) +{ + using namespace std; + V.resize(M.rows(),vector(M.cols())); + // loop over rows + for(int i = 0;i +IGL_INLINE void igl::matrix_to_list( + const Eigen::MatrixBase & M, + std::vector & V) +{ + using namespace std; + V.resize(M.size()); + // loop over cols then rows + for(int j = 0;j +IGL_INLINE std::vector igl::matrix_to_list( + const Eigen::MatrixBase & M) +{ + std::vector V; + matrix_to_list(M,V); + return V; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::matrix_to_list, -1, 1, true> >(Eigen::MatrixBase, -1, 1, true> > const&, std::vector, -1, 1, true>::Scalar, std::allocator, -1, 1, true>::Scalar> >&); +// generated by autoexplicit.sh +template void igl::matrix_to_list, -1, 1, true> >(Eigen::MatrixBase, -1, 1, true> > const&, std::vector, -1, 1, true>::Scalar, std::allocator, -1, 1, true>::Scalar> >&); +// generated by autoexplicit.sh +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >&); +// generated by autoexplicit.sh +template std::vector::Scalar, std::allocator::Scalar> > igl::matrix_to_list >(Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template std::vector::Scalar, std::allocator::Scalar> > igl::matrix_to_list >(Eigen::MatrixBase > const&); +//template void igl::matrix_to_list >, double>(Eigen::PlainObjectBase > const&, std::vector >, std::allocator > > >&); +//template void igl::matrix_to_list >, int>(Eigen::PlainObjectBase > const&, std::vector >, std::allocator > > >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >, std::allocator::Scalar, std::allocator::Scalar> > > >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >, std::allocator::Scalar, std::allocator::Scalar> > > >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >, std::allocator::Scalar, std::allocator::Scalar> > > >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >&); +template void igl::matrix_to_list >(Eigen::MatrixBase > const&, std::vector::Scalar, std::allocator::Scalar> >&); +template std::vector::Scalar, std::allocator::Scalar> > igl::matrix_to_list >(Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/max.cpp b/vendor/libigl/include/igl/max.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e451c3b15f69d504b3acb7df05c1375cef580725 --- /dev/null +++ b/vendor/libigl/include/igl/max.cpp @@ -0,0 +1,46 @@ +#include "max.h" +#include "for_each.h" +#include "find_zero.h" + +template +IGL_INLINE void igl::max( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & I) +{ + const int n = A.cols(); + const int m = A.rows(); + B.resize(dim==1?n:m); + B.setConstant(std::numeric_limits::lowest()); + I.resize(dim==1?n:m); + for_each(A,[&B,&I,&dim](int i, int j,const typename DerivedB::Scalar v) + { + if(dim == 2) + { + std::swap(i,j); + } + // Coded as if dim == 1, assuming swap for dim == 2 + if(v > B(j)) + { + B(j) = v; + I(j) = i; + } + }); + Eigen::VectorXi Z; + find_zero(A,dim,Z); + for(int j = 0;j B(j)) + { + B(j) = 0; + I(j) = Z(j); + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::max, Eigen::Matrix >(Eigen::SparseMatrix const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/max_faces_stopping_condition.cpp b/vendor/libigl/include/igl/max_faces_stopping_condition.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d95022d22e2ef599894a047716b0fe8c92b318f --- /dev/null +++ b/vendor/libigl/include/igl/max_faces_stopping_condition.cpp @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "max_faces_stopping_condition.h" + +IGL_INLINE void igl::max_faces_stopping_condition( + int & m, + const int orig_m, + const int max_m, + decimate_stopping_condition_callback & stopping_condition) +{ + stopping_condition = + [orig_m,max_m,&m]( + const Eigen::MatrixXd &, + const Eigen::MatrixXi &, + const Eigen::MatrixXi &, + const Eigen::VectorXi &, + const Eigen::MatrixXi &, + const Eigen::MatrixXi &, + const igl::min_heap< std::tuple > & , + const Eigen::VectorXi & , + const Eigen::MatrixXd &, + const int, + const int, + const int, + const int f1, + const int f2)->bool + { + // Only subtract if we're collapsing a real face + if(f1 < orig_m) m-=1; + if(f2 < orig_m) m-=1; + return m<=(int)max_m; + }; +} + +IGL_INLINE igl::decimate_stopping_condition_callback +igl::max_faces_stopping_condition( + int & m, + const int orig_m, + const int max_m) +{ + decimate_stopping_condition_callback stopping_condition; + max_faces_stopping_condition(m,orig_m,max_m,stopping_condition); + return stopping_condition; +} diff --git a/vendor/libigl/include/igl/max_faces_stopping_condition.h b/vendor/libigl/include/igl/max_faces_stopping_condition.h new file mode 100644 index 0000000000000000000000000000000000000000..419a427bb59c376e44297e32847bd40f6ee55cd4 --- /dev/null +++ b/vendor/libigl/include/igl/max_faces_stopping_condition.h @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MAX_FACES_STOPPING_CONDITION_H +#define IGL_MAX_FACES_STOPPING_CONDITION_H +#include "igl_inline.h" +#include "decimate_callback_types.h" +#include +#include +#include +#include +namespace igl +{ + // Stopping condition function compatible with igl::decimate. The outpute + // function handle will return true if number of faces is less than max_m + // + // Inputs: + // m reference to working variable initially should be set to current + // number of faces. + // orig_m number (size) of original face list _**not**_ including any + // faces added to handle phony boundary faces connecting to point at + // infinity. For closed meshes it's safe to set this to F.rows() + // max_m maximum number of faces + // Outputs: + // stopping_condition + // + IGL_INLINE void max_faces_stopping_condition( + int & m, + const int orig_m, + const int max_m, + decimate_stopping_condition_callback & stopping_condition); + IGL_INLINE decimate_stopping_condition_callback + max_faces_stopping_condition( + int & m, + const int orign_m, + const int max_m); +} + +#ifndef IGL_STATIC_LIBRARY +# include "max_faces_stopping_condition.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/max_size.cpp b/vendor/libigl/include/igl/max_size.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9957f3b9129beb36d82248dd799a4743e10568dd --- /dev/null +++ b/vendor/libigl/include/igl/max_size.cpp @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "max_size.h" + + +template +IGL_INLINE int igl::max_size(const std::vector & V) +{ + int max_size = -1; + for( + typename std::vector::const_iterator iter = V.begin(); + iter != V.end(); + iter++) + { + int size = (int)iter->size(); + max_size = (max_size > size ? max_size : size); + } + return max_size; +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template int igl::max_size > >(std::vector >, std::allocator > > > const&); +// generated by autoexplicit.sh +template int igl::max_size > >(std::vector >, std::allocator > > > const&); +// generated by autoexplicit.sh +template int igl::max_size > >(std::vector >, std::allocator > > > const&); +// generated by autoexplicit.sh +template int igl::max_size > >(std::vector >, std::allocator > > > const&); +template int igl::max_size > >(std::vector >, std::allocator > > > const&); +template int igl::max_size > >(std::vector >, std::allocator > > > const&); +#ifdef WIN32 +template int igl::max_size > >(class std::vector >,class std::allocator > > > const &); +#endif +#endif diff --git a/vendor/libigl/include/igl/max_size.h b/vendor/libigl/include/igl/max_size.h new file mode 100644 index 0000000000000000000000000000000000000000..58035d4cee68b232d1302f49842d69539645ee35 --- /dev/null +++ b/vendor/libigl/include/igl/max_size.h @@ -0,0 +1,29 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MAX_SIZE_H +#define IGL_MAX_SIZE_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Determine max size of lists in a vector + // Template: + // T some list type object that implements .size() + // Inputs: + // V vector of list types T + // Returns max .size() found in V, returns -1 if V is empty + template + IGL_INLINE int max_size(const std::vector & V); +} + +#ifndef IGL_STATIC_LIBRARY +# include "max_size.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/median.cpp b/vendor/libigl/include/igl/median.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf6424db3a53931c3e83ab67e4c6408eee327bfd --- /dev/null +++ b/vendor/libigl/include/igl/median.cpp @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "median.h" +#include "matrix_to_list.h" + +#include +#include + +template +IGL_INLINE bool igl::median( + const Eigen::MatrixBase & V, mType & m) +{ + using namespace std; + if(V.size() == 0) + { + return false; + } + vector vV; + matrix_to_list(V,vV); + // http://stackoverflow.com/a/1719155/148668 + size_t n = vV.size()/2; + nth_element(vV.begin(),vV.begin()+n,vV.end()); + if(vV.size()%2==0) + { + nth_element(vV.begin(),vV.begin()+n-1,vV.end()); + m = 0.5*(vV[n]+vV[n-1]); + }else + { + m = vV[n]; + } + return true; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::median, -1, 1, true>, float>(Eigen::MatrixBase, -1, 1, true> > const&, float&); +// generated by autoexplicit.sh +template bool igl::median, -1, 1, true>, double>(Eigen::MatrixBase, -1, 1, true> > const&, double&); +template bool igl::median, double>(Eigen::MatrixBase > const&, double&); +#endif diff --git a/vendor/libigl/include/igl/median.h b/vendor/libigl/include/igl/median.h new file mode 100644 index 0000000000000000000000000000000000000000..7986dfda414441bb84b68e375c1676046b78cd4b --- /dev/null +++ b/vendor/libigl/include/igl/median.h @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MEDIAN_H +#define IGL_MEDIAN_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute the median of an eigen vector + // + // Inputs: + // V #V list of unsorted values + // Outputs: + // m median of those values + // Returns true on success, false on failure + template + IGL_INLINE bool median( + const Eigen::MatrixBase & V, mType & m); +} + +#ifndef IGL_STATIC_LIBRARY +# include "median.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/min.cpp b/vendor/libigl/include/igl/min.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce8ba328e63f10f66d8cc9e8a337ad41a61bbf6b --- /dev/null +++ b/vendor/libigl/include/igl/min.cpp @@ -0,0 +1,41 @@ +#include "min.h" +#include "for_each.h" +#include "find_zero.h" + +template +IGL_INLINE void igl::min( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & I) +{ + const int n = A.cols(); + const int m = A.rows(); + B.resize(dim==1?n:m); + B.setConstant(std::numeric_limits::max()); + I.resize(dim==1?n:m); + for_each(A,[&B,&I,&dim](int i, int j,const typename DerivedB::Scalar v) + { + if(dim == 2) + { + std::swap(i,j); + } + // Coded as if dim == 1, assuming swap for dim == 2 + if(v < B(j)) + { + B(j) = v; + I(j) = i; + } + }); + Eigen::VectorXi Z; + find_zero(A,dim,Z); + for(int j = 0;j +#include +namespace igl +{ + // Inputs: + // X m by n matrix + // dim dimension along which to take min + // Outputs: + // Y n-long vector (if dim == 1) + // or + // Y m-long vector (if dim == 2) + // I vector the same size as Y containing the indices along dim of minimum + // entries + template + IGL_INLINE void min( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & I); +} +#ifndef IGL_STATIC_LIBRARY +# include "min.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/min_quad_with_fixed.2.cpp b/vendor/libigl/include/igl/min_quad_with_fixed.2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ecd09c3dc9920ae797bb066eb1233690c3c79fc4 --- /dev/null +++ b/vendor/libigl/include/igl/min_quad_with_fixed.2.cpp @@ -0,0 +1,15 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "min_quad_with_fixed.impl.h" + +#ifdef IGL_STATIC_LIBRARY +template bool igl::min_quad_with_fixed, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/min_quad_with_fixed.h b/vendor/libigl/include/igl/min_quad_with_fixed.h new file mode 100644 index 0000000000000000000000000000000000000000..e400468e22bcdcd48a1e236be825e376cd6c35c0 --- /dev/null +++ b/vendor/libigl/include/igl/min_quad_with_fixed.h @@ -0,0 +1,225 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MIN_QUAD_WITH_FIXED_H +#define IGL_MIN_QUAD_WITH_FIXED_H +#include "igl_inline.h" + +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +#include +// Bug in unsupported/Eigen/SparseExtra needs iostream first +#include +#include + +namespace igl +{ + template + struct min_quad_with_fixed_data; + // Known Bugs: rows of Aeq **should probably** be linearly independent. + // During precomputation, the rows of a Aeq are checked via QR. But in case + // they're not then resulting probably will no longer be sparse: it will be + // slow. + // + // MIN_QUAD_WITH_FIXED Minimize a quadratic energy of the form + // + // trace( 0.5*Z'*A*Z + Z'*B + constant ) + // + // subject to + // + // Z(known,:) = Y, and + // Aeq*Z = Beq + // + // Templates: + // T should be a eigen matrix primitive type like int or double + // Inputs: + // A n by n matrix of quadratic coefficients + // known list of indices to known rows in Z + // Y list of fixed values corresponding to known rows in Z + // Aeq m by n list of linear equality constraint coefficients + // pd flag specifying whether A(unknown,unknown) is positive definite + // Outputs: + // data factorization struct with all necessary information to solve + // using min_quad_with_fixed_solve + // Returns true on success, false on error + // + // Benchmark: For a harmonic solve on a mesh with 325K facets, matlab 2.2 + // secs, igl/min_quad_with_fixed.h 7.1 secs + // + template + IGL_INLINE bool min_quad_with_fixed_precompute( + const Eigen::SparseMatrix& A, + const Eigen::MatrixBase & known, + const Eigen::SparseMatrix& Aeq, + const bool pd, + min_quad_with_fixed_data & data + ); + // Solves a system previously factored using min_quad_with_fixed_precompute + // + // Template: + // T type of sparse matrix (e.g. double) + // DerivedY type of Y (e.g. derived from VectorXd or MatrixXd) + // DerivedZ type of Z (e.g. derived from VectorXd or MatrixXd) + // Inputs: + // data factorization struct with all necessary precomputation to solve + // B n by k column of linear coefficients + // Y b by k list of constant fixed values + // Beq m by k list of linear equality constraint constant values + // Outputs: + // Z n by k solution + // sol #unknowns+#lagrange by k solution to linear system + // Returns true on success, false on error + template < + typename T, + typename DerivedB, + typename DerivedY, + typename DerivedBeq, + typename DerivedZ, + typename Derivedsol> + IGL_INLINE bool min_quad_with_fixed_solve( + const min_quad_with_fixed_data & data, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & Y, + const Eigen::MatrixBase & Beq, + Eigen::PlainObjectBase & Z, + Eigen::PlainObjectBase & sol); + // Wrapper without sol + template < + typename T, + typename DerivedB, + typename DerivedY, + typename DerivedBeq, + typename DerivedZ> + IGL_INLINE bool min_quad_with_fixed_solve( + const min_quad_with_fixed_data & data, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & Y, + const Eigen::MatrixBase & Beq, + Eigen::PlainObjectBase & Z); + template < + typename T, + typename Derivedknown, + typename DerivedB, + typename DerivedY, + typename DerivedBeq, + typename DerivedZ> + IGL_INLINE bool min_quad_with_fixed( + const Eigen::SparseMatrix& A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & known, + const Eigen::MatrixBase & Y, + const Eigen::SparseMatrix& Aeq, + const Eigen::MatrixBase & Beq, + const bool pd, + Eigen::PlainObjectBase & Z); + + // Dense version optimized for very small, known at compile time sizes. Still + // works for Eigen::Dynamic (and then everything needs to be Dynamic). + // + // min_x ½ xᵀ H x + xᵀ f + // subject to + // A x = b + // x(i) = bc(i) iff k(i)==true + // + // Templates: + // Scalar (e.g., double) + // n #H or Eigen::Dynamic if not known at compile time + // m #A or Eigen::Dynamic if not known at compile time + // Hpd whether H is positive definite (LLT used) or not (QR used) + // Inputs: + // H #H by #H quadratic coefficients (only lower triangle used) + // f #H linear coefficients + // k #H list of flags whether to fix value + // bc #H value to fix to (if !k(i) then bc(i) is ignored) + // A #A by #H list of linear equality constraint coefficients, must be + // linearly independent (with self and fixed value constraints) + // b #A list of linear equality right-hand sides + // Returns #H-long solution x + template + IGL_INLINE Eigen::Matrix min_quad_with_fixed( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Array & k, + const Eigen::Matrix & bc, + const Eigen::Matrix & A, + const Eigen::Matrix & b); + template + IGL_INLINE Eigen::Matrix min_quad_with_fixed( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Array & k, + const Eigen::Matrix & bc); + // Special wrapper where the number of constrained values (i.e., true values + // in k) is exposed as a template parameter. Not intended to be called + // directly. The overhead of calling the overloads above is already minimal. + template + IGL_INLINE Eigen::Matrix min_quad_with_fixed( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Array & k, + const Eigen::Matrix & bc); +} + +template +struct igl::min_quad_with_fixed_data +{ + // Size of original system: number of unknowns + number of knowns + int n; + // Whether A(unknown,unknown) is positive definite + bool Auu_pd; + // Whether A(unknown,unknown) is symmetric + bool Auu_sym; + // Indices of known variables + Eigen::VectorXi known; + // Indices of unknown variables + Eigen::VectorXi unknown; + // Indices of lagrange variables + Eigen::VectorXi lagrange; + // Indices of unknown variable followed by Indices of lagrange variables + Eigen::VectorXi unknown_lagrange; + // Matrix multiplied against Y when constructing right hand side + Eigen::SparseMatrix preY; + enum SolverType + { + LLT = 0, + LDLT = 1, + LU = 2, + QR_LLT = 3, + NUM_SOLVER_TYPES = 4 + } solver_type; + // Solvers + Eigen::SimplicialLLT > llt; + Eigen::SimplicialLDLT > ldlt; + Eigen::SparseLU, Eigen::COLAMDOrdering > lu; + // QR factorization + // Are rows of Aeq linearly independent? + bool Aeq_li; + // Columns of Aeq corresponding to unknowns + int neq; + Eigen::SparseQR, Eigen::COLAMDOrdering > AeqTQR; + Eigen::SparseMatrix Aeqk; + Eigen::SparseMatrix Aequ; + Eigen::SparseMatrix Auu; + Eigen::SparseMatrix AeqTQ1; + Eigen::SparseMatrix AeqTQ1T; + Eigen::SparseMatrix AeqTQ2; + Eigen::SparseMatrix AeqTQ2T; + Eigen::SparseMatrix AeqTR1; + Eigen::SparseMatrix AeqTR1T; + Eigen::SparseMatrix AeqTE; + Eigen::SparseMatrix AeqTET; + // Debug + Eigen::SparseMatrix NA; + Eigen::Matrix NB; +}; + +#ifndef IGL_STATIC_LIBRARY +# include "min_quad_with_fixed.impl.h" +#endif + +#endif diff --git a/vendor/libigl/include/igl/min_quad_with_fixed.impl.h b/vendor/libigl/include/igl/min_quad_with_fixed.impl.h new file mode 100644 index 0000000000000000000000000000000000000000..b5632723b1dd4bbb98f731fa0debbd2e419e8847 --- /dev/null +++ b/vendor/libigl/include/igl/min_quad_with_fixed.impl.h @@ -0,0 +1,887 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#pragma once + +#include "min_quad_with_fixed.h" + +#include "slice.h" +#include "is_symmetric.h" +#include "find.h" +#include "sparse.h" +#include "repmat.h" +#include "EPS.h" +#include "cat.h" + +//#include +// Bug in unsupported/Eigen/SparseExtra needs iostream first +#include +#include +#include +#include +#include +#include + +template +IGL_INLINE bool igl::min_quad_with_fixed_precompute( + const Eigen::SparseMatrix& A2, + const Eigen::MatrixBase & known, + const Eigen::SparseMatrix& Aeq, + const bool pd, + min_quad_with_fixed_data & data + ) +{ +//#define MIN_QUAD_WITH_FIXED_CPP_DEBUG + using namespace Eigen; + using namespace std; + const Eigen::SparseMatrix A = 0.5*A2; +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" pre"<= 0)&& "known indices should be in [0,n)"); + assert((kr == 0 || known.maxCoeff() < n) && "known indices should be in [0,n)"); + assert(neq <= n && "Number of equality constraints should be less than DOFs"); + + + // cache known + // FIXME: This is *NOT* generic and introduces a copy. + data.known = known.template cast(); + + // get list of unknown indices + data.unknown.resize(n-kr); + std::vector unknown_mask; + unknown_mask.resize(n,true); + for(int i = 0;i 0) + { + data.unknown_lagrange.head(data.unknown.size()) = data.unknown; + } + if(data.lagrange.size() > 0) + { + data.unknown_lagrange.tail(data.lagrange.size()) = data.lagrange; + } + + SparseMatrix Auu; + slice(A,data.unknown,data.unknown,Auu); + assert(Auu.size() != 0 && Auu.rows() > 0 && "There should be at least one unknown."); + + // Positive definiteness is *not* determined, rather it is given as a + // parameter + data.Auu_pd = pd; + if(data.Auu_pd) + { + // PD implies symmetric + data.Auu_sym = true; + // This is an annoying assertion unless EPS can be chosen in a nicer way. + //assert(is_symmetric(Auu,EPS())); + assert(is_symmetric(Auu,1.0) && + "Auu should be symmetric if positive definite"); + }else + { + // determine if A(unknown,unknown) is symmetric and/or positive definite + VectorXi AuuI,AuuJ; + MatrixXd AuuV; + find(Auu,AuuI,AuuJ,AuuV); + data.Auu_sym = is_symmetric(Auu,EPS()*AuuV.maxCoeff()); + } + + // Determine number of linearly independent constraints + int nc = 0; + if(neq>0) + { +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" qr"<(data.Aequ.transpose().eval()),"AeqT")< new_A; + SparseMatrix AeqT = Aeq.transpose(); + SparseMatrix Z(neq,neq); + // This is a bit slower. But why isn't cat fast? + new_A = cat(1, cat(2, A, AeqT ), + cat(2, Aeq, Z )); + + // precompute RHS builders + if(kr > 0) + { + SparseMatrix Aulk,Akul; + // Slow + slice(new_A,data.unknown_lagrange,data.known,Aulk); + //// This doesn't work!!! + //data.preY = Aulk + Akul.transpose(); + // Slow + if(data.Auu_sym) + { + data.preY = Aulk*2; + }else + { + slice(new_A,data.known,data.unknown_lagrange,Akul); + SparseMatrix AkulT = Akul.transpose(); + data.preY = Aulk + AkulT; + } + }else + { + data.preY.resize(data.unknown_lagrange.size(),0); + } + + // Positive definite and no equality constraints (Positive definiteness + // implies symmetric) +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" factorize"<::LLT; + }else + { +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" ldlt"< NA; + slice(new_A,data.unknown_lagrange,data.unknown_lagrange,NA); + data.NA = NA; + // Ideally we'd use LDLT but Eigen doesn't support positive semi-definite + // matrices: + // http://forum.kde.org/viewtopic.php?f=74&t=106962&p=291990#p291990 + if(data.Auu_sym && false) + { + data.ldlt.compute(NA); + switch(data.ldlt.info()) + { + case Eigen::Success: + break; + case Eigen::NumericalIssue: + cerr<<"Error: Numerical issue."<::LDLT; + }else + { +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" lu"<1/2 + data.lu.compute(NA); + //std::cout<<"NA=["<::LU; + } + } + }else + { +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" Aeq_li=false"< AeqTR,AeqTQ; + AeqTR = data.AeqTQR.matrixR(); + // This shouldn't be necessary + AeqTR.prune(static_cast(0.0)); +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" matrixQ"<(0.0)); + //cout<<"AeqTQ: "< I(neq,neq); + I.setIdentity(); + data.AeqTE = data.AeqTQR.colsPermutation() * I; + data.AeqTET = data.AeqTQR.colsPermutation().transpose() * I; + assert(AeqTR.rows() == nu && "#rows in AeqTR should match #unknowns"); + assert(AeqTR.cols() == neq && "#cols in AeqTR should match #constraints"); + assert(AeqTQ.rows() == nu && "#rows in AeqTQ should match #unknowns"); + assert(AeqTQ.cols() == nu && "#cols in AeqTQ should match #unknowns"); + //cout<<" slice"< QRAuu = data.AeqTQ2T * Auu * data.AeqTQ2; + { +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" factorize"<::QR_LLT; + } +#ifdef MIN_QUAD_WITH_FIXED_CPP_DEBUG + cout<<" smash"< Auk; + slice(A,data.unknown,data.known,Auk); + SparseMatrix Aku; + slice(A,data.known,data.unknown,Aku); + SparseMatrix AkuT = Aku.transpose(); + data.preY = Auk + AkuT; + // Needed during solve + data.Auu = Auu; + slice(Aeq,data.known,2,data.Aeqk); + assert(data.Aeqk.rows() == neq); + assert(data.Aeqk.cols() == data.known.size()); + } + return true; +} + + +template < + typename T, + typename DerivedB, + typename DerivedY, + typename DerivedBeq, + typename DerivedZ, + typename Derivedsol> +IGL_INLINE bool igl::min_quad_with_fixed_solve( + const min_quad_with_fixed_data & data, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & Y, + const Eigen::MatrixBase & Beq, + Eigen::PlainObjectBase & Z, + Eigen::PlainObjectBase & sol) +{ + using namespace std; + using namespace Eigen; + typedef Matrix VectorXT; + typedef Matrix MatrixXT; + // number of known rows + int kr = data.known.size(); + if(kr!=0) + { + assert(kr == Y.rows()); + } + // number of columns to solve + int cols = Y.cols(); + assert(B.cols() == 1 || B.cols() == cols); + assert(Beq.size() == 0 || Beq.cols() == 1 || Beq.cols() == cols); + + // resize output + Z.resize(data.n,cols); + // Set known values + for(int i = 0;i < kr;i++) + { + for(int j = 0;j < cols;j++) + { + Z(data.known(i),j) = Y(i,j); + } + } + + if(data.Aeq_li) + { + // number of lagrange multipliers aka linear equality constraints + int neq = data.lagrange.size(); + // append lagrange multiplier rhs's + MatrixXT BBeq(B.rows() + Beq.rows(),cols); + if(B.size() > 0) + { + BBeq.topLeftCorner(B.rows(),cols) = B.replicate(1,B.cols()==cols?1:cols); + } + if(Beq.size() > 0) + { + BBeq.bottomLeftCorner(Beq.rows(),cols) = -2.0*Beq.replicate(1,Beq.cols()==cols?1:cols); + } + + // Build right hand side + MatrixXT BBequlcols; + igl::slice(BBeq,data.unknown_lagrange,1,BBequlcols); + MatrixXT NB; + if(kr == 0) + { + NB = BBequlcols; + }else + { + NB = data.preY * Y + BBequlcols; + } + + //std::cout<<"NB=["<::LLT: + sol = data.llt.solve(NB); + break; + case igl::min_quad_with_fixed_data::LDLT: + sol = data.ldlt.solve(NB); + break; + case igl::min_quad_with_fixed_data::LU: + // Not a bottleneck + sol = data.lu.solve(NB); + break; + default: + cerr<<"Error: invalid solver type"<::QR_LLT); + MatrixXT eff_Beq; + // Adjust Aeq rhs to include known parts + eff_Beq = + //data.AeqTQR.colsPermutation().transpose() * (-data.Aeqk * Y + Beq); + data.AeqTET * (-data.Aeqk * Y + Beq.replicate(1,Beq.cols()==cols?1:cols)); + // Where did this -0.5 come from? Probably the same place as above. + MatrixXT Bu; + slice(B,data.unknown,1,Bu); + MatrixXT NB; + NB = -0.5*(Bu.replicate(1,B.cols()==cols?1:cols) + data.preY * Y); + // Trim eff_Beq + const int nc = data.AeqTQR.rank(); + const int neq = Beq.rows(); + eff_Beq = eff_Beq.topLeftCorner(nc,cols).eval(); + data.AeqTR1T.template triangularView().solveInPlace(eff_Beq); + // Now eff_Beq = (data.AeqTR1T \ (data.AeqTET * (-data.Aeqk * Y + Beq))) + MatrixXT lambda_0; + lambda_0 = data.AeqTQ1 * eff_Beq; + //cout<().solveInPlace(temp1); + //cout< +IGL_INLINE bool igl::min_quad_with_fixed_solve( + const min_quad_with_fixed_data & data, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & Y, + const Eigen::MatrixBase & Beq, + Eigen::PlainObjectBase & Z) +{ + Eigen::Matrix sol; + return min_quad_with_fixed_solve(data,B,Y,Beq,Z,sol); +} + +template < + typename T, + typename Derivedknown, + typename DerivedB, + typename DerivedY, + typename DerivedBeq, + typename DerivedZ> +IGL_INLINE bool igl::min_quad_with_fixed( + const Eigen::SparseMatrix& A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & known, + const Eigen::MatrixBase & Y, + const Eigen::SparseMatrix& Aeq, + const Eigen::MatrixBase & Beq, + const bool pd, + Eigen::PlainObjectBase & Z) +{ + min_quad_with_fixed_data data; + if(!min_quad_with_fixed_precompute(A,known,Aeq,pd,data)) + { + return false; + } + return min_quad_with_fixed_solve(data,B,Y,Beq,Z); +} + + +template +IGL_INLINE Eigen::Matrix igl::min_quad_with_fixed( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Array & k, + const Eigen::Matrix & bc, + const Eigen::Matrix & A, + const Eigen::Matrix & b) +{ + const auto dyn_n = n == Eigen::Dynamic ? H.rows() : n; + const auto dyn_m = m == Eigen::Dynamic ? A.rows() : m; + constexpr const int nn = n == Eigen::Dynamic ? Eigen::Dynamic : n+m; + const auto dyn_nn = nn == Eigen::Dynamic ? dyn_n+dyn_m : nn; + if(dyn_m == 0) + { + return igl::min_quad_with_fixed(H,f,k,bc); + } + // min_x ½ xᵀ H x + xᵀ f subject to A x = b and x(k) = bc(k) + // let zᵀ = [xᵀ λᵀ] + // min_z ½ zᵀ [H Aᵀ;A 0] z + zᵀ [f;-b] z(k) = bc(k) + const auto make_HH = [&]() + { + // Windows can't remember that nn is const. + constexpr const int nn = n == Eigen::Dynamic ? Eigen::Dynamic : n+m; + Eigen::Matrix HH = + Eigen::Matrix::Zero(dyn_nn,dyn_nn); + HH.topLeftCorner(dyn_n,dyn_n) = H; + HH.bottomLeftCorner(dyn_m,dyn_n) = A; + HH.topRightCorner(dyn_n,dyn_m) = A.transpose(); + return HH; + }; + const Eigen::Matrix HH = make_HH(); + const auto make_ff = [&]() + { + // Windows can't remember that nn is const. + constexpr const int nn = n == Eigen::Dynamic ? Eigen::Dynamic : n+m; + Eigen::Matrix ff(dyn_nn); + ff.head(dyn_n) = f; + ff.tail(dyn_m) = -b; + return ff; + }; + const Eigen::Matrix ff = make_ff(); + const auto make_kk = [&]() + { + // Windows can't remember that nn is const. + constexpr const int nn = n == Eigen::Dynamic ? Eigen::Dynamic : n+m; + Eigen::Array kk = + Eigen::Array::Constant(dyn_nn,1,false); + kk.head(dyn_n) = k; + return kk; + }; + const Eigen::Array kk = make_kk(); + const auto make_bcbc= [&]() + { + // Windows can't remember that nn is const. + constexpr const int nn = n == Eigen::Dynamic ? Eigen::Dynamic : n+m; + Eigen::Matrix bcbc(dyn_nn); + bcbc.head(dyn_n) = bc; + return bcbc; + }; + const Eigen::Matrix bcbc = make_bcbc(); + const Eigen::Matrix xx = + min_quad_with_fixed(HH,ff,kk,bcbc); + return xx.head(dyn_n); +} + +template +IGL_INLINE Eigen::Matrix igl::min_quad_with_fixed( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Array & k, + const Eigen::Matrix & bc) +{ + assert(H.isApprox(H.transpose(),1e-7)); + assert(H.rows() == H.cols()); + assert(H.rows() == f.size()); + assert(H.rows() == k.size()); + assert(H.rows() == bc.size()); + const auto kcount = k.count(); + // Everything fixed + if(kcount == (Eigen::Dynamic?H.rows():n)) + { + return bc; + } + // Nothing fixed + if(kcount == 0) + { + // avoid function call + typedef Eigen::Matrix MatrixSn; + typedef typename + std::conditional,Eigen::CompleteOrthogonalDecomposition>::type + Solver; + return Solver(H).solve(-f); + } + // All-but-one fixed + if( (Eigen::Dynamic?H.rows():n)-kcount == 1) + { + // which one is not fixed? + int u = -1; + for(int i=0;i=0); + // min ½ x(u) Huu x(u) + x(u)(fu + H(u,k)bc(k)) + // Huu x(u) = -(fu + H(u,k) bc(k)) + // x(u) = (-fu + ∑ -Huj bcj)/Huu + Eigen::Matrix x = bc; + x(u) = -f(u); + for(int i=0;i(); + // % Matlibberish for generating these case statements: + // maxi=16;for i=1:maxi;fprintf(' case %d:\n {\n const bool D = (n-%d<=0)||(%d>=n)||(n>%d);\n return min_quad_with_fixed(H,f,k,bc);\n }\n',[i i i maxi i]);end + case 1: + { + const bool D = (n-1<=0)||(1>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 2: + { + const bool D = (n-2<=0)||(2>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 3: + { + const bool D = (n-3<=0)||(3>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 4: + { + const bool D = (n-4<=0)||(4>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 5: + { + const bool D = (n-5<=0)||(5>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 6: + { + const bool D = (n-6<=0)||(6>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 7: + { + const bool D = (n-7<=0)||(7>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 8: + { + const bool D = (n-8<=0)||(8>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 9: + { + const bool D = (n-9<=0)||(9>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 10: + { + const bool D = (n-10<=0)||(10>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 11: + { + const bool D = (n-11<=0)||(11>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 12: + { + const bool D = (n-12<=0)||(12>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 13: + { + const bool D = (n-13<=0)||(13>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 14: + { + const bool D = (n-14<=0)||(14>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 15: + { + const bool D = (n-15<=0)||(15>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + case 16: + { + const bool D = (n-16<=0)||(16>=n)||(n>16); + return min_quad_with_fixed(H,f,k,bc); + } + default: + return min_quad_with_fixed(H,f,k,bc); + } +} + +template +IGL_INLINE Eigen::Matrix igl::min_quad_with_fixed( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Array & k, + const Eigen::Matrix & bc) +{ + // 0 and n should be handle outside this function + static_assert(kcount==Eigen::Dynamic || kcount>0 ,""); + static_assert(kcount==Eigen::Dynamic || kcount MatrixSuu; + typedef Eigen::Matrix MatrixSuk; + typedef Eigen::Matrix VectorSn; + typedef Eigen::Matrix VectorSu; + typedef Eigen::Matrix VectorSk; + const auto dyn_n = n==Eigen::Dynamic ? H.rows() : n; + const auto dyn_kcount = kcount==Eigen::Dynamic ? k.count() : kcount; + const auto dyn_ucount = ucount==Eigen::Dynamic ? dyn_n- dyn_kcount : ucount; + // For ucount==2 or kcount==2 this calls the coefficient initiliazer rather + // than the size initilizer, but I guess that's ok. + MatrixSuu Huu(dyn_ucount,dyn_ucount); + MatrixSuk Huk(dyn_ucount,dyn_kcount); + VectorSu mrhs(dyn_ucount); + VectorSk bck(dyn_kcount); + { + int ui = 0; + int ki = 0; + for(int i = 0;i, + // LDLT should be faster for indefinite problems but already found some + // cases where it was too inaccurate when called via quadprog_primal. + // Ideally this function takes LLT,LDLT, or + // CompleteOrthogonalDecomposition as a template parameter. "template + // template" parameters did work because LLT,LDLT have different number of + // template parameters from CompleteOrthogonalDecomposition. Perhaps + // there's a way to take advantage of LLT and LDLT's default template + // parameters (I couldn't figure out how). + Eigen::CompleteOrthogonalDecomposition>::type + Solver; + VectorSu xu = Solver(Huu).solve(-mrhs); + VectorSn x(dyn_n); + { + int ui = 0; + int ki = 0; + for(int i = 0;i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "min_quad_with_fixed.impl.h" + +#ifdef IGL_STATIC_LIBRARY +template bool igl::min_quad_with_fixed_precompute >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix const&, bool, igl::min_quad_with_fixed_data&); +template bool igl::min_quad_with_fixed_precompute >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix const&, bool, igl::min_quad_with_fixed_data&); +#endif diff --git a/vendor/libigl/include/igl/min_quad_with_fixed_solve.cpp b/vendor/libigl/include/igl/min_quad_with_fixed_solve.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f60bab54626bd17e155a80f451fe7409b8884349 --- /dev/null +++ b/vendor/libigl/include/igl/min_quad_with_fixed_solve.cpp @@ -0,0 +1,23 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "min_quad_with_fixed.impl.h" + +#ifdef IGL_STATIC_LIBRARY +#if EIGEN_VERSION_AT_LEAST(3,3,0) +#else +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix const>, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase, Eigen::Matrix const> > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::CwiseNullaryOp, Eigen::Matrix >, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase, Eigen::Matrix > > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::min_quad_with_fixed_solve, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(igl::min_quad_with_fixed_data const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/min_size.cpp b/vendor/libigl/include/igl/min_size.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8389e6ecc21699e6ff8f8ccc58c399a721a1dae8 --- /dev/null +++ b/vendor/libigl/include/igl/min_size.cpp @@ -0,0 +1,48 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "min_size.h" + +template +IGL_INLINE int igl::min_size(const std::vector & V) +{ + int min_size = -1; + for( + typename std::vector::const_iterator iter = V.begin(); + iter != V.end(); + iter++) + { + int size = (int)iter->size(); + // have to handle base case + if(min_size == -1) + { + min_size = size; + }else{ + min_size = (min_size < size ? min_size : size); + } + } + return min_size; +} + + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template int igl::min_size > >(std::vector >, std::allocator > > > const&); +// generated by autoexplicit.sh +template int igl::min_size > >(std::vector >, std::allocator > > > const&); +// generated by autoexplicit.sh +template int igl::min_size > >(std::vector >, std::allocator > > > const&); +// generated by autoexplicit.sh +template int igl::min_size > >(std::vector >, std::allocator > > > const&); +template int igl::min_size > >(std::vector >, std::allocator > > > const&); +template int igl::min_size > >(std::vector >, std::allocator > > > const&); +#ifdef WIN32 +template int igl::min_size > >(class std::vector >, class std::allocator > > > const&); +#endif +#endif diff --git a/vendor/libigl/include/igl/min_size.h b/vendor/libigl/include/igl/min_size.h new file mode 100644 index 0000000000000000000000000000000000000000..e440362790ded840ddf51192c2aec963345be6ed --- /dev/null +++ b/vendor/libigl/include/igl/min_size.h @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MIN_SIZE_H +#define IGL_MIN_SIZE_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Determine min size of lists in a vector + // Template: + // T some list type object that implements .size() + // Inputs: + // V vector of list types T + // Returns min .size() found in V, returns -1 if V is empty + template + IGL_INLINE int min_size(const std::vector & V); +} + + +#ifndef IGL_STATIC_LIBRARY +# include "min_size.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/mod.cpp b/vendor/libigl/include/igl/mod.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2064fe6a4d642236e59606bf379e24ab39c639aa --- /dev/null +++ b/vendor/libigl/include/igl/mod.cpp @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "mod.h" + +template +IGL_INLINE void igl::mod( + const Eigen::PlainObjectBase & A, + const int base, + Eigen::PlainObjectBase & B) +{ + B.resizeLike(A); + for(int i = 0;i +IGL_INLINE DerivedA igl::mod( + const Eigen::PlainObjectBase & A, const int base) +{ + DerivedA B; + mod(A,base,B); + return B; +} +#ifdef IGL_STATIC_LIBRARY +#endif diff --git a/vendor/libigl/include/igl/mod.h b/vendor/libigl/include/igl/mod.h new file mode 100644 index 0000000000000000000000000000000000000000..3ff58a231c18c6af61c6e56f75d6c36a9c5d22ce --- /dev/null +++ b/vendor/libigl/include/igl/mod.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MOD_H +#define IGL_MOD_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute elementwise mod: B = A % base + // + // Inputs: + // A m by n matrix + // base number to mod against + // Outputs: + // B m by n matrix + template + IGL_INLINE void mod( + const Eigen::PlainObjectBase & A, + const int base, + Eigen::PlainObjectBase & B); + template + IGL_INLINE DerivedA mod( + const Eigen::PlainObjectBase & A, const int base); +} +#ifndef IGL_STATIC_LIBRARY +#include "mod.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/mode.cpp b/vendor/libigl/include/igl/mode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..89df6be66dedfc7fc7d56c88ecd7809360a25f58 --- /dev/null +++ b/vendor/libigl/include/igl/mode.cpp @@ -0,0 +1,62 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "mode.h" + +// Implementation +#include + +template +IGL_INLINE void igl::mode( + const Eigen::Matrix & X, + const int d, + Eigen::Matrix & M) +{ + assert(d==1 || d==2); + using namespace std; + int m = X.rows(); + int n = X.cols(); + M.resize((d==1)?n:m,1); + for(int i = 0;i<((d==2)?m:n);i++) + { + vector counts(((d==2)?n:m),0); + for(int j = 0;j<((d==2)?n:m);j++) + { + T v = (d==2)?X(i,j):X(j,i); + for(int k = 0;k<((d==2)?n:m);k++) + { + T u = (d==2)?X(i,k):X(k,i); + if(v == u) + { + counts[k]++; + } + } + } + assert(counts.size() > 0); + int max_count = -1; + int max_count_j = -1; + int j =0; + for(vector::iterator it = counts.begin();it(Eigen::Matrix const&, int, Eigen::Matrix&); +// generated by autoexplicit.sh +template void igl::mode(Eigen::Matrix const&, int, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/mode.h b/vendor/libigl/include/igl/mode.h new file mode 100644 index 0000000000000000000000000000000000000000..4d094388121f74f8b0433da175f79379976bcb9f --- /dev/null +++ b/vendor/libigl/include/igl/mode.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MODE_H +#define IGL_MODE_H +#include "igl_inline.h" +#include +namespace igl +{ + // Takes mode of coefficients in a matrix along a given dension + // + // Templates: + // T should be a eigen matrix primitive type like int or double + // Inputs: + // X m by n original matrix + // d dension along which to take mode, m or n + // Outputs: + // M vector containing mode along dension d, if d==1 then this will be a + // n-long vector if d==2 then this will be a m-long vector + template + IGL_INLINE void mode( + const Eigen::Matrix & X, + const int d, + Eigen::Matrix & M); +} + +#ifndef IGL_STATIC_LIBRARY +# include "mode.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/mvc.h b/vendor/libigl/include/igl/mvc.h new file mode 100644 index 0000000000000000000000000000000000000000..3c7c2abcc3c876c24cc73a7501bb65f463de13d3 --- /dev/null +++ b/vendor/libigl/include/igl/mvc.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_MVC_H +#define IGL_MVC_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // MVC - MEAN VALUE COORDINATES + // + // mvc(V,C,W) + // + // Inputs: + // V #V x dim list of vertex positions (dim = 2 or dim = 3) + // C #C x dim list of polygon vertex positions in counter-clockwise order + // (dim = 2 or dim = 3) + // + // Outputs: + // W weights, #V by #C matrix of weights + // + // Known Bugs: implementation is listed as "Broken" + IGL_INLINE void mvc( + const Eigen::MatrixXd &V, + const Eigen::MatrixXd &C, + Eigen::MatrixXd &W); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "mvc.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/nchoosek.h b/vendor/libigl/include/igl/nchoosek.h new file mode 100644 index 0000000000000000000000000000000000000000..88ee63642b0e5f037dcd1dbc52a9a2b3e50ab772 --- /dev/null +++ b/vendor/libigl/include/igl/nchoosek.h @@ -0,0 +1,45 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Olga Diamanti, Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_NCHOOSEK +#define IGL_NCHOOSEK +#include "igl_inline.h" +#include + +#include + +namespace igl +{ + // NCHOOSEK Like matlab's nchoosek. + // + // Inputs: + // n total number elements + // k size of sub-set to consider + // Returns number of k-size combinations out of the set [1,...,n] + IGL_INLINE double nchoosek(const int n, const int k); + // + // Inputs: + // V n-long vector of elements + // k size of sub-set to consider + // Outputs: + // U nchoosek by k long matrix where each row is a unique k-size + // combination + template < typename DerivedV, typename DerivedU> + IGL_INLINE void nchoosek( + const Eigen::MatrixBase & V, + const int k, + Eigen::PlainObjectBase & U); +} + + +#ifndef IGL_STATIC_LIBRARY +#include "nchoosek.cpp" +#endif + + +#endif /* defined(IGL_NCHOOSEK) */ diff --git a/vendor/libigl/include/igl/next_filename.h b/vendor/libigl/include/igl/next_filename.h new file mode 100644 index 0000000000000000000000000000000000000000..c56ad0857ccfc6d3ef718abb83816875bd2bdf7b --- /dev/null +++ b/vendor/libigl/include/igl/next_filename.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_NEXT_FILENAME_H +#define IGL_NEXT_FILENAME_H +#include "igl_inline.h" +#include +namespace igl +{ + // Find the file with the first filename of the form + // "prefix%0[zeros]dsuffix" + // + // Inputs: + // prefix path to containing dir and filename prefix + // zeros number of leading zeros as if digit printed with printf + // suffix suffix of filename and extension (should include dot) + // Outputs: + // next path to next file + // Returns true if found, false if exceeding range in zeros + IGL_INLINE bool next_filename( + const std::string & prefix, + const int zeros, + const std::string & suffix, + std::string & next); +} + +#ifndef IGL_STATIC_LIBRARY +# include "next_filename.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/normal_derivative.cpp b/vendor/libigl/include/igl/normal_derivative.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49a332d05999b527a2d1c5e56c2e4069af9740b2 --- /dev/null +++ b/vendor/libigl/include/igl/normal_derivative.cpp @@ -0,0 +1,118 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "LinSpaced.h" +#include "normal_derivative.h" +#include "cotmatrix_entries.h" +#include "slice.h" +#include + +template < + typename DerivedV, + typename DerivedEle, + typename Scalar> +IGL_INLINE void igl::normal_derivative( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & Ele, + Eigen::SparseMatrix& DD) +{ + using namespace Eigen; + using namespace std; + // Element simplex-size + const size_t ss = Ele.cols(); + assert( ((ss==3) || (ss==4)) && "Only triangles or tets"); + // cotangents + Matrix C; + cotmatrix_entries(V,Ele,C); + vector > IJV; + // Number of elements + const size_t m = Ele.rows(); + // Number of vertices + const size_t n = V.rows(); + switch(ss) + { + default: + assert(false); + return; + case 4: + { + const MatrixXi DDJ = + slice( + Ele, + (VectorXi(24)<< + 1,0,2,0,3,0,2,1,3,1,0,1,3,2,0,2,1,2,0,3,1,3,2,3).finished(), + 2); + MatrixXi DDI(m,24); + for(size_t f = 0;f<4;f++) + { + const auto & I = (igl::LinSpaced(m,0,m-1).array()+f*m).eval(); + for(size_t r = 0;r<6;r++) + { + DDI.col(f*6+r) = I; + } + } + const DiagonalMatrix S = + (Matrix(1,-1).template replicate<12,1>()).asDiagonal(); + Matrix DDV = + slice( + C, + (VectorXi(24)<< + 2,2,1,1,3,3,0,0,4,4,2,2,5,5,1,1,0,0,3,3,4,4,5,5).finished(), + 2); + DDV *= S; + + IJV.reserve(DDV.size()); + for(size_t f = 0;f<6*4;f++) + { + for(size_t e = 0;e(DDI(e,f),DDJ(e,f),DDV(e,f))); + } + } + DD.resize(m*4,n); + DD.setFromTriplets(IJV.begin(),IJV.end()); + break; + } + case 3: + { + const MatrixXi DDJ = + slice(Ele,(VectorXi(12)<<2,0,1,0,0,1,2,1,1,2,0,2).finished(),2); + MatrixXi DDI(m,12); + for(size_t f = 0;f<3;f++) + { + const auto & I = (igl::LinSpaced(m,0,m-1).array()+f*m).eval(); + for(size_t r = 0;r<4;r++) + { + DDI.col(f*4+r) = I; + } + } + const DiagonalMatrix S = + (Matrix(1,-1).template replicate<6,1>()).asDiagonal(); + Matrix DDV = + slice(C,(VectorXi(12)<<1,1,2,2,2,2,0,0,0,0,1,1).finished(),2); + DDV *= S; + + IJV.reserve(DDV.size()); + for(size_t f = 0;f<12;f++) + { + for(size_t e = 0;e(DDI(e,f),DDJ(e,f),DDV(e,f))); + } + } + DD.resize(m*3,n); + DD.setFromTriplets(IJV.begin(),IJV.end()); + break; + } + } + +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::normal_derivative, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/normalize_quat.cpp b/vendor/libigl/include/igl/normalize_quat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f110d6b75431a8ef85c6692fb2af5e8d30cb50cd --- /dev/null +++ b/vendor/libigl/include/igl/normalize_quat.cpp @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "normalize_quat.h" + +#include "EPS.h" +#include + +template +IGL_INLINE bool igl::normalize_quat( + const Q_type *q, + Q_type *out) +{ + // Get length + Q_type len = sqrt( + q[0]*q[0]+ + q[1]*q[1]+ + q[2]*q[2]+ + q[3]*q[3]); + + // Noramlize each coordinate + out[0] = q[0]/len; + out[1] = q[1]/len; + out[2] = q[2]/len; + out[3] = q[3]/len; + + // Test whether length was below Epsilon + return (len > igl::EPS()); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::normalize_quat(double const*, double*); +// generated by autoexplicit.sh +template bool igl::normalize_quat(float const*, float*); +#endif diff --git a/vendor/libigl/include/igl/normalize_row_lengths.cpp b/vendor/libigl/include/igl/normalize_row_lengths.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d7e566e882838620101f48886138af24b253e43 --- /dev/null +++ b/vendor/libigl/include/igl/normalize_row_lengths.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "normalize_row_lengths.h" + +template +IGL_INLINE void igl::normalize_row_lengths( + const Eigen::PlainObjectBase& A, + Eigen::PlainObjectBase & B) +{ + // Resize output + B.resizeLike(A); + + // loop over rows + for(int i = 0; i < A.rows();i++) + { + B.row(i) = A.row(i).normalized(); + } + //// Or just: + //B = A; + //B.rowwise().normalize(); +} +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::normalize_row_lengths >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::normalize_row_lengths >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::normalize_row_lengths >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/normalize_row_lengths.h b/vendor/libigl/include/igl/normalize_row_lengths.h new file mode 100644 index 0000000000000000000000000000000000000000..c305c0f65b325e7fe764bdbc5f56c49e0102872b --- /dev/null +++ b/vendor/libigl/include/igl/normalize_row_lengths.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_NORMALIZE_ROW_LENGTHS_H +#define IGL_NORMALIZE_ROW_LENGTHS_H +#include "igl_inline.h" +#include + +// History: +// March 24, 2012: Alec changed function name from normalize_rows to +// normalize_row_lengths to avoid confusion with normalize_row_sums + +namespace igl +{ + // Obsolete: just use A.rowwise().normalize() or B=A.rowwise().normalized(); + // + // Normalize the rows in A so that their lengths are each 1 and place the new + // entries in B + // Inputs: + // A #rows by k input matrix + // Outputs: + // B #rows by k input matrix, can be the same as A + template + IGL_INLINE void normalize_row_lengths( + const Eigen::PlainObjectBase& A, + Eigen::PlainObjectBase & B); +} + +#ifndef IGL_STATIC_LIBRARY +# include "normalize_row_lengths.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/normalize_row_sums.h b/vendor/libigl/include/igl/normalize_row_sums.h new file mode 100644 index 0000000000000000000000000000000000000000..b27c6c2823570f8dbc2df6a86efbb1affe4841b0 --- /dev/null +++ b/vendor/libigl/include/igl/normalize_row_sums.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_NORMALIZE_ROW_SUMS_H +#define IGL_NORMALIZE_ROW_SUMS_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Normalize the rows in A so that their sums are each 1 and place the new + // entries in B + // Inputs: + // A #rows by k input matrix + // Outputs: + // B #rows by k input matrix, can be the same as A + // + // Note: This is just calling an Eigen one-liner: + // + // B = A.array().colwise() / A.array().rowwise().sum(); + // + template + IGL_INLINE void normalize_row_sums( + const Eigen::MatrixBase& A, + Eigen::MatrixBase & B); +} + +#ifndef IGL_STATIC_LIBRARY +# include "normalize_row_sums.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/null.cpp b/vendor/libigl/include/igl/null.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9711492668d62bd0297e997ac65d9739d0b8947d --- /dev/null +++ b/vendor/libigl/include/igl/null.cpp @@ -0,0 +1,25 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "null.h" +#include "EPS.h" + +template +IGL_INLINE void igl::null( + const Eigen::PlainObjectBase & A, + Eigen::PlainObjectBase & N) +{ + using namespace Eigen; + typedef typename DerivedA::Scalar Scalar; + JacobiSVD svd(A, ComputeFullV); + svd.setThreshold(A.cols() * svd.singularValues().maxCoeff() * EPS()); + N = svd.matrixV().rightCols(A.cols()-svd.rank()); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::null, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/null.h b/vendor/libigl/include/igl/null.h new file mode 100644 index 0000000000000000000000000000000000000000..2349217fb2c9604826bd0654dcf2705a0b186a09 --- /dev/null +++ b/vendor/libigl/include/igl/null.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_NULL_H +#define IGL_NULL_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Like MATLAB's null + // + // Compute a basis for the null space for the given matrix A: the columns of + // the output N form a basis for the space orthogonal to that spanned by the + // rows of A. + // + // Inputs: + // A m by n matrix + // Outputs: + // N n by r matrix, where r is the row rank of A + template + IGL_INLINE void null( + const Eigen::PlainObjectBase & A, + Eigen::PlainObjectBase & N); +} + +#ifndef IGL_STATIC_LIBRARY +# include "null.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/octree.cpp b/vendor/libigl/include/igl/octree.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef47411f6b04933f10a6cd25cd61dd5c218339df --- /dev/null +++ b/vendor/libigl/include/igl/octree.cpp @@ -0,0 +1,175 @@ +#include "octree.h" +#include + +namespace igl { + template + IGL_INLINE void octree(const Eigen::MatrixBase& P, + std::vector > & point_indices, + Eigen::PlainObjectBase& CH, + Eigen::PlainObjectBase& CN, + Eigen::PlainObjectBase& W) + { + + + + const int MAX_DEPTH = 30000; + + typedef typename DerivedCH::Scalar ChildrenType; + typedef typename DerivedCN::Scalar CentersType; + typedef typename DerivedW::Scalar WidthsType; + typedef typename DerivedP::Scalar PointScalar; + typedef Eigen::Matrix Vector8i; + typedef Eigen::Matrix RowVector3PType; + typedef Eigen::Matrix RowVector3CentersType; + + std::vector, + Eigen::aligned_allocator > > children; + std::vector, + Eigen::aligned_allocator > > centers; + std::vector widths; + + auto get_octant = [](const RowVector3PType& location, + const RowVector3CentersType& center){ + // We use a binary numbering of children. Treating the parent cell's + // center as the origin, we number the octants in the following manner: + // The first bit is 1 iff the octant's x coordinate is positive + // The second bit is 1 iff the octant's y coordinate is positive + // The third bit is 1 iff the octant's z coordinate is positive + // + // For example, the octant with negative x, positive y, positive z is: + // 110 binary = 6 decimal + IndexType index = 0; + if( location(0) >= center(0)){ + index = index + 1; + } + if( location(1) >= center(1)){ + index = index + 2; + } + if( location(2) >= center(2)){ + index = index + 4; + } + return index; + }; + + + std::function< RowVector3CentersType(const RowVector3CentersType, + const CentersType, + const ChildrenType) > + translate_center = + [](const RowVector3CentersType & parent_center, + const CentersType h, + const ChildrenType child_index){ + RowVector3CentersType change_vector; + change_vector << -h,-h,-h; + + //positive x chilren are 1,3,4,7 + if(child_index % 2){ + change_vector(0) = h; + } + //positive y children are 2,3,6,7 + if(child_index == 2 || child_index == 3 || + child_index == 6 || child_index == 7){ + change_vector(1) = h; + } + //positive z children are 4,5,6,7 + if(child_index > 3){ + change_vector(2) = h; + } + RowVector3CentersType output = parent_center + change_vector; + return output; + }; + + // How many cells do we have so far? + IndexType m = 0; + + // Useful list of number 0..7 + const Vector8i zero_to_seven = (Vector8i()<<0,1,2,3,4,5,6,7).finished(); + const Vector8i neg_ones = Vector8i::Constant(-1); + + std::function< void(const ChildrenType, const int) > helper; + helper = [&helper,&translate_center,&get_octant,&m, + &zero_to_seven,&neg_ones,&P, + &point_indices,&children,¢ers,&widths,&MAX_DEPTH] + (const ChildrenType index, const int depth)-> void + { + if(point_indices.at(index).size() > 1 && depth < MAX_DEPTH){ + //give the parent access to the children + children.at(index) = zero_to_seven.array() + m; + //make the children's data in our arrays + + //Add the children to the lists, as default children + CentersType h = widths.at(index)/2; + RowVector3CentersType curr_center = centers.at(index); + + + for(ChildrenType i = 0; i < 8; i++){ + children.emplace_back(neg_ones); + point_indices.emplace_back(std::vector()); + centers.emplace_back(translate_center(curr_center,h/2,i)); + widths.emplace_back(h); + } + + + //Split up the points into the corresponding children + for(int j = 0; j < point_indices.at(index).size(); j++){ + IndexType curr_point_index = point_indices.at(index).at(j); + IndexType cell_of_curr_point = + get_octant(P.row(curr_point_index),curr_center)+m; + point_indices.at(cell_of_curr_point).emplace_back(curr_point_index); + } + + //Now increase m + m += 8; + + + // Look ma, I'm calling myself. + for(int i = 0; i < 8; i++){ + helper(children.at(index)(i),depth+1); + } + } + }; + + { + std::vector all(P.rows()); + for(IndexType i = 0;i, int, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::octree, int, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/octree.h b/vendor/libigl/include/igl/octree.h new file mode 100644 index 0000000000000000000000000000000000000000..425d86b2db08ca62c7f6ce4ba6a457481060394d --- /dev/null +++ b/vendor/libigl/include/igl/octree.h @@ -0,0 +1,62 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Gavin Barill +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/ + +#ifndef IGL_OCTREE +#define IGL_OCTREE +#include "igl_inline.h" +#include +#include + + + + +namespace igl +{ + // Given a set of 3D points P, generate data structures for a pointerless + // octree. Each cell stores its points, children, center location and width. + // Our octree is not dense. We use the following rule: if the current cell + // has any number of points, it will have all 8 children. A leaf cell will + // have -1's as its list of child indices. + // + // We use a binary numbering of children. Treating the parent cell's center + // as the origin, we number the octants in the following manner: + // The first bit is 1 iff the octant's x coordinate is positive + // The second bit is 1 iff the octant's y coordinate is positive + // The third bit is 1 iff the octant's z coordinate is positive + // + // For example, the octant with negative x, positive y, positive z is: + // 110 binary = 6 decimal + // + // Inputs: + // P #P by 3 list of point locations + // + // Outputs: + // point_indices a vector of vectors, where the ith entry is a vector of + // the indices into P that are the ith octree cell's points + // CH #OctreeCells by 8, where the ith row is the indices of + // the ith octree cell's children + // CN #OctreeCells by 3, where the ith row is a 3d row vector + // representing the position of the ith cell's center + // W #OctreeCells, a vector where the ith entry is the width + // of the ith octree cell + // + template + IGL_INLINE void octree(const Eigen::MatrixBase& P, + std::vector > & point_indices, + Eigen::PlainObjectBase& CH, + Eigen::PlainObjectBase& CN, + Eigen::PlainObjectBase& W); +} + +#ifndef IGL_STATIC_LIBRARY +# include "octree.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/offset_surface.cpp b/vendor/libigl/include/igl/offset_surface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04bdb273b54d8e5afaaad3580540776d1a7ed900 --- /dev/null +++ b/vendor/libigl/include/igl/offset_surface.cpp @@ -0,0 +1,57 @@ +#include "offset_surface.h" +#include "marching_cubes.h" +#include "voxel_grid.h" +#include "signed_distance.h" +#include "flood_fill.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename isolevelType, + typename DerivedSV, + typename DerivedSF, + typename DerivedGV, + typename Derivedside, + typename DerivedS> +void igl::offset_surface( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const isolevelType isolevel, + const typename Derivedside::Scalar s, + const SignedDistanceType & signed_distance_type, + Eigen::PlainObjectBase & SV, + Eigen::PlainObjectBase & SF, + Eigen::PlainObjectBase & GV, + Eigen::PlainObjectBase & side, + Eigen::PlainObjectBase & S) +{ + typedef typename DerivedV::Scalar Scalar; + typedef typename DerivedF::Scalar Index; + igl::voxel_grid(V,isolevel,s,1,GV,side); + + const Scalar h = + (GV.col(0).maxCoeff()-GV.col(0).minCoeff())/((Scalar)(side(0)-1)); + const Scalar lower_bound = isolevel-sqrt(3.0)*h; + const Scalar upper_bound = isolevel+sqrt(3.0)*h; + { + Eigen::Matrix I; + Eigen::Matrix C,N; + igl::signed_distance( + GV,V,F,signed_distance_type,lower_bound,upper_bound,S,I,C,N); + } + igl::flood_fill(side,S); + + DerivedS SS = S.array()-isolevel; + igl::marching_cubes(SS,GV,side(0),side(1),side(2),0,SV,SF); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::offset_surface, Eigen::Matrix, int, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::Matrix::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::offset_surface, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::Matrix::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::offset_surface, Eigen::Matrix, float, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, float, Eigen::Matrix::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::offset_surface, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::Matrix::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/offset_surface.h b/vendor/libigl/include/igl/offset_surface.h new file mode 100644 index 0000000000000000000000000000000000000000..aac8e237500c1882efdfa5c012f24be1e14c0671 --- /dev/null +++ b/vendor/libigl/include/igl/offset_surface.h @@ -0,0 +1,52 @@ +#ifndef IGL_OFFSET_SURFACE_H +#define IGL_OFFSET_SURFACE_H +#include "igl_inline.h" +#include "signed_distance.h" +#include + +namespace igl +{ + // Compute a triangulated offset surface using matching cubes on a grid of + // signed distance values from the input triangle mesh. + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh triangle indices into V + // isolevel iso level to extract (signed distance: negative inside) + // s number of grid cells along longest side (controls resolution) + // signed_distance_type type of signing to use (see + // ../signed_distance.h) + // Outputs: + // SV #SV by 3 list of output surface mesh vertex positions + // SF #SF by 3 list of output mesh triangle indices into SV + // GV #GV=side(0)*side(1)*side(2) by 3 list of grid cell centers + // side list of number of grid cells in x, y, and z directions + // S #GV by 3 list of signed distance values _near_ `isolevel` ("far" + // from `isolevel` these values are incorrect) + // + template < + typename DerivedV, + typename DerivedF, + typename isolevelType, + typename DerivedSV, + typename DerivedSF, + typename DerivedGV, + typename Derivedside, + typename DerivedS> + void offset_surface( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const isolevelType isolevel, + const typename Derivedside::Scalar s, + const SignedDistanceType & signed_distance_type, + Eigen::PlainObjectBase & SV, + Eigen::PlainObjectBase & SF, + Eigen::PlainObjectBase & GV, + Eigen::PlainObjectBase & side, + Eigen::PlainObjectBase & S); + +} +#ifndef IGL_STATIC_LIBRARY +# include "offset_surface.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/on_boundary.cpp b/vendor/libigl/include/igl/on_boundary.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3fb70ec593c0dc1d276851050b53259487a006ca --- /dev/null +++ b/vendor/libigl/include/igl/on_boundary.cpp @@ -0,0 +1,141 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "on_boundary.h" + +// IGL includes +#include "sort.h" +#include "face_occurrences.h" + +// STL includes + +template +IGL_INLINE void igl::on_boundary( + const std::vector > & T, + std::vector & I, + std::vector > & C) +{ + using namespace std; + if(T.empty()) + { + I.clear(); + C.clear(); + return; + } + + switch(T[0].size()) + { + case 3: + { + // Get a list of all faces + vector > F(T.size()*3,vector(2)); + // Gather faces, loop over tets + for(int i = 0; i< (int)T.size();i++) + { + assert(T[i].size() == 3); + // get face in correct order + F[i*3+0][0] = T[i][1]; + F[i*3+0][1] = T[i][2]; + F[i*3+1][0] = T[i][2]; + F[i*3+1][1] = T[i][0]; + F[i*3+2][0] = T[i][0]; + F[i*3+2][1] = T[i][1]; + } + // Counts + vector FC; + face_occurrences(F,FC); + C.resize(T.size(),vector(3)); + I.resize(T.size(),false); + for(int i = 0; i< (int)T.size();i++) + { + for(int j = 0;j<3;j++) + { + assert(FC[i*3+j] == 2 || FC[i*3+j] == 1); + C[i][j] = FC[i*3+j]==1; + // if any are on boundary set to true + I[i] = I[i] || C[i][j]; + } + } + return; + } + case 4: + { + // Get a list of all faces + vector > F(T.size()*4,vector(3)); + // Gather faces, loop over tets + for(int i = 0; i< (int)T.size();i++) + { + assert(T[i].size() == 4); + // get face in correct order + F[i*4+0][0] = T[i][1]; + F[i*4+0][1] = T[i][3]; + F[i*4+0][2] = T[i][2]; + // get face in correct order + F[i*4+1][0] = T[i][0]; + F[i*4+1][1] = T[i][2]; + F[i*4+1][2] = T[i][3]; + // get face in correct order + F[i*4+2][0] = T[i][0]; + F[i*4+2][1] = T[i][3]; + F[i*4+2][2] = T[i][1]; + // get face in correct order + F[i*4+3][0] = T[i][0]; + F[i*4+3][1] = T[i][1]; + F[i*4+3][2] = T[i][2]; + } + // Counts + vector FC; + face_occurrences(F,FC); + C.resize(T.size(),vector(4)); + I.resize(T.size(),false); + for(int i = 0; i< (int)T.size();i++) + { + for(int j = 0;j<4;j++) + { + assert(FC[i*4+j] == 2 || FC[i*4+j] == 1); + C[i][j] = FC[i*4+j]==1; + // if any are on boundary set to true + I[i] = I[i] || C[i][j]; + } + } + return; + } + } + + +} + +#include "list_to_matrix.h" +#include "matrix_to_list.h" + +template +IGL_INLINE void igl::on_boundary( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& I, + Eigen::PlainObjectBase& C) +{ + assert(T.cols() == 0 || T.cols() == 4 || T.cols() == 3); + using namespace std; + using namespace Eigen; + // Cop out: use vector of vectors version + vector > vT; + matrix_to_list(T,vT); + vector vI; + vector > vC; + on_boundary(vT,vI,vC); + list_to_matrix(vI,I); + list_to_matrix(vC,C); +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::on_boundary, Eigen::Array, Eigen::Array >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::on_boundary, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::on_boundary, Eigen::Array, Eigen::Array >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/on_boundary.h b/vendor/libigl/include/igl/on_boundary.h new file mode 100644 index 0000000000000000000000000000000000000000..c4dab17064782c7663c7fdf2b6a21c5d6fb7b399 --- /dev/null +++ b/vendor/libigl/include/igl/on_boundary.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ON_BOUNDARY_H +#define IGL_ON_BOUNDARY_H +#include "igl_inline.h" +#include + +#include + +namespace igl +{ + // ON_BOUNDARY Determine boundary facets of mesh elements stored in T + // + // Templates: + // IntegerT integer-value: i.e. int + // IntegerF integer-value: i.e. int + // Input: + // T triangle|tetrahedron index list, m by 3|4, where m is the number of + // elements + // Output: + // I m long list of bools whether tet is on boundary + // C m by 3|4 list of bools whether opposite facet is on boundary + // + template + IGL_INLINE void on_boundary( + const std::vector > & T, + std::vector & I, + std::vector > & C); + // Templates: + // DerivedT integer-value: i.e. from MatrixXi + // DerivedI bool-value: i.e. from MatrixXi + // DerivedC bool-value: i.e. from MatrixXi + template + IGL_INLINE void on_boundary( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& I, + Eigen::PlainObjectBase& C); +} + +#ifndef IGL_STATIC_LIBRARY +# include "on_boundary.cpp" +#endif + +#endif + + diff --git a/vendor/libigl/include/igl/orient_halfedges.cpp b/vendor/libigl/include/igl/orient_halfedges.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b2abbdc675cc379208cf0ac240f906852675bfe --- /dev/null +++ b/vendor/libigl/include/igl/orient_halfedges.cpp @@ -0,0 +1,48 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "orient_halfedges.h" + +#include "oriented_facets.h" +#include "unique_simplices.h" + + +template +IGL_INLINE void +igl::orient_halfedges( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE) +{ + assert(F.cols()==3 && "This only works for triangle meshes."); + + using Int = typename DerivedF::Scalar; + + const Eigen::Index m = F.rows(); + + DerivedE allE, EE; + oriented_facets(F, allE); + Eigen::Matrix IA, IC; + unique_simplices(allE, EE, IA, IC); + + E.resize(m, 3); + oE.resize(m, 3); + for(Eigen::Index f=0; f, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/orient_outward.h b/vendor/libigl/include/igl/orient_outward.h new file mode 100644 index 0000000000000000000000000000000000000000..5f4fdc31f97d4a2e7fd6c54f6505c5362b077026 --- /dev/null +++ b/vendor/libigl/include/igl/orient_outward.h @@ -0,0 +1,43 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ORIENT_OUTWARD_H +#define IGL_ORIENT_OUTWARD_H +#include "igl_inline.h" +#include +namespace igl +{ + // Orient each component (identified by C) of a mesh (V,F) so the normals on + // average point away from the patch's centroid. + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices + // C #F list of components (output of orientable_patches) + // Outputs: + // FF #F by 3 list of new triangle indices such that FF(~I,:) = F(~I,:) and + // FF(I,:) = fliplr(F(I,:)) (OK if &FF = &F) + // I max(C)+1 list of whether face has been flipped + template < + typename DerivedV, + typename DerivedF, + typename DerivedC, + typename DerivedFF, + typename DerivedI> + IGL_INLINE void orient_outward( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & FF, + Eigen::PlainObjectBase & I); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "orient_outward.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/orientable_patches.cpp b/vendor/libigl/include/igl/orientable_patches.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54ae641b02e05d042f255e238ac7b399812e199d --- /dev/null +++ b/vendor/libigl/include/igl/orientable_patches.cpp @@ -0,0 +1,107 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "orientable_patches.h" +#include "vertex_components.h" +#include "sort.h" +#include "unique_rows.h" +#include +#include + +template +IGL_INLINE void igl::orientable_patches( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & C, + Eigen::SparseMatrix & A) +{ + using namespace Eigen; + using namespace std; + + // simplex size + assert(F.cols() == 3); + + // List of all "half"-edges: 3*#F by 2 + Matrix allE,sortallE,uE; + allE.resize(F.rows()*3,2); + Matrix IX; + VectorXi IA,IC; + allE.block(0*F.rows(),0,F.rows(),1) = F.col(1); + allE.block(0*F.rows(),1,F.rows(),1) = F.col(2); + allE.block(1*F.rows(),0,F.rows(),1) = F.col(2); + allE.block(1*F.rows(),1,F.rows(),1) = F.col(0); + allE.block(2*F.rows(),0,F.rows(),1) = F.col(0); + allE.block(2*F.rows(),1,F.rows(),1) = F.col(1); + // Sort each row + sort(allE,2,true,sortallE,IX); + //IC(i) tells us where to find sortallE(i,:) in uE: + // so that sortallE(i,:) = uE(IC(i),:) + unique_rows(sortallE,uE,IA,IC); + // uE2FT(e,f) = 1 means face f is adjacent to unique edge e + vector > uE2FTijv(IC.rows()); + for(int e = 0;e(e%F.rows(),IC(e),1); + } + SparseMatrix uE2FT(F.rows(),uE.rows()); + uE2FT.setFromTriplets(uE2FTijv.begin(),uE2FTijv.end()); + // kill non-manifold edges + for(int j=0; j<(int)uE2FT.outerSize();j++) + { + int degree = 0; + for(typename SparseMatrix::InnerIterator it (uE2FT,j); it; ++it) + { + degree++; + } + // Iterate over inside + if(degree > 2) + { + for(typename SparseMatrix::InnerIterator it (uE2FT,j); it; ++it) + { + uE2FT.coeffRef(it.row(),it.col()) = 0; + } + } + } + // Face-face Adjacency matrix + SparseMatrix uE2F; + uE2F = uE2FT.transpose().eval(); + A = uE2FT*uE2F; + // All ones + for(int j=0; j::InnerIterator it (A,j); it; ++it) + { + if(it.value() > 1) + { + A.coeffRef(it.row(),it.col()) = 1; + } + } + } + //% Connected components are patches + //%C = vertex_components(A); % alternative to graphconncomp from matlab_bgl + //[~,C] = graphconncomp(A); + // graph connected components + vertex_components(A,C); + +} + +template +IGL_INLINE void igl::orientable_patches( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & C) +{ + Eigen::SparseMatrix A; + return orientable_patches(F,C,A); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::orientable_patches, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&); +template void igl::orientable_patches, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::orientable_patches, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&); +template void igl::orientable_patches, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/oriented_facets.cpp b/vendor/libigl/include/igl/oriented_facets.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ebc122fa7aa1a4eda3c33a1d91c696edc3e52684 --- /dev/null +++ b/vendor/libigl/include/igl/oriented_facets.cpp @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "oriented_facets.h" + +template +IGL_INLINE void igl::oriented_facets( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E) +{ + E.resize(F.rows()*F.cols(),F.cols()-1); + typedef typename DerivedE::Scalar EScalar; + switch(F.cols()) + { + case 4: + E.block(0*F.rows(),0,F.rows(),1) = F.col(1).template cast(); + E.block(0*F.rows(),1,F.rows(),1) = F.col(3).template cast(); + E.block(0*F.rows(),2,F.rows(),1) = F.col(2).template cast(); + + E.block(1*F.rows(),0,F.rows(),1) = F.col(0).template cast(); + E.block(1*F.rows(),1,F.rows(),1) = F.col(2).template cast(); + E.block(1*F.rows(),2,F.rows(),1) = F.col(3).template cast(); + + E.block(2*F.rows(),0,F.rows(),1) = F.col(0).template cast(); + E.block(2*F.rows(),1,F.rows(),1) = F.col(3).template cast(); + E.block(2*F.rows(),2,F.rows(),1) = F.col(1).template cast(); + + E.block(3*F.rows(),0,F.rows(),1) = F.col(0).template cast(); + E.block(3*F.rows(),1,F.rows(),1) = F.col(1).template cast(); + E.block(3*F.rows(),2,F.rows(),1) = F.col(2).template cast(); + return; + case 3: + E.block(0*F.rows(),0,F.rows(),1) = F.col(1).template cast(); + E.block(0*F.rows(),1,F.rows(),1) = F.col(2).template cast(); + E.block(1*F.rows(),0,F.rows(),1) = F.col(2).template cast(); + E.block(1*F.rows(),1,F.rows(),1) = F.col(0).template cast(); + E.block(2*F.rows(),0,F.rows(),1) = F.col(0).template cast(); + E.block(2*F.rows(),1,F.rows(),1) = F.col(1).template cast(); + return; + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::oriented_facets, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/oriented_facets.h b/vendor/libigl/include/igl/oriented_facets.h new file mode 100644 index 0000000000000000000000000000000000000000..9e211cf9b78bbe802a39d0630e593c6a07605da1 --- /dev/null +++ b/vendor/libigl/include/igl/oriented_facets.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ORIENTED_FACETS_H +#define IGL_ORIENTED_FACETS_H +#include "igl_inline.h" +#include +namespace igl +{ + // ORIENTED_FACETS Determines all "directed + // [facets](https://en.wikipedia.org/wiki/Simplex#Elements)" of a given set of + // simplicial elements. For a manifold triangle mesh, this computes all + // half-edges. For a manifold tetrahedral mesh, this computes all half-faces. + // + // Inputs: + // F #F by simplex_size list of simplices + // Outputs: + // E #E by simplex_size-1 list of facets, such that E.row(f+#F*c) is the + // facet opposite F(f,c) + // + // Note: this is not the same as igl::edges because this includes every + // directed edge including repeats (meaning interior edges on a surface will + // show up once for each direction and non-manifold edges may appear more than + // once for each direction). + // + // Note: This replaces the deprecated `all_edges` function + template + IGL_INLINE void oriented_facets( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E); +} + +#ifndef IGL_STATIC_LIBRARY +# include "oriented_facets.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/ortho.cpp b/vendor/libigl/include/igl/ortho.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e634eed746abee734f85567ee1a7130eb853c1a8 --- /dev/null +++ b/vendor/libigl/include/igl/ortho.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ortho.h" + +template < typename DerivedP> +IGL_INLINE void igl::ortho( + const typename DerivedP::Scalar left, + const typename DerivedP::Scalar right, + const typename DerivedP::Scalar bottom, + const typename DerivedP::Scalar top, + const typename DerivedP::Scalar nearVal, + const typename DerivedP::Scalar farVal, + Eigen::PlainObjectBase & P) +{ + P.setIdentity(); + P(0,0) = 2. / (right - left); + P(1,1) = 2. / (top - bottom); + P(2,2) = - 2./ (farVal - nearVal); + P(0,3) = - (right + left) / (right - left); + P(1,3) = - (top + bottom) / (top - bottom); + P(2,3) = - (farVal + nearVal) / (farVal - nearVal); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::ortho >(Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/ortho.h b/vendor/libigl/include/igl/ortho.h new file mode 100644 index 0000000000000000000000000000000000000000..70b9cab4dd1c39d0e380ad550c63a64ac0512d92 --- /dev/null +++ b/vendor/libigl/include/igl/ortho.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ORTHO_H +#define IGL_ORTHO_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Implementation of the deprecated glOrtho function. + // + // Inputs: + // left coordinate of left vertical clipping plane + // right coordinate of right vertical clipping plane + // bottom coordinate of bottom vertical clipping plane + // top coordinate of top vertical clipping plane + // nearVal distance to near plane + // farVal distance to far plane + // Outputs: + // P 4x4 perspective matrix + template < typename DerivedP> + IGL_INLINE void ortho( + const typename DerivedP::Scalar left, + const typename DerivedP::Scalar right, + const typename DerivedP::Scalar bottom, + const typename DerivedP::Scalar top, + const typename DerivedP::Scalar nearVal, + const typename DerivedP::Scalar farVal, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "ortho.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/outer_element.h b/vendor/libigl/include/igl/outer_element.h new file mode 100644 index 0000000000000000000000000000000000000000..937873641bb58ed8920d2e850c726e8f6ae2233a --- /dev/null +++ b/vendor/libigl/include/igl/outer_element.h @@ -0,0 +1,110 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Qingan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_OUTER_ELEMENT_H +#define IGL_OUTER_ELEMENT_H +#include "igl_inline.h" +#include +namespace igl +{ + // Find a vertex that is reachable from infinite without crossing any faces. + // Such vertex is called "outer vertex." + // + // Precondition: The input mesh must have all self-intersection resolved and + // no duplicated vertices. See cgal::remesh_self_intersections.h for how to + // obtain such input. + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices into V + // I #I list of facets to consider + // Outputs: + // v_index index of outer vertex + // A #A list of facets incident to the outer vertex + template < + typename DerivedV, + typename DerivedF, + typename DerivedI, + typename IndexType, + typename DerivedA + > + IGL_INLINE void outer_vertex( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & I, + IndexType & v_index, + Eigen::PlainObjectBase & A); + + + // Find an edge that is reachable from infinity without crossing any faces. + // Such edge is called "outer edge." + // + // Precondition: The input mesh must have all self-intersection resolved and + // no duplicated vertices. The correctness of the output depends on the fact + // that there is no edge overlap. See cgal::remesh_self_intersections.h for + // how to obtain such input. + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices into V + // I #I list of facets to consider + // Outputs: + // v1 index of the first end point of outer edge + // v2 index of the second end point of outer edge + // A #A list of facets incident to the outer edge + template< + typename DerivedV, + typename DerivedF, + typename DerivedI, + typename IndexType, + typename DerivedA + > + IGL_INLINE void outer_edge( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & I, + IndexType & v1, + IndexType & v2, + Eigen::PlainObjectBase & A); + + + // Find a facet that is reachable from infinity without crossing any faces. + // Such facet is called "outer facet." + // + // Precondition: The input mesh must have all self-intersection resolved. I.e + // there is no duplicated vertices, no overlapping edge and no intersecting + // faces (the only exception is there could be topologically duplicated faces). + // See cgal::remesh_self_intersections.h for how to obtain such input. + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices into V + // N #N by 3 list of face normals + // I #I list of facets to consider + // Outputs: + // f Index of the outer facet. + // flipped true iff the normal of f points inwards. + template< + typename DerivedV, + typename DerivedF, + typename DerivedN, + typename DerivedI, + typename IndexType + > + IGL_INLINE void outer_facet( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & I, + IndexType & f, + bool & flipped); +} + +#ifndef IGL_STATIC_LIBRARY +# include "outer_element.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/parallel_for.h b/vendor/libigl/include/igl/parallel_for.h new file mode 100644 index 0000000000000000000000000000000000000000..b6f7f02950330d00d0fac82d91aca080b37a326c --- /dev/null +++ b/vendor/libigl/include/igl/parallel_for.h @@ -0,0 +1,188 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PARALLEL_FOR_H +#define IGL_PARALLEL_FOR_H +#include "igl_inline.h" +#include + +//#warning "Defining IGL_PARALLEL_FOR_FORCE_SERIAL" +//#define IGL_PARALLEL_FOR_FORCE_SERIAL + +namespace igl +{ + // PARALLEL_FOR Functional implementation of a basic, open-mp style, parallel + // for loop. If the inner block of a for-loop can be rewritten/encapsulated in + // a single (anonymous/lambda) function call `func` so that the serial code + // looks like: + // + // for(int i = 0;i + inline bool parallel_for( + const Index loop_size, + const FunctionType & func, + const size_t min_parallel=0); + // PARALLEL_FOR Functional implementation of an open-mp style, parallel for + // loop with accumulation. For example, serial code separated into n chunks + // (each to be parallelized with a thread) might look like: + // + // Eigen::VectorXd S; + // const auto & prep_func = [&S](int n){ S = Eigen:VectorXd::Zero(n); }; + // const auto & func = [&X,&S](int i, int t){ S(t) += X(i); }; + // const auto & accum_func = [&S,&sum](int t){ sum += S(t); }; + // prep_func(n); + // for(int i = 0;i= number of threads as only + // argument + // func function handle taking iteration index i and thread id t as only + // arguments to compute inner block of for loop I.e. + // for(int i ...){ func(i,t); } + // accum_func function handle taking thread index as only argument, to be + // called after all calls of func, e.g., for serial accumulation across + // all n (potential) threads, see n in description of prep_func. + // min_parallel min size of loop_size such that parallel (non-serial) + // thread pooling should be attempted {0} + // Returns true iff thread pool was invoked + template< + typename Index, + typename PrepFunctionType, + typename FunctionType, + typename AccumFunctionType + > + inline bool parallel_for( + const Index loop_size, + const PrepFunctionType & prep_func, + const FunctionType & func, + const AccumFunctionType & accum_func, + const size_t min_parallel=0); +} + +// Implementation + +#include "default_num_threads.h" + +#include +#include +#include +#include +#include + +template +inline bool igl::parallel_for( + const Index loop_size, + const FunctionType & func, + const size_t min_parallel) +{ + using namespace std; + // no op preparation/accumulation + const auto & no_op = [](const size_t /*n/t*/){}; + // two-parameter wrapper ignoring thread id + const auto & wrapper = [&func](Index i,size_t /*t*/){ func(i); }; + return parallel_for(loop_size,no_op,wrapper,no_op,min_parallel); +} + +template< + typename Index, + typename PreFunctionType, + typename FunctionType, + typename AccumFunctionType> +inline bool igl::parallel_for( + const Index loop_size, + const PreFunctionType & prep_func, + const FunctionType & func, + const AccumFunctionType & accum_func, + const size_t min_parallel) +{ + assert(loop_size>=0); + if(loop_size==0) return false; + // Estimate number of threads in the pool + // http://ideone.com/Z7zldb +#ifdef IGL_PARALLEL_FOR_FORCE_SERIAL + const size_t nthreads = 1; +#else + const size_t nthreads = igl::default_num_threads(); +#endif + if(loop_size(nthreads)),(Index)1); + + // [Helper] Inner loop + const auto & range = [&func](const Index k1, const Index k2, const size_t t) + { + for(Index k = k1; k < k2; k++) func(k,t); + }; + prep_func(nthreads); + // Create pool and launch jobs + std::vector pool; + pool.reserve(nthreads); + // Inner range extents + Index i1 = 0; + Index i2 = std::min(0 + slice, loop_size); + { + size_t t = 0; + for (; t+1 < nthreads && i1 < loop_size; ++t) + { + pool.emplace_back(range, i1, i2, t); + i1 = i2; + i2 = std::min(i2 + slice, loop_size); + } + if (i1 < loop_size) + { + pool.emplace_back(range, i1, loop_size, t); + } + } + // Wait for jobs to finish + for (std::thread &t : pool) if (t.joinable()) t.join(); + // Accumulate across threads + for(size_t t = 0;t +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include +#include + +template +IGL_INLINE void igl::parallel_transport_angles( +const Eigen::PlainObjectBase& V, +const Eigen::PlainObjectBase& F, +const Eigen::PlainObjectBase& FN, +const Eigen::MatrixXi &E2F, +const Eigen::MatrixXi &F2E, +Eigen::PlainObjectBase &K) +{ + int numE = E2F.rows(); + + Eigen::VectorXi isBorderEdge; + isBorderEdge.setZero(numE,1); + for(unsigned i=0; i N0 = FN.row(fid0); +// Eigen::Matrix N1 = FN.row(fid1); + + // find common edge on triangle 0 and 1 + int fid0_vc = -1; + int fid1_vc = -1; + for (unsigned i=0;i<3;++i) + { + if (F2E(fid0,i) == eid) + fid0_vc = i; + if (F2E(fid1,i) == eid) + fid1_vc = i; + } + assert(fid0_vc != -1); + assert(fid1_vc != -1); + + Eigen::Matrix common_edge = V.row(F(fid0,(fid0_vc+1)%3)) - V.row(F(fid0,fid0_vc)); + common_edge.normalize(); + + // Map the two triangles in a new space where the common edge is the x axis and the N0 the z axis + Eigen::Matrix P; + Eigen::Matrix o = V.row(F(fid0,fid0_vc)); + Eigen::Matrix tmp = -N0.cross(common_edge); + P << common_edge, tmp, N0; + // P.transposeInPlace(); + + + Eigen::Matrix V0; + V0.row(0) = V.row(F(fid0,0)) -o; + V0.row(1) = V.row(F(fid0,1)) -o; + V0.row(2) = V.row(F(fid0,2)) -o; + + V0 = (P*V0.transpose()).transpose(); + + // assert(V0(0,2) < 1e-10); + // assert(V0(1,2) < 1e-10); + // assert(V0(2,2) < 1e-10); + + Eigen::Matrix V1; + V1.row(0) = V.row(F(fid1,0)) -o; + V1.row(1) = V.row(F(fid1,1)) -o; + V1.row(2) = V.row(F(fid1,2)) -o; + V1 = (P*V1.transpose()).transpose(); + + // assert(V1(fid1_vc,2) < 10e-10); + // assert(V1((fid1_vc+1)%3,2) < 10e-10); + + // compute rotation R such that R * N1 = N0 + // i.e. map both triangles to the same plane + double alpha = -atan2(V1((fid1_vc+2)%3,2),V1((fid1_vc+2)%3,1)); + + Eigen::Matrix R; + R << 1, 0, 0, + 0, cos(alpha), -sin(alpha) , + 0, sin(alpha), cos(alpha); + V1 = (R*V1.transpose()).transpose(); + + // assert(V1(0,2) < 1e-10); + // assert(V1(1,2) < 1e-10); + // assert(V1(2,2) < 1e-10); + + // measure the angle between the reference frames + // k_ij is the angle between the triangle on the left and the one on the right + Eigen::Matrix ref0 = V0.row(1) - V0.row(0); + Eigen::Matrix ref1 = V1.row(1) - V1.row(0); + + ref0.normalize(); + ref1.normalize(); + + double ktemp = atan2(ref1(1),ref1(0)) - atan2(ref0(1),ref0(0)); + + // just to be sure, rotate ref0 using angle ktemp... + Eigen::Matrix R2; + R2 << cos(ktemp), -sin(ktemp), sin(ktemp), cos(ktemp); + +// Eigen::Matrix tmp1 = R2*(ref0.head(2)).transpose(); + + // assert(tmp1(0) - ref1(0) < 1e-10); + // assert(tmp1(1) - ref1(1) < 1e-10); + + K[eid] = ktemp; + } + } + +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::parallel_transport_angles, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/parallel_transport_angles.h b/vendor/libigl/include/igl/parallel_transport_angles.h new file mode 100644 index 0000000000000000000000000000000000000000..e37d7f37358f56b5ac8b5dfb644cd7266936033b --- /dev/null +++ b/vendor/libigl/include/igl/parallel_transport_angles.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_PARALLEL_TRANSPORT_ANGLE +#define IGL_PARALLEL_TRANSPORT_ANGLE +#include "igl_inline.h" + +#include +#include + +namespace igl { + // Given the per-face local bases computed via igl::local_basis, this function + // computes the angle between the two reference frames across each edge. + // Any two vectors across the edge whose 2D representation only differs by + // this angle are considered to be parallel. + + // Inputs: + // V #V by 3 list of mesh vertex coordinates + // F #F by 3 list of mesh faces (must be triangles) + // FN #F by 3 list of face normals + // E2F #E by 2 list of the edge-to-face relation (e.g. computed + // via igl::edge_topology) + // F2E #F by 3 list of the face-to-edge relation (e.g. computed + // via igl::edge_topology) + // Output: + // K #E by 1 list of the parallel transport angles (zero + // for all boundary edges) + // +template +IGL_INLINE void parallel_transport_angles( +const Eigen::PlainObjectBase&V, +const Eigen::PlainObjectBase&F, +const Eigen::PlainObjectBase&FN, +const Eigen::MatrixXi &E2F, +const Eigen::MatrixXi &F2E, +Eigen::PlainObjectBase&K); + +}; + + +#ifndef IGL_STATIC_LIBRARY +#include "parallel_transport_angles.cpp" +#endif + + +#endif /* defined(IGL_PARALLEL_TRANSPORT_ANGLE) */ diff --git a/vendor/libigl/include/igl/partition.h b/vendor/libigl/include/igl/partition.h new file mode 100644 index 0000000000000000000000000000000000000000..167ebd0d7a07ddcfc16e423b5eb274b8b274d3a1 --- /dev/null +++ b/vendor/libigl/include/igl/partition.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PARTITION_H +#define IGL_PARTITION_H +#include "igl_inline.h" +#include + +namespace igl +{ + // PARTITION partition vertices into groups based on each + // vertex's vector: vertices with similar coordinates (close in + // space) will be put in the same group. + // + // Inputs: + // W #W by dim coordinate matrix + // k desired number of groups default is dim + // Output: + // G #W list of group indices (1 to k) for each vertex, such that vertex i + // is assigned to group G(i) + // S k list of seed vertices + // D #W list of squared distances for each vertex to it's corresponding + // closest seed + IGL_INLINE void partition( + const Eigen::MatrixXd & W, + const int k, + Eigen::Matrix & G, + Eigen::Matrix & S, + Eigen::Matrix & D); +} + +#ifndef IGL_STATIC_LIBRARY +#include "partition.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/parula.cpp b/vendor/libigl/include/igl/parula.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42d12ac2003bedc918e9f40d2bf55f692cde7eaa --- /dev/null +++ b/vendor/libigl/include/igl/parula.cpp @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "parula.h" +#include "colormap.h" + +template +IGL_INLINE void igl::parula(const T x, T * rgb) +{ + igl::colormap(igl::COLOR_MAP_TYPE_PARULA,x, rgb); +} + +template +IGL_INLINE void igl::parula(const T f, T & r, T & g, T & b) +{ + igl::colormap(igl::COLOR_MAP_TYPE_PARULA, f, r, g, b); +} + +template +IGL_INLINE void igl::parula( + const Eigen::MatrixBase & Z, + const bool normalize, + Eigen::PlainObjectBase & C) +{ + igl::colormap(igl::COLOR_MAP_TYPE_PARULA, Z, normalize, C); +} +template +IGL_INLINE void igl::parula( + const Eigen::MatrixBase & Z, + const double min_z, + const double max_z, + Eigen::PlainObjectBase & C) +{ + igl::colormap(igl::COLOR_MAP_TYPE_PARULA, Z, min_z, max_z, C); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::parula, Eigen::Matrix >(Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::parula, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::parula(double, double*); +template void igl::parula(double, double&, double&, double&); +template void igl::parula, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::parula, Eigen::Matrix >(Eigen::MatrixBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::parula, Eigen::Matrix >(Eigen::MatrixBase > const&, double, double, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/parula.h b/vendor/libigl/include/igl/parula.h new file mode 100644 index 0000000000000000000000000000000000000000..55cbd447f6b29106ac33f8e594b24e763e57f719 --- /dev/null +++ b/vendor/libigl/include/igl/parula.h @@ -0,0 +1,62 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PARULA_H +#define IGL_PARULA_H +#include "igl_inline.h" +//#ifndef IGL_NO_EIGEN +# include +//#endif +namespace igl +{ + // PARULA like MATLAB's parula + // + // Inputs: + // m number of colors + // Outputs: + // J m by list of RGB colors between 0 and 1 + // + // Wrapper for directly computing [r,g,b] values for a given factor f between + // 0 and 1 + // + // Inputs: + // f factor determining color value as if 0 was min and 1 was max + // Outputs: + // r red value + // g green value + // b blue value + template + IGL_INLINE void parula(const T f, T * rgb); + template + IGL_INLINE void parula(const T f, T & r, T & g, T & b); + // Inputs: + // Z #Z list of factors + // normalize whether to normalize Z to be tightly between [0,1] + // Outputs: + // C #C by 3 list of rgb colors + template + IGL_INLINE void parula( + const Eigen::MatrixBase & Z, + const bool normalize, + Eigen::PlainObjectBase & C); + // Inputs: + // min_Z value at blue + // max_Z value at red + template + IGL_INLINE void parula( + const Eigen::MatrixBase & Z, + const double min_Z, + const double max_Z, + Eigen::PlainObjectBase & C); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "parula.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/path_to_edges.cpp b/vendor/libigl/include/igl/path_to_edges.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97112e4af961cea0dfd4b6ca82736c009eb54d15 --- /dev/null +++ b/vendor/libigl/include/igl/path_to_edges.cpp @@ -0,0 +1,42 @@ +#include "path_to_edges.h" + +template +IGL_INLINE void igl::path_to_edges( + const Eigen::MatrixBase & I, + Eigen::PlainObjectBase & E, + bool make_loop) +{ + // Check that I is 1 dimensional + assert(I.size() == I.rows() || I.size() == I.cols()); + + if(make_loop) { + E.conservativeResize(I.size(), 2); + for(int i = 0; i < I.size() - 1; i++) { + E(i, 0) = I(i); + E(i, 1) = I(i + 1); + } + E(I.size() - 1, 0) = I(I.size() - 1); + E(I.size() - 1, 1) = I(0); + } else { + E.conservativeResize(I.size()-1, 2); + for(int i = 0; i < I.size()-1; i++) { + E(i, 0) = I(i); + E(i, 1) = I(i+1); + } + } +} + +template +IGL_INLINE void igl::path_to_edges( + const std::vector & I, + Eigen::PlainObjectBase & E, + bool make_loop) +{ + igl::path_to_edges(Eigen::Map>(I.data(), I.size()), E, make_loop); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::path_to_edges, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, bool); +template void igl::path_to_edges >(std::vector > const&, Eigen::PlainObjectBase >&, bool); +#endif + \ No newline at end of file diff --git a/vendor/libigl/include/igl/path_to_edges.h b/vendor/libigl/include/igl/path_to_edges.h new file mode 100644 index 0000000000000000000000000000000000000000..81b03eee7bf0772810611545fbba2bbdabd8bae6 --- /dev/null +++ b/vendor/libigl/include/igl/path_to_edges.h @@ -0,0 +1,45 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2019 Lawson Fulton lawsonfulton@gmail.com +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/ +#ifndef IGL_PATH_TO_EDGES_H +#define IGL_PATH_TO_EDGES_H + +#include "igl_inline.h" + +#include + +#include + +namespace igl +{ + // Given a path as an ordered list of N>=2 vertex indices I[0], I[1], ..., I[N-1] + // construct a list of edges [[I[0],I[1]], [I[1],I[2]], ..., [I[N-2], I[N-1]]] + // connecting each sequential pair of vertices. + // + // Inputs: + // I #I list of vertex indices + // make_loop bool If true, include an edge connecting I[N-1] to I[0] + // Outputs: + // E #I-1 by 2 list of edges + // + template + IGL_INLINE void path_to_edges( + const Eigen::MatrixBase & I, + Eigen::PlainObjectBase & E, + bool make_loop=false); + + template + IGL_INLINE void path_to_edges( + const std::vector & I, + Eigen::PlainObjectBase & E, + bool make_loop=false); + +} +#ifndef IGL_STATIC_LIBRARY +# include "path_to_edges.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/path_to_executable.cpp b/vendor/libigl/include/igl/path_to_executable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb42a79ba095b9ceff21cee80525a467a613f97d --- /dev/null +++ b/vendor/libigl/include/igl/path_to_executable.cpp @@ -0,0 +1,53 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "path_to_executable.h" +#ifdef __APPLE__ +# include +#endif +#if defined(_WIN32) +# include +#else + #include +#endif +#include + +IGL_INLINE std::string igl::path_to_executable() +{ + // http://pastebin.com/ffzzxPzi + using namespace std; + std::string path; + char buffer[1024]; + uint32_t size = sizeof(buffer); +#if defined (WIN32) + GetModuleFileName(nullptr,buffer,size); + path = buffer; +#elif defined (__APPLE__) + if(_NSGetExecutablePath(buffer, &size) == 0) + { + path = buffer; + } +#elif defined(UNIX) || defined(unix) || defined(__unix) || defined(__unix__) + int byte_count = readlink("/proc/self/exe", buffer, size); + if (byte_count != -1) + { + path = std::string(buffer, byte_count); + } +#elif defined(__FreeBSD__) + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + sysctl(mib, 4, buffer, sizeof(buffer), NULL, 0); + path = buffer; +#elif defined(SUNOS) + path = getexecname(); +#endif + return path; +} + diff --git a/vendor/libigl/include/igl/path_to_executable.h b/vendor/libigl/include/igl/path_to_executable.h new file mode 100644 index 0000000000000000000000000000000000000000..169c3400bcb8ce5dbabe758ee06e3d70e5017906 --- /dev/null +++ b/vendor/libigl/include/igl/path_to_executable.h @@ -0,0 +1,21 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PATH_TO_EXECUTABLE_H +#define IGL_PATH_TO_EXECUTABLE_H +#include "igl_inline.h" +#include +namespace igl +{ + // Return the path of the current executable. + // Note: Tested for Mac OS X + IGL_INLINE std::string path_to_executable(); +} +#ifndef IGL_STATIC_LIBRARY +# include "path_to_executable.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/pathinfo.h b/vendor/libigl/include/igl/pathinfo.h new file mode 100644 index 0000000000000000000000000000000000000000..b59e481574ed4e7eab32a5ff40627f3abf6dc1f3 --- /dev/null +++ b/vendor/libigl/include/igl/pathinfo.h @@ -0,0 +1,64 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PATHINFO_H +#define IGL_PATHINFO_H +#include "igl_inline.h" + +#include + +namespace igl +{ + //// Decided not to use these + //const int PATHINFO_DIRNAME 01 + //const int PATHINFO_BASENAME 02 + //const int PATHINFO_EXTENSION 04 + //const int PATHINFO_FILENAME 08 + + // Function like PHP's pathinfo + // returns information about path + // Input: + // path string containing input path + // Outputs: + // dirname string containing dirname (see dirname.h) + // basename string containing basename (see basename.h) + // extension string containing extension (characters after last '.') + // filename string containing filename (characters of basename before last + // '.') + // + // + // Examples: + // + // input | dirname basename ext filename + // "/" | "/" "" "" "" + // "//" | "/" "" "" "" + // "/foo" | "/" "foo" "" "foo" + // "/foo/" | "/" "foo" "" "foo" + // "/foo//" | "/" "foo" "" "foo" + // "/foo/./" | "/foo" "." "" "" + // "/foo/bar" | "/foo" "bar" "" "bar" + // "/foo/bar." | "/foo" "bar." "" "bar" + // "/foo/bar.txt" | "/foo" "bar.txt" "txt" "bar" + // "/foo/bar.txt.zip" | "/foo" "bar.txt.zip" "zip" "bar.txt" + // "/foo/bar.dir/" | "/foo" "bar.dir" "dir" "bar" + // "/foo/bar.dir/file" | "/foo/bar.dir" "file" "" "file" + // "/foo/bar.dir/file.txt" | "/foo/bar.dir" "file.txt" "txt" "file" + // See also: basename, dirname + IGL_INLINE void pathinfo( + const std::string & path, + std::string & dirname, + std::string & basename, + std::string & extension, + std::string & filename); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "pathinfo.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/per_corner_normals.h b/vendor/libigl/include/igl/per_corner_normals.h new file mode 100644 index 0000000000000000000000000000000000000000..10613e5b49aef8c3defaffadb1b751c2af527890 --- /dev/null +++ b/vendor/libigl/include/igl/per_corner_normals.h @@ -0,0 +1,129 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2021 Alec Jacobson +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PER_CORNER_NORMALS_H +#define IGL_PER_CORNER_NORMALS_H +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Compute per corner normals for a triangle mesh by computing the + // area-weighted average of normals at incident faces whose normals deviate + // less than the provided threshold. + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of mesh triangle indices into V + // corner_threshold_degrees threshold in degrees on sharp angles + // Outputs: + // CN #F*3 by 3 list of mesh vertex 3D normals, where the normal + // for corner F(i,j) is at CN.row(i*3+j) + template < + typename DerivedV, + typename DerivedF, + typename DerivedCN> + IGL_INLINE void per_corner_normals( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const typename DerivedV::Scalar corner_threshold_degrees, + Eigen::PlainObjectBase & CN); + // Inputs: + // VF 3*#F list List of faces indice on each vertex, so that VF(NI(i)+j) = + // f, means that face f is the jth face (in no particular order) incident + // on vertex i. + // NI #V+1 list cumulative sum of vertex-triangle degrees with a + // preceeding zero. "How many faces" have been seen before visiting this + // vertex and its incident faces. + // + // See also: vertex_triangle_adjacency + template < + typename DerivedV, + typename DerivedF, + typename DerivedVF, + typename DerivedNI, + typename DerivedCN> + IGL_INLINE void per_corner_normals( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const typename DerivedV::Scalar corner_threshold_degrees, + const Eigen::MatrixBase & VF, + const Eigen::MatrixBase & NI, + Eigen::PlainObjectBase & CN); + // Inputs: + // CI #CI list of face neighbors as indices into rows of F + // CC 3*#F+1 list of cumulative sizes so that CC(i*3+j+1) - CC(i*3+j) is + // the number of faces considered smoothly incident on corner at F(i,j) + // + // See also smooth_corner_adjacency + template < + typename DerivedV, + typename DerivedF, + typename DerivedCI, + typename DerivedCC, + typename DerivedCN> + IGL_INLINE void per_corner_normals( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & CI, + const Eigen::MatrixBase & CC, + Eigen::PlainObjectBase & CN); + // Given indexed normals (e.g., read from a .obj file), explode into + // per-corner normals (e.g., as expected by igl::opengl::ViewerData) + // + // Inputs: + // NV #NV by 3 list of index normal vectors + // NF #F by nc list of indices into rows of NV + // Outputs + // CN #F*nc by 3 list of per-corner normals so that + // CN.row(i*nc+c) = NV.row(NF(i,c)) + template + IGL_INLINE void per_corner_normals( + const Eigen::MatrixBase & NV, + const Eigen::MatrixBase & NF, + Eigen::PlainObjectBase & CN); + // Inputs: + // V #V by 3 list of mesh vertex positions + // I #I vectorized list of polygon corner indices into rows of some matrix V + // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = size of + // the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the indices of + // the ith polygon + // corner_threshold threshold in degrees on sharp angles + // Outputs: + // N #I by 3 list of per corner normals + // VV #I+#polygons by 3 list of auxiliary triangle mesh vertex positions + // FF #I by 3 list of triangle indices into rows of VV + // J #I list of indices into original polygons + // NN #FF by 3 list of normals for each auxiliary triangle + template < + typename DerivedV, + typename DerivedI, + typename DerivedC, + typename DerivedN, + typename DerivedVV, + typename DerivedFF, + typename DerivedJ, + typename DerivedNN> + IGL_INLINE void per_corner_normals( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + const typename DerivedV::Scalar corner_threshold_degrees, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & VV, + Eigen::PlainObjectBase & FF, + Eigen::PlainObjectBase & J, + Eigen::PlainObjectBase & NN); +} + +#ifndef IGL_STATIC_LIBRARY +# include "per_corner_normals.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/per_face_normals.cpp b/vendor/libigl/include/igl/per_face_normals.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a49e28d449ada95fac30ec036bd2bac6ecee45a4 --- /dev/null +++ b/vendor/libigl/include/igl/per_face_normals.cpp @@ -0,0 +1,192 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "per_face_normals.h" +#include + +#define SQRT_ONE_OVER_THREE 0.57735026918962573 +template +IGL_INLINE void igl::per_face_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase & Z, + Eigen::PlainObjectBase & N) +{ + N.resize(F.rows(),3); + // loop over faces + int Frows = F.rows(); +#pragma omp parallel for if (Frows>10000) + for(int i = 0; i < Frows;i++) + { + const Eigen::Matrix v1 = V.row(F(i,1)) - V.row(F(i,0)); + const Eigen::Matrix v2 = V.row(F(i,2)) - V.row(F(i,0)); + N.row(i) = v1.cross(v2);//.normalized(); + typename DerivedV::Scalar r = N.row(i).norm(); + if(r == 0) + { + N.row(i) = Z; + }else + { + N.row(i) /= r; + } + } +} + +template +IGL_INLINE void igl::per_face_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & N) +{ + Eigen::Matrix Z(0,0,0); + return per_face_normals(V,F,Z,N); +} + +template +IGL_INLINE void igl::per_face_normals_stable( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & N) +{ + typedef Eigen::Matrix RowVectorV3; + typedef typename DerivedV::Scalar Scalar; + + const size_t m = F.rows(); + + N.resize(F.rows(),3); + // Grad all points + for(size_t f = 0;f sum3 = + [&sum3](Scalar a, Scalar b, Scalar c)->Scalar + { + if(fabs(c)>fabs(a)) + { + return sum3(c,b,a); + } + // c < a + if(fabs(c)>fabs(b)) + { + return sum3(a,c,b); + } + // c < a, c < b + if(fabs(b)>fabs(a)) + { + return sum3(b,a,c); + } + return (a+b)+c; + }; + + N(f,d) = sum3(n0(d),n1(d),n2(d)); + } + // sum better not be sure, or else NaN + N.row(f) /= N.row(f).norm(); + } + +} + +#include "cotmatrix.h" + +template < + typename DerivedV, + typename DerivedI, + typename DerivedC, + typename DerivedN, + typename DerivedVV, + typename DerivedFF, + typename DerivedJ> +IGL_INLINE void igl::per_face_normals( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & VV, + Eigen::PlainObjectBase & FF, + Eigen::PlainObjectBase & J) +{ + assert(V.cols() == 3); + typedef Eigen::Index Index; + typedef typename DerivedN::Scalar Scalar; + // Use Bunge et al. algorithm in igl::cotmatrix to insert a point for each + // polygon which minimizes squared area. + { + Eigen::SparseMatrix _1,_2,P; + igl::cotmatrix(V,I,C,_1,_2,P); + VV = P*V; + } + // number of polygons + const Eigen::Index m = C.size()-1; + N.resize(m,3); + FF.resize(C(m),3); + J.resize(C(m)); + { + Eigen::Index k = 0; + for(Eigen::Index p = 0;p V3; + N.row(p) += + V3(VV.row(I(C(p)+((i+0)%np)))-VV.row(V.rows()+p)).cross( + V3(VV.row(I(C(p)+((i+1)%np)))-VV.row(V.rows()+p))); + } + // normalize to take average + N.row(p) /= N.row(p).stableNorm(); + } + assert(k == FF.rows()); + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// Nonsense template. Where'd this come from? AABB nonsense? +namespace igl{template<> void per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&){} } +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals,class Eigen::Matrix,class Eigen::Matrix >(class Eigen::MatrixBase > const &,class Eigen::MatrixBase > const &,class Eigen::PlainObjectBase > &); +template void igl::per_face_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals_stable, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals_stable, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_face_normals_stable, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/per_face_normals.h b/vendor/libigl/include/igl/per_face_normals.h new file mode 100644 index 0000000000000000000000000000000000000000..13745353e63f935e5dea55b2e60910c7f1470a0f --- /dev/null +++ b/vendor/libigl/include/igl/per_face_normals.h @@ -0,0 +1,79 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PER_FACE_NORMALS_H +#define IGL_PER_FACE_NORMALS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute face normals via vertex position list, face list + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 3 eigen Matrix of face (triangle) indices + // Z 3 vector normal given to faces with degenerate normal. + // Output: + // N #F by 3 eigen Matrix of mesh face (triangle) 3D normals + // + // Example: + // // Give degenerate faces (1/3,1/3,1/3)^0.5 + // per_face_normals(V,F,Vector3d(1,1,1).normalized(),N); + template + IGL_INLINE void per_face_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase & Z, + Eigen::PlainObjectBase & N); + // Wrapper with Z = (0,0,0). Note that this means that row norms will be zero + // (i.e. not 1) for degenerate normals. + template + IGL_INLINE void per_face_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & N); + // Special version where order of face indices is guaranteed not to effect + // output. + template + IGL_INLINE void per_face_normals_stable( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & N); + // Inputs: + // V #V by 3 list of mesh vertex positions + // I #I vectorized list of polygon corner indices into rows of some matrix V + // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = size of + // the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the indices of + // the ith polygon + // corner_threshold threshold in degrees on sharp angles + // Outputs: + // N #polygons by 3 list of per face normals + // VV #I+#polygons by 3 list of auxiliary triangle mesh vertex positions + // FF #I by 3 list of triangle indices into rows of VV + // J #I list of indices into original polygons + template < + typename DerivedV, + typename DerivedI, + typename DerivedC, + typename DerivedN, + typename DerivedVV, + typename DerivedFF, + typename DerivedJ> + IGL_INLINE void per_face_normals( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & VV, + Eigen::PlainObjectBase & FF, + Eigen::PlainObjectBase & J); +} + +#ifndef IGL_STATIC_LIBRARY +# include "per_face_normals.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/per_vertex_attribute_smoothing.cpp b/vendor/libigl/include/igl/per_vertex_attribute_smoothing.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91021a3097656bec15ffa9df2993f2b963497479 --- /dev/null +++ b/vendor/libigl/include/igl/per_vertex_attribute_smoothing.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "per_vertex_attribute_smoothing.h" +#include + +template +IGL_INLINE void igl::per_vertex_attribute_smoothing( + const Eigen::MatrixBase& Ain, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & Aout) +{ + std::vector denominator(Ain.rows(), 0); + Aout = DerivedV::Zero(Ain.rows(), Ain.cols()); + for (int i = 0; i < F.rows(); ++i) { + for (int j = 0; j < 3; ++j) { + int j1 = (j + 1) % 3; + int j2 = (j + 2) % 3; + Aout.row(F(i, j)) += Ain.row(F(i, j1)) + Ain.row(F(i, j2)); + denominator[F(i, j)] += 2; + } + } + for (int i = 0; i < Ain.rows(); ++i) + Aout.row(i) /= denominator[i]; +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::per_vertex_attribute_smoothing, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/per_vertex_normals.cpp b/vendor/libigl/include/igl/per_vertex_normals.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a15f92317754618912edac191c69e33ec300bd42 --- /dev/null +++ b/vendor/libigl/include/igl/per_vertex_normals.cpp @@ -0,0 +1,139 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "per_vertex_normals.h" + +#include "get_seconds.h" +#include "per_face_normals.h" +#include "doublearea.h" +#include "parallel_for.h" +#include "internal_angles.h" + +template < + typename DerivedV, + typename DerivedF, + typename DerivedN> +IGL_INLINE void igl::per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const igl::PerVertexNormalsWeightingType weighting, + Eigen::PlainObjectBase & N) +{ + Eigen::Matrix PFN; + igl::per_face_normals(V,F,PFN); + return per_vertex_normals(V,F,weighting,PFN,N); +} + +template +IGL_INLINE void igl::per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & N) +{ + return per_vertex_normals(V,F,PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT,N); +} + +template +IGL_INLINE void igl::per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const igl::PerVertexNormalsWeightingType weighting, + const Eigen::MatrixBase& FN, + Eigen::PlainObjectBase & N) +{ + using namespace std; + // Resize for output + N.setZero(V.rows(),3); + + Eigen::Matrix + W(F.rows(),3); + switch(weighting) + { + case PER_VERTEX_NORMALS_WEIGHTING_TYPE_UNIFORM: + W.setConstant(1.); + break; + default: + assert(false && "Unknown weighting type"); + case PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT: + case PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA: + { + Eigen::Matrix A; + doublearea(V,F,A); + W = A.replicate(1,3); + break; + } + case PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE: + internal_angles(V,F,W); + break; + } + + // loop over faces + for(int i = 0;i NN; + //parallel_for( + // F.rows(), + // [&NN,&N](const size_t n){ NN.resize(n,DerivedN::Zero(N.rows(),3));}, + // [&F,&W,&FN,&NN,&critical](const int i, const size_t t) + // { + // // throw normal at each corner + // for(int j = 0; j < 3;j++) + // { + // // Q: Does this need to be critical? + // // A: Yes. Different (i,j)'s could produce the same F(i,j) + // NN[t].row(F(i,j)) += W(i,j) * FN.row(i); + // } + // }, + // [&N,&NN](const size_t t){ N += NN[t]; }, + // 1000l); + + // take average via normalization + N.rowwise().normalize(); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedN> +IGL_INLINE void igl::per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& FN, + Eigen::PlainObjectBase & N) +{ + return + per_vertex_normals(V,F,PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT,FN,N); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::PerVertexNormalsWeightingType, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::per_vertex_normals, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/per_vertex_normals.h b/vendor/libigl/include/igl/per_vertex_normals.h new file mode 100644 index 0000000000000000000000000000000000000000..be4ba04610019d0b7df180401ef2bf06eca8e837 --- /dev/null +++ b/vendor/libigl/include/igl/per_vertex_normals.h @@ -0,0 +1,80 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PER_VERTEX_NORMALS_H +#define IGL_PER_VERTEX_NORMALS_H +#include "igl_inline.h" +#include +// Note: It would be nice to support more or all of the methods here: +// "A comparison of algorithms for vertex normal computation" +namespace igl +{ + enum PerVertexNormalsWeightingType + { + // Incident face normals have uniform influence on vertex normal + PER_VERTEX_NORMALS_WEIGHTING_TYPE_UNIFORM = 0, + // Incident face normals are averaged weighted by area + PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA = 1, + // Incident face normals are averaged weighted by incident angle of vertex + PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE = 2, + // Area weights + PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT = 3, + NUM_PER_VERTEX_NORMALS_WEIGHTING_TYPE = 4 + }; + // Compute vertex normals via vertex position list, face list + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 3 eigne Matrix of face (triangle) indices + // weighting Weighting type + // Output: + // N #V by 3 eigen Matrix of mesh vertex 3D normals + template < + typename DerivedV, + typename DerivedF, + typename DerivedN> + IGL_INLINE void per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const igl::PerVertexNormalsWeightingType weighting, + Eigen::PlainObjectBase & N); + // Without weighting + template < + typename DerivedV, + typename DerivedF, + typename DerivedN> + IGL_INLINE void per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & N); + // Inputs: + // FN #F by 3 matrix of face (triangle) normals + template + IGL_INLINE void per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const PerVertexNormalsWeightingType weighting, + const Eigen::MatrixBase& FN, + Eigen::PlainObjectBase & N); + // Without weighting + template < + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedN> + IGL_INLINE void per_vertex_normals( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& FN, + Eigen::PlainObjectBase & N); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "per_vertex_normals.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/per_vertex_point_to_plane_quadrics.cpp b/vendor/libigl/include/igl/per_vertex_point_to_plane_quadrics.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4503873ca106c40f09a7fd9dd2314af7d2157092 --- /dev/null +++ b/vendor/libigl/include/igl/per_vertex_point_to_plane_quadrics.cpp @@ -0,0 +1,157 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "per_vertex_point_to_plane_quadrics.h" +#include "quadric_binary_plus_operator.h" +#include +#include +#include + + +IGL_INLINE void igl::per_vertex_point_to_plane_quadrics( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const Eigen::MatrixXi & EMAP, + const Eigen::MatrixXi & EF, + const Eigen::MatrixXi & EI, + std::vector< + std::tuple > & quadrics) +{ + using namespace std; + typedef std::tuple Quadric; + const int dim = V.cols(); + //// Quadrics per face + //std::vector face_quadrics(F.rows()); + // Initialize each vertex quadric to zeros + quadrics.resize( + V.rows(), + // gcc <=4.8 can't handle initializer lists correctly + Quadric{Eigen::MatrixXd::Zero(dim,dim),Eigen::RowVectorXd::Zero(dim),0}); + Eigen::MatrixXd I = Eigen::MatrixXd::Identity(dim,dim); + // Rather initial with zeros, initial with a small amount of energy pull + // toward original vertex position + const double w = 1e-10; + for(int v = 0;v(quadrics[v]) = w*I; + Eigen::RowVectorXd Vv = V.row(v); + std::get<1>(quadrics[v]) = w*-Vv; + std::get<2>(quadrics[v]) = w*Vv.dot(Vv); + } + // Generic nD qslim from "Simplifying Surfaces with Color and Texture + // using Quadric Error Metric" (follow up to original QSlim) + for(int f = 0;fQuadric + { + // Dimension of subspace + const int m = S.rows(); + // Weight face's quadric (v'*A*v + 2*b'*v + c) by area + // e1 and e2 should be perpendicular + Eigen::MatrixXd A = I; + Eigen::RowVectorXd b = -p; + double c = p.dot(p); + for(int i = 0;i edge opposite cth corner is boundary + // Boundary edge vector + const Eigen::RowVectorXd p = V.row(F(f,(infinite_corner+1)%3)); + Eigen::RowVectorXd ev = V.row(F(f,(infinite_corner+2)%3)) - p; + const double length = ev.norm(); + ev /= length; + // Face neighbor across boundary edge + int e = EMAP(f+F.rows()*infinite_corner); + int opp = EF(e,0) == f ? 1 : 0; + int n = EF(e,opp); + int nc = EI(e,opp); + assert( + ((F(f,(infinite_corner+1)%3) == F(n,(nc+1)%3) && + F(f,(infinite_corner+2)%3) == F(n,(nc+2)%3)) || + (F(f,(infinite_corner+1)%3) == F(n,(nc+2)%3) + && F(f,(infinite_corner+2)%3) == F(n,(nc+1)%3))) && + "Edge flaps not agreeing on shared edge"); + // Edge vector on opposite face + const Eigen::RowVectorXd eu = V.row(F(n,nc)) - p; + assert(!std::isinf(eu(0))); + // Matrix with vectors spanning plane as columns + Eigen::MatrixXd A(ev.size(),2); + A< qr(A); + const Eigen::MatrixXd Q = qr.householderQ(); + const Eigen::MatrixXd N = + Q.topRightCorner(ev.size(),ev.size()-2).transpose(); + assert(N.cols() == ev.size()); + assert(N.rows() == ev.size()-2); + Eigen::MatrixXd S(N.rows()+1,ev.size()); + S< +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PER_VERTEX_POINT_TO_PLANE_QUADRICS_H +#define IGL_PER_VERTEX_POINT_TO_PLANE_QUADRICS_H +#include "igl_inline.h" +#include +#include +#include +namespace igl +{ + // Compute quadrics per vertex of a "closed" triangle mesh (V,F). Rather than + // follow the qslim paper, this implements the lesser-known _follow up_ + // "Simplifying Surfaces with Color and Texture using Quadric Error Metrics". + // This allows V to be n-dimensional (where the extra coordiantes store + // texture UVs, color RGBs, etc. + // + // Inputs: + // V #V by n list of vertex positions. Assumes that vertices with + // infinite coordinates are "points at infinity" being used to close up + // boundary edges with faces. This allows special subspace quadrice for + // boundary edges: There should never be more than one "point at + // infinity" in a single triangle. + // F #F by 3 list of triangle indices into V + // E #E by 2 list of edge indices into V. + // EMAP #F*3 list of indices into E, mapping each directed edge to unique + // unique edge in E + // EF #E by 2 list of edge flaps, EF(e,0)=f means e=(i-->j) is the edge of + // F(f,:) opposite the vth corner, where EI(e,0)=v. Similarly EF(e,1) " + // e=(j->i) + // EI #E by 2 list of edge flap corners (see above). + // Outputs: + // quadrics #V list of quadrics, where a quadric is a tuple {A,b,c} such + // that the quadratic energy of moving this vertex to position x is + // given by x'Ax - 2b + c + // + IGL_INLINE void per_vertex_point_to_plane_quadrics( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const Eigen::MatrixXi & EMAP, + const Eigen::MatrixXi & EF, + const Eigen::MatrixXi & EI, + std::vector< + std::tuple > & quadrics); +} +#ifndef IGL_STATIC_LIBRARY +# include "per_vertex_point_to_plane_quadrics.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/piecewise_constant_winding_number.h b/vendor/libigl/include/igl/piecewise_constant_winding_number.h new file mode 100644 index 0000000000000000000000000000000000000000..ebbeb6e98b5954a54b7a56fc18e3106044f1715c --- /dev/null +++ b/vendor/libigl/include/igl/piecewise_constant_winding_number.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PIECEWISE_CONSTANT_WINDING_NUMBER_H +#define IGL_PIECEWISE_CONSTANT_WINDING_NUMBER_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // PIECEWISE_CONSTANT_WINDING_NUMBER Determine if a given mesh induces a + // piecewise constant winding number field: Is this mesh valid input to solid + // set operations. **Assumes** that `(V,F)` contains no self-intersections + // (including degeneracies and co-incidences). If there are co-planar and + // co-incident vertex placements, a mesh could _fail_ this combinatorial test + // but still induce a piecewise-constant winding number _geometrically_. For + // example, consider a hemisphere with boundary and then pinch the boundary + // "shut" along a line segment. The **_bullet-proof_** check is to first + // resolve all self-intersections in `(V,F) -> (SV,SF)` (i.e. what the + // `igl::copyleft::cgal::piecewise_constant_winding_number` overload does). + // + // Inputs: + // F #F by 3 list of triangle indices into some (abstract) list of + // vertices V + // uE #uE by 2 list of unique edges indices into V + // uE2E #uE list of lists of indices into directed edges (#F * 3) + // Returns true if the mesh _combinatorially_ induces a piecewise constant + // winding number field. + // + template < + typename DerivedF, + typename DeriveduE, + typename uE2EType> + IGL_INLINE bool piecewise_constant_winding_number( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& uE, + const std::vector >& uE2E); + template + IGL_INLINE bool piecewise_constant_winding_number( + const Eigen::MatrixBase& F); +} +#ifndef IGL_STATIC_LIBRARY +# include "piecewise_constant_winding_number.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/pinv.cpp b/vendor/libigl/include/igl/pinv.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e3b2ceebbbf233b0f566d8f176611dcf19515c18 --- /dev/null +++ b/vendor/libigl/include/igl/pinv.cpp @@ -0,0 +1,42 @@ +#include "pinv.h" +#include +#include +#include + +template +void igl::pinv( + const Eigen::MatrixBase & A, + typename DerivedA::Scalar tol, + Eigen::PlainObjectBase & X) +{ + Eigen::JacobiSVD svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV ); + typedef typename DerivedA::Scalar Scalar; + const Eigen::Matrix & U = svd.matrixU(); + const Eigen::Matrix & V = svd.matrixV(); + const Eigen::Matrix & S = svd.singularValues(); + if(tol < 0) + { + const Scalar smax = S.array().abs().maxCoeff(); + tol = + (Scalar)(std::max(A.rows(),A.cols())) * + (smax-std::nextafter(smax,std::numeric_limits::epsilon())); + } + const int rank = (S.array()>0).count(); + X = (V.leftCols(rank).array().rowwise() * + (1.0/S.head(rank).array()).transpose()).matrix()* + U.leftCols(rank).transpose(); +} + +template +void igl::pinv( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & X) +{ + return pinv(A,-1,X); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::pinv, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/pinv.h b/vendor/libigl/include/igl/pinv.h new file mode 100644 index 0000000000000000000000000000000000000000..12ccf3f29d36b81b8dae76f22966a5afc95a5d09 --- /dev/null +++ b/vendor/libigl/include/igl/pinv.h @@ -0,0 +1,33 @@ +#ifndef IGL_PINV_H +#define IGL_PINV_H +#include "igl_inline.h" +#include "deprecated.h" +#include +namespace igl +{ + // Compute the Moore-Penrose pseudoinverse + // + // Inputs: + // A m by n matrix + // tol tolerance (if negative then default is used) + // Outputs: + // X n by m matrix so that A*X*A = A and X*A*X = X and A*X = (A*X)' and + // (X*A) = (X*A)' + // + // Obsolete: Use Eigen::CompleteOrthogonalDecomposition + // .solve() or .pseudoinverse() instead. + template + IGL_DEPRECATED void pinv( + const Eigen::MatrixBase & A, + typename DerivedA::Scalar tol, + Eigen::PlainObjectBase & X); + // Wrapper using default tol + template + IGL_DEPRECATED void pinv( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & X); +} +#ifndef IGL_STATIC_LIBRARY +# include "pinv.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/planarize_quad_mesh.cpp b/vendor/libigl/include/igl/planarize_quad_mesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24687e9a744b0becd709b0bf3a9a1cc2d427f9c6 --- /dev/null +++ b/vendor/libigl/include/igl/planarize_quad_mesh.cpp @@ -0,0 +1,245 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "planarize_quad_mesh.h" +#include "quad_planarity.h" +#include +#include +#include + +namespace igl +{ + template + class PlanarizerShapeUp + { + protected: + // number of faces, number of vertices + long numV, numF; + // references to the input faces and vertices + const Eigen::MatrixBase &Vin; + const Eigen::MatrixBase &Fin; + + // vector consisting of the vertex positions stacked: [x;y;z;x;y;z...] + // vector consisting of a weight per face (currently all set to 1) + // vector consisting of the projected face vertices (might be different for the same vertex belonging to different faces) + Eigen::Matrix Vv, weightsSqrt, P; + + // Matrices as in the paper + // Q: lhs matrix + // Ni: matrix that subtracts the mean of a face from the 4 vertices of a face + Eigen::SparseMatrix Q, Ni; + Eigen::SimplicialLDLT > solver; + + int maxIter; + double threshold; + const int ni = 4; + + // Matrix assemblers + inline void assembleQ(); + inline void assembleP(); + inline void assembleNi(); + + // Selects out of Vv the 4 vertices belonging to face fi + inline void assembleSelector(int fi, + Eigen::SparseMatrix &S); + + + public: + // Init - assemble stacked vector and lhs matrix, factorize + inline PlanarizerShapeUp(const Eigen::MatrixBase &V_, + const Eigen::MatrixBase &F_, + const int maxIter_, + const double &threshold_); + // Planarization - output to Vout + inline void planarize(Eigen::PlainObjectBase &Vout); + }; +} + +//Implementation + +template +inline igl::PlanarizerShapeUp::PlanarizerShapeUp(const Eigen::MatrixBase &V_, + const Eigen::MatrixBase &F_, + const int maxIter_, + const double &threshold_): +numV(V_.rows()), +numF(F_.rows()), +Vin(V_), +Fin(F_), +weightsSqrt(Eigen::Matrix::Ones(numF,1)), +maxIter(maxIter_), +threshold(threshold_) +{ + // assemble stacked vertex position vector + Vv.setZero(3*numV,1); + for (int i =0;i +inline void igl::PlanarizerShapeUp::assembleQ() +{ + std::vector > tripletList; + + // assemble the Ni matrix + assembleNi(); + + for (int fi = 0; fi< numF; fi++) + { + Eigen::SparseMatrix Sfi; + assembleSelector(fi, Sfi); + + // the final matrix per face + Eigen::SparseMatrix Qi = weightsSqrt(fi)*Ni*Sfi; + // put it in the correct block of Q + // todo: this can be made faster by omitting the selector matrix + for (int k=0; k::InnerIterator it(Qi,k); it; ++it) + { + typename DerivedV::Scalar val = it.value(); + int row = it.row(); + int col = it.col(); + tripletList.push_back(Eigen::Triplet(row+3*ni*fi,col,val)); + } + } + + Q.resize(3*ni*numF,3*numV); + Q.setFromTriplets(tripletList.begin(), tripletList.end()); + // the actual lhs matrix is Q'*Q + // prefactor that matrix + solver.compute(Q.transpose()*Q); + if(solver.info()!=Eigen::Success) + { + std::cerr << "Cholesky failed - PlanarizerShapeUp.cpp" << std::endl; + assert(0); + } +} + +template +inline void igl::PlanarizerShapeUp::assembleNi() +{ + std::vector> tripletList; + for (int ii = 0; ii< ni; ii++) + { + for (int jj = 0; jj< ni; jj++) + { + tripletList.push_back(Eigen::Triplet(3*ii+0,3*jj+0,-1./ni)); + tripletList.push_back(Eigen::Triplet(3*ii+1,3*jj+1,-1./ni)); + tripletList.push_back(Eigen::Triplet(3*ii+2,3*jj+2,-1./ni)); + } + tripletList.push_back(Eigen::Triplet(3*ii+0,3*ii+0,1.)); + tripletList.push_back(Eigen::Triplet(3*ii+1,3*ii+1,1.)); + tripletList.push_back(Eigen::Triplet(3*ii+2,3*ii+2,1.)); + } + Ni.resize(3*ni,3*ni); + Ni.setFromTriplets(tripletList.begin(), tripletList.end()); +} + +//assumes V stacked [x;y;z;x;y;z...]; +template +inline void igl::PlanarizerShapeUp::assembleSelector(int fi, + Eigen::SparseMatrix &S) +{ + + std::vector> tripletList; + for (int fvi = 0; fvi< ni; fvi++) + { + int vi = Fin(fi,fvi); + tripletList.push_back(Eigen::Triplet(3*fvi+0,3*vi+0,1.)); + tripletList.push_back(Eigen::Triplet(3*fvi+1,3*vi+1,1.)); + tripletList.push_back(Eigen::Triplet(3*fvi+2,3*vi+2,1.)); + } + + S.resize(3*ni,3*numV); + S.setFromTriplets(tripletList.begin(), tripletList.end()); + +} + +//project all faces to their closest planar face +template +inline void igl::PlanarizerShapeUp::assembleP() +{ + P.setZero(3*ni*numF); + for (int fi = 0; fi< numF; fi++) + { + // todo: this can be made faster by omitting the selector matrix + Eigen::SparseMatrix Sfi; + assembleSelector(fi, Sfi); + Eigen::SparseMatrix NSi = Ni*Sfi; + + Eigen::Matrix Vi = NSi*Vv; + Eigen::Matrix CC(3,ni); + for (int i = 0; i C = CC*CC.transpose(); + + // Alec: Doesn't compile + Eigen::EigenSolver> es(C); + // the real() is for compilation purposes + Eigen::Matrix lambda = es.eigenvalues().real(); + Eigen::Matrix U = es.eigenvectors().real(); + int min_i; + lambda.cwiseAbs().minCoeff(&min_i); + U.col(min_i).setZero(); + Eigen::Matrix PP = U*U.transpose()*CC; + for (int i = 0; i +inline void igl::PlanarizerShapeUp::planarize(Eigen::PlainObjectBase &Vout) +{ + Eigen::Matrix planarity; + Vout = Vin; + + for (int iter =0; iter oldMean, newMean; + oldMean = Vin.colwise().mean(); + newMean = Vout.colwise().mean(); + Vout.rowwise() += (oldMean - newMean); + +}; + + + +template +IGL_INLINE void igl::planarize_quad_mesh(const Eigen::MatrixBase &Vin, + const Eigen::MatrixBase &Fin, + const int maxIter, + const double &threshold, + Eigen::PlainObjectBase &Vout) +{ + PlanarizerShapeUp planarizer(Vin, Fin, maxIter, threshold); + planarizer.planarize(Vout); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::planarize_quad_mesh, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, double const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/planarize_quad_mesh.h b/vendor/libigl/include/igl/planarize_quad_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..3d257da8a09b018043aa55e5a6b52ed1cc131f05 --- /dev/null +++ b/vendor/libigl/include/igl/planarize_quad_mesh.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PLANARIZE_QUAD_MESH_H +#define IGL_PLANARIZE_QUAD_MESH_H +#include "igl_inline.h" +#include +namespace igl +{ + // Planarizes a given quad mesh using the algorithm described in the paper + // "Shape-Up: Shaping Discrete Geometry with Projections" by S. Bouaziz, + // M. Deuss, Y. Schwartzburg, T. Weise, M. Pauly, Computer Graphics Forum, + // Volume 31, Issue 5, August 2012, p. 1657-1667 + // (http://dl.acm.org/citation.cfm?id=2346802). + // The algorithm iterates between projecting each quad to its closest planar + // counterpart and stitching those quads together via a least squares + // optimization. It stops whenever all quads' non-planarity is less than a + // given threshold (suggested value: 0.01), or a maximum number of iterations + // is reached. + + + // Inputs: + // Vin #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 4 eigen Matrix of face (quad) indices + // maxIter maximum numbers of iterations + // threshold minimum allowed threshold for non-planarity + // Output: + // Vout #V by 3 eigen Matrix of planar mesh vertex 3D positions + // + + template + IGL_INLINE void planarize_quad_mesh(const Eigen::MatrixBase &Vin, + const Eigen::MatrixBase &F, + const int maxIter, + const double &threshold, + Eigen::PlainObjectBase &Vout); +} +#ifndef IGL_STATIC_LIBRARY +# include "planarize_quad_mesh.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/point_in_circle.h b/vendor/libigl/include/igl/point_in_circle.h new file mode 100644 index 0000000000000000000000000000000000000000..f19344c405e3c0e58eddb17d499d763ddaf87293 --- /dev/null +++ b/vendor/libigl/include/igl/point_in_circle.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_POINT_IN_CIRCLE_H +#define IGL_POINT_IN_CIRCLE_H +#include "igl_inline.h" + +namespace igl +{ + // Determine if 2d point is in a circle + // Inputs: + // qx x-coordinate of query point + // qy y-coordinate of query point + // cx x-coordinate of circle center + // cy y-coordinate of circle center + // r radius of circle + // Returns true if query point is in circle, false otherwise + IGL_INLINE bool point_in_circle( + const double qx, + const double qy, + const double cx, + const double cy, + const double r); +} + +#ifndef IGL_STATIC_LIBRARY +# include "point_in_circle.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/polar_dec.h b/vendor/libigl/include/igl/polar_dec.h new file mode 100644 index 0000000000000000000000000000000000000000..2b995eabe1bd9ffaa3a7b98d4d3012c5fa7b83d1 --- /dev/null +++ b/vendor/libigl/include/igl/polar_dec.h @@ -0,0 +1,53 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_POLAR_DEC +#define IGL_POLAR_DEC +#include "igl_inline.h" +#include + +namespace igl +{ + // Computes the polar decomposition (R,T) of a matrix A + // Inputs: + // A 3 by 3 matrix to be decomposed + // Outputs: + // R 3 by 3 orthonormal matrix part of decomposition + // T 3 by 3 stretch matrix part of decomposition + // U 3 by 3 left-singular vectors + // S 3 by 1 singular values + // V 3 by 3 right-singular vectors + // + // + template < + typename DerivedA, + typename DerivedR, + typename DerivedT, + typename DerivedU, + typename DerivedS, + typename DerivedV> + IGL_INLINE void polar_dec( + const Eigen::PlainObjectBase & A, + Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & T, + Eigen::PlainObjectBase & U, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & V); + template < + typename DerivedA, + typename DerivedR, + typename DerivedT> + IGL_INLINE void polar_dec( + const Eigen::PlainObjectBase & A, + Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & T); +} +#ifndef IGL_STATIC_LIBRARY +# include "polar_dec.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/polar_svd.h b/vendor/libigl/include/igl/polar_svd.h new file mode 100644 index 0000000000000000000000000000000000000000..f0f38e7a120bec313c9130e018e4b20498f29d87 --- /dev/null +++ b/vendor/libigl/include/igl/polar_svd.h @@ -0,0 +1,54 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_POLAR_SVD +#define IGL_POLAR_SVD +#include "igl_inline.h" +#include + +namespace igl +{ + // Computes the polar decomposition (R,T) of a matrix A using SVD singular + // value decomposition + // + // Inputs: + // A 3 by 3 matrix to be decomposed + // Outputs: + // R 3 by 3 rotation matrix part of decomposition (**always rotataion**) + // T 3 by 3 stretch matrix part of decomposition + // U 3 by 3 left-singular vectors + // S 3 by 1 singular values + // V 3 by 3 right-singular vectors + // + // + template < + typename DerivedA, + typename DerivedR, + typename DerivedT, + typename DerivedU, + typename DerivedS, + typename DerivedV> + IGL_INLINE void polar_svd( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & T, + Eigen::PlainObjectBase & U, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & V); + template < + typename DerivedA, + typename DerivedR, + typename DerivedT> + IGL_INLINE void polar_svd( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & T); +} +#ifndef IGL_STATIC_LIBRARY +# include "polar_svd.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/polar_svd3x3.cpp b/vendor/libigl/include/igl/polar_svd3x3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54ffb590018f3b41ea363b00487983cf865263e6 --- /dev/null +++ b/vendor/libigl/include/igl/polar_svd3x3.cpp @@ -0,0 +1,94 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "polar_svd3x3.h" +#include "svd3x3.h" +#ifdef __SSE__ +# include "svd3x3_sse.h" +#endif +#ifdef __AVX__ +# include "svd3x3_avx.h" +#endif + +template +IGL_INLINE void igl::polar_svd3x3(const Mat& A, Mat& R) +{ + // should be caught at compile time, but just to be 150% sure: + assert(A.rows() == 3 && A.cols() == 3); + + Eigen::Matrix U, Vt; + Eigen::Matrix S; + svd3x3(A, U, S, Vt); + R = U * Vt.transpose(); +} + +#ifdef __SSE__ +template +IGL_INLINE void igl::polar_svd3x3_sse(const Eigen::Matrix& A, Eigen::Matrix &R) +{ + // should be caught at compile time, but just to be 150% sure: + assert(A.rows() == 3*4 && A.cols() == 3); + + Eigen::Matrix U, Vt; + Eigen::Matrix S; + svd3x3_sse(A, U, S, Vt); + + for (int k=0; k<4; k++) + { + R.block(3*k, 0, 3, 3) = U.block(3*k, 0, 3, 3) * Vt.block(3*k, 0, 3, 3).transpose(); + } + + //// test: + //for (int k=0; k<4; k++) + //{ + // Eigen::Matrix3f Apart = A.block(3*k, 0, 3, 3); + // Eigen::Matrix3f Rpart; + // polar_svd3x3(Apart, Rpart); + + // Eigen::Matrix3f Rpart_SSE = R.block(3*k, 0, 3, 3); + // Eigen::Matrix3f diff = Rpart - Rpart_SSE; + // float diffNorm = diff.norm(); + + // int hu = 1; + //} + //// eof test +} +#endif + +#ifdef __AVX__ +template +IGL_INLINE void igl::polar_svd3x3_avx(const Eigen::Matrix& A, Eigen::Matrix &R) +{ + // should be caught at compile time, but just to be 150% sure: + assert(A.rows() == 3*8 && A.cols() == 3); + + Eigen::Matrix U, Vt; + Eigen::Matrix S; + svd3x3_avx(A, U, S, Vt); + + for (int k=0; k<8; k++) + { + R.block(3*k, 0, 3, 3) = U.block(3*k, 0, 3, 3) * Vt.block(3*k, 0, 3, 3).transpose(); + } + +} +#endif + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::polar_svd3x3 >(Eigen::Matrix const&, Eigen::Matrix&); +template void igl::polar_svd3x3 >(Eigen::Matrix const &,Eigen::Matrix &); + +#ifdef __SSE__ +template void igl::polar_svd3x3_sse(Eigen::Matrix const&, Eigen::Matrix&); +#endif + +#ifdef __AVX__ +template void igl::polar_svd3x3_avx(Eigen::Matrix const&, Eigen::Matrix&); +#endif + +#endif diff --git a/vendor/libigl/include/igl/polar_svd3x3.h b/vendor/libigl/include/igl/polar_svd3x3.h new file mode 100644 index 0000000000000000000000000000000000000000..a579774e09549900867eb1f716942c75178835fc --- /dev/null +++ b/vendor/libigl/include/igl/polar_svd3x3.h @@ -0,0 +1,43 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_POLAR_SVD3X3_H +#define IGL_POLAR_SVD3X3_H +#include +#include "igl_inline.h" +namespace igl +{ + // Computes the closest rotation to input matrix A using specialized 3x3 SVD + // singular value decomposition (WunderSVD3x3) + // + // Inputs: + // A 3 by 3 matrix to be decomposed + // Outputs: + // R 3 by 3 closest element in SO(3) (closeness in terms of Frobenius + // metric) + // + // This means that det(R) = 1. Technically it's not polar decomposition + // which guarantees positive semidefinite stretch factor (at the cost of + // having det(R) = -1). "• The orthogonal factors U and V will be true + // rotation matrices..." [McAdams, Selle, Tamstorf, Teran, Sefakis 2011] + // + template + IGL_INLINE void polar_svd3x3(const Mat& A, Mat& R); + #ifdef __SSE__ + template + IGL_INLINE void polar_svd3x3_sse(const Eigen::Matrix& A, Eigen::Matrix &R); + #endif + #ifdef __AVX__ + template + IGL_INLINE void polar_svd3x3_avx(const Eigen::Matrix& A, Eigen::Matrix &R); + #endif +} +#ifndef IGL_STATIC_LIBRARY +# include "polar_svd3x3.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/polygon_corners.cpp b/vendor/libigl/include/igl/polygon_corners.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e090a9ca4945a7d4a5d9dcfd695cf089ddd6517d --- /dev/null +++ b/vendor/libigl/include/igl/polygon_corners.cpp @@ -0,0 +1,70 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "polygon_corners.h" + +template < + typename PType, + typename DerivedI, + typename DerivedC> +IGL_INLINE void igl::polygon_corners( + const std::vector > & P, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & C) +{ + typedef typename DerivedI::Scalar IType; + // JD: Honestly you could do a first loop over P, compute C, and then fill the + // entries of I directly. No need for guesses and push_back(), or the extra + // copy at the end. That would be more efficient. + std::vector vI;vI.reserve(P.size()*4); + C.resize(P.size()+1); + C(0) = 0; + for(size_t p = 0;p(vI.data(),vI.size()); +} + +template < + typename DerivedQ, + typename DerivedI, + typename DerivedC> +IGL_INLINE void igl::polygon_corners( + const Eigen::MatrixBase & Q, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & C) +{ + I.resize(Q.size()); + C.resize(Q.rows()+1); + Eigen::Index c = 0; + C(0) = 0; + for(Eigen::Index p = 0;p, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::polygon_corners, Eigen::Matrix >(std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/polygons_to_triangles.h b/vendor/libigl/include/igl/polygons_to_triangles.h new file mode 100644 index 0000000000000000000000000000000000000000..e3d240fd76375e1a0670bf06d93d8c6554767e9e --- /dev/null +++ b/vendor/libigl/include/igl/polygons_to_triangles.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_POLYGONS_TO_TRIANGLES_H +#define IGL_POLYGONS_TO_TRIANGLES_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Given a polygon mesh, trivially triangulate each polygon with a fan. This + // purely combinatorial triangulation will work well for convex/flat polygons + // and degrade otherwise. + // + // Inputs: + // I #I vectorized list of polygon corner indices into rows of some matrix V + // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = + // size of the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the + // indices of the ith polygon + // Outputs: + // F #F by 3 list of triangle indices into rows of V + // J #F list of indices into 0:#P-1 of corresponding polygon + // + template < + typename DerivedI, + typename DerivedC, + typename DerivedF, + typename DerivedJ> + IGL_INLINE void polygons_to_triangles( + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & J); +} + +#ifndef IGL_STATIC_LIBRARY +# include "polygons_to_triangles.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/principal_curvature.cpp b/vendor/libigl/include/igl/principal_curvature.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4839fd99e5127c2449aa00ce2d7a89bef300418 --- /dev/null +++ b/vendor/libigl/include/igl/principal_curvature.cpp @@ -0,0 +1,936 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "principal_curvature.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// Lib IGL includes +#include +#include +#include +#include +#include + +typedef enum +{ + SPHERE_SEARCH, + K_RING_SEARCH +} searchType; + +typedef enum +{ + AVERAGE, + PROJ_PLANE +} normalType; + +class CurvatureCalculator +{ +public: + /* Row number i represents the i-th vertex, whose columns are: + curv[i][0] : K1 + curv[i][1] : K2 + curvDir[i][0] : PD1 + curvDir[i][1] : PD2 + */ + std::vector< std::vector > curv; + std::vector< std::vector > curvDir; + bool curvatureComputed; + class Quadric + { + public: + + IGL_INLINE Quadric () + { + a() = b() = c() = d() = e() = 1.0; + } + + IGL_INLINE Quadric(double av, double bv, double cv, double dv, double ev) + { + a() = av; + b() = bv; + c() = cv; + d() = dv; + e() = ev; + } + + IGL_INLINE double& a() { return data[0];} + IGL_INLINE double& b() { return data[1];} + IGL_INLINE double& c() { return data[2];} + IGL_INLINE double& d() { return data[3];} + IGL_INLINE double& e() { return data[4];} + + double data[5]; + + IGL_INLINE double evaluate(double u, double v) + { + return a()*u*u + b()*u*v + c()*v*v + d()*u + e()*v; + } + + IGL_INLINE double du(double u, double v) + { + return 2.0*a()*u + b()*v + d(); + } + + IGL_INLINE double dv(double u, double v) + { + return 2.0*c()*v + b()*u + e(); + } + + IGL_INLINE double duv(double u, double v) + { + return b(); + } + + IGL_INLINE double duu(double u, double v) + { + return 2.0*a(); + } + + IGL_INLINE double dvv(double u, double v) + { + return 2.0*c(); + } + + + IGL_INLINE static Quadric fit(const std::vector &VV) + { + assert(VV.size() >= 5); + if (VV.size() < 5) + { + std::cerr << "ASSERT FAILED! fit function requires at least 5 points: Only " << VV.size() << " were given." << std::endl; + exit(0); + } + + Eigen::MatrixXd A(VV.size(),5); + Eigen::MatrixXd b(VV.size(),1); + Eigen::MatrixXd sol(5,1); + + for(unsigned int c=0; c < VV.size(); ++c) + { + double u = VV[c][0]; + double v = VV[c][1]; + double n = VV[c][2]; + + A(c,0) = u*u; + A(c,1) = u*v; + A(c,2) = v*v; + A(c,3) = u; + A(c,4) = v; + + b(c) = n; + } + + sol=A.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b); + + return Quadric(sol(0),sol(1),sol(2),sol(3),sol(4)); + } + }; + +public: + + Eigen::MatrixXd vertices; + // Face list of current mesh (#F x 3) or (#F x 4) + // The i-th row contains the indices of the vertices that forms the i-th face in ccw order + Eigen::MatrixXi faces; + + std::vector > vertex_to_vertices; + std::vector > vertex_to_faces; + std::vector > vertex_to_faces_index; + Eigen::MatrixXd face_normals; + Eigen::MatrixXd vertex_normals; + + /* Size of the neighborhood */ + double sphereRadius; + int kRing; + + bool localMode; /* Use local mode */ + bool projectionPlaneCheck; /* Check collected vertices on tangent plane */ + bool montecarlo; + unsigned int montecarloN; + + searchType st; /* Use either a sphere search or a k-ring search */ + normalType nt; + + double lastRadius; + double scaledRadius; + std::string lastMeshName; + + /* Benchmark related variables */ + bool expStep; /* True if we want the radius to increase exponentially */ + int step; /* If expStep==false, by how much rhe radius increases on every step */ + int maxSize; /* The maximum limit of the radius in the benchmark */ + + IGL_INLINE CurvatureCalculator(); + IGL_INLINE void init(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F); + + IGL_INLINE void finalEigenStuff(int, const std::vector&, Quadric&); + IGL_INLINE void fitQuadric(const Eigen::Vector3d&, const std::vector& ref, const std::vector& , Quadric *); + IGL_INLINE void applyProjOnPlane(const Eigen::Vector3d&, const std::vector&, std::vector&); + IGL_INLINE void getSphere(const int, const double, std::vector&, int min); + IGL_INLINE void getKRing(const int, const double,std::vector&); + IGL_INLINE Eigen::Vector3d project(const Eigen::Vector3d&, const Eigen::Vector3d&, const Eigen::Vector3d&); + IGL_INLINE void computeReferenceFrame(int, const Eigen::Vector3d&, std::vector&); + IGL_INLINE void getAverageNormal(int, const std::vector&, Eigen::Vector3d&); + IGL_INLINE void getProjPlane(int, const std::vector&, Eigen::Vector3d&); + IGL_INLINE void applyMontecarlo(const std::vector&,std::vector*); + IGL_INLINE void computeCurvature(); + IGL_INLINE void printCurvature(const std::string& outpath); + IGL_INLINE double getAverageEdge(); + + IGL_INLINE static int rotateForward (double *v0, double *v1, double *v2) + { + double t; + + if (std::abs(*v2) >= std::abs(*v1) && std::abs(*v2) >= std::abs(*v0)) + return 0; + + t = *v0; + *v0 = *v2; + *v2 = *v1; + *v1 = t; + + return 1 + rotateForward (v0, v1, v2); + } + + IGL_INLINE static void rotateBackward (int nr, double *v0, double *v1, double *v2) + { + double t; + + if (nr == 0) + return; + + t = *v2; + *v2 = *v0; + *v0 = *v1; + *v1 = t; + + rotateBackward (nr - 1, v0, v1, v2); + } + + IGL_INLINE static Eigen::Vector3d chooseMax (Eigen::Vector3d n, Eigen::Vector3d abc, double ab) + { + int max_i; + double max_sp; + Eigen::Vector3d nt[8]; + + n.normalize (); + abc.normalize (); + + max_sp = - std::numeric_limits::max(); + + for (int i = 0; i < 4; ++i) + { + nt[i] = n; + if (ab > 0) + { + switch (i) + { + case 0: + break; + + case 1: + nt[i][2] = -n[2]; + break; + + case 2: + nt[i][0] = -n[0]; + nt[i][1] = -n[1]; + break; + + case 3: + nt[i][0] = -n[0]; + nt[i][1] = -n[1]; + nt[i][2] = -n[2]; + break; + } + } + else + { + switch (i) + { + case 0: + nt[i][0] = -n[0]; + break; + + case 1: + nt[i][1] = -n[1]; + break; + + case 2: + nt[i][0] = -n[0]; + nt[i][2] = -n[2]; + break; + + case 3: + nt[i][1] = -n[1]; + nt[i][2] = -n[2]; + break; + } + } + + if (nt[i].dot(abc) > max_sp) + { + max_sp = nt[i].dot(abc); + max_i = i; + } + } + return nt[max_i]; + } + +}; + +class comparer +{ +public: + IGL_INLINE bool operator() (const std::pair& lhs, const std::pair&rhs) const + { + return lhs.second>rhs.second; + } +}; + +IGL_INLINE CurvatureCalculator::CurvatureCalculator() +{ + this->localMode=true; + this->projectionPlaneCheck=true; + this->sphereRadius=5; + this->st=SPHERE_SEARCH; + this->nt=AVERAGE; + this->montecarlo=false; + this->montecarloN=0; + this->kRing=3; + this->curvatureComputed=false; + this->expStep=true; +} + +IGL_INLINE void CurvatureCalculator::init(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) +{ + // Normalize vertices + vertices = V; + +// vertices = vertices.array() - vertices.minCoeff(); +// vertices = vertices.array() / vertices.maxCoeff(); +// vertices = vertices.array() * (1.0/igl::avg_edge_length(V,F)); + + faces = F; + igl::adjacency_list(F, vertex_to_vertices); + igl::vertex_triangle_adjacency(V, F, vertex_to_faces, vertex_to_faces_index); + igl::per_face_normals(V, F, face_normals); + igl::per_vertex_normals(V, F, face_normals, vertex_normals); +} + +IGL_INLINE void CurvatureCalculator::fitQuadric(const Eigen::Vector3d& v, const std::vector& ref, const std::vector& vv, Quadric *q) +{ + std::vector points; + points.reserve (vv.size()); + + for (unsigned int i = 0; i < vv.size(); ++i) { + + Eigen::Vector3d cp = vertices.row(vv[i]); + + // vtang non e` il v tangente!!! + Eigen::Vector3d vTang = cp - v; + + double x = vTang.dot(ref[0]); + double y = vTang.dot(ref[1]); + double z = vTang.dot(ref[2]); + points.push_back(Eigen::Vector3d (x,y,z)); + } + if (points.size() < 5) + { + std::cerr << "ASSERT FAILED! fit function requires at least 5 points: Only " << points.size() << " were given." << std::endl; + *q = Quadric(0,0,0,0,0); + } + else + { + *q = Quadric::fit (points); + } +} + +IGL_INLINE void CurvatureCalculator::finalEigenStuff(int i, const std::vector& ref, Quadric& q) +{ + + const double a = q.a(); + const double b = q.b(); + const double c = q.c(); + const double d = q.d(); + const double e = q.e(); + +// if (fabs(a) < 10e-8 || fabs(b) < 10e-8) +// { +// std::cout << "Degenerate quadric: " << i << std::endl; +// } + + double E = 1.0 + d*d; + double F = d*e; + double G = 1.0 + e*e; + + Eigen::Vector3d n = Eigen::Vector3d(-d,-e,1.0).normalized(); + + double L = 2.0 * a * n[2]; + double M = b * n[2]; + double N = 2 * c * n[2]; + + + // ----------------- Eigen stuff + Eigen::Matrix2d m; + m << L*G - M*F, M*E-L*F, M*E-L*F, N*E-M*F; + m = m / (E*G-F*F); + Eigen::SelfAdjointEigenSolver eig(m); + + Eigen::Vector2d c_val = eig.eigenvalues(); + Eigen::Matrix2d c_vec = eig.eigenvectors(); + + // std::cerr << "c_val:" << c_val << std::endl; + // std::cerr << "c_vec:" << c_vec << std::endl; + + // std::cerr << "c_vec:" << c_vec(0) << " " << c_vec(1) << std::endl; + + c_val = -c_val; + + Eigen::Vector3d v1, v2; + v1[0] = c_vec(0); + v1[1] = c_vec(1); + v1[2] = 0; //d * v1[0] + e * v1[1]; + + v2[0] = c_vec(2); + v2[1] = c_vec(3); + v2[2] = 0; //d * v2[0] + e * v2[1]; + + + // v1 = v1.normalized(); + // v2 = v2.normalized(); + + Eigen::Vector3d v1global = ref[0] * v1[0] + ref[1] * v1[1] + ref[2] * v1[2]; + Eigen::Vector3d v2global = ref[0] * v2[0] + ref[1] * v2[1] + ref[2] * v2[2]; + + v1global.normalize(); + v2global.normalize(); + + v1global *= c_val(0); + v2global *= c_val(1); + + if (c_val[0] > c_val[1]) + { + curv[i]=std::vector(2); + curv[i][0]=c_val(0); + curv[i][1]=c_val(1); + curvDir[i]=std::vector(2); + curvDir[i][0]=v1global; + curvDir[i][1]=v2global; + } + else + { + curv[i]=std::vector(2); + curv[i][0]=c_val(1); + curv[i][1]=c_val(0); + curvDir[i]=std::vector(2); + curvDir[i][0]=v2global; + curvDir[i][1]=v1global; + } + // ---- end Eigen stuff +} + +IGL_INLINE void CurvatureCalculator::getKRing(const int start, const double r, std::vector&vv) +{ + int bufsize=vertices.rows(); + vv.reserve(bufsize); + std::list > queue; + std::vector visited(bufsize, false); + queue.push_back(std::pair(start,0)); + visited[start]=true; + while (!queue.empty()) + { + int toVisit=queue.front().first; + int distance=queue.front().second; + queue.pop_front(); + vv.push_back(toVisit); + if (distance<(int)r) + { + for (unsigned int i=0; i (neighbor,distance+1)); + visited[neighbor]=true; + } + } + } + } +} + + +IGL_INLINE void CurvatureCalculator::getSphere(const int start, const double r, std::vector &vv, int min) +{ + int bufsize=vertices.rows(); + vv.reserve(bufsize); + std::list queue; + std::vector visited(bufsize, false); + queue.push_back(start); + visited[start]=true; + Eigen::Vector3d me=vertices.row(start); + std::priority_queue, std::vector >, comparer > extra_candidates; + while (!queue.empty()) + { + int toVisit=queue.front(); + queue.pop_front(); + vv.push_back(toVisit); + for (unsigned int i=0; i(neighbor,distance)); + visited[neighbor]=true; + } + } + } + while (!extra_candidates.empty() && (int)vv.size() cand=extra_candidates.top(); + extra_candidates.pop(); + vv.push_back(cand.first); + for (unsigned int i=0; i(neighbor,distance)); + visited[neighbor]=true; + } + } + } +} + +IGL_INLINE Eigen::Vector3d CurvatureCalculator::project(const Eigen::Vector3d& v, const Eigen::Vector3d& vp, const Eigen::Vector3d& ppn) +{ + return (vp - (ppn * ((vp - v).dot(ppn)))); +} + +IGL_INLINE void CurvatureCalculator::computeReferenceFrame(int i, const Eigen::Vector3d& normal, std::vector& ref ) +{ + + Eigen::Vector3d longest_v=Eigen::Vector3d(vertices.row(vertex_to_vertices[i][0])); + + longest_v=(project(vertices.row(i),longest_v,normal)-Eigen::Vector3d(vertices.row(i))).normalized(); + + /* L'ultimo asse si ottiene come prodotto vettoriale tra i due + * calcolati */ + Eigen::Vector3d y_axis=(normal.cross(longest_v)).normalized(); + ref[0]=longest_v; + ref[1]=y_axis; + ref[2]=normal; +} + +IGL_INLINE void CurvatureCalculator::getAverageNormal(int j, const std::vector& vv, Eigen::Vector3d& normal) +{ + normal=(vertex_normals.row(j)).normalized(); + if (localMode) + return; + + for (unsigned int i=0; i& vv, Eigen::Vector3d& ppn) +{ + int nr; + double a, b, c; + double nx, ny, nz; + double abcq; + + a = b = c = 0; + + if (localMode) + { + for (unsigned int i=0; i& vin, std::vector &vout) +{ + for (std::vector::const_iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) + if (vertex_normals.row(*vpi) * ppn > 0.0) + vout.push_back(*vpi); +} + +IGL_INLINE void CurvatureCalculator::applyMontecarlo(const std::vector& vin, std::vector *vout) +{ + if (montecarloN >= vin.size ()) + { + *vout = vin; + return; + } + + float p = ((float) montecarloN) / (float) vin.size(); + for (std::vector::const_iterator vpi = vin.begin(); vpi != vin.end(); ++vpi) + { + float r; + if ((r = ((float)rand () / RAND_MAX)) < p) + { + vout->push_back(*vpi); + } + } +} + +IGL_INLINE void CurvatureCalculator::computeCurvature() +{ + //CHECK che esista la mesh + const size_t vertices_count=vertices.rows(); + + if (vertices_count ==0) + return; + + curvDir=std::vector< std::vector >(vertices_count); + curv=std::vector >(vertices_count); + + + + scaledRadius=getAverageEdge()*sphereRadius; + + std::vector vv; + std::vector vvtmp; + Eigen::Vector3d normal; + + //double time_spent; + //double searchtime=0, ref_time=0, fit_time=0, final_time=0; + + for (size_t i=0; i= 6 && vvtmp.size() ref(3); + computeReferenceFrame(i,normal,ref); + + Quadric q; + fitQuadric (me, ref, vv, &q); + finalEigenStuff(i,ref,q); + } + + lastRadius=sphereRadius; + curvatureComputed=true; +} + +IGL_INLINE void CurvatureCalculator::printCurvature(const std::string& outpath) +{ + using namespace std; + if (!curvatureComputed) + return; + + std::ofstream of; + of.open(outpath.c_str()); + + if (!of) + { + fprintf(stderr, "Error: could not open output file %s\n", outpath.c_str()); + return; + } + + int vertices_count=vertices.rows(); + of << vertices_count << endl; + for (int i=0; i +IGL_INLINE void igl::principal_curvature( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& PD1, + Eigen::PlainObjectBase& PD2, + Eigen::PlainObjectBase& PV1, + Eigen::PlainObjectBase& PV2, + std::vector& bad_vertices, + unsigned radius, + bool useKring) +{ + + if (radius < 2) + { + radius = 2; + std::cout << "WARNING: igl::principal_curvature needs a radius >= 2, fixing it to 2." << std::endl; + } + + // Preallocate memory + PD1.resize(V.rows(),3); + PD2.resize(V.rows(),3); + + // Preallocate memory + PV1.resize(V.rows(),1); + PV2.resize(V.rows(),1); + + // Precomputation + CurvatureCalculator cc; + cc.init(V.template cast(),F.template cast()); + cc.sphereRadius = radius; + + if (useKring) + { + cc.kRing = radius; + cc.st = K_RING_SEARCH; + } + + // Compute + cc.computeCurvature(); + + // Copy it back + for (unsigned i=0; i 10e-6) + { + bad_vertices.push_back((Index)i); + + PD1.row(i) *= 0; + PD2.row(i) *= 0; + } + } else { + bad_vertices.push_back((Index)i); + + PV1(i) = 0; + PV2(i) = 0; + PD1.row(i) << 0,0,0; + PD2.row(i) << 0,0,0; + } + } + +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedPD1, + typename DerivedPD2, + typename DerivedPV1, + typename DerivedPV2> +IGL_INLINE void igl::principal_curvature( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& PD1, + Eigen::PlainObjectBase& PD2, + Eigen::PlainObjectBase& PV1, + Eigen::PlainObjectBase& PV2, + unsigned radius, + bool useKring) +{ + if (radius < 2) + { + radius = 2; + std::cout << "WARNING: igl::principal_curvature needs a radius >= 2, fixing it to 2." << std::endl; + } + + // Preallocate memory + PD1.resize(V.rows(),3); + PD2.resize(V.rows(),3); + + // Preallocate memory + PV1.resize(V.rows(),1); + PV2.resize(V.rows(),1); + + // Precomputation + CurvatureCalculator cc; + cc.init(V.template cast(),F.template cast()); + cc.sphereRadius = radius; + + if (useKring) + { + cc.kRing = radius; + cc.st = K_RING_SEARCH; + } + + // Compute + cc.computeCurvature(); + + // Copy it back + for (unsigned i=0; i 10e-6) + { + std::cerr << "PRINCIPAL_CURVATURE: Something is wrong with vertex: " << i << std::endl; + PD1.row(i) *= 0; + PD2.row(i) *= 0; + } + } + +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, unsigned int, bool); +template void igl::principal_curvature, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >&, unsigned int, bool); +#endif diff --git a/vendor/libigl/include/igl/principal_curvature.h b/vendor/libigl/include/igl/principal_curvature.h new file mode 100644 index 0000000000000000000000000000000000000000..d8b49b4b772ee769d909353c1141b89ed800e8a7 --- /dev/null +++ b/vendor/libigl/include/igl/principal_curvature.h @@ -0,0 +1,93 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PRINCIPAL_CURVATURE_H +#define IGL_PRINCIPAL_CURVATURE_H + + +#include +#include + +#include + +#include "igl_inline.h" +//#include +//#include + + + +namespace igl +{ + + // Compute the principal curvature directions and magnitude of the given triangle mesh + // DerivedV derived from vertex positions matrix type: i.e. MatrixXd + // DerivedF derived from face indices matrix type: i.e. MatrixXi + // Inputs: + // V eigen matrix #V by 3 + // F #F by 3 list of mesh faces (must be triangles) + // radius controls the size of the neighbourhood used, 1 = average edge length + // + // Outputs: + // PD1 #V by 3 maximal curvature direction for each vertex. + // PD2 #V by 3 minimal curvature direction for each vertex. + // PV1 #V by 1 maximal curvature value for each vertex. + // PV2 #V by 1 minimal curvature value for each vertex. + // + // Return value: + // Function returns vector of indices of bad vertices if any. + // + // See also: average_onto_faces, average_onto_vertices + // + // This function has been developed by: Nikolas De Giorgis, Luigi Rocca and Enrico Puppo. + // The algorithm is based on: + // Efficient Multi-scale Curvature and Crease Estimation + // Daniele Panozzo, Enrico Puppo, Luigi Rocca + // GraVisMa, 2010 +template < + typename DerivedV, + typename DerivedF, + typename DerivedPD1, + typename DerivedPD2, + typename DerivedPV1, + typename DerivedPV2> +IGL_INLINE void principal_curvature( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& PD1, + Eigen::PlainObjectBase& PD2, + Eigen::PlainObjectBase& PV1, + Eigen::PlainObjectBase& PV2, + unsigned radius = 5, + bool useKring = true); + +template < + typename DerivedV, + typename DerivedF, + typename DerivedPD1, + typename DerivedPD2, + typename DerivedPV1, + typename DerivedPV2, + typename Index> +IGL_INLINE void principal_curvature( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& PD1, + Eigen::PlainObjectBase& PD2, + Eigen::PlainObjectBase& PV1, + Eigen::PlainObjectBase& PV2, + std::vector& bad_vertices, + unsigned radius = 5, + bool useKring = true); + +} + + +#ifndef IGL_STATIC_LIBRARY +#include "principal_curvature.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/print_ijv.cpp b/vendor/libigl/include/igl/print_ijv.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38b1dd22a3bc8858e401b5aa432893a84df66f36 --- /dev/null +++ b/vendor/libigl/include/igl/print_ijv.cpp @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "print_ijv.h" + +#include "find.h" +#include + +template +IGL_INLINE void igl::print_ijv( + const Eigen::SparseMatrix& X, + const int offset) +{ + Eigen::Matrix I; + Eigen::Matrix J; + Eigen::Matrix V; + igl::find(X,I,J,V); + // Concatenate I,J,V + Eigen::Matrix IJV(I.size(),3); + IJV.col(0) = I.cast(); + IJV.col(1) = J.cast(); + IJV.col(2) = V; + // Offset + if(offset != 0) + { + IJV.col(0).array() += offset; + IJV.col(1).array() += offset; + } + std::cout<(Eigen::SparseMatrix const&, int); +#endif diff --git a/vendor/libigl/include/igl/print_ijv.h b/vendor/libigl/include/igl/print_ijv.h new file mode 100644 index 0000000000000000000000000000000000000000..e45c1a76cadfb035ca29a8266cd138282953d6de --- /dev/null +++ b/vendor/libigl/include/igl/print_ijv.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PRINT_IJV_H +#define IGL_PRINT_IJV_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +namespace igl +{ + // Prints a 3 column matrix representing [I,J,V] = find(X). That is, each + // row is the row index, column index and value for each non zero entry. Each + // row is printed on a new line + // + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Input: + // X m by n matrix whose entries are to be sorted + // offset optional offset for I and J indices {0} + template + IGL_INLINE void print_ijv( + const Eigen::SparseMatrix& X, + const int offset=0); +} + +#ifndef IGL_STATIC_LIBRARY +# include "print_ijv.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/print_vector.h b/vendor/libigl/include/igl/print_vector.h new file mode 100644 index 0000000000000000000000000000000000000000..ab2dd018c19c06bb35e5fc3ad2325ec9c8c6b1f7 --- /dev/null +++ b/vendor/libigl/include/igl/print_vector.h @@ -0,0 +1,29 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PRINT_VECTOR_H +#define IGL_PRINT_VECTOR_H +#include "igl_inline.h" + +#include +namespace igl +{ + // Not clear what these are supposed to be doing. Currently they print + // vectors to standard error... + template + IGL_INLINE void print_vector( std::vector& v); + template + IGL_INLINE void print_vector( std::vector< std::vector >& v); + template + IGL_INLINE void print_vector(std::vector< std::vector< std::vector > >& v); +} + +#ifndef IGL_STATIC_LIBRARY +# include "print_vector.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/procrustes.h b/vendor/libigl/include/igl/procrustes.h new file mode 100644 index 0000000000000000000000000000000000000000..8cacf2171a15859b3458c72bb35a1fe78c9dc064 --- /dev/null +++ b/vendor/libigl/include/igl/procrustes.h @@ -0,0 +1,137 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Stefan Brugger +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PROCRUSTES_H +#define IGL_PROCRUSTES_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Solve Procrustes problem in d dimensions. Given two point sets X,Y in R^d + // find best scale s, orthogonal R and translation t s.t. |s*X*R + t - Y|^2 + // is minimized. + // + // Templates: + // DerivedV point type + // Scalar scalar type + // DerivedR type of R + // DerivedT type of t + // Inputs: + // X #V by DIM first list of points + // Y #V by DIM second list of points + // includeScaling if scaling should be allowed + // includeReflections if R is allowed to be a reflection + // Outputs: + // scale scaling + // R orthogonal matrix + // t translation + // + // Example: + // MatrixXd X, Y; (containing 3d points as rows) + // double scale; + // MatrixXd R; + // VectorXd t; + // igl::procrustes(X,Y,true,false,scale,R,t); + // R *= scale; + // MatrixXd Xprime = (X * R).rowwise() + t.transpose(); + // + template < + typename DerivedX, + typename DerivedY, + typename Scalar, + typename DerivedR, + typename DerivedT> + IGL_INLINE void procrustes( + const Eigen::MatrixBase& X, + const Eigen::MatrixBase& Y, + bool includeScaling, + bool includeReflections, + Scalar& scale, + Eigen::PlainObjectBase& R, + Eigen::PlainObjectBase& t); + // Same as above but returns Eigen transformation object. + // + // Templates: + // DerivedV point type + // Scalar scalar type + // DIM point dimension + // TType type of transformation + // (Isometry,Affine,AffineCompact,Projective) + // Inputs: + // X #V by DIM first list of points + // Y #V by DIM second list of points + // includeScaling if scaling should be allowed + // includeReflections if R is allowed to be a reflection + // Outputs: + // T transformation that minimizes error + // + // Example: + // MatrixXd X, Y; (containing 3d points as rows) + // AffineCompact3d T; + // igl::procrustes(X,Y,true,false,T); + // MatrixXd Xprime = (X * T.linear()).rowwise() + T.translation().transpose(); + template < + typename DerivedX, + typename DerivedY, + typename Scalar, + int DIM, + int TType> + IGL_INLINE void procrustes( + const Eigen::MatrixBase& X, + const Eigen::MatrixBase& Y, + bool includeScaling, + bool includeReflections, + Eigen::Transform& T); + + + // Convenient wrapper that returns S=scale*R instead of scale and R separately + template < + typename DerivedX, + typename DerivedY, + typename DerivedR, + typename DerivedT> + IGL_INLINE void procrustes( + const Eigen::MatrixBase& X, + const Eigen::MatrixBase& Y, + bool includeScaling, + bool includeReflections, + Eigen::PlainObjectBase& S, + Eigen::PlainObjectBase& t); + + // Convenient wrapper for rigid case (no scaling, no reflections) + template < + typename DerivedX, + typename DerivedY, + typename DerivedR, + typename DerivedT> + IGL_INLINE void procrustes( + const Eigen::MatrixBase& X, + const Eigen::MatrixBase& Y, + Eigen::PlainObjectBase& R, + Eigen::PlainObjectBase& t); + + // Convenient wrapper for 2D case. + template < + typename DerivedX, + typename DerivedY, + typename Scalar, + typename DerivedT> + IGL_INLINE void procrustes( + const Eigen::MatrixBase& X, + const Eigen::MatrixBase& Y, + Eigen::Rotation2D& R, + Eigen::PlainObjectBase& t); +} + +#ifndef IGL_STATIC_LIBRARY + #include "procrustes.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/project.cpp b/vendor/libigl/include/igl/project.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5ce901f00bc18f4eb50a6f0031df1cbbc24402d5 --- /dev/null +++ b/vendor/libigl/include/igl/project.cpp @@ -0,0 +1,62 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "project.h" + +template +Eigen::Matrix igl::project( + const Eigen::Matrix& obj, + const Eigen::Matrix& model, + const Eigen::Matrix& proj, + const Eigen::Matrix& viewport) +{ + Eigen::Matrix tmp; + tmp << obj,1; + + tmp = model * tmp; + + tmp = proj * tmp; + + tmp = tmp.array() / tmp(3); + tmp = tmp.array() * 0.5f + 0.5f; + tmp(0) = tmp(0) * viewport(2) + viewport(0); + tmp(1) = tmp(1) * viewport(3) + viewport(1); + + return tmp.head(3); +} + +template +IGL_INLINE void igl::project( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + Eigen::PlainObjectBase & P) +{ + typedef typename DerivedP::Scalar PScalar; + Eigen::Matrix HV(V.rows(),4); + HV.leftCols(3) = V.template cast(); + HV.col(3).setConstant(1); + HV = (HV*model.template cast().transpose()* + proj.template cast().transpose()).eval(); + HV = (HV.array().colwise()/HV.col(3).array()).eval(); + HV = (HV.array() * 0.5 + 0.5).eval(); + HV.col(0) = (HV.array().col(0) * viewport(2) + viewport(0)).eval(); + HV.col(1) = (HV.array().col(1) * viewport(3) + viewport(1)).eval(); + P = HV.leftCols(3); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::project, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// Explicit template instantiation +template Eigen::Matrix igl::project(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); +template Eigen::Matrix igl::project(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); +template void igl::project, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix>(const Eigen::MatrixBase>&, const Eigen::MatrixBase>&, const Eigen::MatrixBase>&, const Eigen::MatrixBase>&, Eigen::PlainObjectBase>&); +template void igl::project, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix>(const Eigen::MatrixBase>&, const Eigen::MatrixBase>&, const Eigen::MatrixBase>&, const Eigen::MatrixBase>&, Eigen::PlainObjectBase>&); +template void igl::project, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::project, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/project.h b/vendor/libigl/include/igl/project.h new file mode 100644 index 0000000000000000000000000000000000000000..494636cb16985ec0d7c10addda826d2e3337fd25 --- /dev/null +++ b/vendor/libigl/include/igl/project.h @@ -0,0 +1,57 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PROJECT_H +#define IGL_PROJECT_H +#include "igl_inline.h" +#include +namespace igl +{ + // Eigen reimplementation of gluProject + // Inputs: + // obj* 3D objects' x, y, and z coordinates respectively + // model model matrix + // proj projection matrix + // viewport viewport vector + // Returns: + // screen space x, y, and z coordinates respectively + template + IGL_INLINE Eigen::Matrix project( + const Eigen::Matrix& obj, + const Eigen::Matrix& model, + const Eigen::Matrix& proj, + const Eigen::Matrix& viewport); + // Inputs: + // V #V by 3 list of object points + // model model matrix + // proj projection matrix + // viewport viewport vector + // Outputs: + // P #V by 3 list of screen space points + // + // Known issue: + // The compiler will not complain if V and P are Vector3d, but the result + // will be incorrect. + // + // Example: + // igl::opengl::glfw::Viewer vr; + // ... + // igl::project(V,vr.core().view,vr.core().proj,vr.core().viewport,P); + template + IGL_INLINE void project( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "project.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/project_isometrically_to_plane.cpp b/vendor/libigl/include/igl/project_isometrically_to_plane.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dcaa3a8d1c2e74c2062b41777a6e6b5572627a84 --- /dev/null +++ b/vendor/libigl/include/igl/project_isometrically_to_plane.cpp @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "project_isometrically_to_plane.h" +#include "edge_lengths.h" + +template < + typename DerivedV, + typename DerivedF, + typename DerivedU, + typename DerivedUF, + typename Scalar> +IGL_INLINE void igl::project_isometrically_to_plane( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & U, + Eigen::PlainObjectBase & UF, + Eigen::SparseMatrix& I) +{ + using namespace std; + using namespace Eigen; + assert(F.cols() == 3 && "F should contain triangles"); + typedef Eigen::Matrix MatrixX; + MatrixX l; + edge_lengths(V,F,l); + // Number of faces + const int m = F.rows(); + + // First corner at origin + U = DerivedU::Zero(m*3,2); + // Second corner along x-axis + U.block(m,0,m,1) = l.col(2); + // Third corner rotated onto plane + U.block(m*2,0,m,1) = + (-l.col(0).array().square() + + l.col(1).array().square() + + l.col(2).array().square())/(2.*l.col(2).array()); + U.block(m*2,1,m,1) = + (l.col(1).array().square()-U.block(m*2,0,m,1).array().square()).sqrt(); + + typedef Triplet IJV; + vector ijv; + ijv.reserve(3*m); + UF.resize(m,3); + for(int f = 0;f, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/project_to_line.h b/vendor/libigl/include/igl/project_to_line.h new file mode 100644 index 0000000000000000000000000000000000000000..d11399a76e945241e69a12cc8c4a78c117292f82 --- /dev/null +++ b/vendor/libigl/include/igl/project_to_line.h @@ -0,0 +1,83 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PROJECT_TO_LINE_H +#define IGL_PROJECT_TO_LINE_H +#include "igl_inline.h" +#include + +namespace igl +{ + // PROJECT_TO_LINE project points onto vectors, that is find the parameter + // t for a point p such that proj_p = (y-x).*t, additionally compute the + // squared distance from p to the line of the vector, such that + // |p - proj_p|² = sqr_d + // + // [T,sqrD] = project_to_line(P,S,D) + // + // Inputs: + // P #P by dim list of points to be projected + // S size dim start position of line vector + // D size dim destination position of line vector + // Outputs: + // T #P by 1 list of parameters + // sqrD #P by 1 list of squared distances + // + // + template < + typename DerivedP, + typename DerivedS, + typename DerivedD, + typename Derivedt, + typename DerivedsqrD> + IGL_INLINE void project_to_line( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & S, + const Eigen::MatrixBase & D, + Eigen::PlainObjectBase & t, + Eigen::PlainObjectBase & sqrD); + + // Same as above but for a single query point + template + IGL_INLINE void project_to_line( + const Scalar px, + const Scalar py, + const Scalar pz, + const Scalar sx, + const Scalar sy, + const Scalar sz, + const Scalar dx, + const Scalar dy, + const Scalar dz, + Scalar & projpx, + Scalar & projpy, + Scalar & projpz, + Scalar & t, + Scalar & sqrd); + + // Same as above but for a single query point + template + IGL_INLINE void project_to_line( + const Scalar px, + const Scalar py, + const Scalar pz, + const Scalar sx, + const Scalar sy, + const Scalar sz, + const Scalar dx, + const Scalar dy, + const Scalar dz, + Scalar & t, + Scalar & sqrd); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "project_to_line.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/project_to_line_segment.cpp b/vendor/libigl/include/igl/project_to_line_segment.cpp new file mode 100644 index 0000000000000000000000000000000000000000..71866fa33eede073bcfbcdd8fbf5814537e34b00 --- /dev/null +++ b/vendor/libigl/include/igl/project_to_line_segment.cpp @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "project_to_line_segment.h" +#include "project_to_line.h" +#include + +template < + typename DerivedP, + typename DerivedS, + typename DerivedD, + typename Derivedt, + typename DerivedsqrD> +IGL_INLINE void igl::project_to_line_segment( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & S, + const Eigen::MatrixBase & D, + Eigen::PlainObjectBase & t, + Eigen::PlainObjectBase & sqrD) +{ + project_to_line(P,S,D,t,sqrD); + const int np = P.rows(); + // loop over points and fix those that projected beyond endpoints +#pragma omp parallel for if (np>10000) + for(int p = 0;p1) + { + sqrD(p) = (Pp-D).squaredNorm(); + t(p) = 1; + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::project_to_line_segment, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::project_to_line_segment, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::project_to_line_segment, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::project_to_line_segment, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::project_to_line_segment, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/project_to_line_segment.h b/vendor/libigl/include/igl/project_to_line_segment.h new file mode 100644 index 0000000000000000000000000000000000000000..2fe33f2d402842b90d5a47a61710e5fd9ee1f80b --- /dev/null +++ b/vendor/libigl/include/igl/project_to_line_segment.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PROJECT_TO_LINE_SEGMENT_H +#define IGL_PROJECT_TO_LINE_SEGMENT_H +#include "igl_inline.h" +#include + +namespace igl +{ + // PROJECT_TO_LINE_SEGMENT project points onto vectors, that is find the parameter + // t for a point p such that proj_p = (y-x).*t, additionally compute the + // squared distance from p to the line of the vector, such that + // |p - proj_p|² = sqr_d + // + // [T,sqrD] = project_to_line_segment(P,S,D) + // + // Inputs: + // P #P by dim list of points to be projected + // S size dim start position of line vector + // D size dim destination position of line vector + // Outputs: + // T #P by 1 list of parameters + // sqrD #P by 1 list of squared distances + // + // + template < + typename DerivedP, + typename DerivedS, + typename DerivedD, + typename Derivedt, + typename DerivedsqrD> + IGL_INLINE void project_to_line_segment( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & S, + const Eigen::MatrixBase & D, + Eigen::PlainObjectBase & t, + Eigen::PlainObjectBase & sqrD); +} + +#ifndef IGL_STATIC_LIBRARY +# include "project_to_line_segment.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/projection_constraint.h b/vendor/libigl/include/igl/projection_constraint.h new file mode 100644 index 0000000000000000000000000000000000000000..4db366d1b5cd90c8bafd66225fffb8f6de23905b --- /dev/null +++ b/vendor/libigl/include/igl/projection_constraint.h @@ -0,0 +1,43 @@ +#ifndef IGL_PROJECTION_CONSTRAINT_H +#define IGL_PROJECTION_CONSTRAINT_H + +#include + +namespace igl +{ + // Construct two constraint equations of the form: + // + // A z = B + // + // with A 2x3 and B 2x1, where z is the 3d position of point in the scene, + // given the current projection matrix (e.g. gl_proj * gl_modelview), viewport + // (corner u/v and width/height) and screen space point x,y. Satisfying this + // equation means that z projects to screen space point (x,y). + // + // Inputs: + // UV 2-long uv-coordinates of screen space point + // M 4 by 4 projection matrix + // VP 4-long viewport: (corner_u, corner_v, width, height) + // Outputs: + // A 2 by 3 system matrix + // B 2 by 1 right-hand side + template < + typename DerivedUV, + typename DerivedM, + typename DerivedVP, + typename DerivedA, + typename DerivedB> + void projection_constraint( + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & M, + const Eigen::MatrixBase & VP, + Eigen::PlainObjectBase & A, + Eigen::PlainObjectBase & B); +} + +#ifndef IGL_STATIC_LIBRARY +# include "projection_constraint.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/pseudonormal_test.cpp b/vendor/libigl/include/igl/pseudonormal_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2708a52fec301f762f05d10c0e90ebd0bebe508e --- /dev/null +++ b/vendor/libigl/include/igl/pseudonormal_test.cpp @@ -0,0 +1,227 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "pseudonormal_test.h" +#include "barycentric_coordinates.h" +#include "doublearea.h" +#include "project_to_line_segment.h" +#include +template < + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedVN, + typename DerivedEN, + typename DerivedEMAP, + typename Derivedq, + typename Derivedc, + typename Scalar, + typename Derivedn> +IGL_INLINE void igl::pseudonormal_test( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & FN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & EMAP, + const Eigen::MatrixBase & q, + const int f, + Eigen::PlainObjectBase & c, + Scalar & s, + Eigen::PlainObjectBase & n) +{ + using namespace Eigen; + const auto & qc = q-c; + typedef Eigen::Matrix RowVector3S; + RowVector3S b; + // Using barycentric coorindates to determine whether close to a vertex/edge + // seems prone to error when dealing with nearly degenerate triangles: Even + // the barycenter (1/3,1/3,1/3) can be made arbitrarily close to an + // edge/vertex + // + const RowVector3S A = V.row(F(f,0)); + const RowVector3S B = V.row(F(f,1)); + const RowVector3S C = V.row(F(f,2)); + + const double area = [&A,&B,&C]() + { + Matrix area; + doublearea(A,B,C,area); + return area(0); + }(); + // These were chosen arbitrarily. In a floating point scenario, I'm not sure + // the best way to determine if c is on a vertex/edge or in the middle of the + // face: specifically, I'm worrying about degenerate triangles where + // barycentric coordinates are error-prone. + const double MIN_DOUBLE_AREA = 1e-4; + const double epsilon = 1e-12; + if(area>MIN_DOUBLE_AREA) + { + barycentric_coordinates( c,A,B,C,b); + // Determine which normal to use + const int type = (b.array()<=epsilon).template cast().sum(); + switch(type) + { + case 2: + // Find vertex + for(int x = 0;x<3;x++) + { + if(b(x)>epsilon) + { + n = VN.row(F(f,x)); + break; + } + } + break; + case 1: + // Find edge + for(int x = 0;x<3;x++) + { + if(b(x)<=epsilon) + { + n = EN.row(EMAP(F.rows()*x+f)); + break; + } + } + break; + default: + assert(false && "all barycentric coords zero."); + case 0: + n = FN.row(f); + break; + } + }else + { + // Check each vertex + bool found = false; + for(int v = 0;v<3 && !found;v++) + { + if( (c-V.row(F(f,v))).norm() < epsilon) + { + found = true; + n = VN.row(F(f,v)); + } + } + // Check each edge + for(int e = 0;e<3 && !found;e++) + { + const RowVector3S s = V.row(F(f,(e+1)%3)); + const RowVector3S d = V.row(F(f,(e+2)%3)); + Matrix sqr_d_j_x(1,1); + Matrix t(1,1); + project_to_line_segment(c,s,d,t,sqr_d_j_x); + if(sqrt(sqr_d_j_x(0)) < epsilon) + { + n = EN.row(EMAP(F.rows()*e+f)); + found = true; + } + } + // Finally just use face + if(!found) + { + n = FN.row(f); + } + } + s = (qc.dot(n) >= 0 ? 1. : -1.); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedEN, + typename DerivedVN, + typename Derivedq, + typename Derivedc, + typename Scalar, + typename Derivedn> +IGL_INLINE void igl::pseudonormal_test( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & q, + const int e, + Eigen::PlainObjectBase & c, + Scalar & s, + Eigen::PlainObjectBase & n) +{ + using namespace Eigen; + const auto & qc = q-c; + const double len = (V.row(E(e,1))-V.row(E(e,0))).norm(); + // barycentric coordinates + // this .head() nonsense is for "ridiculus" templates instantiations that AABB + // needs to compile + Eigen::Matrix + b((c-V.row(E(e,1))).norm()/len,(c-V.row(E(e,0))).norm()/len); + //b((c-V.row(E(e,1)).head(c.size())).norm()/len,(c-V.row(E(e,0)).head(c.size())).norm()/len); + // Determine which normal to use + const double epsilon = 1e-12; + const int type = (b.array()<=epsilon).template cast().sum(); + switch(type) + { + case 1: + // Find vertex + for(int x = 0;x<2;x++) + { + if(b(x)>epsilon) + { + n = VN.row(E(e,x)).head(2); + break; + } + } + break; + default: + assert(false && "all barycentric coords zero."); + case 0: + n = EN.row(e).head(2); + break; + } + s = (qc.dot(n) >= 0 ? 1. : -1.); +} + +// This is a bullshit template because AABB annoyingly needs templates for bad +// combinations of 3D V with DIM=2 AABB +// +// _Define_ as a no-op rather than monkeying around with the proper code above +namespace igl +{ + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&) {assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&){assert(false);}; + template <> IGL_INLINE void pseudonormal_test(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&){assert(false);}; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +// NEW +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +// OLD +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Block, 1, -1, false>, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase, 1, -1, false> > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, float&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +template void igl::pseudonormal_test, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, double&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/pseudonormal_test.h b/vendor/libigl/include/igl/pseudonormal_test.h new file mode 100644 index 0000000000000000000000000000000000000000..fc07946fbfc48f6afc03de3f436e6c510c1c087d --- /dev/null +++ b/vendor/libigl/include/igl/pseudonormal_test.h @@ -0,0 +1,78 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_PSEUDONORMAL_TEST_H +#define IGL_PSEUDONORMAL_TEST_H +#include "igl_inline.h" +#include +namespace igl +{ + // Given a mesh (V,F), a query point q, and a point on (V,F) c, determine + // whether q is inside (V,F) --> s=-1 or outside (V,F) s=1, based on the + // sign of the dot product between (q-c) and n, where n is the normal _at c_, + // carefully chosen according to [Bærentzen & Aanæs 2005] + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices + // FN #F by 3 list of triangle normals + // VN #V by 3 list of vertex normals (ANGLE WEIGHTING) + // EN #E by 3 list of edge normals (UNIFORM WEIGHTING) + // EMAP #F*3 mapping edges in F to E + // q Query point + // f index into F to face to which c belongs + // c Point on (V,F) + // Outputs: + // s sign + // n normal + template < + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedVN, + typename DerivedEN, + typename DerivedEMAP, + typename Derivedq, + typename Derivedc, + typename Scalar, + typename Derivedn> + IGL_INLINE void pseudonormal_test( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & FN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & EMAP, + const Eigen::MatrixBase & q, + const int f, + Eigen::PlainObjectBase & c, + Scalar & s, + Eigen::PlainObjectBase & n); + template < + typename DerivedV, + typename DerivedF, + typename DerivedEN, + typename DerivedVN, + typename Derivedq, + typename Derivedc, + typename Scalar, + typename Derivedn> + IGL_INLINE void pseudonormal_test( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & q, + const int e, + Eigen::PlainObjectBase & c, + Scalar & s, + Eigen::PlainObjectBase & n); +} +#ifndef IGL_STATIC_LIBRARY +# include "pseudonormal_test.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/pso.h b/vendor/libigl/include/igl/pso.h new file mode 100644 index 0000000000000000000000000000000000000000..d2a2ccdffaf741b7199238c7db79ad314080c9a1 --- /dev/null +++ b/vendor/libigl/include/igl/pso.h @@ -0,0 +1,59 @@ +#ifndef IGL_PSO_H +#define IGL_PSO_H +#include +#include +#include + +namespace igl +{ + // Solve the problem: + // + // minimize f(x) + // subject to lb ≤ x ≤ ub + // + // by particle swarm optimization (PSO). + // + // Inputs: + // f function that evaluates the objective for a given "particle" location + // LB #X vector of lower bounds + // UB #X vector of upper bounds + // max_iters maximum number of iterations + // population number of particles in swarm + // Outputs: + // X best particle seen so far + // Returns objective corresponding to best particle seen so far + template < + typename Scalar, + typename DerivedX, + typename DerivedLB, + typename DerivedUB> + IGL_INLINE Scalar pso( + const std::function< Scalar (DerivedX &) > f, + const Eigen::MatrixBase & LB, + const Eigen::MatrixBase & UB, + const int max_iters, + const int population, + DerivedX & X); + // Inputs: + // P whether each DOF is periodic + template < + typename Scalar, + typename DerivedX, + typename DerivedLB, + typename DerivedUB, + typename DerivedP> + IGL_INLINE Scalar pso( + const std::function< Scalar (DerivedX &) > f, + const Eigen::MatrixBase & LB, + const Eigen::MatrixBase & UB, + const Eigen::DenseBase & P, + const int max_iters, + const int population, + DerivedX & X); +} + +#ifndef IGL_STATIC_LIBRARY +# include "pso.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/qslim.cpp b/vendor/libigl/include/igl/qslim.cpp new file mode 100644 index 0000000000000000000000000000000000000000..62195437ccb16c01230d14f2d664800d5230141f --- /dev/null +++ b/vendor/libigl/include/igl/qslim.cpp @@ -0,0 +1,84 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "qslim.h" + +#include "collapse_edge.h" +#include "connect_boundary_to_infinity.h" +#include "decimate.h" +#include "edge_flaps.h" +#include "is_edge_manifold.h" +#include "max_faces_stopping_condition.h" +#include "per_vertex_point_to_plane_quadrics.h" +#include "qslim_optimal_collapse_edge_callbacks.h" +#include "quadric_binary_plus_operator.h" +#include "remove_unreferenced.h" +#include "slice.h" +#include "slice_mask.h" + +IGL_INLINE bool igl::qslim( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const size_t max_m, + Eigen::MatrixXd & U, + Eigen::MatrixXi & G, + Eigen::VectorXi & J, + Eigen::VectorXi & I) +{ + using namespace igl; + + // Original number of faces + const int orig_m = F.rows(); + // Tracking number of faces + int m = F.rows(); + typedef Eigen::MatrixXd DerivedV; + typedef Eigen::MatrixXi DerivedF; + DerivedV VO; + DerivedF FO; + igl::connect_boundary_to_infinity(V,F,VO,FO); + // decimate will not work correctly on non-edge-manifold meshes. By extension + // this includes meshes with non-manifold vertices on the boundary since these + // will create a non-manifold edge when connected to infinity. + if(!is_edge_manifold(FO)) + { + return false; + } + Eigen::VectorXi EMAP; + Eigen::MatrixXi E,EF,EI; + edge_flaps(FO,E,EMAP,EF,EI); + // Quadrics per vertex + typedef std::tuple Quadric; + std::vector quadrics; + per_vertex_point_to_plane_quadrics(VO,FO,EMAP,EF,EI,quadrics); + // State variables keeping track of edge we just collapsed + int v1 = -1; + int v2 = -1; + // Callbacks for computing and updating metric + decimate_cost_and_placement_callback cost_and_placement; + decimate_pre_collapse_callback pre_collapse; + decimate_post_collapse_callback post_collapse; + qslim_optimal_collapse_edge_callbacks( + E,quadrics,v1,v2, cost_and_placement, pre_collapse,post_collapse); + // Call to greedy decimator + bool ret = decimate( + VO, FO, + cost_and_placement, + max_faces_stopping_condition(m,orig_m,max_m), + pre_collapse, + post_collapse, + E, EMAP, EF, EI, + U, G, J, I); + // Remove phony boundary faces and clean up + const Eigen::Array keep = (J.array() +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QSLIM_OPTIMAL_COLLAPSE_EDGE_CALLBACKS_H +#define IGL_QSLIM_OPTIMAL_COLLAPSE_EDGE_CALLBACKS_H +#include "igl_inline.h" +#include "decimate_callback_types.h" +#include +#include +#include +#include +#include +namespace igl +{ + // Prepare callbacks for decimating edges using the qslim optimal placement + // metric. + // + // Inputs: + // E #E by 2 list of working edges + // quadrics reference to list of working per vertex quadrics + // v1 working variable to maintain end point of collapsed edge + // v2 working variable to maintain end point of collapsed edge + // Outputs + // cost_and_placement callback for evaluating cost of edge collapse and + // determining placement of vertex (see collapse_edge) + // pre_collapse callback before edge collapse (see collapse_edge) + // post_collapse callback after edge collapse (see collapse_edge) + IGL_INLINE void qslim_optimal_collapse_edge_callbacks( + Eigen::MatrixXi & E, + std::vector > & + quadrics, + int & v1, + int & v2, + decimate_cost_and_placement_callback & cost_and_placement, + decimate_pre_collapse_callback & pre_collapse, + decimate_post_collapse_callback & post_collapse); +} +#ifndef IGL_STATIC_LIBRARY +# include "qslim_optimal_collapse_edge_callbacks.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/quad_grid.h b/vendor/libigl/include/igl/quad_grid.h new file mode 100644 index 0000000000000000000000000000000000000000..db9592e4d75fed4e426eb78fa40d9f85d493f7d9 --- /dev/null +++ b/vendor/libigl/include/igl/quad_grid.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2019 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUAD_GRID_H +#define IGL_QUAD_GRID_H + +#include +#include + +namespace igl +{ + // Generate a quad mesh over a regular grid. + // + // Inputs: + // nx number of vertices in the x direction + // ny number of vertices in the y direction + // Outputs: + // V nx*ny by 2 list of vertex positions + // Q (nx-1)*(ny-1) by 4 list of quad indices into V + // E (nx-1)*ny+(ny-1)*nx by 2 list of undirected quad edge indices into V + // + // See also: grid, triangulated_grid + template< + typename DerivedV, + typename DerivedQ, + typename DerivedE> + IGL_INLINE void quad_grid( + const int nx, + const int ny, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & Q, + Eigen::PlainObjectBase & E); + template< + typename DerivedQ, + typename DerivedE> + IGL_INLINE void quad_grid( + const int nx, + const int ny, + Eigen::PlainObjectBase & Q, + Eigen::PlainObjectBase & E); +} + +#ifndef IGL_STATIC_LIBRARY +# include "quad_grid.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/quad_planarity.h b/vendor/libigl/include/igl/quad_planarity.h new file mode 100644 index 0000000000000000000000000000000000000000..b6a535c7b37bafb3bd26caa3767a286c63537418 --- /dev/null +++ b/vendor/libigl/include/igl/quad_planarity.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUAD_PLANARITY_H +#define IGL_QUAD_PLANARITY_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute planarity of the faces of a quad mesh + // Inputs: + // V #V by 3 eigen Matrix of mesh vertex 3D positions + // F #F by 4 eigen Matrix of face (quad) indices + // Output: + // P #F by 1 eigen Matrix of mesh face (quad) planarities + // + template + IGL_INLINE void quad_planarity( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "quad_planarity.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/quadprog.cpp b/vendor/libigl/include/igl/quadprog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa0d82b343780f827b7bef87027edb7c4f7450d1 --- /dev/null +++ b/vendor/libigl/include/igl/quadprog.cpp @@ -0,0 +1,123 @@ +#include "quadprog.h" +#include "min_quad_with_fixed.h" +#include + +template +IGL_INLINE Eigen::Matrix igl::quadprog( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Matrix & A, + const Eigen::Matrix & b, + const Eigen::Matrix & lb, + const Eigen::Matrix & ub) +{ + // Alec 16/2/2021: + // igl::quadprog implements a very simple primal active set method. The new + // igl::min_quad_with_fixed is very fast for small dense problems so the + // iterations of igl::quadprog become very fast. Even if it ends up doing many + // more iterations than igl::copyleft::quadprog it would be much faster (in + // reality it doesn't do that many more iterations). It's a healthy 10-100x + // faster than igl::copyleft::quadprog for specific cases of QPs. + // + // Unfortunately, that set is limited. igl::quadprog is really good at tiny + // box-constrained QPs with a positive definite objective (like the kind that show + // up in dual contouring). igl::copyleft::quadprog handles more general problems + // (and also starts to beat igl::quadprog when the number of variables gets over + // ~20). I tried extending igl::quadprog so that we could use it for + // igl::copyleft::progressive_hulls and drop igl::copyleft::quadprog but it was + // trickier than I thought. Something like qpmad or the non GPL version of + // quadrog++ would be good future PR. + // + typedef Eigen::Matrix VectorSn; + typedef Eigen::Array Arraybn; + assert( (lb.array() < ub.array() ).all() ); + const int dyn_n = n == Eigen::Dynamic ? H.rows() : n; + VectorSn x(dyn_n); + VectorSn bc = VectorSn::Constant(dyn_n,1,-1e26); + Arraybn k = Arraybn::Constant(dyn_n,1,false); + Eigen::Index iter; + // n³ is probably way too conservative. + for(iter = 0;iter(H,f,k,bc,A,b); + // constraint violations + VectorSn vl = lb-x; + VectorSn vu = x-ub; + + // try to add/remove constraints + Eigen::Index best_add = -1; Scalar worst_offense = 0; + bool add_lower; + Eigen::Index best_remove = -1; Scalar worst_lambda = 0; + for(Eigen::Index i = 0;iworst_offense) + { + best_add = i; + add_lower = true; + worst_offense = vl(i); + } + if(vu(i)>worst_offense) + { + best_add = i; + add_lower = false; + worst_offense = vu(i); + } + // bias toward adding constraints + if(best_add<0 && k(i)) + { + const Scalar sign = bc(i)==ub(i)?1:-1; + const Scalar lambda_i = sign * (H.row(i)*x+f(i)); + if(lambda_i > worst_lambda) + { + best_remove = i; + worst_lambda = lambda_i; + } + } + } + // bias toward adding constraints + if(best_add >= 0) + { + const auto i = best_add; + assert(!k(i)); + bc(i) = add_lower ? lb(i) : ub(i); + k(i) = true; + }else if(best_remove >= 0) + { + const auto i = best_remove; + assert(k(i)); + k(i) = false; + }else /*if(best_add < 0 && best_remove < 0)*/ + { + return x; + } + } + // Should never happen. + assert(false && "quadprog failed after too many iterations"); + return VectorSn::Zero(dyn_n); +} + +template +IGL_INLINE Eigen::Matrix igl::quadprog( + const Eigen::Matrix & H, + const Eigen::Matrix & f, + const Eigen::Matrix & lb, + const Eigen::Matrix & ub) +{ + const int m = n == Eigen::Dynamic ? Eigen::Dynamic : 0; + // Windows needs template parameters spelled out + return quadprog( + H,f, + Eigen::Matrix(0,H.cols()), + Eigen::Matrix(0,1), + lb,ub); +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template Eigen::Matrix igl::quadprog(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); +template Eigen::Matrix igl::quadprog(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); +#endif diff --git a/vendor/libigl/include/igl/quadric_binary_plus_operator.cpp b/vendor/libigl/include/igl/quadric_binary_plus_operator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb3fd695e2a29c584094f7bf0fb32a74d7bb8963 --- /dev/null +++ b/vendor/libigl/include/igl/quadric_binary_plus_operator.cpp @@ -0,0 +1,24 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "quadric_binary_plus_operator.h" + +IGL_INLINE std::tuple< Eigen::MatrixXd, Eigen::RowVectorXd, double> + igl::operator+( + const std::tuple< Eigen::MatrixXd, Eigen::RowVectorXd, double> & a, + const std::tuple< Eigen::MatrixXd, Eigen::RowVectorXd, double> & b) +{ + std::tuple< + Eigen::MatrixXd, + Eigen::RowVectorXd, + double> c; + std::get<0>(c) = (std::get<0>(a) + std::get<0>(b)).eval(); + std::get<1>(c) = (std::get<1>(a) + std::get<1>(b)).eval(); + std::get<2>(c) = (std::get<2>(a) + std::get<2>(b)); + return c; +} + diff --git a/vendor/libigl/include/igl/quadric_binary_plus_operator.h b/vendor/libigl/include/igl/quadric_binary_plus_operator.h new file mode 100644 index 0000000000000000000000000000000000000000..3c6b845d80504217b8720379611226448301e8cd --- /dev/null +++ b/vendor/libigl/include/igl/quadric_binary_plus_operator.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUADRIC_BINARY_PLUS_OPERATOR_H +#define IGL_QUADRIC_BINARY_PLUS_OPERATOR_H +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // A binary addition operator for Quadric tuples compatible with qslim, + // computing c = a+b + // + // Inputs: + // a QSlim quadric + // b QSlim quadric + // Output + // c QSlim quadric + // + IGL_INLINE std::tuple< Eigen::MatrixXd, Eigen::RowVectorXd, double> + operator+( + const std::tuple< Eigen::MatrixXd, Eigen::RowVectorXd, double> & a, + const std::tuple< Eigen::MatrixXd, Eigen::RowVectorXd, double> & b); +} + +#ifndef IGL_STATIC_LIBRARY +# include "quadric_binary_plus_operator.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/quat_conjugate.cpp b/vendor/libigl/include/igl/quat_conjugate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5856ea72d483e94e0fac213a853757441eaea8ef --- /dev/null +++ b/vendor/libigl/include/igl/quat_conjugate.cpp @@ -0,0 +1,27 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "quat_conjugate.h" + +template +IGL_INLINE void igl::quat_conjugate( + const Q_type *q1, + Q_type *out) +{ + out[0] = -q1[0]; + out[1] = -q1[1]; + out[2] = -q1[2]; + out[3] = q1[3]; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::quat_conjugate(double const*, double*); +// generated by autoexplicit.sh +template void igl::quat_conjugate(float const*, float*); +#endif diff --git a/vendor/libigl/include/igl/quat_conjugate.h b/vendor/libigl/include/igl/quat_conjugate.h new file mode 100644 index 0000000000000000000000000000000000000000..32ccb3b5b2da9576e3019335a5c7f4849cdfe54f --- /dev/null +++ b/vendor/libigl/include/igl/quat_conjugate.h @@ -0,0 +1,32 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUAT_CONJUGATE_H +#define IGL_QUAT_CONJUGATE_H +#include "igl_inline.h" + +namespace igl +{ + // Compute conjugate of given quaternion + // http://en.wikipedia.org/wiki/Quaternion#Conjugation.2C_the_norm.2C_and_reciprocal + // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), + // such that q = x*i + y*j + z*k + w + // Inputs: + // q1 input quaternion + // Outputs: + // out result of conjugation, allowed to be same as input + template + IGL_INLINE void quat_conjugate( + const Q_type *q1, + Q_type *out); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "quat_conjugate.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/quat_mult.cpp b/vendor/libigl/include/igl/quat_mult.cpp new file mode 100644 index 0000000000000000000000000000000000000000..beb7baba5db00690a5758080c7ed661ec620cd72 --- /dev/null +++ b/vendor/libigl/include/igl/quat_mult.cpp @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "quat_mult.h" + +#include +// http://www.antisphere.com/Wiki/tools:anttweakbar +template +IGL_INLINE void igl::quat_mult( + const Q_type *q1, + const Q_type *q2, + Q_type *out) +{ + // output can't be either of the inputs + assert(q1 != out); + assert(q2 != out); + + out[0] = q1[3]*q2[0] + q1[0]*q2[3] + q1[1]*q2[2] - q1[2]*q2[1]; + out[1] = q1[3]*q2[1] + q1[1]*q2[3] + q1[2]*q2[0] - q1[0]*q2[2]; + out[2] = q1[3]*q2[2] + q1[2]*q2[3] + q1[0]*q2[1] - q1[1]*q2[0]; + out[3] = q1[3]*q2[3] - (q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2]); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::quat_mult(double const*, double const*, double*); +// generated by autoexplicit.sh +template void igl::quat_mult(float const*, float const*, float*); +#endif diff --git a/vendor/libigl/include/igl/quat_mult.h b/vendor/libigl/include/igl/quat_mult.h new file mode 100644 index 0000000000000000000000000000000000000000..4a7ba654f458b146175c02d54e5fc88103c4726d --- /dev/null +++ b/vendor/libigl/include/igl/quat_mult.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUAT_MULT_H +#define IGL_QUAT_MULT_H +#include "igl_inline.h" + +namespace igl +{ + // Computes out = q1 * q2 with quaternion multiplication + // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), + // such that q = x*i + y*j + z*k + w + // Inputs: + // q1 left quaternion + // q2 right quaternion + // Outputs: + // out result of multiplication + template + IGL_INLINE void quat_mult( + const Q_type *q1, + const Q_type *q2, + Q_type *out); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "quat_mult.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/quat_to_axis_angle.h b/vendor/libigl/include/igl/quat_to_axis_angle.h new file mode 100644 index 0000000000000000000000000000000000000000..77ea10e5c435e30a60c9d7fd260f2af3a3777650 --- /dev/null +++ b/vendor/libigl/include/igl/quat_to_axis_angle.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUAT_TO_AXIS_ANGLE_H +#define IGL_QUAT_TO_AXIS_ANGLE_H +#include "igl_inline.h" + +namespace igl +{ + // Convert quat representation of a rotation to axis angle + // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), + // such that q = x*i + y*j + z*k + w + // Inputs: + // q quaternion + // Outputs: + // axis 3d vector + // angle scalar in radians + template + IGL_INLINE void quat_to_axis_angle( + const Q_type *q, + Q_type *axis, + Q_type & angle); + // Wrapper with angle in degrees + template + IGL_INLINE void quat_to_axis_angle_deg( + const Q_type *q, + Q_type *axis, + Q_type & angle); +} + +#ifndef IGL_STATIC_LIBRARY +# include "quat_to_axis_angle.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/quat_to_mat.h b/vendor/libigl/include/igl/quat_to_mat.h new file mode 100644 index 0000000000000000000000000000000000000000..4291b291ec0b96bfca213b3c1bac1c482f67cf5a --- /dev/null +++ b/vendor/libigl/include/igl/quat_to_mat.h @@ -0,0 +1,30 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUAT_TO_MAT_H +#define IGL_QUAT_TO_MAT_H +#include "igl_inline.h" +// Name history: +// quat2mat until 16 Sept 2011 +namespace igl +{ + // Convert a quaternion to a 4x4 matrix + // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), + // such that q = x*i + y*j + z*k + w + // Input: + // quat pointer to four elements of quaternion (x,y,z,w) + // Output: + // mat pointer to 16 elements of matrix + template + IGL_INLINE void quat_to_mat(const Q_type * quat, Q_type * mat); +} + +#ifndef IGL_STATIC_LIBRARY +# include "quat_to_mat.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/quats_to_column.cpp b/vendor/libigl/include/igl/quats_to_column.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4a88a666d8a78c47f47f2c755ddaff1c847c135 --- /dev/null +++ b/vendor/libigl/include/igl/quats_to_column.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "quats_to_column.h" + +IGL_INLINE void igl::quats_to_column( + const std::vector< + Eigen::Quaterniond,Eigen::aligned_allocator > vQ, + Eigen::VectorXd & Q) +{ + Q.resize(vQ.size()*4); + for(int q = 0;q<(int)vQ.size();q++) + { + auto & xyzw = vQ[q].coeffs(); + for(int c = 0;c<4;c++) + { + Q(q*4+c) = xyzw(c); + } + } +} + +IGL_INLINE Eigen::VectorXd igl::quats_to_column( + const std::vector< + Eigen::Quaterniond,Eigen::aligned_allocator > vQ) +{ + Eigen::VectorXd Q; + quats_to_column(vQ,Q); + return Q; +} diff --git a/vendor/libigl/include/igl/quats_to_column.h b/vendor/libigl/include/igl/quats_to_column.h new file mode 100644 index 0000000000000000000000000000000000000000..4a7795ae148bf73fe5c089c71efac8366dc98be8 --- /dev/null +++ b/vendor/libigl/include/igl/quats_to_column.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_QUATS_TO_COLUMN_H +#define IGL_QUATS_TO_COLUMN_H +#include "igl_inline.h" +#include +#include +#include +#include +namespace igl +{ + // "Columnize" a list of quaternions (q1x,q1y,q1z,q1w,q2x,q2y,q2z,q2w,...) + // + // Inputs: + // vQ n-long list of quaternions + // Outputs: + // Q n*4-long list of coefficients + IGL_INLINE void quats_to_column( + const std::vector< + Eigen::Quaterniond,Eigen::aligned_allocator > vQ, + Eigen::VectorXd & Q); + IGL_INLINE Eigen::VectorXd quats_to_column( + const std::vector< + Eigen::Quaterniond,Eigen::aligned_allocator > vQ); +} + +#ifndef IGL_STATIC_LIBRARY +# include "quats_to_column.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/ramer_douglas_peucker.cpp b/vendor/libigl/include/igl/ramer_douglas_peucker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f09a1bea7d7c1ca6f12d90fb1853b8f7aed1387 --- /dev/null +++ b/vendor/libigl/include/igl/ramer_douglas_peucker.cpp @@ -0,0 +1,150 @@ +#include "ramer_douglas_peucker.h" + +#include "LinSpaced.h" +#include "find.h" +#include "cumsum.h" +#include "histc.h" +#include "slice.h" +#include "project_to_line.h" +#include "EPS.h" +#include "slice_mask.h" + +template +IGL_INLINE void igl::ramer_douglas_peucker( + const Eigen::MatrixBase & P, + const typename DerivedP::Scalar tol, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & J) +{ + typedef typename DerivedP::Scalar Scalar; + // number of vertices + const int n = P.rows(); + // Trivial base case + if(n <= 1) + { + J = DerivedJ::Zero(n); + S = P; + return; + } + // number of dimensions + const int m = P.cols(); + Eigen::Array I = + Eigen::Array::Constant(n,1,true); + const auto stol = tol*tol; + std::function simplify; + simplify = [&I,&P,&stol,&simplify](const int ixs, const int ixe)->void + { + assert(ixe>ixs); + Scalar sdmax = 0; + typename Eigen::Matrix::Index ixc = -1; + if((ixe-ixs)>1) + { + Scalar sdes = (P.row(ixe)-P.row(ixs)).squaredNorm(); + Eigen::Matrix sD; + const auto & Pblock = P.block(ixs+1,0,((ixe+1)-ixs)-2,P.cols()); + if(sdes<=EPS()) + { + sD = (Pblock.rowwise()-P.row(ixs)).rowwise().squaredNorm(); + }else + { + Eigen::Matrix T; + project_to_line(Pblock,P.row(ixs).eval(),P.row(ixe).eval(),T,sD); + } + sdmax = sD.maxCoeff(&ixc); + // Index full P + ixc = ixc+(ixs+1); + } + if(sdmax <= stol) + { + if(ixs != ixe-1) + { + I.block(ixs+1,0,((ixe+1)-ixs)-2,1).setConstant(false); + } + }else + { + simplify(ixs,ixc); + simplify(ixc,ixe); + } + }; + simplify(0,n-1); + slice_mask(P,I,1,S); + find(I,J); +} + +template < + typename DerivedP, + typename DerivedS, + typename DerivedJ, + typename DerivedQ> +IGL_INLINE void igl::ramer_douglas_peucker( + const Eigen::MatrixBase & P, + const typename DerivedP::Scalar tol, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & J, + Eigen::PlainObjectBase & Q) +{ + typedef typename DerivedP::Scalar Scalar; + ramer_douglas_peucker(P,tol,S,J); + const int n = P.rows(); + assert(n>=2 && "Curve should be at least 2 points"); + typedef Eigen::Matrix VectorXS; + // distance traveled along high-res curve + VectorXS L(n); + L(0) = 0; + L.block(1,0,n-1,1) = (P.bottomRows(n-1)-P.topRows(n-1)).rowwise().norm(); + // Give extra on end + VectorXS T; + cumsum(L,1,T); + T.conservativeResize(T.size()+1); + T(T.size()-1) = T(T.size()-2); + // index of coarse point before each fine vertex + Eigen::VectorXi B; + { + Eigen::VectorXi N; + histc(igl::LinSpaced(n,0,n-1),J,N,B); + } + // Add extra point at end + J.conservativeResize(J.size()+1); + J(J.size()-1) = J(J.size()-2); + Eigen::VectorXi s,d; + // Find index in original list of "start" vertices + slice(J,B,s); + // Find index in original list of "destination" vertices + slice(J,(B.array()+1).matrix().eval(),d); + // Parameter between start and destination is linear in arc-length + VectorXS Ts,Td; + slice(T,s,Ts); + slice(T,d,Td); + T = ((T.head(T.size()-1)-Ts).array()/(Td-Ts).array()).eval(); + for(int t =0;t= S.rows()) + { + MB(b) = S.rows()-1; + } + } + DerivedS SMB; + slice(S,MB,1,SMB); + Q = SB.array() + ((SMB.array()-SB.array()).colwise()*T.array()); + + // Remove extra point at end + J.conservativeResize(J.size()-1); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::ramer_douglas_peucker, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::ramer_douglas_peucker, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/random_dir.cpp b/vendor/libigl/include/igl/random_dir.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f307834180e5345e0455fb5c432f81104059261f --- /dev/null +++ b/vendor/libigl/include/igl/random_dir.cpp @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "random_dir.h" +#include +#include + +IGL_INLINE Eigen::Vector3d igl::random_dir() +{ + using namespace Eigen; + double z = (double)rand() / (double)RAND_MAX*2.0 - 1.0; + double t = (double)rand() / (double)RAND_MAX*2.0*PI; + // http://www.altdevblogaday.com/2012/05/03/generating-uniformly-distributed-points-on-sphere/ + double r = sqrt(1.0-z*z); + double x = r * cos(t); + double y = r * sin(t); + return Vector3d(x,y,z); +} + +IGL_INLINE Eigen::MatrixXd igl::random_dir_stratified(const int n) +{ + using namespace Eigen; + using namespace std; + const double m = std::floor(sqrt(double(n))); + MatrixXd N(n,3); + int row = 0; + for(int i = 0;i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RANDOM_DIR_H +#define IGL_RANDOM_DIR_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Generate a uniformly random unit direction in 3D, return as vector + IGL_INLINE Eigen::Vector3d random_dir(); + // Generate n stratified uniformly random unit directions in 3d, return as rows + // of an n by 3 matrix + // + // Inputs: + // n number of directions + // Return n by 3 matrix of random directions + IGL_INLINE Eigen::MatrixXd random_dir_stratified(const int n); +} + +#ifndef IGL_STATIC_LIBRARY +# include "random_dir.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/random_points_on_mesh.h b/vendor/libigl/include/igl/random_points_on_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..b3e96d4c9c336dc217fde47f220121bf71c75766 --- /dev/null +++ b/vendor/libigl/include/igl/random_points_on_mesh.h @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RANDOM_POINTS_ON_MESH_H +#define IGL_RANDOM_POINTS_ON_MESH_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // RANDOM_POINTS_ON_MESH Randomly sample a mesh (V,F) n times. + // + // Inputs: + // n number of samples + // V #V by dim list of mesh vertex positions + // F #F by 3 list of mesh triangle indices + // Outputs: + // B n by 3 list of barycentric coordinates, ith row are coordinates of + // ith sampled point in face FI(i) + // FI n list of indices into F + // + template + IGL_INLINE void random_points_on_mesh( + const int n, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & FI); + // Outputs: + // X n by dim list of sample positions. + template < + typename DerivedV, + typename DerivedF, + typename DerivedB, + typename DerivedFI, + typename DerivedX> + IGL_INLINE void random_points_on_mesh( + const int n, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & B, + Eigen::PlainObjectBase & FI, + Eigen::PlainObjectBase & X); + // Outputs: + // B n by #V sparse matrix so that B*V produces a list of sample points + template + IGL_INLINE void random_points_on_mesh( + const int n, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::SparseMatrix & B, + Eigen::PlainObjectBase & FI); +} + +#ifndef IGL_STATIC_LIBRARY +# include "random_points_on_mesh.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/random_quaternion.h b/vendor/libigl/include/igl/random_quaternion.h new file mode 100644 index 0000000000000000000000000000000000000000..dfa36022bebca2e4805699315762e3d866a63f30 --- /dev/null +++ b/vendor/libigl/include/igl/random_quaternion.h @@ -0,0 +1,21 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RANDOM_QUATERNION_H +#define IGL_RANDOM_QUATERNION_H +#include "igl_inline.h" +#include +namespace igl +{ + // Return a random quaternion via uniform sampling of the 4-sphere + template + IGL_INLINE Eigen::Quaternion random_quaternion(); +} +#ifndef IGL_STATIC_LIBRARY +#include "random_quaternion.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/random_search.cpp b/vendor/libigl/include/igl/random_search.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d248d73e6845b227f7589a48af68bdc6796bbff8 --- /dev/null +++ b/vendor/libigl/include/igl/random_search.cpp @@ -0,0 +1,36 @@ +#include "random_search.h" +#include +#include + +template < + typename Scalar, + typename DerivedX, + typename DerivedLB, + typename DerivedUB> +IGL_INLINE Scalar igl::random_search( + const std::function< Scalar (DerivedX &) > f, + const Eigen::MatrixBase & LB, + const Eigen::MatrixBase & UB, + const int iters, + DerivedX & X) +{ + Scalar min_f = std::numeric_limits::max(); + const int dim = LB.size(); + assert(UB.size() == dim && "UB should match LB size"); + for(int iter = 0;iter, Eigen::Matrix, Eigen::Matrix >(std::function&)>, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/randperm.cpp b/vendor/libigl/include/igl/randperm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c9ac266c046b02ac8733368b44042daab802a66 --- /dev/null +++ b/vendor/libigl/include/igl/randperm.cpp @@ -0,0 +1,73 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "randperm.h" +#include "colon.h" +#include + +template +IGL_INLINE void igl::randperm( + const int n, + Eigen::PlainObjectBase & I, + URBG && urbg) +{ + Eigen::VectorXi II; + igl::colon(0,1,n-1,II); + I = II; + + std::shuffle(I.data(),I.data()+n, urbg); +} + +template +IGL_INLINE void igl::randperm( + const int n, + Eigen::PlainObjectBase & I) +{ + return igl::randperm(n, I, std::minstd_rand(std::rand())); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::randperm, std::minstd_rand0>(int, Eigen::PlainObjectBase >&, std::minstd_rand0 &&); +template void igl::randperm, std::minstd_rand0 &>(int, Eigen::PlainObjectBase >&, std::minstd_rand0 &); +template void igl::randperm, std::minstd_rand0>(int, Eigen::PlainObjectBase >&, std::minstd_rand0 &&); +template void igl::randperm, std::minstd_rand0 &>(int, Eigen::PlainObjectBase >&, std::minstd_rand0 &); +template void igl::randperm, std::minstd_rand>(int, Eigen::PlainObjectBase >&, std::minstd_rand &&); +template void igl::randperm, std::minstd_rand &>(int, Eigen::PlainObjectBase >&, std::minstd_rand &); +template void igl::randperm, std::minstd_rand>(int, Eigen::PlainObjectBase >&, std::minstd_rand &&); +template void igl::randperm, std::minstd_rand &>(int, Eigen::PlainObjectBase >&, std::minstd_rand &); +template void igl::randperm, std::mt19937>(int, Eigen::PlainObjectBase >&, std::mt19937 &&); +template void igl::randperm, std::mt19937 &>(int, Eigen::PlainObjectBase >&, std::mt19937 &); +template void igl::randperm, std::mt19937>(int, Eigen::PlainObjectBase >&, std::mt19937 &&); +template void igl::randperm, std::mt19937 &>(int, Eigen::PlainObjectBase >&, std::mt19937 &); +template void igl::randperm, std::mt19937_64>(int, Eigen::PlainObjectBase >&, std::mt19937_64 &&); +template void igl::randperm, std::mt19937_64 &>(int, Eigen::PlainObjectBase >&, std::mt19937_64 &); +template void igl::randperm, std::mt19937_64>(int, Eigen::PlainObjectBase >&, std::mt19937_64 &&); +template void igl::randperm, std::mt19937_64 &>(int, Eigen::PlainObjectBase >&, std::mt19937_64 &); +template void igl::randperm, std::ranlux24_base>(int, Eigen::PlainObjectBase >&, std::ranlux24_base &&); +template void igl::randperm, std::ranlux24_base &>(int, Eigen::PlainObjectBase >&, std::ranlux24_base &); +template void igl::randperm, std::ranlux24_base>(int, Eigen::PlainObjectBase >&, std::ranlux24_base &&); +template void igl::randperm, std::ranlux24_base &>(int, Eigen::PlainObjectBase >&, std::ranlux24_base &); +template void igl::randperm, std::ranlux48_base>(int, Eigen::PlainObjectBase >&, std::ranlux48_base &&); +template void igl::randperm, std::ranlux48_base &>(int, Eigen::PlainObjectBase >&, std::ranlux48_base &); +template void igl::randperm, std::ranlux48_base>(int, Eigen::PlainObjectBase >&, std::ranlux48_base &&); +template void igl::randperm, std::ranlux48_base &>(int, Eigen::PlainObjectBase >&, std::ranlux48_base &); +template void igl::randperm, std::ranlux24>(int, Eigen::PlainObjectBase >&, std::ranlux24 &&); +template void igl::randperm, std::ranlux24 &>(int, Eigen::PlainObjectBase >&, std::ranlux24 &); +template void igl::randperm, std::ranlux24>(int, Eigen::PlainObjectBase >&, std::ranlux24 &&); +template void igl::randperm, std::ranlux24 &>(int, Eigen::PlainObjectBase >&, std::ranlux24 &); +template void igl::randperm, std::ranlux48>(int, Eigen::PlainObjectBase >&, std::ranlux48 &&); +template void igl::randperm, std::ranlux48 &>(int, Eigen::PlainObjectBase >&, std::ranlux48 &); +template void igl::randperm, std::ranlux48>(int, Eigen::PlainObjectBase >&, std::ranlux48 &&); +template void igl::randperm, std::ranlux48 &>(int, Eigen::PlainObjectBase >&, std::ranlux48 &); +template void igl::randperm, std::knuth_b>(int, Eigen::PlainObjectBase >&, std::knuth_b &&); +template void igl::randperm, std::knuth_b &>(int, Eigen::PlainObjectBase >&, std::knuth_b &); +template void igl::randperm, std::knuth_b>(int, Eigen::PlainObjectBase >&, std::knuth_b &&); +template void igl::randperm, std::knuth_b &>(int, Eigen::PlainObjectBase >&, std::knuth_b &); +template void igl::randperm>(int, Eigen::PlainObjectBase >&); +template void igl::randperm>(int, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/randperm.h b/vendor/libigl/include/igl/randperm.h new file mode 100644 index 0000000000000000000000000000000000000000..30c2ba48954da3d04e8cc204b10d57d5aede9c65 --- /dev/null +++ b/vendor/libigl/include/igl/randperm.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RANDPERM_H +#define IGL_RANDPERM_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Like matlab's randperm(n) but minus 1 + // + // When urbg is not specified, randperm will use default random bit generator + // std::minstd_rand initialized with random seed generated by std::rand() + // + // Inputs: + // n number of elements + // urbg An instance of UnformRandomBitGenerator. + // Outputs: + // I n list of rand permutation of 0:n-1 + template + IGL_INLINE void randperm( + const int n, + Eigen::PlainObjectBase & I, + URBG && urbg); + + template + IGL_INLINE void randperm( + const int n, + Eigen::PlainObjectBase & I); +} +#ifndef IGL_STATIC_LIBRARY +# include "randperm.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/ray_box_intersect.cpp b/vendor/libigl/include/igl/ray_box_intersect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..95a9daaa73b977d4a9c30a80f88e538b75afa5bc --- /dev/null +++ b/vendor/libigl/include/igl/ray_box_intersect.cpp @@ -0,0 +1,150 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ray_box_intersect.h" +#include + +template < + typename Derivedsource, + typename Deriveddir, + typename Scalar> +IGL_INLINE bool igl::ray_box_intersect( + const Eigen::MatrixBase & origin, + const Eigen::MatrixBase & dir, + const Eigen::AlignedBox & box, + const Scalar & t0, + const Scalar & t1, + Scalar & tmin, + Scalar & tmax) +{ +#ifdef false + // https://github.com/RMonica/basic_next_best_view/blob/master/src/RayTracer.cpp + const auto & intersectRayBox = []( + const Eigen::Vector3f& rayo, + const Eigen::Vector3f& rayd, + const Eigen::Vector3f& bmin, + const Eigen::Vector3f& bmax, + float & tnear, + float & tfar + )->bool + { + Eigen::Vector3f bnear; + Eigen::Vector3f bfar; + // Checks for intersection testing on each direction coordinate + // Computes + float t1, t2; + tnear = -1e+6f, tfar = 1e+6f; //, tCube; + bool intersectFlag = true; + for (int i = 0; i < 3; ++i) { + // std::cout << "coordinate " << i << ": bmin " << bmin(i) << ", bmax " << bmax(i) << std::endl; + assert(bmin(i) <= bmax(i)); + if (::fabs(rayd(i)) < 1e-6) { // Ray parallel to axis i-th + if (rayo(i) < bmin(i) || rayo(i) > bmax(i)) { + intersectFlag = false; + } + } + else { + // Finds the nearest and the farthest vertices of the box from the ray origin + if (::fabs(bmin(i) - rayo(i)) < ::fabs(bmax(i) - rayo(i))) { + bnear(i) = bmin(i); + bfar(i) = bmax(i); + } + else { + bnear(i) = bmax(i); + bfar(i) = bmin(i); + } + // std::cout << " bnear " << bnear(i) << ", bfar " << bfar(i) << std::endl; + // Finds the distance parameters t1 and t2 of the two ray-box intersections: + // t1 must be the closest to the ray origin rayo. + t1 = (bnear(i) - rayo(i)) / rayd(i); + t2 = (bfar(i) - rayo(i)) / rayd(i); + if (t1 > t2) { + std::swap(t1,t2); + } + // The two intersection values are used to saturate tnear and tfar + if (t1 > tnear) { + tnear = t1; + } + if (t2 < tfar) { + tfar = t2; + } + // std::cout << " t1 " << t1 << ", t2 " << t2 << ", tnear " << tnear << ", tfar " << tfar + // << " tnear > tfar? " << (tnear > tfar) << ", tfar < 0? " << (tfar < 0) << std::endl; + if(tnear > tfar) { + intersectFlag = false; + } + if(tfar < 0) { + intersectFlag = false; + } + } + } + // Checks whether intersection occurs or not + return intersectFlag; + }; + float tmin_f, tmax_f; + bool ret = intersectRayBox( + origin. template cast(), + dir. template cast(), + box.min().template cast(), + box.max().template cast(), + tmin_f, + tmax_f); + tmin = tmin_f; + tmax = tmax_f; + return ret; +#else + using namespace Eigen; + // This should be precomputed and provided as input + typedef Matrix RowVector3S; + const RowVector3S inv_dir( 1./dir(0),1./dir(1),1./dir(2)); + const std::array sign = { inv_dir(0)<0, inv_dir(1)<0, inv_dir(2)<0}; + // http://people.csail.mit.edu/amy/papers/box-jgt.pdf + // "An Efficient and Robust Ray–Box Intersection Algorithm" + Scalar tymin, tymax, tzmin, tzmax; + std::array bounds = {box.min(),box.max()}; + tmin = ( bounds[sign[0]](0) - origin(0)) * inv_dir(0); + tmax = ( bounds[1-sign[0]](0) - origin(0)) * inv_dir(0); + tymin = (bounds[sign[1]](1) - origin(1)) * inv_dir(1); + tymax = (bounds[1-sign[1]](1) - origin(1)) * inv_dir(1); + if ( (tmin > tymax) || (tymin > tmax) ) + { + return false; + } + if (tymin > tmin) + { + tmin = tymin; + } + if (tymax < tmax) + { + tmax = tymax; + } + tzmin = (bounds[sign[2]](2) - origin(2)) * inv_dir(2); + tzmax = (bounds[1-sign[2]](2) - origin(2)) * inv_dir(2); + if ( (tmin > tzmax) || (tzmin > tmax) ) + { + return false; + } + if (tzmin > tmin) + { + tmin = tzmin; + } + if (tzmax < tmax) + { + tmax = tzmax; + } + if(!( (tmin < t1) && (tmax > t0) )) + { + return false; + } + return true; +#endif +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template bool igl::ray_box_intersect, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::AlignedBox const&, double const&, double const&, double&, double&); +#endif diff --git a/vendor/libigl/include/igl/ray_box_intersect.h b/vendor/libigl/include/igl/ray_box_intersect.h new file mode 100644 index 0000000000000000000000000000000000000000..6b6e14aaa33baf72fcd067e2494aa08c001eaa55 --- /dev/null +++ b/vendor/libigl/include/igl/ray_box_intersect.h @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RAY_BOX_INTERSECT_H +#define IGL_RAY_BOX_INTERSECT_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Determine whether a ray origin+t*dir and box intersect within the ray's parameterized + // range (t0,t1) + // + // Inputs: + // source 3-vector origin of ray + // dir 3-vector direction of ray + // box axis aligned box + // t0 hit only if hit.t less than t0 + // t1 hit only if hit.t greater than t1 + // Outputs: + // tmin minimum of interval of overlap within [t0,t1] + // tmax maximum of interval of overlap within [t0,t1] + // Returns true if hit + template < + typename Derivedsource, + typename Deriveddir, + typename Scalar> + IGL_INLINE bool ray_box_intersect( + const Eigen::MatrixBase & source, + const Eigen::MatrixBase & dir, + const Eigen::AlignedBox & box, + const Scalar & t0, + const Scalar & t1, + Scalar & tmin, + Scalar & tmax); +} +#ifndef IGL_STATIC_LIBRARY +# include "ray_box_intersect.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/ray_mesh_intersect.cpp b/vendor/libigl/include/igl/ray_mesh_intersect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..444ee83229168717225be8cafe12fb9642811ad3 --- /dev/null +++ b/vendor/libigl/include/igl/ray_mesh_intersect.cpp @@ -0,0 +1,90 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ray_mesh_intersect.h" + +extern "C" +{ +#include "raytri.c" +} + +template < + typename Derivedsource, + typename Deriveddir, + typename DerivedV, + typename DerivedF> +IGL_INLINE bool igl::ray_mesh_intersect( + const Eigen::MatrixBase & s, + const Eigen::MatrixBase & dir, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + std::vector & hits) +{ + using namespace Eigen; + using namespace std; + // Should be but can't be const + Vector3d s_d = s.template cast(); + Vector3d dir_d = dir.template cast(); + hits.clear(); + hits.reserve(F.rows()); + + // loop over all triangles + for(int f = 0;f(); + RowVector3d v1 = V.row(F(f,1)).template cast(); + RowVector3d v2 = V.row(F(f,2)).template cast(); + // shoot ray, record hit + double t,u,v; + if(intersect_triangle1( + s_d.data(), dir_d.data(), v0.data(), v1.data(), v2.data(), &t, &u, &v) && + t>0) + { + hits.push_back({(int)f,(int)-1,(float)u,(float)v,(float)t}); + } + } + // Sort hits based on distance + std::sort( + hits.begin(), + hits.end(), + [](const Hit & a, const Hit & b)->bool{ return a.t < b.t;}); + return hits.size() > 0; +} + +template < + typename Derivedsource, + typename Deriveddir, + typename DerivedV, + typename DerivedF> +IGL_INLINE bool igl::ray_mesh_intersect( + const Eigen::MatrixBase & source, + const Eigen::MatrixBase & dir, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + igl::Hit & hit) +{ + std::vector hits; + ray_mesh_intersect(source,dir,V,F,hits); + if(hits.size() > 0) + { + hit = hits.front(); + return true; + }else + { + return false; + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::ray_mesh_intersect, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >&); +template bool igl::ray_mesh_intersect, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >&); +template bool igl::ray_mesh_intersect, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::Hit&); +template bool igl::ray_mesh_intersect, Eigen::Matrix, Eigen::Matrix, Eigen::Block const, 1, -1, false> >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase const, 1, -1, false> > const&, igl::Hit&); +#endif diff --git a/vendor/libigl/include/igl/ray_mesh_intersect.h b/vendor/libigl/include/igl/ray_mesh_intersect.h new file mode 100644 index 0000000000000000000000000000000000000000..5e10dc94209b0d40940ce139bc0e0339ccb0770f --- /dev/null +++ b/vendor/libigl/include/igl/ray_mesh_intersect.h @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RAY_MESH_INTERSECT_H +#define IGL_RAY_MESH_INTERSECT_H +#include "igl_inline.h" +#include "Hit.h" +#include +#include +namespace igl +{ + // Shoot a ray against a mesh (V,F) and collect all hits. If you have many + // rays, consider using AABB.h + // + // Inputs: + // source 3-vector origin of ray + // dir 3-vector direction of ray + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh face indices into V + // Outputs: + // hits **sorted** list of hits + // Returns true if there were any hits (hits.size() > 0) + // + // See also: AABB.h + template < + typename Derivedsource, + typename Deriveddir, + typename DerivedV, + typename DerivedF> + IGL_INLINE bool ray_mesh_intersect( + const Eigen::MatrixBase & source, + const Eigen::MatrixBase & dir, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + std::vector & hits); + // Outputs: + // hit first hit, set only if it exists + // Returns true if there was a hit + template < + typename Derivedsource, + typename Deriveddir, + typename DerivedV, + typename DerivedF> + IGL_INLINE bool ray_mesh_intersect( + const Eigen::MatrixBase & source, + const Eigen::MatrixBase & dir, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + igl::Hit & hit); +} +#ifndef IGL_STATIC_LIBRARY +# include "ray_mesh_intersect.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/ray_sphere_intersect.cpp b/vendor/libigl/include/igl/ray_sphere_intersect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a05c2a12c229f7bdf7fb60de02a448920f72f75 --- /dev/null +++ b/vendor/libigl/include/igl/ray_sphere_intersect.cpp @@ -0,0 +1,74 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "ray_sphere_intersect.h" + +template < + typename Derivedo, + typename Derivedd, + typename Derivedc, + typename r_type, + typename t_type> +IGL_INLINE int igl::ray_sphere_intersect( + const Eigen::PlainObjectBase & ao, + const Eigen::PlainObjectBase & d, + const Eigen::PlainObjectBase & ac, + r_type r, + t_type & t0, + t_type & t1) +{ + Eigen::Vector3d o = ao-ac; + // http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection + //Compute A, B and C coefficients + double a = d.dot(d); + double b = 2 * d.dot(o); + double c = o.dot(o) - (r * r); + + //Find discriminant + double disc = b * b - 4 * a * c; + + // if discriminant is negative there are no real roots, so return + // false as ray misses sphere + if (disc < 0) + { + return 0; + } + + // compute q as described above + double distSqrt = sqrt(disc); + double q; + if (b < 0) + { + q = (-b - distSqrt)/2.0; + } else + { + q = (-b + distSqrt)/2.0; + } + + // compute t0 and t1 + t0 = q / a; + double _t1 = c/q; + if(_t1 == t0) + { + return 1; + } + t1 = _t1; + // make sure t0 is smaller than t1 + if (t0 > t1) + { + // if t0 is bigger than t1 swap them around + double temp = t0; + t0 = t1; + t1 = temp; + } + return 2; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template int igl::ray_sphere_intersect, Eigen::Matrix, Eigen::Matrix, double, double>(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, double, double&, double&); +#endif diff --git a/vendor/libigl/include/igl/ray_sphere_intersect.h b/vendor/libigl/include/igl/ray_sphere_intersect.h new file mode 100644 index 0000000000000000000000000000000000000000..b4dfea37941e265fd2ccb89272ae7544a0fb3be7 --- /dev/null +++ b/vendor/libigl/include/igl/ray_sphere_intersect.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RAY_SPHERE_INTERSECT_H +#define IGL_RAY_SPHERE_INTERSECT_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute the intersection between a ray from O in direction D and a sphere + // centered at C with radius r + // + // Inputs: + // o origin of ray + // d direction of ray + // c center of sphere + // r radius of sphere + // Outputs: + // t0 parameterization of first hit (set only if exists) so that hit + // position = o + t0*d + // t1 parameterization of second hit (set only if exists) + // + // Returns the number of hits + template < + typename Derivedo, + typename Derivedd, + typename Derivedc, + typename r_type, + typename t_type> + IGL_INLINE int ray_sphere_intersect( + const Eigen::PlainObjectBase & o, + const Eigen::PlainObjectBase & d, + const Eigen::PlainObjectBase & c, + r_type r, + t_type & t0, + t_type & t1); +} +#ifndef IGL_STATIC_LIBRARY +#include "ray_sphere_intersect.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/raytri.c b/vendor/libigl/include/igl/raytri.c new file mode 100644 index 0000000000000000000000000000000000000000..b5e7f7b1f19bc3451aeca382d48c8543596a5f76 --- /dev/null +++ b/vendor/libigl/include/igl/raytri.c @@ -0,0 +1,267 @@ +/* Ray-Triangle Intersection Test Routines */ +/* Different optimizations of my and Ben Trumbore's */ +/* code from journals of graphics tools (JGT) */ +/* http://www.acm.org/jgt/ */ +/* by Tomas Moller, May 2000 */ + + +// Alec: this file is listed as "Public Domain" +// http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/ + +// Alec: I've added an include guard, made all functions inline and added +// IGL_RAY_TRI_ to #define macros +#ifndef IGL_RAY_TRI_C +#define IGL_RAY_TRI_C + +#include + +#define IGL_RAY_TRI_EPSILON 0.000001 +#define IGL_RAY_TRI_CROSS(dest,v1,v2) \ + dest[0]=v1[1]*v2[2]-v1[2]*v2[1]; \ + dest[1]=v1[2]*v2[0]-v1[0]*v2[2]; \ + dest[2]=v1[0]*v2[1]-v1[1]*v2[0]; +#define IGL_RAY_TRI_DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]) +#define IGL_RAY_TRI_SUB(dest,v1,v2) \ + dest[0]=v1[0]-v2[0]; \ + dest[1]=v1[1]-v2[1]; \ + dest[2]=v1[2]-v2[2]; + +/* the original jgt code */ +inline int intersect_triangle(double orig[3], double dir[3], + double vert0[3], double vert1[3], double vert2[3], + double *t, double *u, double *v) +{ + double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; + double det,inv_det; + + /* find vectors for two edges sharing vert0 */ + IGL_RAY_TRI_SUB(edge1, vert1, vert0); + IGL_RAY_TRI_SUB(edge2, vert2, vert0); + + /* begin calculating determinant - also used to calculate U parameter */ + IGL_RAY_TRI_CROSS(pvec, dir, edge2); + + /* if determinant is near zero, ray lies in plane of triangle */ + det = IGL_RAY_TRI_DOT(edge1, pvec); + + if (det > -IGL_RAY_TRI_EPSILON && det < IGL_RAY_TRI_EPSILON) + return 0; + inv_det = 1.0 / det; + + /* calculate distance from vert0 to ray origin */ + IGL_RAY_TRI_SUB(tvec, orig, vert0); + + /* calculate U parameter and test bounds */ + *u = IGL_RAY_TRI_DOT(tvec, pvec) * inv_det; + if (*u < 0.0 || *u > 1.0) + return 0; + + /* prepare to test V parameter */ + IGL_RAY_TRI_CROSS(qvec, tvec, edge1); + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec) * inv_det; + if (*v < 0.0 || *u + *v > 1.0) + return 0; + + /* calculate t, ray intersects triangle */ + *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; + + return 1; +} + + +/* code rewritten to do tests on the sign of the determinant */ +/* the division is at the end in the code */ +inline int intersect_triangle1(double orig[3], double dir[3], + double vert0[3], double vert1[3], double vert2[3], + double *t, double *u, double *v) +{ + double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; + double det,inv_det; + + /* find vectors for two edges sharing vert0 */ + IGL_RAY_TRI_SUB(edge1, vert1, vert0); + IGL_RAY_TRI_SUB(edge2, vert2, vert0); + + /* begin calculating determinant - also used to calculate U parameter */ + IGL_RAY_TRI_CROSS(pvec, dir, edge2); + + /* if determinant is near zero, ray lies in plane of triangle */ + det = IGL_RAY_TRI_DOT(edge1, pvec); + + if (det > IGL_RAY_TRI_EPSILON) + { + /* calculate distance from vert0 to ray origin */ + IGL_RAY_TRI_SUB(tvec, orig, vert0); + + /* calculate U parameter and test bounds */ + *u = IGL_RAY_TRI_DOT(tvec, pvec); + if (*u < 0.0 || *u > det) + return 0; + + /* prepare to test V parameter */ + IGL_RAY_TRI_CROSS(qvec, tvec, edge1); + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec); + if (*v < 0.0 || *u + *v > det) + return 0; + + } + else if(det < -IGL_RAY_TRI_EPSILON) + { + /* calculate distance from vert0 to ray origin */ + IGL_RAY_TRI_SUB(tvec, orig, vert0); + + /* calculate U parameter and test bounds */ + *u = IGL_RAY_TRI_DOT(tvec, pvec); +/* printf("*u=%f\n",(float)*u); */ +/* printf("det=%f\n",det); */ + if (*u > 0.0 || *u < det) + return 0; + + /* prepare to test V parameter */ + IGL_RAY_TRI_CROSS(qvec, tvec, edge1); + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec) ; + if (*v > 0.0 || *u + *v < det) + return 0; + } + else return 0; /* ray is parallel to the plane of the triangle */ + + + inv_det = 1.0 / det; + + /* calculate t, ray intersects triangle */ + *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; + (*u) *= inv_det; + (*v) *= inv_det; + + return 1; +} + +/* code rewritten to do tests on the sign of the determinant */ +/* the division is before the test of the sign of the det */ +inline int intersect_triangle2(double orig[3], double dir[3], + double vert0[3], double vert1[3], double vert2[3], + double *t, double *u, double *v) +{ + double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; + double det,inv_det; + + /* find vectors for two edges sharing vert0 */ + IGL_RAY_TRI_SUB(edge1, vert1, vert0); + IGL_RAY_TRI_SUB(edge2, vert2, vert0); + + /* begin calculating determinant - also used to calculate U parameter */ + IGL_RAY_TRI_CROSS(pvec, dir, edge2); + + /* if determinant is near zero, ray lies in plane of triangle */ + det = IGL_RAY_TRI_DOT(edge1, pvec); + + /* calculate distance from vert0 to ray origin */ + IGL_RAY_TRI_SUB(tvec, orig, vert0); + inv_det = 1.0 / det; + + if (det > IGL_RAY_TRI_EPSILON) + { + /* calculate U parameter and test bounds */ + *u = IGL_RAY_TRI_DOT(tvec, pvec); + if (*u < 0.0 || *u > det) + return 0; + + /* prepare to test V parameter */ + IGL_RAY_TRI_CROSS(qvec, tvec, edge1); + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec); + if (*v < 0.0 || *u + *v > det) + return 0; + + } + else if(det < -IGL_RAY_TRI_EPSILON) + { + /* calculate U parameter and test bounds */ + *u = IGL_RAY_TRI_DOT(tvec, pvec); + if (*u > 0.0 || *u < det) + return 0; + + /* prepare to test V parameter */ + IGL_RAY_TRI_CROSS(qvec, tvec, edge1); + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec) ; + if (*v > 0.0 || *u + *v < det) + return 0; + } + else return 0; /* ray is parallel to the plane of the triangle */ + + /* calculate t, ray intersects triangle */ + *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; + (*u) *= inv_det; + (*v) *= inv_det; + + return 1; +} + +/* code rewritten to do tests on the sign of the determinant */ +/* the division is before the test of the sign of the det */ +/* and one IGL_RAY_TRI_CROSS has been moved out from the if-else if-else */ +inline int intersect_triangle3(double orig[3], double dir[3], + double vert0[3], double vert1[3], double vert2[3], + double *t, double *u, double *v) +{ + double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; + double det,inv_det; + + /* find vectors for two edges sharing vert0 */ + IGL_RAY_TRI_SUB(edge1, vert1, vert0); + IGL_RAY_TRI_SUB(edge2, vert2, vert0); + + /* begin calculating determinant - also used to calculate U parameter */ + IGL_RAY_TRI_CROSS(pvec, dir, edge2); + + /* if determinant is near zero, ray lies in plane of triangle */ + det = IGL_RAY_TRI_DOT(edge1, pvec); + + /* calculate distance from vert0 to ray origin */ + IGL_RAY_TRI_SUB(tvec, orig, vert0); + inv_det = 1.0 / det; + + IGL_RAY_TRI_CROSS(qvec, tvec, edge1); + + if (det > IGL_RAY_TRI_EPSILON) + { + *u = IGL_RAY_TRI_DOT(tvec, pvec); + if (*u < 0.0 || *u > det) + return 0; + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec); + if (*v < 0.0 || *u + *v > det) + return 0; + + } + else if(det < -IGL_RAY_TRI_EPSILON) + { + /* calculate U parameter and test bounds */ + *u = IGL_RAY_TRI_DOT(tvec, pvec); + if (*u > 0.0 || *u < det) + return 0; + + /* calculate V parameter and test bounds */ + *v = IGL_RAY_TRI_DOT(dir, qvec) ; + if (*v > 0.0 || *u + *v < det) + return 0; + } + else return 0; /* ray is parallel to the plane of the triangle */ + + *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; + (*u) *= inv_det; + (*v) *= inv_det; + + return 1; +} +#endif diff --git a/vendor/libigl/include/igl/readBF.h b/vendor/libigl/include/igl/readBF.h new file mode 100644 index 0000000000000000000000000000000000000000..a2b010c85af953a0172bfc6c62c1a96968218d08 --- /dev/null +++ b/vendor/libigl/include/igl/readBF.h @@ -0,0 +1,67 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READBF_H +#define IGL_READBF_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Read a bones forest from a file, returns a list of bone roots + // Input: + // file_name path to .bf bones tree file + // Output: + // WI #B list of unique weight indices + // P #B list of parent indices into B, -1 for roots + // O #B by 3 list of tip offset vectors from parent (or position for roots) + // Returns true on success, false on errors + template < + typename DerivedWI, + typename DerivedP, + typename DerivedO> + IGL_INLINE bool readBF( + const std::string & filename, + Eigen::PlainObjectBase & WI, + Eigen::PlainObjectBase & P, + Eigen::PlainObjectBase & O); + // Read bone forest into pure bone-skeleton format, expects only bones (no + // point handles), and that a root in the .bf <---> no weight attachment. + // + // Input: + // file_name path to .bf bones tree file + // Output: + // WI #B list of unique weight indices + // P #B list of parent indices into B, -1 for roots + // O #B by 3 list of tip offset vectors from parent (or position for roots) + // C #C by 3 list of absolute joint locations + // BE #BE by 3 list of bone indices into C, in order of weight index + // P #BE list of parent bone indices into BE, -1 means root bone + // Returns true on success, false on errors + // + // See also: readTGF, bone_parents, forward_kinematics + template < + typename DerivedWI, + typename DerivedbfP, + typename DerivedO, + typename DerivedC, + typename DerivedBE, + typename DerivedP> + IGL_INLINE bool readBF( + const std::string & filename, + Eigen::PlainObjectBase & WI, + Eigen::PlainObjectBase & bfP, + Eigen::PlainObjectBase & O, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & BE, + Eigen::PlainObjectBase & P); +} + +#ifndef IGL_STATIC_LIBRARY +# include "readBF.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/readCSV.cpp b/vendor/libigl/include/igl/readCSV.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbe0240f2447a8ec29e239e380bcd2efa988be98 --- /dev/null +++ b/vendor/libigl/include/igl/readCSV.cpp @@ -0,0 +1,72 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "readCSV.h" + +#include +#include +#include +#include + +#include + +template +IGL_INLINE bool igl::readCSV( + const std::string str, + Eigen::Matrix& M) +{ + using namespace std; + + std::vector > Mt; + + std::ifstream infile(str.c_str()); + std::string line; + while (std::getline(infile, line)) + { + std::istringstream iss(line); + vector temp; + Scalar a; + char ch; + while (iss >> a){ + temp.push_back(a); + if(!(iss >> ch)) + break; + } + + if (temp.size() != 0) // skip empty lines + Mt.push_back(temp); + } + + if (Mt.size() != 0) + { + // Verify that it is indeed a matrix + for (unsigned i = 0; i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "readDMAT.h" + +#include "verbose.h" +#include +#include +#include +#include + +// Static helper method reads the first to elements in the given file +// Inputs: +// fp file pointer of .dmat file that was just opened +// Outputs: +// num_rows number of rows +// num_cols number of columns +// Returns +// 0 success +// 1 did not find header +// 2 bad num_cols +// 3 bad num_rows +// 4 bad line ending +static inline int readDMAT_read_header(FILE * fp, int & num_rows, int & num_cols) +{ + // first line contains number of rows and number of columns + int res = fscanf(fp,"%d %d",&num_cols,&num_rows); + if(res != 2) + { + return 1; + } + // check that number of columns and rows are sane + if(num_cols < 0) + { + fprintf(stderr,"IOError: readDMAT() number of columns %d < 0\n",num_cols); + return 2; + } + if(num_rows < 0) + { + fprintf(stderr,"IOError: readDMAT() number of rows %d < 0\n",num_rows); + return 3; + } + // finish reading header + char lf; + + if(fread(&lf, sizeof(char), 1, fp)!=1 || !(lf == '\n' || lf == '\r')) + { + fprintf(stderr,"IOError: bad line ending in header\n"); + return 4; + } + + return 0; +} + +#ifndef IGL_NO_EIGEN +template +IGL_INLINE bool igl::readDMAT(const std::string file_name, + Eigen::PlainObjectBase & W) +{ + FILE * fp = fopen(file_name.c_str(),"rb"); + if(fp == NULL) + { + fprintf(stderr,"IOError: readDMAT() could not open %s...\n",file_name.c_str()); + return false; + } + int num_rows,num_cols; + int head_success = readDMAT_read_header(fp,num_rows,num_cols); + if(head_success != 0) + { + if(head_success == 1) + { + fprintf(stderr, + "IOError: readDMAT() first row should be [num cols] [num rows]...\n"); + } + fclose(fp); + return false; + } + + // Resize output to fit matrix, only if non-empty since this will trigger an + // error on fixed size matrices before reaching binary data. + bool empty = num_rows == 0 || num_cols == 0; + if(!empty) + { + W.resize(num_rows,num_cols); + } + + // Loop over columns slowly + for(int j = 0;j < num_cols;j++) + { + // loop over rows (down columns) quickly + for(int i = 0;i < num_rows;i++) + { + double d; + if(fscanf(fp," %lg",&d) != 1) + { + fclose(fp); + fprintf( + stderr, + "IOError: readDMAT() bad format after reading %d entries\n", + j*num_rows + i); + return false; + } + W(i,j) = d; + } + } + + // Try to read header for binary part + head_success = readDMAT_read_header(fp,num_rows,num_cols); + if(head_success == 0) + { + assert(W.size() == 0); + // Resize for output + W.resize(num_rows,num_cols); + std::unique_ptr Wraw(new double[num_rows*num_cols]); + fread(Wraw.get(), sizeof(double), num_cols*num_rows, fp); + // Loop over columns slowly + for(int j = 0;j < num_cols;j++) + { + // loop over rows (down columns) quickly + for(int i = 0;i < num_rows;i++) + { + W(i,j) = Wraw[j*num_rows+i]; + } + } + }else + { + // we skipped resizing before in case there was binary data + if(empty) + { + // This could trigger an error if using fixed size matrices. + W.resize(num_rows,num_cols); + } + } + + fclose(fp); + return true; +} +#endif + +template +IGL_INLINE bool igl::readDMAT( + const std::string file_name, + std::vector > & W) +{ + FILE * fp = fopen(file_name.c_str(),"r"); + if(fp == NULL) + { + fprintf(stderr,"IOError: readDMAT() could not open %s...\n",file_name.c_str()); + return false; + } + int num_rows,num_cols; + bool head_success = readDMAT_read_header(fp,num_rows,num_cols); + if(head_success != 0) + { + if(head_success == 1) + { + fprintf(stderr, + "IOError: readDMAT() first row should be [num cols] [num rows]...\n"); + } + fclose(fp); + return false; + } + + // Resize for output + W.resize(num_rows,typename std::vector(num_cols)); + + // Loop over columns slowly + for(int j = 0;j < num_cols;j++) + { + // loop over rows (down columns) quickly + for(int i = 0;i < num_rows;i++) + { + double d; + if(fscanf(fp," %lg",&d) != 1) + { + fclose(fp); + fprintf( + stderr, + "IOError: readDMAT() bad format after reading %d entries\n", + j*num_rows + i); + return false; + } + W[i][j] = (Scalar)d; + } + } + + // Try to read header for binary part + head_success = readDMAT_read_header(fp,num_rows,num_cols); + if(head_success == 0) + { + assert(W.size() == 0); + // Resize for output + W.resize(num_rows,typename std::vector(num_cols)); + std::unique_ptr Wraw(new double[num_rows*num_cols]); + fread(Wraw.get(), sizeof(double), num_cols*num_rows, fp); + // Loop over columns slowly + for(int j = 0;j < num_cols;j++) + { + // loop over rows (down columns) quickly + for(int i = 0;i < num_rows;i++) + { + W[i][j] = Wraw[j*num_rows+i]; + } + } + } + + fclose(fp); + return true; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::readDMAT >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT(std::string, std::vector >, std::allocator > > >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >( std::string, Eigen::PlainObjectBase >&); +template bool igl::readDMAT >(std::string, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/readDMAT.h b/vendor/libigl/include/igl/readDMAT.h new file mode 100644 index 0000000000000000000000000000000000000000..e09c492c12e02ce1531f5f0f7ef7e416e11414a4 --- /dev/null +++ b/vendor/libigl/include/igl/readDMAT.h @@ -0,0 +1,53 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READDMAT_H +#define IGL_READDMAT_H +#include "igl_inline.h" +// .dmat is a simple ascii matrix file type, defined as follows. The first line +// is always: +// <#columns> <#rows> +// Then the coefficients of the matrix are given separated by whitespace with +// columns running fastest. +// +// Example: +// The matrix m = [1 2 3; 4 5 6]; +// corresponds to a .dmat file containing: +// 3 2 +// 1 4 2 5 3 6 +#include +#include +#ifndef IGL_NO_EIGEN +# include +#endif +namespace igl +{ + // Read a matrix from an ascii dmat file + // + // Inputs: + // file_name path to .dmat file + // Outputs: + // W eigen matrix containing read-in coefficients + // Returns true on success, false on error + // +#ifndef IGL_NO_EIGEN + template + IGL_INLINE bool readDMAT(const std::string file_name, + Eigen::PlainObjectBase & W); +#endif + // Wrapper for vector of vectors + template + IGL_INLINE bool readDMAT( + const std::string file_name, + std::vector > & W); +} + +#ifndef IGL_STATIC_LIBRARY +# include "readDMAT.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/readMESH.cpp b/vendor/libigl/include/igl/readMESH.cpp new file mode 100644 index 0000000000000000000000000000000000000000..954360a0e2e9671bca35e33fc3d817dff25aa83b --- /dev/null +++ b/vendor/libigl/include/igl/readMESH.cpp @@ -0,0 +1,223 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "readMESH.h" +#include + + +template +IGL_INLINE bool igl::readMESH( + const std::string mesh_file_name, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& T, + Eigen::PlainObjectBase& F) +{ + using namespace std; + FILE * mesh_file = fopen(mesh_file_name.c_str(),"r"); + if(NULL==mesh_file) + { + fprintf(stderr,"IOError: %s could not be opened...",mesh_file_name.c_str()); + return false; + } + return readMESH(mesh_file,V,T,F); +} + +template +IGL_INLINE bool igl::readMESH( + FILE * mesh_file, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& T, + Eigen::PlainObjectBase& F) +{ + using namespace std; +#ifndef LINE_MAX +# define LINE_MAX 2048 +#endif + char line[LINE_MAX]; + bool still_comments; + + // eat comments at beginning of file + const auto eat_comments = [&]()->bool + { + bool still_comments= true; + bool has_line = false; + while(still_comments) + { + has_line = fgets(line,LINE_MAX,mesh_file) != NULL; + still_comments = (line[0] == '#' || line[0] == '\n' || line[0] == '\r'); + } + return has_line; + }; + eat_comments(); + + char str[LINE_MAX]; + sscanf(line," %s",str); + // check that first word is MeshVersionFormatted + if(0!=strcmp(str,"MeshVersionFormatted")) + { + fprintf(stderr, + "Error: first word should be MeshVersionFormatted not %s\n",str); + fclose(mesh_file); + return false; + } + int version = -1; + if(2 != sscanf(line,"%s %d",str,&version)) { fscanf(mesh_file," %d",&version); } + if(version != 1 && version != 2) + { + fprintf(stderr,"Error: second word should be 1 or 2 not %d\n",version); + fclose(mesh_file); + return false; + } + + while(eat_comments()) + { + sscanf(line," %s",str); + int extra; + // check that third word is Dimension + if(0==strcmp(str,"Dimension")) + { + int three = -1; + if(2 != sscanf(line,"%s %d",str,&three)) + { + // 1 appears on next line? + fscanf(mesh_file," %d",&three); + } + if(three != 3) + { + fprintf(stderr,"Error: only Dimension 3 supported not %d\n",three); + fclose(mesh_file); + return false; + } + }else if(0==strcmp(str,"Vertices")) + { + int number_of_vertices; + if(1 != fscanf(mesh_file," %d",&number_of_vertices) || number_of_vertices > 1000000000) + { + fprintf(stderr,"Error: expecting number of vertices less than 10^9...\n"); + fclose(mesh_file); + return false; + } + // allocate space for vertices + V.resize(number_of_vertices,3); + for(int i = 0;i, Eigen::Matrix, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readMESH, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/readMSH.cpp b/vendor/libigl/include/igl/readMSH.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e8a787b1ae0741ba7f7de1098b87c4a591770ca --- /dev/null +++ b/vendor/libigl/include/igl/readMSH.cpp @@ -0,0 +1,211 @@ +// high level interface for MshLoader +// +// Copyright (C) 2020 Vladimir Fonov +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "readMSH.h" +#include "MshLoader.h" +#include + +IGL_INLINE bool igl::readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri, + Eigen::MatrixXi &Tet, + Eigen::VectorXi &TriTag, + Eigen::VectorXi &TetTag, + std::vector &XFields, + std::vector &XF, + std::vector &EFields, + std::vector &TriF, + std::vector &TetF + ) +{ + try + { + igl::MshLoader _loader(msh); + const int USETAG = 1; + + #ifndef NDEBUG + std::cout<<"readMSH:Total number of nodes:" << _loader.get_nodes().size()<c_str() << ":" << _loader.get_node_fields()[i-std::begin(_loader.get_node_fields_names())].size() << std::endl; + } + + std::cout << "readMSH:Element fields:" << std::endl; + for(auto i=std::begin(_loader.get_element_fields_names()); i!=std::end(_loader.get_element_fields_names()); i++) + { + std::cout << i->c_str() << ":" << _loader.get_element_fields()[i-std::begin(_loader.get_element_fields_names())].size() << std::endl; + } + + if(_loader.is_element_map_identity()) + std::cout<<"readMSH:Element ids map is identity"< > + node_map( _loader.get_nodes().data(), _loader.get_nodes().size()/3, 3 ); + + X = node_map; + XFields = _loader.get_element_fields_names(); + XF.resize(_loader.get_node_fields().size()); + XFields = _loader.get_node_fields_names(); + for(size_t i=0;i<_loader.get_node_fields().size();++i) + { + Eigen::Map< const Eigen::Matrix > + field_map( _loader.get_node_fields()[i].data(), + _loader.get_node_fields()[i].size()/_loader.get_node_fields_components()[i], + _loader.get_node_fields_components()[i] ); + XF[i] = field_map; + } + + // calculate number of elements + std::map element_counts; + + for(auto i:_loader.get_elements_types()) + { + auto j=element_counts.insert({i,1}); + if(!j.second) (*j.first).second+=1; + } + #ifndef NDEBUG + std::cout<<"ReadMSH: elements found"<second; + if(n_tet_el_!=std::end(element_counts)) + n_tet_el=n_tet_el_->second; + + Tri.resize(n_tri_el,3); + Tet.resize(n_tet_el,4); + TriTag.resize(n_tri_el); + TetTag.resize(n_tet_el); + size_t el_start = 0; + TriF.resize(_loader.get_element_fields().size()); + TetF.resize(_loader.get_element_fields().size()); + for(size_t i=0;i<_loader.get_element_fields().size();++i) + { + TriF[i].resize(n_tri_el,_loader.get_element_fields_components()[i]); + TetF[i].resize(n_tet_el,_loader.get_element_fields_components()[i]); + } + EFields = _loader.get_element_fields_names(); + int i_tri = 0; + int i_tet = 0; + + for(size_t i=0;i<_loader.get_elements_lengths().size();++i) + { + if(_loader.get_elements_types()[i]==MshLoader::ELEMENT_TRI ) + { + assert(_loader.get_elements_lengths()[i]==3); + + Tri(i_tri, 0) = _loader.get_elements()[el_start ]; + Tri(i_tri, 1) = _loader.get_elements()[el_start+1]; + Tri(i_tri, 2) = _loader.get_elements()[el_start+2]; + + TriTag(i_tri) = _loader.get_elements_tags()[1][i]; + + for(size_t j=0;j<_loader.get_element_fields().size();++j) + for(size_t k=0;k<_loader.get_element_fields_components()[j];++k) + TriF[j](i_tri,k) = _loader.get_element_fields()[j][_loader.get_element_fields_components()[j]*i+k]; + + ++i_tri; + } else if(_loader.get_elements_types()[i]==MshLoader::ELEMENT_TET ) { + assert(_loader.get_elements_lengths()[i]==4); + + Tet(i_tet, 0) = _loader.get_elements()[el_start ]; + Tet(i_tet, 1) = _loader.get_elements()[el_start+1]; + Tet(i_tet, 2) = _loader.get_elements()[el_start+2]; + Tet(i_tet, 3) = _loader.get_elements()[el_start+3]; + + TetTag(i_tet) = _loader.get_elements_tags()[USETAG][i]; + + for(size_t j=0;j<_loader.get_element_fields().size();++j) + for(size_t k=0;k<_loader.get_element_fields_components()[j];++k) + TetF[j](i_tet,k) = _loader.get_element_fields()[j][_loader.get_element_fields_components()[j]*i+k]; + + ++i_tet; + } else { + // else: it's unsupported type of the element, ignore for now + std::cerr<<"readMSH: unsupported element type: "<<_loader.get_elements_types()[i] << + ", length: "<< _loader.get_elements_lengths()[i] < XFields; + std::vector XF; + std::vector EFields; + std::vector TriF; + std::vector TetF; + return igl::readMSH(msh,X,Tri,Tet,TriTag,TetTag,XFields,XF,EFields,TriF,TetF); +} + +IGL_INLINE bool igl::readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri, + Eigen::VectorXi &TriTag + ) +{ + Eigen::MatrixXi Tet; + Eigen::VectorXi TetTag; + + std::vector XFields; + std::vector XF; + std::vector EFields; + std::vector TriF; + std::vector TetF; + + return igl::readMSH(msh,X,Tri,Tet,TriTag,TetTag,XFields,XF,EFields,TriF,TetF); +} + +IGL_INLINE bool igl::readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri + ) +{ + Eigen::MatrixXi Tet; + Eigen::VectorXi TetTag; + Eigen::VectorXi TriTag; + + std::vector XFields; + std::vector XF; + std::vector EFields; + std::vector TriF; + std::vector TetF; + + return igl::readMSH(msh,X,Tri,Tet,TriTag,TetTag,XFields,XF,EFields,TriF,TetF); +} diff --git a/vendor/libigl/include/igl/readMSH.h b/vendor/libigl/include/igl/readMSH.h new file mode 100644 index 0000000000000000000000000000000000000000..53f5f8e09ee3076a8f962ec4b81351b1777a1083 --- /dev/null +++ b/vendor/libigl/include/igl/readMSH.h @@ -0,0 +1,103 @@ +// high level interface for MshLoader.h/.cpp + +// Copyright (C) 2020 Vladimir Fonov +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distribute +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READ_MSH_H +#define IGL_READ_MSH_H +#include "igl_inline.h" + +#include +#include +#include + + +namespace igl +{ + // read triangle surface mesh and tetrahedral volume mesh from .msh file + // Inputs: + // msh - file name + // Outputs: + // X eigen double matrix of vertex positions #X by 3 + // Tri #Tri eigen integer matrix of triangular faces indices into vertex positions + // Tet #Tet eigen integer matrix of tetrahedral indices into vertex positions + // TriTag #Tri eigen integer vector of tags associated with surface faces + // TetTag #Tet eigen integer vector of tags associated with volume elements + // XFields #XFields list of strings with field names associated with nodes + // XF #XFields list of eigen double matrices, fields associated with nodes + // EFields #EFields list of strings with field names associated with elements + // TriF #EFields list of eigen double matrices, fields associated with surface elements + // TetF #EFields list of eigen double matrices, fields associated with volume elements + // Known bugs: + // only version 2.2 of .msh file is supported (gmsh 3.X) + // only triangle surface elements and tetrahedral volumetric elements are supported + // only 3D information is supported + // only the 1st tag per element is returned (physical) + // same element fields are expected to be associated with surface elements and volumetric elements + IGL_INLINE bool readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri, + Eigen::MatrixXi &Tet, + Eigen::VectorXi &TriTag, + Eigen::VectorXi &TetTag, + std::vector &XFields, + std::vector &XF, + std::vector &EFields, + std::vector &TriF, + std::vector &TetF + ); + + // read triangle surface mesh and tetrahedral volume mesh from .msh file + // ignoring any fields + // Inputs: + // msh - file name + // Outputs: + // X eigen double matrix of vertex positions #X by 3 + // Tri #Tri eigen integer matrix of triangular faces indices into vertex positions + // Tet #Tet eigen integer matrix of tetrahedral indices into vertex positions + // TriTag #Tri eigen integer vector of tags associated with surface faces + // TetTag #Tet eigen integer vector of tags associated with volume elements + IGL_INLINE bool readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri, + Eigen::MatrixXi &Tet, + Eigen::VectorXi &TriTag, + Eigen::VectorXi &TetTag + ); + + // read triangle surface mesh and tetrahedral volume mesh from .msh file + // ignoring any fields, and any volumetric elements + // Inputs: + // msh - file name + // Outputs: + // X eigen double matrix of vertex positions #X by 3 + // Tri #Tri eigen integer matrix of triangular faces indices into vertex positions + // TriTag #Tri eigen integer vector of tags associated with surface faces + IGL_INLINE bool readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri, + Eigen::VectorXi &TriTag + ); + + // read triangle surface mesh and tetrahedral volume mesh from .msh file + // ignoring any fields, and any volumetric elements and tags + // Inputs: + // msh - file name + // Outputs: + // X eigen double matrix of vertex positions #X by 3 + // Tri #Tri eigen integer matrix of triangular faces indices into vertex positions + IGL_INLINE bool readMSH(const std::string &msh, + Eigen::MatrixXd &X, + Eigen::MatrixXi &Tri + ); + +} + + +#ifndef IGL_STATIC_LIBRARY +# include "readMSH.cpp" +#endif + +#endif //IGL_READ_MSH_H diff --git a/vendor/libigl/include/igl/readNODE.h b/vendor/libigl/include/igl/readNODE.h new file mode 100644 index 0000000000000000000000000000000000000000..a4bdb4774ad86038f78863cc0f81059e9ac77107 --- /dev/null +++ b/vendor/libigl/include/igl/readNODE.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READNODE_H +#define IGL_READNODE_H +#include "igl_inline.h" + +#include +#include +#include + +namespace igl +{ + // load a list of points from a .node file + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Index type for indices (will be read as int and cast to Index) + // Input: + // node_file_name path of .node file + // Outputs: + // V double matrix of vertex positions #V by dim + // I list of indices (first tells whether 0 or 1 indexed) + template + IGL_INLINE bool readNODE( + const std::string node_file_name, + std::vector > & V, + std::vector > & I); + + // Input: + // node_file_name path of .node file + // Outputs: + // V eigen double matrix #V by dim + template + IGL_INLINE bool readNODE( + const std::string node_file_name, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& I); +} + +#ifndef IGL_STATIC_LIBRARY +# include "readNODE.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/readOFF.cpp b/vendor/libigl/include/igl/readOFF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11d7e0efc80f21e06efd11f047a39d5e1354fd81 --- /dev/null +++ b/vendor/libigl/include/igl/readOFF.cpp @@ -0,0 +1,268 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "readOFF.h" +#include "list_to_matrix.h" + +template +IGL_INLINE bool igl::readOFF( + const std::string off_file_name, + std::vector > & V, + std::vector > & F, + std::vector > & N, + std::vector > & C) +{ + using namespace std; + FILE * off_file = fopen(off_file_name.c_str(),"r"); + if(NULL==off_file) + { + printf("IOError: %s could not be opened...\n",off_file_name.c_str()); + return false; + } + return readOFF(off_file,V,F,N,C); +} + +template +IGL_INLINE bool igl::readOFF( + FILE * off_file, + std::vector > & V, + std::vector > & F, + std::vector > & N, + std::vector > & C) +{ + using namespace std; + V.clear(); + F.clear(); + N.clear(); + C.clear(); + + // First line is always OFF + char header[1000]; + const std::string OFF("OFF"); + const std::string NOFF("NOFF"); + const std::string COFF("COFF"); + if(fscanf(off_file,"%s\n",header)!=1 + || !( + string(header).compare(0, OFF.length(), OFF)==0 || + string(header).compare(0, COFF.length(), COFF)==0 || + string(header).compare(0,NOFF.length(),NOFF)==0)) + { + printf("Error: readOFF() first line should be OFF or NOFF or COFF, not %s...",header); + fclose(off_file); + return false; + } + bool has_normals = string(header).compare(0,NOFF.length(),NOFF)==0; + bool has_vertexColors = string(header).compare(0,COFF.length(),COFF)==0; + // Second line is #vertices #faces #edges + int number_of_vertices; + int number_of_faces; + int number_of_edges; + char tic_tac_toe; + char line[1000]; + bool still_comments = true; + while(still_comments) + { + fgets(line,1000,off_file); + still_comments = (line[0] == '#' || line[0] == '\n'); + } + sscanf(line,"%d %d %d",&number_of_vertices,&number_of_faces,&number_of_edges); + V.resize(number_of_vertices); + if (has_normals) + N.resize(number_of_vertices); + if (has_vertexColors) + C.resize(number_of_vertices); + F.resize(number_of_faces); + //printf("%s %d %d %d\n",(has_normals ? "NOFF" : "OFF"),number_of_vertices,number_of_faces,number_of_edges); + // Read vertices + for(int i = 0;i= 3) + { + std::vector vertex; + vertex.resize(3); + vertex[0] = x; + vertex[1] = y; + vertex[2] = z; + V[i] = vertex; + + if (has_normals) + { + std::vector normal; + normal.resize(3); + normal[0] = nx; + normal[1] = ny; + normal[2] = nz; + N[i] = normal; + } + + if (has_vertexColors) + { + C[i].resize(3); + C[i][0] = nx / 255.0; + C[i][1] = ny / 255.0; + C[i][2] = nz / 255.0; + } + i++; + }else if( + fscanf(off_file,"%[#]",&tic_tac_toe)==1) + { + char comment[1000]; + fscanf(off_file,"%[^\n]",comment); + }else + { + printf("Error: bad line (%d)\n",i); + if(feof(off_file)) + { + fclose(off_file); + return false; + } + } + } + // Read faces + for(int i = 0;i face; + int valence; + if(fscanf(off_file,"%d",&valence)==1) + { + face.resize(valence); + for(int j = 0;j +IGL_INLINE bool igl::readOFF( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F) +{ + std::vector > vV; + std::vector > vN; + std::vector > vF; + std::vector > vC; + bool success = igl::readOFF(str,vV,vF,vN,vC); + if(!success) + { + // readOFF(str,vV,vF,vN,vC) should have already printed an error + // message to stderr + return false; + } + bool V_rect = igl::list_to_matrix(vV,V); + if(!V_rect) + { + // igl::list_to_matrix(vV,V) already printed error message to std err + return false; + } + bool F_rect = igl::list_to_matrix(vF,F); + if(!F_rect) + { + // igl::list_to_matrix(vF,F) already printed error message to std err + return false; + } + return true; +} + + +template +IGL_INLINE bool igl::readOFF( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + Eigen::PlainObjectBase& N) +{ + std::vector > vV; + std::vector > vN; + std::vector > vF; + std::vector > vC; + bool success = igl::readOFF(str,vV,vF,vN,vC); + if(!success) + { + // readOFF(str,vV,vF,vC) should have already printed an error + // message to stderr + return false; + } + bool V_rect = igl::list_to_matrix(vV,V); + if(!V_rect) + { + // igl::list_to_matrix(vV,V) already printed error message to std err + return false; + } + bool F_rect = igl::list_to_matrix(vF,F); + if(!F_rect) + { + // igl::list_to_matrix(vF,F) already printed error message to std err + return false; + } + + if (vN.size()) + { + bool N_rect = igl::list_to_matrix(vN,N); + if(!N_rect) + { + // igl::list_to_matrix(vN,N) already printed error message to std err + return false; + } + } + + //Warning: RGB colors will be returned in the N matrix + if (vC.size()) + { + bool C_rect = igl::list_to_matrix(vC,N); + if(!C_rect) + { + // igl::list_to_matrix(vC,N) already printed error message to std err + return false; + } + } + + return true; +} +#endif + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::readOFF(std::basic_string, std::allocator >, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +// generated by autoexplicit.sh +template bool igl::readOFF, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::readOFF, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readOFF, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readOFF, Eigen::Matrix >(std::string, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readOFF, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/readOFF.h b/vendor/libigl/include/igl/readOFF.h new file mode 100644 index 0000000000000000000000000000000000000000..3d8c41fa52449f118d004b7cf0ddbfd4527c1421 --- /dev/null +++ b/vendor/libigl/include/igl/readOFF.h @@ -0,0 +1,86 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READOFF_H +#define IGL_READOFF_H +#include "igl_inline.h" +// History: +// return type changed from void to bool Alec 18 Sept 2011 + +#ifndef IGL_NO_EIGEN +# include +#endif +#include +#include +#include + +namespace igl +{ + + // Read a mesh from an ascii OFF file, filling in vertex positions, normals + // and texture coordinates. Mesh may have faces of any number of degree + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Index type for indices (will be read as int and cast to Index) + // Inputs: + // str path to .obj file + // Outputs: + // V double matrix of vertex positions #V by 3 + // F #F list of face indices into vertex positions + // N list of vertex normals #V by 3 + // C list of rgb color values per vertex #V by 3 + // Returns true on success, false on errors + template + IGL_INLINE bool readOFF( + const std::string off_file_name, + std::vector > & V, + std::vector > & F, + std::vector > & N, + std::vector > & C); + // Inputs: + // off_file pointer to already opened .off file + // Outputs: + // off_file closed file + template + IGL_INLINE bool readOFF( + FILE * off_file, + std::vector > & V, + std::vector > & F, + std::vector > & N, + std::vector > & C); + + +#ifndef IGL_NO_EIGEN + // read mesh from a ascii off file + // Inputs: + // str path to .off file + // Outputs: + // V eigen double matrix #V by 3 + // F eigen int matrix #F by 3 + template + IGL_INLINE bool readOFF( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F); + + template + IGL_INLINE bool readOFF( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + Eigen::PlainObjectBase& N); +#endif + +} + +#ifndef IGL_STATIC_LIBRARY +# include "readOFF.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/readPLY.cpp b/vendor/libigl/include/igl/readPLY.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61080b3b7f59b4c85edecf6747f1dacf414a3e84 --- /dev/null +++ b/vendor/libigl/include/igl/readPLY.cpp @@ -0,0 +1,644 @@ +#include "readPLY.h" +#include +#include +#include +#include +#include + +#include "tinyply.h" +#include "read_file_binary.h" +#include "FileMemoryStream.h" + + +namespace igl +{ + +template +IGL_INLINE bool _tinyply_buffer_to_matrix( + tinyply::PlyData & D, + Eigen::PlainObjectBase & M, + size_t rows, + size_t cols ) +{ + Eigen::Map< Eigen::Matrix > + _map( reinterpret_cast( D.buffer.get()), rows, cols ); + + M = _map.template cast(); + return true; +} + + + +template +IGL_INLINE bool tinyply_buffer_to_matrix( + tinyply::PlyData & D, + Eigen::PlainObjectBase & M, + size_t rows, + size_t cols ) +{ + switch(D.t) + { + case tinyply::Type::INT8 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::UINT8 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::INT16 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::UINT16 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::INT32 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::UINT32 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::FLOAT32 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + case tinyply::Type::FLOAT64 : + return _tinyply_buffer_to_matrix(D, M,rows,cols); + default: + return false; + } +} + + +template +IGL_INLINE bool _tinyply_tristrips_to_trifaces( + tinyply::PlyData & D, + Eigen::PlainObjectBase & M, + size_t el, + size_t el_len ) +{ + + Eigen::Map< Eigen::Matrix > + _map( reinterpret_cast( D.buffer.get()), el, el_len ); + + // to make it more interesting, triangles in triangle strip can be separated by negative index elements + // 1. count all triangles + size_t triangles=0; + + // TODO: it's possible to optimize this , i suppose + for(size_t i=0; i=0 && _map(i,j+1)>=0 && _map(i,j+2)>=0) + triangles++; + } + + // 2. convert triangles to faces, skipping over the negative indeces, indicating separate strips + M.resize(triangles, 3); + size_t k=0; + for(size_t i=0; i=0 && _map(i,j+1)>=0 && _map(i,j+2)>=0) + { + // consequtive faces on the same strip have to be flip-flopped, to preserve orientation + M( k,0 ) = static_cast( _map(i, j ) ); + M( k,1 ) = static_cast( _map(i, j+1+flip ) ); + M( k,2 ) = static_cast( _map(i, j+1+(flip^1) ) ); + k++; + flip ^= 1; + } else { + // reset flip on new strip start + flip = 0; + } + } + } + assert(k==triangles); + return true; +} + +template +IGL_INLINE bool tinyply_tristrips_to_faces( + tinyply::PlyData & D, + Eigen::PlainObjectBase & M, + size_t el, + size_t el_len ) +{ + switch(D.t) + { + case tinyply::Type::INT8 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::UINT8 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::INT16 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::UINT16 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::INT32 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::UINT32 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::FLOAT32 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + case tinyply::Type::FLOAT64 : + return _tinyply_tristrips_to_trifaces(D, M,el,el_len); + default: + return false; + } +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED + > +IGL_INLINE bool readPLY( + FILE *fp, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & UV, + + Eigen::PlainObjectBase & VD, + std::vector & Vheader, + Eigen::PlainObjectBase & FD, + std::vector & Fheader, + Eigen::PlainObjectBase & ED, + std::vector & Eheader, + std::vector & comments + ) +{ + // buffer the whole file in memory + // then read from memory buffer + try + { + std::vector fileBufferBytes; + // read_file_binary will call fclose + read_file_binary(fp,fileBufferBytes); + FileMemoryStream stream((char*)fileBufferBytes.data(), fileBufferBytes.size()); + return readPLY(stream,V,F,E,N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); + } + catch(const std::exception& e) + { + std::cerr << "ReadPLY error: " << e.what() << std::endl; + } + fclose(fp); + return false; +} + + + +template < + typename DerivedV, + typename DerivedF + > +IGL_INLINE bool readPLY( + FILE *fp, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F + ) +{ + Eigen::MatrixXd N,UV,VD,FD,ED; + Eigen::MatrixXi E; + std::vector Vheader,Eheader,Fheader,comments; + return readPLY(fp,V,F,E,N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE + > +IGL_INLINE bool readPLY( + FILE *fp, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E + ) +{ + Eigen::MatrixXd N,UV,VD,FD,ED; + std::vector Vheader,Eheader,Fheader,comments; + return readPLY(fp,V,F,E,N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED + > +IGL_INLINE bool readPLY( + std::istream & ply_stream, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & UV, + + Eigen::PlainObjectBase & VD, + std::vector & Vheader, + Eigen::PlainObjectBase & FD, + std::vector & Fheader, + Eigen::PlainObjectBase & ED, + std::vector & Eheader, + std::vector & comments + ) +{ + tinyply::PlyFile file; + file.parse_header(ply_stream); + + std::set vertex_std{ "x","y","z", "nx","ny","nz", "u","v", "texture_u", "texture_v", "s", "t"}; + std::set face_std { "vertex_index", "vertex_indices"}; + std::set edge_std { "vertex1", "vertex2"}; //non-standard edge indexes + + // Tinyply treats parsed data as untyped byte buffers. + std::shared_ptr vertices, normals, faces, texcoords, edges; + + // Some ply files contain tristrips instead of faces + std::shared_ptr tristrips; + + std::shared_ptr _vertex_data; + std::vector _vertex_header; + + std::shared_ptr _face_data; + std::vector _face_header; + + std::shared_ptr _edge_data; + std::vector _edge_header; + + for (auto c : file.get_comments()) + comments.push_back(c); + + for (auto e : file.get_elements()) + { + if(e.name == "vertex" ) // found a vertex + { + for (auto p : e.properties) + { + if(vertex_std.find(p.name) == vertex_std.end()) + { + _vertex_header.push_back(p.name); + } + } + } + else if(e.name == "face" ) // found face + { + for (auto p : e.properties) + { + if(face_std.find(p.name) == face_std.end()) + { + _face_header.push_back(p.name); + } + } + } + else if(e.name == "edge" ) // found edge + { + for (auto p : e.properties) + { + if(edge_std.find(p.name) == edge_std.end()) + { + _edge_header.push_back(p.name); + } + } + } + // skip the unknown entries + } + + // The header information can be used to programmatically extract properties on elements + // known to exist in the header prior to reading the data. For brevity of this sample, properties + // like vertex position are hard-coded: + try { + vertices = file.request_properties_from_element("vertex", { "x", "y", "z" }); + } + catch (const std::exception & ) { } + + try { + normals = file.request_properties_from_element("vertex", { "nx", "ny", "nz" }); + } + catch (const std::exception & ) { } + + //Try texture coordinates with several names + try { + //texture_u texture_v are the names used by meshlab to store textures + texcoords = file.request_properties_from_element("vertex", { "texture_u", "texture_v" }); + } + catch (const std::exception & ) { } + if (!texcoords) + { + try { + //u v are the naive names + texcoords = file.request_properties_from_element("vertex", { "u", "v" }); + } + catch (const std::exception & ) { } + + } + if (!texcoords) + { + try { + //s t were the names used by blender and the previous libigl PLY reader. + texcoords = file.request_properties_from_element("vertex", { "s", "t" }); + } + catch (const std::exception & ) { } + + } + + // Providing a list size hint (the last argument) is a 2x performance improvement. If you have + // arbitrary ply files, it is best to leave this 0. + try { + faces = file.request_properties_from_element( "face", { "vertex_indices" }, 0); + } + catch (const std::exception & ) { } + + if (!faces) + { + try { + // alternative name of the elements + faces = file.request_properties_from_element( "face", { "vertex_index" },0); + } + catch (const std::exception & ) { } + } + + if (!faces) + { + try { + // try using tristrips + tristrips = file.request_properties_from_element( "tristrips", { "vertex_indices" }, 0); + } + catch (const std::exception & ) { } + + if (!tristrips) + { + try { + // alternative name of the elements + tristrips = file.request_properties_from_element( "tristrips", { "vertex_index" }, 0); + } + catch (const std::exception & ) { } + } + } + + + try { + edges = file.request_properties_from_element("edge", { "vertex1", "vertex2" }); + } + catch (const std::exception & ) { } + + if(! _vertex_header.empty()) + _vertex_data = file.request_properties_from_element( "vertex", _vertex_header); + if(! _face_header.empty()) + _face_data = file.request_properties_from_element( "face", _face_header); + if(! _edge_header.empty()) + _edge_data = file.request_properties_from_element( "edge", _edge_header); + + // Parse the geometry data + file.read(ply_stream); + + if (!vertices || !tinyply_buffer_to_matrix(*vertices,V,vertices->count,3) ) { + V.resize(0,0); + } + + if (!normals || !tinyply_buffer_to_matrix(*normals,N,normals->count,3) ) { + N.resize(0,0); + } + + if (!texcoords || !tinyply_buffer_to_matrix(*texcoords,UV,texcoords->count,2) ) { + UV.resize(0,0); + } + + //HACK: Unfortunately, tinyply doesn't store list size as a separate variable + if (!faces || !tinyply_buffer_to_matrix(*faces, F, faces->count, faces->count==0?0:faces->buffer.size_bytes()/(tinyply::PropertyTable[faces->t].stride*faces->count) )) { + + if(tristrips) { // need to convert to faces + // code based on blender importer for ply + // converting triangle strips into triangles + // tinyply supports tristrips of the same length only + size_t el_count = tristrips->buffer.size_bytes()/(tinyply::PropertyTable[tristrips->t].stride*tristrips->count); + + // all strips should have tristrips->count elements + if(!tinyply_tristrips_to_faces(*tristrips, F , tristrips->count, el_count)) + F.resize(0,0); + + } else { + F.resize(0,0); + } + } + + if(!edges || !tinyply_buffer_to_matrix(*edges,E, edges->count,2)) { + E.resize(0,0); + } + + /// convert vertex data: + Vheader=_vertex_header; + if(_vertex_header.empty()) + { + VD.resize(0,0); + } + else + { + VD.resize(vertices->count,_vertex_header.size()); + tinyply_buffer_to_matrix(*_vertex_data, VD, vertices->count, _vertex_header.size()); + } + + /// convert face data: + Fheader=_face_header; + if(_face_header.empty()) + { + FD.resize(0,0); + } + else + { + FD.resize(faces->count, _face_header.size()); + tinyply_buffer_to_matrix(*_face_data, FD, faces->count, _face_header.size()); + } + + /// convert edge data: + Eheader=_edge_header; + if(_edge_header.empty()) + { + ED.resize(0,0); + } + else + { + ED.resize(_edge_data->count, _edge_header.size()); + tinyply_buffer_to_matrix(*_edge_data, ED, _edge_data->count, _edge_header.size()); + } + return true; +} + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED + > +IGL_INLINE bool readPLY( + const std::string& ply_file, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & UV, + + Eigen::PlainObjectBase & VD, + std::vector & VDheader, + + Eigen::PlainObjectBase & FD, + std::vector & FDheader, + + Eigen::PlainObjectBase & ED, + std::vector & EDheader, + std::vector & comments + ) +{ + + std::ifstream ply_stream(ply_file, std::ios::binary); + if (ply_stream.fail()) + { + std::cerr << "ReadPLY: Error opening file " << ply_file << std::endl; + return false; + } + try + { + return readPLY(ply_stream, V, F, E, N, UV, VD, VDheader, FD,FDheader, ED, EDheader, comments ); + } catch (const std::exception& e) { + std::cerr << "ReadPLY error: " << ply_file << e.what() << std::endl; + } + return false; +} + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedD + > +IGL_INLINE bool readPLY( + const std::string & filename, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & UV, + Eigen::PlainObjectBase & VD, + std::vector & Vheader + ) +{ + Eigen::MatrixXd FD,ED; + std::vector Fheader,Eheader; + std::vector comments; + return readPLY(filename,V,F,E,N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV + > +IGL_INLINE bool readPLY( + const std::string & filename, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & UV + ) +{ + Eigen::MatrixXd VD,FD,ED; + std::vector Vheader,Fheader,Eheader; + std::vector comments; + return readPLY(filename,V,F,E, N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedN, + typename DerivedUV + > +IGL_INLINE bool readPLY( + const std::string & filename, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & N, + Eigen::PlainObjectBase & UV + ) +{ + Eigen::MatrixXd VD,FD,ED; + Eigen::MatrixXi E; + std::vector Vheader,Fheader,Eheader; + std::vector comments; + return readPLY(filename,V,F,E, N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + +template < + typename DerivedV, + typename DerivedF + > +IGL_INLINE bool readPLY( + const std::string & filename, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F + ) +{ + Eigen::MatrixXd N,UV; + Eigen::MatrixXd VD,FD,ED; + Eigen::MatrixXi E; + + std::vector Vheader,Fheader,Eheader; + std::vector comments; + return readPLY(filename,V,F,E,N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE + > +IGL_INLINE bool readPLY( + const std::string & filename, + Eigen::PlainObjectBase & V, + Eigen::PlainObjectBase & F, + Eigen::PlainObjectBase & E + ) +{ + Eigen::MatrixXd N,UV; + Eigen::MatrixXd VD,FD,ED; + + std::vector Vheader,Fheader,Eheader; + std::vector comments; + return readPLY(filename,V,F,E,N,UV,VD,Vheader,FD,Fheader,ED,Eheader,comments); +} + + +} //igl namespace + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::readPLY, Eigen::Matrix >(FILE*, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); + +template bool igl::readPLY, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&, Eigen::PlainObjectBase >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&, Eigen::PlainObjectBase >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&); +template bool igl::readPLY, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&, Eigen::PlainObjectBase >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&, Eigen::PlainObjectBase >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&, std::vector, std::allocator >, std::allocator, std::allocator > > >&); +#endif diff --git a/vendor/libigl/include/igl/readTGF.h b/vendor/libigl/include/igl/readTGF.h new file mode 100644 index 0000000000000000000000000000000000000000..68c5ddef8d72b49abcef6897a4450a4ea027806f --- /dev/null +++ b/vendor/libigl/include/igl/readTGF.h @@ -0,0 +1,66 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READTGF_H +#define IGL_READTGF_H +#include "igl_inline.h" + +#include +#include +#ifndef IGL_NO_EIGEN +#include +#endif + +namespace igl +{ + // READTGF + // + // [V,E,P,BE,CE,PE] = readTGF(filename) + // + // Read a graph from a .tgf file + // + // Input: + // filename .tgf file name + // Output: + // V # vertices by 3 list of vertex positions + // E # edges by 2 list of edge indices + // P # point-handles list of point handle indices + // BE # bone-edges by 2 list of bone-edge indices + // CE # cage-edges by 2 list of cage-edge indices + // PE # pseudo-edges by 2 list of pseudo-edge indices + // + // Assumes that graph vertices are 3 dimensional + IGL_INLINE bool readTGF( + const std::string tgf_filename, + std::vector > & C, + std::vector > & E, + std::vector & P, + std::vector > & BE, + std::vector > & CE, + std::vector > & PE); + + #ifndef IGL_NO_EIGEN + IGL_INLINE bool readTGF( + const std::string tgf_filename, + Eigen::MatrixXd & C, + Eigen::MatrixXi & E, + Eigen::VectorXi & P, + Eigen::MatrixXi & BE, + Eigen::MatrixXi & CE, + Eigen::MatrixXi & PE); + IGL_INLINE bool readTGF( + const std::string tgf_filename, + Eigen::MatrixXd & C, + Eigen::MatrixXi & E); + #endif +} + +#ifndef IGL_STATIC_LIBRARY +# include "readTGF.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/readWRL.cpp b/vendor/libigl/include/igl/readWRL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce6de3e733957ddc3ea498cd31787e6154d8700e --- /dev/null +++ b/vendor/libigl/include/igl/readWRL.cpp @@ -0,0 +1,121 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "readWRL.h" +#include + +template +IGL_INLINE bool igl::readWRL( + const std::string wrl_file_name, + std::vector > & V, + std::vector > & F) +{ + using namespace std; + FILE * wrl_file = fopen(wrl_file_name.c_str(),"r"); + if(NULL==wrl_file) + { + printf("IOError: %s could not be opened...",wrl_file_name.c_str()); + return false; + } + return readWRL(wrl_file,V,F); +} + +template +IGL_INLINE bool igl::readWRL( + FILE * wrl_file, + std::vector > & V, + std::vector > & F) +{ + using namespace std; + + char line[1000]; + // Read lines until seeing "point [" + // treat other lines in file as "comments" + bool still_comments = true; + string needle("point ["); + string haystack; + while(still_comments) + { + if(fgets(line,1000,wrl_file) == NULL) + { + std::cerr<<"readWRL, reached EOF without finding \"point [\""< point; + point.resize(3); + point[0] = x; + point[1] = y; + point[2] = z; + V.push_back(point); + //printf("(%g, %g, %g)\n",x,y,z); + }else if(floats_read != 0) + { + printf("ERROR: unrecognized format...\n"); + return false; + } + } + // Read lines until seeing "coordIndex [" + // treat other lines in file as "comments" + still_comments = true; + needle = string("coordIndex ["); + while(still_comments) + { + fgets(line,1000,wrl_file); + haystack = string(line); + still_comments = string::npos == haystack.find(needle); + } + // read F + int ints_read = 1; + while(ints_read > 0) + { + // read new face indices (until hit -1) + vector face; + while(true) + { + // indices are 0-indexed + int i; + ints_read = fscanf(wrl_file," %d,",&i); + if(ints_read > 0) + { + if(i>=0) + { + face.push_back(i); + }else + { + F.push_back(face); + break; + } + }else + { + break; + } + } + } + + + + fclose(wrl_file); + return true; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template bool igl::readWRL(std::basic_string, std::allocator >, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +#endif diff --git a/vendor/libigl/include/igl/readWRL.h b/vendor/libigl/include/igl/readWRL.h new file mode 100644 index 0000000000000000000000000000000000000000..45c1fa0484617d74a1e25c9d38abe4092ef4183e --- /dev/null +++ b/vendor/libigl/include/igl/readWRL.h @@ -0,0 +1,53 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READWRL_H +#define IGL_READWRL_H +#include "igl_inline.h" + +#include +#include +#include + +namespace igl +{ + // Read a mesh from an ascii wrl file, filling in vertex positions and face + // indices of the first model. Mesh may have faces of any number of degree + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Index type for indices (will be read as int and cast to Index) + // Inputs: + // str path to .wrl file + // Outputs: + // V double matrix of vertex positions #V by 3 + // F #F list of face indices into vertex positions + // Returns true on success, false on errors + template + IGL_INLINE bool readWRL( + const std::string wrl_file_name, + std::vector > & V, + std::vector > & F); + // Inputs: + // wrl_file pointer to already opened .wrl file + // Outputs: + // wrl_file closed file + template + IGL_INLINE bool readWRL( + FILE * wrl_file, + std::vector > & V, + std::vector > & F); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "readWRL.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/read_file_binary.h b/vendor/libigl/include/igl/read_file_binary.h new file mode 100644 index 0000000000000000000000000000000000000000..2c2a1488ea9a56d11cc2a712fc28c4dd8ad568fb --- /dev/null +++ b/vendor/libigl/include/igl/read_file_binary.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Jérémie Dumas +// Copyright (C) 2021 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READ_FILE_BINARY_H +#define IGL_READ_FILE_BINARY_H + +#include "igl_inline.h" + +#include +#include +#include +#include + +namespace igl { + + // Read contents of file into a buffer of uint8_t bytes. + // + // Input: + // fp pointer to open File + // Outputs: + // fileBufferBytes contents of file as vector of bytes + // Side effects: + // closes fp + // Throws runtime_error on error + IGL_INLINE void read_file_binary( + FILE *fp, + std::vector &fileBufferBytes); +} + +#ifndef IGL_STATIC_LIBRARY +#include "read_file_binary.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/read_triangle_mesh.cpp b/vendor/libigl/include/igl/read_triangle_mesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f6180a345afb1da71f6bc1935c905a92d5a04951 --- /dev/null +++ b/vendor/libigl/include/igl/read_triangle_mesh.cpp @@ -0,0 +1,225 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "read_triangle_mesh.h" + +#include "list_to_matrix.h" +#include "readMSH.h" +#include "readMESH.h" +#include "readOBJ.h" +#include "readOFF.h" +#include "readSTL.h" +#include "readPLY.h" +#include "readWRL.h" +#include "pathinfo.h" +#include "boundary_facets.h" +#include "polygon_corners.h" +#include "polygons_to_triangles.h" + +#include +#include + + +template +IGL_INLINE bool igl::read_triangle_mesh( + const std::string str, + std::vector > & V, + std::vector > & F) +{ + using namespace std; + // dirname, basename, extension and filename + string d,b,e,f; + pathinfo(str,d,b,e,f); + // Convert extension to lower case + std::transform(e.begin(), e.end(), e.begin(), ::tolower); + vector > TC, N, C; + vector > FTC, FN; + if(e == "obj") + { + // Annoyingly obj can store 4 coordinates, truncate to xyz for this generic + // read_triangle_mesh + bool success = readOBJ(str,V,TC,N,F,FTC,FN); + for(auto & v : V) + { + v.resize(std::min(v.size(),(size_t)3)); + } + return success; + }else if(e == "off") + { + return readOFF(str,V,F,N,C); + } + cerr<<"Error: "<<__FUNCTION__<<": "<< + str<<" is not a recognized mesh file format."< +IGL_INLINE bool igl::read_triangle_mesh( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F) +{ + std::string _1,_2,_3,_4; + return read_triangle_mesh(str,V,F,_1,_2,_3,_4); +} + +template +IGL_INLINE bool igl::read_triangle_mesh( + const std::string filename, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + std::string & dir, + std::string & base, + std::string & ext, + std::string & name) +{ + using namespace std; + using namespace Eigen; + + // dirname, basename, extension and filename + pathinfo(filename,dir,base,ext,name); + // Convert extension to lower case + transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + // readMSH requires filename + if(ext == "msh") + { + // readMSH is not properly templated + Eigen::MatrixXd mV; + Eigen::MatrixXi mF,T; + Eigen::VectorXi _1,_2; + // *TetWild doesn't use Tri field... + //bool res = readMSH(filename,mV,mF); + bool res = readMSH(filename,mV,mF,T,_1,_2); + V = mV.template cast(); + if(mF.rows() == 0 && T.rows() > 0) + { + boundary_facets(T,F); + // outward facing + F = F.rowwise().reverse().eval(); + }else + { + F = mF.template cast(); + } + return res; + }else + { + FILE * fp = fopen(filename.c_str(),"rb"); + if(NULL==fp) + { + fprintf(stderr,"IOError: %s could not be opened...\n", + filename.c_str()); + return false; + } + return read_triangle_mesh(ext,fp,V,F); + } +} + +template +IGL_INLINE bool igl::read_triangle_mesh( + const std::string & ext, + FILE * fp, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F) +{ + using namespace std; + using namespace Eigen; + Eigen::MatrixXd N; + vector > vV,vN,vTC,vC; + vector > vF,vFTC,vFN; + vector> FM; + + if(ext == "mesh") + { + // Convert extension to lower case + MatrixXi T; + if(!readMESH(fp,V,T,F)) + { + return 1; + } + //if(F.size() > T.size() || F.size() == 0) + { + boundary_facets(T,F); + // outward facing + F = F.rowwise().reverse().eval(); + } + }else if(ext == "obj") + { + if(!readOBJ(fp,vV,vTC,vN,vF,vFTC,vFN,FM)) + { + return false; + } + // Annoyingly obj can store 4 coordinates, truncate to xyz for this generic + // read_triangle_mesh + for(auto & v : vV) + { + v.resize(std::min(v.size(),(size_t)3)); + } + }else if(ext == "off") + { + if(!readOFF(fp,vV,vF,vN,vC)) + { + return false; + } + }else if(ext == "ply") + { + return readPLY(fp, V, F); + + }else if(ext == "stl") + { + if(!readSTL(fp,V,F,N)) + { + return false; + } + }else if(ext == "wrl") + { + if(!readWRL(fp,vV,vF)) + { + return false; + } + }else + { + cerr<<"Error: unknown extension: "< 0) + { + if(!list_to_matrix(vV,V)) + { + return false; + } + { + Eigen::VectorXi I,C; + igl::polygon_corners(vF,I,C); + Eigen::VectorXi J; + igl::polygons_to_triangles(I,C,F,J); + } + } + return true; +} + +#endif + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::string, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, std::basic_string, std::allocator >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template bool igl::read_triangle_mesh(std::basic_string, std::allocator >, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +#endif diff --git a/vendor/libigl/include/igl/read_triangle_mesh.h b/vendor/libigl/include/igl/read_triangle_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..26b84c5f1f321a5cd5b36c671be5a4e3d3dc245a --- /dev/null +++ b/vendor/libigl/include/igl/read_triangle_mesh.h @@ -0,0 +1,80 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_READ_TRIANGLE_MESH_H +#define IGL_READ_TRIANGLE_MESH_H +#include "igl_inline.h" + +#ifndef IGL_NO_EIGEN +# include +#endif +#include +#include +#include +// History: +// renamed read -> read_triangle_mesh Daniele 24 June 2014 +// return type changed from void to bool Alec 18 Sept 2011 + +namespace igl +{ + // read mesh from an ascii file with automatic detection of file format. + // supported: obj, off, stl, wrl, ply, mesh) + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Index type for indices (will be read as int and cast to Index) + // Inputs: + // str path to file + // Outputs: + // V eigen double matrix #V by 3 + // F eigen int matrix #F by 3 + // Returns true iff success + template + IGL_INLINE bool read_triangle_mesh( + const std::string str, + std::vector > & V, + std::vector > & F); +#ifndef IGL_NO_EIGEN + template + IGL_INLINE bool read_triangle_mesh( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F); + // Outputs: + // dir directory path (see pathinfo.h) + // base base name (see pathinfo.h) + // ext extension (see pathinfo.h) + // name filename (see pathinfo.h) + template + IGL_INLINE bool read_triangle_mesh( + const std::string str, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F, + std::string & dir, + std::string & base, + std::string & ext, + std::string & name); + // Inputs: + // ext file extension + // fp pointer to already opened .ext file + // Outputs: + // fp closed file + template + IGL_INLINE bool read_triangle_mesh( + const std::string & ext, + FILE * fp, + Eigen::PlainObjectBase& V, + Eigen::PlainObjectBase& F); +#endif +} + +#ifndef IGL_STATIC_LIBRARY +# include "read_triangle_mesh.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/remesh_along_isoline.cpp b/vendor/libigl/include/igl/remesh_along_isoline.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c719ba9940d3c73ad59087b51b2f3ff6bf375c9 --- /dev/null +++ b/vendor/libigl/include/igl/remesh_along_isoline.cpp @@ -0,0 +1,167 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "remesh_along_isoline.h" +#include "list_to_matrix.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedS, + typename DerivedU, + typename DerivedG, + typename DerivedJ, + typename BCtype, + typename DerivedSU, + typename DerivedL> + IGL_INLINE void igl::remesh_along_isoline( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & S, + const typename DerivedS::Scalar val, + Eigen::PlainObjectBase & U, + Eigen::PlainObjectBase & G, + Eigen::PlainObjectBase & SU, + Eigen::PlainObjectBase & J, + Eigen::SparseMatrix & BC, + Eigen::PlainObjectBase & L) +{ + igl::remesh_along_isoline(V.rows(),F,S,val,G,SU,J,BC,L); + U = BC * V; +} + +template < + typename DerivedF, + typename DerivedS, + typename DerivedG, + typename DerivedJ, + typename BCtype, + typename DerivedSU, + typename DerivedL> + IGL_INLINE void igl::remesh_along_isoline( + const int num_vertices, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & S, + const typename DerivedS::Scalar val, + Eigen::PlainObjectBase & G, + Eigen::PlainObjectBase & SU, + Eigen::PlainObjectBase & J, + Eigen::SparseMatrix & BC, + Eigen::PlainObjectBase & L) +{ + // Lazy implementation using vectors + + //assert(val.size() == 1); + const int isoval_i = 0; + //auto isoval = val(isoval_i); + auto isoval = val; + std::vector > vG; + std::vector vJ; + std::vector vL; + std::vector > vBC; + int Ucount = 0; + for(int i = 0;i> edgeToBirthVert; + for(int f = 0;f isoval; + // Find crossings + const int n = (p+1)%3; + const bool nsign = S(F(f,n)) > isoval; + if(psign != nsign) + { + P[count] = p; + Psign[count] = psign; + // record crossing + count++; + } + } + + assert(count == 0 || count == 2); + switch(count) + { + case 0: + { + // Easy case + std::vector row = {F(f,0),F(f,1),F(f,2)}; + vG.push_back(row); + vJ.push_back(f); + vL.push_back( S(F(f,0))>isoval ? isoval_i+1 : isoval_i ); + break; + } + case 2: + { + // Cut case + // flip so that P[1] is the one-off vertex + if(P[0] == 0 && P[1] == 2) + { + std::swap(P[0],P[1]); + std::swap(Psign[0],Psign[1]); + } + assert(Psign[0] != Psign[1]); + // Create two new vertices + for(int i = 0;i<2;i++) + { + if ((edgeToBirthVert.find(F(f, P[i])) == edgeToBirthVert.end()) || (edgeToBirthVert.at(F(f, P[i])).find(F(f, (P[i] + 1) % 3)) == edgeToBirthVert.at(F(f, P[i])).end())) + { + const double bci = (isoval - S(F(f,(P[i]+1)%3)))/ + (S(F(f,P[i]))-S(F(f,(P[i]+1)%3))); + vBC.emplace_back(Ucount,F(f,P[i]),bci); + vBC.emplace_back(Ucount,F(f,(P[i]+1)%3),1.0-bci); + edgeToBirthVert[F(f, P[i])][F(f, (P[i] + 1) % 3)] = Ucount; + edgeToBirthVert[F(f, (P[i] + 1) % 3)][F(f, P[i])] = Ucount; + Ucount++; + } + } + const int v0 = F(f,P[0]); + assert(((P[0]+1)%3) == P[1]); + const int v1 = F(f,P[1]); + const int v2 = F(f,(P[1]+1)%3); + const int v01 = edgeToBirthVert[v0][v1]; + const int v12 = edgeToBirthVert[v1][v2]; + // v0 + // | \ + // | \ + // | \ + // v01 \ + // | \ + // | \ + // | \ + // v1--v12---v2 + typedef std::vector Row; + {Row row = {v01,v1,v12}; vG.push_back(row);vJ.push_back(f);vL.push_back(Psign[0]?isoval_i:isoval_i+1);} + {Row row = {v12,v2,v01}; vG.push_back(row);vJ.push_back(f);vL.push_back(Psign[1]?isoval_i:isoval_i+1);} + {Row row = {v2,v0,v01}; vG.push_back(row) ;vJ.push_back(f);vL.push_back(Psign[1]?isoval_i:isoval_i+1);} + break; + } + default: assert(false); + } + } + igl::list_to_matrix(vG,G); + igl::list_to_matrix(vJ,J); + igl::list_to_matrix(vL,L); + BC.resize(Ucount,num_vertices); + BC.setFromTriplets(vBC.begin(),vBC.end()); + SU = BC * S; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::remesh_along_isoline, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::Matrix::Scalar, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::SparseMatrix&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/remove_duplicate_vertices.cpp b/vendor/libigl/include/igl/remove_duplicate_vertices.cpp new file mode 100644 index 0000000000000000000000000000000000000000..318f55c2cd6bdb3c7aea5cf8067e90b1b0884c01 --- /dev/null +++ b/vendor/libigl/include/igl/remove_duplicate_vertices.cpp @@ -0,0 +1,87 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "remove_duplicate_vertices.h" +#include "round.h" +#include "unique_rows.h" +#include "colon.h" +#include "slice.h" +#include + +template < + typename DerivedV, + typename DerivedSV, + typename DerivedSVI, + typename DerivedSVJ> +IGL_INLINE void igl::remove_duplicate_vertices( + const Eigen::MatrixBase& V, + const double epsilon, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SVI, + Eigen::PlainObjectBase& SVJ) +{ + if(epsilon > 0) + { + DerivedV rV,rSV; + round((V/(epsilon)).eval(),rV); + unique_rows(rV,rSV,SVI,SVJ); + slice(V,SVI,colon(0,V.cols()-1),SV); + }else + { + unique_rows(V,SV,SVI,SVJ); + } +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedSV, + typename DerivedSVI, + typename DerivedSVJ, + typename DerivedSF> +IGL_INLINE void igl::remove_duplicate_vertices( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const double epsilon, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SVI, + Eigen::PlainObjectBase& SVJ, + Eigen::PlainObjectBase& SF) +{ + using namespace Eigen; + using namespace std; + remove_duplicate_vertices(V,epsilon,SV,SVI,SVJ); + SF.resizeLike(F); + for(int f = 0;f, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_duplicate_vertices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/remove_duplicate_vertices.h b/vendor/libigl/include/igl/remove_duplicate_vertices.h new file mode 100644 index 0000000000000000000000000000000000000000..ebffc09b0598a2ffa3924211562e2eddea669642 --- /dev/null +++ b/vendor/libigl/include/igl/remove_duplicate_vertices.h @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_REMOVE_DUPLICATE_VERTICES_H +#define IGL_REMOVE_DUPLICATE_VERTICES_H +#include "igl_inline.h" +#include +namespace igl +{ + // REMOVE_DUPLICATE_VERTICES Remove duplicate vertices upto a uniqueness + // tolerance (epsilon) + // + // Inputs: + // V #V by dim list of vertex positions + // epsilon uniqueness tolerance used coordinate-wise: 1e0 --> integer + // match, 1e-1 --> match up to first decimal, ... , 0 --> exact match. + // Outputs: + // SV #SV by dim new list of vertex positions + // SVI #SV by 1 list of indices so SV = V(SVI,:) + // SVJ #V by 1 list of indices so V = SV(SVJ,:) + // + // Example: + // % Mesh in (V,F) + // [SV,SVI,SVJ] = remove_duplicate_vertices(V,1e-7); + // % remap faces + // SF = SVJ(F); + // + template < + typename DerivedV, + typename DerivedSV, + typename DerivedSVI, + typename DerivedSVJ> + IGL_INLINE void remove_duplicate_vertices( + const Eigen::MatrixBase& V, + const double epsilon, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SVI, + Eigen::PlainObjectBase& SVJ); + // Wrapper that also remaps given faces (F) --> (SF) so that SF index SV + template < + typename DerivedV, + typename DerivedF, + typename DerivedSV, + typename DerivedSVI, + typename DerivedSVJ, + typename DerivedSF> + IGL_INLINE void remove_duplicate_vertices( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const double epsilon, + Eigen::PlainObjectBase& SV, + Eigen::PlainObjectBase& SVI, + Eigen::PlainObjectBase& SVJ, + Eigen::PlainObjectBase& SF); +} + +#ifndef IGL_STATIC_LIBRARY +# include "remove_duplicate_vertices.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/remove_unreferenced.cpp b/vendor/libigl/include/igl/remove_unreferenced.cpp new file mode 100644 index 0000000000000000000000000000000000000000..98ed8fcf5242ed2aacdc5617d1cda14235b83388 --- /dev/null +++ b/vendor/libigl/include/igl/remove_unreferenced.cpp @@ -0,0 +1,129 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "remove_unreferenced.h" +#include "slice.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedNV, + typename DerivedNF, + typename DerivedI> +IGL_INLINE void igl::remove_unreferenced( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &NV, + Eigen::PlainObjectBase &NF, + Eigen::PlainObjectBase &I) +{ + Eigen::Matrix J; + remove_unreferenced(V,F,NV,NF,I,J); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedNV, + typename DerivedNF, + typename DerivedI, + typename DerivedJ> +IGL_INLINE void igl::remove_unreferenced( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &NV, + Eigen::PlainObjectBase &NF, + Eigen::PlainObjectBase &I, + Eigen::PlainObjectBase &J) +{ + using namespace std; + const size_t n = V.rows(); + remove_unreferenced(n,F,I,J); + NF = F; + std::for_each(NF.data(),NF.data()+NF.size(), + [&I](typename DerivedNF::Scalar & a){a=I(a);}); + slice(V,J,1,NV); +} + +template < + typename DerivedF, + typename DerivedI, + typename DerivedJ> +IGL_INLINE void igl::remove_unreferenced( + const size_t n, + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &I, + Eigen::PlainObjectBase &J) +{ + // Mark referenced vertices + typedef Eigen::Matrix MatrixXb; + MatrixXb mark = MatrixXb::Zero(n,1); + for(int i=0; i, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +// generated by autoexplicit.sh +// generated by autoexplicit.sh +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +//template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix >(unsigned long, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::remove_unreferenced, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/remove_unreferenced.h b/vendor/libigl/include/igl/remove_unreferenced.h new file mode 100644 index 0000000000000000000000000000000000000000..b0dfce0d7155aeaf6441361b72f06f049b4c61a9 --- /dev/null +++ b/vendor/libigl/include/igl/remove_unreferenced.h @@ -0,0 +1,84 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +// +// remove_unreferenced.h +// Preview3D +// +// Created by Daniele Panozzo on 17/11/11. + +#ifndef IGL_REMOVE_UNREFERENCED_H +#define IGL_REMOVE_UNREFERENCED_H +#include "igl_inline.h" + +#include +namespace igl +{ + // Remove unreferenced vertices from V, updating F accordingly + // + // Input: + // V #V by dim list of mesh vertex positions + // F #F by ss list of simplices (Values of -1 are quitely skipped) + // Outputs: + // NV #NV by dim list of mesh vertex positions + // NF #NF by ss list of simplices + // I #V by 1 list of indices such that: NF = IM(F) and NT = IM(T) + // and V(find(IM<=size(NV,1)),:) = NV + // J #NV by 1 list, such that NV = V(J,:) + // + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedNV, + typename DerivedNF, + typename DerivedI> + IGL_INLINE void remove_unreferenced( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &NV, + Eigen::PlainObjectBase &NF, + Eigen::PlainObjectBase &I); + template < + typename DerivedV, + typename DerivedF, + typename DerivedNV, + typename DerivedNF, + typename DerivedI, + typename DerivedJ> + IGL_INLINE void remove_unreferenced( + const Eigen::MatrixBase &V, + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &NV, + Eigen::PlainObjectBase &NF, + Eigen::PlainObjectBase &I, + Eigen::PlainObjectBase &J); + // Inputs: + // n number of vertices (possibly greater than F.maxCoeff()+1) + // F #F by ss list of simplices + // Outputs: + // IM #V by 1 list of indices such that: NF = IM(F) and NT = IM(T) + // and V(find(IM<=size(NV,1)),:) = NV + // J #RV by 1 list, such that RV = V(J,:) + // + template < + typename DerivedF, + typename DerivedI, + typename DerivedJ> + IGL_INLINE void remove_unreferenced( + const size_t n, + const Eigen::MatrixBase &F, + Eigen::PlainObjectBase &I, + Eigen::PlainObjectBase &J); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "remove_unreferenced.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/reorder.cpp b/vendor/libigl/include/igl/reorder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3dd9ba797b4fbf4270a453d0316149c8fab493d --- /dev/null +++ b/vendor/libigl/include/igl/reorder.cpp @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "reorder.h" +#include "SortableRow.h" +#ifndef IGL_NO_EIGEN +#include +#endif + +// This implementation is O(n), but also uses O(n) extra memory +template< class T > +IGL_INLINE void igl::reorder( + const std::vector & unordered, + std::vector const & index_map, + std::vector & ordered) +{ + // copy for the reorder according to index_map, because unsorted may also be + // sorted + std::vector copy = unordered; + ordered.resize(index_map.size()); + for(int i = 0; i<(int)index_map.size();i++) + { + ordered[i] = copy[index_map[i]]; + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::reorder(std::vector > const&, std::vector > const&, std::vector >&); +// generated by autoexplicit.sh +template void igl::reorder(std::vector > const&, std::vector > const&, std::vector >&); +template void igl::reorder(std::vector > const&, std::vector > const&, std::vector >&); +template void igl::reorder(std::vector > const&, std::vector > const&, std::vector >&); +# ifndef IGL_NO_EIGEN + template void igl::reorder > >(std::vector >, std::allocator > > > const&, std::vector > const&, std::vector >, std::allocator > > >&); + template void igl::reorder > >(std::vector >, std::allocator > > > const&, std::vector > const&, std::vector >, std::allocator > > >&); +# endif +template void igl::reorder(std::vector > const&, std::vector > const&, std::vector >&); +#ifdef WIN32 +template void igl::reorder(class std::vector > const &,class std::vector > const &,class std::vector > &); +template void igl::reorder(class std::vector > const &,class std::vector > const &,class std::vector > &); +template void igl::reorder<__int64>(class std::vector<__int64,class std::allocator<__int64> > const &,class std::vector > const &,class std::vector<__int64,class std::allocator<__int64> > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/repdiag.h b/vendor/libigl/include/igl/repdiag.h new file mode 100644 index 0000000000000000000000000000000000000000..7794433745573db30665903c9640923c19f903b3 --- /dev/null +++ b/vendor/libigl/include/igl/repdiag.h @@ -0,0 +1,54 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_REPDIAG_H +#define IGL_REPDIAG_H +#include "igl_inline.h" + +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include + +namespace igl +{ + // REPDIAG repeat a matrix along the diagonal a certain number of times, so + // that if A is a m by n matrix and we want to repeat along the diagonal d + // times, we get a m*d by n*d matrix B such that: + // B( (k*m+1):(k*m+1+m-1), (k*n+1):(k*n+1+n-1)) = A + // for k from 0 to d-1 + // + // Inputs: + // A m by n matrix we are repeating along the diagonal. May be dense or + // sparse + // d number of times to repeat A along the diagonal + // Outputs: + // B m*d by n*d matrix with A repeated d times along the diagonal, + // will be dense or sparse to match A + // + + // Sparse version + template + IGL_INLINE void repdiag( + const Eigen::SparseMatrix& A, + const int d, + Eigen::SparseMatrix& B); + // Dense version + template + IGL_INLINE void repdiag( + const Eigen::Matrix & A, + const int d, + Eigen::Matrix & B); + // Wrapper with B as output + template + IGL_INLINE Mat repdiag(const Mat & A, const int d); +} + +#ifndef IGL_STATIC_LIBRARY +# include "repdiag.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/resolve_duplicated_faces.cpp b/vendor/libigl/include/igl/resolve_duplicated_faces.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d55e01dd85619e7fefca9f6d542afb1f6282b5a7 --- /dev/null +++ b/vendor/libigl/include/igl/resolve_duplicated_faces.cpp @@ -0,0 +1,96 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Qingnan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +// + +#include "resolve_duplicated_faces.h" + +#include "slice.h" +#include "unique_simplices.h" + +template< + typename DerivedF1, + typename DerivedF2, + typename DerivedJ > +IGL_INLINE void igl::resolve_duplicated_faces( + const Eigen::MatrixBase& F1, + Eigen::PlainObjectBase& F2, + Eigen::PlainObjectBase& J) { + + //typedef typename DerivedF1::Scalar Index; + Eigen::Matrix IA,IC; + DerivedF1 uF; + igl::unique_simplices(F1,uF,IA,IC); + + const size_t num_faces = F1.rows(); + const size_t num_unique_faces = uF.rows(); + assert((size_t) IA.rows() == num_unique_faces); + // faces on top of each unique face + std::vector > uF2F(num_unique_faces); + // signed counts + Eigen::VectorXi counts = Eigen::VectorXi::Zero(num_unique_faces); + Eigen::VectorXi ucounts = Eigen::VectorXi::Zero(num_unique_faces); + // loop over all faces + for (size_t i=0; i kept_faces; + for (size_t i=0; i 0) { + kept_faces.push_back(abs(fid)-1); + found = true; + break; + } + } + assert(found); + } else if (counts[i] == -1) { + bool found = false; + for (auto fid : uF2F[i]) { + if (fid < 0) { + kept_faces.push_back(abs(fid)-1); + found = true; + break; + } + } + assert(found); + } else { + assert(counts[i] == 0); + } + } + + const size_t num_kept = kept_faces.size(); + J.resize(num_kept, 1); + std::copy(kept_faces.begin(), kept_faces.end(), J.data()); + igl::slice(F1, J, 1, F2); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::resolve_duplicated_faces, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::resolve_duplicated_faces, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::resolve_duplicated_faces, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::resolve_duplicated_faces, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template void igl::resolve_duplicated_faces, class Eigen::Matrix, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1>>(class Eigen::MatrixBase> const &, class Eigen::PlainObjectBase> &, class Eigen::PlainObjectBase> &); +#endif +#endif diff --git a/vendor/libigl/include/igl/resolve_duplicated_faces.h b/vendor/libigl/include/igl/resolve_duplicated_faces.h new file mode 100644 index 0000000000000000000000000000000000000000..e3861fa8c60cc3aa74f54cf0c14b91e0294195ed --- /dev/null +++ b/vendor/libigl/include/igl/resolve_duplicated_faces.h @@ -0,0 +1,52 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Qingnan Zhou +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +// +#ifndef IGL_COPYLEFT_RESOLVE_DUPLICATED_FACES +#define IGL_COPYLEFT_RESOLVE_DUPLICATED_FACES + +#include "igl_inline.h" +#include + +namespace igl { + + // Resolve duplicated faces according to the following rules per unique face: + // + // 1. If the number of positively oriented faces equals the number of + // negatively oriented faces, remove all duplicated faces at this triangle. + // 2. If the number of positively oriented faces equals the number of + // negatively oriented faces plus 1, keeps one of the positively oriented + // face. + // 3. If the number of positively oriented faces equals the number of + // negatively oriented faces minus 1, keeps one of the negatively oriented + // face. + // 4. If the number of postively oriented faces differ with the number of + // negativley oriented faces by more than 1, the mesh is not orientable. + // An exception will be thrown. + // + // Inputs: + // F1 #F1 by 3 array of input faces. + // + // Outputs: + // F2 #F2 by 3 array of output faces without duplicated faces. + // J #F2 list of indices into F1. + template< + typename DerivedF1, + typename DerivedF2, + typename DerivedJ > + IGL_INLINE void resolve_duplicated_faces( + const Eigen::MatrixBase& F1, + Eigen::PlainObjectBase& F2, + Eigen::PlainObjectBase& J); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "resolve_duplicated_faces.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/rgb_to_hsv.cpp b/vendor/libigl/include/igl/rgb_to_hsv.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fbf32bfec37810ed66dffd6104086faed5f77acd --- /dev/null +++ b/vendor/libigl/include/igl/rgb_to_hsv.cpp @@ -0,0 +1,102 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "rgb_to_hsv.h" + +template +IGL_INLINE void igl::rgb_to_hsv(const R * rgb, H * hsv) +{ + // http://en.literateprograms.org/RGB_to_HSV_color_space_conversion_%28C%29 + R rgb_max = 0.0; + R rgb_min = 1.0; + rgb_max = (rgb[0]>rgb_max?rgb[0]:rgb_max); + rgb_max = (rgb[1]>rgb_max?rgb[1]:rgb_max); + rgb_max = (rgb[2]>rgb_max?rgb[2]:rgb_max); + rgb_min = (rgb[0]rgb_max?rgb_n[0]:rgb_max); + rgb_max = (rgb_n[1]>rgb_max?rgb_n[1]:rgb_max); + rgb_max = (rgb_n[2]>rgb_max?rgb_n[2]:rgb_max); + rgb_min = 1; + rgb_min = (rgb_n[0]rgb_max?rgb_n[0]:rgb_max); + rgb_max = (rgb_n[1]>rgb_max?rgb_n[1]:rgb_max); + rgb_max = (rgb_n[2]>rgb_max?rgb_n[2]:rgb_max); + rgb_min = 1; + rgb_min = (rgb_n[0] +IGL_INLINE void igl::rgb_to_hsv( + const Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & H) +{ + assert(R.cols() == 3); + H.resizeLike(R); + for(typename DerivedR::Index r = 0;r(float const*, double*); +template void igl::rgb_to_hsv(double const*, double*); +template void igl::rgb_to_hsv, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::rgb_to_hsv, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::rgb_to_hsv, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/rgb_to_hsv.h b/vendor/libigl/include/igl/rgb_to_hsv.h new file mode 100644 index 0000000000000000000000000000000000000000..ed695ad606909dd310917a3fa2537d76690971cd --- /dev/null +++ b/vendor/libigl/include/igl/rgb_to_hsv.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_RGB_TO_HSV_H +#define IGL_RGB_TO_HSV_H +#include "igl_inline.h" +#include +namespace igl +{ + // Convert RGB to HSV + // + // Inputs: + // r red value ([0,1]) + // g green value ([0,1]) + // b blue value ([0,1]) + // Outputs: + // h hue value (degrees: [0,360]) + // s saturation value ([0,1]) + // v value value ([0,1]) + template + IGL_INLINE void rgb_to_hsv(const R * rgb, H * hsv); + template + IGL_INLINE void rgb_to_hsv( + const Eigen::PlainObjectBase & R, + Eigen::PlainObjectBase & H); +}; + +#ifndef IGL_STATIC_LIBRARY +# include "rgb_to_hsv.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/rotate_by_quat.cpp b/vendor/libigl/include/igl/rotate_by_quat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b77c812ea3c786b56dac0c900f938fe469d11b82 --- /dev/null +++ b/vendor/libigl/include/igl/rotate_by_quat.cpp @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "rotate_by_quat.h" + +#include "quat_conjugate.h" +#include "quat_mult.h" +#include "normalize_quat.h" +#include + +template +IGL_INLINE void igl::rotate_by_quat( + const Q_type *v, + const Q_type *q, + Q_type *out) +{ + // Quaternion form of v, copy data in v, (as a result out can be same pointer + // as v) + Q_type quat_v[4] = {v[0],v[1],v[2],0}; + + // normalize input + Q_type normalized_q[4]; + +#ifndef NDEBUG + bool normalized = +#endif + igl::normalize_quat(q,normalized_q); +#ifndef NDEBUG + assert(normalized); +#endif + + // Conjugate of q + Q_type q_conj[4]; + igl::quat_conjugate(normalized_q,q_conj); + + // Rotate of vector v by quaternion q is: + // q*v*conj(q) + // Compute q*v + Q_type q_mult_quat_v[4]; + igl::quat_mult(normalized_q,quat_v,q_mult_quat_v); + // Compute (q*v) * conj(q) + igl::quat_mult(q_mult_quat_v,q_conj,out); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::rotate_by_quat(double const*, double const*, double*); +// generated by autoexplicit.sh +template void igl::rotate_by_quat(float const*, float const*, float*); +#endif diff --git a/vendor/libigl/include/igl/rotate_vectors.h b/vendor/libigl/include/igl/rotate_vectors.h new file mode 100644 index 0000000000000000000000000000000000000000..a11e6a8444648449392f885cb842d79fc0052b07 --- /dev/null +++ b/vendor/libigl/include/igl/rotate_vectors.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_ROTATE_VECTORS_H +#define IGL_ROTATE_VECTORS_H +#include "igl_inline.h" +#include +namespace igl +{ + // Rotate the vectors V by A radians on the tangent plane spanned by B1 and + // B2 + // + // Inputs: + // V #V by 3 eigen Matrix of vectors + // A #V eigen vector of rotation angles or a single angle to be applied + // to all vectors + // B1 #V by 3 eigen Matrix of base vector 1 + // B2 #V by 3 eigen Matrix of base vector 2 + // + // Output: + // Returns the rotated vectors + // + IGL_INLINE Eigen::MatrixXd rotate_vectors( + const Eigen::MatrixXd& V, + const Eigen::VectorXd& A, + const Eigen::MatrixXd& B1, + const Eigen::MatrixXd& B2); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "rotate_vectors.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/round.h b/vendor/libigl/include/igl/round.h new file mode 100644 index 0000000000000000000000000000000000000000..cdaac731bf7e00fa4b63beefb981d7e1cc75bb71 --- /dev/null +++ b/vendor/libigl/include/igl/round.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ROUND_H +#define IGL_ROUND_H +#include "igl_inline.h" +#include +namespace igl +{ + // Round a scalar value + // + // Inputs: + // x number + // Returns x rounded to integer + template + DerivedX round(const DerivedX r); + // Round a given matrix to nearest integers + // + // Inputs: + // X m by n matrix of scalars + // Outputs: + // Y m by n matrix of rounded integers + template < typename DerivedX, typename DerivedY> + IGL_INLINE void round( + const Eigen::PlainObjectBase& X, + Eigen::PlainObjectBase& Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "round.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/rows_to_matrix.cpp b/vendor/libigl/include/igl/rows_to_matrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14c369e40f40b07efa05f7a9baf19bafac856de3 --- /dev/null +++ b/vendor/libigl/include/igl/rows_to_matrix.cpp @@ -0,0 +1,54 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "rows_to_matrix.h" + +#include +#include + +#include "max_size.h" +#include "min_size.h" + +template +IGL_INLINE bool igl::rows_to_matrix(const std::vector & V,Mat & M) +{ + // number of columns + int m = V.size(); + if(m == 0) + { + fprintf(stderr,"Error: rows_to_matrix() list is empty()\n"); + return false; + } + // number of rows + int n = igl::min_size(V); + if(n != igl::max_size(V)) + { + fprintf(stderr,"Error: rows_to_matrix()" + " list elements are not all the same size\n"); + return false; + } + assert(n != -1); + // Resize output + M.resize(m,n); + + // Loop over rows + int i = 0; + typename std::vector::const_iterator iter = V.begin(); + while(iter != V.end()) + { + M.row(i) = V[i]; + // increment index and iterator + i++; + iter++; + } + + return true; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/rows_to_matrix.h b/vendor/libigl/include/igl/rows_to_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..8f62b5a2d010a2f5d4aa985d4213b29f59244f8b --- /dev/null +++ b/vendor/libigl/include/igl/rows_to_matrix.h @@ -0,0 +1,34 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_ROWS_TO_MATRIX_H +#define IGL_ROWS_TO_MATRIX_H +#include "igl_inline.h" +#include +namespace igl +{ + // Convert a list (std::vector) of row vectors of the same length to a matrix + // Template: + // Row row vector type, must implement: + // .size() + // Mat Matrix type, must implement: + // .resize(m,n) + // .row(i) = Row + // Inputs: + // V a m-long list of vectors of size n + // Outputs: + // M an m by n matrix + // Returns true on success, false on errors + template + IGL_INLINE bool rows_to_matrix(const std::vector & V,Mat & M); +} + +#ifndef IGL_STATIC_LIBRARY +# include "rows_to_matrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/sample_edges.h b/vendor/libigl/include/igl/sample_edges.h new file mode 100644 index 0000000000000000000000000000000000000000..96822736f07bf46b946c5196f5f0d6bd5105cc51 --- /dev/null +++ b/vendor/libigl/include/igl/sample_edges.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SAMPLE_EDGES_H +#define IGL_SAMPLE_EDGES_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Compute samples_per_edge extra points along each edge in E defined over + // vertices of V. + // + // Inputs: + // V vertices over which edges are defined, # vertices by dim + // E edge list, # edges by 2 + // k number of extra samples to be computed along edge not + // including start and end points + // Output: + // S sampled vertices, size less than # edges * (2+k) by dim always begins + // with V so that E is also defined over S + IGL_INLINE void sample_edges( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & E, + const int k, + Eigen::MatrixXd & S); +} +#ifndef IGL_STATIC_LIBRARY +# include "sample_edges.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/scalar_to_cr_vector_gradient.h b/vendor/libigl/include/igl/scalar_to_cr_vector_gradient.h new file mode 100644 index 0000000000000000000000000000000000000000..4e9861c3cb5674b2e0b32b7aee5f219a7174fc70 --- /dev/null +++ b/vendor/libigl/include/igl/scalar_to_cr_vector_gradient.h @@ -0,0 +1,100 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SCALAR_TO_CR_VECTOT_GRADIENT_H +#define IGL_SCALAR_TO_CR_VECTOT_GRADIENT_H + +#include "igl_inline.h" + +#include +#include + + +namespace igl +{ + // Computes the gradient matrix with hat functions on the right, and + // vector CR functions on the left. + // See Oded Stein, Max Wardetzky, Alec Jacobson, Eitan Grinspun, 2020. + // "A Simple Discretization of the Vector Dirichlet Energy" + // + // Inputs: + // V, F: input mesh + // E: a mapping from each halfedge to each edge, as computed with + // orient_halfedges. + // will be computed if not provided. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge, as computed with orient_halfedges. + // will be computed if not provided. + // + // Outputs: + // G: computed gradient matrix + // E, oE: these are computed if they are not present, as described above + + template + IGL_INLINE void + scalar_to_cr_vector_gradient( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& G); + + template + IGL_INLINE void + scalar_to_cr_vector_gradient( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& E, + Eigen::PlainObjectBase& oE, + Eigen::SparseMatrix& G); + + + // Version that uses intrinsic quantities as input + // + // Inputs: + // F: input mesh connectivity + // l_sq: squared edge lengths of each halfedge + // dA: double area of each face + // E: a mapping from each halfedge to each edge. + // oE: the orientation of each halfedge compared to the orientation of the + // actual edge. + // + // Outputs: + // G: computed gradient matrix + + template + IGL_INLINE void + scalar_to_cr_vector_gradient_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& G); + + template + IGL_INLINE void + scalar_to_cr_vector_gradient_intrinsic( + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& l_sq, + const Eigen::MatrixBase& dA, + const Eigen::MatrixBase& E, + const Eigen::MatrixBase& oE, + Eigen::SparseMatrix& G); + + +} + + +#ifndef IGL_STATIC_LIBRARY +# include "scalar_to_cr_vector_gradient.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/screen_space_selection.cpp b/vendor/libigl/include/igl/screen_space_selection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..819ddfb92536690f393fee7b5650acb1b9e7afe9 --- /dev/null +++ b/vendor/libigl/include/igl/screen_space_selection.cpp @@ -0,0 +1,100 @@ +#include "screen_space_selection.h" + +#include +#include +#include +#include +#include +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedM, + typename DerivedN, + typename DerivedO, + typename Ltype, + typename DerivedW, + typename Deriveda> +IGL_INLINE void igl::screen_space_selection( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const igl::AABB & tree, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + const std::vector > & L, + Eigen::PlainObjectBase & W, + Eigen::PlainObjectBase & and_visible) +{ + typedef typename DerivedV::Scalar Scalar; + screen_space_selection(V,model,proj,viewport,L,W); + const Eigen::RowVector3d origin = + (model.inverse().col(3)).head(3).template cast(); + igl::parallel_for(V.rows(),[&](const int i) + { + // Skip unselected points + if(W(i)<0.5){ return; } + igl::Hit hit; + tree.intersect_ray(V,F,origin,V.row(i)-origin,hit); + and_visible(i) = !(hit.t>1e-5 && hit.t<(1-1e-5)); + }); +} + +template < + typename DerivedV, + typename DerivedM, + typename DerivedN, + typename DerivedO, + typename Ltype, + typename DerivedW> +IGL_INLINE void igl::screen_space_selection( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + const std::vector > & L, + Eigen::PlainObjectBase & W) +{ + typedef typename DerivedV::Scalar Scalar; + Eigen::Matrix P(L.size(),2); + Eigen::Matrix E(L.size(),2); + for(int i = 0;i(); + E(i,0) = i; + E(i,1) = (i+1)%E.rows(); + } + return screen_space_selection(V,model,proj,viewport,P,E,W); +} + +template < + typename DerivedV, + typename DerivedM, + typename DerivedN, + typename DerivedO, + typename DerivedP, + typename DerivedE, + typename DerivedW> +IGL_INLINE void igl::screen_space_selection( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & W) +{ + // project all mesh vertices to 2D + DerivedV V2; + igl::project(V,model,proj,viewport,V2); + // In 2D this uses O(N*M) naive algorithm. + igl::winding_number(P,E,V2,W); + W = W.array().abs().eval(); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::screen_space_selection, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix, Eigen::Array >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::AABB, 3> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::screen_space_selection, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, float, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector, std::allocator > > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/screen_space_selection.h b/vendor/libigl/include/igl/screen_space_selection.h new file mode 100644 index 0000000000000000000000000000000000000000..cb79838870997138b7ab9a171d93ad61d2fa57d5 --- /dev/null +++ b/vendor/libigl/include/igl/screen_space_selection.h @@ -0,0 +1,105 @@ +#ifndef IGL_SCREEN_SPACE_SELECTION_H +#define IGL_SCREEN_SPACE_SELECTION_H + +#include "igl/igl_inline.h" +#include +#include +// Forward declaration +namespace igl { template class AABB; } + +namespace igl +{ + // Given a mesh, a camera determine which points are inside of a given 2D + // screen space polygon **culling points based on self-occlusion.** + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh triangle indices into rows of V + // tree precomputed bounding volume heirarchy + // model 4 by 4 camera model-view matrix + // proj 4 by 4 camera projection matrix (perspective or orthoraphic) + // viewport 4-vector containing camera viewport + // L #L by 2 list of 2D polygon vertices (in order) + // Outputs: + // W #V by 1 list of winding numbers (|W|>0.5 indicates inside) + // and_visible #V by 1 list of visibility values (only correct for vertices + // with |W|>0.5) + template < + typename DerivedV, + typename DerivedF, + typename DerivedM, + typename DerivedN, + typename DerivedO, + typename Ltype, + typename DerivedW, + typename Deriveda> + IGL_INLINE void screen_space_selection( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const igl::AABB & tree, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + const std::vector > & L, + Eigen::PlainObjectBase & W, + Eigen::PlainObjectBase & and_visible); + // Given a mesh, a camera determine which points are inside of a given 2D + // screen space polygon + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // model 4 by 4 camera model-view matrix + // proj 4 by 4 camera projection matrix (perspective or orthoraphic) + // viewport 4-vector containing camera viewport + // L #L by 2 list of 2D polygon vertices (in order) + // Outputs: + // W #V by 1 list of winding numbers (|W|>0.5 indicates inside) + template < + typename DerivedV, + typename DerivedM, + typename DerivedN, + typename DerivedO, + typename Ltype, + typename DerivedW> + IGL_INLINE void screen_space_selection( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + const std::vector > & L, + Eigen::PlainObjectBase & W); + // Given a mesh, a camera determine which points are inside of a given 2D + // screen space polygon + // + // Inputs: + // V #V by 3 list of mesh vertex positions + // model 4 by 4 camera model-view matrix + // proj 4 by 4 camera projection matrix (perspective or orthoraphic) + // viewport 4-vector containing camera viewport + // P #P by 2 list of screen space polygon vertices + // E #E by 2 list of screen space edges as indices into rows of P + // Outputs: + // W #V by 1 list of winding numbers (|W|>0.5 indicates inside) + template < + typename DerivedV, + typename DerivedM, + typename DerivedN, + typename DerivedO, + typename DerivedP, + typename DerivedE, + typename DerivedW> + IGL_INLINE void screen_space_selection( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & W); +} + +#ifndef IGL_STATIC_LIBRARY +#include "screen_space_selection.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/seam_edges.cpp b/vendor/libigl/include/igl/seam_edges.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cbca143cd94395d156148cc800bc2199673d5b1 --- /dev/null +++ b/vendor/libigl/include/igl/seam_edges.cpp @@ -0,0 +1,211 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Yotam Gingold +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "seam_edges.h" +#include +#include +#include + +// Yotam has verified that this function produces the exact same output as +// `find_seam_fast.py` for `cow_triangled.obj`. +template < + typename DerivedV, + typename DerivedTC, + typename DerivedF, + typename DerivedFTC, + typename Derivedseams, + typename Derivedboundaries, + typename Derivedfoldovers> +IGL_INLINE void igl::seam_edges( + const Eigen::PlainObjectBase& V, + const Eigen::PlainObjectBase& TC, + const Eigen::PlainObjectBase& F, + const Eigen::PlainObjectBase& FTC, + Eigen::PlainObjectBase& seams, + Eigen::PlainObjectBase& boundaries, + Eigen::PlainObjectBase& foldovers) +{ + // Assume triangles. + assert( F.cols() == 3 ); + assert( F.cols() == FTC.cols() ); + assert( F.rows() == FTC.rows() ); + + // Assume 2D texture coordinates (foldovers tests). + assert( TC.cols() == 2 ); + typedef Eigen::Matrix< typename DerivedTC::Scalar, 2, 1 > Vector2S; + // Computes the orientation of `c` relative to the line between `a` and `b`. + // Assumes 2D vector input. + // Based on: https://www.cs.cmu.edu/~quake/robust.html + const auto& Orientation = []( + const Vector2S& a, + const Vector2S& b, + const Vector2S& c ) -> typename DerivedTC::Scalar + { + const Vector2S row0 = a - c; + const Vector2S row1 = b - c; + return row0(0)*row1(1) - row1(0)*row0(1); + }; + + seams .setZero( 3*F.rows(), 4 ); + boundaries.setZero( 3*F.rows(), 2 ); + foldovers .setZero( 3*F.rows(), 4 ); + + int num_seams = 0; + int num_boundaries = 0; + int num_foldovers = 0; + + // A map from a pair of vertex indices to the index (face and endpoints) + // into face_position_indices. + // The following should be true for every key, value pair: + // key == face_position_indices[ value ] + // This gives us a "reverse map" so that we can look up other face + // attributes based on position edges. + // The value are written in the format returned by numpy.where(), + // which stores multi-dimensional indices such as array[a0,b0], array[a1,b1] + // as ( (a0,a1), (b0,b1) ). + + // We need to make a hash function for our directed edges. + // We'll use i*V.rows() + j. + typedef std::pair< typename DerivedF::Scalar, typename DerivedF::Scalar > + directed_edge; + const int numV = V.rows(); + const int numF = F.rows(); + const auto& edge_hasher = + [numV]( directed_edge const& e ) { return e.first*numV + e.second; }; + // When we pass a hash function object, we also need to specify the number of + // buckets. The Euler characteristic says that the number of undirected edges + // is numV + numF -2*genus. + std::unordered_map,decltype(edge_hasher) > + directed_position_edge2face_position_index(2*( numV + numF ), edge_hasher); + for( int fi = 0; fi < F.rows(); ++fi ) + { + for( int i = 0; i < 3; ++i ) + { + const int j = ( i+1 ) % 3; + directed_position_edge2face_position_index[ + std::make_pair( F(fi,i), F(fi,j) ) ] = std::make_pair( fi, i ); + } + } + + // First find all undirected position edges (collect a canonical orientation + // of the directed edges). + std::unordered_set< directed_edge, decltype( edge_hasher ) > + undirected_position_edges( numV + numF, edge_hasher ); + for( const auto& el : directed_position_edge2face_position_index ) + { + // The canonical orientation is the one where the smaller of + // the two vertex indices is first. + undirected_position_edges.insert( std::make_pair( + std::min( el.first.first, el.first.second ), + std::max( el.first.first, el.first.second ) ) ); + } + + // Now we will iterate over all position edges. + // Seam edges are the edges whose two opposite directed edges have different + // texcoord indices (or one doesn't exist at all in the case of a mesh + // boundary). + for( const auto& vp_edge : undirected_position_edges ) + { + // We should only see canonical edges, + // where the first vertex index is smaller. + assert( vp_edge.first < vp_edge.second ); + + const auto vp_edge_reverse = std::make_pair(vp_edge.second, vp_edge.first); + // If it and its opposite exist as directed edges, check if their + // texture coordinate indices match. + if( directed_position_edge2face_position_index.count( vp_edge ) && + directed_position_edge2face_position_index.count( vp_edge_reverse ) ) + { + const auto forwards = + directed_position_edge2face_position_index[ vp_edge ]; + const auto backwards = + directed_position_edge2face_position_index[ vp_edge_reverse ]; + + // NOTE: They should never be equal. + assert( forwards != backwards ); + + // If the texcoord indices match (are similarly flipped), + // this edge is not a seam. It could be a foldover. + if( + std::make_pair( + FTC( forwards.first, forwards.second ), + FTC( forwards.first, ( forwards.second+1 ) % 3 ) ) + == + std::make_pair( + FTC( backwards.first, ( backwards.second+1 ) % 3 ), + FTC( backwards.first, backwards.second ) )) + { + // Check for foldovers in UV space. + // Get the edge (a,b) and the two opposite vertices's texture + // coordinates. + const Vector2S a = TC.row( FTC( forwards.first, forwards.second ) ); + const Vector2S b = + TC.row( FTC( forwards.first, (forwards.second+1) % 3 ) ); + const Vector2S c_forwards = + TC.row( FTC( forwards .first, (forwards .second+2) % 3 ) ); + const Vector2S c_backwards = + TC.row( FTC( backwards.first, (backwards.second+2) % 3 ) ); + // If the opposite vertices' texture coordinates fall on the same side + // of the edge, we have a UV-space foldover. + const auto orientation_forwards = Orientation( a, b, c_forwards ); + const auto orientation_backwards = Orientation( a, b, c_backwards ); + if( ( orientation_forwards > 0 && orientation_backwards > 0 ) || + ( orientation_forwards < 0 && orientation_backwards < 0 ) + ) { + foldovers( num_foldovers, 0 ) = forwards.first; + foldovers( num_foldovers, 1 ) = forwards.second; + foldovers( num_foldovers, 2 ) = backwards.first; + foldovers( num_foldovers, 3 ) = backwards.second; + num_foldovers += 1; + } + } + // Otherwise, we have a non-matching seam edge. + else + { + seams( num_seams, 0 ) = forwards.first; + seams( num_seams, 1 ) = forwards.second; + seams( num_seams, 2 ) = backwards.first; + seams( num_seams, 3 ) = backwards.second; + num_seams += 1; + } + } + // Otherwise, the edge and its opposite aren't both in the directed edges. + // One of them should be. + else if( directed_position_edge2face_position_index.count( vp_edge ) ) + { + const auto forwards = directed_position_edge2face_position_index[vp_edge]; + boundaries( num_boundaries, 0 ) = forwards.first; + boundaries( num_boundaries, 1 ) = forwards.second; + num_boundaries += 1; + } else if( + directed_position_edge2face_position_index.count( vp_edge_reverse ) ) + { + const auto backwards = + directed_position_edge2face_position_index[ vp_edge_reverse ]; + boundaries( num_boundaries, 0 ) = backwards.first; + boundaries( num_boundaries, 1 ) = backwards.second; + num_boundaries += 1; + } else { + // This should never happen! One of these two must have been seen. + assert( + directed_position_edge2face_position_index.count( vp_edge ) || + directed_position_edge2face_position_index.count( vp_edge_reverse ) + ); + } + } + + seams .conservativeResize( num_seams, Eigen::NoChange_t() ); + boundaries.conservativeResize( num_boundaries, Eigen::NoChange_t() ); + foldovers .conservativeResize( num_foldovers, Eigen::NoChange_t() ); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::seam_edges, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/segment_segment_intersect.cpp b/vendor/libigl/include/igl/segment_segment_intersect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ebc2c6b9d0cf85092235857c7f490f2b2125eba5 --- /dev/null +++ b/vendor/libigl/include/igl/segment_segment_intersect.cpp @@ -0,0 +1,67 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Francisca Gil Ureta +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "segment_segment_intersect.h" + +#include + +template +IGL_INLINE bool igl::segment_segment_intersect( + const Eigen::MatrixBase &p, + const Eigen::MatrixBase &r, + const Eigen::MatrixBase &q, + const Eigen::MatrixBase &s, + double &a_t, + double &a_u, + double eps +) +{ + // http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect + // Search intersection between two segments + // p + t*r : t \in [0,1] + // q + u*s : u \in [0,1] + + // p + t * r = q + u * s // x s + // t(r x s) = (q - p) x s + // t = (q - p) x s / (r x s) + + // (r x s) ~ 0 --> directions are parallel, they will never cross + Eigen::Matrix rxs = r.cross(s); + if (rxs.norm() <= eps) + return false; + + int sign; + + double u; + // u = (q − p) × r / (r × s) + Eigen::Matrix u1 = (q - p).cross(r); + sign = ((u1.dot(rxs)) > 0) ? 1 : -1; + u = u1.norm() / rxs.norm(); + u = u * sign; + + double t; + // t = (q - p) x s / (r x s) + Eigen::Matrix t1 = (q - p).cross(s); + sign = ((t1.dot(rxs)) > 0) ? 1 : -1; + t = t1.norm() / rxs.norm(); + t = t * sign; + + a_t = t; + a_u = u; + + if ((u - 1.) > eps || u < -eps) + return false; + + if ((t - 1.) > eps || t < -eps) + return false; + + return true; +}; + +#ifdef IGL_STATIC_LIBRARY +template bool igl::segment_segment_intersect, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double&, double&, double); +#endif diff --git a/vendor/libigl/include/igl/serialize.h b/vendor/libigl/include/igl/serialize.h new file mode 100644 index 0000000000000000000000000000000000000000..fad7229556b512b8bc1e8ba5acc901bc1d1fe431 --- /dev/null +++ b/vendor/libigl/include/igl/serialize.h @@ -0,0 +1,1296 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Christian Schüller +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SERIALIZE_H +#define IGL_SERIALIZE_H + +// ----------------------------------------------------------------------------- +// Functions to save and load a serialization of fundamental c++ data types to +// and from a binary file. STL containers, Eigen matrix types and nested data +// structures are also supported. To serialize a user defined class implement +// the interface Serializable or SerializableBase. +// +// See also: xml/serialize_xml.h +// ----------------------------------------------------------------------------- +// TODOs: +// * arbitrary pointer graph structures +// ----------------------------------------------------------------------------- + +// Known issues: This is not written in libigl-style so it isn't (easily) +// "dualized" into the static library. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "igl_inline.h" + +// non-intrusive serialization helper macros + +#define SERIALIZE_TYPE(Type,Params) \ +namespace igl { namespace serialization { \ + void _serialization(bool s,Type& obj,std::vector& buffer) {Params} \ + template<> inline void serialize(const Type& obj,std::vector& buffer) { \ + _serialization(true,const_cast(obj),buffer); \ + } \ + template<> inline void deserialize(Type& obj,const std::vector& buffer) { \ + _serialization(false,obj,const_cast&>(buffer)); \ + } \ +}} + +#define SERIALIZE_TYPE_SOURCE(Type,Params) \ +namespace igl { namespace serialization { \ + void _serialization(bool s,Type& obj,std::vector& buffer) {Params} \ + void _serialize(const Type& obj,std::vector& buffer) { \ + _serialization(true,const_cast(obj),buffer); \ + } \ + void _deserialize(Type& obj,const std::vector& buffer) { \ + _serialization(false,obj,const_cast&>(buffer)); \ + } \ +}} + +#define SERIALIZE_MEMBER(Object) igl::serializer(s,obj.Object,std::string(#Object),buffer); +#define SERIALIZE_MEMBER_NAME(Object,Name) igl::serializer(s,obj.Object,std::string(Name),buffer); + + +namespace igl +{ + struct IndexedPointerBase; + + // Serializes the given object either to a file or to a provided buffer + // Templates: + // T type of the object to serialize + // Inputs: + // obj object to serialize + // objectName unique object name,used for the identification + // overwrite set to true to overwrite an existing file + // filename name of the file containing the serialization + // Outputs: + // buffer binary serialization + // + template + inline bool serialize(const T& obj,const std::string& filename); + template + inline bool serialize(const T& obj,const std::string& objectName,const std::string& filename,bool overwrite = false); + template + inline bool serialize(const T& obj,const std::string& objectName,std::vector& buffer); + template + inline bool serialize(const T& obj,const std::string& objectName,std::vector& buffer); + + // Deserializes the given data from a file or buffer back to the provided object + // + // Templates: + // T type of the object to serialize + // Inputs: + // buffer binary serialization + // objectName unique object name, used for the identification + // filename name of the file containing the serialization + // Outputs: + // obj object to load back serialization to + // + template + inline bool deserialize(T& obj,const std::string& filename); + template + inline bool deserialize(T& obj,const std::string& objectName,const std::string& filename); + template + inline bool deserialize(T& obj,const std::string& objectName,const std::vector& buffer); + + // Wrapper to expose both, the de- and serialization as one function + // + template + inline bool serializer(bool serialize,T& obj,const std::string& filename); + template + inline bool serializer(bool serialize,T& obj,const std::string& objectName,const std::string& filename,bool overwrite = false); + template + inline bool serializer(bool serialize,T& obj,const std::string& objectName,std::vector& buffer); + + // User defined types have to either overload the function igl::serialization::serialize() + // and igl::serialization::deserialize() for their type (non-intrusive serialization): + // + // namespace igl { namespace serialization + // { + // template<> + // inline void serialize(const UserType& obj,std::vector& buffer) { + // ::igl::serialize(obj.var,"var",buffer); + // } + // + // template<> + // inline void deserialize(UserType& obj,const std::vector& buffer) { + // ::igl::deserialize(obj.var,"var",buffer); + // } + // }} + // + // or use this macro for convenience: + // + // SERIALIZE_TYPE(UserType, + // SERIALIZE_MEMBER(var) + // ) + // + // or to derive from the class Serializable and add their the members + // in InitSerialization like the following: + // + // class UserType : public igl::Serializable { + // + // int var; + // + // void InitSerialization() { + // this->Add(var,"var"); + // } + // }; + + // Base interface for user defined types + struct SerializableBase + { + virtual ~SerializableBase() = default; + virtual void Serialize(std::vector& buffer) const = 0; + virtual void Deserialize(const std::vector& buffer) = 0; + }; + + // Convenient interface for user defined types + class Serializable: public SerializableBase + { + private: + + template + struct SerializationObject : public SerializableBase + { + bool Binary; + std::string Name; + std::unique_ptr Object; + + void Serialize(std::vector& buffer) const override { + igl::serialize(*Object,Name,buffer); + } + + void Deserialize(const std::vector& buffer) override { + igl::deserialize(*Object,Name,buffer); + } + }; + + mutable bool initialized; + mutable std::vector objects; + + public: + + // You **MUST** Override this function to add your member variables which + // should be serialized + // + // http://stackoverflow.com/a/6634382/148668 + virtual void InitSerialization() = 0; + + // Following functions can be overridden to handle the specific events. + // Return false to prevent the de-/serialization of an object. + inline virtual bool PreSerialization() const; + inline virtual void PostSerialization() const; + inline virtual bool PreDeserialization(); + inline virtual void PostDeserialization(); + + // Default implementation of SerializableBase interface + inline void Serialize(std::vector& buffer) const override final; + inline void Deserialize(const std::vector& buffer) override final; + + // Default constructor, destructor, assignment and copy constructor + inline Serializable(); + inline Serializable(const Serializable& obj); + virtual inline ~Serializable(); + inline Serializable& operator=(const Serializable& obj); + + // Use this function to add your variables which should be serialized + template + inline void Add(T& obj,std::string name,bool binary = false); + }; + + // structure for pointer handling + struct IndexedPointerBase + { + enum { BEGIN,END } Type; + size_t Index; + }; + template + struct IndexedPointer: public IndexedPointerBase + { + const T* Object; + }; + + // internal functions + namespace serialization + { + // compile time type checks + template + struct is_stl_container { static const bool value = false; }; + template + struct is_stl_container > { static const bool value = true; }; + template + struct is_stl_container > { static const bool value = true; }; + template + struct is_stl_container > { static const bool value = true; }; + template + struct is_stl_container > { static const bool value = true; }; + template + struct is_stl_container > { static const bool value = true; }; + + template + struct is_eigen_type { static const bool value = false; }; + template + struct is_eigen_type > { static const bool value = true; }; + template + struct is_eigen_type > { static const bool value = true; }; + template + struct is_eigen_type > { static const bool value = true; }; + + template + struct is_smart_ptr { static const bool value = false; }; + template + struct is_smart_ptr > { static const bool value = true; }; + template + struct is_smart_ptr > { static const bool value = true; }; + template + struct is_smart_ptr > { static const bool value = true; }; + + template + struct is_serializable { + static const bool value = std::is_fundamental::value || std::is_same::value || std::is_enum::value || std::is_base_of::value + || is_stl_container::value || is_eigen_type::value || std::is_pointer::value || serialization::is_smart_ptr::value; + }; + + // non serializable types + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj); + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter); + + // fundamental types + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj); + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter); + + // std::string + inline size_t getByteSize(const std::string& obj); + inline void serialize(const std::string& obj,std::vector& buffer,std::vector::iterator& iter); + inline void deserialize(std::string& obj,std::vector::const_iterator& iter); + + // enum types + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj); + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter); + + // SerializableBase + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj); + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter); + + // stl containers + // std::pair + template + inline size_t getByteSize(const std::pair& obj); + template + inline void serialize(const std::pair& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(std::pair& obj,std::vector::const_iterator& iter); + + // std::vector + template + inline size_t getByteSize(const std::vector& obj); + template + inline void serialize(const std::vector& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(std::vector& obj,std::vector::const_iterator& iter); + template + inline void deserialize(std::vector& obj,std::vector::const_iterator& iter); + + // std::set + template + inline size_t getByteSize(const std::set& obj); + template + inline void serialize(const std::set& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(std::set& obj,std::vector::const_iterator& iter); + + // std::map + template + inline size_t getByteSize(const std::map& obj); + template + inline void serialize(const std::map& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(std::map& obj,std::vector::const_iterator& iter); + + // std::list + template + inline size_t getByteSize(const std::list& obj); + template + inline void serialize(const std::list& obj, std::vector& buffer, std::vector::iterator& iter); + template + inline void deserialize(std::list& obj, std::vector::const_iterator& iter); + + // Eigen types + template + inline size_t getByteSize(const Eigen::Matrix& obj); + template + inline void serialize(const Eigen::Matrix& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(Eigen::Matrix& obj,std::vector::const_iterator& iter); + + template + inline size_t getByteSize(const Eigen::Array& obj); + template + inline void serialize(const Eigen::Array& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(Eigen::Array& obj,std::vector::const_iterator& iter); + + template + inline size_t getByteSize(const Eigen::SparseMatrix& obj); + template + inline void serialize(const Eigen::SparseMatrix& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(Eigen::SparseMatrix& obj,std::vector::const_iterator& iter); + + template + inline size_t getByteSize(const Eigen::Quaternion& obj); + template + inline void serialize(const Eigen::Quaternion& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(Eigen::Quaternion& obj,std::vector::const_iterator& iter); + + // raw pointers + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj); + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter); + + // std::shared_ptr and std::unique_ptr + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj); + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter); + template class T0, typename T1> + inline typename std::enable_if >::value>::type deserialize(T0& obj,std::vector::const_iterator& iter); + + // std::weak_ptr + template + inline size_t getByteSize(const std::weak_ptr& obj); + template + inline void serialize(const std::weak_ptr& obj,std::vector& buffer,std::vector::iterator& iter); + template + inline void deserialize(std::weak_ptr& obj,std::vector::const_iterator& iter); + + // functions to overload for non-intrusive serialization + template + inline void serialize(const T& obj,std::vector& buffer); + template + inline void deserialize(T& obj,const std::vector& buffer); + + // helper functions + template + inline void updateMemoryMap(T& obj,size_t size); + } +} + +// Always include inlines for these functions + +// IMPLEMENTATION + +namespace igl +{ + template + inline bool serialize(const T& obj,const std::string& filename) + { + return serialize(obj,"obj",filename,true); + } + + template + inline bool serialize(const T& obj,const std::string& objectName,const std::string& filename,bool overwrite) + { + bool success = false; + + std::vector buffer; + + std::ios_base::openmode mode = std::ios::out | std::ios::binary; + + if(overwrite) + mode |= std::ios::trunc; + else + mode |= std::ios::app; + + std::ofstream file(filename.c_str(),mode); + + if(file.is_open()) + { + serialize(obj,objectName,buffer); + + file.write(&buffer[0],buffer.size()); + + file.close(); + + success = true; + } + else + { + std::cerr << "serialization: file " << filename << " not found!" << std::endl; + } + + return success; + } + + template + inline bool serialize(const T& obj,const std::string& objectName,std::vector& buffer) + { + // serialize object data + size_t size = serialization::getByteSize(obj); + std::vector tmp(size); + auto it = tmp.begin(); + serialization::serialize(obj,tmp,it); + + std::string objectType(typeid(obj).name()); + size_t newObjectSize = tmp.size(); + size_t newHeaderSize = serialization::getByteSize(objectName) + serialization::getByteSize(objectType) + sizeof(size_t); + size_t curSize = buffer.size(); + size_t newSize = curSize + newHeaderSize + newObjectSize; + + buffer.resize(newSize); + + std::vector::iterator iter = buffer.begin()+curSize; + + // serialize object header (name/type/size) + serialization::serialize(objectName,buffer,iter); + serialization::serialize(objectType,buffer,iter); + serialization::serialize(newObjectSize,buffer,iter); + + // copy serialized data to buffer + iter = std::copy(tmp.begin(),tmp.end(),iter); + + return true; + } + + template + inline bool deserialize(T& obj,const std::string& filename) + { + return deserialize(obj,"obj",filename); + } + + template + inline bool deserialize(T& obj,const std::string& objectName,const std::string& filename) + { + bool success = false; + + std::ifstream file(filename.c_str(),std::ios::binary); + + if(file.is_open()) + { + file.seekg(0,std::ios::end); + std::streamoff size = file.tellg(); + file.seekg(0,std::ios::beg); + + std::vector buffer(size); + file.read(&buffer[0],size); + + success = deserialize(obj, objectName, buffer); + file.close(); + } + else + { + std::cerr << "serialization: file " << filename << " not found!" << std::endl; + } + + return success; + } + + template + inline bool deserialize(T& obj,const std::string& objectName,const std::vector& buffer) + { + bool success = false; + + // find suitable object header + auto objectIter = buffer.cend(); + auto iter = buffer.cbegin(); + while(iter != buffer.end()) + { + std::string name; + std::string type; + size_t size; + serialization::deserialize(name,iter); + serialization::deserialize(type,iter); + serialization::deserialize(size,iter); + + if(name == objectName && type == typeid(obj).name()) + { + objectIter = iter; + //break; // find first suitable object header + } + + iter+=size; + } + + if(objectIter != buffer.end()) + { + serialization::deserialize(obj,objectIter); + success = true; + } + else + { + obj = T(); + } + + return success; + } + + // Wrapper function which combines both, de- and serialization + template + inline bool serializer(bool s,T& obj,const std::string& filename) + { + return s ? serialize(obj,filename) : deserialize(obj,filename); + } + + template + inline bool serializer(bool s,T& obj,const std::string& objectName,const std::string& filename,bool overwrite) + { + return s ? serialize(obj,objectName,filename,overwrite) : deserialize(obj,objectName,filename); + } + + template + inline bool serializer(bool s,T& obj,const std::string& objectName,std::vector& buffer) + { + return s ? serialize(obj,objectName,buffer) : deserialize(obj,objectName,buffer); + } + + inline bool Serializable::PreSerialization() const + { + return true; + } + + inline void Serializable::PostSerialization() const + { + } + + inline bool Serializable::PreDeserialization() + { + return true; + } + + inline void Serializable::PostDeserialization() + { + } + + inline void Serializable::Serialize(std::vector& buffer) const + { + if(this->PreSerialization()) + { + if(initialized == false) + { + objects.clear(); + (const_cast(this))->InitSerialization(); + initialized = true; + } + + for(const auto& v : objects) + { + v->Serialize(buffer); + } + + this->PostSerialization(); + } + } + + inline void Serializable::Deserialize(const std::vector& buffer) + { + if(this->PreDeserialization()) + { + if(initialized == false) + { + objects.clear(); + (const_cast(this))->InitSerialization(); + initialized = true; + } + + for(auto& v : objects) + { + v->Deserialize(buffer); + } + + this->PostDeserialization(); + } + } + + inline Serializable::Serializable() + { + initialized = false; + } + + inline Serializable::Serializable(const Serializable& obj) + { + initialized = false; + objects.clear(); + } + + inline Serializable::~Serializable() + { + initialized = false; + objects.clear(); + } + + inline Serializable& Serializable::operator=(const Serializable& obj) + { + if(this != &obj) + { + if(initialized) + { + initialized = false; + objects.clear(); + } + } + return *this; + } + + template + inline void Serializable::Add(T& obj,const std::string name,bool binary) + { + auto object = new SerializationObject(); + object->Binary = binary; + object->Name = name; + object->Object = std::unique_ptr(&obj); + + objects.push_back(object); + } + + namespace serialization + { + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj) + { + return sizeof(std::vector::size_type); + } + + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter) + { + // data + std::vector tmp; + serialize<>(obj,tmp); + + // size + size_t size = buffer.size(); + serialization::serialize(tmp.size(),buffer,iter); + size_t cur = iter - buffer.begin(); + + buffer.resize(size+tmp.size()); + iter = buffer.begin()+cur; + iter = std::copy(tmp.begin(),tmp.end(),iter); + } + + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter) + { + std::vector::size_type size; + serialization::deserialize<>(size,iter); + + std::vector tmp; + tmp.resize(size); + std::copy(iter,iter+size,tmp.begin()); + + deserialize<>(obj,tmp); + iter += size; + } + + // fundamental types + + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj) + { + return sizeof(T); + } + + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter) + { + //serialization::updateMemoryMap(obj,sizeof(T)); + const uint8_t* ptr = reinterpret_cast(&obj); + iter = std::copy(ptr,ptr+sizeof(T),iter); + } + + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter) + { + uint8_t* ptr = reinterpret_cast(&obj); + std::copy(iter,iter+sizeof(T),ptr); + iter += sizeof(T); + } + + // std::string + + inline size_t getByteSize(const std::string& obj) + { + return getByteSize(obj.length())+obj.length()*sizeof(uint8_t); + } + + inline void serialize(const std::string& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.length(),buffer,iter); + for(const auto& cur : obj) + { + serialization::serialize(cur,buffer,iter); + } + } + + inline void deserialize(std::string& obj,std::vector::const_iterator& iter) + { + size_t size; + serialization::deserialize(size,iter); + + std::string str(size,'\0'); + for(size_t i=0; i + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj) + { + return sizeof(T); + } + + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter) + { + const uint8_t* ptr = reinterpret_cast(&obj); + iter = std::copy(ptr,ptr+sizeof(T),iter); + } + + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter) + { + uint8_t* ptr = reinterpret_cast(&obj); + std::copy(iter,iter+sizeof(T),ptr); + iter += sizeof(T); + } + + // SerializableBase + + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj) + { + return sizeof(std::vector::size_type); + } + + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter) + { + // data + std::vector tmp; + obj.Serialize(tmp); + + // size + size_t size = buffer.size(); + serialization::serialize(tmp.size(),buffer,iter); + size_t cur = iter - buffer.begin(); + + buffer.resize(size+tmp.size()); + iter = buffer.begin()+cur; + iter = std::copy(tmp.begin(),tmp.end(),iter); + } + + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter) + { + std::vector::size_type size; + serialization::deserialize(size,iter); + + std::vector tmp; + tmp.resize(size); + std::copy(iter,iter+size,tmp.begin()); + + obj.Deserialize(tmp); + iter += size; + } + + // STL containers + + // std::pair + + template + inline size_t getByteSize(const std::pair& obj) + { + return getByteSize(obj.first)+getByteSize(obj.second); + } + + template + inline void serialize(const std::pair& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.first,buffer,iter); + serialization::serialize(obj.second,buffer,iter); + } + + template + inline void deserialize(std::pair& obj,std::vector::const_iterator& iter) + { + serialization::deserialize(obj.first,iter); + serialization::deserialize(obj.second,iter); + } + + // std::vector + + template + inline size_t getByteSize(const std::vector& obj) + { + return std::accumulate(obj.begin(),obj.end(),sizeof(size_t),[](const size_t& acc,const T1& cur) { return acc+getByteSize(cur); }); + } + + template + inline void serialize(const std::vector& obj,std::vector& buffer,std::vector::iterator& iter) + { + size_t size = obj.size(); + serialization::serialize(size,buffer,iter); + for(const T1& cur : obj) + { + serialization::serialize(cur,buffer,iter); + } + } + + template + inline void deserialize(std::vector& obj,std::vector::const_iterator& iter) + { + size_t size; + serialization::deserialize(size,iter); + + obj.resize(size); + for(T1& v : obj) + { + serialization::deserialize(v,iter); + } + } + + template + inline void deserialize(std::vector& obj,std::vector::const_iterator& iter) + { + size_t size; + serialization::deserialize(size,iter); + + obj.resize(size); + for(int i=0;i + inline size_t getByteSize(const std::set& obj) + { + return std::accumulate(obj.begin(),obj.end(),getByteSize(obj.size()),[](const size_t& acc,const T& cur) { return acc+getByteSize(cur); }); + } + + template + inline void serialize(const std::set& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.size(),buffer,iter); + for(const T& cur : obj) + { + serialization::serialize(cur,buffer,iter); + } + } + + template + inline void deserialize(std::set& obj,std::vector::const_iterator& iter) + { + size_t size; + serialization::deserialize(size,iter); + + obj.clear(); + for(size_t i=0; i + inline size_t getByteSize(const std::map& obj) + { + return std::accumulate(obj.begin(),obj.end(),sizeof(size_t),[](const size_t& acc,const std::pair& cur) { return acc+getByteSize(cur); }); + } + + template + inline void serialize(const std::map& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.size(),buffer,iter); + for(const auto& cur : obj) + { + serialization::serialize(cur,buffer,iter); + } + } + + template + inline void deserialize(std::map& obj,std::vector::const_iterator& iter) + { + size_t size; + serialization::deserialize(size,iter); + + obj.clear(); + for(size_t i=0; i pair; + serialization::deserialize(pair,iter); + obj.insert(pair); + } + } + + //std::list + + template + inline size_t getByteSize(const std::list& obj) + { + return std::accumulate(obj.begin(), obj.end(), getByteSize(obj.size()), [](const size_t& acc, const T& cur) { return acc + getByteSize(cur); }); + } + + template + inline void serialize(const std::list& obj, std::vector& buffer, std::vector::iterator& iter) + { + serialization::serialize(obj.size(), buffer, iter); + for (const T& cur : obj) + { + serialization::serialize(cur, buffer, iter); + } + } + + template + inline void deserialize(std::list& obj, std::vector::const_iterator& iter) + { + size_t size; + serialization::deserialize(size, iter); + + obj.clear(); + for (size_t i = 0; i < size; ++i) + { + T val; + serialization::deserialize(val, iter); + obj.emplace_back(val); + } + } + + + // Eigen types + template + inline size_t getByteSize(const Eigen::Matrix& obj) + { + // space for numbers of rows,cols and data + return 2*sizeof(typename Eigen::Matrix::Index)+sizeof(T)*obj.rows()*obj.cols(); + } + + template + inline void serialize(const Eigen::Matrix& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.rows(),buffer,iter); + serialization::serialize(obj.cols(),buffer,iter); + size_t size = sizeof(T)*obj.rows()*obj.cols(); + auto ptr = reinterpret_cast(obj.data()); + iter = std::copy(ptr,ptr+size,iter); + } + + template + inline void deserialize(Eigen::Matrix& obj,std::vector::const_iterator& iter) + { + typename Eigen::Matrix::Index rows,cols; + serialization::deserialize(rows,iter); + serialization::deserialize(cols,iter); + size_t size = sizeof(T)*rows*cols; + obj.resize(rows,cols); + auto ptr = reinterpret_cast(obj.data()); + std::copy(iter,iter+size,ptr); + iter+=size; + } + + template + inline size_t getByteSize(const Eigen::Array& obj) + { + // space for numbers of rows,cols and data + return 2*sizeof(typename Eigen::Array::Index)+sizeof(T)*obj.rows()*obj.cols(); + } + + template + inline void serialize(const Eigen::Array& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.rows(),buffer,iter); + serialization::serialize(obj.cols(),buffer,iter); + size_t size = sizeof(T)*obj.rows()*obj.cols(); + auto ptr = reinterpret_cast(obj.data()); + iter = std::copy(ptr,ptr+size,iter); + } + + template + inline void deserialize(Eigen::Array& obj,std::vector::const_iterator& iter) + { + typename Eigen::Array::Index rows,cols; + serialization::deserialize(rows,iter); + serialization::deserialize(cols,iter); + size_t size = sizeof(T)*rows*cols; + obj.resize(rows,cols); + auto ptr = reinterpret_cast(obj.data()); + std::copy(iter,iter+size,ptr); + iter+=size; + } + + template + inline size_t getByteSize(const Eigen::SparseMatrix& obj) + { + // space for numbers of rows,cols,nonZeros and tripplets with data (rowIdx,colIdx,value) + size_t size = sizeof(typename Eigen::SparseMatrix::Index); + return 3*size+(sizeof(T)+2*size)*obj.nonZeros(); + } + + template + inline void serialize(const Eigen::SparseMatrix& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.rows(),buffer,iter); + serialization::serialize(obj.cols(),buffer,iter); + serialization::serialize(obj.nonZeros(),buffer,iter); + + for(int k=0;k::InnerIterator it(obj,k);it;++it) + { + serialization::serialize(it.row(),buffer,iter); + serialization::serialize(it.col(),buffer,iter); + serialization::serialize(it.value(),buffer,iter); + } + } + } + + template + inline void deserialize(Eigen::SparseMatrix& obj,std::vector::const_iterator& iter) + { + typename Eigen::SparseMatrix::Index rows,cols,nonZeros; + serialization::deserialize(rows,iter); + serialization::deserialize(cols,iter); + serialization::deserialize(nonZeros,iter); + + obj.resize(rows,cols); + obj.setZero(); + + std::vector > triplets; + for(int i=0;i::Index rowId,colId; + serialization::deserialize(rowId,iter); + serialization::deserialize(colId,iter); + T value; + serialization::deserialize(value,iter); + triplets.push_back(Eigen::Triplet(rowId,colId,value)); + } + obj.setFromTriplets(triplets.begin(),triplets.end()); + } + + template + inline size_t getByteSize(const Eigen::Quaternion& obj) + { + return sizeof(T)*4; + } + + template + inline void serialize(const Eigen::Quaternion& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj.w(),buffer,iter); + serialization::serialize(obj.x(),buffer,iter); + serialization::serialize(obj.y(),buffer,iter); + serialization::serialize(obj.z(),buffer,iter); + } + + template + inline void deserialize(Eigen::Quaternion& obj,std::vector::const_iterator& iter) + { + serialization::deserialize(obj.w(),iter); + serialization::deserialize(obj.x(),iter); + serialization::deserialize(obj.y(),iter); + serialization::deserialize(obj.z(),iter); + } + + // pointers + + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj) + { + size_t size = sizeof(bool); + + if(obj) + size += getByteSize(*obj); + + return size; + } + + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialization::serialize(obj == nullptr,buffer,iter); + + if(obj) + serialization::serialize(*obj,buffer,iter); + } + + template + inline typename std::enable_if::value>::type deserialize(T& obj,std::vector::const_iterator& iter) + { + bool isNullPtr; + serialization::deserialize(isNullPtr,iter); + + if(isNullPtr) + { + if(obj) + { + std::cout << "serialization: possible memory leak in serialization for '" << typeid(obj).name() << "'" << std::endl; + obj = nullptr; + } + } + else + { + if(obj) + { + std::cout << "serialization: possible memory corruption in deserialization for '" << typeid(obj).name() << "'" << std::endl; + } + else + { + obj = new typename std::remove_pointer::type(); + } + serialization::deserialize(*obj,iter); + } + } + + // std::shared_ptr and std::unique_ptr + + template + inline typename std::enable_if::value,size_t>::type getByteSize(const T& obj) + { + return getByteSize(obj.get()); + } + + template + inline typename std::enable_if::value>::type serialize(const T& obj,std::vector& buffer,std::vector::iterator& iter) + { + serialize(obj.get(),buffer,iter); + } + + template class T0,typename T1> + inline typename std::enable_if >::value>::type deserialize(T0& obj,std::vector::const_iterator& iter) + { + bool isNullPtr; + serialization::deserialize(isNullPtr,iter); + + if(isNullPtr) + { + obj.reset(); + } + else + { + obj = T0(new T1()); + serialization::deserialize(*obj,iter); + } + } + + // std::weak_ptr + + template + inline size_t getByteSize(const std::weak_ptr& obj) + { + return sizeof(size_t); + } + + template + inline void serialize(const std::weak_ptr& obj,std::vector& buffer,std::vector::iterator& iter) + { + + } + + template + inline void deserialize(std::weak_ptr& obj,std::vector::const_iterator& iter) + { + + } + + // functions to overload for non-intrusive serialization + template + inline void serialize(const T& obj,std::vector& buffer) + { + std::cerr << typeid(obj).name() << " is not serializable: derive from igl::Serializable or specialize the template function igl::serialization::serialize(const T& obj,std::vector& buffer)" << std::endl; + } + + template + inline void deserialize(T& obj,const std::vector& buffer) + { + std::cerr << typeid(obj).name() << " is not deserializable: derive from igl::Serializable or specialize the template function igl::serialization::deserialize(T& obj, const std::vector& buffer)" << std::endl; + } + + // helper functions + + template + inline void updateMemoryMap(T& obj,size_t size,std::map& memoryMap) + { + // check if object is already serialized + auto startPtr = new IndexedPointer(); + startPtr->Object = &obj; + auto startBasePtr = static_cast(startPtr); + startBasePtr->Type = IndexedPointerBase::BEGIN; + auto startAddress = reinterpret_cast(&obj); + auto p = std::pair(startAddress,startBasePtr); + + auto el = memoryMap.insert(p); + auto iter = ++el.first; // next elememt + if(el.second && (iter == memoryMap.end() || iter->second->Type != IndexedPointerBase::END)) + { + // not yet serialized + auto endPtr = new IndexedPointer(); + auto endBasePtr = static_cast(endPtr); + endBasePtr->Type = IndexedPointerBase::END; + auto endAddress = reinterpret_cast(&obj) + size - 1; + auto p = std::pair(endAddress,endBasePtr); + + // insert end address + memoryMap.insert(el.first,p); + } + else + { + // already serialized + + // remove inserted address + memoryMap.erase(el.first); + } + } + } +} + +#endif diff --git a/vendor/libigl/include/igl/setdiff.cpp b/vendor/libigl/include/igl/setdiff.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d5980c6280314769aa1a9910186d428fcbbaab6 --- /dev/null +++ b/vendor/libigl/include/igl/setdiff.cpp @@ -0,0 +1,84 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "setdiff.h" +#include "LinSpaced.h" +#include "list_to_matrix.h" +#include "sort.h" +#include "unique.h" + +template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedIA> +IGL_INLINE void igl::setdiff( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & IA) +{ + using namespace Eigen; + using namespace std; + // boring base cases + if(A.size() == 0) + { + C.resize(0,1); + IA.resize(0,1); + return; + } + + // Get rid of any duplicates + typedef Matrix VectorA; + typedef Matrix VectorB; + VectorA uA; + VectorB uB; + typedef DerivedIA IAType; + IAType uIA,uIuA,uIB,uIuB; + unique(A,uA,uIA,uIuA); + unique(B,uB,uIB,uIuB); + + // Sort both + VectorA sA; + VectorB sB; + IAType sIA,sIB; + sort(uA,1,true,sA,sIA); + sort(uB,1,true,sB,sIB); + + vector vC; + vector vIA; + int bi = 0; + // loop over sA + bool past = false; + bool sBempty = sB.size()==0; + for(int a = 0;asB(bi)) + { + bi++; + past = bi>=sB.size(); + } + if(sBempty || past || sA(a), Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::setdiff, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::setdiff, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::setdiff, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::setdiff, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/setdiff.h b/vendor/libigl/include/igl/setdiff.h new file mode 100644 index 0000000000000000000000000000000000000000..a8f9e0775ac09b9b8aba02fcb2d1da13f10f4525 --- /dev/null +++ b/vendor/libigl/include/igl/setdiff.h @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SETDIFF_H +#define IGL_SETDIFF_H +#include "igl_inline.h" +#include +namespace igl +{ + // Set difference of elements of matrices + // + // Inputs: + // A m-long vector of indices + // B n-long vector of indices + // Outputs: + // C (k<=m)-long vector of unique elements appearing in A but not in B + // IA (k<=m)-long list of indices into A so that C = A(IA) + // + template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedIA> + IGL_INLINE void setdiff( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & IA); +} + +#ifndef IGL_STATIC_LIBRARY +# include "setdiff.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/setunion.cpp b/vendor/libigl/include/igl/setunion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb0e721d8e498f9fe4678d17e1e035683a0e2412 --- /dev/null +++ b/vendor/libigl/include/igl/setunion.cpp @@ -0,0 +1,74 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "setunion.h" +#include "unique.h" + +template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedIA, + typename DerivedIB> +IGL_INLINE void igl::setunion( + const Eigen::DenseBase & A, + const Eigen::DenseBase & B, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & IA, + Eigen::PlainObjectBase & IB) +{ + DerivedC CS(A.size()+B.size(),1); + { + int k = 0; + for(int j = 0;j, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/setunion.h b/vendor/libigl/include/igl/setunion.h new file mode 100644 index 0000000000000000000000000000000000000000..f28bff653a89df96d9f6dc726f1d7e287fb065f0 --- /dev/null +++ b/vendor/libigl/include/igl/setunion.h @@ -0,0 +1,43 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SETUNION_H +#define IGL_SETUNION_H +#include "igl_inline.h" +#include +namespace igl +{ + // Union of elements of matrices (like matlab's `union`) + // + // Inputs: + // A m-long vector of indices + // B n-long vector of indices + // Outputs: + // C (k>=m)-long vector of unique elements appearing in A and/or B + // IA (=m)-long list of indices into A so that C = sort([A(IA);B(IB)]) + // IB (=m)-long list of indices into B so that C = sort([A(IA);B(IB)]) + // + template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedIA, + typename DerivedIB> + IGL_INLINE void setunion( + const Eigen::DenseBase & A, + const Eigen::DenseBase & B, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & IA, + Eigen::PlainObjectBase & IB); +} + +#ifndef IGL_STATIC_LIBRARY +# include "setunion.cpp" +#endif +#endif + + diff --git a/vendor/libigl/include/igl/shape_diameter_function.cpp b/vendor/libigl/include/igl/shape_diameter_function.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c611fb9434127812ebea809613f4aaa4e8110f1 --- /dev/null +++ b/vendor/libigl/include/igl/shape_diameter_function.cpp @@ -0,0 +1,182 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "shape_diameter_function.h" +#include "random_dir.h" +#include "barycenter.h" +#include "ray_mesh_intersect.h" +#include "per_vertex_normals.h" +#include "per_face_normals.h" +#include "EPS.h" +#include "Hit.h" +#include "parallel_for.h" +#include +#include +#include + +template < + typename DerivedP, + typename DerivedN, + typename DerivedS > +IGL_INLINE void igl::shape_diameter_function( + const std::function< + double( + const Eigen::Vector3f&, + const Eigen::Vector3f&) + > & shoot_ray, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + using namespace Eigen; + const int n = P.rows(); + // Resize output + S.resize(n,1); + // Embree seems to be parallel when constructing but not when tracing rays + const MatrixXf D = random_dir_stratified(num_samples).cast(); + + const auto & inner = [&P,&N,&num_samples,&D,&S,&shoot_ray](const int p) + { + const Vector3f origin = P.row(p).template cast(); + const Vector3f normal = N.row(p).template cast(); + int num_hits = 0; + double total_distance = 0; + for(int s = 0;s 0) + { + // reverse ray + d *= -1; + } + const double dist = shoot_ray(origin,d); + if(std::isfinite(dist)) + { + total_distance += dist; + num_hits++; + } + } + S(p) = total_distance/(double)num_hits; + }; + parallel_for(n,inner,1000); +} + +template < + typename DerivedV, + int DIM, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > +IGL_INLINE void igl::shape_diameter_function( + const igl::AABB & aabb, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + const auto & shoot_ray = [&aabb,&V,&F]( + const Eigen::Vector3f& _s, + const Eigen::Vector3f& dir)->double + { + Eigen::Vector3f s = _s+1e-4*dir; + igl::Hit hit; + if(aabb.intersect_ray( + V, + F, + s .cast().eval(), + dir.cast().eval(), + hit)) + { + return hit.t; + }else + { + return std::numeric_limits::infinity(); + } + }; + return shape_diameter_function(shoot_ray,P,N,num_samples,S); + +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > +IGL_INLINE void igl::shape_diameter_function( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + if(F.rows() < 100) + { + // Super naive + const auto & shoot_ray = [&V,&F]( + const Eigen::Vector3f& _s, + const Eigen::Vector3f& dir)->double + { + Eigen::Vector3f s = _s+1e-4*dir; + igl::Hit hit; + if(ray_mesh_intersect(s,dir,V,F,hit)) + { + return hit.t; + }else + { + return std::numeric_limits::infinity(); + } + }; + return shape_diameter_function(shoot_ray,P,N,num_samples,S); + } + AABB aabb; + aabb.init(V,F); + return shape_diameter_function(aabb,V,F,P,N,num_samples,S); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedS> +IGL_INLINE void igl::shape_diameter_function( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const bool per_face, + const int num_samples, + Eigen::PlainObjectBase & S) +{ + if (per_face) + { + DerivedV N; + igl::per_face_normals(V, F, N); + DerivedV P; + igl::barycenter(V, F, P); + return igl::shape_diameter_function(V, F, P, N, num_samples, S); + } + else + { + DerivedV N; + igl::per_vertex_normals(V, F, N); + return igl::shape_diameter_function(V, F, V, N, num_samples, S); + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::shape_diameter_function, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::shape_diameter_function, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::shape_diameter_function, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::shape_diameter_function, Eigen::Matrix, Eigen::Matrix >(std::function const&, Eigen::Matrix const&)> const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&); +template void igl::shape_diameter_function, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, bool, int, Eigen::PlainObjectBase >&); +#endif + diff --git a/vendor/libigl/include/igl/shape_diameter_function.h b/vendor/libigl/include/igl/shape_diameter_function.h new file mode 100644 index 0000000000000000000000000000000000000000..01e5c5b7a38905ef264961fce8524e0b342f6584 --- /dev/null +++ b/vendor/libigl/include/igl/shape_diameter_function.h @@ -0,0 +1,95 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SHAPE_DIAMETER_FUNCTION_H +#define IGL_SHAPE_DIAMETER_FUNCTION_H +#include "igl_inline.h" +#include "AABB.h" +#include +#include +namespace igl +{ + // Compute shape diamater function per given point. In the parlence of the + // paper "Consistent Mesh Partitioning and Skeletonisation using the Shape + // Diameter Function" [Shapiro et al. 2008], this implementation uses a 180° + // cone and a _uniform_ average (_not_ a average weighted by inverse angles). + // + // Inputs: + // shoot_ray function handle that outputs hits of a given ray against a + // mesh (embedded in function handles as captured variable/data) + // P #P by 3 list of origin points + // N #P by 3 list of origin normals + // Outputs: + // S #P list of shape diamater function values between bounding box + // diagonal (perfect sphere) and 0 (perfect needle hook) + // + template < + typename DerivedP, + typename DerivedN, + typename DerivedS > + IGL_INLINE void shape_diameter_function( + const std::function< + double( + const Eigen::Vector3f&, + const Eigen::Vector3f&) + > & shoot_ray, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S); + // Inputs: + // AABB axis-aligned bounding box hierarchy around (V,F) + template < + typename DerivedV, + int DIM, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > + IGL_INLINE void shape_diameter_function( + const igl::AABB & aabb, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S); + // Inputs: + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh face indices into V + template < + typename DerivedV, + typename DerivedF, + typename DerivedP, + typename DerivedN, + typename DerivedS > + IGL_INLINE void shape_diameter_function( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & N, + const int num_samples, + Eigen::PlainObjectBase & S); + // per_face whether to compute per face (S is #F by 1) or per vertex (S is + // #V by 1) + template < + typename DerivedV, + typename DerivedF, + typename DerivedS> + IGL_INLINE void shape_diameter_function( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const bool per_face, + const int num_samples, + Eigen::PlainObjectBase & S); +}; +#ifndef IGL_STATIC_LIBRARY +# include "shape_diameter_function.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/shapeup.cpp b/vendor/libigl/include/igl/shapeup.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f352d22bfd58bd3759bc0e944447c8caf6624764 --- /dev/null +++ b/vendor/libigl/include/igl/shapeup.cpp @@ -0,0 +1,238 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Amir Vaxman +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace igl +{ + + //This projection does nothing but render points into projP. Mostly used for "echoing" the global step + IGL_INLINE bool shapeup_identity_projection(const Eigen::PlainObjectBase& P, const Eigen::PlainObjectBase& SC, const Eigen::PlainObjectBase& S, Eigen::PlainObjectBase& projP){ + projP.conservativeResize(SC.rows(), 3*SC.maxCoeff()); + for (int i=0;i& P, const Eigen::PlainObjectBase& SC, const Eigen::PlainObjectBase& S, Eigen::PlainObjectBase& projP){ + projP.conservativeResize(SC.rows(), 3*SC.maxCoeff()); + for (int currRow=0;currRow svd(corrMat, Eigen::ComputeFullU | Eigen::ComputeFullV); + Eigen::MatrixXd R=svd.matrixU()*svd.matrixV().transpose(); + //getting scale by edge length change average. TODO: by singular values + Eigen::VectorXd sourceEdgeLengths(N); + Eigen::VectorXd targetEdgeLengths(N); + for (int j=0;j + IGL_INLINE bool shapeup_precomputation(const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& SC, + const Eigen::PlainObjectBase& S, + const Eigen::PlainObjectBase& E, + const Eigen::PlainObjectBase& b, + const Eigen::PlainObjectBase& wShape, + const Eigen::PlainObjectBase& wSmooth, + ShapeupData & sudata) + { + using namespace std; + using namespace Eigen; + sudata.P=P; + sudata.SC=SC; + sudata.S=S; + sudata.b=b; + typedef typename DerivedP::Scalar Scalar; + + //checking for consistency of the input + assert(SC.rows()==S.rows()); + assert(SC.rows()==wShape.rows()); + assert(E.rows()==wSmooth.rows()); + assert(b.rows()!=0); //would lead to matrix becoming SPD + + sudata.DShape.conservativeResize(SC.sum(), P.rows()); //Shape matrix (integration); + sudata.DClose.conservativeResize(b.rows(), P.rows()); //Closeness matrix for positional constraints + sudata.DSmooth.conservativeResize(E.rows(), P.rows()); //smoothness matrix + + //Building shape matrix + std::vector > DShapeTriplets; + int currRow=0; + for (int i=0;i(currRow+j, S(i,k), (1.0-avgCoeff))); + else + DShapeTriplets.push_back(Triplet(currRow+j, S(i,k), (-avgCoeff))); + } + } + currRow+=SC(i); + + } + + sudata.DShape.setFromTriplets(DShapeTriplets.begin(), DShapeTriplets.end()); + + //Building closeness matrix + std::vector > DCloseTriplets; + for (int i=0;i(i,b(i), 1.0)); + + sudata.DClose.setFromTriplets(DCloseTriplets.begin(), DCloseTriplets.end()); + + //Building smoothness matrix + std::vector > DSmoothTriplets; + for (int i=0; i(i, E(i, 0), -1)); + DSmoothTriplets.push_back(Triplet(i, E(i, 1), 1)); + } + + SparseMatrix tempMat; + igl::cat(1, sudata.DShape, sudata.DClose, tempMat); + igl::cat(1, tempMat, sudata.DSmooth, sudata.A); + + //weight matrix + vector > WTriplets; + + //one weight per set in S. + currRow=0; + for (int i=0;i(currRow+j,currRow+j,sudata.shapeCoeff*wShape(i))); + currRow+=SC(i); + } + + for (int i=0;i(SC.sum()+i, SC.sum()+i, sudata.closeCoeff)); + + for (int i=0;i(SC.sum()+b.size()+i, SC.sum()+b.size()+i, sudata.smoothCoeff*wSmooth(i))); + + sudata.W.conservativeResize(SC.sum()+b.size()+E.rows(), SC.sum()+b.size()+E.rows()); + sudata.W.setFromTriplets(WTriplets.begin(), WTriplets.end()); + + sudata.At=sudata.A.transpose(); //for efficieny, as we use the transpose a lot in the iteration + sudata.Q=sudata.At*sudata.W*sudata.A; + + return min_quad_with_fixed_precompute(sudata.Q,VectorXi(),SparseMatrix(),true,sudata.solver_data); + } + + + template < + typename DerivedP, + typename DerivedSC, + typename DerivedS> + IGL_INLINE bool shapeup_solve(const Eigen::PlainObjectBase& bc, + const std::function&, const Eigen::PlainObjectBase&, const Eigen::PlainObjectBase&, Eigen::PlainObjectBase&)>& local_projection, + const Eigen::PlainObjectBase& P0, + const ShapeupData & sudata, + const bool quietIterations, + Eigen::PlainObjectBase& P) + { + using namespace Eigen; + using namespace std; + MatrixXd currP=P0; + MatrixXd prevP=P0; + MatrixXd projP; + + assert(bc.rows()==sudata.b.rows()); + + MatrixXd rhs(sudata.A.rows(), 3); rhs.setZero(); + rhs.block(sudata.DShape.rows(), 0, sudata.b.rows(),3)=bc; //this stays constant throughout the iterations + + if (!quietIterations){ + cout<<"Shapeup Iterations, "<(); + if (!quietIterations) + cout << "Iteration "<, typename Eigen::Matrix, typename Eigen::Matrix, typename Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, igl::ShapeupData&); + +template bool igl::shapeup_solve, typename Eigen::Matrix, typename Eigen::Matrix >(const Eigen::PlainObjectBase >& bc, const std::function >&, const Eigen::PlainObjectBase >&, const Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >& ) >& local_projection, const Eigen::PlainObjectBase >& P0, const igl::ShapeupData & sudata, const bool quietIterations, Eigen::PlainObjectBase >& P); +#endif diff --git a/vendor/libigl/include/igl/shapeup.h b/vendor/libigl/include/igl/shapeup.h new file mode 100644 index 0000000000000000000000000000000000000000..7230a8dc7c439bf94540a505a0b3cc14a9bdad02 --- /dev/null +++ b/vendor/libigl/include/igl/shapeup.h @@ -0,0 +1,128 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Amir Vaxman +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SHAPEUP_H +#define IGL_SHAPEUP_H + +#include +#include +#include +#include +#include +#include +#include + + +//This file implements the following algorithm: + +//Boaziz et al. +//Shape-Up: Shaping Discrete Geometry with Projections +//Computer Graphics Forum (Proc. SGP) 31(5), 2012 + +namespace igl +{ + struct ShapeupData{ + //input data + Eigen::MatrixXd P; + Eigen::VectorXi SC; + Eigen::MatrixXi S; + Eigen::VectorXi b; + int maxIterations; //referring to number of local-global pairs. + double pTolerance; //algorithm stops when max(|P_k-P_{k-1}|) DShape, DClose, DSmooth, Q, A, At, W; + + min_quad_with_fixed_data solver_data; + + ShapeupData(): + maxIterations(50), + pTolerance(10e-6), + shapeCoeff(1.0), + closeCoeff(100.0), + smoothCoeff(0.0){} + }; + + //Every function here defines a local projection for ShapeUp, and must have the following structure to qualify: + //Input: + // P #P by 3 the set of points, either the initial solution, or from previous iteration. + // SC #Set by 1 cardinalities of sets in S + // S #Sets by max(SC) independent sets where the local projection applies. Values beyond column SC(i)-1 in row S(i,:) are "don't care" + //Output: + // projP #S by 3*max(SC) in format xyzxyzxyz, where the projected points correspond to each set in S in the same order. + typedef std::function&, const Eigen::PlainObjectBase&, const Eigen::PlainObjectBase&, Eigen::PlainObjectBase&)> shapeup_projection_function; + + + //This projection does nothing but render points into projP. Mostly used for "echoing" the global step + IGL_INLINE bool shapeup_identity_projection(const Eigen::PlainObjectBase& P, const Eigen::PlainObjectBase& SC, const Eigen::PlainObjectBase& S, Eigen::PlainObjectBase& projP); + + //the projection assumes that the sets are vertices of polygons in cyclic order + IGL_INLINE bool shapeup_regular_face_projection(const Eigen::PlainObjectBase& P, const Eigen::PlainObjectBase& SC, const Eigen::PlainObjectBase& S, Eigen::PlainObjectBase& projP); + + + //This function precomputation the necessary matrices for the ShapeUp process, and prefactorizes them. + + //input: + // P #P by 3 point positions + // SC #Set by 1 cardinalities of sets in S + // S #Sets by max(SC) independent sets where the local projection applies. Values beyond column SC(i)-1 in row S(i,:) are "don't care" + // E #E by 2 the "edges" of the set P; used for the smoothness energy. + // b #b by 1 boundary (fixed) vertices from P. + // wShape, #Set by 1 + // wSmooth #b by 1 weights for constraints from S and positional constraints (used in the global step) + + // Output: + // sudata struct ShapeupData the data necessary to solve the system in shapeup_solve + + template < + typename DerivedP, + typename DerivedSC, + typename DerivedS, + typename Derivedw> + IGL_INLINE bool shapeup_precomputation(const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& SC, + const Eigen::PlainObjectBase& S, + const Eigen::PlainObjectBase& E, + const Eigen::PlainObjectBase& b, + const Eigen::PlainObjectBase& wShape, + const Eigen::PlainObjectBase& wSmooth, + ShapeupData & sudata); + + + + //This function solve the shapeup project optimization. shapeup_precompute must be called before with the same sudata, or results are unpredictable + + //Input: + //bc #b by 3 fixed point values corresonding to "b" in sudata + //local_projection function pointer taking (P,SC,S,projP), + // where the first three parameters are as defined, and "projP" is the output, as a #S by 3*max(SC) function in format xyzxyzxyz, and where it returns the projected points corresponding to each set in S in the same order. + //NOTE: the input values in P0 don't need to correspond to prescribed values in bc; the iterations will project them automatically (by design). + //P0 #P by 3 initial solution (point positions) + //sudata the ShapeUpData structure computed in shapeup_precomputation() + //quietIterations flagging if to output iteration information. + + //Output: + //P the solution to the problem, indices corresponding to P0. + template < + typename DerivedP, + typename DerivedSC, + typename DerivedS> + IGL_INLINE bool shapeup_solve(const Eigen::PlainObjectBase& bc, + const std::function&, const Eigen::PlainObjectBase&, const Eigen::PlainObjectBase&, Eigen::PlainObjectBase&)>& local_projection, + const Eigen::PlainObjectBase& P0, + const ShapeupData & sudata, + const bool quietIterations, + Eigen::PlainObjectBase& P); + +} + +#ifndef IGL_STATIC_LIBRARY +#include "shapeup.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/sharp_edges.h b/vendor/libigl/include/igl/sharp_edges.h new file mode 100644 index 0000000000000000000000000000000000000000..6f939bfc22aaae352e3a23479eb131f69e1d0fdb --- /dev/null +++ b/vendor/libigl/include/igl/sharp_edges.h @@ -0,0 +1,61 @@ +#ifndef IGL_SHARP_EDGES_H +#define IGL_SHARP_EDGES_H + +#include +#include +#include + +namespace igl +{ + // SHARP_EDGES Given a mesh, compute sharp edges. + // + // Inputs: + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle mesh indices into V + // angle dihedral angle considered to sharp (e.g., igl::PI * 0.11) + // Outputs: + // SE #SE by 2 list of edge indices into V + // uE #uE by 2 list of unique undirected edges + // EMAP #F*3 list of indices into uE, mapping each directed edge to unique + // undirected edge so that uE(EMAP(f+#F*c)) is the unique edge + // corresponding to E.row(f+#F*c) + // uE2E #uE list of lists of indices into E of coexisting edges, so that + // E.row(uE2E[i][j]) corresponds to uE.row(i) for all j in + // 0..uE2E[i].size()-1. + // sharp #SE list of indices into uE revealing sharp undirected edges + template < + typename DerivedV, + typename DerivedF, + typename DerivedSE, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2Etype, + typename sharptype> + IGL_INLINE void sharp_edges( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const typename DerivedV::Scalar angle, + Eigen::PlainObjectBase & SE, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E, + std::vector< sharptype > & sharp); + template < + typename DerivedV, + typename DerivedF, + typename DerivedSE> + IGL_INLINE void sharp_edges( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const typename DerivedV::Scalar angle, + Eigen::PlainObjectBase & SE + ); +} + +#ifndef IGL_STATIC_LIBRARY +# include "sharp_edges.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/shortest_edge_and_midpoint.cpp b/vendor/libigl/include/igl/shortest_edge_and_midpoint.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db5338d0d71e8d6911262091dae059320c8fb0f1 --- /dev/null +++ b/vendor/libigl/include/igl/shortest_edge_and_midpoint.cpp @@ -0,0 +1,23 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "shortest_edge_and_midpoint.h" + +IGL_INLINE void igl::shortest_edge_and_midpoint( + const int e, + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & /*F*/, + const Eigen::MatrixXi & E, + const Eigen::VectorXi & /*EMAP*/, + const Eigen::MatrixXi & /*EF*/, + const Eigen::MatrixXi & /*EI*/, + double & cost, + Eigen::RowVectorXd & p) +{ + cost = (V.row(E(e,0))-V.row(E(e,1))).norm(); + p = 0.5*(V.row(E(e,0))+V.row(E(e,1))); +} diff --git a/vendor/libigl/include/igl/shortest_edge_and_midpoint.h b/vendor/libigl/include/igl/shortest_edge_and_midpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..45a4a2abfe021aee1d839626d5ea8047f4d9c220 --- /dev/null +++ b/vendor/libigl/include/igl/shortest_edge_and_midpoint.h @@ -0,0 +1,48 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SHORTEST_EDGE_AND_MIDPOINT_H +#define IGL_SHORTEST_EDGE_AND_MIDPOINT_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Cost and placement function compatible with igl::decimate. The cost of + // collapsing an edge is its length (prefer to collapse short edges) and the + // placement strategy for the new vertex is the midpoint of the collapsed + // edge. + // + // Inputs: + // e index into E of edge to be considered for collapse + // V #V by dim list of vertex positions + // F #F by 3 list of faces (ignored) + // E #E by 2 list of edge indices into V + // EMAP #F*3 list of half-edges indices into E (ignored) + // EF #E by 2 list of edge-face flaps into F (ignored) + // EI #E by 2 list of edge-face opposite corners (ignored) + // Outputs: + // cost set to edge length + // p placed point set to edge midpoint + IGL_INLINE void shortest_edge_and_midpoint( + const int e, + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & /*F*/, + const Eigen::MatrixXi & E, + const Eigen::VectorXi & /*EMAP*/, + const Eigen::MatrixXi & /*EF*/, + const Eigen::MatrixXi & /*EI*/, + double & cost, + Eigen::RowVectorXd & p); +} + +#ifndef IGL_STATIC_LIBRARY +# include "shortest_edge_and_midpoint.cpp" +#endif +#endif + + diff --git a/vendor/libigl/include/igl/signed_angle.cpp b/vendor/libigl/include/igl/signed_angle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c851122e2defb9a2d6e4c22bca35aac11281b827 --- /dev/null +++ b/vendor/libigl/include/igl/signed_angle.cpp @@ -0,0 +1,67 @@ +#include "signed_angle.h" +#include "PI.h" +#include + +template < + typename DerivedA, + typename DerivedB, + typename DerivedP> +IGL_INLINE typename DerivedA::Scalar igl::signed_angle( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & P) +{ + typedef typename DerivedA::Scalar SType; + // Gather vectors to source and destination + SType o2A[2]; + SType o2B[2]; + // and lengths + SType o2Al = 0; + SType o2Bl = 0; + for(int i = 0;i<2;i++) + { + o2A[i] = P(i) - A(i); + o2B[i] = P(i) - B(i); + o2Al += o2A[i]*o2A[i]; + o2Bl += o2B[i]*o2B[i]; + } + o2Al = sqrt(o2Al); + o2Bl = sqrt(o2Bl); + // Normalize + for(int i = 0;i<2;i++) + { + // Matlab crashes on NaN + if(o2Al!=0) + { + o2A[i] /= o2Al; + } + if(o2Bl!=0) + { + o2B[i] /= o2Bl; + } + } + return + -atan2(o2B[0]*o2A[1]-o2B[1]*o2A[0],o2B[0]*o2A[0]+o2B[1]*o2A[1])/ + (2.*igl::PI); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template Eigen::Block const, 1, 2, false>::Scalar igl::signed_angle const, 1, 2, false>, Eigen::Block const, 1, 2, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, 2, false>::Scalar igl::signed_angle const, 1, 2, false>, Eigen::Block const, 1, 2, false>, Eigen::Block const, 1, -1, false> >(Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&); +template Eigen::Block const, 1, 3, true>::Scalar igl::signed_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, 3, true>::Scalar igl::signed_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, -1, false>::Scalar igl::signed_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, 3, true>::Scalar igl::signed_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, 3, false>::Scalar igl::signed_angle const, 1, 3, false>, Eigen::Block const, 1, 3, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, -1, false>::Scalar igl::signed_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false> >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&); +template Eigen::Block const, 1, -1, false>::Scalar igl::signed_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, -1, false>::Scalar igl::signed_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, -1, false>::Scalar igl::signed_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, 3, false>::Scalar igl::signed_angle const, 1, 3, false>, Eigen::Block const, 1, 3, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase > const&); +template Eigen::Block const, 1, 3, true>::Scalar igl::signed_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +#ifdef WIN32 +template float igl::signed_angle const ,1,3,1>,class Eigen::Block const ,1,3,1>,class Eigen::Matrix >(class Eigen::MatrixBase const ,1,3,1> > const &,class Eigen::MatrixBase const ,1,3,1> > const &,class Eigen::MatrixBase > const &); +template float igl::signed_angle const ,1,3,0>,class Eigen::Block const ,1,3,0>,class Eigen::Matrix >(class Eigen::MatrixBase const ,1,3,0> > const &,class Eigen::MatrixBase const ,1,3,0> > const &,class Eigen::MatrixBase > const &); +#endif +#endif diff --git a/vendor/libigl/include/igl/signed_angle.h b/vendor/libigl/include/igl/signed_angle.h new file mode 100644 index 0000000000000000000000000000000000000000..547ba00a42a71efc982ba258ba69f14a1574c047 --- /dev/null +++ b/vendor/libigl/include/igl/signed_angle.h @@ -0,0 +1,27 @@ +#ifndef IGL_SIGNED_ANGLE_H +#define IGL_SIGNED_ANGLE_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute the signed angle subtended by the oriented 3d triangle (A,B,C) at some point P + // + // Inputs: + // A 2D position of corner + // B 2D position of corner + // P 2D position of query point + // returns signed angle + template < + typename DerivedA, + typename DerivedB, + typename DerivedP> + IGL_INLINE typename DerivedA::Scalar signed_angle( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & P); +} +#ifndef IGL_STATIC_LIBRARY +# include "signed_angle.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/signed_distance.h b/vendor/libigl/include/igl/signed_distance.h new file mode 100644 index 0000000000000000000000000000000000000000..ae54eb3ad93cc981d18aff7cc9b5d99a9b5a5c70 --- /dev/null +++ b/vendor/libigl/include/igl/signed_distance.h @@ -0,0 +1,321 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SIGNED_DISTANCE_H +#define IGL_SIGNED_DISTANCE_H + +#include "igl_inline.h" +#include "AABB.h" +#include "WindingNumberAABB.h" +#include "fast_winding_number.h" +#include +#include +namespace igl +{ + enum SignedDistanceType + { + // Use fast pseudo-normal test [Bærentzen & Aanæs 2005] + SIGNED_DISTANCE_TYPE_PSEUDONORMAL = 0, + // Use winding number [Jacobson, Kavan Sorking-Hornug 2013] + SIGNED_DISTANCE_TYPE_WINDING_NUMBER = 1, + SIGNED_DISTANCE_TYPE_DEFAULT = 2, + SIGNED_DISTANCE_TYPE_UNSIGNED = 3, + // Use Fast winding number [Barill, Dickson, Schmidt, Levin, Jacobson 2018] + SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER = 4, + NUM_SIGNED_DISTANCE_TYPE = 5 + }; + // Computes signed distance to a mesh + // + // Inputs: + // P #P by 3 list of query point positions + // V #V by 3 list of vertex positions + // F #F by ss list of triangle indices, ss should be 3 unless sign_type == + // SIGNED_DISTANCE_TYPE_UNSIGNED + // sign_type method for computing distance _sign_ S + // lower_bound lower bound of distances needed {std::numeric_limits::min} + // upper_bound lower bound of distances needed {std::numeric_limits::max} + // Outputs: + // S #P list of smallest signed distances + // I #P list of facet indices corresponding to smallest distances + // C #P by 3 list of closest points + // N #P by 3 list of closest normals (only set if + // sign_type=SIGNED_DISTANCE_TYPE_PSEUDONORMAL) + // + // Known bugs: This only computes distances to triangles. So unreferenced + // vertices and degenerate triangles are ignored. + template < + typename DerivedP, + typename DerivedV, + typename DerivedF, + typename DerivedS, + typename DerivedI, + typename DerivedC, + typename DerivedN> + IGL_INLINE void signed_distance( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const SignedDistanceType sign_type, + const typename DerivedV::Scalar lower_bound, + const typename DerivedV::Scalar upper_bound, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & N); + // Computes signed distance to a mesh, with default bounds + // + // Inputs: + // P #P by 3 list of query point positions + // V #V by 3 list of vertex positions + // F #F by ss list of triangle indices, ss should be 3 unless sign_type == + // SIGNED_DISTANCE_TYPE_UNSIGNED + // sign_type method for computing distance _sign_ S + // lower_bound lower bound of distances needed {std::numeric_limits::min} + // upper_bound lower bound of distances needed {std::numeric_limits::max} + // Outputs: + // S #P list of smallest signed distances + // I #P list of facet indices corresponding to smallest distances + // C #P by 3 list of closest points + // N #P by 3 list of closest normals (only set if + // sign_type=SIGNED_DISTANCE_TYPE_PSEUDONORMAL) + template < + typename DerivedP, + typename DerivedV, + typename DerivedF, + typename DerivedS, + typename DerivedI, + typename DerivedC, + typename DerivedN> + IGL_INLINE void signed_distance( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const SignedDistanceType sign_type, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & N); + // Computes signed distance to mesh using pseudonormal with precomputed AABB tree and edge/vertice normals + // + // Inputs: + // tree AABB acceleration tree (see AABB.h) + // F #F by 3 list of triangle indices + // FN #F by 3 list of triangle normals + // VN #V by 3 list of vertex normals (ANGLE WEIGHTING) + // EN #E by 3 list of edge normals (UNIFORM WEIGHTING) + // EMAP #F*3 mapping edges in F to E + // q Query point + // Returns signed distance to mesh + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedVN, + typename DerivedEN, + typename DerivedEMAP, + typename Derivedq> + IGL_INLINE typename DerivedV::Scalar signed_distance_pseudonormal( + const AABB & tree, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & FN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & EMAP, + const Eigen::MatrixBase & q); + template < + typename DerivedP, + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedVN, + typename DerivedEN, + typename DerivedEMAP, + typename DerivedS, + typename DerivedI, + typename DerivedC, + typename DerivedN> + IGL_INLINE void signed_distance_pseudonormal( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const AABB & tree, + const Eigen::MatrixBase & FN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & EMAP, + Eigen::PlainObjectBase & S, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & N); + // Outputs: + // s sign + // sqrd squared distance + // i closest primitive + // c closest point + // n normal + template < + typename DerivedV, + typename DerivedF, + typename DerivedFN, + typename DerivedVN, + typename DerivedEN, + typename DerivedEMAP, + typename Derivedq, + typename Scalar, + typename Derivedc, + typename Derivedn> + IGL_INLINE void signed_distance_pseudonormal( + const AABB & tree, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & FN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & EMAP, + const Eigen::MatrixBase & q, + Scalar & s, + Scalar & sqrd, + int & i, + Eigen::PlainObjectBase & c, + Eigen::PlainObjectBase & n); + template < + typename DerivedV, + typename DerivedE, + typename DerivedEN, + typename DerivedVN, + typename Derivedq, + typename Scalar, + typename Derivedc, + typename Derivedn> + IGL_INLINE void signed_distance_pseudonormal( + const AABB & tree, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EN, + const Eigen::MatrixBase & VN, + const Eigen::MatrixBase & q, + Scalar & s, + Scalar & sqrd, + int & i, + Eigen::PlainObjectBase & c, + Eigen::PlainObjectBase & n); + // Inputs: + // tree AABB acceleration tree (see cgal/point_mesh_squared_distance.h) + // hier Winding number evaluation hierarchy + // q Query point + // Returns signed distance to mesh + template < + typename DerivedV, + typename DerivedF, + typename Derivedq> + IGL_INLINE typename DerivedV::Scalar signed_distance_winding_number( + const AABB & tree, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const igl::WindingNumberAABB & hier, + const Eigen::MatrixBase & q); + // Outputs: + // s sign + // sqrd squared distance + // pp closest point and primitve + template < + typename DerivedV, + typename DerivedF, + typename Derivedq, + typename Scalar, + typename Derivedc> + IGL_INLINE void signed_distance_winding_number( + const AABB & tree, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const igl::WindingNumberAABB & hier, + const Eigen::MatrixBase & q, + Scalar & s, + Scalar & sqrd, + int & i, + Eigen::PlainObjectBase & c); + template < + typename DerivedV, + typename DerivedF, + typename Derivedq, + typename Scalar, + typename Derivedc> + IGL_INLINE void signed_distance_winding_number( + const AABB & tree, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & q, + Scalar & s, + Scalar & sqrd, + int & i, + Eigen::PlainObjectBase & c); + + + // Calculates signed distance at query points P, using fast winding number + // for sign. + // + // Usage: + // VectorXd S; + // VectorXd V, P; //where V is mesh vertices, P are query points + // VectorXi F; + // igl::FastWindingNumberBVH fwn_bvh; + // igl::fast_winding_number(V.cast(), F, 2, fwn_bvh); + // igl::signed_distance_fast_winding_number(P,V,F,tree,fwn_bvh,S); + // + // Inputs: + // P #P by 3 list of query point positions + // V #V by 3 list of triangle indices + // F #F by 3 list of triangle normals + // tree AABB acceleration tree (see AABB.h) + // bvh fast winding precomputation (see Fast_Winding_Number.h) + // Outputs: + // S #P list of signed distances of each point in P + template < + typename DerivedP, + typename DerivedV, + typename DerivedF, + typename DerivedS> + IGL_INLINE void signed_distance_fast_winding_number( + const Eigen::MatrixBase & P, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const AABB & tree, + const igl::FastWindingNumberBVH & fwn_bvh, + Eigen::PlainObjectBase & S + ); + + // Calculates signed distance at query point q, using fast winding number + // for sign. + // + // Inputs: + // tree AABB acceleration tree (see AABB.h) + // V #V by 3 list of triangle indices + // F #F by 3 list of triangle normals + // bvh fast winding precomputation (see Fast_Winding_Number.h) + // q 1 by 3 list of query point positions + // Outputs: + // S #P list of signed distances of each point in P + template < + typename Derivedq, + typename DerivedV, + typename DerivedF> + IGL_INLINE typename DerivedV::Scalar signed_distance_fast_winding_number( + const Eigen::MatrixBase & q, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const AABB & tree, + const igl::FastWindingNumberBVH & fwn_bvh + ); +} + +#ifndef IGL_STATIC_LIBRARY +# include "signed_distance.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/simplify_polyhedron.h b/vendor/libigl/include/igl/simplify_polyhedron.h new file mode 100644 index 0000000000000000000000000000000000000000..5b501819268ef10e906413e33630dc9816be3d4e --- /dev/null +++ b/vendor/libigl/include/igl/simplify_polyhedron.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SIMPLIFY_POLYHEDRON_H +#define IGL_SIMPLIFY_POLYHEDRON_H +#include "igl_inline.h" +#include +namespace igl +{ + // Simplify a polyhedron represented as a triangle mesh (OV,OF) by collapsing + // any edge that doesn't contribute to defining surface's pointset. This + // _would_ also make sense for open and non-manifold meshes, but the current + // implementation only works with closed manifold surfaces with well defined + // triangle normals. + // + // Inputs: + // OV #OV by 3 list of input mesh vertex positions + // OF #OF by 3 list of input mesh triangle indices into OV + // Outputs: + // V #V by 3 list of output mesh vertex positions + // F #F by 3 list of input mesh triangle indices into V + // J #F list of indices into OF of birth parents + IGL_INLINE void simplify_polyhedron( + const Eigen::MatrixXd & OV, + const Eigen::MatrixXi & OF, + Eigen::MatrixXd & V, + Eigen::MatrixXi & F, + Eigen::VectorXi & J); +} +#ifndef IGL_STATIC_LIBRARY +# include "simplify_polyhedron.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/slice.h b/vendor/libigl/include/igl/slice.h new file mode 100644 index 0000000000000000000000000000000000000000..542fafd1773226f1175d0f51a46aae9cef6d9a96 --- /dev/null +++ b/vendor/libigl/include/igl/slice.h @@ -0,0 +1,93 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SLICE_H +#define IGL_SLICE_H +#include "igl_inline.h" + +#include +namespace igl +{ + // Act like the matlab X(row_indices,col_indices) operator, where + // row_indices, col_indices are non-negative integer indices. + // + // Inputs: + // X m by n matrix + // R list of row indices + // C list of column indices + // Output: + // Y #R by #C matrix + // + // See also: slice_mask, and Eigen's unaryExpr + // https://stackoverflow.com/a/49411587/148668 + template < + typename TX, + typename TY, + typename DerivedR, + typename DerivedC> + IGL_INLINE void slice( + const Eigen::SparseMatrix& X, + const Eigen::DenseBase & R, + const Eigen::DenseBase & C, + Eigen::SparseMatrix& Y); + + // Wrapper to only slice in one direction + // + // Inputs: + // dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R) + // + // Note: For now this is just a cheap wrapper. + template < + typename MatX, + typename DerivedR, + typename MatY> + IGL_INLINE void slice( + const MatX& X, + const Eigen::DenseBase & R, + const int dim, + MatY& Y); + + template < + typename DerivedX, + typename DerivedR, + typename DerivedC, + typename DerivedY> + IGL_INLINE void slice( + const Eigen::DenseBase & X, + const Eigen::DenseBase & R, + const Eigen::DenseBase & C, + Eigen::PlainObjectBase & Y); + + template + IGL_INLINE void slice( + const Eigen::DenseBase & X, + const Eigen::DenseBase & R, + Eigen::PlainObjectBase & Y); + + // VectorXi Y = slice(X,R); + // + // This templating is bad because the return type might not have the same + // size as `DerivedX`. This will probably only work if DerivedX has Dynamic + // as it's non-trivial sizes or if the number of rows in R happens to equal + // the number of rows in `DerivedX`. + template + IGL_INLINE DerivedX slice( + const Eigen::DenseBase & X, + const Eigen::DenseBase & R); + template + IGL_INLINE DerivedX slice( + const Eigen::DenseBase& X, + const Eigen::DenseBase & R, + const int dim); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "slice.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/slice_cached.cpp b/vendor/libigl/include/igl/slice_cached.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0f13d804f6416820f39f52ce749d09d9dfaa9f7 --- /dev/null +++ b/vendor/libigl/include/igl/slice_cached.cpp @@ -0,0 +1,57 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "slice_cached.h" + +#include +#include +#include +#include "slice.h" + +template +IGL_INLINE void igl::slice_cached_precompute( + const Eigen::SparseMatrix& X, + const Eigen::Matrix & R, + const Eigen::Matrix & C, + Eigen::MatrixBase& data, + Eigen::SparseMatrix& Y + ) +{ + // Create a sparse matrix whose entries are the ids + Eigen::SparseMatrix TS = X.template cast(); + + TS.makeCompressed(); + for (unsigned i=0;i TS_sliced; + igl::slice(TS,R,C,TS_sliced); + Y = TS_sliced.cast(); + + data.resize(TS_sliced.nonZeros()); + for (unsigned i=0;i +IGL_INLINE void igl::slice_cached( + const Eigen::SparseMatrix& X, + const Eigen::MatrixBase& data, + Eigen::SparseMatrix& Y + ) +{ + for (unsigned i=0; i >(Eigen::SparseMatrix const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); +template void igl::slice_cached_precompute >(Eigen::SparseMatrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::MatrixBase >&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/slice_cached.h b/vendor/libigl/include/igl/slice_cached.h new file mode 100644 index 0000000000000000000000000000000000000000..84ced8dc930c1bef7259e14067ff3275b25f5378 --- /dev/null +++ b/vendor/libigl/include/igl/slice_cached.h @@ -0,0 +1,69 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SLICE_CACHED_H +#define IGL_SLICE_CACHED_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +namespace igl +{ + + // Act like the matlab X(row_indices,col_indices) operator, where row_indices, + // col_indices are non-negative integer indices. This is a fast version of + // igl::slice that can analyze and store the sparsity structure. It is slower + // at the irst evaluation (slice_cached_precompute), but faster on the + // subsequent ones. + // + // Inputs: + // X m by n matrix + // R list of row indices + // C list of column indices + // + // Output: + // Y #R by #C matrix + // data Temporary data used by slice_cached to repeat this operation + // + // Usage: + // + // // Construct and slice up Laplacian + // SparseMatrix L,L_sliced; + // igl::cotmatrix(V,F,L); + + // // Normal igl::slice call + // igl::slice(L,in,in,L_in_in); + + // // Fast version + // static VectorXi data; // static or saved in a global state + // if (data.size() == 0) + // igl::slice_cached_precompute(L,in,in,data,L_sliced); + // else + // igl::slice_cached(L,data,L_sliced); + +template +IGL_INLINE void slice_cached_precompute( + const Eigen::SparseMatrix& X, + const Eigen::Matrix & R, + const Eigen::Matrix & C, + Eigen::MatrixBase& data, + Eigen::SparseMatrix& Y + ); + +template +IGL_INLINE void slice_cached( + const Eigen::SparseMatrix& X, + const Eigen::MatrixBase& data, + Eigen::SparseMatrix& Y + ); +} + +#ifndef IGL_STATIC_LIBRARY +# include "slice_cached.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/slice_into.h b/vendor/libigl/include/igl/slice_into.h new file mode 100644 index 0000000000000000000000000000000000000000..5971d97ee67ee4d714083fe691734fad55ebbb57 --- /dev/null +++ b/vendor/libigl/include/igl/slice_into.h @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SLICE_INTO_H +#define IGL_SLICE_INTO_H +#include "igl_inline.h" + +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +namespace igl +{ + // Act like the matlab Y(row_indices,col_indices) = X + // + // Inputs: + // X xm by xn rhs matrix + // R list of row indices + // C list of column indices + // Y ym by yn lhs matrix + // Output: + // Y ym by yn lhs matrix, same as input but Y(R,C) = X + template + IGL_INLINE void slice_into( + const Eigen::SparseMatrix& X, + const Eigen::MatrixBase & R, + const Eigen::MatrixBase & C, + Eigen::SparseMatrix& Y); + + template + IGL_INLINE void slice_into( + const Eigen::MatrixBase & X, + const Eigen::MatrixBase & R, + const Eigen::MatrixBase & C, + Eigen::PlainObjectBase & Y); + // Wrapper to only slice in one direction + // + // Inputs: + // dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R) + // + // Note: For now this is just a cheap wrapper. + template + IGL_INLINE void slice_into( + const MatX & X, + const Eigen::MatrixBase & R, + const int dim, + MatY& Y); + + template + IGL_INLINE void slice_into( + const Eigen::MatrixBase& X, + const Eigen::MatrixBase& R, + Eigen::PlainObjectBase& Y); +} + +#ifndef IGL_STATIC_LIBRARY +# include "slice_into.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/slice_mask.h b/vendor/libigl/include/igl/slice_mask.h new file mode 100644 index 0000000000000000000000000000000000000000..0a0dcda7c1b3739300ad700802f64733150a9bef --- /dev/null +++ b/vendor/libigl/include/igl/slice_mask.h @@ -0,0 +1,74 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SLICE_MASK_H +#define IGL_SLICE_MASK_H +#include "igl_inline.h" + +#include +#include +namespace igl +{ + // Act like the matlab X(row_mask,col_mask) operator, where + // row_mask, col_mask are non-negative integer indices. + // + // Inputs: + // X m by n matrix + // R m list of row bools + // C n list of column bools + // Output: + // Y #trues-in-R by #trues-in-C matrix + // + // See also: slice_mask + + template + IGL_INLINE void slice_mask( + const Eigen::DenseBase & X, + const Eigen::Array & R, + const Eigen::Array & C, + Eigen::PlainObjectBase & Y); + template + IGL_INLINE void slice_mask( + const Eigen::DenseBase & X, + const Eigen::Array & R, + const int dim, + Eigen::PlainObjectBase & Y); + // + // This templating is bad because the return type might not have the same + // size as `DerivedX`. This will probably only work if DerivedX has Dynamic + // as it's non-trivial sizes or if the number of rows in R happens to equal + // the number of rows in `DerivedX`. + template + IGL_INLINE DerivedX slice_mask( + const Eigen::DenseBase & X, + const Eigen::Array & R, + const Eigen::Array & C); + template + IGL_INLINE DerivedX slice_mask( + const Eigen::DenseBase & X, + const Eigen::Array & R, + const int dim); + template + IGL_INLINE void slice_mask( + const Eigen::SparseMatrix & X, + const Eigen::Array & R, + const int dim, + Eigen::SparseMatrix & Y); + template + IGL_INLINE void slice_mask( + const Eigen::SparseMatrix & X, + const Eigen::Array & R, + const Eigen::Array & C, + Eigen::SparseMatrix & Y); +} + + +#ifndef IGL_STATIC_LIBRARY +# include "slice_mask.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/slice_sorted.cpp b/vendor/libigl/include/igl/slice_sorted.cpp new file mode 100644 index 0000000000000000000000000000000000000000..000a20aa95b8d9f3da9e5697697ee837eef0391a --- /dev/null +++ b/vendor/libigl/include/igl/slice_sorted.cpp @@ -0,0 +1,88 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "slice_sorted.h" + +#include + +// TODO: Write a version that works for row-major sparse matrices as well. +template +IGL_INLINE void igl::slice_sorted(const Eigen::SparseMatrix &X, + const Eigen::DenseBase &R, + const Eigen::DenseBase &C, + Eigen::SparseMatrix &Y) +{ + int xm = X.rows(); + int xn = X.cols(); + int ym = R.size(); + int yn = C.size(); + + // Special case when R or C is empty + if (ym == 0 || yn == 0) + { + Y.resize(ym, yn); + return; + } + + assert(R.minCoeff() >= 0); + assert(R.maxCoeff() < xm); + assert(C.minCoeff() >= 0); + assert(C.maxCoeff() < xn); + + // Multiplicity count for each row/col + using RowIndexType = typename DerivedR::Scalar; + using ColIndexType = typename DerivedC::Scalar; + std::vector slicedRowStart(xm); + std::vector rowRepeat(xm, 0); + for (int i = 0; i < ym; ++i) + { + if (rowRepeat[R(i)] == 0) + { + slicedRowStart[R(i)] = i; + } + rowRepeat[R(i)]++; + } + std::vector columnRepeat(xn, 0); + for (int i = 0; i < yn; i++) + { + columnRepeat[C(i)]++; + } + // Count number of nnz per outer row/col + Eigen::VectorXi nnz(yn); + for (int k = 0, c = 0; k < X.outerSize(); ++k) + { + int cnt = 0; + for (typename Eigen::SparseMatrix::InnerIterator it(X, k); it; ++it) + { + cnt += rowRepeat[it.row()]; + } + for (int i = 0; i < columnRepeat[k]; ++i, ++c) + { + nnz(c) = cnt; + } + } + Y.resize(ym, yn); + Y.reserve(nnz); + // Insert values + for (int k = 0, c = 0; k < X.outerSize(); ++k) + { + for (int i = 0; i < columnRepeat[k]; ++i, ++c) + { + for (typename Eigen::SparseMatrix::InnerIterator it(X, k); it; ++it) + { + for (int j = 0, r = slicedRowStart[it.row()]; j < rowRepeat[it.row()]; ++j, ++r) + { + Y.insert(r, c) = it.value(); + } + } + } + } +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::slice_sorted, Eigen::Matrix >(Eigen::SparseMatrix const&, Eigen::DenseBase > const&, Eigen::DenseBase > const&, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/slice_sorted.h b/vendor/libigl/include/igl/slice_sorted.h new file mode 100644 index 0000000000000000000000000000000000000000..47826b9273f116d8aa30c45c59e1127e5154e41e --- /dev/null +++ b/vendor/libigl/include/igl/slice_sorted.h @@ -0,0 +1,42 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2019 Jérémie Dumas +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_SLICE_SORTED_H +#define IGL_SLICE_SORTED_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Act like the matlab X(row_indices,col_indices) operator, where row_indices, + // col_indices are non-negative integer indices. This version is about 2x faster + // than igl::slice, but it assumes that the indices to slice with are already sorted. + // + // Inputs: + // X m by n matrix + // R list of row indices + // C list of column indices + // + // Output: + // Y #R by #C matrix + // + template + IGL_INLINE void slice_sorted(const Eigen::SparseMatrix &X, + const Eigen::DenseBase &R, + const Eigen::DenseBase &C, + Eigen::SparseMatrix &Y); + +} // namespace igl + +#ifndef IGL_STATIC_LIBRARY +#include "slice_sorted.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/slim.cpp b/vendor/libigl/include/igl/slim.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed779eadf004b3f31fcce09a3a37a288c834811e --- /dev/null +++ b/vendor/libigl/include/igl/slim.cpp @@ -0,0 +1,811 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "slim.h" + +#include "boundary_loop.h" +#include "cotmatrix.h" +#include "edge_lengths.h" +#include "grad.h" +#include "local_basis.h" +#include "repdiag.h" +#include "vector_area_matrix.h" +#include "arap.h" +#include "cat.h" +#include "doublearea.h" +#include "grad.h" +#include "local_basis.h" +#include "per_face_normals.h" +#include "slice_into.h" +#include "volume.h" +#include "polar_svd.h" +#include "flip_avoiding_line_search.h" +#include "mapping_energy_with_jacobians.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "Timer.h" +#include "sparse_cached.h" +#include "AtA_cached.h" + +#ifdef CHOLMOD +#include +#endif + +namespace igl +{ + namespace slim + { + // Definitions of internal functions + IGL_INLINE void buildRhs(igl::SLIMData& s, const Eigen::SparseMatrix &A); + IGL_INLINE void add_soft_constraints(igl::SLIMData& s, Eigen::SparseMatrix &L); + IGL_INLINE double compute_energy(igl::SLIMData& s, const Eigen::MatrixXd &V_new); + IGL_INLINE double compute_soft_const_energy(igl::SLIMData& s, + const Eigen::MatrixXd &V, + const Eigen::MatrixXi &F, + const Eigen::MatrixXd &V_o); + + IGL_INLINE void solve_weighted_arap(igl::SLIMData& s, + const Eigen::MatrixXd &V, + const Eigen::MatrixXi &F, + Eigen::MatrixXd &uv, + Eigen::VectorXi &soft_b_p, + Eigen::MatrixXd &soft_bc_p); + IGL_INLINE void update_weights_and_closest_rotations( igl::SLIMData& s, + Eigen::MatrixXd &uv); + IGL_INLINE void compute_jacobians(igl::SLIMData& s, const Eigen::MatrixXd &uv); + IGL_INLINE void build_linear_system(igl::SLIMData& s, Eigen::SparseMatrix &L); + IGL_INLINE void pre_calc(igl::SLIMData& s); + + // Implementation + + IGL_INLINE void compute_jacobians(igl::SLIMData& s, const Eigen::MatrixXd &uv) + { + if (s.F.cols() == 3) + { + // Ji=[D1*u,D2*u,D1*v,D2*v]; + s.Ji.col(0) = s.Dx * uv.col(0); + s.Ji.col(1) = s.Dy * uv.col(0); + s.Ji.col(2) = s.Dx * uv.col(1); + s.Ji.col(3) = s.Dy * uv.col(1); + } + else /*tet mesh*/{ + // Ji=[D1*u,D2*u,D3*u, D1*v,D2*v, D3*v, D1*w,D2*w,D3*w]; + s.Ji.col(0) = s.Dx * uv.col(0); + s.Ji.col(1) = s.Dy * uv.col(0); + s.Ji.col(2) = s.Dz * uv.col(0); + s.Ji.col(3) = s.Dx * uv.col(1); + s.Ji.col(4) = s.Dy * uv.col(1); + s.Ji.col(5) = s.Dz * uv.col(1); + s.Ji.col(6) = s.Dx * uv.col(2); + s.Ji.col(7) = s.Dy * uv.col(2); + s.Ji.col(8) = s.Dz * uv.col(2); + } + } + + IGL_INLINE void update_weights_and_closest_rotations(igl::SLIMData& s, Eigen::MatrixXd &uv) + { + compute_jacobians(s, uv); + slim_update_weights_and_closest_rotations_with_jacobians(s.Ji, s.slim_energy, s.exp_factor, s.W, s.Ri); + } + + + + + IGL_INLINE void solve_weighted_arap(igl::SLIMData& s, + const Eigen::MatrixXd &V, + const Eigen::MatrixXi &F, + Eigen::MatrixXd &uv, + Eigen::VectorXi &soft_b_p, + Eigen::MatrixXd &soft_bc_p) + { + using namespace Eigen; + + Eigen::SparseMatrix L; + build_linear_system(s,L); + + igl::Timer t; + + //t.start(); + // solve + Eigen::VectorXd Uc; +#ifndef CHOLMOD + if (s.dim == 2) + { + SimplicialLDLT > solver; + Uc = solver.compute(L).solve(s.rhs); + } + else + { // seems like CG performs much worse for 2D and way better for 3D + Eigen::VectorXd guess(uv.rows() * s.dim); + for (int i = 0; i < s.v_num; i++) for (int j = 0; j < s.dim; j++) guess(uv.rows() * j + i) = uv(i, j); // flatten vector + ConjugateGradient, Lower | Upper> cg; + cg.setTolerance(1e-8); + cg.compute(L); + Uc = cg.solveWithGuess(s.rhs, guess); + } +#else + CholmodSimplicialLDLT > solver; + Uc = solver.compute(L).solve(s.rhs); +#endif + for (int i = 0; i < s.dim; i++) + uv.col(i) = Uc.block(i * s.v_n, 0, s.v_n, 1); + + // t.stop(); + // std::cerr << "solve: " << t.getElapsedTime() << std::endl; + + } + + + IGL_INLINE void pre_calc(igl::SLIMData& s) + { + if (!s.has_pre_calc) + { + s.v_n = s.v_num; + s.f_n = s.f_num; + + if (s.F.cols() == 3) + { + s.dim = 2; + Eigen::MatrixXd F1, F2, F3; + igl::local_basis(s.V, s.F, F1, F2, F3); + Eigen::SparseMatrix G; + igl::grad(s.V, s.F, G); + Eigen::SparseMatrix Face_Proj; + + auto face_proj = [](Eigen::MatrixXd& F){ + std::vector >IJV; + int f_num = F.rows(); + for(int i=0; i(i, i, F(i,0))); + IJV.push_back(Eigen::Triplet(i, i+f_num, F(i,1))); + IJV.push_back(Eigen::Triplet(i, i+2*f_num, F(i,2))); + } + Eigen::SparseMatrix P(f_num, 3*f_num); + P.setFromTriplets(IJV.begin(), IJV.end()); + return P; + }; + + s.Dx = face_proj(F1) * G; + s.Dy = face_proj(F2) * G; + } + else + { + s.dim = 3; + Eigen::SparseMatrix G; + igl::grad(s.V, s.F, G, + s.mesh_improvement_3d /*use normal gradient, or one from a "regular" tet*/); + s.Dx = G.block(0, 0, s.F.rows(), s.V.rows()); + s.Dy = G.block(s.F.rows(), 0, s.F.rows(), s.V.rows()); + s.Dz = G.block(2 * s.F.rows(), 0, s.F.rows(), s.V.rows()); + } + + s.W.resize(s.f_n, s.dim * s.dim); + s.Dx.makeCompressed(); + s.Dy.makeCompressed(); + s.Dz.makeCompressed(); + s.Ri.resize(s.f_n, s.dim * s.dim); + s.Ji.resize(s.f_n, s.dim * s.dim); + s.rhs.resize(s.dim * s.v_num); + + // flattened weight matrix + s.WGL_M.resize(s.dim * s.dim * s.f_n); + for (int i = 0; i < s.dim * s.dim; i++) + for (int j = 0; j < s.f_n; j++) + s.WGL_M(i * s.f_n + j) = s.M(j); + + s.first_solve = true; + s.has_pre_calc = true; + } + } + + IGL_INLINE void build_linear_system(igl::SLIMData& s, Eigen::SparseMatrix &L) + { + // formula (35) in paper + std::vector > IJV; + + #ifdef SLIM_CACHED + slim_buildA(s.Dx, s.Dy, s.Dz, s.W, IJV); + if (s.A.rows() == 0) + { + s.A = Eigen::SparseMatrix(s.dim * s.dim * s.f_n, s.dim * s.v_n); + igl::sparse_cached_precompute(IJV,s.A_data,s.A); + } + else + igl::sparse_cached(IJV,s.A_data,s.A); + #else + Eigen::SparseMatrix A(s.dim * s.dim * s.f_n, s.dim * s.v_n); + slim_buildA(s.Dx, s.Dy, s.Dz, s.W, IJV); + A.setFromTriplets(IJV.begin(),IJV.end()); + A.makeCompressed(); + #endif + + #ifdef SLIM_CACHED + #else + Eigen::SparseMatrix At = A.transpose(); + At.makeCompressed(); + #endif + + #ifdef SLIM_CACHED + Eigen::SparseMatrix id_m(s.A.cols(), s.A.cols()); + #else + Eigen::SparseMatrix id_m(A.cols(), A.cols()); + #endif + + id_m.setIdentity(); + + // add proximal penalty + #ifdef SLIM_CACHED + s.AtA_data.W = s.WGL_M; + if (s.AtA.rows() == 0) + igl::AtA_cached_precompute(s.A,s.AtA_data,s.AtA); + else + igl::AtA_cached(s.A,s.AtA_data,s.AtA); + + L = s.AtA + s.proximal_p * id_m; //add also a proximal + L.makeCompressed(); + + #else + L = At * s.WGL_M.asDiagonal() * A + s.proximal_p * id_m; //add also a proximal term + L.makeCompressed(); + #endif + + #ifdef SLIM_CACHED + buildRhs(s, s.A); + #else + buildRhs(s, A); + #endif + + Eigen::SparseMatrix OldL = L; + add_soft_constraints(s,L); + L.makeCompressed(); + } + + IGL_INLINE void add_soft_constraints(igl::SLIMData& s, Eigen::SparseMatrix &L) + { + int v_n = s.v_num; + for (int d = 0; d < s.dim; d++) + { + for (int i = 0; i < s.b.rows(); i++) + { + int v_idx = s.b(i); + s.rhs(d * v_n + v_idx) += s.soft_const_p * s.bc(i, d); // rhs + L.coeffRef(d * v_n + v_idx, d * v_n + v_idx) += s.soft_const_p; // diagonal of matrix + } + } + } + + IGL_INLINE double compute_energy(igl::SLIMData& s, const Eigen::MatrixXd &V_new) + { + compute_jacobians(s,V_new); + return mapping_energy_with_jacobians(s.Ji, s.M, s.slim_energy, s.exp_factor) + + compute_soft_const_energy(s, s.V, s.F, V_new); + } + + IGL_INLINE double compute_soft_const_energy(igl::SLIMData& s, + const Eigen::MatrixXd &V, + const Eigen::MatrixXi &F, + const Eigen::MatrixXd &V_o) + { + double e = 0; + for (int i = 0; i < s.b.rows(); i++) + { + e += s.soft_const_p * (s.bc.row(i) - V_o.row(s.b(i))).squaredNorm(); + } + return e; + } + + + + IGL_INLINE void buildRhs(igl::SLIMData& s, const Eigen::SparseMatrix &A) + { + Eigen::VectorXd f_rhs(s.dim * s.dim * s.f_n); + f_rhs.setZero(); + if (s.dim == 2) + { + /*b = [W11*R11 + W12*R21; (formula (36)) + W11*R12 + W12*R22; + W21*R11 + W22*R21; + W21*R12 + W22*R22];*/ + for (int i = 0; i < s.f_n; i++) + { + f_rhs(i + 0 * s.f_n) = s.W(i, 0) * s.Ri(i, 0) + s.W(i, 1) * s.Ri(i, 1); + f_rhs(i + 1 * s.f_n) = s.W(i, 0) * s.Ri(i, 2) + s.W(i, 1) * s.Ri(i, 3); + f_rhs(i + 2 * s.f_n) = s.W(i, 2) * s.Ri(i, 0) + s.W(i, 3) * s.Ri(i, 1); + f_rhs(i + 3 * s.f_n) = s.W(i, 2) * s.Ri(i, 2) + s.W(i, 3) * s.Ri(i, 3); + } + } + else + { + /*b = [W11*R11 + W12*R21 + W13*R31; + W11*R12 + W12*R22 + W13*R32; + W11*R13 + W12*R23 + W13*R33; + W21*R11 + W22*R21 + W23*R31; + W21*R12 + W22*R22 + W23*R32; + W21*R13 + W22*R23 + W23*R33; + W31*R11 + W32*R21 + W33*R31; + W31*R12 + W32*R22 + W33*R32; + W31*R13 + W32*R23 + W33*R33;];*/ + for (int i = 0; i < s.f_n; i++) + { + f_rhs(i + 0 * s.f_n) = s.W(i, 0) * s.Ri(i, 0) + s.W(i, 1) * s.Ri(i, 1) + s.W(i, 2) * s.Ri(i, 2); + f_rhs(i + 1 * s.f_n) = s.W(i, 0) * s.Ri(i, 3) + s.W(i, 1) * s.Ri(i, 4) + s.W(i, 2) * s.Ri(i, 5); + f_rhs(i + 2 * s.f_n) = s.W(i, 0) * s.Ri(i, 6) + s.W(i, 1) * s.Ri(i, 7) + s.W(i, 2) * s.Ri(i, 8); + f_rhs(i + 3 * s.f_n) = s.W(i, 3) * s.Ri(i, 0) + s.W(i, 4) * s.Ri(i, 1) + s.W(i, 5) * s.Ri(i, 2); + f_rhs(i + 4 * s.f_n) = s.W(i, 3) * s.Ri(i, 3) + s.W(i, 4) * s.Ri(i, 4) + s.W(i, 5) * s.Ri(i, 5); + f_rhs(i + 5 * s.f_n) = s.W(i, 3) * s.Ri(i, 6) + s.W(i, 4) * s.Ri(i, 7) + s.W(i, 5) * s.Ri(i, 8); + f_rhs(i + 6 * s.f_n) = s.W(i, 6) * s.Ri(i, 0) + s.W(i, 7) * s.Ri(i, 1) + s.W(i, 8) * s.Ri(i, 2); + f_rhs(i + 7 * s.f_n) = s.W(i, 6) * s.Ri(i, 3) + s.W(i, 7) * s.Ri(i, 4) + s.W(i, 8) * s.Ri(i, 5); + f_rhs(i + 8 * s.f_n) = s.W(i, 6) * s.Ri(i, 6) + s.W(i, 7) * s.Ri(i, 7) + s.W(i, 8) * s.Ri(i, 8); + } + } + Eigen::VectorXd uv_flat(s.dim *s.v_n); + for (int i = 0; i < s.dim; i++) + for (int j = 0; j < s.v_n; j++) + uv_flat(s.v_n * i + j) = s.V_o(j, i); + + s.rhs = (f_rhs.transpose() * s.WGL_M.asDiagonal() * A).transpose() + s.proximal_p * uv_flat; + } + + } +} + +IGL_INLINE void igl::slim_update_weights_and_closest_rotations_with_jacobians(const Eigen::MatrixXd &Ji, + igl::MappingEnergyType slim_energy, + double exp_factor, + Eigen::MatrixXd &W, + Eigen::MatrixXd &Ri) +{ + const double eps = 1e-8; + double exp_f = exp_factor; + const int dim = (Ji.cols()==4? 2:3); + + if (dim == 2) + { + for (int i = 0; i < Ji.rows(); ++i) + { + typedef Eigen::Matrix2d Mat2; + typedef Eigen::Matrix RMat2; + typedef Eigen::Vector2d Vec2; + Mat2 ji, ri, ti, ui, vi; + Vec2 sing; + Vec2 closest_sing_vec; + RMat2 mat_W; + Vec2 m_sing_new; + double s1, s2; + + ji(0, 0) = Ji(i, 0); + ji(0, 1) = Ji(i, 1); + ji(1, 0) = Ji(i, 2); + ji(1, 1) = Ji(i, 3); + + igl::polar_svd(ji, ri, ti, ui, sing, vi); + + s1 = sing(0); + s2 = sing(1); + + // Update Weights according to energy + switch (slim_energy) + { + case igl::MappingEnergyType::ARAP: + { + m_sing_new << 1, 1; + break; + } + case igl::MappingEnergyType::SYMMETRIC_DIRICHLET: + { + double s1_g = 2 * (s1 - pow(s1, -3)); + double s2_g = 2 * (s2 - pow(s2, -3)); + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))); + break; + } + case igl::MappingEnergyType::LOG_ARAP: + { + double s1_g = 2 * (log(s1) / s1); + double s2_g = 2 * (log(s2) / s2); + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))); + break; + } + case igl::MappingEnergyType::CONFORMAL: + { + double s1_g = 1 / (2 * s2) - s2 / (2 * pow(s1, 2)); + double s2_g = 1 / (2 * s1) - s1 / (2 * pow(s2, 2)); + + double geo_avg = sqrt(s1 * s2); + double s1_min = geo_avg; + double s2_min = geo_avg; + + m_sing_new << sqrt(s1_g / (2 * (s1 - s1_min))), sqrt(s2_g / (2 * (s2 - s2_min))); + + // change local step + closest_sing_vec << s1_min, s2_min; + ri = ui * closest_sing_vec.asDiagonal() * vi.transpose(); + break; + } + case igl::MappingEnergyType::EXP_CONFORMAL: + { + double s1_g = 2 * (s1 - pow(s1, -3)); + double s2_g = 2 * (s2 - pow(s2, -3)); + + double geo_avg = sqrt(s1 * s2); + double s1_min = geo_avg; + double s2_min = geo_avg; + + double in_exp = exp_f * ((pow(s1, 2) + pow(s2, 2)) / (2 * s1 * s2)); + double exp_thing = exp(in_exp); + + s1_g *= exp_thing * exp_f; + s2_g *= exp_thing * exp_f; + + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))); + break; + } + case igl::MappingEnergyType::EXP_SYMMETRIC_DIRICHLET: + { + double s1_g = 2 * (s1 - pow(s1, -3)); + double s2_g = 2 * (s2 - pow(s2, -3)); + + double in_exp = exp_f * (pow(s1, 2) + pow(s1, -2) + pow(s2, 2) + pow(s2, -2)); + double exp_thing = exp(in_exp); + + s1_g *= exp_thing * exp_f; + s2_g *= exp_thing * exp_f; + + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))); + break; + } + default: assert(false); + } + + if (std::abs(s1 - 1) < eps) m_sing_new(0) = 1; + if (std::abs(s2 - 1) < eps) m_sing_new(1) = 1; + mat_W = ui * m_sing_new.asDiagonal() * ui.transpose(); + + W.row(i) = Eigen::Map>(mat_W.data()); + // 2) Update local step (doesn't have to be a rotation, for instance in case of conformal energy) + Ri.row(i) = Eigen::Map>(ri.data()); + } + } + else + { + typedef Eigen::Matrix Vec3; + typedef Eigen::Matrix Mat3; + typedef Eigen::Matrix RMat3; + Mat3 ji; + Vec3 m_sing_new; + Vec3 closest_sing_vec; + const double sqrt_2 = sqrt(2); + for (int i = 0; i < Ji.rows(); ++i) + { + ji << Ji(i,0), Ji(i,1), Ji(i,2), + Ji(i,3), Ji(i,4), Ji(i,5), + Ji(i,6), Ji(i,7), Ji(i,8); + + Mat3 ri, ti, ui, vi; + Vec3 sing; + igl::polar_svd(ji, ri, ti, ui, sing, vi); + + double s1 = sing(0); + double s2 = sing(1); + double s3 = sing(2); + + // 1) Update Weights + switch (slim_energy) + { + case igl::MappingEnergyType::ARAP: + { + m_sing_new << 1, 1, 1; + break; + } + case igl::MappingEnergyType::LOG_ARAP: + { + double s1_g = 2 * (log(s1) / s1); + double s2_g = 2 * (log(s2) / s2); + double s3_g = 2 * (log(s3) / s3); + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))), sqrt(s3_g / (2 * (s3 - 1))); + break; + } + case igl::MappingEnergyType::SYMMETRIC_DIRICHLET: + { + double s1_g = 2 * (s1 - pow(s1, -3)); + double s2_g = 2 * (s2 - pow(s2, -3)); + double s3_g = 2 * (s3 - pow(s3, -3)); + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))), sqrt(s3_g / (2 * (s3 - 1))); + break; + } + case igl::MappingEnergyType::EXP_SYMMETRIC_DIRICHLET: + { + double s1_g = 2 * (s1 - pow(s1, -3)); + double s2_g = 2 * (s2 - pow(s2, -3)); + double s3_g = 2 * (s3 - pow(s3, -3)); + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))), sqrt(s3_g / (2 * (s3 - 1))); + + double in_exp = exp_f * (pow(s1, 2) + pow(s1, -2) + pow(s2, 2) + pow(s2, -2) + pow(s3, 2) + pow(s3, -2)); + double exp_thing = exp(in_exp); + + s1_g *= exp_thing * exp_f; + s2_g *= exp_thing * exp_f; + s3_g *= exp_thing * exp_f; + + m_sing_new << sqrt(s1_g / (2 * (s1 - 1))), sqrt(s2_g / (2 * (s2 - 1))), sqrt(s3_g / (2 * (s3 - 1))); + + break; + } + case igl::MappingEnergyType::CONFORMAL: + { + double common_div = 9 * (pow(s1 * s2 * s3, 5. / 3.)); + + double s1_g = (-2 * s2 * s3 * (pow(s2, 2) + pow(s3, 2) - 2 * pow(s1, 2))) / common_div; + double s2_g = (-2 * s1 * s3 * (pow(s1, 2) + pow(s3, 2) - 2 * pow(s2, 2))) / common_div; + double s3_g = (-2 * s1 * s2 * (pow(s1, 2) + pow(s2, 2) - 2 * pow(s3, 2))) / common_div; + + double closest_s = sqrt(pow(s1, 2) + pow(s3, 2)) / sqrt_2; + double s1_min = closest_s; + double s2_min = closest_s; + double s3_min = closest_s; + + m_sing_new << sqrt(s1_g / (2 * (s1 - s1_min))), sqrt(s2_g / (2 * (s2 - s2_min))), sqrt( + s3_g / (2 * (s3 - s3_min))); + + // change local step + closest_sing_vec << s1_min, s2_min, s3_min; + ri = ui * closest_sing_vec.asDiagonal() * vi.transpose(); + break; + } + case igl::MappingEnergyType::EXP_CONFORMAL: + { + // E_conf = (s1^2 + s2^2 + s3^2)/(3*(s1*s2*s3)^(2/3) ) + // dE_conf/ds1 = (-2*(s2*s3)*(s2^2+s3^2 -2*s1^2) ) / (9*(s1*s2*s3)^(5/3)) + // Argmin E_conf(s1): s1 = sqrt(s1^2+s2^2)/sqrt(2) + double common_div = 9 * (pow(s1 * s2 * s3, 5. / 3.)); + + double s1_g = (-2 * s2 * s3 * (pow(s2, 2) + pow(s3, 2) - 2 * pow(s1, 2))) / common_div; + double s2_g = (-2 * s1 * s3 * (pow(s1, 2) + pow(s3, 2) - 2 * pow(s2, 2))) / common_div; + double s3_g = (-2 * s1 * s2 * (pow(s1, 2) + pow(s2, 2) - 2 * pow(s3, 2))) / common_div; + + double in_exp = exp_f * ((pow(s1, 2) + pow(s2, 2) + pow(s3, 2)) / (3 * pow((s1 * s2 * s3), 2. / 3)));; + double exp_thing = exp(in_exp); + + double closest_s = sqrt(pow(s1, 2) + pow(s3, 2)) / sqrt_2; + double s1_min = closest_s; + double s2_min = closest_s; + double s3_min = closest_s; + + s1_g *= exp_thing * exp_f; + s2_g *= exp_thing * exp_f; + s3_g *= exp_thing * exp_f; + + m_sing_new << sqrt(s1_g / (2 * (s1 - s1_min))), sqrt(s2_g / (2 * (s2 - s2_min))), sqrt( + s3_g / (2 * (s3 - s3_min))); + + // change local step + closest_sing_vec << s1_min, s2_min, s3_min; + ri = ui * closest_sing_vec.asDiagonal() * vi.transpose(); + break; + } + default: assert(false); + } + if (std::abs(s1 - 1) < eps) m_sing_new(0) = 1; + if (std::abs(s2 - 1) < eps) m_sing_new(1) = 1; + if (std::abs(s3 - 1) < eps) m_sing_new(2) = 1; + RMat3 mat_W; + mat_W = ui * m_sing_new.asDiagonal() * ui.transpose(); + + W.row(i) = Eigen::Map>(mat_W.data()); + // 2) Update closest rotations (not rotations in case of conformal energy) + Ri.row(i) = Eigen::Map>(ri.data()); + } // for loop end + + } // if dim end + +} + +IGL_INLINE void igl::slim_buildA(const Eigen::SparseMatrix &Dx, + const Eigen::SparseMatrix &Dy, + const Eigen::SparseMatrix &Dz, + const Eigen::MatrixXd &W, +std::vector > & IJV) +{ + const int dim = (W.cols() == 4) ? 2 : 3; + const int f_n = W.rows(); + const int v_n = Dx.cols(); + + // formula (35) in paper + if (dim == 2) + { + IJV.reserve(4 * (Dx.outerSize() + Dy.outerSize())); + + /*A = [W11*Dx, W12*Dx; + W11*Dy, W12*Dy; + W21*Dx, W22*Dx; + W21*Dy, W22*Dy];*/ + for (int k = 0; k < Dx.outerSize(); ++k) + { + for (Eigen::SparseMatrix::InnerIterator it(Dx, k); it; ++it) + { + int dx_r = it.row(); + int dx_c = it.col(); + double val = it.value(); + + IJV.push_back(Eigen::Triplet(dx_r, dx_c, val * W(dx_r, 0))); + IJV.push_back(Eigen::Triplet(dx_r, v_n + dx_c, val * W(dx_r, 1))); + + IJV.push_back(Eigen::Triplet(2 * f_n + dx_r, dx_c, val * W(dx_r, 2))); + IJV.push_back(Eigen::Triplet(2 * f_n + dx_r, v_n + dx_c, val * W(dx_r, 3))); + } + } + + for (int k = 0; k < Dy.outerSize(); ++k) + { + for (Eigen::SparseMatrix::InnerIterator it(Dy, k); it; ++it) + { + int dy_r = it.row(); + int dy_c = it.col(); + double val = it.value(); + + IJV.push_back(Eigen::Triplet(f_n + dy_r, dy_c, val * W(dy_r, 0))); + IJV.push_back(Eigen::Triplet(f_n + dy_r, v_n + dy_c, val * W(dy_r, 1))); + + IJV.push_back(Eigen::Triplet(3 * f_n + dy_r, dy_c, val * W(dy_r, 2))); + IJV.push_back(Eigen::Triplet(3 * f_n + dy_r, v_n + dy_c, val * W(dy_r, 3))); + } + } + } + else + { + + /*A = [W11*Dx, W12*Dx, W13*Dx; + W11*Dy, W12*Dy, W13*Dy; + W11*Dz, W12*Dz, W13*Dz; + W21*Dx, W22*Dx, W23*Dx; + W21*Dy, W22*Dy, W23*Dy; + W21*Dz, W22*Dz, W23*Dz; + W31*Dx, W32*Dx, W33*Dx; + W31*Dy, W32*Dy, W33*Dy; + W31*Dz, W32*Dz, W33*Dz;];*/ + IJV.reserve(9 * (Dx.outerSize() + Dy.outerSize() + Dz.outerSize())); + for (int k = 0; k < Dx.outerSize(); k++) + { + for (Eigen::SparseMatrix::InnerIterator it(Dx, k); it; ++it) + { + int dx_r = it.row(); + int dx_c = it.col(); + double val = it.value(); + + IJV.push_back(Eigen::Triplet(dx_r, dx_c, val * W(dx_r, 0))); + IJV.push_back(Eigen::Triplet(dx_r, v_n + dx_c, val * W(dx_r, 1))); + IJV.push_back(Eigen::Triplet(dx_r, 2 * v_n + dx_c, val * W(dx_r, 2))); + + IJV.push_back(Eigen::Triplet(3 * f_n + dx_r, dx_c, val * W(dx_r, 3))); + IJV.push_back(Eigen::Triplet(3 * f_n + dx_r, v_n + dx_c, val * W(dx_r, 4))); + IJV.push_back(Eigen::Triplet(3 * f_n + dx_r, 2 * v_n + dx_c, val * W(dx_r, 5))); + + IJV.push_back(Eigen::Triplet(6 * f_n + dx_r, dx_c, val * W(dx_r, 6))); + IJV.push_back(Eigen::Triplet(6 * f_n + dx_r, v_n + dx_c, val * W(dx_r, 7))); + IJV.push_back(Eigen::Triplet(6 * f_n + dx_r, 2 * v_n + dx_c, val * W(dx_r, 8))); + } + } + + for (int k = 0; k < Dy.outerSize(); k++) + { + for (Eigen::SparseMatrix::InnerIterator it(Dy, k); it; ++it) + { + int dy_r = it.row(); + int dy_c = it.col(); + double val = it.value(); + + IJV.push_back(Eigen::Triplet(f_n + dy_r, dy_c, val * W(dy_r, 0))); + IJV.push_back(Eigen::Triplet(f_n + dy_r, v_n + dy_c, val * W(dy_r, 1))); + IJV.push_back(Eigen::Triplet(f_n + dy_r, 2 * v_n + dy_c, val * W(dy_r, 2))); + + IJV.push_back(Eigen::Triplet(4 * f_n + dy_r, dy_c, val * W(dy_r, 3))); + IJV.push_back(Eigen::Triplet(4 * f_n + dy_r, v_n + dy_c, val * W(dy_r, 4))); + IJV.push_back(Eigen::Triplet(4 * f_n + dy_r, 2 * v_n + dy_c, val * W(dy_r, 5))); + + IJV.push_back(Eigen::Triplet(7 * f_n + dy_r, dy_c, val * W(dy_r, 6))); + IJV.push_back(Eigen::Triplet(7 * f_n + dy_r, v_n + dy_c, val * W(dy_r, 7))); + IJV.push_back(Eigen::Triplet(7 * f_n + dy_r, 2 * v_n + dy_c, val * W(dy_r, 8))); + } + } + + for (int k = 0; k < Dz.outerSize(); k++) + { + for (Eigen::SparseMatrix::InnerIterator it(Dz, k); it; ++it) + { + int dz_r = it.row(); + int dz_c = it.col(); + double val = it.value(); + + IJV.push_back(Eigen::Triplet(2 * f_n + dz_r, dz_c, val * W(dz_r, 0))); + IJV.push_back(Eigen::Triplet(2 * f_n + dz_r, v_n + dz_c, val * W(dz_r, 1))); + IJV.push_back(Eigen::Triplet(2 * f_n + dz_r, 2 * v_n + dz_c, val * W(dz_r, 2))); + + IJV.push_back(Eigen::Triplet(5 * f_n + dz_r, dz_c, val * W(dz_r, 3))); + IJV.push_back(Eigen::Triplet(5 * f_n + dz_r, v_n + dz_c, val * W(dz_r, 4))); + IJV.push_back(Eigen::Triplet(5 * f_n + dz_r, 2 * v_n + dz_c, val * W(dz_r, 5))); + + IJV.push_back(Eigen::Triplet(8 * f_n + dz_r, dz_c, val * W(dz_r, 6))); + IJV.push_back(Eigen::Triplet(8 * f_n + dz_r, v_n + dz_c, val * W(dz_r, 7))); + IJV.push_back(Eigen::Triplet(8 * f_n + dz_r, 2 * v_n + dz_c, val * W(dz_r, 8))); + } + } + } +} +/// Slim Implementation + +IGL_INLINE void igl::slim_precompute( + const Eigen::MatrixXd &V, + const Eigen::MatrixXi &F, + const Eigen::MatrixXd &V_init, + igl::SLIMData &data, + igl::MappingEnergyType slim_energy, + const Eigen::VectorXi &b, + const Eigen::MatrixXd &bc, + double soft_p) +{ + + data.V = V; + data.F = F; + data.V_o = V_init; + + data.v_num = V.rows(); + data.f_num = F.rows(); + + data.slim_energy = slim_energy; + + data.b = b; + data.bc = bc; + data.soft_const_p = soft_p; + + data.proximal_p = 0.0001; + + igl::doublearea(V, F, data.M); + data.M /= 2.; + data.mesh_area = data.M.sum(); + data.mesh_improvement_3d = false; // whether to use a jacobian derived from a real mesh or an abstract regular mesh (used for mesh improvement) + data.exp_factor = 1.0; // param used only for exponential energies (e.g exponential symmetric dirichlet) + + assert (F.cols() == 3 || F.cols() == 4); + + igl::slim::pre_calc(data); + data.energy = igl::slim::compute_energy(data,data.V_o) / data.mesh_area; +} + +IGL_INLINE Eigen::MatrixXd igl::slim_solve(igl::SLIMData &data, int iter_num) +{ + for (int i = 0; i < iter_num; i++) + { + Eigen::MatrixXd dest_res; + dest_res = data.V_o; + + // Solve Weighted Proxy + igl::slim::update_weights_and_closest_rotations(data, dest_res); + igl::slim::solve_weighted_arap(data,data.V, data.F, dest_res, data.b, data.bc); + + double old_energy = data.energy; + + std::function compute_energy = [&]( + Eigen::MatrixXd &aaa) { return igl::slim::compute_energy(data,aaa); }; + + data.energy = igl::flip_avoiding_line_search(data.F, data.V_o, dest_res, compute_energy, + data.energy * data.mesh_area) / data.mesh_area; + } + return data.V_o; +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/slim.h b/vendor/libigl/include/igl/slim.h new file mode 100644 index 0000000000000000000000000000000000000000..5661ec63a0064853830022c858df2d2d61a76143 --- /dev/null +++ b/vendor/libigl/include/igl/slim.h @@ -0,0 +1,115 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Michael Rabinovich +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef SLIM_H +#define SLIM_H + +#include "igl_inline.h" +#include "MappingEnergyType.h" +#include +#include + +// This option makes the iterations faster (all except the first) by caching the +// sparsity pattern of the matrix involved in the assembly. It should be on if you plan to do many iterations, off if you have to change the matrix structure at every iteration. +#define SLIM_CACHED + +#ifdef SLIM_CACHED +#include +#endif + +namespace igl +{ + +// Compute a SLIM map as derived in "Scalable Locally Injective Maps" [Rabinovich et al. 2016]. +struct SLIMData +{ + // Input + Eigen::MatrixXd V; // #V by 3 list of mesh vertex positions + Eigen::MatrixXi F; // #F by 3/3 list of mesh faces (triangles/tets) + MappingEnergyType slim_energy; + + // Optional Input + // soft constraints + Eigen::VectorXi b; + Eigen::MatrixXd bc; + double soft_const_p; + + double exp_factor; // used for exponential energies, ignored otherwise + bool mesh_improvement_3d; // only supported for 3d + + // Output + Eigen::MatrixXd V_o; // #V by dim list of mesh vertex positions (dim = 2 for parametrization, 3 otherwise) + double energy; // objective value + + // INTERNAL + Eigen::VectorXd M; + double mesh_area; + double avg_edge_length; + int v_num; + int f_num; + double proximal_p; + + Eigen::VectorXd WGL_M; + Eigen::VectorXd rhs; + Eigen::MatrixXd Ri,Ji; + Eigen::MatrixXd W; + Eigen::SparseMatrix Dx,Dy,Dz; + int f_n,v_n; + bool first_solve; + bool has_pre_calc = false; + int dim; + + #ifdef SLIM_CACHED + Eigen::SparseMatrix A; + Eigen::VectorXi A_data; + Eigen::SparseMatrix AtA; + igl::AtA_cached_data AtA_data; + #endif +}; + +// Compute necessary information to start using SLIM +// Inputs: +// V #V by 3 list of mesh vertex positions +// F #F by 3/3 list of mesh faces (triangles/tets) +// b list of boundary indices into V +// bc #b by dim list of boundary conditions +// soft_p Soft penalty factor (can be zero) +// slim_energy Energy to minimize +IGL_INLINE void slim_precompute( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& V_init, + SLIMData& data, + MappingEnergyType slim_energy, + const Eigen::VectorXi& b, + const Eigen::MatrixXd& bc, + double soft_p); + +// Run iter_num iterations of SLIM +// Outputs: +// V_o (in SLIMData): #V by dim list of mesh vertex positions +IGL_INLINE Eigen::MatrixXd slim_solve(SLIMData& data, int iter_num); + +// Internal Routine. Exposed for Integration with SCAF +IGL_INLINE void slim_update_weights_and_closest_rotations_with_jacobians(const Eigen::MatrixXd &Ji, + igl::MappingEnergyType slim_energy, + double exp_factor, + Eigen::MatrixXd &W, + Eigen::MatrixXd &Ri); + +IGL_INLINE void slim_buildA(const Eigen::SparseMatrix &Dx, + const Eigen::SparseMatrix &Dy, + const Eigen::SparseMatrix &Dz, + const Eigen::MatrixXd &W, + std::vector > & IJV); +} // END NAMESPACE + +#ifndef IGL_STATIC_LIBRARY +# include "slim.cpp" +#endif + +#endif // SLIM_H diff --git a/vendor/libigl/include/igl/smooth_corner_adjacency.cpp b/vendor/libigl/include/igl/smooth_corner_adjacency.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78eecff9fce1f228180539ca22051f44cb48120c --- /dev/null +++ b/vendor/libigl/include/igl/smooth_corner_adjacency.cpp @@ -0,0 +1,148 @@ +#include "smooth_corner_adjacency.h" +#include "vertex_triangle_adjacency.h" +#include "matlab_format.h" +#include "parallel_for.h" +#include "unzip_corners.h" +#include + +void igl::smooth_corner_adjacency( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const double corner_threshold_radians, + Eigen::VectorXi & CI, + Eigen::VectorXi & CC) +{ + typedef double Scalar; + typedef Eigen::Index Index; + Eigen::Matrix VF,NI; + igl::vertex_triangle_adjacency(F,V.rows(),VF,NI); + // unit normals + Eigen::Matrix FN(F.rows(),3); + igl::parallel_for(F.rows(),[&](const Index f) + { + const Eigen::Matrix v10 = V.row(F(f,1))-V.row(F(f,0)); + const Eigen::Matrix v20 = V.row(F(f,2))-V.row(F(f,0)); + const Eigen::Matrix n = v10.cross(v20); + const Scalar a = n.norm(); + FN.row(f) = n/a; + },10000); + + // number of faces + const Index m = F.rows(); + // valence of faces + const Index n = F.cols(); + assert(n == 3); + + CI.resize(m*n*8); + CI.setConstant(-1); + Index ncc = 0; + Index ci = -1; + // assumes that ci is strictly increasing and we're appending to CI + const auto append_CI = [&](Index nf) + { + // make room + if(ncc >= CI.size()) { CI.conservativeResize(CI.size()*2+1); } + CI(ncc++) = nf; + CC(ci+1)++; + }; + CC.resize(m*3+1); + CC.setConstant(-1); + CC(0) = 0; + + const Scalar cos_thresh = cos(corner_threshold_radians); + // parallelizing this probably requires map-reduce + for(Index i = 0;i cos_thresh) + { + append_CI(nf); + } + } + } + } + CI.conservativeResize(ncc); +} + + +void igl::smooth_corner_adjacency( + const Eigen::MatrixXi & FV, + const Eigen::MatrixXi & FN, + Eigen::VectorXi & CI, + Eigen::VectorXi & CC) +{ + typedef double Scalar; + typedef Eigen::Index Index; + assert(FV.rows() == FN.rows()); + assert(FV.cols() == 3); + assert(FN.cols() == 3); + Eigen::VectorXi J; + Index nu = -1; + { + Eigen::MatrixXi U; + Eigen::MatrixXi _; + igl::unzip_corners({FV,FN},U,_,J); + nu = U.rows(); + assert(J.maxCoeff() == nu-1); + } + // could use linear arrays here if every becomes bottleneck + std::vector> U2F(nu); + const Index m = FV.rows(); + for(Index j = 0;j<3;j++) + { + for(Index i = 0;i= CI.size()) { CI.conservativeResize(CI.size()*2+1); } + CI(ncc++) = nf; + CC(ci+1)++; + }; + for(Index i = 0;i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "snap_points.h" +#include +#include + +template < + typename DerivedC, + typename DerivedV, + typename DerivedI, + typename DerivedminD, + typename DerivedVI> +IGL_INLINE void igl::snap_points( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & minD, + Eigen::PlainObjectBase & VI) +{ + snap_points(C,V,I,minD); + const int m = C.rows(); + VI.resize(m,V.cols()); + for(int c = 0;c +IGL_INLINE void igl::snap_points( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & minD) +{ + using namespace std; + const int n = V.rows(); + const int m = C.rows(); + assert(V.cols() == C.cols() && "Dimensions should match"); + // O(m*n) + // + // I believe there should be a way to do this in O(m*log(n) + n) assuming + // reasonably distubed points. + I.resize(m,1); + typedef typename DerivedV::Scalar Scalar; + minD.setConstant(m,1,numeric_limits::max()); + for(int v = 0;v +IGL_INLINE void igl::snap_points( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & I) +{ + Eigen::Matrix minD; + return igl::snap_points(C,V,I,minD); +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::snap_points, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::snap_points, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::snap_points, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif + diff --git a/vendor/libigl/include/igl/snap_points.h b/vendor/libigl/include/igl/snap_points.h new file mode 100644 index 0000000000000000000000000000000000000000..21ad448b527e96121ec858037b1768541a18a321 --- /dev/null +++ b/vendor/libigl/include/igl/snap_points.h @@ -0,0 +1,67 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SNAP_POINTS_H +#define IGL_SNAP_POINTS_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // SNAP_POINTS snap list of points C to closest of another list of points V + // + // [I,minD,VI] = snap_points(C,V) + // + // Inputs: + // C #C by dim list of query point positions + // V #V by dim list of data point positions + // Outputs: + // I #C list of indices into V of closest points to C + // minD #C list of squared (^p) distances to closest points + // VI #C by dim list of new point positions, VI = V(I,:) + template < + typename DerivedC, + typename DerivedV, + typename DerivedI, + typename DerivedminD, + typename DerivedVI> + IGL_INLINE void snap_points( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & minD, + Eigen::PlainObjectBase & VI); + template < + typename DerivedC, + typename DerivedV, + typename DerivedI, + typename DerivedminD> + IGL_INLINE void snap_points( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & I, + Eigen::PlainObjectBase & minD); + template < + typename DerivedC, + typename DerivedV, + typename DerivedI > + IGL_INLINE void snap_points( + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & V, + Eigen::PlainObjectBase & I); +} + +#ifndef IGL_STATIC_LIBRARY +# include "snap_points.cpp" +#endif + +#endif + + + + diff --git a/vendor/libigl/include/igl/snap_to_canonical_view_quat.h b/vendor/libigl/include/igl/snap_to_canonical_view_quat.h new file mode 100644 index 0000000000000000000000000000000000000000..79bc3e02467f740b12d27162c68294db30835e41 --- /dev/null +++ b/vendor/libigl/include/igl/snap_to_canonical_view_quat.h @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SNAP_TO_CANONICAL_VIEW_QUAT_H +#define IGL_SNAP_TO_CANONICAL_VIEW_QUAT_H +#include "igl_inline.h" +#include +// A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w), +// such that q = x*i + y*j + z*k + w +namespace igl +{ + // Snap the quaternion q to the nearest canonical view quaternion + // Input: + // q quaternion to be snapped (also see Outputs) + // threshold (optional) threshold: + // 1.0 --> snap any input + // 0.5 --> snap inputs somewhat close to canonical views + // 0.0 --> snap no input + // Output: + // q quaternion possibly set to nearest canonical view + // Return: + // true only if q was snapped to the nearest canonical view + template + IGL_INLINE bool snap_to_canonical_view_quat( + const Q_type* q, + const Q_type threshold, + Q_type* s); + + template + IGL_INLINE bool snap_to_canonical_view_quat( + const Eigen::Quaternion & q, + const double threshold, + Eigen::Quaternion & s); +} + +#ifndef IGL_STATIC_LIBRARY +# include "snap_to_canonical_view_quat.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/snap_to_fixed_up.cpp b/vendor/libigl/include/igl/snap_to_fixed_up.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0fdd7de888fb3b95f141a4a451c14e11c662204 --- /dev/null +++ b/vendor/libigl/include/igl/snap_to_fixed_up.cpp @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "snap_to_fixed_up.h" + +template +IGL_INLINE void igl::snap_to_fixed_up( + const Eigen::Quaternion & q, + Eigen::Quaternion & s) +{ + using namespace Eigen; + typedef Eigen::Matrix Vector3Q; + const Vector3Q up = q.matrix() * Vector3Q(0,1,0); + Vector3Q proj_up(0,up(1),up(2)); + if(proj_up.norm() == 0) + { + proj_up = Vector3Q(0,1,0); + } + proj_up.normalize(); + Quaternion dq; + dq = Quaternion::FromTwoVectors(up,proj_up); + s = dq * q; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiations +template void igl::snap_to_fixed_up(Eigen::Quaternion const&, Eigen::Quaternion&); +template void igl::snap_to_fixed_up(Eigen::Quaternion const&, Eigen::Quaternion&); +#endif diff --git a/vendor/libigl/include/igl/snap_to_fixed_up.h b/vendor/libigl/include/igl/snap_to_fixed_up.h new file mode 100644 index 0000000000000000000000000000000000000000..4276fa79ca25050ccb39e49f6c1b83050fd0e163 --- /dev/null +++ b/vendor/libigl/include/igl/snap_to_fixed_up.h @@ -0,0 +1,39 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SNAP_TO_FIXED_UP_H +#define IGL_SNAP_TO_FIXED_UP_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Snap an arbitrary rotation to a rotation resulting from a rotation about + // the y-axis then the x-axis (maintaining fixed up like + // two_axis_valuator_fixed_up.) + // + // Inputs: + // q General rotation as quaternion + // Outputs: + // s the resulting rotation (as quaternion) + // + // See also: two_axis_valuator_fixed_up + template + IGL_INLINE void snap_to_fixed_up( + const Eigen::Quaternion & q, + Eigen::Quaternion & s); +} + +#ifndef IGL_STATIC_LIBRARY +# include "snap_to_fixed_up.cpp" +#endif + +#endif + + diff --git a/vendor/libigl/include/igl/solid_angle.cpp b/vendor/libigl/include/igl/solid_angle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d0b296a70222d9cceb26f984da963da2ef906537 --- /dev/null +++ b/vendor/libigl/include/igl/solid_angle.cpp @@ -0,0 +1,85 @@ +#include "solid_angle.h" +#include "PI.h" +#include + +template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedP> +IGL_INLINE typename DerivedA::Scalar igl::solid_angle( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & P) +{ + typedef typename DerivedA::Scalar SType; + // Gather vectors to corners + Eigen::Matrix v; + // Don't use this since it will freak out for templates with != 3 size + //v<< (A-P),(B-P),(C-P); + for(int d = 0;d<3;d++) + { + v(0,d) = A(d)-P(d); + v(1,d) = B(d)-P(d); + v(2,d) = C(d)-P(d); + } + Eigen::Matrix vl = v.rowwise().norm(); + //printf("\n"); + // Compute determinant + SType detf = + v(0,0)*v(1,1)*v(2,2)+ + v(1,0)*v(2,1)*v(0,2)+ + v(2,0)*v(0,1)*v(1,2)- + v(2,0)*v(1,1)*v(0,2)- + v(1,0)*v(0,1)*v(2,2)- + v(0,0)*v(2,1)*v(1,2); + // Compute pairwise dotproducts + Eigen::Matrix dp; + dp(0) = v(1,0)*v(2,0); + dp(0) += v(1,1)*v(2,1); + dp(0) += v(1,2)*v(2,2); + dp(1) = v(2,0)*v(0,0); + dp(1) += v(2,1)*v(0,1); + dp(1) += v(2,2)*v(0,2); + dp(2) = v(0,0)*v(1,0); + dp(2) += v(0,1)*v(1,1); + dp(2) += v(0,2)*v(1,2); + // Compute winding number + // Only divide by TWO_PI instead of 4*pi because there was a 2 out front + return atan2(detf, + vl(0)*vl(1)*vl(2) + + dp(0)*vl(0) + + dp(1)*vl(1) + + dp(2)*vl(2)) / (2.*igl::PI); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template Eigen::Block const, 1, 2, false>::Scalar igl::solid_angle const, 1, 2, false>, Eigen::Block const, 1, 2, false>, Eigen::Block const, 1, 2, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 2, false>::Scalar igl::solid_angle const, 1, 2, false>, Eigen::Block const, 1, 2, false>, Eigen::Block const, 1, 2, false>, Eigen::Block const, 1, -1, false> >(Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, 2, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 3, true>::Scalar igl::solid_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 3, true>::Scalar igl::solid_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, -1, false>::Scalar igl::solid_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 3, true>::Scalar igl::solid_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 3, true>::Scalar igl::solid_angle const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Block const, 1, 3, true>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase const, 1, 3, true> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 3, false>::Scalar igl::solid_angle const, 1, 3, false>, Eigen::Block const, 1, 3, false>, Eigen::Block const, 1, 3, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, 3, false>::Scalar igl::solid_angle const, 1, 3, false>, Eigen::Block const, 1, 3, false>, Eigen::Block const, 1, 3, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase const, 1, 3, false> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, -1, false>::Scalar igl::solid_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false> >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, -1, false>::Scalar igl::solid_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, -1, false>::Scalar igl::solid_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template Eigen::Block const, 1, -1, false>::Scalar igl::solid_angle const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Block const, 1, -1, false>, Eigen::Matrix >(Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase const, 1, -1, false> > const&, Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/solid_angle.h b/vendor/libigl/include/igl/solid_angle.h new file mode 100644 index 0000000000000000000000000000000000000000..2ee98a24742ae376c46cee4a2cfcd9aa71455d56 --- /dev/null +++ b/vendor/libigl/include/igl/solid_angle.h @@ -0,0 +1,29 @@ +#ifndef IGL_SOLID_ANGLE_H +#define IGL_SOLID_ANGLE_H +#include "igl_inline.h" +#include +namespace igl +{ + // Compute the signed solid angle subtended by the oriented 3d triangle (A,B,C) at some point P + // + // Inputs: + // A 3D position of corner + // B 3D position of corner + // C 3D position of corner + // P 3D position of query point + // Returns signed solid angle + template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedP> + IGL_INLINE typename DerivedA::Scalar solid_angle( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & P); +} +#ifndef IGL_STATIC_LIBRARY +# include "solid_angle.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/sort.cpp b/vendor/libigl/include/igl/sort.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13c407fc18d3d4195a4d57b2d39f724a09d6941d --- /dev/null +++ b/vendor/libigl/include/igl/sort.cpp @@ -0,0 +1,384 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "sort.h" + +#include "SortableRow.h" +#include "reorder.h" +#include "IndexComparison.h" +#include "colon.h" +#include "parallel_for.h" + +#include +#include +#include + +template +IGL_INLINE void igl::sort( + const Eigen::DenseBase& X, + const int dim, + const bool ascending, + Eigen::PlainObjectBase& Y, + Eigen::PlainObjectBase& IX) +{ + typedef typename DerivedX::Scalar Scalar; + // get number of rows (or columns) + int num_inner = (dim == 1 ? X.rows() : X.cols() ); + // Special case for swapping + switch(num_inner) + { + default: + break; + case 2: + return igl::sort2(X,dim,ascending,Y,IX); + case 3: + return igl::sort3(X,dim,ascending,Y,IX); + } + using namespace Eigen; + // get number of columns (or rows) + int num_outer = (dim == 1 ? X.cols() : X.rows() ); + // dim must be 2 or 1 + assert(dim == 1 || dim == 2); + // Resize output + Y.resizeLike(X); + IX.resizeLike(X); + // idea is to process each column (or row) as a std vector + // loop over columns (or rows) + for(int i = 0; i index_map(num_inner); + std::vector data(num_inner); + for(int j = 0;j +IGL_INLINE void igl::sort( + const Eigen::DenseBase& X, + const int dim, + const bool ascending, + Eigen::PlainObjectBase& Y) +{ + Eigen::Matrix< int, DerivedX::RowsAtCompileTime, DerivedX::ColsAtCompileTime > IX; + return sort(X,dim,ascending,Y,IX); +} + +template +IGL_INLINE void igl::sort_new( + const Eigen::DenseBase& X, + const int dim, + const bool ascending, + Eigen::PlainObjectBase& Y, + Eigen::PlainObjectBase& IX) +{ + // get number of rows (or columns) + int num_inner = (dim == 1 ? X.rows() : X.cols() ); + // Special case for swapping + switch(num_inner) + { + default: + break; + case 2: + return igl::sort2(X,dim,ascending,Y,IX); + case 3: + return igl::sort3(X,dim,ascending,Y,IX); + } + using namespace Eigen; + // get number of columns (or rows) + int num_outer = (dim == 1 ? X.cols() : X.rows() ); + // dim must be 2 or 1 + assert(dim == 1 || dim == 2); + // Resize output + Y.resizeLike(X); + IX.resizeLike(X); + // idea is to process each column (or row) as a std vector + // loop over columns (or rows) + for(int i = 0; i(X.col(i))); + }else + { + std::sort( + ix.data(), + ix.data()+ix.size(), + igl::IndexVectorLessThan(X.row(i))); + } + // if not ascending then reverse + if(!ascending) + { + std::reverse(ix.data(),ix.data()+ix.size()); + } + for(int j = 0;j +IGL_INLINE void igl::sort2( + const Eigen::DenseBase& X, + const int dim, + const bool ascending, + Eigen::PlainObjectBase& Y, + Eigen::PlainObjectBase& IX) +{ + using namespace Eigen; + using namespace std; + typedef typename DerivedY::Scalar YScalar; + Y = X.derived().template cast(); + + + // get number of columns (or rows) + int num_outer = (dim == 1 ? X.cols() : X.rows() ); + // get number of rows (or columns) + int num_inner = (dim == 1 ? X.rows() : X.cols() ); + assert(num_inner == 2);(void)num_inner; + typedef typename DerivedIX::Scalar Index; + IX.resizeLike(X); + if(dim==1) + { + IX.row(0).setConstant(0);// = DerivedIX::Zero(1,IX.cols()); + IX.row(1).setConstant(1);// = DerivedIX::Ones (1,IX.cols()); + }else + { + IX.col(0).setConstant(0);// = DerivedIX::Zero(IX.rows(),1); + IX.col(1).setConstant(1);// = DerivedIX::Ones (IX.rows(),1); + } + // loop over columns (or rows) + for(int i = 0;ib) || (!ascending && a +IGL_INLINE void igl::sort3( + const Eigen::DenseBase& X, + const int dim, + const bool ascending, + Eigen::PlainObjectBase& Y, + Eigen::PlainObjectBase& IX) +{ + using namespace Eigen; + using namespace std; + typedef typename DerivedY::Scalar YScalar; + Y = X.derived().template cast(); + Y.resizeLike(X); + for(int j=0;j b) + { + std::swap(a,b); + std::swap(ai,bi); + } + // 123 132 123 231 132 231 + if(b > c) + { + std::swap(b,c); + std::swap(bi,ci); + // 123 123 123 213 123 213 + if(a > b) + { + std::swap(a,b); + std::swap(ai,bi); + } + // 123 123 123 123 123 123 + } + }else + { + // 123 132 213 231 312 321 + if(a < b) + { + std::swap(a,b); + std::swap(ai,bi); + } + // 213 312 213 321 312 321 + if(b < c) + { + std::swap(b,c); + std::swap(bi,ci); + // 231 321 231 321 321 321 + if(a < b) + { + std::swap(a,b); + std::swap(ai,bi); + } + // 321 321 321 321 321 321 + } + } + }; + parallel_for(num_outer,inner,16000); +} + +template +IGL_INLINE void igl::sort( +const std::vector & unsorted, +const bool ascending, +std::vector & sorted, +std::vector & index_map) +{ +// Original unsorted index map +index_map.resize(unsorted.size()); +for(size_t i=0;i& >(unsorted)); + +// if not ascending then reverse +if(!ascending) +{ + std::reverse(index_map.begin(),index_map.end()); +} + // make space for output without clobbering + sorted.resize(unsorted.size()); + // reorder unsorted into sorted using index map + igl::reorder(unsorted,index_map,sorted); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, 1, -1, false>, Eigen::Matrix >(Eigen::DenseBase, 1, -1, false> > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort(std::vector > const&, bool, std::vector >&, std::vector > &); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort_new, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort(std::vector > const&, bool, std::vector >&, std::vector >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template void igl::sort,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::DenseBase > const &,int,bool,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +template void igl::sort<__int64>(class std::vector<__int64,class std::allocator<__int64> > const &,bool,class std::vector<__int64,class std::allocator<__int64> > &,class std::vector > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/sort_triangles.cpp b/vendor/libigl/include/igl/sort_triangles.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f2cc2304b11f9f87e2fc2cd81d721da0f90d3db --- /dev/null +++ b/vendor/libigl/include/igl/sort_triangles.cpp @@ -0,0 +1,57 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "sort_triangles.h" +#include "barycenter.h" +#include "sort.h" +#include "sortrows.h" +#include "slice.h" +#include "round.h" +#include "colon.h" + +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedMV, + typename DerivedP, + typename DerivedFF, + typename DerivedI> +IGL_INLINE void igl::sort_triangles( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & MV, + const Eigen::MatrixBase & P, + Eigen::PlainObjectBase & FF, + Eigen::PlainObjectBase & I) +{ + using namespace Eigen; + using namespace std; + + + typedef typename DerivedV::Scalar Scalar; + // Barycenter, centroid + Eigen::Matrix D,sD; + Eigen::Matrix BC; + barycenter(V,F,BC); + Eigen::Matrix BC4(BC.rows(),4); + BC4.leftCols(3) = BC; + BC4.col(3).setConstant(1); + D = BC4*( + MV.template cast().transpose()* + P.template cast().transpose().eval().col(2)); + sort(D,1,false,sD,I); + slice(F,I,1,FF); +} + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::sort_triangles, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::sort_triangles, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/sort_vectors_ccw.cpp b/vendor/libigl/include/igl/sort_vectors_ccw.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea613c51b7c660d607370494e2cc272709553001 --- /dev/null +++ b/vendor/libigl/include/igl/sort_vectors_ccw.cpp @@ -0,0 +1,103 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include +#include +#include + +template +IGL_INLINE void igl::sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order) +{ + int half_degree = P.cols()/3; + //local frame + Eigen::Matrix e1 = P.head(3).normalized(); + Eigen::Matrix e3 = N.normalized(); + Eigen::Matrix e2 = e3.cross(e1); + + Eigen::Matrix F; F< angles(half_degree,1); + for (int i=0; i Pl = F.colPivHouseholderQr().solve(P.segment(i*3,3).transpose()).transpose(); +// assert(fabs(Pl(2))/Pl.cwiseAbs().maxCoeff() <1e-5); + angles[i] = atan2(Pl(1),Pl(0)); + } + + igl::sort( angles, 1, true, angles, order); + //make sure that the first element is always at the top + while (order[0] != 0) + { + //do a circshift + int temp = order[0]; + for (int i =0; i< half_degree-1; ++i) + order[i] = order[i+1]; + order(half_degree-1) = temp; + } +} + +template +IGL_INLINE void igl::sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order, + Eigen::PlainObjectBase &sorted) + { + int half_degree = P.cols()/3; + igl::sort_vectors_ccw(P,N,order); + sorted.resize(1,half_degree*3); + for (int i=0; i +IGL_INLINE void igl::sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order, + Eigen::PlainObjectBase &inv_order) + { + int half_degree = P.cols()/3; + igl::sort_vectors_ccw(P,N,order); + inv_order.resize(half_degree,1); + for (int i=0; i +IGL_INLINE void igl::sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order, + Eigen::PlainObjectBase &sorted, + Eigen::PlainObjectBase &inv_order) +{ + int half_degree = P.cols()/3; + + igl::sort_vectors_ccw(P,N,order,inv_order); + + sorted.resize(1,half_degree*3); + for (int i=0; i, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +template void igl::sort_vectors_ccw, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/sort_vectors_ccw.h b/vendor/libigl/include/igl/sort_vectors_ccw.h new file mode 100644 index 0000000000000000000000000000000000000000..73c2f6fba6513bd6c4f7213c50047ca9f00a8af8 --- /dev/null +++ b/vendor/libigl/include/igl/sort_vectors_ccw.h @@ -0,0 +1,68 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Olga Diamanti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_SORT_VECTORS_CCW +#define IGL_SORT_VECTORS_CCW +#include "igl_inline.h" + +#include + +namespace igl { + // Sorts a set of N coplanar vectors in a ccw order, and returns their order. + // Optionally it also returns a copy of the ordered vector set, or the indices, + // in the original unordered set, of the vectors in the ordered set (called here + // the "inverse" set of indices). + + // Inputs: + // P 1 by 3N row vector of the vectors to be sorted, stacked horizontally + // N #1 by 3 normal of the plane where the vectors lie + // Output: + // order N by 1 order of the vectors (indices of the unordered vectors into + // the ordered vector set) + // sorted 1 by 3N row vector of the ordered vectors, stacked horizontally + // inv_order N by 1 "inverse" order of the vectors (the indices of the ordered + // vectors into the unordered vector set) + // + template + IGL_INLINE void sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order, + Eigen::PlainObjectBase &sorted, + Eigen::PlainObjectBase &inv_order); + + template + IGL_INLINE void sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order, + Eigen::PlainObjectBase &sorted); + + template + IGL_INLINE void sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order, + Eigen::PlainObjectBase &inv_order); + + + template + IGL_INLINE void sort_vectors_ccw( + const Eigen::PlainObjectBase& P, + const Eigen::PlainObjectBase& N, + Eigen::PlainObjectBase &order); + +}; + + +#ifndef IGL_STATIC_LIBRARY +#include "sort_vectors_ccw.cpp" +#endif + + +#endif /* defined(IGL_FIELD_LOCAL_GLOBAL_CONVERSIONS) */ diff --git a/vendor/libigl/include/igl/sparse.cpp b/vendor/libigl/include/igl/sparse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b3a85b2d10492071ebea98542696459017257873 --- /dev/null +++ b/vendor/libigl/include/igl/sparse.cpp @@ -0,0 +1,129 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "sparse.h" + +#include +#include + +template +IGL_INLINE void igl::sparse( + const IndexVector & I, + const IndexVector & J, + const ValueVector & V, + Eigen::SparseMatrix& X) +{ + size_t m = (size_t)I.maxCoeff()+1; + size_t n = (size_t)J.maxCoeff()+1; + return igl::sparse(I,J,V,m,n,X); +} + +#include "verbose.h" +template < + class IndexVectorI, + class IndexVectorJ, + class ValueVector, + typename T> +IGL_INLINE void igl::sparse( + const IndexVectorI & I, + const IndexVectorJ & J, + const ValueVector & V, + const size_t m, + const size_t n, + Eigen::SparseMatrix& X) +{ + using namespace std; + using namespace Eigen; + assert((int)I.maxCoeff() < (int)m); + assert((int)I.minCoeff() >= 0); + assert((int)J.maxCoeff() < (int)n); + assert((int)J.minCoeff() >= 0); + assert(I.size() == J.size()); + assert(J.size() == V.size()); + // Really we just need .size() to be the same, but this is safer + assert(I.rows() == J.rows()); + assert(J.rows() == V.rows()); + assert(I.cols() == J.cols()); + assert(J.cols() == V.cols()); + //// number of values + //int nv = V.size(); + + //Eigen::DynamicSparseMatrix dyn_X(m,n); + //// over estimate the number of entries + //dyn_X.reserve(I.size()); + //for(int i = 0;i < nv;i++) + //{ + // dyn_X.coeffRef((int)I(i),(int)J(i)) += (T)V(i); + //} + //X = Eigen::SparseMatrix(dyn_X); + vector > IJV; + IJV.reserve(I.size()); + for(int x = 0;x(I(x),J(x),V(x))); + } + X.resize(m,n); + X.setFromTriplets(IJV.begin(),IJV.end()); +} + +template +IGL_INLINE void igl::sparse( + const Eigen::PlainObjectBase& D, + Eigen::SparseMatrix& X) +{ + assert(false && "Obsolete. Just call D.sparseView() directly"); + using namespace std; + using namespace Eigen; + vector > DIJV; + const int m = D.rows(); + const int n = D.cols(); + for(int i = 0;i(i,j,D(i,j))); + } + } + } + X.resize(m,n); + X.setFromTriplets(DIJV.begin(),DIJV.end()); +} + +template +IGL_INLINE Eigen::SparseMatrix igl::sparse( + const Eigen::PlainObjectBase& D) +{ + assert(false && "Obsolete. Just call D.sparseView() directly"); + Eigen::SparseMatrix X; + igl::sparse(D,X); + return X; +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::sparse, Eigen::Matrix, Eigen::Matrix, int>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, unsigned long, unsigned long, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::sparse, -1, 1, true>, Eigen::Block, -1, 1, true>, Eigen::CwiseNullaryOp, Eigen::Matrix >, int>(Eigen::Block, -1, 1, true> const&, Eigen::Block, -1, 1, true> const&, Eigen::CwiseNullaryOp, Eigen::Matrix > const&, unsigned long, unsigned long, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +template void igl::sparse, -1, 1, true>, Eigen::Block, -1, 1, true>, Eigen::CwiseBinaryOp, Eigen::CwiseNullaryOp, Eigen::Array const> const, Eigen::CwiseBinaryOp, Eigen::CwiseNullaryOp, Eigen::Array const> const, Eigen::CwiseUnaryOp, Eigen::CwiseBinaryOp, Eigen::ArrayWrapper, -1, 1, true> > const, Eigen::ArrayWrapper, -1, 1, true> > const> const> const> const>, int>(Eigen::Block, -1, 1, true> const&, Eigen::Block, -1, 1, true> const&, Eigen::CwiseBinaryOp, Eigen::CwiseNullaryOp, Eigen::Array const> const, Eigen::CwiseBinaryOp, Eigen::CwiseNullaryOp, Eigen::Array const> const, Eigen::CwiseUnaryOp, Eigen::CwiseBinaryOp, Eigen::ArrayWrapper, -1, 1, true> > const, Eigen::ArrayWrapper, -1, 1, true> > const> const> const> const> const&, unsigned long, unsigned long, Eigen::SparseMatrix&); +// generated by autoexplicit.sh +#ifndef WIN32 +//template void igl::sparse >, Eigen::Matrix, Eigen::CwiseNullaryOp, Eigen::Array >, bool>(Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::CwiseNullaryOp, Eigen::Array > const&, unsigned long, unsigned long, Eigen::SparseMatrix&); +//template void igl::sparse >, Eigen::MatrixBase >, Eigen::CwiseNullaryOp, Eigen::Array >, bool>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::CwiseNullaryOp, Eigen::Array > const&, unsigned long, unsigned long, Eigen::SparseMatrix&); +#if EIGEN_VERSION_AT_LEAST(3,3,0) +#else +//template void igl::sparse, Eigen::Matrix >, Eigen::Matrix, Eigen::CwiseNullaryOp, Eigen::Array >, bool>(Eigen::CwiseNullaryOp, Eigen::Matrix > const&, Eigen::Matrix const&, Eigen::CwiseNullaryOp, Eigen::Array > const&, unsigned long, unsigned long, Eigen::SparseMatrix&); +#endif +#endif + +template void igl::sparse, Eigen::Matrix, Eigen::Matrix, std::complex >(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, size_t, size_t, Eigen::SparseMatrix, 0, int>&); +template void igl::sparse, Eigen::Matrix, double>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::SparseMatrix&); +template void igl::sparse, Eigen::Matrix, Eigen::Matrix, double>(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, size_t, size_t, Eigen::SparseMatrix&); +#endif diff --git a/vendor/libigl/include/igl/sparse.h b/vendor/libigl/include/igl/sparse.h new file mode 100644 index 0000000000000000000000000000000000000000..a947978ab1dada3198f7126390b810b6f03f89cf --- /dev/null +++ b/vendor/libigl/include/igl/sparse.h @@ -0,0 +1,78 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SPARSE_H +#define IGL_SPARSE_H +#include "igl_inline.h" +#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET +#include +#include +namespace igl +{ + // Build a sparse matrix from list of indices and values (I,J,V), functions + // like the sparse function in matlab + // + // Templates: + // IndexVector list of indices, value should be non-negative and should + // expect to be cast to an index. Must implement operator(i) to retrieve + // ith element + // ValueVector list of values, value should be expect to be cast to type + // T. Must implement operator(i) to retrieve ith element + // T should be a eigen sparse matrix primitive type like int or double + // Input: + // I nnz vector of row indices of non zeros entries in X + // J nnz vector of column indices of non zeros entries in X + // V nnz vector of non-zeros entries in X + // Optional: + // m number of rows + // n number of cols + // Outputs: + // X m by n matrix of type T whose entries are to be found + // + template + IGL_INLINE void sparse( + const IndexVector & I, + const IndexVector & J, + const ValueVector & V, + Eigen::SparseMatrix& X); + template < + class IndexVectorI, + class IndexVectorJ, + class ValueVector, + typename T> + IGL_INLINE void sparse( + const IndexVectorI & I, + const IndexVectorJ & J, + const ValueVector & V, + const size_t m, + const size_t n, + Eigen::SparseMatrix& X); + // THIS MAY BE SUPERSEDED BY EIGEN'S .sparseView Indeed it is. + // Convert a full, dense matrix to a sparse one + // + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Input: + // D m by n full, dense matrix + // Output: + // X m by n sparse matrix + template + IGL_INLINE void sparse( + const Eigen::PlainObjectBase& D, + Eigen::SparseMatrix& X); + // Wrapper with return + template + IGL_INLINE Eigen::SparseMatrix sparse( + const Eigen::PlainObjectBase& D); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "sparse.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/sparse_cached.cpp b/vendor/libigl/include/igl/sparse_cached.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ddd65aadf50d1b5cda335fe287709429dce365fc --- /dev/null +++ b/vendor/libigl/include/igl/sparse_cached.cpp @@ -0,0 +1,127 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "sparse_cached.h" + +#include +#include +#include +#include +#include +#include + +template +IGL_INLINE void igl::sparse_cached_precompute( + const Eigen::MatrixBase & I, + const Eigen::MatrixBase & J, + Eigen::VectorXi& data, + Eigen::SparseMatrix& X) +{ + // Generates the triplets + std::vector > t(I.size()); + for (unsigned i = 0; i(I[i],J[i],1); + + // Call the triplets version + sparse_cached_precompute(t,X,data); +} + +template +IGL_INLINE void igl::sparse_cached_precompute( + const std::vector >& triplets, + Eigen::VectorXi& data, + Eigen::SparseMatrix& X) +{ + // Construct an empty sparse matrix + X.setFromTriplets(triplets.begin(),triplets.end()); + X.makeCompressed(); + + std::vector > T(triplets.size()); + for (unsigned i=0; i= 0); + assert(row < X.rows()); + assert(row >= 0); + assert(value_index >= 0); + assert(value_index < X.nonZeros()); + + std::pair p_m = std::make_pair(row,col); + + while (t +IGL_INLINE void igl::sparse_cached( + const std::vector >& triplets, + const Eigen::VectorXi& data, + Eigen::SparseMatrix& X) +{ + assert(triplets.size() == data.size()); + + // Clear it first + for (unsigned i = 0; i +IGL_INLINE void igl::sparse_cached( + const Eigen::MatrixBase& V, + const Eigen::VectorXi& data, + Eigen::SparseMatrix& X) +{ + assert(V.size() == data.size()); + + // Clear it first + for (unsigned i = 0; i(std::vector::StorageIndex>, std::allocator::StorageIndex> > > const&, Eigen::Matrix const&, Eigen::SparseMatrix&); + template void igl::sparse_cached_precompute(std::vector::StorageIndex>, std::allocator::StorageIndex> > > const&, Eigen::Matrix&, Eigen::SparseMatrix&); +#else + template void igl::sparse_cached(std::vector::Index>, std::allocator::Index> > > const&, Eigen::Matrix const&, Eigen::SparseMatrix&); + template void igl::sparse_cached_precompute(std::vector::Index>, std::allocator::Index> > > const&, Eigen::Matrix&, Eigen::SparseMatrix&); +#endif +#endif diff --git a/vendor/libigl/include/igl/squared_edge_lengths.h b/vendor/libigl/include/igl/squared_edge_lengths.h new file mode 100644 index 0000000000000000000000000000000000000000..2f374d6c3af75418a9bba9bc6f0b8d4d99125965 --- /dev/null +++ b/vendor/libigl/include/igl/squared_edge_lengths.h @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SQUARED_EDGE_LENGTHS_H +#define IGL_SQUARED_EDGE_LENGTHS_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Constructs a list of squared lengths of edges opposite each index in a face + // (triangle/tet) list + // + // Templates: + // DerivedV derived from vertex positions matrix type: i.e. MatrixXd + // DerivedF derived from face indices matrix type: i.e. MatrixXi + // DerivedL derived from edge lengths matrix type: i.e. MatrixXd + // Inputs: + // V eigen matrix #V by 3 + // F #F by 2 list of mesh edges + // or + // F #F by 3 list of mesh faces (must be triangles) + // or + // T #T by 4 list of mesh elements (must be tets) + // Outputs: + // L #F by {1|3|6} list of edge lengths squared + // for edges, column of lengths + // for triangles, columns correspond to edges [1,2],[2,0],[0,1] + // for tets, columns correspond to edges + // [3 0],[3 1],[3 2],[1 2],[2 0],[0 1] + // + template + IGL_INLINE void squared_edge_lengths( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& L); +} + +#ifndef IGL_STATIC_LIBRARY +# include "squared_edge_lengths.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/stdin_to_temp.cpp b/vendor/libigl/include/igl/stdin_to_temp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7a7fbd70a1dfa732734fe265fd2a78b09a7ff45 --- /dev/null +++ b/vendor/libigl/include/igl/stdin_to_temp.cpp @@ -0,0 +1,38 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "stdin_to_temp.h" + +#include + +IGL_INLINE bool igl::stdin_to_temp(FILE ** temp_file) +{ + // get a temporary file + *temp_file = tmpfile(); + if(*temp_file == NULL) + { + fprintf(stderr,"IOError: temp file could not be created.\n"); + return false; + } + char c; + // c++'s cin handles the stdind input in a reasonable way + while (std::cin.good()) + { + c = std::cin.get(); + if(std::cin.good()) + { + if(1 != fwrite(&c,sizeof(char),1,*temp_file)) + { + fprintf(stderr,"IOError: error writing to tempfile.\n"); + return false; + } + } + } + // rewind file getting it ready to read from + rewind(*temp_file); + return true; +} diff --git a/vendor/libigl/include/igl/stdin_to_temp.h b/vendor/libigl/include/igl/stdin_to_temp.h new file mode 100644 index 0000000000000000000000000000000000000000..ae35219ea52d0258f34cbedae049f6b23ec1ab35 --- /dev/null +++ b/vendor/libigl/include/igl/stdin_to_temp.h @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_STDIN_TO_TEMP_H +#define IGL_STDIN_TO_TEMP_H +#include "igl_inline.h" +#include +namespace igl +{ + // Write stdin/piped input to a temporary file which can than be preprocessed as it + // is (a normal file). This is often useful if you want to process stdin/piped + // with library functions that expect to be able to fseek(), rewind() etc.. + // + // If your application is not using fseek(), rewind(), etc. but just reading + // from stdin then this will likely cause a bottle neck as it defeats the whole + // purpose of piping. + // + // Outputs: + // temp_file pointer to temp file pointer, rewound to beginning of file so + // its ready to be read + // Return true only if no errors were found + // + // Note: Caller is responsible for closing the file (tmpfile() automatically + // unlinks the file so there is no need to remove/delete/unlink the file) + IGL_INLINE bool stdin_to_temp(FILE ** temp_file); +} + +#ifndef IGL_STATIC_LIBRARY +# include "stdin_to_temp.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/straighten_seams.cpp b/vendor/libigl/include/igl/straighten_seams.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d15f1b6340e9af3f579bec20c5b4e7c5b04e2893 --- /dev/null +++ b/vendor/libigl/include/igl/straighten_seams.cpp @@ -0,0 +1,370 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "straighten_seams.h" +#include "LinSpaced.h" +#include "on_boundary.h" +#include "sparse.h" +#include "max.h" +#include "count.h" +#include "any.h" +#include "slice_mask.h" +#include "slice_into.h" +#include "unique_simplices.h" +#include "adjacency_matrix.h" +#include "setxor.h" +#include "edges_to_path.h" +#include "ramer_douglas_peucker.h" +#include "vertex_components.h" +#include "list_to_matrix.h" +#include "ears.h" +#include "slice.h" +#include "sum.h" +#include "find.h" +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedVT, + typename DerivedFT, + typename Scalar, + typename DerivedUE, + typename DerivedUT, + typename DerivedOT> +IGL_INLINE void igl::straighten_seams( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & VT, + const Eigen::MatrixBase & FT, + const Scalar tol, + Eigen::PlainObjectBase & UE, + Eigen::PlainObjectBase & UT, + Eigen::PlainObjectBase & OT) +{ + using namespace Eigen; + // number of faces + assert(FT.rows() == F.rows() && "#FT must == #F"); + assert(F.cols() == 3 && "F should contain triangles"); + assert(FT.cols() == 3 && "FT should contain triangles"); + const int m = F.rows(); + // Boundary edges of the texture map and 3d meshes + Array _; + Array BT,BF; + on_boundary(FT,_,BT); + on_boundary(F,_,BF); + assert((!((BF && (BT!=true)).any())) && + "Not dealing with boundaries of mesh that get 'stitched' in texture mesh"); + typedef Matrix MatrixX2I; + const MatrixX2I ET = (MatrixX2I(FT.rows()*3,2) + <vBT = Map >(BT.data(),BT.size(),1); + ArrayvBF = Map >(BF.data(),BF.size(),1); + MatrixX2I OF; + slice_mask(ET,vBT,1,OT); + slice_mask(EF,vBT,1,OF); + VectorXi OFMAP; + slice_mask(EFMAP,vBT,1,OFMAP); + // Two boundary edges on the texture-mapping are "equivalent" to each other on + // the 3D-mesh if their 3D-mesh vertex indices match + SparseMatrix OEQ; + { + SparseMatrix OEQR; + sparse( + igl::LinSpaced(OT.rows(),0,OT.rows()-1), + OFMAP, + Array::Ones(OT.rows(),1), + OT.rows(), + m*3, + OEQR); + OEQ = OEQR * OEQR.transpose(); + // Remove diagonal + OEQ.prune([](const int r, const int c, const bool)->bool{return r!=c;}); + } + // For each edge in OT, for each endpoint, how many _other_ texture-vertices + // are images of all the 3d-mesh vertices in F who map from "corners" in F/FT + // mapping to this endpoint. + // + // Adjacency matrix between 3d-vertices and texture-vertices + SparseMatrix V2VT; + sparse( + F, + FT, + Array::Ones(F.rows(),F.cols()), + V.rows(), + VT.rows(), + V2VT); + // For each 3d-vertex count how many different texture-coordinates its getting + // from different incident corners + VectorXi DV; + count(V2VT,2,DV); + VectorXi M,I; + max(V2VT,1,M,I); + assert( (M.array() == 1).all() ); + VectorXi DT; + // Map counts onto texture-vertices + slice(DV,I,1,DT); + // Boundary in 3D && UV + Array BTF; + slice_mask(vBF, vBT, 1, BTF); + // Texture-vertex is "sharp" if incident on "half-"edge that is not a + // boundary in the 3D mesh but is a boundary in the texture-mesh AND is not + // "cut cleanly" (the vertex is mapped to exactly 2 locations) + Array SV = Array::Zero(VT.rows(),1); + //std::cout<<"#SV: "< CL = DT.array()==2; + SparseMatrix VTOT; + { + Eigen::MatrixXi I = + igl::LinSpaced(OT.rows(),0,OT.rows()-1).replicate(1,2); + sparse( + OT, + I, + Array::Ones(OT.rows(),OT.cols()), + VT.rows(), + OT.rows(), + VTOT); + Array cuts; + count( (VTOT*OEQ).eval(), 2, cuts); + CL = (CL && (cuts.array() == 2)).eval(); + } + //std::cout<<"#CL: "< earT = Array::Zero(VT.rows(),1); + for(int e = 0;e A; + adjacency_matrix(FT,A); + earT = (earT || (A*earT.matrix()).array()).eval(); + //std::cout<<"#earT: "< V2VTSV,V2VTC; + slice_mask(V2VT,SV,2,V2VTSV); + Array Cb; + any(V2VTSV,2,Cb); + slice_mask(V2VT,Cb,1,V2VTC); + any(V2VTC,1,SV); + } + //std::cout<<"#SV: "< OTVT = VTOT.transpose(); + int nc; + ArrayXi C; + { + // Doesn't Compile on older Eigen: + //SparseMatrix A = OTVT * (!SV).matrix().asDiagonal() * VTOT; + SparseMatrix A = OTVT * (SV!=true).matrix().asDiagonal() * VTOT; + vertex_components(A,C); + nc = C.maxCoeff()+1; + } + //std::cout<<"nc: "< > vUE; + // loop over each component + std::vector done(nc,false); + for(int c = 0;c OEQIc; + slice(OEQ,Ic,1,OEQIc); + Eigen::VectorXi N; + sum(OEQIc,2,N); + const int ncopies = N(0)+1; + assert((N.array() == ncopies-1).all()); + assert((ncopies == 1 || ncopies == 2) && + "Not dealing with non-manifold meshes"); + Eigen::VectorXi vpath,epath,eend; + typedef Eigen::Matrix MatrixX2S; + switch(ncopies) + { + case 1: + { + MatrixX2I OTIc; + slice(OT,Ic,1,OTIc); + edges_to_path(OTIc,vpath,epath,eend); + Array SVvpath; + slice(SV,vpath,1,SVvpath); + assert( + (vpath(0) != vpath(vpath.size()-1) || !SVvpath.any()) && + "Not dealing with 1-loops touching 'sharp' corners"); + // simple open boundary + MatrixX2S PI; + slice(VT,vpath,1,PI); + const Scalar bbd = + (PI.colwise().maxCoeff() - PI.colwise().minCoeff()).norm(); + // Do not collapse boundaries to fewer than 3 vertices + const bool allow_boundary_collapse = false; + assert(PI.size() >= 2); + const bool is_closed = PI(0) == PI(PI.size()-1); + assert(!is_closed || vpath.size() >= 4); + Scalar eff_tol = std::min(tol,2.); + VectorXi UIc; + while(true) + { + MatrixX2S UPI,UTvpath; + ramer_douglas_peucker(PI,eff_tol*bbd,UPI,UIc,UTvpath); + slice_into(UTvpath,vpath,1,UT); + if(!is_closed || allow_boundary_collapse) + { + break; + } + if(UPI.rows()>=4) + { + break; + } + eff_tol = eff_tol*0.5; + } + for(int i = 0;i IV; + SparseMatrix OEQIcT = OEQIc.transpose().eval(); + find(OEQIcT,Icc,II,IV); + assert(II.size() == Ic.size() && + (II.array() == + igl::LinSpaced(Ic.size(),0,Ic.size()-1).array()).all()); + assert(Icc.size() == Ic.size()); + const int cc = C(Icc(0)); + Eigen::VectorXi CIcc; + slice(C,Icc,1,CIcc); + assert((CIcc.array() == cc).all()); + assert(!done[cc]); + done[cc] = true; + } + Array flipped; + { + MatrixX2I OFIc,OFIcc; + slice(OF,Ic,1,OFIc); + slice(OF,Icc,1,OFIcc); + Eigen::VectorXi XOR,IA,IB; + setxor(OFIc,OFIcc,XOR,IA,IB); + assert(XOR.size() == 0); + flipped = OFIc.array().col(0) != OFIcc.array().col(0); + } + if(Ic.size() == 1) + { + // No change to UT + vUE.push_back({OT(Ic(0),0),OT(Ic(0),1)}); + assert(Icc.size() == 1); + vUE.push_back({OT(Icc(0),flipped(0)?1:0),OT(Icc(0),flipped(0)?0:1)}); + }else + { + MatrixX2I OTIc; + slice(OT,Ic,1,OTIc); + edges_to_path(OTIc,vpath,epath,eend); + // Flip endpoints if needed + for(int e = 0;e PI(vpath.size(),VT.cols()*2); + for(int p = 0;p UPI,SI; + VectorXi UIc; + ramer_douglas_peucker(PI,tol*bbd,UPI,UIc,SI); + slice_into(SI.leftCols (VT.cols()), vpath,1,UT); + slice_into(SI.rightCols(VT.cols()),vpathc,1,UT); + for(int i = 0;i, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, double, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, double, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/straighten_seams.h b/vendor/libigl/include/igl/straighten_seams.h new file mode 100644 index 0000000000000000000000000000000000000000..2eb0e9d469eebdc470719f13f439b0e047a248b0 --- /dev/null +++ b/vendor/libigl/include/igl/straighten_seams.h @@ -0,0 +1,57 @@ +#ifndef IGL_STRAIGHTEN_SEAMS_H +#define IGL_STRAIGHTEN_SEAMS_H + +#include "igl_inline.h" +#include + +namespace igl +{ + // STRAIGHTEN_SEAMS Given a obj-style mesh with (V,F) defining the geometric + // surface of the mesh and (VT,FT) defining the + // parameterization/texture-mapping of the mesh in the uv-domain, find all + // seams and boundaries in the texture-mapping and "straighten" them, + // remapping vertices along the boundary and in the interior. This will be + // careful to consistently straighten multiple seams in the texture-mesh + // corresponding to the same edge chains in the surface-mesh. + // + // [UT] = straighten_seams(V,F,VT,FT) + // + // Inputs: + // V #V by 3 list of vertices + // F #F by 3 list of triangle indices + // VT #VT by 2 list of texture coordinates + // FT #F by 3 list of triangle texture coordinates + // Optional: + // 'Tol' followed by Ramer-Douglas-Peucker tolerance as a fraction of the + // curves bounding box diagonal (see dpsimplify) + // Outputs: + // UE #UE by 2 list of indices into VT of coarse output polygon edges + // UT #VT by 3 list of new texture coordinates + // OT #OT by 2 list of indices into VT of boundary edges + // + // See also: simplify_curve, dpsimplify + template < + typename DerivedV, + typename DerivedF, + typename DerivedVT, + typename DerivedFT, + typename Scalar, + typename DerivedUE, + typename DerivedUT, + typename DerivedOT> + IGL_INLINE void straighten_seams( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & VT, + const Eigen::MatrixBase & FT, + const Scalar tol, + Eigen::PlainObjectBase & UE, + Eigen::PlainObjectBase & UT, + Eigen::PlainObjectBase & OT); +} + +#ifndef IGL_STATIC_LIBRARY +# include "straighten_seams.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/string_utils.cpp b/vendor/libigl/include/igl/string_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d3edb1da9d77254eb24e8728588641d859ae48b --- /dev/null +++ b/vendor/libigl/include/igl/string_utils.cpp @@ -0,0 +1,22 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Jérémie Dumas +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "string_utils.h" + +#include + +namespace igl { + +IGL_INLINE bool starts_with(const std::string &str, const std::string &prefix) { + return (str.rfind(prefix, 0) == 0); +} + +IGL_INLINE bool starts_with(const char *str, const char* prefix) { + return strncmp(prefix, str, strlen(prefix)) == 0; +} + +} diff --git a/vendor/libigl/include/igl/string_utils.h b/vendor/libigl/include/igl/string_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..7f472508254f1de8f8b6c401a318d4dd0397ba9b --- /dev/null +++ b/vendor/libigl/include/igl/string_utils.h @@ -0,0 +1,27 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Jérémie Dumas +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_STRING_UTILS_H +#define IGL_STRING_UTILS_H + +#include "igl_inline.h" + +#include + +namespace igl { + +IGL_INLINE bool starts_with(const std::string &str, const std::string &prefix); + +IGL_INLINE bool starts_with(const char *str, const char* prefix); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "string_utils.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/sum.h b/vendor/libigl/include/igl/sum.h new file mode 100644 index 0000000000000000000000000000000000000000..6caeac3447050efa1f7e44762e72d8d58469abdc --- /dev/null +++ b/vendor/libigl/include/igl/sum.h @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SUM_H +#define IGL_SUM_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Note: If your looking for dense matrix matlab like sum for eigen matrics + // just use: + // M.colwise().sum() or M.rowwise().sum() + // + + // Sum the columns or rows of a sparse matrix + // Templates: + // T should be a eigen sparse matrix primitive type like int or double + // Inputs: + // X m by n sparse matrix + // dim dimension along which to sum (1 or 2) + // Output: + // S n-long sparse vector (if dim == 1) + // or + // S m-long sparse vector (if dim == 2) + template + IGL_INLINE void sum( + const Eigen::SparseMatrix& X, + const int dim, + Eigen::SparseVector& S); + // Sum is "conducted" in the type of DerivedB::Scalar + template + IGL_INLINE void sum( + const Eigen::SparseMatrix & A, + const int dim, + Eigen::PlainObjectBase& B); +} + +#ifndef IGL_STATIC_LIBRARY +# include "sum.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/svd3x3.h b/vendor/libigl/include/igl/svd3x3.h new file mode 100644 index 0000000000000000000000000000000000000000..900d459f47fa2f7e05eefdbff285f7c31764be45 --- /dev/null +++ b/vendor/libigl/include/igl/svd3x3.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SVD3X3_H +#define IGL_SVD3X3_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Super fast 3x3 SVD according to http://pages.cs.wisc.edu/~sifakis/project_pages/svd.html + // The resulting decomposition is A = U * diag(S[0], S[1], S[2]) * V' + // BEWARE: this SVD algorithm guarantees that det(U) = det(V) = 1, but this + // comes at the cost that 'sigma3' can be negative + // for computing polar decomposition it's great because all we need to do is U*V' + // and the result will automatically have positive determinant + // + // Inputs: + // A 3x3 matrix + // Outputs: + // U 3x3 left singular vectors + // S 3x1 singular values + // V 3x3 right singular vectors + // + // Known bugs: this will not work correctly for double precision. + template + IGL_INLINE void svd3x3( + const Eigen::Matrix& A, + Eigen::Matrix &U, + Eigen::Matrix &S, + Eigen::Matrix&V); +} +#ifndef IGL_STATIC_LIBRARY +# include "svd3x3.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/svd3x3_avx.cpp b/vendor/libigl/include/igl/svd3x3_avx.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db56ee30ab6b468f3c3565364f0ed2f905372d2e --- /dev/null +++ b/vendor/libigl/include/igl/svd3x3_avx.cpp @@ -0,0 +1,108 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifdef __AVX__ +#include "svd3x3_avx.h" + +#include +#include + +#undef USE_SCALAR_IMPLEMENTATION +#undef USE_SSE_IMPLEMENTATION +#define USE_AVX_IMPLEMENTATION +#define COMPUTE_U_AS_MATRIX +#define COMPUTE_V_AS_MATRIX +#include "Singular_Value_Decomposition_Preamble.hpp" + +#pragma runtime_checks( "u", off ) // disable runtime asserts on xor eax,eax type of stuff (doesn't always work, disable explicitly in compiler settings) +template +IGL_INLINE void igl::svd3x3_avx( + const Eigen::Matrix& A, + Eigen::Matrix &U, + Eigen::Matrix &S, + Eigen::Matrix&V) +{ + // this code assumes USE_AVX_IMPLEMENTATION is defined + float Ashuffle[9][8], Ushuffle[9][8], Vshuffle[9][8], Sshuffle[3][8]; + for (int i=0; i<3; i++) + { + for (int j=0; j<3; j++) + { + for (int k=0; k<8; k++) + { + Ashuffle[i + j*3][k] = A(i + 3*k, j); + } + } + } + +#include "Singular_Value_Decomposition_Kernel_Declarations.hpp" + + ENABLE_AVX_IMPLEMENTATION(Va11=_mm256_loadu_ps(Ashuffle[0]);) + ENABLE_AVX_IMPLEMENTATION(Va21=_mm256_loadu_ps(Ashuffle[1]);) + ENABLE_AVX_IMPLEMENTATION(Va31=_mm256_loadu_ps(Ashuffle[2]);) + ENABLE_AVX_IMPLEMENTATION(Va12=_mm256_loadu_ps(Ashuffle[3]);) + ENABLE_AVX_IMPLEMENTATION(Va22=_mm256_loadu_ps(Ashuffle[4]);) + ENABLE_AVX_IMPLEMENTATION(Va32=_mm256_loadu_ps(Ashuffle[5]);) + ENABLE_AVX_IMPLEMENTATION(Va13=_mm256_loadu_ps(Ashuffle[6]);) + ENABLE_AVX_IMPLEMENTATION(Va23=_mm256_loadu_ps(Ashuffle[7]);) + ENABLE_AVX_IMPLEMENTATION(Va33=_mm256_loadu_ps(Ashuffle[8]);) + +#include "Singular_Value_Decomposition_Main_Kernel_Body.hpp" + + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[0],Vu11);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[1],Vu21);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[2],Vu31);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[3],Vu12);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[4],Vu22);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[5],Vu32);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[6],Vu13);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[7],Vu23);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Ushuffle[8],Vu33);) + + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[0],Vv11);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[1],Vv21);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[2],Vv31);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[3],Vv12);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[4],Vv22);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[5],Vv32);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[6],Vv13);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[7],Vv23);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Vshuffle[8],Vv33);) + + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Sshuffle[0],Va11);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Sshuffle[1],Va22);) + ENABLE_AVX_IMPLEMENTATION(_mm256_storeu_ps(Sshuffle[2],Va33);) + + for (int i=0; i<3; i++) + { + for (int j=0; j<3; j++) + { + for (int k=0; k<8; k++) + { + U(i + 3*k, j) = Ushuffle[i + j*3][k]; + V(i + 3*k, j) = Vshuffle[i + j*3][k]; + } + } + } + + for (int i=0; i<3; i++) + { + for (int k=0; k<8; k++) + { + S(i + 3*k, 0) = Sshuffle[i][k]; + } + } +} +#pragma runtime_checks( "u", restore ) + +#ifdef IGL_STATIC_LIBRARY +// forced instantiation +//template void igl::svd3x3_avx(const Eigen::Matrix& A, Eigen::Matrix &U, Eigen::Matrix &S, Eigen::Matrix&V); +// doesn't even make sense with double because the wunder-SVD code is only single precision anyway... +template void igl::svd3x3_avx(Eigen::Matrix const&, Eigen::Matrix&, Eigen::Matrix&, Eigen::Matrix&); +#endif +#endif diff --git a/vendor/libigl/include/igl/svd3x3_avx.h b/vendor/libigl/include/igl/svd3x3_avx.h new file mode 100644 index 0000000000000000000000000000000000000000..b814acc956c43f36c7fb2ffc33b9cd076af33588 --- /dev/null +++ b/vendor/libigl/include/igl/svd3x3_avx.h @@ -0,0 +1,40 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SVD3X3_AVX_H +#define IGL_SVD3X3_AVX_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Super fast 3x3 SVD according to + // http://pages.cs.wisc.edu/~sifakis/project_pages/svd.html This is AVX + // version of svd3x3 (see svd3x3.h) which works on 8 matrices at a time These + // eight matrices are simply stacked in columns, the rest is the same as for + // svd3x3 + // + // Inputs: + // A 12 by 3 stack of 3x3 matrices + // Outputs: + // U 12x3 left singular vectors stacked + // S 12x1 singular values stacked + // V 12x3 right singular vectors stacked + // + // Known bugs: this will not work correctly for double precision. + template + IGL_INLINE void svd3x3_avx( + const Eigen::Matrix& A, + Eigen::Matrix &U, + Eigen::Matrix &S, + Eigen::Matrix&V); +} +#ifndef IGL_STATIC_LIBRARY +# include "svd3x3_avx.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/svd3x3_sse.cpp b/vendor/libigl/include/igl/svd3x3_sse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ef4e0fe8f8276a6de17194911fe8367bf19e131 --- /dev/null +++ b/vendor/libigl/include/igl/svd3x3_sse.cpp @@ -0,0 +1,108 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifdef __SSE__ +#include "svd3x3_sse.h" + +#include +#include + +#undef USE_SCALAR_IMPLEMENTATION +#define USE_SSE_IMPLEMENTATION +#undef USE_AVX_IMPLEMENTATION +#define COMPUTE_U_AS_MATRIX +#define COMPUTE_V_AS_MATRIX +#include "Singular_Value_Decomposition_Preamble.hpp" + +// disable runtime asserts on xor eax,eax type of stuff (doesn't always work, +// disable explicitly in compiler settings) +#pragma runtime_checks( "u", off ) +template +IGL_INLINE void igl::svd3x3_sse( + const Eigen::Matrix& A, + Eigen::Matrix &U, + Eigen::Matrix &S, + Eigen::Matrix&V) +{ + // this code assumes USE_SSE_IMPLEMENTATION is defined + float Ashuffle[9][4], Ushuffle[9][4], Vshuffle[9][4], Sshuffle[3][4]; + for (int i=0; i<3; i++) + { + for (int j=0; j<3; j++) + { + for (int k=0; k<4; k++) + { + Ashuffle[i + j*3][k] = A(i + 3*k, j); + } + } + } + +#include "Singular_Value_Decomposition_Kernel_Declarations.hpp" + + ENABLE_SSE_IMPLEMENTATION(Va11=_mm_loadu_ps(Ashuffle[0]);) + ENABLE_SSE_IMPLEMENTATION(Va21=_mm_loadu_ps(Ashuffle[1]);) + ENABLE_SSE_IMPLEMENTATION(Va31=_mm_loadu_ps(Ashuffle[2]);) + ENABLE_SSE_IMPLEMENTATION(Va12=_mm_loadu_ps(Ashuffle[3]);) + ENABLE_SSE_IMPLEMENTATION(Va22=_mm_loadu_ps(Ashuffle[4]);) + ENABLE_SSE_IMPLEMENTATION(Va32=_mm_loadu_ps(Ashuffle[5]);) + ENABLE_SSE_IMPLEMENTATION(Va13=_mm_loadu_ps(Ashuffle[6]);) + ENABLE_SSE_IMPLEMENTATION(Va23=_mm_loadu_ps(Ashuffle[7]);) + ENABLE_SSE_IMPLEMENTATION(Va33=_mm_loadu_ps(Ashuffle[8]);) + +#include "Singular_Value_Decomposition_Main_Kernel_Body.hpp" + + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[0],Vu11);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[1],Vu21);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[2],Vu31);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[3],Vu12);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[4],Vu22);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[5],Vu32);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[6],Vu13);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[7],Vu23);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Ushuffle[8],Vu33);) + + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[0],Vv11);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[1],Vv21);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[2],Vv31);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[3],Vv12);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[4],Vv22);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[5],Vv32);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[6],Vv13);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[7],Vv23);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Vshuffle[8],Vv33);) + + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Sshuffle[0],Va11);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Sshuffle[1],Va22);) + ENABLE_SSE_IMPLEMENTATION(_mm_storeu_ps(Sshuffle[2],Va33);) + + for (int i=0; i<3; i++) + { + for (int j=0; j<3; j++) + { + for (int k=0; k<4; k++) + { + U(i + 3*k, j) = Ushuffle[i + j*3][k]; + V(i + 3*k, j) = Vshuffle[i + j*3][k]; + } + } + } + + for (int i=0; i<3; i++) + { + for (int k=0; k<4; k++) + { + S(i + 3*k, 0) = Sshuffle[i][k]; + } + } +} +#pragma runtime_checks( "u", restore ) + +// forced instantiation +template void igl::svd3x3_sse(const Eigen::Matrix& A, Eigen::Matrix &U, Eigen::Matrix &S, Eigen::Matrix&V); +//// doesn't even make sense with double because the wunder-SVD code is only single precision anyway... +//template void wunderSVD3x3_SSE(Eigen::Matrix const&, Eigen::Matrix&, Eigen::Matrix&, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/svd3x3_sse.h b/vendor/libigl/include/igl/svd3x3_sse.h new file mode 100644 index 0000000000000000000000000000000000000000..1fcff988ae27d9b650d551eb2f1a95afe4f9327c --- /dev/null +++ b/vendor/libigl/include/igl/svd3x3_sse.h @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_SVD3X3_SSE_H +#define IGL_SVD3X3_SSE_H +#include "igl_inline.h" +#include + +namespace igl +{ + // Super fast 3x3 SVD according to http://pages.cs.wisc.edu/~sifakis/project_pages/svd.html + // This is SSE version of svd3x3 (see svd3x3.h) which works on 4 matrices at a time + // These four matrices are simply stacked in columns, the rest is the same as for svd3x3 + // + // Inputs: + // A 12 by 3 stack of 3x3 matrices + // Outputs: + // U 12x3 left singular vectors stacked + // S 12x1 singular values stacked + // V 12x3 right singular vectors stacked + // + // Known bugs: this will not work correctly for double precision. + template + IGL_INLINE void svd3x3_sse( + const Eigen::Matrix& A, + Eigen::Matrix &U, + Eigen::Matrix &S, + Eigen::Matrix&V); +} +#ifndef IGL_STATIC_LIBRARY +# include "svd3x3_sse.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/swept_volume.cpp b/vendor/libigl/include/igl/swept_volume.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c5ebe73c1463b8760e7ce1b0ad4481786e159c7 --- /dev/null +++ b/vendor/libigl/include/igl/swept_volume.cpp @@ -0,0 +1,48 @@ +#include "swept_volume.h" +#include "swept_volume_bounding_box.h" +#include "swept_volume_signed_distance.h" +#include "voxel_grid.h" +#include "marching_cubes.h" +#include + +IGL_INLINE void igl::swept_volume( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const std::function & transform, + const size_t steps, + const size_t grid_res, + const size_t isolevel_grid, + Eigen::MatrixXd & SV, + Eigen::MatrixXi & SF) +{ + using namespace std; + using namespace Eigen; + using namespace igl; + + const auto & Vtransform = + [&V,&transform](const size_t vi,const double t)->RowVector3d + { + Vector3d Vvi = V.row(vi).transpose(); + return (transform(t)*Vvi).transpose(); + }; + AlignedBox3d Mbox; + swept_volume_bounding_box(V.rows(),Vtransform,steps,Mbox); + + // Amount of padding: pad*h should be >= isolevel + const int pad = isolevel_grid+1; + // number of vertices on the largest side + const int s = grid_res+2*pad; + const double h = Mbox.diagonal().maxCoeff()/(double)(s-2.*pad-1.); + const double isolevel = isolevel_grid*h; + + // create grid + RowVector3i res; + MatrixXd GV; + voxel_grid(Mbox,s,pad,GV,res); + + // compute values + VectorXd S; + swept_volume_signed_distance(V,F,transform,steps,GV,res,h,isolevel,S); + S.array()-=isolevel; + marching_cubes(S,GV,res(0),res(1),res(2),0,SV,SF); +} diff --git a/vendor/libigl/include/igl/swept_volume.h b/vendor/libigl/include/igl/swept_volume.h new file mode 100644 index 0000000000000000000000000000000000000000..42d9024a5f0b8a4a654cb025a8e50116c69b004c --- /dev/null +++ b/vendor/libigl/include/igl/swept_volume.h @@ -0,0 +1,39 @@ +#ifndef IGL_SWEPT_VOLUME_H +#define IGL_SWEPT_VOLUME_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Compute the surface of the swept volume of a solid object with surface + // (V,F) mesh under going rigid motion. + // + // Inputs: + // V #V by 3 list of mesh positions in reference pose + // F #F by 3 list of mesh indices into V + // transform function handle so that transform(t) returns the rigid + // transformation at time t∈[0,1] + // steps number of time steps: steps=3 --> t∈{0,0.5,1} + // grid_res number of grid cells on the longest side containing the + // motion (isolevel+1 cells will also be added on each side as padding) + // isolevel distance level to be contoured as swept volume + // Outputs: + // SV #SV by 3 list of mesh positions of the swept surface + // SF #SF by 3 list of mesh faces into SV + IGL_INLINE void swept_volume( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const std::function & transform, + const size_t steps, + const size_t grid_res, + const size_t isolevel, + Eigen::MatrixXd & SV, + Eigen::MatrixXi & SF); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "swept_volume.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/swept_volume_bounding_box.cpp b/vendor/libigl/include/igl/swept_volume_bounding_box.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7fc12e2f1001918bc37ccd550a15f34d586b6b8c --- /dev/null +++ b/vendor/libigl/include/igl/swept_volume_bounding_box.cpp @@ -0,0 +1,28 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "swept_volume_bounding_box.h" +#include "LinSpaced.h" + +IGL_INLINE void igl::swept_volume_bounding_box( + const size_t & n, + const std::function & V, + const size_t & steps, + Eigen::AlignedBox3d & box) +{ + using namespace Eigen; + box.setEmpty(); + const VectorXd t = igl::LinSpaced(steps,0,1); + // Find extent over all time steps + for(int ti = 0;ti +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "swept_volume_signed_distance.h" +#include "LinSpaced.h" +#include "flood_fill.h" +#include "signed_distance.h" +#include "AABB.h" +#include "pseudonormal_test.h" +#include "per_face_normals.h" +#include "per_vertex_normals.h" +#include "per_edge_normals.h" +#include +#include +#include + +IGL_INLINE void igl::swept_volume_signed_distance( + const Eigen::MatrixXd & V, + const Eigen::MatrixXi & F, + const std::function & transform, + const size_t & steps, + const Eigen::MatrixXd & GV, + const Eigen::RowVector3i & res, + const double h, + const double isolevel, + const Eigen::VectorXd & S0, + Eigen::VectorXd & S) +{ + using namespace std; + using namespace igl; + using namespace Eigen; + S = S0; + const VectorXd t = igl::LinSpaced(steps,0,1); + const bool finite_iso = isfinite(isolevel); + const double extension = (finite_iso ? isolevel : 0) + sqrt(3.0)*h; + Eigen::AlignedBox3d box( + V.colwise().minCoeff().array()-extension, + V.colwise().maxCoeff().array()+extension); + // Precomputation + Eigen::MatrixXd FN,VN,EN; + Eigen::MatrixXi E; + Eigen::VectorXi EMAP; + per_face_normals(V,F,FN); + per_vertex_normals(V,F,PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE,FN,VN); + per_edge_normals( + V,F,PER_EDGE_NORMALS_WEIGHTING_TYPE_UNIFORM,FN,EN,E,EMAP); + AABB tree; + tree.init(V,F); + for(int ti = 0;ti::infinity(); + sqrd = tree.squared_distance(V,F,gv,min_sqrd,i,c); + if(sqrd & transform, + const size_t & steps, + const Eigen::MatrixXd & GV, + const Eigen::RowVector3i & res, + const double h, + const double isolevel, + Eigen::VectorXd & S) +{ + using namespace std; + using namespace igl; + using namespace Eigen; + S = VectorXd::Constant(GV.rows(),1,numeric_limits::quiet_NaN()); + return + swept_volume_signed_distance(V,F,transform,steps,GV,res,h,isolevel,S,S); +} diff --git a/vendor/libigl/include/igl/tan_half_angle.cpp b/vendor/libigl/include/igl/tan_half_angle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9455241a48dfacb1bb60ed295a6834c481341eeb --- /dev/null +++ b/vendor/libigl/include/igl/tan_half_angle.cpp @@ -0,0 +1,37 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "tan_half_angle.h" +#include +template < typename Scalar> +IGL_INLINE Scalar igl::tan_half_angle( + const Scalar & a, + const Scalar & b, + const Scalar & c) +{ + // . + // /| + // c/ | + // / | + // / | + // .α | a + // \ | + // \ | + // b\ | + // \| + // + // tan(α/2) + // Fisher 2007 + return sqrt(((a-b+c)*(a+b-c))/((a+b+c)*(-a+b+c))); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template double igl::tan_half_angle(double const&, double const&, double const&); +#endif diff --git a/vendor/libigl/include/igl/tan_half_angle.h b/vendor/libigl/include/igl/tan_half_angle.h new file mode 100644 index 0000000000000000000000000000000000000000..053bd59fd3f1dd3f108293556e9c18db54d7b026 --- /dev/null +++ b/vendor/libigl/include/igl/tan_half_angle.h @@ -0,0 +1,35 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TAN_HALF_ANGLE_H +#define IGL_TAN_HALF_ANGLE_H +#include "igl_inline.h" +namespace igl +{ + // TAN_HALF_ANGLE Compute the tangent of half of the angle opposite the side + // with length a, in a triangle with side lengths (a,b,c). + // + // Inputs: + // a scalar edge length of first side of triangle + // b scalar edge length of second side of triangle + // c scalar edge length of third side of triangle + // Returns tangent of half of the angle opposite side with length a + // + // See also: is_intrinsic_delaunay + template < typename Scalar> + IGL_INLINE Scalar tan_half_angle( + const Scalar & a, + const Scalar & b, + const Scalar & c); +} + +#ifndef IGL_STATIC_LIBRARY +# include "tan_half_angle.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/tet_tet_adjacency.cpp b/vendor/libigl/include/igl/tet_tet_adjacency.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c8b42d9ea2ccf9190ab6c89f00a41b42033cf53 --- /dev/null +++ b/vendor/libigl/include/igl/tet_tet_adjacency.cpp @@ -0,0 +1,73 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + + +#include "tet_tet_adjacency.h" + +#include "parallel_for.h" + +#include +#include + +template +IGL_INLINE void +igl::tet_tet_adjacency( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& TT, + Eigen::PlainObjectBase& TTi) +{ + assert(T.cols()==4 && "Tets have four vertices."); + + //Preprocess + using Array = std::array; + std::vector TTT(4*T.rows()); + const auto loop_f = [&](const int t) { + TTT[4*t] = {T(t,0),T(t,1),T(t,2),t,0}; + TTT[4*t+1] = {T(t,0),T(t,1),T(t,3),t,1}; + TTT[4*t+2] = {T(t,1),T(t,2),T(t,3),t,2}; + TTT[4*t+3] = {T(t,2),T(t,0),T(t,3),t,3}; + for(int i=0; i<4; ++i) + std::sort(TTT[4*t+i].begin(), TTT[4*t+i].begin()+3); + }; + + //for(int t=0; t +IGL_INLINE void +igl::tet_tet_adjacency( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& TT) +{ + DerivedTT TTi; + tet_tet_adjacency(T, TT, TTi); +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::tet_tet_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif + diff --git a/vendor/libigl/include/igl/tet_tet_adjacency.h b/vendor/libigl/include/igl/tet_tet_adjacency.h new file mode 100644 index 0000000000000000000000000000000000000000..79b935c758f0ef029214c183c4bc978fdd6e4e10 --- /dev/null +++ b/vendor/libigl/include/igl/tet_tet_adjacency.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Oded Stein +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef IGL_TET_TET_ADJACENCY_H +#define IGL_TET_TET_ADJACENCY_H + +#include + +#include + +namespace igl +{ + + // Constructs the tet_tet adjacency matrix for a given tet mesh with tets T + // + // Inputs: + // T #T by 4 list of tets + // Outputs: + // TT #T by #4 adjacency matrix, the element i,j is the id of the tet + // adjacent to the j face of tet i + // TTi #T by #4 adjacency matrix, the element i,j is the id of face of + // the tet TT(i,j) that is adjacent to tet i + // + // NOTE: the first face of a tet is [0,1,2], the second [0,1,3], the third + // [1,2,3], and the fourth [2,0,3]. + + template + IGL_INLINE void tet_tet_adjacency( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& TT, + Eigen::PlainObjectBase& TTi); + + + template + IGL_INLINE void tet_tet_adjacency( + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& TT); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "tet_tet_adjacency.cpp" +#endif + + +#endif diff --git a/vendor/libigl/include/igl/tetrahedralized_grid.h b/vendor/libigl/include/igl/tetrahedralized_grid.h new file mode 100644 index 0000000000000000000000000000000000000000..47cc15f5aa1dd44397bc539ff4948d43ca55ec18 --- /dev/null +++ b/vendor/libigl/include/igl/tetrahedralized_grid.h @@ -0,0 +1,67 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2020 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TETRAHEDRALIZED_GRID_H +#define IGL_TETRAHEDRALIZED_GRID_H +#include "igl_inline.h" +#include +namespace igl +{ + enum TetrahedralizedGripType + { + TETRAHEDRALIZED_GRID_TYPE_5 = 0, + TETRAHEDRALIZED_GRID_TYPE_6_ROTATIONAL = 1, + NUM_TETRAHEDRALIZED_GRID_TYPE = 2 + }; + // Construct vertices of a regular grid, suitable for input to + // `igl::marching_tets` + // + // Inputs: + // nx number of grid vertices in x direction + // ny number of grid vertices in y direction + // nz number of grid vertices in z direction + // type type of tetrahedralization of cube to use + // Outputs: + // GV nx*ny*nz by 3 list of grid vertex positions + // GT (nx-1)*(ny-1)*(nz-1)*k by 4 list of tetrahedron indices into rows of + // V, where k is the number of tets per cube (dependent on type) + // + // See also: triangulated_grid, quad_grid + template < + typename DerivedGV, + typename DerivedGT> + IGL_INLINE void tetrahedralized_grid( + const int nx, + const int ny, + const int nz, + const TetrahedralizedGripType type, + Eigen::PlainObjectBase & GV, + Eigen::PlainObjectBase & GT); + // + // Inputs: + // GV nx*ny*nz by 3 list of grid vertex positions + // side 3-long list {nx,ny,nz} see above + // type type of tetrahedralization of cube to use + // Outputs: + // GT (nx-1)*(ny-1)*(nz-1)*k by 4 list of tetrahedron indices into rows of + // V, where k is the number of tets per cube (dependent on type) + // + template < + typename DerivedGV, + typename Derivedside, + typename DerivedGT> + IGL_INLINE void tetrahedralized_grid( + const Eigen::MatrixBase & GV, + const Eigen::MatrixBase & side, + const TetrahedralizedGripType type, + Eigen::PlainObjectBase & GT); +} +#ifndef IGL_STATIC_LIBRARY +# include "tetrahedralized_grid.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/tinyply.cpp b/vendor/libigl/include/igl/tinyply.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b99d1c7c853803e238fb995b3ef99d729f19108d --- /dev/null +++ b/vendor/libigl/include/igl/tinyply.cpp @@ -0,0 +1,797 @@ +#include "tinyply.h" +// Moved from origin tinyply.h +//////////////////////////////// +// tinyply implementation // +//////////////////////////////// + +#include +#include +#include +#include +#include +#include + +namespace igl +{ +namespace tinyply +{ +template T2 endian_swap(const T & v) noexcept {assert(false);} //{ return v; } + +template<> uint16_t IGL_INLINE endian_swap(const uint16_t & v) noexcept { return (v << 8) | (v >> 8); } +template<> uint32_t IGL_INLINE endian_swap(const uint32_t & v) noexcept { return (v << 24) | ((v << 8) & 0x00ff0000) | ((v >> 8) & 0x0000ff00) | (v >> 24); } +template<> uint64_t IGL_INLINE endian_swap(const uint64_t & v) noexcept +{ + return (((v & 0x00000000000000ffLL) << 56) | + ((v & 0x000000000000ff00LL) << 40) | + ((v & 0x0000000000ff0000LL) << 24) | + ((v & 0x00000000ff000000LL) << 8) | + ((v & 0x000000ff00000000LL) >> 8) | + ((v & 0x0000ff0000000000LL) >> 24) | + ((v & 0x00ff000000000000LL) >> 40) | + ((v & 0xff00000000000000LL) >> 56)); +} +template<> int16_t IGL_INLINE endian_swap(const int16_t & v) noexcept { uint16_t r = endian_swap(*(uint16_t*)&v); return *(int16_t*)&r; } +template<> int32_t IGL_INLINE endian_swap(const int32_t & v) noexcept { uint32_t r = endian_swap(*(uint32_t*)&v); return *(int32_t*)&r; } +template<> int64_t IGL_INLINE endian_swap(const int64_t & v) noexcept { uint64_t r = endian_swap(*(uint64_t*)&v); return *(int64_t*)&r; } +template<> float IGL_INLINE endian_swap(const uint32_t & v) noexcept { union { float f; uint32_t i; }; i = endian_swap(v); return f; } +template<> double IGL_INLINE endian_swap(const uint64_t & v) noexcept { union { double d; uint64_t i; }; i = endian_swap(v); return d; } + + +IGL_INLINE uint32_t hash_fnv1a(const std::string & str) noexcept +{ + static const uint32_t fnv1aBase32 = 0x811C9DC5u; + static const uint32_t fnv1aPrime32 = 0x01000193u; + uint32_t result = fnv1aBase32; + for (auto & c : str) { result ^= static_cast(c); result *= fnv1aPrime32; } + return result; +} + +IGL_INLINE Type property_type_from_string(const std::string & t) noexcept +{ + if (t == "int8" || t == "char") return Type::INT8; + else if (t == "uint8" || t == "uchar") return Type::UINT8; + else if (t == "int16" || t == "short") return Type::INT16; + else if (t == "uint16" || t == "ushort") return Type::UINT16; + else if (t == "int32" || t == "int") return Type::INT32; + else if (t == "uint32" || t == "uint") return Type::UINT32; + else if (t == "float32" || t == "float") return Type::FLOAT32; + else if (t == "float64" || t == "double") return Type::FLOAT64; + return Type::INVALID; +} + +struct PlyFile::PlyFileImpl +{ + struct PlyDataCursor + { + size_t byteOffset{ 0 }; + size_t totalSizeBytes{ 0 }; + }; + + struct ParsingHelper + { + std::shared_ptr data; + std::shared_ptr cursor; + uint32_t list_size_hint; + }; + + struct PropertyLookup + { + ParsingHelper * helper{ nullptr }; + bool skip{ false }; + size_t prop_stride{ 0 }; // precomputed + size_t list_stride{ 0 }; // precomputed + }; + + std::unordered_map userData; + + bool isBinary = false; + bool isBigEndian = false; + std::vector elements; + std::vector comments; + std::vector objInfo; + uint8_t scratch[64]; // large enough for max list size + + void read(std::istream & is); + void write(std::ostream & os, bool isBinary); + + std::shared_ptr request_properties_from_element(const std::string & elementKey, + const std::vector propertyKeys, + const uint32_t list_size_hint); + + void add_properties_to_element(const std::string & elementKey, + const std::vector propertyKeys, + const Type type, const size_t count, uint8_t * data, const Type listType, const size_t listCount); + + size_t read_property_binary(const size_t & stride, void * dest, size_t & destOffset, std::istream & is) noexcept; + size_t read_property_ascii(const Type & t, const size_t & stride, void * dest, size_t & destOffset, std::istream & is); + + std::vector> make_property_lookup_table(); + + bool parse_header(std::istream & is); + void parse_data(std::istream & is, bool firstPass); + void read_header_format(std::istream & is); + void read_header_element(std::istream & is); + void read_header_property(std::istream & is); + void read_header_text(std::string line, std::vector & place, int erase = 0); + + void write_header(std::ostream & os) noexcept; + void write_ascii_internal(std::ostream & os) noexcept; + void write_binary_internal(std::ostream & os) noexcept; + void write_property_ascii(Type t, std::ostream & os, uint8_t * src, size_t & srcOffset); + void write_property_binary(std::ostream & os, uint8_t * src, size_t & srcOffset, const size_t & stride) noexcept; +}; + +IGL_INLINE PlyProperty::PlyProperty(std::istream & is) : isList(false) +{ + std::string type; + is >> type; + if (type == "list") + { + std::string countType; + is >> countType >> type; + listType = property_type_from_string(countType); + isList = true; + } + propertyType = property_type_from_string(type); + is >> name; +} + +IGL_INLINE PlyElement::PlyElement(std::istream & is) +{ + is >> name >> size; +} + +template IGL_INLINE T ply_read_ascii(std::istream & is) +{ + T data; + is >> data; + return data; +} + +template +IGL_INLINE void endian_swap_buffer(uint8_t * data_ptr, const size_t num_bytes, const size_t stride) +{ + for (size_t count = 0; count < num_bytes; count += stride) + { + *(reinterpret_cast(data_ptr)) = endian_swap(*(reinterpret_cast(data_ptr))); + data_ptr += stride; + } +} + +template void ply_cast_ascii(void * dest, std::istream & is) +{ + *(static_cast(dest)) = ply_read_ascii(is); +} + +IGL_INLINE int64_t find_element(const std::string & key, const std::vector & list) +{ + for (size_t i = 0; i < list.size(); i++) if (list[i].name == key) return i; + return -1; +} + +IGL_INLINE int64_t find_property(const std::string & key, const std::vector & list) +{ + for (size_t i = 0; i < list.size(); ++i) if (list[i].name == key) return i; + return -1; +} + +// The `userData` table is an easy data structure for capturing what data the +// user would like out of the ply file, but an inner-loop hash lookup is non-ideal. +// The property lookup table flattens the table down into a 2D array optimized +// for parsing. The first index is the element, and the second index is the property. +IGL_INLINE std::vector> PlyFile::PlyFileImpl::make_property_lookup_table() +{ + std::vector> element_property_lookup; + + for (auto & element : elements) + { + std::vector lookups; + + for (auto & property : element.properties) + { + PropertyLookup f; + + auto cursorIt = userData.find(hash_fnv1a(element.name + property.name)); + if (cursorIt != userData.end()) f.helper = &cursorIt->second; + else f.skip = true; + + f.prop_stride = PropertyTable[property.propertyType].stride; + if (property.isList) f.list_stride = PropertyTable[property.listType].stride; + + lookups.push_back(f); + } + + element_property_lookup.push_back(lookups); + } + + return element_property_lookup; +} + +IGL_INLINE bool PlyFile::PlyFileImpl::parse_header(std::istream & is) +{ + std::string line; + bool success = true; + while (std::getline(is, line)) + { + std::istringstream ls(line); + std::string token; + ls >> token; + if (token == "ply" || token == "PLY" || token == "") continue; + else if (token == "comment") read_header_text(line, comments, 8); + else if (token == "format") read_header_format(ls); + else if (token == "element") read_header_element(ls); + else if (token == "property") read_header_property(ls); + else if (token == "obj_info") read_header_text(line, objInfo, 9); + else if (token == "end_header") break; + else success = false; // unexpected header field + } + return success; +} + +IGL_INLINE void PlyFile::PlyFileImpl::read_header_text(std::string line, std::vector& place, int erase) +{ + place.push_back((erase > 0) ? line.erase(0, erase) : line); +} + +IGL_INLINE void PlyFile::PlyFileImpl::read_header_format(std::istream & is) +{ + std::string s; + (is >> s); + if (s == "binary_little_endian") isBinary = true; + else if (s == "binary_big_endian") isBinary = isBigEndian = true; +} + +IGL_INLINE void PlyFile::PlyFileImpl::read_header_element(std::istream & is) +{ + elements.emplace_back(is); +} + +IGL_INLINE void PlyFile::PlyFileImpl::read_header_property(std::istream & is) +{ + if (!elements.size()) throw std::runtime_error("no elements defined; file is malformed"); + elements.back().properties.emplace_back(is); +} + +IGL_INLINE size_t PlyFile::PlyFileImpl::read_property_binary(const size_t & stride, void * dest, size_t & destOffset, std::istream & is) noexcept +{ + destOffset += stride; + is.read((char*)dest, stride); + return stride; +} + +IGL_INLINE size_t PlyFile::PlyFileImpl::read_property_ascii(const Type & t, const size_t & stride, void * dest, size_t & destOffset, std::istream & is) +{ + destOffset += stride; + switch (t) + { + case Type::INT8: *((int8_t *)dest) = static_cast(ply_read_ascii(is)); break; + case Type::UINT8: *((uint8_t *)dest) = static_cast(ply_read_ascii(is)); break; + case Type::INT16: ply_cast_ascii(dest, is); break; + case Type::UINT16: ply_cast_ascii(dest, is); break; + case Type::INT32: ply_cast_ascii(dest, is); break; + case Type::UINT32: ply_cast_ascii(dest, is); break; + case Type::FLOAT32: ply_cast_ascii(dest, is); break; + case Type::FLOAT64: ply_cast_ascii(dest, is); break; + case Type::INVALID: throw std::invalid_argument("invalid ply property"); + } + return stride; +} + +IGL_INLINE void PlyFile::PlyFileImpl::write_property_ascii(Type t, std::ostream & os, uint8_t * src, size_t & srcOffset) +{ + switch (t) + { + case Type::INT8: os << static_cast(*reinterpret_cast(src)); break; + case Type::UINT8: os << static_cast(*reinterpret_cast(src)); break; + case Type::INT16: os << *reinterpret_cast(src); break; + case Type::UINT16: os << *reinterpret_cast(src); break; + case Type::INT32: os << *reinterpret_cast(src); break; + case Type::UINT32: os << *reinterpret_cast(src); break; + case Type::FLOAT32: os << *reinterpret_cast(src); break; + case Type::FLOAT64: os << *reinterpret_cast(src); break; + case Type::INVALID: throw std::invalid_argument("invalid ply property"); + } + os << " "; + srcOffset += PropertyTable[t].stride; +} + +IGL_INLINE void PlyFile::PlyFileImpl::write_property_binary(std::ostream & os, uint8_t * src, size_t & srcOffset, const size_t & stride) noexcept +{ + os.write((char *)src, stride); + srcOffset += stride; +} + +IGL_INLINE void PlyFile::PlyFileImpl::read(std::istream & is) +{ + std::vector> buffers; + for (auto & entry : userData) buffers.push_back(entry.second.data); + + // Discover if we can allocate up front without parsing the file twice + uint32_t list_hints = 0; + for (auto & b : buffers) for (auto & entry : userData) {list_hints += entry.second.list_size_hint;(void)b;} + + // No list hints? Then we need to calculate how much memory to allocate + if (list_hints == 0) + { + parse_data(is, true); + } + + // Count the number of properties (required for allocation) + // e.g. if we have properties x y and z requested, we ensure + // that their buffer points to the same PlyData + std::unordered_map unique_data_count; + for (auto & ptr : buffers) unique_data_count[ptr.get()] += 1; + + // Since group-requested properties share the same cursor, + // we need to find unique cursors so we only allocate once + std::sort(buffers.begin(), buffers.end()); + buffers.erase(std::unique(buffers.begin(), buffers.end()), buffers.end()); + + // We sorted by ptrs on PlyData, need to remap back onto its cursor in the userData table + for (auto & b : buffers) + { + for (auto & entry : userData) + { + if (entry.second.data == b && b->buffer.get() == nullptr) + { + // If we didn't receive any list hints, it means we did two passes over the + // file to compute the total length of all (potentially) variable-length lists + if (list_hints == 0) + { + b->buffer = Buffer(entry.second.cursor->totalSizeBytes); + } + else + { + // otherwise, we can allocate up front, skipping the first pass. + const size_t list_size_multiplier = (entry.second.data->isList ? entry.second.list_size_hint : 1); + auto bytes_per_property = entry.second.data->count * PropertyTable[entry.second.data->t].stride * list_size_multiplier; + bytes_per_property *= unique_data_count[b.get()]; + b->buffer = Buffer(bytes_per_property); + } + + } + } + } + + // Populate the data + parse_data(is, false); + + // In-place big-endian to little-endian swapping if required + if (isBigEndian) + { + for (auto & b : buffers) + { + uint8_t * data_ptr = b->buffer.get(); + const size_t stride = PropertyTable[b->t].stride; + const size_t buffer_size_bytes = b->buffer.size_bytes(); + + switch (b->t) + { + case Type::INT16: endian_swap_buffer(data_ptr, buffer_size_bytes, stride); break; + case Type::UINT16: endian_swap_buffer(data_ptr, buffer_size_bytes, stride); break; + case Type::INT32: endian_swap_buffer(data_ptr, buffer_size_bytes, stride); break; + case Type::UINT32: endian_swap_buffer(data_ptr, buffer_size_bytes, stride); break; + case Type::FLOAT32: endian_swap_buffer(data_ptr, buffer_size_bytes, stride); break; + case Type::FLOAT64: endian_swap_buffer(data_ptr, buffer_size_bytes, stride); break; + default: break; + } + } + } +} + +IGL_INLINE void PlyFile::PlyFileImpl::write(std::ostream & os, bool _isBinary) +{ + for (auto & d : userData) { d.second.cursor->byteOffset = 0; } + if (_isBinary) + { + isBinary = true; + isBigEndian = false; + write_binary_internal(os); + } + else + { + isBinary = false; + isBigEndian = false; + write_ascii_internal(os); + } +} + +IGL_INLINE void PlyFile::PlyFileImpl::write_binary_internal(std::ostream & os) noexcept +{ + isBinary = true; + + write_header(os); + + uint8_t listSize[4] = { 0, 0, 0, 0 }; + size_t dummyCount = 0; + + auto element_property_lookup = make_property_lookup_table(); + + size_t element_idx = 0; + for (auto & e : elements) + { + for (size_t i = 0; i < e.size; ++i) + { + size_t property_index = 0; + for (auto & p : e.properties) + { + auto & f = element_property_lookup[element_idx][property_index]; + auto * helper = f.helper; + if (f.skip || helper == nullptr) continue; + + if (p.isList) + { + std::memcpy(listSize, &p.listCount, sizeof(uint32_t)); + write_property_binary(os, listSize, dummyCount, f.list_stride); + write_property_binary(os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset, f.prop_stride * p.listCount); + } + else + { + write_property_binary(os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset, f.prop_stride); + } + property_index++; + } + } + element_idx++; + } +} + +IGL_INLINE void PlyFile::PlyFileImpl::write_ascii_internal(std::ostream & os) noexcept +{ + write_header(os); + + auto element_property_lookup = make_property_lookup_table(); + + size_t element_idx = 0; + for (auto & e : elements) + { + for (size_t i = 0; i < e.size; ++i) + { + size_t property_index = 0; + for (auto & p : e.properties) + { + auto & f = element_property_lookup[element_idx][property_index]; + auto * helper = f.helper; + if (f.skip || helper == nullptr) continue; + + if (p.isList) + { + os << p.listCount << " "; + for (size_t j = 0; j < p.listCount; ++j) + { + write_property_ascii(p.propertyType, os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset); + } + } + else + { + write_property_ascii(p.propertyType, os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset); + } + property_index++; + } + os << "\n"; + } + element_idx++; + } +} + +IGL_INLINE void PlyFile::PlyFileImpl::write_header(std::ostream & os) noexcept +{ + const std::locale & fixLoc = std::locale("C"); + os.imbue(fixLoc); + + os << "ply\n"; + if (isBinary) os << ((isBigEndian) ? "format binary_big_endian 1.0" : "format binary_little_endian 1.0") << "\n"; + else os << "format ascii 1.0\n"; + + for (const auto & comment : comments) os << "comment " << comment << "\n"; + + auto property_lookup = make_property_lookup_table(); + + size_t element_idx = 0; + for (auto & e : elements) + { + os << "element " << e.name << " " << e.size << "\n"; + size_t property_idx = 0; + for (const auto & p : e.properties) + { + PropertyLookup & lookup = property_lookup[element_idx][property_idx]; + + if (!lookup.skip) + { + if (p.isList) + { + os << "property list " << PropertyTable[p.listType].str << " " + << PropertyTable[p.propertyType].str << " " << p.name << "\n"; + } + else + { + os << "property " << PropertyTable[p.propertyType].str << " " << p.name << "\n"; + } + } + property_idx++; + } + element_idx++; + } + os << "end_header\n"; +} + +IGL_INLINE std::shared_ptr PlyFile::PlyFileImpl::request_properties_from_element(const std::string & elementKey, + const std::vector propertyKeys, + const uint32_t list_size_hint) +{ + if (elements.empty()) throw std::runtime_error("header had no elements defined. malformed file?"); + if (elementKey.empty()) throw std::invalid_argument("`elementKey` argument is empty"); + if (propertyKeys.empty()) throw std::invalid_argument("`propertyKeys` argument is empty"); + + std::shared_ptr out_data = std::make_shared(); + + const int64_t elementIndex = find_element(elementKey, elements); + + std::vector keys_not_found; + + // Sanity check if the user requested element is in the pre-parsed header + if (elementIndex >= 0) + { + // We found the element + const PlyElement & element = elements[elementIndex]; + + // Each key in `propertyKey` gets an entry into the userData map (keyed by a hash of + // element name and property name), but groups of properties (requested from the + // public api through this function) all share the same `ParsingHelper`. When it comes + // time to .read(), we check the number of unique PlyData shared pointers + // and allocate a single buffer that will be used by each property key group. + // That way, properties like, {"x", "y", "z"} will all be put into the same buffer. + + ParsingHelper helper; + helper.data = out_data; + helper.data->count = element.size; // how many items are in the element? + helper.data->isList = false; + helper.data->t = Type::INVALID; + helper.cursor = std::make_shared(); + helper.list_size_hint = list_size_hint; + + // Find each of the keys + for (const auto & key : propertyKeys) + { + const int64_t propertyIndex = find_property(key, element.properties); + if (propertyIndex < 0) keys_not_found.push_back(key); + } + + if (keys_not_found.size()) + { + std::stringstream ss; + for (auto & str : keys_not_found) ss << str << ", "; + throw std::invalid_argument("the following property keys were not found in the header: " + ss.str()); + } + + for (const auto & key : propertyKeys) + { + const int64_t propertyIndex = find_property(key, element.properties); + const PlyProperty & property = element.properties[propertyIndex]; + helper.data->t = property.propertyType; + helper.data->isList = property.isList; + auto result = userData.insert(std::pair(hash_fnv1a(element.name + property.name), helper)); + if (result.second == false) + { + throw std::invalid_argument("element-property key has already been requested: " + element.name + " " + property.name); + } + } + + // Sanity check that all properties share the same type + std::vector propertyTypes; + for (const auto & key : propertyKeys) + { + const int64_t propertyIndex = find_property(key, element.properties); + const PlyProperty & property = element.properties[propertyIndex]; + propertyTypes.push_back(property.propertyType); + } + + if (std::adjacent_find(propertyTypes.begin(), propertyTypes.end(), std::not_equal_to()) != propertyTypes.end()) + { + throw std::invalid_argument("all requested properties must share the same type."); + } + } + else throw std::invalid_argument("the element key was not found in the header: " + elementKey); + + return out_data; +} + +IGL_INLINE void PlyFile::PlyFileImpl::add_properties_to_element(const std::string & elementKey, + const std::vector propertyKeys, + const Type type, const size_t count, uint8_t * data, const Type listType, const size_t listCount) +{ + ParsingHelper helper; + helper.data = std::make_shared(); + helper.data->count = count; + helper.data->t = type; + helper.data->buffer = Buffer(data); // we should also set size for safety reasons + helper.cursor = std::make_shared(); + + auto create_property_on_element = [&](PlyElement & e) + { + for (auto key : propertyKeys) + { + PlyProperty newProp = (listType == Type::INVALID) ? PlyProperty(type, key) : PlyProperty(listType, type, key, listCount); + userData.insert(std::pair(hash_fnv1a(elementKey + key), helper)); + e.properties.push_back(newProp); + } + }; + + const int64_t idx = find_element(elementKey, elements); + if (idx >= 0) + { + PlyElement & e = elements[idx]; + create_property_on_element(e); + } + else + { + PlyElement newElement = (listType == Type::INVALID) ? PlyElement(elementKey, count) : PlyElement(elementKey, count); + create_property_on_element(newElement); + elements.push_back(newElement); + } +} + +IGL_INLINE void PlyFile::PlyFileImpl::parse_data(std::istream & is, bool firstPass) +{ + std::function read; + std::function skip; + + const auto start = is.tellg(); + + uint32_t listSize = 0; + size_t dummyCount = 0; + std::string skip_ascii_buffer; + + // Special case mirroring read_property_binary but for list types; this + // has an additional big endian check to flip the data in place immediately + // after reading. We do this as a performance optimization; endian flipping is + // done on regular properties as a post-process after reading (also for optimization) + // but we need the correct little-endian list count as we read the file. + auto read_list_binary = [this](const Type & t, void * dst, size_t & destOffset, const size_t & stride, std::istream & _is) noexcept + { + destOffset += stride; + _is.read((char*)dst, stride); + + if (isBigEndian) + { + switch (t) + { + case Type::INT16: *(int16_t*)dst = endian_swap(*(int16_t*)dst); break; + case Type::UINT16: *(uint16_t*)dst = endian_swap(*(uint16_t*)dst); break; + case Type::INT32: *(int32_t*)dst = endian_swap(*(int32_t*)dst); break; + case Type::UINT32: *(uint32_t*)dst = endian_swap(*(uint32_t*)dst); break; + default: break; + } + } + + return stride; + }; + + if (isBinary) + { + read = [this, &listSize, &dummyCount, &read_list_binary](PropertyLookup & f, const PlyProperty & p, uint8_t * dest, size_t & destOffset, std::istream & _is) noexcept + { + if (!p.isList) + { + return read_property_binary(f.prop_stride, dest + destOffset, destOffset, _is); + } + read_list_binary(p.listType, &listSize, dummyCount, f.list_stride, _is); // the list size + return read_property_binary(f.prop_stride * listSize, dest + destOffset, destOffset, _is); // properties in list + }; + skip = [this, &listSize, &dummyCount, &read_list_binary](PropertyLookup & f, const PlyProperty & p, std::istream & _is) noexcept + { + if (!p.isList) + { + _is.read((char*)scratch, f.prop_stride); + return f.prop_stride; + } + read_list_binary(p.listType, &listSize, dummyCount, f.list_stride, _is); // the list size (does not count for memory alloc) + auto bytes_to_skip = f.prop_stride * listSize; + _is.ignore(bytes_to_skip); + return bytes_to_skip; + }; + } + else + { + read = [this, &listSize, &dummyCount](PropertyLookup & f, const PlyProperty & p, uint8_t * dest, size_t & destOffset, std::istream & _is) noexcept + { + if (!p.isList) + { + read_property_ascii(p.propertyType, f.prop_stride, dest + destOffset, destOffset, _is); + } + else + { + read_property_ascii(p.listType, f.list_stride, &listSize, dummyCount, _is); // the list size + for (size_t i = 0; i < listSize; ++i) + { + read_property_ascii(p.propertyType, f.prop_stride, dest + destOffset, destOffset, _is); + } + } + }; + skip = [this, &listSize, &dummyCount, &skip_ascii_buffer](PropertyLookup & f, const PlyProperty & p, std::istream & _is) noexcept + { + skip_ascii_buffer.clear(); + if (p.isList) + { + read_property_ascii(p.listType, f.list_stride, &listSize, dummyCount, _is); // the list size (does not count for memory alloc) + for (size_t i = 0; i < listSize; ++i) _is >> skip_ascii_buffer; // properties in list + return listSize * f.prop_stride; + } + _is >> skip_ascii_buffer; + return f.prop_stride; + }; + } + + std::vector> element_property_lookup = make_property_lookup_table(); + size_t element_idx = 0; + size_t property_idx = 0; + ParsingHelper * helper {nullptr}; + + // This is the inner import loop + for (auto & element : elements) + { + for (size_t count = 0; count < element.size; ++count) + { + property_idx = 0; + for (auto & property : element.properties) + { + PropertyLookup & lookup = element_property_lookup[element_idx][property_idx]; + + if (!lookup.skip) + { + helper = lookup.helper; + if (firstPass) + { + helper->cursor->totalSizeBytes += skip(lookup, property, is); + + // These lines will be changed when tinyply supports + // variable length lists. We add it here so our header data structure + // contains enough info to write it back out again (e.g. transcoding). + if (property.listCount == 0) property.listCount = listSize; + if (property.listCount != listSize) throw std::runtime_error("variable length lists are not supported yet."); + } + else + { + read(lookup, property, helper->data->buffer.get(), helper->cursor->byteOffset, is); + } + } + else + { + skip(lookup, property, is); + } + property_idx++; + } + } + element_idx++; + } + + // Reset istream position to the start of the data + if (firstPass) is.seekg(start, is.beg); +} + +// Wrap the public interface: + +IGL_INLINE PlyFile::PlyFile() { impl.reset(new PlyFileImpl()); } +IGL_INLINE PlyFile::~PlyFile() { } +IGL_INLINE bool PlyFile::parse_header(std::istream & is) { return impl->parse_header(is); } +IGL_INLINE void PlyFile::read(std::istream & is) { return impl->read(is); } +IGL_INLINE void PlyFile::write(std::ostream & os, bool isBinary) { return impl->write(os, isBinary); } +IGL_INLINE std::vector PlyFile::get_elements() const { return impl->elements; } +IGL_INLINE std::vector & PlyFile::get_comments() { return impl->comments; } +IGL_INLINE std::vector PlyFile::get_info() const { return impl->objInfo; } +IGL_INLINE bool PlyFile::is_binary_file() const { return impl->isBinary; } +IGL_INLINE std::shared_ptr PlyFile::request_properties_from_element(const std::string & elementKey, + const std::vector propertyKeys, + const uint32_t list_size_hint) +{ + return impl->request_properties_from_element(elementKey, propertyKeys, list_size_hint); +} +IGL_INLINE void PlyFile::add_properties_to_element(const std::string & elementKey, + const std::vector propertyKeys, + const Type type, const size_t count, uint8_t * data, const Type listType, const size_t listCount) +{ + return impl->add_properties_to_element(elementKey, propertyKeys, type, count, data, listType, listCount); +} + +} // tinyply +} // igl diff --git a/vendor/libigl/include/igl/tinyply.h b/vendor/libigl/include/igl/tinyply.h new file mode 100644 index 0000000000000000000000000000000000000000..73c35a73fb94fe74b2ef2a61b0e5d20be90d05e6 --- /dev/null +++ b/vendor/libigl/include/igl/tinyply.h @@ -0,0 +1,187 @@ +/* + * tinyply 2.3.2 (https://github.com/ddiakopoulos/tinyply) + * + * A single-header, zero-dependency (except the C++ STL) public domain implementation + * of the PLY mesh file format. Requires C++11; errors are handled through exceptions. + * + * This software is in the public domain. Where that dedication is not + * recognized, you are granted a perpetual, irrevocable license to copy, + * distribute, and modify this file as you see fit. + * + * Authored by Dimitri Diakopoulos (http://www.dimitridiakopoulos.com) + * + * tinyply.h may be included in many files, however in a single compiled file, + * the implementation must be created with the following defined prior to header inclusion + * #define TINYPLY_IMPLEMENTATION + * + */ + +//////////////////////// +// tinyply header // +//////////////////////// + +#ifndef tinyply_h +#define tinyply_h +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace igl +{ +namespace tinyply +{ + + enum class Type : uint8_t + { + INVALID, + INT8, + UINT8, + INT16, + UINT16, + INT32, + UINT32, + FLOAT32, + FLOAT64 + }; + + struct PropertyInfo + { + PropertyInfo() {}; + PropertyInfo(int stride, std::string str) + : stride(stride), str(str) {} + int stride {0}; + std::string str; + }; + + static std::map PropertyTable + { + { Type::INT8, PropertyInfo(1, std::string("char")) }, + { Type::UINT8, PropertyInfo(1, std::string("uchar")) }, + { Type::INT16, PropertyInfo(2, std::string("short")) }, + { Type::UINT16, PropertyInfo(2, std::string("ushort")) }, + { Type::INT32, PropertyInfo(4, std::string("int")) }, + { Type::UINT32, PropertyInfo(4, std::string("uint")) }, + { Type::FLOAT32, PropertyInfo(4, std::string("float")) }, + { Type::FLOAT64, PropertyInfo(8, std::string("double")) }, + { Type::INVALID, PropertyInfo(0, std::string("INVALID"))} + }; + + class Buffer + { + uint8_t * alias{ nullptr }; + struct delete_array { void operator()(uint8_t * p) { delete[] p; } }; + std::unique_ptr data; + size_t size {0}; + public: + Buffer() {}; + Buffer(const size_t size) : data(new uint8_t[size], delete_array()), size(size) { alias = data.get(); } // allocating + Buffer(uint8_t * ptr): alias(ptr) { } // non-allocating, todo: set size? + uint8_t * get() { return alias; } + size_t size_bytes() const { return size; } + }; + + struct PlyData + { + Type t; + Buffer buffer; + size_t count {0}; + bool isList {false}; + }; + + struct PlyProperty + { + PlyProperty(std::istream & is); + PlyProperty(Type type, std::string & _name) : name(_name), propertyType(type) {} + PlyProperty(Type list_type, Type prop_type, std::string & _name, size_t list_count) + : name(_name), propertyType(prop_type), isList(true), listType(list_type), listCount(list_count) {} + std::string name; + Type propertyType{ Type::INVALID }; + bool isList{ false }; + Type listType{ Type::INVALID }; + size_t listCount {0}; + }; + + struct PlyElement + { + PlyElement(std::istream & istream); + PlyElement(const std::string & _name, size_t count) : name(_name), size(count) {} + std::string name; + size_t size {0}; + std::vector properties; + }; + + struct PlyFile + { + struct PlyFileImpl; + std::unique_ptr impl; + + PlyFile(); + ~PlyFile(); + + /* + * The ply format requires an ascii header. This can be used to determine at + * runtime which properties or elements exist in the file. Limited validation of the + * header is performed; it is assumed the header correctly reflects the contents of the + * payload. This function may throw. Returns true on success, false on failure. + */ + bool parse_header(std::istream & is); + + /* + * Execute a read operation. Data must be requested via `request_properties_from_element(...)` + * prior to calling this function. + */ + void read(std::istream & is); + + /* + * `write` performs no validation and assumes that the data passed into + * `add_properties_to_element` is well-formed. + */ + void write(std::ostream & os, bool isBinary); + + /* + * These functions are valid after a call to `parse_header(...)`. In the case of + * writing, get_comments() reference may also be used to add new comments to the ply header. + */ + std::vector get_elements() const; + std::vector get_info() const; + std::vector & get_comments(); + bool is_binary_file() const; + + /* + * In the general case where |list_size_hint| is zero, `read` performs a two-pass + * parse to support variable length lists. The most general use of the + * ply format is storing triangle meshes. When this fact is known a-priori, we can pass + * an expected list length that will apply to this element. Doing so results in an up-front + * memory allocation and a single-pass import, a 2x performance optimization. + */ + std::shared_ptr request_properties_from_element(const std::string & elementKey, + const std::vector propertyKeys, const uint32_t list_size_hint = 0); + + void add_properties_to_element(const std::string & elementKey, + const std::vector propertyKeys, + const Type type, + const size_t count, + uint8_t * data, + const Type listType, + const size_t listCount); + }; + +} // end namespace tinyply +} // end namespace igl + +#ifndef IGL_STATIC_LIBRARY +// implementation moved to tinyply.cpp +# include "tinyply.cpp" +#endif + + +#endif // end tinyply_h diff --git a/vendor/libigl/include/igl/topological_hole_fill.cpp b/vendor/libigl/include/igl/topological_hole_fill.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1ecfb536cca73d06dfbcd05a8e9a6f72b074e022 --- /dev/null +++ b/vendor/libigl/include/igl/topological_hole_fill.cpp @@ -0,0 +1,55 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Zhongshi Jiang +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "topological_hole_fill.h" + template < + typename DerivedF, + typename Derivedb, + typename VectorIndex, + typename DerivedF_filled> +IGL_INLINE void igl::topological_hole_fill( + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const std::vector & holes, + Eigen::PlainObjectBase &F_filled) +{ + int n_filled_faces = 0; + int num_holes = holes.size(); + int real_F_num = F.rows(); + const int V_rows = F.maxCoeff()+1; + + for (int i = 0; i < num_holes; i++) + n_filled_faces += holes[i].size(); + F_filled.resize(n_filled_faces + real_F_num, 3); + F_filled.topRows(real_F_num) = F; + + int new_vert_id = V_rows; + int new_face_id = real_F_num; + + for (int i = 0; i < num_holes; i++, new_vert_id++) + { + int cur_bnd_size = holes[i].size(); + int it = 0; + int back = holes[i].size() - 1; + F_filled.row(new_face_id++) << holes[i][it], holes[i][back], new_vert_id; + while (it != back) + { + F_filled.row(new_face_id++) + << holes[i][(it + 1)], + holes[i][(it)], new_vert_id; + it++; + } + } + assert(new_face_id == F_filled.rows()); + assert(new_vert_id == V_rows + num_holes); + +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::topological_hole_fill, Eigen::Matrix, std::vector > >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/topological_hole_fill.h b/vendor/libigl/include/igl/topological_hole_fill.h new file mode 100644 index 0000000000000000000000000000000000000000..945e127e8dc2d1a0557c4aa8e56a822514905b06 --- /dev/null +++ b/vendor/libigl/include/igl/topological_hole_fill.h @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Zhongshi Jiang +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TOPOLOGICAL_HOLE_FILL_H +#define IGL_TOPOLOGICAL_HOLE_FILL_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + + // Topological fill hole on a mesh, with one additional vertex each hole + // Index of new abstract vertices will be F.maxCoeff() + (index of hole) + // + // Inputs: + // F #F by simplex-size list of element indices + // b #b boundary indices to preserve + // holes vector of hole loops to fill + // Outputs: + // F_filled input F stacked with filled triangles. + // + template < + typename DerivedF, + typename Derivedb, + typename VectorIndex, + typename DerivedF_filled> +IGL_INLINE void topological_hole_fill( + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & b, + const std::vector & holes, + Eigen::PlainObjectBase &F_filled); + +} + + +#ifndef IGL_STATIC_LIBRARY +# include "topological_hole_fill.cpp" +#endif + +#endif \ No newline at end of file diff --git a/vendor/libigl/include/igl/trackball.cpp b/vendor/libigl/include/igl/trackball.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a5fa2e9f8e5e3b94a4db46db1e4acb66c51ad22 --- /dev/null +++ b/vendor/libigl/include/igl/trackball.cpp @@ -0,0 +1,168 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "trackball.h" + +#include "EPS.h" +#include "dot.h" +#include "cross.h" +#include "axis_angle_to_quat.h" +#include "quat_mult.h" +#include +#include +#include +#include +#include + +// Utility IGL_INLINE functions +template +static IGL_INLINE Q_type _QuatD(double w, double h) +{ + using namespace std; + return (Q_type)(std::abs(w) < std::abs(h) ? std::abs(w) : std::abs(h)) - 4; +} +template +static IGL_INLINE Q_type _QuatIX(double x, double w, double h) +{ + return (2.0f*(Q_type)x - (Q_type)w - 1.0f)/_QuatD(w, h); +} +template +static IGL_INLINE Q_type _QuatIY(double y, double w, double h) +{ + return (-2.0f*(Q_type)y + (Q_type)h - 1.0f)/_QuatD(w, h); +} + +// This is largely the trackball as implemented in AntTweakbar. Much of the +// code is straight from its source in TwMgr.cpp +// http://www.antisphere.com/Wiki/tools:anttweakbar +template +IGL_INLINE void igl::trackball( + const double w, + const double h, + const Q_type speed_factor, + const double down_mouse_x, + const double down_mouse_y, + const double mouse_x, + const double mouse_y, + Q_type * quat) +{ + assert(speed_factor > 0); + + double original_x = + _QuatIX(speed_factor*(down_mouse_x-w/2)+w/2, w, h); + double original_y = + _QuatIY(speed_factor*(down_mouse_y-h/2)+h/2, w, h); + + double x = _QuatIX(speed_factor*(mouse_x-w/2)+w/2, w, h); + double y = _QuatIY(speed_factor*(mouse_y-h/2)+h/2, w, h); + + double z = 1; + double n0 = sqrt(original_x*original_x + original_y*original_y + z*z); + double n1 = sqrt(x*x + y*y + z*z); + if(n0>igl::DOUBLE_EPS && n1>igl::DOUBLE_EPS) + { + double v0[] = { original_x/n0, original_y/n0, z/n0 }; + double v1[] = { x/n1, y/n1, z/n1 }; + double axis[3]; + cross(v0,v1,axis); + double sa = sqrt(dot(axis, axis)); + double ca = dot(v0, v1); + double angle = atan2(sa, ca); + if( x*x+y*y>1.0 ) + { + angle *= 1.0 + 0.2f*(sqrt(x*x+y*y)-1.0); + } + double qrot[4]; + axis_angle_to_quat(axis,angle,qrot); + quat[0] = qrot[0]; + quat[1] = qrot[1]; + quat[2] = qrot[2]; + quat[3] = qrot[3]; + } +} + + +template +IGL_INLINE void igl::trackball( + const double w, + const double h, + const Q_type speed_factor, + const Q_type * down_quat, + const double down_mouse_x, + const double down_mouse_y, + const double mouse_x, + const double mouse_y, + Q_type * quat) +{ + double qrot[4], qres[4], qorig[4]; + igl::trackball( + w,h, + speed_factor, + down_mouse_x,down_mouse_y, + mouse_x,mouse_y, + qrot); + double nqorig = + sqrt(down_quat[0]*down_quat[0]+ + down_quat[1]*down_quat[1]+ + down_quat[2]*down_quat[2]+ + down_quat[3]*down_quat[3]); + + if( fabs(nqorig)>igl::DOUBLE_EPS_SQ ) + { + qorig[0] = down_quat[0]/nqorig; + qorig[1] = down_quat[1]/nqorig; + qorig[2] = down_quat[2]/nqorig; + qorig[3] = down_quat[3]/nqorig; + igl::quat_mult(qrot,qorig,qres); + quat[0] = qres[0]; + quat[1] = qres[1]; + quat[2] = qres[2]; + quat[3] = qres[3]; + } + else + { + quat[0] = qrot[0]; + quat[1] = qrot[1]; + quat[2] = qrot[2]; + quat[3] = qrot[3]; + } +} + +template +IGL_INLINE void igl::trackball( + const double w, + const double h, + const double speed_factor, + const Eigen::Quaternion & down_quat, + const double down_mouse_x, + const double down_mouse_y, + const double mouse_x, + const double mouse_y, + Eigen::Quaternion & quat) +{ + using namespace std; + return trackball( + w, + h, + (Scalarquat)speed_factor, + down_quat.coeffs().data(), + down_mouse_x, + down_mouse_y, + mouse_x, + mouse_y, + quat.coeffs().data()); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::trackball(double, double, double, double const*, double, double, double, double, double*); +// generated by autoexplicit.sh +template void igl::trackball(double, double, float, float const*, double, double, double, double, float*); +template void igl::trackball(double, double, double, Eigen::Quaternion const&, double, double, double, double, Eigen::Quaternion&); +template void igl::trackball(double, double, double, Eigen::Quaternion const&, double, double, double, double, Eigen::Quaternion&); +#endif diff --git a/vendor/libigl/include/igl/trackball.h b/vendor/libigl/include/igl/trackball.h new file mode 100644 index 0000000000000000000000000000000000000000..6bf79e01981ac7e48af674224e021823fbbbbca8 --- /dev/null +++ b/vendor/libigl/include/igl/trackball.h @@ -0,0 +1,80 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TRACKBALL_H +#define IGL_TRACKBALL_H +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Applies a trackball drag to identity + // Inputs: + // w width of the trackball context + // h height of the trackball context + // speed_factor controls how fast the trackball feels, 1 is normal + // down_mouse_x x position of mouse down + // down_mouse_y y position of mouse down + // mouse_x current x position of mouse + // mouse_y current y position of mouse + // Outputs: + // quat the resulting rotation (as quaternion) + template + IGL_INLINE void trackball( + const double w, + const double h, + const Q_type speed_factor, + const double down_mouse_x, + const double down_mouse_y, + const double mouse_x, + const double mouse_y, + Q_type * quat); + + // Applies a trackball drag to a given rotation + // Inputs: + // w width of the trackball context + // h height of the trackball context + // speed_factor controls how fast the trackball feels, 1 is normal + // down_quat rotation at mouse down, i.e. the rotation we're applying the + // trackball motion to (as quaternion) + // down_mouse_x x position of mouse down + // down_mouse_y y position of mouse down + // mouse_x current x position of mouse + // mouse_y current y position of mouse + // Outputs: + // quat the resulting rotation (as quaternion) + template + IGL_INLINE void trackball( + const double w, + const double h, + const Q_type speed_factor, + const Q_type * down_quat, + const double down_mouse_x, + const double down_mouse_y, + const double mouse_x, + const double mouse_y, + Q_type * quat); + // Eigen wrapper. + template + IGL_INLINE void trackball( + const double w, + const double h, + const double speed_factor, + const Eigen::Quaternion & down_quat, + const double down_mouse_x, + const double down_mouse_y, + const double mouse_x, + const double mouse_y, + Eigen::Quaternion & quat); +} + +#ifndef IGL_STATIC_LIBRARY +# include "trackball.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/transpose_blocks.cpp b/vendor/libigl/include/igl/transpose_blocks.cpp new file mode 100644 index 0000000000000000000000000000000000000000..004edd7ac2ab2d1568fc6e36204ebb9731743751 --- /dev/null +++ b/vendor/libigl/include/igl/transpose_blocks.cpp @@ -0,0 +1,63 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "transpose_blocks.h" + +#include + +template +IGL_INLINE void igl::transpose_blocks( + const Eigen::Matrix & A, + const size_t k, + const size_t dim, + Eigen::Matrix & B) +{ + // Eigen matrices must be 2d so dim must be only 1 or 2 + assert(dim == 1 || dim == 2); + // Output is not allowed to be input + assert(&A != &B); + + + // block height, width, and number of blocks + int m,n; + if(dim == 1) + { + m = A.rows()/k; + n = A.cols(); + }else// dim == 2 + { + m = A.rows(); + n = A.cols()/k; + } + + // resize output + if(dim == 1) + { + B.resize(n*k,m); + }else//dim ==2 + { + B.resize(n,m*k); + } + + // loop over blocks + for(int b = 0;b<(int)k;b++) + { + if(dim == 1) + { + B.block(b*n,0,n,m) = A.block(b*m,0,m,n).transpose(); + }else//dim ==2 + { + B.block(0,b*m,n,m) = A.block(0,b*n,m,n).transpose(); + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::transpose_blocks(Eigen::Matrix const&, size_t, size_t, Eigen::Matrix&); +#endif diff --git a/vendor/libigl/include/igl/transpose_blocks.h b/vendor/libigl/include/igl/transpose_blocks.h new file mode 100644 index 0000000000000000000000000000000000000000..65ce89fbd3bf87e41c1f04beba27b3dcc2c1b0d7 --- /dev/null +++ b/vendor/libigl/include/igl/transpose_blocks.h @@ -0,0 +1,61 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TRANSPOSE_BLOCKS_H +#define IGL_TRANSPOSE_BLOCKS_H +#include "igl_inline.h" + +#include + +namespace igl +{ + // Templates: + // T should be a eigen matrix primitive type like int or double + // Inputs: + // A m*k by n (dim: 1) or m by n*k (dim: 2) eigen Matrix of type T values + // k number of blocks + // dim dimension in which to transpose + // Output + // B n*k by m (dim: 1) or n by m*k (dim: 2) eigen Matrix of type T values, + // NOT allowed to be the same as A + // + // Example: + // A = [ + // 1 2 3 4 + // 5 6 7 8 + // 101 102 103 104 + // 105 106 107 108 + // 201 202 203 204 + // 205 206 207 208]; + // transpose_blocks(A,1,3,B); + // B -> [ + // 1 5 + // 2 6 + // 3 7 + // 4 8 + // 101 105 + // 102 106 + // 103 107 + // 104 108 + // 201 205 + // 202 206 + // 203 207 + // 204 208]; + // + template + IGL_INLINE void transpose_blocks( + const Eigen::Matrix & A, + const size_t k, + const size_t dim, + Eigen::Matrix & B); +} + +#ifndef IGL_STATIC_LIBRARY +# include "transpose_blocks.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/triangle_fan.cpp b/vendor/libigl/include/igl/triangle_fan.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97f2887ec05317bd1b9cdfedae8cb114c1006258 --- /dev/null +++ b/vendor/libigl/include/igl/triangle_fan.cpp @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "triangle_fan.h" +#include "exterior_edges.h" +#include "list_to_matrix.h" + +template +IGL_INLINE void igl::triangle_fan( + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & cap) +{ + using namespace std; + using namespace Eigen; + + // Handle lame base case + if(E.size() == 0) + { + cap.resize(0,E.cols()+1); + return; + } + // "Triangulate" aka "close" the E trivially with facets + // Note: in 2D we need to know if E endpoints are incoming or + // outgoing (left or right). Thus this will not work. + assert(E.cols() == 2); + // Arbitrary starting vertex + //int s = E(int(((double)rand() / RAND_MAX)*E.rows()),0); + int s = E(rand()%E.rows(),0); + vector > lcap; + for(int i = 0;i e(3); + e[0] = s; + e[1] = E(i,0); + e[2] = E(i,1); + lcap.push_back(e); + } + list_to_matrix(lcap,cap); +} + +IGL_INLINE Eigen::MatrixXi igl::triangle_fan( const Eigen::MatrixXi & E) +{ + Eigen::MatrixXi cap; + triangle_fan(E,cap); + return cap; +} + +#if IGL_STATIC_LIBRARY +#endif diff --git a/vendor/libigl/include/igl/triangle_fan.h b/vendor/libigl/include/igl/triangle_fan.h new file mode 100644 index 0000000000000000000000000000000000000000..bd9dca73b1d78aea2f48327dee9dddc4bcde5f14 --- /dev/null +++ b/vendor/libigl/include/igl/triangle_fan.h @@ -0,0 +1,31 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TRIANGLE_FAN_H +#define IGL_TRIANGLE_FAN_H +#include "igl_inline.h" +#include +namespace igl +{ + // Given a list of faces tessellate all of the "exterior" edges forming another + // list of + // + // Inputs: + // E #E by simplex_size-1 list of exterior edges (see exterior_edges.h) + // Outputs: + // cap #cap by simplex_size list of "faces" tessellating the boundary edges + template + IGL_INLINE void triangle_fan( + const Eigen::MatrixBase & E, + Eigen::PlainObjectBase & cap); + // In-line version + IGL_INLINE Eigen::MatrixXi triangle_fan( const Eigen::MatrixXi & E); +} +#ifndef IGL_STATIC_LIBRARY +# include "triangle_fan.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/triangle_triangle_adjacency.cpp b/vendor/libigl/include/igl/triangle_triangle_adjacency.cpp new file mode 100644 index 0000000000000000000000000000000000000000..901d2e12f2c9052f66499024174c7c1d8a127232 --- /dev/null +++ b/vendor/libigl/include/igl/triangle_triangle_adjacency.cpp @@ -0,0 +1,275 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2018 Alec Jacobson, Marc Alexa +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "triangle_triangle_adjacency.h" +#include "vertex_triangle_adjacency.h" +#include "parallel_for.h" +#include "unique_edge_map.h" +#include +#include + +// Extract the face adjacencies +template +IGL_INLINE void igl::triangle_triangle_adjacency_extractTT( + const Eigen::MatrixBase& F, + std::vector >& TTT, + Eigen::PlainObjectBase& TT) +{ + TT.setConstant((int)(F.rows()),F.cols(),-1); + + for(int i=1;i<(int)TTT.size();++i) + { + std::vector& r1 = TTT[i-1]; + std::vector& r2 = TTT[i]; + if ((r1[0] == r2[0]) && (r1[1] == r2[1])) + { + TT(r1[2],r1[3]) = r2[2]; + TT(r2[2],r2[3]) = r1[2]; + } + } +} + +template +IGL_INLINE void igl::triangle_triangle_adjacency( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& TT) +{ + const int n = F.maxCoeff()+1; + typedef Eigen::Matrix VectorXI; + VectorXI VF,NI; + vertex_triangle_adjacency(F,n,VF,NI); + TT = DerivedTT::Constant(F.rows(),3,-1); + // Loop over faces + igl::parallel_for(F.rows(),[&](int f) + { + // Loop over corners + for (int k = 0; k < 3; k++) + { + int vi = F(f,k), vin = F(f,(k+1)%3); + // Loop over face neighbors incident on this corner + for (int j = NI[vi]; j < NI[vi+1]; j++) + { + int fn = VF[j]; + // Not this face + if (fn != f) + { + // Face neighbor also has [vi,vin] edge + if (F(fn,0) == vin || F(fn,1) == vin || F(fn,2) == vin) + { + TT(f,k) = fn; + break; + } + } + } + } + }); +} + +template +IGL_INLINE void igl::triangle_triangle_adjacency_preprocess( + const Eigen::MatrixBase& F, + std::vector >& TTT) +{ + for(int f=0;f v2) std::swap(v1,v2); + std::vector r(4); + r[0] = v1; r[1] = v2; + r[2] = f; r[3] = i; + TTT.push_back(r); + } + std::sort(TTT.begin(),TTT.end()); +} + +// Extract the face adjacencies indices (needed for fast traversal) +template +IGL_INLINE void igl::triangle_triangle_adjacency_extractTTi( + const Eigen::MatrixBase& F, + std::vector >& TTT, + Eigen::PlainObjectBase& TTi) +{ + TTi.setConstant((int)(F.rows()),F.cols(),-1); + + for(int i=1;i<(int)TTT.size();++i) + { + std::vector& r1 = TTT[i-1]; + std::vector& r2 = TTT[i]; + if ((r1[0] == r2[0]) && (r1[1] == r2[1])) + { + TTi(r1[2],r1[3]) = r2[3]; + TTi(r2[2],r2[3]) = r1[3]; + } + } +} + +// Compute triangle-triangle adjacency with indices +template +IGL_INLINE void igl::triangle_triangle_adjacency( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& TT, + Eigen::PlainObjectBase& TTi) +{ + triangle_triangle_adjacency(F,TT); + TTi = DerivedTTi::Constant(TT.rows(),TT.cols(),-1); + //for(int f = 0; f= 0) + { + for(int kn = 0;kn<3;kn++) + { + int vin = F(fn,kn), vjn = F(fn,(kn+1)%3); + if(vi == vjn && vin == vj) + { + TTi(f,k) = kn; + break; + } + } + } + } + }); +} + +template < + typename DerivedF, + typename TTIndex, + typename TTiIndex> + IGL_INLINE void igl::triangle_triangle_adjacency( + const Eigen::MatrixBase & F, + std::vector > > & TT, + std::vector > > & TTi) +{ + return triangle_triangle_adjacency(F,true,TT,TTi); +} + +template < + typename DerivedF, + typename TTIndex> + IGL_INLINE void igl::triangle_triangle_adjacency( + const Eigen::MatrixBase & F, + std::vector > > & TT) +{ + std::vector > > not_used; + return triangle_triangle_adjacency(F,false,TT,not_used); +} + +template < + typename DerivedF, + typename TTIndex, + typename TTiIndex> + IGL_INLINE void igl::triangle_triangle_adjacency( + const Eigen::MatrixBase & F, + const bool construct_TTi, + std::vector > > & TT, + std::vector > > & TTi) +{ + using namespace Eigen; + using namespace std; + assert(F.cols() == 3 && "Faces must be triangles"); + // number of faces + typedef typename DerivedF::Index Index; + typedef Matrix MatrixX2I; + typedef Matrix VectorXI; + MatrixX2I E,uE; + VectorXI EMAP; + vector > uE2E; + unique_edge_map(F,E,uE,EMAP,uE2E); + return triangle_triangle_adjacency(E,EMAP,uE2E,construct_TTi,TT,TTi); +} + +template < + typename DerivedE, + typename DerivedEMAP, + typename uE2EType, + typename TTIndex, + typename TTiIndex> + IGL_INLINE void igl::triangle_triangle_adjacency( + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EMAP, + const std::vector > & uE2E, + const bool construct_TTi, + std::vector > > & TT, + std::vector > > & TTi) +{ + using namespace std; + using namespace Eigen; + typedef typename DerivedE::Index Index; + const size_t m = E.rows()/3; + assert((size_t)E.rows() == m*3 && "E should come from list of triangles."); + // E2E[i] --> {j,k,...} means face edge i corresponds to other faces edges j + // and k + TT.resize (m,vector >(3)); + if(construct_TTi) + { + TTi.resize(m,vector >(3)); + } + + // No race conditions because TT*[f][c]'s are in bijection with e's + // Minimum number of items per thread + //const size_t num_e = E.rows(); + // Slightly better memory access than loop over E + igl::parallel_for( + m, + [&](const Index & f) + { + for(Index c = 0;c<3;c++) + { + const Index e = f + m*c; + //const Index c = e/m; + const vector & N = uE2E[EMAP(e)]; + for(const auto & ne : N) + { + const Index nf = ne%m; + // don't add self + if(nf != f) + { + TT[f][c].push_back(nf); + if(construct_TTi) + { + const Index nc = ne/m; + TTi[f][c].push_back(nc); + } + } + } + } + }, + 1000ul); + + +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::triangle_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::triangle_triangle_adjacency, int>(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); +// generated by autoexplicit.sh +template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::triangle_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::triangle_triangle_adjacency, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::triangle_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::triangle_triangle_adjacency, long, long>(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); +template void igl::triangle_triangle_adjacency, int>(Eigen::MatrixBase > const&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); +#ifdef WIN32 +template void igl::triangle_triangle_adjacency, __int64, __int64>(class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>>, class std::allocator>, class std::allocator>>>>> &, class std::vector>, class std::allocator>>>, class std::allocator>, class std::allocator>>>>> &); +template void igl::triangle_triangle_adjacency, class Eigen::Matrix, unsigned __int64, int, int>(class Eigen::MatrixBase> const &, class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>> const &, bool, class std::vector>, class std::allocator>>>, class std::allocator>, class std::allocator>>>>> &, class std::vector>, class std::allocator>>>, class std::allocator>, class std::allocator>>>>> &); +#endif +template void igl::triangle_triangle_adjacency, Eigen::Matrix, long, long, long>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, bool, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); +template void igl::triangle_triangle_adjacency, Eigen::Matrix, unsigned long, int, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > > const&, bool, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&, std::vector >, std::allocator > > >, std::allocator >, std::allocator > > > > >&); +#endif diff --git a/vendor/libigl/include/igl/triangle_triangle_adjacency.h b/vendor/libigl/include/igl/triangle_triangle_adjacency.h new file mode 100644 index 0000000000000000000000000000000000000000..7a3148f05ca4a206af96d0441517282ab5a7fb8b --- /dev/null +++ b/vendor/libigl/include/igl/triangle_triangle_adjacency.h @@ -0,0 +1,126 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TRIANGLE_TRIANGLE_ADJACENCY_H +#define IGL_TRIANGLE_TRIANGLE_ADJACENCY_H +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Constructs the triangle-triangle adjacency matrix for a given + // mesh (V,F). + // + // Inputs: + // F #F by simplex_size list of mesh faces (must be triangles) + // Outputs: + // TT #F by #3 adjacent matrix, the element i,j is the id of the triangle + // adjacent to the j edge of triangle i + // TTi #F by #3 adjacent matrix, the element i,j is the id of edge of the + // triangle TT(i,j) that is adjacent with triangle i + // + // NOTE: the first edge of a triangle is [0,1] the second [1,2] and the third + // [2,3]. this convention is DIFFERENT from + // cotmatrix_entries.h/edge_lengths.h/etc. To fix this you could use: + // // Fix mis-match convention + // { + // Eigen::PermutationMatrix<3,3> perm(3); + // perm.indices() = Eigen::Vector3i(1,2,0); + // TT = (TT*perm).eval(); + // TTi = (TTi*perm).eval(); + // for(int i=0;i + IGL_INLINE void triangle_triangle_adjacency( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& TT, + Eigen::PlainObjectBase& TTi); + template + IGL_INLINE void triangle_triangle_adjacency( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& TT); + // Preprocessing + template + IGL_INLINE void triangle_triangle_adjacency_preprocess( + const Eigen::MatrixBase& F, + std::vector >& TTT); + // Extract the face adjacencies + template + IGL_INLINE void triangle_triangle_adjacency_extractTT( + const Eigen::MatrixBase& F, + std::vector >& TTT, + Eigen::PlainObjectBase& TT); + // Extract the face adjacencies indices (needed for fast traversal) + template + IGL_INLINE void triangle_triangle_adjacency_extractTTi( + const Eigen::MatrixBase& F, + std::vector >& TTT, + Eigen::PlainObjectBase& TTi); + // Adjacency list version, which works with non-manifold meshes + // + // Inputs: + // F #F by 3 list of triangle indices + // Outputs: + // TT #F by 3 list of lists so that TT[i][c] --> {j,k,...} means that + // faces j and k etc. are edge-neighbors of face i on face i's edge + // opposite corner c + // TTj #F list of lists so that TTj[i][c] --> {j,k,...} means that face + // TT[i][c][0] is an edge-neighbor of face i incident on the edge of face + // TT[i][c][0] opposite corner j, and TT[i][c][1] " corner k, etc. + template < + typename DerivedF, + typename TTIndex, + typename TTiIndex> + IGL_INLINE void triangle_triangle_adjacency( + const Eigen::MatrixBase & F, + std::vector > > & TT, + std::vector > > & TTi); + template < typename DerivedF, typename TTIndex> + IGL_INLINE void triangle_triangle_adjacency( + const Eigen::MatrixBase & F, + std::vector > > & TT); + // Wrapper with bool to choose whether to compute TTi (this prototype should + // be "hidden"). + template < + typename DerivedF, + typename TTIndex, + typename TTiIndex> + IGL_INLINE void triangle_triangle_adjacency( + const Eigen::MatrixBase & F, + const bool construct_TTi, + std::vector > > & TT, + std::vector > > & TTi); + // Inputs: + // E #F*3 by 2 list of all of directed edges in order (see + // `oriented_facets`) + // EMAP #F*3 list of indices into uE, mapping each directed edge to unique + // undirected edge + // uE2E #uE list of lists of indices into E of coexisting edges + // See also: unique_edge_map, oriented_facets + template < + typename DerivedE, + typename DerivedEMAP, + typename uE2EType, + typename TTIndex, + typename TTiIndex> + IGL_INLINE void triangle_triangle_adjacency( + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & EMAP, + const std::vector > & uE2E, + const bool construct_TTi, + std::vector > > & TT, + std::vector > > & TTi); +} + +#ifndef IGL_STATIC_LIBRARY +# include "triangle_triangle_adjacency.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/triangles_from_strip.cpp b/vendor/libigl/include/igl/triangles_from_strip.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1db854834d36aaa49388bc8fda934c188fc0fcb2 --- /dev/null +++ b/vendor/libigl/include/igl/triangles_from_strip.cpp @@ -0,0 +1,36 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "triangles_from_strip.h" +#include + +template +IGL_INLINE void igl::triangles_from_strip( + const Eigen::MatrixBase& S, + Eigen::PlainObjectBase& F) +{ + using namespace std; + F.resize(S.size()-2,3); + for(int s = 0;s < S.size()-2;s++) + { + if(s%2 == 0) + { + F(s,0) = S(s+2); + F(s,1) = S(s+1); + F(s,2) = S(s+0); + }else + { + F(s,0) = S(s+0); + F(s,1) = S(s+1); + F(s,2) = S(s+2); + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +#endif diff --git a/vendor/libigl/include/igl/triangles_from_strip.h b/vendor/libigl/include/igl/triangles_from_strip.h new file mode 100644 index 0000000000000000000000000000000000000000..01ffd64028db792b21c189eb859b2040f6ea5b75 --- /dev/null +++ b/vendor/libigl/include/igl/triangles_from_strip.h @@ -0,0 +1,33 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TRIANGLES_FROM_STRIP_H +#define IGL_TRIANGLES_FROM_STRIP_H +#include "igl_inline.h" +#include +namespace igl +{ + // TRIANGLES_FROM_STRIP Create a list of triangles from a stream of indices + // along a strip. + // + // Inputs: + // S #S list of indices + // Outputs: + // F #S-2 by 3 list of triangle indices + // + template + IGL_INLINE void triangles_from_strip( + const Eigen::MatrixBase& S, + Eigen::PlainObjectBase& F); +} + +#ifndef IGL_STATIC_LIBRARY +# include "triangles_from_strip.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/triangulated_grid.cpp b/vendor/libigl/include/igl/triangulated_grid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c84f9e370677e7f2387163e83aadaa8807c959a --- /dev/null +++ b/vendor/libigl/include/igl/triangulated_grid.cpp @@ -0,0 +1,65 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "triangulated_grid.h" +#include "grid.h" +#include + +template < + typename XType, + typename YType, + typename DerivedGV, + typename DerivedGF> +IGL_INLINE void igl::triangulated_grid( + const XType & nx, + const YType & ny, + Eigen::PlainObjectBase & GV, + Eigen::PlainObjectBase & GF) +{ + using namespace Eigen; + Eigen::Matrix res(nx,ny); + igl::grid(res,GV); + return igl::triangulated_grid(nx,ny,GF); +}; + +template < + typename XType, + typename YType, + typename DerivedGF> +IGL_INLINE void igl::triangulated_grid( + const XType & nx, + const YType & ny, + Eigen::PlainObjectBase & GF) +{ + GF.resize((nx-1)*(ny-1)*2,3); + for(int y = 0;y, Eigen::Matrix >(int const&, int const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/two_axis_valuator_fixed_up.cpp b/vendor/libigl/include/igl/two_axis_valuator_fixed_up.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc35475b0f25f8607d421942c00cb9859585c652 --- /dev/null +++ b/vendor/libigl/include/igl/two_axis_valuator_fixed_up.cpp @@ -0,0 +1,47 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "two_axis_valuator_fixed_up.h" +#include "PI.h" + +template +IGL_INLINE void igl::two_axis_valuator_fixed_up( + const int w, + const int h, + const double speed, + const Eigen::Quaternion & down_quat, + const int down_x, + const int down_y, + const int mouse_x, + const int mouse_y, + Eigen::Quaternion & quat) +{ + Eigen::Matrix axis(0,1,0); + quat = down_quat * + Eigen::Quaternion( + Eigen::AngleAxis( + PI*((Scalarquat)(mouse_x-down_x))/(Scalarquat)w*speed/2.0, + axis.normalized())); + quat.normalize(); + { + Eigen::Matrix axis(1,0,0); + if(axis.norm() != 0) + { + quat = Eigen::Quaternion( + Eigen::AngleAxis( + PI*(mouse_y-down_y)/(Scalarquat)h*speed/2.0, + axis.normalized())) * quat; + quat.normalize(); + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template void igl::two_axis_valuator_fixed_up(int, int, double, Eigen::Quaternion const&, int, int, int, int, Eigen::Quaternion&); +template void igl::two_axis_valuator_fixed_up(int, int, double, Eigen::Quaternion const&, int, int, int, int, Eigen::Quaternion&); +#endif diff --git a/vendor/libigl/include/igl/two_axis_valuator_fixed_up.h b/vendor/libigl/include/igl/two_axis_valuator_fixed_up.h new file mode 100644 index 0000000000000000000000000000000000000000..7b2e9aabf0b58d54088ffcc3dd5983cd6dec33a8 --- /dev/null +++ b/vendor/libigl/include/igl/two_axis_valuator_fixed_up.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_TWO_AXIS_VALUATOR_FIXED_AXIS_UP_H +#define IGL_TWO_AXIS_VALUATOR_FIXED_AXIS_UP_H + +#include "igl_inline.h" +#include +#include + +namespace igl +{ + // Applies a two-axis valuator drag rotation (as seen in Maya/Studio max) to a given rotation. + // Inputs: + // w width of the trackball context + // h height of the trackball context + // speed controls how fast the trackball feels, 1 is normal + // down_quat rotation at mouse down, i.e. the rotation we're applying the + // trackball motion to (as quaternion). **Note:** Up-vector that is fixed + // is with respect to this rotation. + // down_x position of mouse down + // down_y position of mouse down + // mouse_x current x position of mouse + // mouse_y current y position of mouse + // Outputs: + // quat the resulting rotation (as quaternion) + // + // See also: snap_to_fixed_up + template + IGL_INLINE void two_axis_valuator_fixed_up( + const int w, + const int h, + const double speed, + const Eigen::Quaternion & down_quat, + const int down_x, + const int down_y, + const int mouse_x, + const int mouse_y, + Eigen::Quaternion & quat); +} + +#ifndef IGL_STATIC_LIBRARY +# include "two_axis_valuator_fixed_up.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/uniformly_sample_two_manifold.cpp b/vendor/libigl/include/igl/uniformly_sample_two_manifold.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d35f741131271ac7c04bfb6fea51d4b80541b3fe --- /dev/null +++ b/vendor/libigl/include/igl/uniformly_sample_two_manifold.cpp @@ -0,0 +1,427 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "uniformly_sample_two_manifold.h" +#include "verbose.h" +#include "slice.h" +#include "colon.h" +#include "all_pairs_distances.h" +#include "mat_max.h" +#include "vertex_triangle_adjacency.h" +#include "get_seconds.h" +#include "cat.h" +//#include "MT19937.h" +#include "partition.h" + +////////////////////////////////////////////////////////////////////////////// +// Helper functions +////////////////////////////////////////////////////////////////////////////// + +IGL_INLINE void igl::uniformly_sample_two_manifold( + const Eigen::MatrixXd & W, + const Eigen::MatrixXi & F, + const int k, + const double push, + Eigen::MatrixXd & WS) +{ + using namespace Eigen; + using namespace std; + + // Euclidean distance between two points on a mesh given as barycentric + // coordinates + // Inputs: + // W #W by dim positions of mesh in weight space + // F #F by 3 indices of triangles + // face_A face index where 1st point lives + // bary_A barycentric coordinates of 1st point on face_A + // face_B face index where 2nd point lives + // bary_B barycentric coordinates of 2nd point on face_B + // Returns distance in euclidean space + const auto & bary_dist = [] ( + const Eigen::MatrixXd & W, + const Eigen::MatrixXi & F, + const int face_A, + const Eigen::Vector3d & bary_A, + const int face_B, + const Eigen::Vector3d & bary_B) -> double + { + return + ((bary_A(0)*W.row(F(face_A,0)) + + bary_A(1)*W.row(F(face_A,1)) + + bary_A(2)*W.row(F(face_A,2))) + - + (bary_B(0)*W.row(F(face_B,0)) + + bary_B(1)*W.row(F(face_B,1)) + + bary_B(2)*W.row(F(face_B,2)))).norm(); + }; + + // Base case if F is a tet list, find all faces and pass as non-manifold + // triangle mesh + if(F.cols() == 4) + { + verbose("uniform_sample.h: sampling tet mesh\n"); + MatrixXi T0 = F.col(0); + MatrixXi T1 = F.col(1); + MatrixXi T2 = F.col(2); + MatrixXi T3 = F.col(3); + // Faces from tets + MatrixXi TF = + cat(1, + cat(1, + cat(2,T0, cat(2,T1,T2)), + cat(2,T0, cat(2,T2,T3))), + cat(1, + cat(2,T0, cat(2,T3,T1)), + cat(2,T1, cat(2,T3,T2))) + ); + assert(TF.rows() == 4*F.rows()); + assert(TF.cols() == 3); + uniformly_sample_two_manifold(W,TF,k,push,WS); + return; + } + + double start = get_seconds(); + + VectorXi S; + // First get sampling as best as possible on mesh + uniformly_sample_two_manifold_at_vertices(W,k,push,S); + verbose("Lap: %g\n",get_seconds()-start); + slice(W,S,colon(0,W.cols()-1),WS); + //cout<<"WSmesh=["< > VF,VFi; + vertex_triangle_adjacency(W,F,VF,VFi); + + // List of list of face indices, for each sample gives index to face it is on + vector > sample_faces; sample_faces.resize(k); + // List of list of barycentric coordinates, for each sample gives b-coords in + // face its on + vector > sample_barys; sample_barys.resize(k); + // List of current maxmins amongst samples + vector cur_maxmin; cur_maxmin.resize(k); + // List of distance matrices, D(i)(s,j) reveals distance from i's sth sample + // to jth seed if j D; D.resize(k); + + // Precompute an W.cols() by W.cols() identity matrix + MatrixXd I(MatrixXd::Identity(W.cols(),W.cols())); + + // Describe each seed as a face index and barycentric coordinates + for(int i = 0;i < k;i++) + { + // Unreferenced vertex? + assert(VF[S(i)].size() > 0); + sample_faces[i].push_back(VF[S(i)][0]); + // We're right on a face vertex so barycentric coordinates are 0, but 1 at + // that vertex + Eigen::Vector3d bary(0,0,0); + bary( VFi[S(i)][0] ) = 1; + sample_barys[i].push_back(bary); + // initialize this to current maxmin + cur_maxmin[i] = 0; + } + + // initialize radius + double radius = 1.0; + // minimum radius (bound on precision) + //double min_radius = 1e-5; + double min_radius = 1e-5; + int max_num_rand_samples_per_triangle = 100; + int max_sample_attempts_per_triangle = 1000; + // Max number of outer iterations for a given radius + int max_iters = 1000; + + // continue iterating until radius is smaller than some threshold + while(radius > min_radius) + { + // initialize each seed + for(int i = 0;i < k;i++) + { + // Keep track of cur_maxmin data + int face_i = sample_faces[i][cur_maxmin[i]]; + Eigen::Vector3d bary(sample_barys[i][cur_maxmin[i]]); + // Find index in face of closest mesh vertex (on this face) + int index_in_face = + (bary(0) > bary(1) ? (bary(0) > bary(2) ? 0 : 2) + : (bary(1) > bary(2) ? 1 : 2)); + // find closest mesh vertex + int vertex_i = F(face_i,index_in_face); + // incident triangles + vector incident_F = VF[vertex_i]; + // We're going to try to place num_rand_samples_per_triangle samples on + // each sample *after* this location + sample_barys[i].clear(); + sample_faces[i].clear(); + cur_maxmin[i] = 0; + sample_barys[i].push_back(bary); + sample_faces[i].push_back(face_i); + // Current seed location in weight space + VectorXd seed = + bary(0)*W.row(F(face_i,0)) + + bary(1)*W.row(F(face_i,1)) + + bary(2)*W.row(F(face_i,2)); +#ifdef EXTREME_VERBOSE + verbose("i: %d\n",i); + verbose("face_i: %d\n",face_i); + //cout<<"bary: "<1) + { + u = 1-rv; + v = 1-ru; + }else + { + u = ru; + v = rv; + } + Eigen::Vector3d sample_bary(u,v,1-u-v); + double d = bary_dist(W,F,face_i,bary,face_f,sample_bary); + // check that sample is close enough + if(d= max_num_rand_samples_per_triangle) + { +#ifdef EXTREME_VERBOSE + verbose("Reached maximum number of samples per face\n"); +#endif + break; + } + if(s==(max_sample_attempts_per_triangle-1)) + { +#ifdef EXTREME_VERBOSE + verbose("Reached maximum sample attempts per triangle\n"); +#endif + } + } +#ifdef EXTREME_VERBOSE + verbose("sample_faces[%d].size(): %d\n",i,sample_faces[i].size()); + verbose("sample_barys[%d].size(): %d\n",i,sample_barys[i].size()); +#endif + } + } + + // Precompute distances from each seed's random samples to each "pushed" + // corner + // Put -1 in entries corresponding distance of a seed's random samples to + // self + // Loop over seeds + for(int i = 0;i < k;i++) + { + // resize distance matrix for new samples + D[i].resize(sample_faces[i].size(),k+W.cols()); + // Loop over i's samples + for(int s = 0;s<(int)sample_faces[i].size();s++) + { + int sample_face = sample_faces[i][s]; + Eigen::Vector3d sample_bary = sample_barys[i][s]; + // Loop over other seeds + for(int j = 0;j < k;j++) + { + // distance from sample(i,s) to seed j + double d; + if(i==j) + { + // phony self distance: Ilya's idea of infinite + d = 10; + }else + { + int seed_j_face = sample_faces[j][cur_maxmin[j]]; + Eigen::Vector3d seed_j_bary(sample_barys[j][cur_maxmin[j]]); + d = bary_dist(W,F,sample_face,sample_bary,seed_j_face,seed_j_bary); + } + D[i](s,j) = d; + } + // Loop over corners + for(int j = 0;j < W.cols();j++) + { + // distance from sample(i,s) to corner j + double d = + ((sample_bary(0)*W.row(F(sample_face,0)) + + sample_bary(1)*W.row(F(sample_face,1)) + + sample_bary(2)*W.row(F(sample_face,2))) + - I.row(j)).norm()/push; + // append after distances to seeds + D[i](s,k+j) = d; + } + } + } + + int iters = 0; + while(true) + { + bool has_changed = false; + // try to move each seed + for(int i = 0;i < k;i++) + { + // for each sample look at distance to closest seed/corner + VectorXd minD = D[i].rowwise().minCoeff(); + assert(minD.size() == (int)sample_faces[i].size()); + // find random sample with maximum minimum distance to other seeds + int old_cur_maxmin = cur_maxmin[i]; + double max_min = -2; + for(int s = 0;s<(int)sample_faces[i].size();s++) + { + if(max_min < minD(s)) + { + max_min = minD(s); + // Set this as the new seed location + cur_maxmin[i] = s; + } + } +#ifdef EXTREME_VERBOSE + verbose("max_min: %g\n",max_min); + verbose("cur_maxmin[%d]: %d->%d\n",i,old_cur_maxmin,cur_maxmin[i]); +#endif + // did location change? + has_changed |= (old_cur_maxmin!=cur_maxmin[i]); + // update distances of random samples of other seeds + } + // if no seed moved, exit + if(!has_changed) + { + break; + } + iters++; + if(iters>=max_iters) + { + verbose("Hit max iters (%d) before converging\n",iters); + } + } + // shrink radius + //radius *= 0.9; + //radius *= 0.99; + radius *= 0.9; + } + // Collect weight space locations + WS.resize(k,W.cols()); + for(int i = 0;i ignore; + partition(W,k+W.cols(),G,S,ignore); + // Remove corners, which better be at top + S = S.segment(W.cols(),k).eval(); + + MatrixXd WS; + slice(W,S,colon(0,W.cols()-1),WS); + //cout<<"WSpartition=["< +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNIFORMLY_SAMPLE_TWO_MANIFOLD_H +#define IGL_UNIFORMLY_SAMPLE_TWO_MANIFOLD_H +#include "igl_inline.h" +#include +namespace igl +{ + // UNIFORMLY_SAMPLE_TWO_MANIFOLD Attempt to sample a mesh uniformly with + // k-points by furthest point relaxation as described in "Fast Automatic + // Skinning Transformations" [Jacobson et al. 12] Section 3.3. The input is + // not expected to be a typical 3D triangle mesh (e.g., [V,F]), instead each + // vertex is embedded in a high dimensional unit-hypercude ("weight space") + // defined by W, with triangles given by F. This algorithm will first conduct + // furthest point sampling from the set of vertices and then attempt to relax + // the sampled points along the surface of the high-dimensional triangle mesh + // (i.e., the output points may be in the middle of triangles, not just at + // vertices). An additional "push" factor will repel samples away from the + // corners of the hypercube. + // + // Inputs: + // W #W by dim positions of mesh in weight space + // F #F by 3 indices of triangles + // k number of samples + // push factor by which corners should be pushed away + // Outputs + // WS k by dim locations in weight space + // + // See also: + // random_points_on_mesh + // + IGL_INLINE void uniformly_sample_two_manifold( + const Eigen::MatrixXd & W, + const Eigen::MatrixXi & F, + const int k, + const double push, + Eigen::MatrixXd & WS); + // Find uniform sampling up to placing samples on mesh vertices + IGL_INLINE void uniformly_sample_two_manifold_at_vertices( + const Eigen::MatrixXd & OW, + const int k, + const double push, + Eigen::VectorXi & S); +} +#ifndef IGL_STATIC_LIBRARY +# include "uniformly_sample_two_manifold.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/unique.cpp b/vendor/libigl/include/igl/unique.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5420e44aa2aa8fc1a4d2ab8b07a3f30c2e8d72eb --- /dev/null +++ b/vendor/libigl/include/igl/unique.cpp @@ -0,0 +1,223 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unique.h" +#include "sort.h" +#include "IndexComparison.h" +#include "SortableRow.h" +#include "sortrows.h" +#include "list_to_matrix.h" +#include "matrix_to_list.h" + +#include +#include +#include + +template +IGL_INLINE void igl::unique( + const std::vector & A, + std::vector & C, + std::vector & IA, + std::vector & IC) +{ + using namespace std; + std::vector IM; + std::vector sortA; + igl::sort(A,true,sortA,IM); + // Original unsorted index map + IA.resize(sortA.size()); + for(int i=0;i<(int)sortA.size();i++) + { + IA[i] = i; + } + IA.erase( + std::unique( + IA.begin(), + IA.end(), + igl::IndexEquals& >(sortA)),IA.end()); + + IC.resize(A.size()); + { + int j = 0; + for(int i = 0;i<(int)sortA.size();i++) + { + if(sortA[IA[j]] != sortA[i]) + { + j++; + } + IC[IM[i]] = j; + } + } + C.resize(IA.size()); + // Reindex IA according to IM + for(int i = 0;i<(int)IA.size();i++) + { + IA[i] = IM[IA[i]]; + C[i] = A[IA[i]]; + } + +} + +template +IGL_INLINE void igl::unique( + const std::vector & A, + std::vector & C) +{ + std::vector IA,IC; + return igl::unique(A,C,IA,IC); +} + +template < + typename DerivedA, + typename DerivedC, + typename DerivedIA, + typename DerivedIC> +IGL_INLINE void igl::unique( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & IA, + Eigen::PlainObjectBase & IC) +{ + using namespace std; + using namespace Eigen; + vector vA; + vector vC; + vector vIA,vIC; + matrix_to_list(A,vA); + unique(vA,vC,vIA,vIC); + list_to_matrix(vC,C); + list_to_matrix(vIA,IA); + list_to_matrix(vIC,IC); +} + +template < + typename DerivedA, + typename DerivedC + > +IGL_INLINE void igl::unique( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & C) +{ + using namespace std; + using namespace Eigen; + vector vA; + vector vC; + vector vIA,vIC; + matrix_to_list(A,vA); + unique(vA,vC,vIA,vIC); + list_to_matrix(vC,C); +} + +// Obsolete slow version converting to vectors +// template +// IGL_INLINE void igl::unique_rows( +// const Eigen::PlainObjectBase& A, +// Eigen::PlainObjectBase& C, +// Eigen::PlainObjectBase& IA, +// Eigen::PlainObjectBase& IC) +// { +// using namespace std; +// +// typedef Eigen::Matrix RowVector; +// vector > rows; +// rows.resize(A.rows()); +// // Loop over rows +// for(int i = 0;i(ri); +// } +// vector > vC; +// +// // unique on rows +// vector vIA; +// vector vIC; +// unique(rows,vC,vIA,vIC); +// +// // Convert to eigen +// C.resize(vC.size(),A.cols()); +// IA.resize(vIA.size(),1); +// IC.resize(vIC.size(),1); +// for(int i = 0;i +// IGL_INLINE void igl::unique_rows_many( +// const Eigen::PlainObjectBase& A, +// Eigen::PlainObjectBase& C, +// Eigen::PlainObjectBase& IA, +// Eigen::PlainObjectBase& IC) +// { +// using namespace std; +// // frequency map +// typedef Eigen::Matrix RowVector; +// IC.resize(A.rows(),1); +// map, int> fm; +// const int m = A.rows(); +// for(int i = 0;i(ri)) == 0) +// { +// fm[SortableRow(ri)] = i; +// } +// IC(i) = fm[SortableRow(ri)]; +// } +// IA.resize(fm.size(),1); +// Eigen::VectorXi RIA(m); +// C.resize(fm.size(),A.cols()); +// { +// int i = 0; +// for(typename map , int >::const_iterator fit = fm.begin(); +// fit != fm.end(); +// fit++) +// { +// IA(i) = fit->second; +// RIA(fit->second) = i; +// C.row(i) = fit->first.data; +// i++; +// } +// } +// // IC should index C +// for(int i = 0;i, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique(std::vector > const&, std::vector >&); +template void igl::unique(std::vector > const&, std::vector >&); +template void igl::unique(std::vector > const&, std::vector >&, std::vector >&, std::vector >&); +template void igl::unique(std::vector > const&, std::vector >&, std::vector >&, std::vector >&); +#ifdef WIN32 +template void igl::unique,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::MatrixBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +template void igl::unique<__int64>(class std::vector<__int64,class std::allocator<__int64> > const &,class std::vector<__int64,class std::allocator<__int64> > &,class std::vector > &,class std::vector > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/unique.h b/vendor/libigl/include/igl/unique.h new file mode 100644 index 0000000000000000000000000000000000000000..0e5061d46d32abf5041590bf92e69dc8c3f6a6d2 --- /dev/null +++ b/vendor/libigl/include/igl/unique.h @@ -0,0 +1,58 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNIQUE_H +#define IGL_UNIQUE_H +#include "igl_inline.h" + +#include +#include +namespace igl +{ + // Act like matlab's [C,IA,IC] = unique(X) + // + // Templates: + // T comparable type T + // Inputs: + // A #A vector of type T + // Outputs: + // C #C vector of unique entries in A + // IA #C index vector so that C = A(IA); + // IC #A index vector so that A = C(IC); + template + IGL_INLINE void unique( + const std::vector & A, + std::vector & C, + std::vector & IA, + std::vector & IC); + template + IGL_INLINE void unique( + const std::vector & A, + std::vector & C); + template < + typename DerivedA, + typename DerivedC, + typename DerivedIA, + typename DerivedIC> + IGL_INLINE void unique( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & IA, + Eigen::PlainObjectBase & IC); + template < + typename DerivedA, + typename DerivedC> + IGL_INLINE void unique( + const Eigen::MatrixBase & A, + Eigen::PlainObjectBase & C); +} + +#ifndef IGL_STATIC_LIBRARY +# include "unique.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/unique_edge_map.cpp b/vendor/libigl/include/igl/unique_edge_map.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87e06e7ce79a35e70dbfaf068b20c6a0667d73e5 --- /dev/null +++ b/vendor/libigl/include/igl/unique_edge_map.cpp @@ -0,0 +1,145 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unique_edge_map.h" +#include "oriented_facets.h" +#include "unique_simplices.h" +#include "cumsum.h" +#include "accumarray.h" +#include +#include + +template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType> +IGL_INLINE void igl::unique_edge_map( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E) +{ + using namespace Eigen; + using namespace std; + unique_edge_map(F,E,uE,EMAP); + uE2E.resize(uE.rows()); + // This does help a little + for_each(uE2E.begin(),uE2E.end(),[](vector & v){v.reserve(2);}); + const size_t ne = E.rows(); + assert((size_t)EMAP.size() == ne); + for(uE2EType e = 0;e<(uE2EType)ne;e++) + { + uE2E[EMAP(e)].push_back(e); + } +} + +template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP> +IGL_INLINE void igl::unique_edge_map( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP) +{ + using namespace Eigen; + using namespace std; + // All occurrences of directed edges + oriented_facets(F,E); + const size_t ne = E.rows(); + // This is 2x faster to create than a map from pairs to lists of edges and 5x + // faster to access (actually access is probably assympotically faster O(1) + // vs. O(log m) + Matrix IA; + unique_simplices(E,uE,IA,EMAP); + assert((size_t)EMAP.size() == ne); +} + +template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename DeriveduEC, + typename DeriveduEE> +IGL_INLINE void igl::unique_edge_map( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + Eigen::PlainObjectBase & uEC, + Eigen::PlainObjectBase & uEE) +{ + // Avoid using uE2E + igl::unique_edge_map(F,E,uE,EMAP); + assert(EMAP.maxCoeff() < uE.rows()); + // counts of each unique edge + typedef Eigen::Matrix VectorXI; + VectorXI uEK; + igl::accumarray(EMAP,1,uEK); + assert(uEK.rows() == uE.rows()); + // base offset in uEE + igl::cumsum(uEK,1,true,uEC); + assert(uEK.rows()+1 == uEC.rows()); + // running inner offset in uEE + VectorXI uEO = VectorXI::Zero(uE.rows(),1); + // flat array of faces incide on each uE + uEE.resize(EMAP.rows(),1); + for(Eigen::Index e = 0;e, class Eigen::Matrix, class Eigen::Matrix, class Eigen::Matrix, unsigned __int64>(class Eigen::MatrixBase > const&, class Eigen::PlainObjectBase >&, class Eigen::PlainObjectBase >&, class Eigen::PlainObjectBase >&, class std::vector >, class std::allocator > > >&); +#endif +// generated by autoexplicit.sh +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, unsigned long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +// generated by autoexplicit.sh +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, unsigned long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, unsigned long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, unsigned long>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); +template void igl::unique_edge_map, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, std::vector >, std::allocator > > >&); + +#ifdef WIN32 +template void igl::unique_edge_map, class Eigen::Matrix, class Eigen::Matrix, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1>, __int64>(class Eigen::MatrixBase > const &, class Eigen::PlainObjectBase > &, class Eigen::PlainObjectBase > &, class Eigen::PlainObjectBase > &, class std::vector >, class std::allocator > > > &); +template void igl::unique_edge_map,class Eigen::Matrix,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1>,__int64>(class Eigen::MatrixBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class std::vector >,class std::allocator > > > &); +template void igl::unique_edge_map, class Eigen::Matrix, class Eigen::Matrix, class Eigen::Matrix, unsigned __int64>(class Eigen::MatrixBase> const &, class Eigen::PlainObjectBase> &, class Eigen::PlainObjectBase> &, class Eigen::PlainObjectBase> &, class std::vector>, class std::allocator>>> &); +template void igl::unique_edge_map, class Eigen::Matrix, class Eigen::Matrix, class Eigen::Matrix, unsigned __int64>(class Eigen::MatrixBase> const &, class Eigen::PlainObjectBase> &, class Eigen::PlainObjectBase> &, class Eigen::PlainObjectBase> &, class std::vector>, class std::allocator>>> &); +template void igl::unique_edge_map,class Eigen::Matrix,class Eigen::Matrix,class Eigen::Matrix,unsigned __int64>(class Eigen::MatrixBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class std::vector >,class std::allocator > > > &); +#endif + +#endif diff --git a/vendor/libigl/include/igl/unique_edge_map.h b/vendor/libigl/include/igl/unique_edge_map.h new file mode 100644 index 0000000000000000000000000000000000000000..348bccfdaab579ddf7b8160b175c792de8b34f11 --- /dev/null +++ b/vendor/libigl/include/igl/unique_edge_map.h @@ -0,0 +1,79 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNIQUE_EDGE_MAP_H +#define IGL_UNIQUE_EDGE_MAP_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Construct relationships between facet "half"-(or rather "viewed")-edges E + // to unique edges of the mesh seen as a graph. + // + // Inputs: + // F #F by 3 list of simplices + // Outputs: + // E #F*3 by 2 list of all directed edges, such that E.row(f+#F*c) is the + // edge opposite F(f,c) + // uE #uE by 2 list of unique undirected edges + // EMAP #F*3 list of indices into uE, mapping each directed edge to unique + // undirected edge so that uE(EMAP(f+#F*c)) is the unique edge + // corresponding to E.row(f+#F*c) + // uE2E #uE list of lists of indices into E of coexisting edges, so that + // E.row(uE2E[i][j]) corresponds to uE.row(i) for all j in + // 0..uE2E[i].size()-1. + template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename uE2EType> + IGL_INLINE void unique_edge_map( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + std::vector > & uE2E); + template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP> + IGL_INLINE void unique_edge_map( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP); + // Outputs: + // uEC #uEC+1 list of cumulative counts of directed edges sharing each + // unique edge so the uEC(i+1)-uEC(i) is the number of directed edges + // sharing the ith unique edge. + // uEE #E list of indices into E, so that the consecutive segment of + // indices uEE.segment(uEC(i),uEC(i+1)-uEC(i)) lists all directed edges + // sharing the ith unique edge. + template < + typename DerivedF, + typename DerivedE, + typename DeriveduE, + typename DerivedEMAP, + typename DeriveduEC, + typename DeriveduEE> + IGL_INLINE void unique_edge_map( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & E, + Eigen::PlainObjectBase & uE, + Eigen::PlainObjectBase & EMAP, + Eigen::PlainObjectBase & uEC, + Eigen::PlainObjectBase & uEE); + +} +#ifndef IGL_STATIC_LIBRARY +# include "unique_edge_map.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/unique_rows.cpp b/vendor/libigl/include/igl/unique_rows.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5289bbca6135d0c88cf49ea3da637e156a82fd67 --- /dev/null +++ b/vendor/libigl/include/igl/unique_rows.cpp @@ -0,0 +1,126 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unique_rows.h" +#include "sortrows.h" + +#include +#include +#include + + +template +IGL_INLINE void igl::unique_rows( + const Eigen::DenseBase& A, + Eigen::PlainObjectBase& C, + Eigen::PlainObjectBase& IA, + Eigen::PlainObjectBase& IC) +{ + using namespace std; + using namespace Eigen; + VectorXi IM; + DerivedA sortA; + sortrows(A,true,sortA,IM); + + + const int num_rows = sortA.rows(); + const int num_cols = sortA.cols(); + vector vIA(num_rows); + for(int i=0;i, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::DenseBase > const&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&,Eigen::PlainObjectBase >&); +template void igl::unique_rows, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::DenseBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template void igl::unique_rows, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1>, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1> >(class Eigen::DenseBase > const &, class Eigen::PlainObjectBase > &, class Eigen::PlainObjectBase > &, class Eigen::PlainObjectBase > &); +template void igl::unique_rows,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::DenseBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +template void igl::unique_rows,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::DenseBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +template void igl::unique_rows,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::DenseBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +template void igl::unique_rows,class Eigen::Matrix,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::DenseBase > const &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/unique_rows.h b/vendor/libigl/include/igl/unique_rows.h new file mode 100644 index 0000000000000000000000000000000000000000..c612c8b1db561e513e5e0d9fdf2f4bc033dab829 --- /dev/null +++ b/vendor/libigl/include/igl/unique_rows.h @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2017 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNIQUE_ROWS_H +#define IGL_UNIQUE_ROWS_H +#include "igl_inline.h" + +#include +#include +namespace igl +{ + // Act like matlab's [C,IA,IC] = unique(X,'rows') + // + // Templates: + // DerivedA derived scalar type, e.g. MatrixXi or MatrixXd + // DerivedIA derived integer type, e.g. MatrixXi + // DerivedIC derived integer type, e.g. MatrixXi + // Inputs: + // A m by n matrix whose entries are to unique'd according to rows + // Outputs: + // C #C vector of unique rows in A + // IA #C index vector so that C = A(IA,:); + // IC #A index vector so that A = C(IC,:); + template + IGL_INLINE void unique_rows( + const Eigen::DenseBase& A, + Eigen::PlainObjectBase& C, + Eigen::PlainObjectBase& IA, + Eigen::PlainObjectBase& IC); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "unique_rows.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/unique_simplices.cpp b/vendor/libigl/include/igl/unique_simplices.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f20ff22720320a02fd0016bfab97b2a7add3c63 --- /dev/null +++ b/vendor/libigl/include/igl/unique_simplices.cpp @@ -0,0 +1,76 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unique_simplices.h" +#include "sort.h" +#include "unique_rows.h" +#include "parallel_for.h" + +template < + typename DerivedF, + typename DerivedFF, + typename DerivedIA, + typename DerivedIC> +IGL_INLINE void igl::unique_simplices( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& FF, + Eigen::PlainObjectBase& IA, + Eigen::PlainObjectBase& IC) +{ + using namespace Eigen; + using namespace std; + typedef Eigen::Matrix + MatrixXI; + // Sort each face + MatrixXI sortF, unusedI; + igl::sort(F,2,true,sortF,unusedI); + // Find unique faces + MatrixXI C; + igl::unique_rows(sortF,C,IA,IC); + FF.resize(IA.size(),F.cols()); + const size_t mff = FF.rows(); + parallel_for(mff,[&F,&IA,&FF](size_t & i) + { + FF.row(i) = F.row(IA(i)).template cast(); + },1000ul); +} + +template < + typename DerivedF, + typename DerivedFF> +IGL_INLINE void igl::unique_simplices( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& FF) +{ + Eigen::VectorXi IA,IC; + return unique_simplices(F,FF,IA,IC); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::unique_simplices, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#ifdef WIN32 +template void igl::unique_simplices, class Eigen::Matrix, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1>, class Eigen::Matrix<__int64, -1, 1, 0, -1, 1> >(class Eigen::MatrixBase > const &, class Eigen::PlainObjectBase > &, class Eigen::PlainObjectBase > &, class Eigen::PlainObjectBase > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/unique_simplices.h b/vendor/libigl/include/igl/unique_simplices.h new file mode 100644 index 0000000000000000000000000000000000000000..a7c13849ef3348db55e74b47705780671da769bd --- /dev/null +++ b/vendor/libigl/include/igl/unique_simplices.h @@ -0,0 +1,44 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNIQUE_SIMPLICES_H +#define IGL_UNIQUE_SIMPLICES_H +#include "igl_inline.h" +#include +namespace igl +{ + // Find *combinatorially* unique simplices in F. **Order independent** + // + // Inputs: + // F #F by simplex-size list of simplices + // Outputs: + // FF #FF by simplex-size list of unique simplices in F + // IA #FF index vector so that FF == sort(F(IA,:),2); + // IC #F index vector so that sort(F,2) == FF(IC,:); + template < + typename DerivedF, + typename DerivedFF, + typename DerivedIA, + typename DerivedIC> + IGL_INLINE void unique_simplices( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& FF, + Eigen::PlainObjectBase& IA, + Eigen::PlainObjectBase& IC); + template < + typename DerivedF, + typename DerivedFF> + IGL_INLINE void unique_simplices( + const Eigen::MatrixBase& F, + Eigen::PlainObjectBase& FF); +} + +#ifndef IGL_STATIC_LIBRARY +# include "unique_simplices.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/unproject.cpp b/vendor/libigl/include/igl/unproject.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3487cb6974700224e7c2cff50636a148e252225e --- /dev/null +++ b/vendor/libigl/include/igl/unproject.cpp @@ -0,0 +1,76 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unproject.h" + +#include +#include + +template < + typename Derivedwin, + typename Derivedmodel, + typename Derivedproj, + typename Derivedviewport, + typename Derivedscene> +IGL_INLINE void igl::unproject( + const Eigen::MatrixBase& win, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + Eigen::PlainObjectBase & scene) +{ + if(win.cols() != 3) + { + assert(win.rows() == 3); + // needless transposes + Eigen::Matrix sceneT; + unproject(win.transpose().eval(),model,proj,viewport,sceneT); + scene = sceneT.head(3); + return; + } + assert(win.cols() == 3); + const int n = win.rows(); + scene.resize(n,3); + for(int i = 0;i Inverse = + (proj.template cast() * model.template cast()).inverse(); + + Eigen::Matrix tmp; + tmp << win.row(i).head(3).transpose(), 1; + tmp(0) = (tmp(0) - viewport(0, 0)) / viewport(2, 0); + tmp(1) = (tmp(1) - viewport(1, 0)) / viewport(3, 0); + tmp = tmp.array() * 2.0f - 1.0f; + + Eigen::Matrix obj = Inverse * tmp; + obj /= obj(3); + + scene.row(i).head(3) = obj.head(3); + } +} + +template +IGL_INLINE Eigen::Matrix igl::unproject( + const Eigen::Matrix& win, + const Eigen::Matrix& model, + const Eigen::Matrix& proj, + const Eigen::Matrix& viewport) +{ + Eigen::Matrix scene; + unproject(win,model,proj,viewport,scene); + return scene; +} + +#ifdef IGL_STATIC_LIBRARY +template Eigen::Matrix igl::unproject(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); +template Eigen::Matrix igl::unproject(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); +template void igl::unproject, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unproject, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unproject, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +template void igl::unproject, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/unproject.h b/vendor/libigl/include/igl/unproject.h new file mode 100644 index 0000000000000000000000000000000000000000..72b4808cfd36fa60dbf0cb1f8bee941e2127967e --- /dev/null +++ b/vendor/libigl/include/igl/unproject.h @@ -0,0 +1,51 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNPROJECT_H +#define IGL_UNPROJECT_H +#include "igl_inline.h" +#include +namespace igl +{ + // Eigen reimplementation of gluUnproject + // + // Inputs: + // win #P by 3 or 3-vector (#P=1) of screen space x, y, and z coordinates + // model 4x4 model-view matrix + // proj 4x4 projection matrix + // viewport 4-long viewport vector + // Outputs: + // scene #P by 3 or 3-vector (#P=1) the unprojected x, y, and z coordinates + // + // Known issue: + // The compiler will not complain if V and P are Vector3d, but the result + // will be incorrect. + template < + typename Derivedwin, + typename Derivedmodel, + typename Derivedproj, + typename Derivedviewport, + typename Derivedscene> + IGL_INLINE void unproject( + const Eigen::MatrixBase& win, + const Eigen::MatrixBase& model, + const Eigen::MatrixBase& proj, + const Eigen::MatrixBase& viewport, + Eigen::PlainObjectBase & scene); + template + IGL_INLINE Eigen::Matrix unproject( + const Eigen::Matrix& win, + const Eigen::Matrix& model, + const Eigen::Matrix& proj, + const Eigen::Matrix& viewport); +} + +#ifndef IGL_STATIC_LIBRARY +# include "unproject.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/unproject_in_mesh.h b/vendor/libigl/include/igl/unproject_in_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..02c392004f104bca6b22a590265c8ba2cb8a4321 --- /dev/null +++ b/vendor/libigl/include/igl/unproject_in_mesh.h @@ -0,0 +1,88 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNPROJECT_IN_MESH +#define IGL_UNPROJECT_IN_MESH +#include "igl_inline.h" +#include + +#include +#include "Hit.h" + +namespace igl +{ + // Unproject a screen location (using current opengl viewport, projection, and + // model view) to a 3D position _inside_ a given mesh. If the ray through the + // given screen location (x,y) _hits_ the mesh more than twice then the 3D + // midpoint between the first two hits is return. If it hits once, then that + // point is return. If it does not hit the mesh then obj is not set. + // + // Inputs: + // pos screen space coordinates + // model model matrix + // proj projection matrix + // viewport vieweport vector + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh triangle indices into V + // Outputs: + // obj 3d unprojected mouse point in mesh + // hits vector of hits + // Returns number of hits + // + template < typename DerivedV, typename DerivedF, typename Derivedobj> + IGL_INLINE int unproject_in_mesh( + const Eigen::Vector2f& pos, + const Eigen::Matrix4f& model, + const Eigen::Matrix4f& proj, + const Eigen::Vector4f& viewport, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & obj, + std::vector & hits); + // + // Inputs: + // pos screen space coordinates + // model model matrix + // proj projection matrix + // viewport vieweport vector + // shoot_ray function handle that outputs first hit of a given ray + // against a mesh (embedded in function handles as captured + // variable/data) + // Outputs: + // obj 3d unprojected mouse point in mesh + // hits vector of hits + // Returns number of hits + // + template < typename Derivedobj> + IGL_INLINE int unproject_in_mesh( + const Eigen::Vector2f& pos, + const Eigen::Matrix4f& model, + const Eigen::Matrix4f& proj, + const Eigen::Vector4f& viewport, + const std::function< + void( + const Eigen::Vector3f&, + const Eigen::Vector3f&, + std::vector &) + > & shoot_ray, + Eigen::PlainObjectBase & obj, + std::vector & hits); + template < typename DerivedV, typename DerivedF, typename Derivedobj> + IGL_INLINE int unproject_in_mesh( + const Eigen::Vector2f& pos, + const Eigen::Matrix4f& model, + const Eigen::Matrix4f& proj, + const Eigen::Vector4f& viewport, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & obj); +} +#ifndef IGL_STATIC_LIBRARY +# include "unproject_in_mesh.cpp" +#endif +#endif + diff --git a/vendor/libigl/include/igl/unproject_on_line.h b/vendor/libigl/include/igl/unproject_on_line.h new file mode 100644 index 0000000000000000000000000000000000000000..9dbb39eb039a218c3f87aaf5f5271b05ff8d93e7 --- /dev/null +++ b/vendor/libigl/include/igl/unproject_on_line.h @@ -0,0 +1,56 @@ +#ifndef IGL_UNPROJECT_ON_LINE_H +#define IGL_UNPROJECT_ON_LINE_H + +#include + +namespace igl +{ + // Given a screen space point (u,v) and the current projection matrix (e.g. + // gl_proj * gl_modelview) and viewport, _unproject_ the point into the scene + // so that it lies on given line (origin and dir) and projects as closely as + // possible to the given screen space point. + // + // Inputs: + // UV 2-long uv-coordinates of screen space point + // M 4 by 4 projection matrix + // VP 4-long viewport: (corner_u, corner_v, width, height) + // origin point on line + // dir vector parallel to line + // Output: + // t line parameter so that closest poin on line to viewer ray through UV + // lies at origin+t*dir + template < + typename DerivedUV, + typename DerivedM, + typename DerivedVP, + typename Derivedorigin, + typename Deriveddir> + void unproject_on_line( + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & M, + const Eigen::MatrixBase & VP, + const Eigen::MatrixBase & origin, + const Eigen::MatrixBase & dir, + typename DerivedUV::Scalar & t); + // Z 3d position of closest point on line to viewing ray through UV + template < + typename DerivedUV, + typename DerivedM, + typename DerivedVP, + typename Derivedorigin, + typename Deriveddir, + typename DerivedZ> + void unproject_on_line( + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & M, + const Eigen::MatrixBase & VP, + const Eigen::MatrixBase & origin, + const Eigen::MatrixBase & dir, + Eigen::PlainObjectBase & Z); +} + +#ifndef IGL_STATIC_LIBRARY +# include "unproject_on_line.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/unproject_onto_mesh.h b/vendor/libigl/include/igl/unproject_onto_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..1912c2c63728cdae9caa032623fae1225fa59da9 --- /dev/null +++ b/vendor/libigl/include/igl/unproject_onto_mesh.h @@ -0,0 +1,80 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNPROJECT_ONTO_MESH +#define IGL_UNPROJECT_ONTO_MESH +#include "igl_inline.h" +#include "Hit.h" +#include +#include + +namespace igl +{ + // Unproject a screen location (using current opengl viewport, projection, and + // model view) to a 3D position _onto_ a given mesh, if the ray through the + // given screen location (x,y) _hits_ the mesh. + // + // Inputs: + // pos screen space coordinates + // model model matrix + // proj projection matrix + // viewport vieweport vector + // V #V by 3 list of mesh vertex positions + // F #F by 3 list of mesh triangle indices into V + // Outputs: + // fid id of the first face hit + // bc barycentric coordinates of hit + // Returns true if there's a hit + // + // Example: + // igl::opengl::glfw::Viewer vr; + // ... + // igl::unproject_onto_mesh( + // pos,vr.core().view,vr.core().proj,vr.core().viewport,V,F,fid,bc); + template < typename DerivedV, typename DerivedF, typename Derivedbc> + IGL_INLINE bool unproject_onto_mesh( + const Eigen::Vector2f& pos, + const Eigen::Matrix4f& model, + const Eigen::Matrix4f& proj, + const Eigen::Vector4f& viewport, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + int & fid, + Eigen::PlainObjectBase & bc); + // + // Inputs: + // pos screen space coordinates + // model model matrix + // proj projection matrix + // viewport viewport vector + // shoot_ray function handle that outputs hits of a given ray against a + // mesh (embedded in function handles as captured variable/data) + // Outputs: + // fid id of the first face hit + // bc barycentric coordinates of hit + // Returns true if there's a hit + template + IGL_INLINE bool unproject_onto_mesh( + const Eigen::Vector2f& pos, + const Eigen::Matrix4f& model, + const Eigen::Matrix4f& proj, + const Eigen::Vector4f& viewport, + const std::function< + bool( + const Eigen::Vector3f&, + const Eigen::Vector3f&, + igl::Hit &) + > & shoot_ray, + int & fid, + Eigen::PlainObjectBase & bc); +} +#ifndef IGL_STATIC_LIBRARY +# include "unproject_onto_mesh.cpp" +#endif +#endif + + diff --git a/vendor/libigl/include/igl/unproject_ray.cpp b/vendor/libigl/include/igl/unproject_ray.cpp new file mode 100644 index 0000000000000000000000000000000000000000..07bc84f6efd45e6efc10340082908ff0cbd26e4c --- /dev/null +++ b/vendor/libigl/include/igl/unproject_ray.cpp @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unproject_ray.h" +#include "unproject.h" + +template < + typename Derivedpos, + typename Derivedmodel, + typename Derivedproj, + typename Derivedviewport, + typename Deriveds, + typename Deriveddir> +IGL_INLINE void igl::unproject_ray( + const Eigen::MatrixBase & pos, + const Eigen::MatrixBase & model, + const Eigen::MatrixBase & proj, + const Eigen::MatrixBase & viewport, + Eigen::PlainObjectBase & s, + Eigen::PlainObjectBase & dir) +{ + using namespace std; + using namespace Eigen; + // Source and direction on screen + typedef Eigen::Matrix Vec3; + Vec3 win_s(pos(0, 0),pos(1, 0),0); + Vec3 win_d(pos(0, 0),pos(1, 0),1); + // Source, destination and direction in world + Vec3 d; + igl::unproject(win_s,model,proj,viewport,s); + igl::unproject(win_d,model,proj,viewport,d); + dir = d-s; +} + +#ifdef IGL_STATIC_LIBRARY +template void igl::unproject_ray, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +#endif diff --git a/vendor/libigl/include/igl/unzip_corners.cpp b/vendor/libigl/include/igl/unzip_corners.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a2ed004c8a03239e5fa0fe8eb99a0d53568cf1d --- /dev/null +++ b/vendor/libigl/include/igl/unzip_corners.cpp @@ -0,0 +1,48 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "unzip_corners.h" + +#include "unique_rows.h" +#include "slice.h" + +template < typename DerivedA, typename DerivedU, typename DerivedG, typename DerivedJ > +IGL_INLINE void igl::unzip_corners( + const std::vector > & A, + Eigen::PlainObjectBase & U, + Eigen::PlainObjectBase & G, + Eigen::PlainObjectBase & J) +{ + if(A.size() == 0) + { + U.resize(0,0); + G.resize(0,3); + J.resize(0,0); + return; + } + const size_t num_a = A.size(); + const typename DerivedA::Index m = A[0].get().rows(); + DerivedU C(m*3,num_a); + for(int a = 0;a +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_UNZIP_CORNERS_H +#define IGL_UNZIP_CORNERS_H +#include "igl_inline.h" +#include +#include +#include + +namespace igl +{ + // UNZIP_CORNERS Given a triangle mesh where corners of each triangle index + // different matrices of attributes (e.g. read from an OBJ file), unzip the + // corners into unique efficiently: attributes become properly vertex valued + // (usually creating greater than #V but less than #F*3 vertices). + // + // To pass a list of attributes this function takes an std::vector of + // std::reference_wrapper of an Eigen::... type. This allows you to use list + // initializers **without** incurring a copy, but means you'll need to + // provide the derived type of A as an explicit template parameter: + // + // unzip_corners({F,FTC,FN},U,G,J); + // + // Inputs: + // A #A list of #F by 3 attribute indices, typically {F,FTC,FN} + // Outputs: + // U #U by #A list of indices into each attribute for each unique mesh + // vertex: U(v,a) is the attribute index of vertex v in attribute a. + // G #F by 3 list of triangle indices into U + // J #F*3 by 1 list of indices so that A[](i,j) = U.row(i+j*#F) + // Example: + // [V,F,TC,FTC] = readOBJ('~/Downloads/kiwis/kiwi.obj'); + // [U,G] = unzip_corners(cat(3,F,FTC)); + // % display mesh + // tsurf(G,V(U(:,1),:)); + // % display texture coordinates + // tsurf(G,TC(U(:,2),:)); + // + template < typename DerivedA, typename DerivedU, typename DerivedG, typename DerivedJ> + IGL_INLINE void unzip_corners( + const std::vector > & A, + Eigen::PlainObjectBase & U, + Eigen::PlainObjectBase & G, + Eigen::PlainObjectBase & J); +} + +#ifndef IGL_STATIC_LIBRARY +# include "unzip_corners.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/vector_area_matrix.h b/vendor/libigl/include/igl/vector_area_matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..4a42ea5af08ff1cabec19fb6279b44566cc31f77 --- /dev/null +++ b/vendor/libigl/include/igl/vector_area_matrix.h @@ -0,0 +1,41 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_VECTOR_AREA_MATRIX_H +#define IGL_VECTOR_AREA_MATRIX_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // Constructs the symmetric area matrix A, s.t. [V.col(0)' V.col(1)'] * A * + // [V.col(0); V.col(1)] is the **vector area** of the mesh (V,F). + // + // Templates: + // DerivedV derived type of eigen matrix for V (e.g. derived from + // MatrixXd) + // DerivedF derived type of eigen matrix for F (e.g. derived from + // MatrixXi) + // Scalar scalar type for eigen sparse matrix (e.g. double) + // Inputs: + // F #F by 3 list of mesh faces (must be triangles) + // Outputs: + // A #Vx2 by #Vx2 area matrix + // + template + IGL_INLINE void vector_area_matrix( + const Eigen::MatrixBase & F, + Eigen::SparseMatrix& A); +} + +#ifndef IGL_STATIC_LIBRARY +# include "vector_area_matrix.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/verbose.h b/vendor/libigl/include/igl/verbose.h new file mode 100644 index 0000000000000000000000000000000000000000..e4aa8695801f8173e120f8d2af6b6a86bebd0041 --- /dev/null +++ b/vendor/libigl/include/igl/verbose.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_VERBOSE_H +#define IGL_VERBOSE_H + +// This function is only useful as a header-only inlined function + +namespace igl +{ + // Provide a wrapper for printf, called verbose that functions exactly like + // printf if VERBOSE is defined and does exactly nothing if VERBOSE is + // undefined + inline int verbose(const char * msg,...); +} + + + +#include +#ifdef VERBOSE +# include +#endif + +#include +// http://channel9.msdn.com/forums/techoff/254707-wrapping-printf-in-c/ +#ifdef VERBOSE +inline int igl::verbose(const char * msg,...) +{ + va_list argList; + va_start(argList, msg); + int count = vprintf(msg, argList); + va_end(argList); + return count; +} +#else +inline int igl::verbose(const char * /*msg*/,...) +{ + return 0; +} +#endif + +#endif diff --git a/vendor/libigl/include/igl/vertex_components.h b/vendor/libigl/include/igl/vertex_components.h new file mode 100644 index 0000000000000000000000000000000000000000..f744fa8b45d404a541d4b890d54236ec9d3f2812 --- /dev/null +++ b/vendor/libigl/include/igl/vertex_components.h @@ -0,0 +1,59 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_COMPONENTS_H +#define IGL_COMPONENTS_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Compute connected components of a graph represented by an adjacency + // matrix. + // + // Returns a component ID per vertex of the graph where connectivity is established by edges. + // + // Inputs: + // A n by n adjacency matrix + // Outputs: + // C n list of component ids (starting with 0) + // counts #components list of counts for each component + // + template + IGL_INLINE void vertex_components( + const Eigen::SparseCompressedBase & A, + Eigen::PlainObjectBase & C, + Eigen::PlainObjectBase & counts); + + template + IGL_INLINE void vertex_components( + const Eigen::SparseCompressedBase & A, + Eigen::PlainObjectBase & C); + + // Compute the connected components for a mesh given its faces. + // Returns a component ID per vertex of the mesh where connectivity is established by edges. + // + // For computing connected components per face see igl::facet_components + // + // + // Inputs: + // F n by 3 list of triangle indices + // Outputs: + // C max(F) list of component ids + template + IGL_INLINE void vertex_components( + const Eigen::MatrixBase & F, + Eigen::PlainObjectBase & C); + +} + +#ifndef IGL_STATIC_LIBRARY +# include "vertex_components.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/vertex_triangle_adjacency.cpp b/vendor/libigl/include/igl/vertex_triangle_adjacency.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b028e9a99fcace41df9991ad167e1f9c6a17f22f --- /dev/null +++ b/vendor/libigl/include/igl/vertex_triangle_adjacency.cpp @@ -0,0 +1,107 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "vertex_triangle_adjacency.h" +#include "cumsum.h" + +template +IGL_INLINE void igl::vertex_triangle_adjacency( + const typename DerivedF::Scalar n, + const Eigen::MatrixBase& F, + std::vector >& VF, + std::vector >& VFi) +{ + VF.clear(); + VFi.clear(); + + VF.resize(n); + VFi.resize(n); + + typedef typename DerivedF::Index Index; + for(Index fi=0; fi +IGL_INLINE void igl::vertex_triangle_adjacency( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + std::vector >& VF, + std::vector >& VFi) +{ + return vertex_triangle_adjacency(V.rows(),F,VF,VFi); +} + +template < + typename DerivedF, + typename DerivedVF, + typename DerivedNI> +IGL_INLINE void igl::vertex_triangle_adjacency( + const Eigen::MatrixBase & F, + const int n, + Eigen::PlainObjectBase & VF, + Eigen::PlainObjectBase & NI) +{ + typedef Eigen::Matrix VectorXI; + // vfd #V list so that vfd(i) contains the vertex-face degree (number of + // faces incident on vertex i) + VectorXI vfd = VectorXI::Zero(n); + for (int i = 0; i < F.rows(); i++) + { + for (int j = 0; j < 3; j++) + { + vfd[F(i,j)]++; + } + } + igl::cumsum(vfd,1,NI); + // Prepend a zero + NI = (DerivedNI(n+1)<<0,NI).finished(); + // vfd now acts as a counter + vfd = NI; + + VF.derived()= Eigen::Matrix(3*F.rows(), 1); + for (int i = 0; i < F.rows(); i++) + { + for (int j = 0; j < 3; j++) + { + VF[vfd[F(i,j)]] = i; + vfd[F(i,j)]++; + } + } +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template void igl::vertex_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +// generated by autoexplicit.sh +template void igl::vertex_triangle_adjacency, unsigned long, unsigned long>(Eigen::Matrix::Scalar, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +// generated by autoexplicit.sh +template void igl::vertex_triangle_adjacency, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, Eigen::Matrix, unsigned int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, long, long>(Eigen::Matrix::Scalar, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, long, long>(Eigen::Matrix::Scalar, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, unsigned long, unsigned long>(Eigen::Matrix::Scalar, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, Eigen::Matrix, int>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +template void igl::vertex_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::vertex_triangle_adjacency, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, int, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); +template void igl::vertex_triangle_adjacency, int, int>(Eigen::Matrix::Scalar, Eigen::MatrixBase > const&, std::vector >, std::allocator > > >&, std::vector >, std::allocator > > >&); +#ifdef WIN32 +template void igl::vertex_triangle_adjacency, unsigned __int64, unsigned __int64>(int, class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>> &, class std::vector>, class std::allocator>>> &); +template void igl::vertex_triangle_adjacency, unsigned __int64, unsigned __int64>(int, class Eigen::MatrixBase> const &, class std::vector>, class std::allocator>>> &, class std::vector>, class std::allocator>>> &); +template void igl::vertex_triangle_adjacency,__int64,__int64>(int,class Eigen::MatrixBase > const &,class std::vector >,class std::allocator > > > &,class std::vector >,class std::allocator > > > &); +template void igl::vertex_triangle_adjacency,class Eigen::Matrix<__int64,-1,1,0,-1,1>,class Eigen::Matrix<__int64,-1,1,0,-1,1> >(class Eigen::MatrixBase > const &,int,class Eigen::PlainObjectBase > &,class Eigen::PlainObjectBase > &); +#endif +#endif diff --git a/vendor/libigl/include/igl/vertex_triangle_adjacency.h b/vendor/libigl/include/igl/vertex_triangle_adjacency.h new file mode 100644 index 0000000000000000000000000000000000000000..ce67b1f3dd784e7ffd9c2a11f3a151b9ef44eb51 --- /dev/null +++ b/vendor/libigl/include/igl/vertex_triangle_adjacency.h @@ -0,0 +1,71 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Daniele Panozzo +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_VERTEX_TRIANGLE_ADJACENCY_H +#define IGL_VERTEX_TRIANGLE_ADJACENCY_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + // vertex_face_adjacency constructs the vertex-face topology of a given mesh (V,F) + // + // Inputs: + // //V #V by 3 list of vertex coordinates + // n number of vertices #V (e.g. `F.maxCoeff()+1` or `V.rows()`) + // F #F by dim list of mesh faces (must be triangles) + // Outputs: + // VF #V list of lists of incident faces (adjacency list) + // VI #V list of lists of index of incidence within incident faces listed + // in VF + // + // See also: edges, cotmatrix, diag, vv + // + // Known bugs: this should not take V as an input parameter. + // Known bugs/features: if a facet is combinatorially degenerate then faces + // will appear multiple times in VF and correspondingly in VFI (j appears + // twice in F.row(i) then i will appear twice in VF[j]) + template + IGL_INLINE void vertex_triangle_adjacency( + const typename DerivedF::Scalar n, + const Eigen::MatrixBase& F, + std::vector >& VF, + std::vector >& VFi); + template + IGL_INLINE void vertex_triangle_adjacency( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + std::vector >& VF, + std::vector >& VFi); + // Inputs: + // F #F by 3 list of triangle indices into some vertex list V + // n number of vertices, #V (e.g., F.maxCoeff()+1) + // Outputs: + // VF 3*#F list List of faces indice on each vertex, so that VF(NI(i)+j) = + // f, means that face f is the jth face (in no particular order) incident + // on vertex i. + // NI #V+1 list cumulative sum of vertex-triangle degrees with a + // preceeding zero. "How many faces" have been seen before visiting this + // vertex and its incident faces. + template < + typename DerivedF, + typename DerivedVF, + typename DerivedNI> + IGL_INLINE void vertex_triangle_adjacency( + const Eigen::MatrixBase & F, + const int n, + Eigen::PlainObjectBase & VF, + Eigen::PlainObjectBase & NI); +} + +#ifndef IGL_STATIC_LIBRARY +# include "vertex_triangle_adjacency.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/volume.h b/vendor/libigl/include/igl/volume.h new file mode 100644 index 0000000000000000000000000000000000000000..960d95f41e9ee110ddb0d370498d62ccd5c57b73 --- /dev/null +++ b/vendor/libigl/include/igl/volume.h @@ -0,0 +1,74 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_VOLUME_H +#define IGL_VOLUME_H +#include "igl_inline.h" +#include +namespace igl +{ + // VOLUME Compute volume for all tets of a given tet mesh + // (V,T) + // + // vol = volume(V,T) + // + // Inputs: + // V #V by dim list of vertex positions + // T #V by 4 list of tet indices + // Outputs: + // vol #T list of tetrahedron volumes + // + template < + typename DerivedV, + typename DerivedT, + typename Derivedvol> + IGL_INLINE void volume( + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& T, + Eigen::PlainObjectBase& vol); + template < + typename DerivedA, + typename DerivedB, + typename DerivedC, + typename DerivedD, + typename Derivedvol> + IGL_INLINE void volume( + const Eigen::MatrixBase & A, + const Eigen::MatrixBase & B, + const Eigen::MatrixBase & C, + const Eigen::MatrixBase & D, + Eigen::PlainObjectBase & vol); + // Single tet + template < + typename VecA, + typename VecB, + typename VecC, + typename VecD> + IGL_INLINE typename VecA::Scalar volume_single( + const VecA & a, + const VecB & b, + const VecC & c, + const VecD & d); + // Intrinsic version: + // + // Inputs: + // L #V by 6 list of edge lengths (see edge_lengths) + template < + typename DerivedL, + typename Derivedvol> + IGL_INLINE void volume( + const Eigen::MatrixBase& L, + Eigen::PlainObjectBase& vol); +} + +#ifndef IGL_STATIC_LIBRARY +# include "volume.cpp" +#endif + +#endif + + diff --git a/vendor/libigl/include/igl/winding_number.h b/vendor/libigl/include/igl/winding_number.h new file mode 100644 index 0000000000000000000000000000000000000000..56b21e3d1768c61914da53ce7771cd488c0cce5e --- /dev/null +++ b/vendor/libigl/include/igl/winding_number.h @@ -0,0 +1,71 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WINDING_NUMBER_H +#define IGL_WINDING_NUMBER_H +#include "igl_inline.h" +#include + +// Minimum number of iterms per openmp thread +#ifndef IGL_WINDING_NUMBER_OMP_MIN_VALUE +# define IGL_WINDING_NUMBER_OMP_MIN_VALUE 1000 +#endif +namespace igl +{ + // WINDING_NUMBER Computes the generalized winding number at each + // dim-dimensional query point in O with respect to the oriented + // one-codimensional mesh (V,F). This is equivalent to summing the subtended + // signed angles/solid angles of each element in (V,F). See, "Robust + // Inside-Outside Segmentation using Generalized Winding Numbers" [Jacobson et + // al. 2013]. + // + // + // Inputs: + // V #V by dim list of mesh vertex positions + // F #F by dim list of mesh facets as indices into rows of V. If dim==2, + // then (V,F) describes a set of edges in the plane. If dim==3, then (V,F) + // describes a triangle mesh/soup. + // O #O by dim list of query points + // Output: + // W #O by 1 list of winding numbers + // + // See also: igl::fast_winding_number + // + template < + typename DerivedV, + typename DerivedF, + typename DerivedO, + typename DerivedW> + IGL_INLINE void winding_number( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & O, + Eigen::PlainObjectBase & W); + // Compute winding number of a single point + // + // Inputs: + // V n by dim list of vertex positions + // F #F by dim list of triangle indices, minimum index is 0 + // p single origin position + // Outputs: + // w winding number of this point + // + template < + typename DerivedV, + typename DerivedF, + typename Derivedp> + IGL_INLINE typename DerivedV::Scalar winding_number( + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & p); +} + +#ifndef IGL_STATIC_LIBRARY +# include "winding_number.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/writeBF.cpp b/vendor/libigl/include/igl/writeBF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18dc6a9343f749ac15d6d72851d466317155de88 --- /dev/null +++ b/vendor/libigl/include/igl/writeBF.cpp @@ -0,0 +1,49 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2016 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "writeBF.h" +#include +#include +template < + typename DerivedWI, + typename DerivedP, + typename DerivedO> +IGL_INLINE bool igl::writeBF( + const std::string & filename, + const Eigen::PlainObjectBase & WI, + const Eigen::PlainObjectBase & P, + const Eigen::PlainObjectBase & O) +{ + using namespace Eigen; + using namespace std; + const int n = WI.rows(); + assert(n == WI.rows() && "WI must have n rows"); + assert(n == P.rows() && "P must have n rows"); + assert(n == O.rows() && "O must have n rows"); + MatrixXd WIPO(n,1+1+3); + for(int i = 0;i, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&); +#endif diff --git a/vendor/libigl/include/igl/writeDMAT.cpp b/vendor/libigl/include/igl/writeDMAT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa39855f9bb47d4db1f789259352db86288e6e7f --- /dev/null +++ b/vendor/libigl/include/igl/writeDMAT.cpp @@ -0,0 +1,99 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "writeDMAT.h" +#include "list_to_matrix.h" +#include + +#include + +template +IGL_INLINE bool igl::writeDMAT( + const std::string file_name, + const Eigen::MatrixBase & W, + const bool ascii) +{ + FILE * fp = fopen(file_name.c_str(),"wb"); + if(fp == NULL) + { + fprintf(stderr,"IOError: writeDMAT() could not open %s...",file_name.c_str()); + return false; + } + if(ascii) + { + // first line contains number of rows and number of columns + fprintf(fp,"%d %d\n",(int)W.cols(),(int)W.rows()); + // Loop over columns slowly + for(int j = 0;j < W.cols();j++) + { + // loop over rows (down columns) quickly + for(int i = 0;i < W.rows();i++) + { + fprintf(fp,"%0.17lg\n",(double)W(i,j)); + } + } + }else + { + // write header for ascii + fprintf(fp,"0 0\n"); + // first line contains number of rows and number of columns + fprintf(fp,"%d %d\n",(int)W.cols(),(int)W.rows()); + // reader assumes the binary part is double precision + Eigen::MatrixXd Wd = W.template cast(); + fwrite(Wd.data(),sizeof(double),Wd.size(),fp); + //// Loop over columns slowly + //for(int j = 0;j < W.cols();j++) + //{ + // // loop over rows (down columns) quickly + // for(int i = 0;i < W.rows();i++) + // { + // double d = (double)W(i,j); + // fwrite(&d,sizeof(double),1,fp); + // } + //} + } + fclose(fp); + return true; +} + +template +IGL_INLINE bool igl::writeDMAT( + const std::string file_name, + const std::vector > & W, + const bool ascii) +{ + Eigen::Matrix mW; + list_to_matrix(W,mW); + return igl::writeDMAT(file_name,mW,ascii); +} + +template +IGL_INLINE bool igl::writeDMAT( + const std::string file_name, + const std::vector & W, + const bool ascii) +{ + Eigen::Matrix mW; + list_to_matrix(W,mW); + return igl::writeDMAT(file_name,mW,ascii); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::string, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::string, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, bool); +#endif diff --git a/vendor/libigl/include/igl/writeDMAT.h b/vendor/libigl/include/igl/writeDMAT.h new file mode 100644 index 0000000000000000000000000000000000000000..08409ef67c06851ed73cacb59dac819386eeac10 --- /dev/null +++ b/vendor/libigl/include/igl/writeDMAT.h @@ -0,0 +1,48 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WRITEDMAT_H +#define IGL_WRITEDMAT_H +#include "igl_inline.h" +// See writeDMAT.h for a description of the .dmat file type +#include +#include +#include +namespace igl +{ + // Write a matrix using ascii dmat file type + // + // Template: + // Mat matrix type that supports .rows(), .cols(), operator(i,j) + // Inputs: + // file_name path to .dmat file + // W eigen matrix containing to-be-written coefficients + // ascii write ascii file {true} + // Returns true on success, false on error + // + template + IGL_INLINE bool writeDMAT( + const std::string file_name, + const Eigen::MatrixBase & W, + const bool ascii=true); + template + IGL_INLINE bool writeDMAT( + const std::string file_name, + const std::vector > & W, + const bool ascii=true); + template + IGL_INLINE bool writeDMAT( + const std::string file_name, + const std::vector &W, + const bool ascii=true); +} + +#ifndef IGL_STATIC_LIBRARY +# include "writeDMAT.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/writeMSH.cpp b/vendor/libigl/include/igl/writeMSH.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b0decc4bd1ea968e0035c170dc5344190c658133 --- /dev/null +++ b/vendor/libigl/include/igl/writeMSH.cpp @@ -0,0 +1,149 @@ +/* high level interface for MshSaver*/ + +/* Copyright (C) 2020 Vladimir Fonov */ +/* +/* This Source Code Form is subject to the terms of the Mozilla */ +/* Public License v. 2.0. If a copy of the MPL was not distributed */ +/* with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "writeMSH.h" +#include "MshSaver.h" +#include "MshLoader.h" +#include + + +namespace igl { +namespace internal { + + // helper function, appends contents of Eigen matrix to an std::vector, in RowMajor fashion + template + void append_mat_to_vec(std::vector &vec, const Eigen::PlainObjectBase & mat) + { + size_t st = vec.size(); + vec.resize(st + mat.size()); + + Eigen::Map< Eigen::Matrix > + _map_vec( reinterpret_cast( vec.data() + st ), mat.rows(), mat.cols() ); + _map_vec = mat; + } + +} +} + +IGL_INLINE bool igl::writeMSH( + const std::string &msh, + const Eigen::MatrixXd &X, + const Eigen::MatrixXi &Tri, + const Eigen::MatrixXi &Tet, + const Eigen::MatrixXi &TriTag, + const Eigen::MatrixXi &TetTag, + const std::vector &XFields, + const std::vector &XF, + const std::vector &EFields, + const std::vector &TriF, + const std::vector &TetF + ) +{ + using namespace internal; + + try + { + // error checks + if(!XFields.empty()) + { + if(XFields.size()!=XF.size()) + throw std::invalid_argument("Vertex field count mismatch"); + for(int i=0;i _X; + append_mat_to_vec(_X, X); + + std::vector _Tri_Tet; + append_mat_to_vec( _Tri_Tet, Tri); + append_mat_to_vec( _Tri_Tet, Tet); + + std::vector _Tri_Tet_len(Tri.rows(), 3); //each is 3 elements long + _Tri_Tet_len.insert(_Tri_Tet_len.end(), Tet.rows(), 4); + + std::vector _Tri_Tet_type(Tri.rows(), MshLoader::ELEMENT_TRI); + _Tri_Tet_type.insert(_Tri_Tet_type.end(), Tet.rows(), MshLoader::ELEMENT_TET); + + std::vector _Tri_Tet_tag; + append_mat_to_vec(_Tri_Tet_tag, TriTag); + append_mat_to_vec(_Tri_Tet_tag, TetTag); + + + igl::MshSaver msh_saver(msh, true); + msh_saver.save_mesh( _X, + _Tri_Tet, + _Tri_Tet_len, + _Tri_Tet_type, + _Tri_Tet_tag); + + // append vertex data + for(size_t i=0;i _XF; + append_mat_to_vec(_XF, XF[i]); + + if(XF[i].cols() == 1) + msh_saver.save_scalar_field(XFields[i], _XF ); + else if(XF[i].cols() == 3) + msh_saver.save_vector_field(XFields[i], _XF ); + else + { + throw std::invalid_argument("unsupported vertex field dimensionality"); + } + } + + // append node data + for(size_t i=0; i _EF; + append_mat_to_vec(_EF, TriF[i]); + append_mat_to_vec(_EF, TetF[i]); + + assert(_EF.size() == (TriF[i].size()+TetF[i].size())); + + if( TriF[i].cols() == 1 ) + msh_saver.save_elem_scalar_field(EFields[i], _EF ); + else if( TriF[i].cols() == 3 ) + msh_saver.save_elem_vector_field(EFields[i], _EF ); + else + { + throw std::invalid_argument("unsupported node field dimensionality"); + } + } + } catch(const std::exception& e) { + std::cerr << e.what() << std::endl; + return false; + } + return true; +} + diff --git a/vendor/libigl/include/igl/writeOBJ.cpp b/vendor/libigl/include/igl/writeOBJ.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0848dbd4aee4d9aca625138f28f945686b481b51 --- /dev/null +++ b/vendor/libigl/include/igl/writeOBJ.cpp @@ -0,0 +1,169 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "writeOBJ.h" + +#include +#include +#include +#include +#include +#include + +template < + typename DerivedV, + typename DerivedF, + typename DerivedCN, + typename DerivedFN, + typename DerivedTC, + typename DerivedFTC> +IGL_INLINE bool igl::writeOBJ( + const std::string str, + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& CN, + const Eigen::MatrixBase& FN, + const Eigen::MatrixBase& TC, + const Eigen::MatrixBase& FTC) +{ + FILE * obj_file = fopen(str.c_str(),"w"); + if(NULL==obj_file) + { + printf("IOError: %s could not be opened for writing...",str.c_str()); + return false; + } + // Loop over V + for(int i = 0;i<(int)V.rows();i++) + { + fprintf(obj_file,"v"); + for(int j = 0;j<(int)V.cols();++j) + { + fprintf(obj_file," %0.17g", V(i,j)); + } + fprintf(obj_file,"\n"); + } + bool write_N = CN.rows() >0; + + if(write_N) + { + for(int i = 0;i<(int)CN.rows();i++) + { + fprintf(obj_file,"vn %0.17g %0.17g %0.17g\n", + CN(i,0), + CN(i,1), + CN(i,2) + ); + } + fprintf(obj_file,"\n"); + } + + bool write_texture_coords = TC.rows() >0; + + if(write_texture_coords) + { + for(int i = 0;i<(int)TC.rows();i++) + { + fprintf(obj_file, "vt %0.17g %0.17g\n",TC(i,0),TC(i,1)); + } + fprintf(obj_file,"\n"); + } + + // loop over F + for(int i = 0;i<(int)F.rows();++i) + { + fprintf(obj_file,"f"); + for(int j = 0; j<(int)F.cols();++j) + { + // OBJ is 1-indexed + fprintf(obj_file," %u",F(i,j)+1); + + if(write_texture_coords) + fprintf(obj_file,"/%u",FTC(i,j)+1); + if(write_N) + { + if (write_texture_coords) + fprintf(obj_file,"/%u",FN(i,j)+1); + else + fprintf(obj_file,"//%u",FN(i,j)+1); + } + } + fprintf(obj_file,"\n"); + } + fclose(obj_file); + return true; +} + +template +IGL_INLINE bool igl::writeOBJ( + const std::string str, + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F) +{ + using namespace std; + using namespace Eigen; + assert(V.cols() == 3 && "V should have 3 columns"); + ofstream s(str); + if(!s.is_open()) + { + fprintf(stderr,"IOError: writeOBJ() could not open %s\n",str.c_str()); + return false; + } + s<< + V.format(IOFormat(FullPrecision,DontAlignCols," ","\n","v ","","","\n"))<< + (F.array()+1).format(IOFormat(FullPrecision,DontAlignCols," ","\n","f ","","","\n")); + return true; +} + +template +IGL_INLINE bool igl::writeOBJ( + const std::string &str, + const Eigen::MatrixBase& V, + const std::vector >& F) +{ + using namespace std; + using namespace Eigen; + assert(V.cols() == 3 && "V should have 3 columns"); + ofstream s(str); + if(!s.is_open()) + { + fprintf(stderr,"IOError: writeOBJ() could not open %s\n",str.c_str()); + return false; + } + s<, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template bool igl::writeOBJ, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template bool igl::writeOBJ, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template bool igl::writeOBJ, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeOBJ, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeOBJ, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeOBJ, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeOBJ, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeOBJ, Eigen::Matrix >(std::basic_string, std::allocator >, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/writeOFF.h b/vendor/libigl/include/igl/writeOFF.h new file mode 100644 index 0000000000000000000000000000000000000000..a7312373d3750fb9fa309ac682d03d678a7d9acf --- /dev/null +++ b/vendor/libigl/include/igl/writeOFF.h @@ -0,0 +1,50 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WRITEOFF_H +#define IGL_WRITEOFF_H +#include "igl_inline.h" + +#include +#include + +namespace igl +{ + //Export geometry and colors-by-vertex + // Export a mesh from an ascii OFF file, filling in vertex positions. + // Only triangle meshes are supported + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Index type for indices (will be read as int and cast to Index) + // Inputs: + // str path to .off output file + // V #V by 3 mesh vertex positions + // F #F by 3 mesh indices into V + // C double matrix of rgb values per vertex #V by 3 + // Outputs: + // Returns true on success, false on errors + template + IGL_INLINE bool writeOFF( + const std::string str, + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + const Eigen::MatrixBase& C); + + template + IGL_INLINE bool writeOFF( + const std::string str, + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F); +} + +#ifndef IGL_STATIC_LIBRARY +# include "writeOFF.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/writePLY.cpp b/vendor/libigl/include/igl/writePLY.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f325e5de40d109c790f69c0db818c81dd2015679 --- /dev/null +++ b/vendor/libigl/include/igl/writePLY.cpp @@ -0,0 +1,419 @@ +#include "writePLY.h" +#include + +#include "tinyply.h" + + +namespace igl +{ + template tinyply::Type tynyply_type(); + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::INT8; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::INT16; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::INT32; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::UINT8; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::UINT16; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::UINT32; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::FLOAT32; } + template <> tinyply::Type IGL_INLINE tynyply_type(){ return tinyply::Type::FLOAT64; } + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED +> +bool writePLY( + std::ostream & ply_stream, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + + const Eigen::MatrixBase & VD, + const std::vector & VDheader, + + const Eigen::MatrixBase & FD, + const std::vector & FDheader, + + const Eigen::MatrixBase & ED, + const std::vector & EDheader, + + const std::vector & comments, + FileEncoding encoding + ) +{ + typedef typename DerivedV::Scalar VScalar; + typedef typename DerivedN::Scalar NScalar; + typedef typename DerivedUV::Scalar UVScalar; + typedef typename DerivedF::Scalar FScalar; + typedef typename DerivedE::Scalar EScalar; + + typedef typename DerivedVD::Scalar VDScalar; + typedef typename DerivedFD::Scalar FDScalar; + typedef typename DerivedED::Scalar EDScalar; + + // temporary storage for data to be passed to tinyply internals + std::vector _v; + std::vector _n; + std::vector _uv; + std::vector _vd; + std::vector _fd; + std::vector _ev; + std::vector _ed; + + // check dimensions + if( V.cols()!=3) + { + std::cerr << "writePLY: unexpected dimensions " << std::endl; + return false; + } + tinyply::PlyFile file; + + _v.resize(V.size()); + Eigen::Map< Eigen::Matrix >( &_v[0], V.rows(), V.cols() ) = V; + + file.add_properties_to_element("vertex", { "x", "y", "z" }, + tynyply_type(), V.rows(), reinterpret_cast( &_v[0] ), tinyply::Type::INVALID, 0); + + if(N.rows()>0) + { + _n.resize(N.size()); + Eigen::Map >( &_n[0], N.rows(), N.cols() ) = N; + file.add_properties_to_element("vertex", { "nx", "ny", "nz" }, + tynyply_type(), N.rows(), reinterpret_cast( &_n[0] ),tinyply::Type::INVALID, 0); + } + + if(UV.rows()>0) + { + _uv.resize(UV.size()); + Eigen::Map >( &_uv[0], UV.rows(), UV.cols() ) = UV; + + file.add_properties_to_element("vertex", { "u", "v" }, + tynyply_type(), UV.rows() , reinterpret_cast( &_uv[0] ), tinyply::Type::INVALID, 0); + } + + if(VD.cols()>0) + { + assert(VD.cols() == VDheader.size()); + assert(VD.rows() == V.rows()); + + _vd.resize(VD.size()); + Eigen::Map< Eigen::Matrix >( &_vd[0], VD.rows(), VD.cols() ) = VD; + + file.add_properties_to_element("vertex", VDheader, + tynyply_type(), VD.rows(), reinterpret_cast( &_vd[0] ), tinyply::Type::INVALID, 0); + } + + + + std::vector _f(F.size()); + Eigen::Map >( &_f[0], F.rows(), F.cols() ) = F; + file.add_properties_to_element("face", { "vertex_indices" }, + tynyply_type(), F.rows(), reinterpret_cast(&_f[0]), tinyply::Type::UINT8, F.cols() ); + + if(FD.cols()>0) + { + assert(FD.rows()==F.rows()); + assert(FD.cols() == FDheader.size()); + + _fd.resize(FD.size()); + Eigen::Map >( &_fd[0], FD.rows(), FD.cols() ) = FD; + + file.add_properties_to_element("face", FDheader, + tynyply_type(), FD.rows(), reinterpret_cast( &_fd[0] ), tinyply::Type::INVALID, 0); + } + + if(E.rows()>0) + { + assert(E.cols()==2); + _ev.resize(E.size()); + Eigen::Map >( &_ev[0], E.rows(), E.cols() ) = E; + + file.add_properties_to_element("edge", { "vertex1", "vertex2" }, + tynyply_type(), E.rows() , reinterpret_cast( &_ev[0] ), tinyply::Type::INVALID, 0); + } + + if(ED.cols()>0) + { + assert(ED.rows()==F.rows()); + assert(ED.cols() == EDheader.size()); + + _ed.resize(ED.size()); + Eigen::Map >( &_ed[0], ED.rows(), ED.cols() ) = ED; + + file.add_properties_to_element("edge", EDheader, + tynyply_type(), ED.rows(), reinterpret_cast( &_ed[0] ), tinyply::Type::INVALID, 0); + } + + for(auto a:comments) + file.get_comments().push_back(a); + + // Write a binary file + file.write(ply_stream, (encoding == FileEncoding::Binary)); + + return true; +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + + const Eigen::MatrixBase & VD, + const std::vector & VDheader, + + const Eigen::MatrixBase & FD, + const std::vector & FDheader, + + const Eigen::MatrixBase & ED, + const std::vector & EDheader, + + const std::vector & comments, + FileEncoding encoding + ) +{ + try + { + if(encoding == FileEncoding::Binary) + { + std::filebuf fb_binary; + fb_binary.open(filename , std::ios::out | std::ios::binary); + std::ostream outstream_binary(&fb_binary); + if (outstream_binary.fail()) { + std::cerr << "writePLY: Error opening file " << filename << std::endl; + return false; //throw std::runtime_error("failed to open " + filename); + } + return writePLY(outstream_binary,V,F,E,N,UV,VD,VDheader,FD,FDheader,ED,EDheader,comments,encoding); + } else { + std::filebuf fb_ascii; + fb_ascii.open(filename, std::ios::out); + std::ostream outstream_ascii(&fb_ascii); + if (outstream_ascii.fail()) { + std::cerr << "writePLY: Error opening file " << filename << std::endl; + return false; //throw std::runtime_error("failed to open " + filename); + } + return writePLY(outstream_ascii,V,F,E,N,UV,VD,VDheader,FD,FDheader,ED,EDheader,comments,encoding); + } + } + catch(const std::exception& e) + { + std::cerr << "writePLY error: " << filename << e.what() << std::endl; + } + return false; +} + +template < + typename DerivedV, + typename DerivedF +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F + ) +{ + Eigen::MatrixXd _dummy; + std::vector _dummy_header; + + return writePLY(filename,V,F,_dummy, _dummy, _dummy, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E + ) +{ + Eigen::MatrixXd _dummy; + std::vector _dummy_header; + + return writePLY(filename,V,F,E, _dummy, _dummy, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary); +} + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedN, + typename DerivedUV +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV + ) +{ + Eigen::MatrixXd _dummy; + std::vector _dummy_header; + + return writePLY(filename,V,F,_dummy, N,UV, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV + ) +{ + Eigen::MatrixXd _dummy; + std::vector _dummy_header; + + return writePLY(filename,V,F,E, N,UV, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary); +} + +template < + typename DerivedV, + typename DerivedF +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + FileEncoding encoding + ) +{ + Eigen::MatrixXd _dummy(0,0); + std::vector _dummy_header; + + return writePLY(filename,V,F,_dummy, _dummy,_dummy, _dummy, _dummy_header, + _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, encoding); +} + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + FileEncoding encoding + ) +{ + Eigen::MatrixXd _dummy(0,0); + std::vector _dummy_header; + + return writePLY(filename,V,F,E, _dummy,_dummy, _dummy, _dummy_header, + _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, encoding); +} + + + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedN, + typename DerivedUV, + typename DerivedVD +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & VD, + const std::vector & VDheader, + const std::vector & comments + ) +{ + Eigen::MatrixXd _dummy(0,0); + std::vector _dummy_header; + + return writePLY(filename,V,F,_dummy, N, UV, VD, VDheader, + _dummy, _dummy_header, _dummy, _dummy_header, comments, FileEncoding::Binary); +} + + + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & VD, + const std::vector & VDheader, + const std::vector & comments + ) +{ + Eigen::MatrixXd _dummy(0,0); + std::vector _dummy_header; + + return writePLY(filename,V,F,E, N, UV, VD, VDheader, + _dummy, _dummy_header, _dummy, _dummy_header, comments, FileEncoding::Binary); + +} + + + +} + + + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::writePLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writePLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writePLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writePLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writePLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +template bool igl::writePLY, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writePLY, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, Eigen::MatrixBase > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, Eigen::MatrixBase > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, igl::FileEncoding); +template bool igl::writePLY, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, Eigen::MatrixBase > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, Eigen::MatrixBase > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, igl::FileEncoding); +#endif diff --git a/vendor/libigl/include/igl/writePLY.h b/vendor/libigl/include/igl/writePLY.h new file mode 100644 index 0000000000000000000000000000000000000000..52a78fb4dd5acae4640edf181a9537926cf7ad34 --- /dev/null +++ b/vendor/libigl/include/igl/writePLY.h @@ -0,0 +1,240 @@ +#ifndef IGL_WRITEPLY_H +#define IGL_WRITEPLY_H +#include +#include + +#include +#include +#include +#include + + +namespace igl +{ + // write triangular mesh to ply file + // + // Templates: + // Derived from Eigen matrix parameters + // Inputs: + // ply_stream ply file output stream + // V (#V,3) matrix of vertex positions + // F (#F,3) list of face indices into vertex positions + // E (#E,2) list of edge indices into vertex positions + // N (#V,3) list of normals + // UV (#V,2) list of texture coordinates + // VD (#V,*) additional vertex data + // Vheader (#V) list of vertex data headers + // FD (#F,*) additional face data + // Fheader (#F) list of face data headers + // ED (#E,*) additional edge data + // Eheader (#E) list of edge data headers + // comments (*) file comments + // encoding - enum, to set binary or ascii file format + // Returns true on success, false on errors + template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED +> +bool writePLY( + std::ostream & ply_stream, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + + const Eigen::MatrixBase & VD, + const std::vector & VDheader, + + const Eigen::MatrixBase & FD, + const std::vector & FDheader, + + const Eigen::MatrixBase & ED, + const std::vector & EDheader, + + const std::vector & comments, + FileEncoding encoding + ); + + // write triangular mesh to ply file + // + // Templates: + // Derived from Eigen matrix parameters + // Inputs: + // filename ply file name + // V (#V,3) matrix of vertex positions + // F (#F,3) list of face indices into vertex positions + // E (#E,2) list of edge indices into vertex positions + // N (#V,3) list of normals + // UV (#V,2) list of texture coordinates + // VD (#V,*) additional vertex data + // Vheader (#V) list of vertex data headers + // FD (#F,*) additional face data + // Fheader (#F) list of face data headers + // ED (#E,*) additional edge data + // Eheader (#E) list of edge data headers + // comments (*) file comments + // encoding - enum, to set binary or ascii file format + // Returns true on success, false on errors +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD, + typename DerivedFD, + typename DerivedED +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + + const Eigen::MatrixBase & VD, + const std::vector & VDheader, + + const Eigen::MatrixBase & FD, + const std::vector & FDheader, + + const Eigen::MatrixBase & ED, + const std::vector & EDheader, + + const std::vector & comments, + FileEncoding encoding + ); + +template < + typename DerivedV, + typename DerivedF +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F + ); + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E + ); + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedN, + typename DerivedUV +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV + ); + + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV + ); + + +template < + typename DerivedV, + typename DerivedF +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + FileEncoding encoding + ); + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + FileEncoding encoding + ); + +template < + typename DerivedV, + typename DerivedF, + typename DerivedN, + typename DerivedUV, + typename DerivedVD +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & VD=Eigen::MatrixXd(0,0), + const std::vector & VDheader={}, + const std::vector & comments={} + ); + +template < + typename DerivedV, + typename DerivedF, + typename DerivedE, + typename DerivedN, + typename DerivedUV, + typename DerivedVD +> +bool writePLY( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & E, + const Eigen::MatrixBase & N, + const Eigen::MatrixBase & UV, + const Eigen::MatrixBase & VD=Eigen::MatrixXd(0,0), + const std::vector & VDheader={}, + const std::vector & comments={} + ); + +} + + + +#ifndef IGL_STATIC_LIBRARY +# include "writePLY.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/writeSTL.cpp b/vendor/libigl/include/igl/writeSTL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..720c92df83bbdaffa75a80a58809b5cd19b45888 --- /dev/null +++ b/vendor/libigl/include/igl/writeSTL.cpp @@ -0,0 +1,123 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2014 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "writeSTL.h" +#include + +template +IGL_INLINE bool igl::writeSTL( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + FileEncoding encoding) +{ + using namespace std; + assert(N.rows() == 0 || F.rows() == N.rows()); + if(encoding == FileEncoding::Ascii) + { + FILE * stl_file = fopen(filename.c_str(),"w"); + if(stl_file == NULL) + { + cerr<<"IOError: "<0) + { + fprintf(stl_file,"%e %e %e\n", + (float)N(f,0), + (float)N(f,1), + (float)N(f,2)); + }else + { + fprintf(stl_file,"0 0 0\n"); + } + fprintf(stl_file,"outer loop\n"); + for(int c = 0;c n(3,0); + if(N.rows() > 0) + { + n[0] = N(f,0); + n[1] = N(f,1); + n[2] = N(f,2); + } + fwrite(&n[0],sizeof(float),3,stl_file); + for(int c = 0;c<3;c++) + { + vector v(3); + v[0] = V(F(f,c),0); + v[1] = V(F(f,c),1); + v[2] = V(F(f,c),2); + fwrite(&v[0],sizeof(float),3,stl_file); + } + unsigned short att_count = 0; + fwrite(&att_count,sizeof(unsigned short),1,stl_file); + } + fclose(stl_file); + return true; + } +} + +template +IGL_INLINE bool igl::writeSTL( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + FileEncoding encoding) +{ + return writeSTL(filename,V,F, Eigen::Matrix(), encoding); +} + +#ifdef IGL_STATIC_LIBRARY +// Explicit template instantiation +// generated by autoexplicit.sh +template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +// generated by autoexplicit.sh +template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +template bool igl::writeSTL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::FileEncoding); +#endif diff --git a/vendor/libigl/include/igl/writeSTL.h b/vendor/libigl/include/igl/writeSTL.h new file mode 100644 index 0000000000000000000000000000000000000000..6cf9896d21aefbc3fc8f54439cc95aa6fa00635d --- /dev/null +++ b/vendor/libigl/include/igl/writeSTL.h @@ -0,0 +1,53 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WRITESTL_H +#define IGL_WRITESTL_H +#include "igl_inline.h" +#include + +#ifndef IGL_NO_EIGEN +# include +#endif +#include +#include + +namespace igl +{ + // Write a mesh to an stl file. + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Inputs: + // filename path to .obj file + // V double matrix of vertex positions #F*3 by 3 + // F index matrix of triangle indices #F by 3 + // N double matrix of vertex positions #F by 3 + // encoding enum to set file encoding (ascii by default) + // Returns true on success, false on errors + // + template + IGL_INLINE bool writeSTL( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & N, + FileEncoding encoding=FileEncoding::Ascii); + template + IGL_INLINE bool writeSTL( + const std::string & filename, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + FileEncoding encoding=FileEncoding::Ascii); +} + +#ifndef IGL_STATIC_LIBRARY +# include "writeSTL.cpp" +#endif + +#endif diff --git a/vendor/libigl/include/igl/writeTGF.cpp b/vendor/libigl/include/igl/writeTGF.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65c8fc6a42e5a592eb494e7e138e2f281ec1b2a0 --- /dev/null +++ b/vendor/libigl/include/igl/writeTGF.cpp @@ -0,0 +1,73 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "writeTGF.h" +#include + +IGL_INLINE bool igl::writeTGF( + const std::string tgf_filename, + const std::vector > & C, + const std::vector > & E) +{ + FILE * tgf_file = fopen(tgf_filename.c_str(),"w"); + if(NULL==tgf_file) + { + printf("IOError: %s could not be opened\n",tgf_filename.c_str()); + return false; + } + // Loop over vertices + for(int i = 0; i<(int)C.size();i++) + { + assert(C[i].size() == 3); + // print a line with vertex number then "description" + // Where "description" in our case is the 3d position in space + // + fprintf(tgf_file, + "%4d " + "%10.17g %10.17g %10.17g " // current location + // All others are not needed for this legacy support + "\n", + i+1, + C[i][0], C[i][1], C[i][2]); + } + + // print a comment to separate vertices and edges + fprintf(tgf_file,"#\n"); + + // loop over edges + for(int i = 0;i<(int)E.size();i++) + { + assert(E[i].size()==2); + fprintf(tgf_file,"%4d %4d\n", + E[i][0]+1, + E[i][1]+1); + } + + // print a comment to separate edges and faces + fprintf(tgf_file,"#\n"); + + fclose(tgf_file); + + return true; +} + +#ifndef IGL_NO_EIGEN +#include "matrix_to_list.h" + +IGL_INLINE bool igl::writeTGF( + const std::string tgf_filename, + const Eigen::MatrixXd & C, + const Eigen::MatrixXi & E) +{ + using namespace std; + vector > vC; + vector > vE; + matrix_to_list(C,vC); + matrix_to_list(E,vE); + return writeTGF(tgf_filename,vC,vE); +} +#endif diff --git a/vendor/libigl/include/igl/writeTGF.h b/vendor/libigl/include/igl/writeTGF.h new file mode 100644 index 0000000000000000000000000000000000000000..999584463a23af7f9ac48dfb4aae6cf863a8be1c --- /dev/null +++ b/vendor/libigl/include/igl/writeTGF.h @@ -0,0 +1,48 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WRITETGF_H +#define IGL_WRITETGF_H +#include "igl_inline.h" + +#include +#include +#ifndef IGL_NO_EIGEN +#include +#endif + +namespace igl +{ + // WRITETGF + // + // Write a graph to a .tgf file + // + // Input: + // filename .tgf file name + // V # vertices by 3 list of vertex positions + // E # edges by 2 list of edge indices + // + // Assumes that graph vertices are 3 dimensional + IGL_INLINE bool writeTGF( + const std::string tgf_filename, + const std::vector > & C, + const std::vector > & E); + + #ifndef IGL_NO_EIGEN + IGL_INLINE bool writeTGF( + const std::string tgf_filename, + const Eigen::MatrixXd & C, + const Eigen::MatrixXi & E); + #endif +} + +#ifndef IGL_STATIC_LIBRARY +# include "writeTGF.cpp" +#endif + +#endif + diff --git a/vendor/libigl/include/igl/writeWRL.cpp b/vendor/libigl/include/igl/writeWRL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76dfb9088a02a55fe27e3a5d110eacd617a49d2f --- /dev/null +++ b/vendor/libigl/include/igl/writeWRL.cpp @@ -0,0 +1,126 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "writeWRL.h" +#include +#include +template +IGL_INLINE bool igl::writeWRL( + const std::string & str, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F) +{ + using namespace std; + using namespace Eigen; + assert(V.cols() == 3 && "V should have 3 columns"); + assert(F.cols() == 3 && "F should have 3 columns"); + ofstream s(str); + if(!s.is_open()) + { + cerr<<"IOError: writeWRL() could not open "< FF(F.rows(),4); + FF.leftCols(3) = F; + FF.col(3).setConstant(-1); + + s< +IGL_INLINE bool igl::writeWRL( + const std::string & str, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & C) +{ + using namespace std; + using namespace Eigen; + assert(V.cols() == 3 && "V should have 3 columns"); + assert(F.cols() == 3 && "F should have 3 columns"); + ofstream s(str); + if(!s.is_open()) + { + cerr<<"IOError: writeWRL() could not open "< FF(F.rows(),4); + FF.leftCols(3) = F; + FF.col(3).setConstant(-1); + + + //Check if RGB values are in the range [0..1] or [0..255] + double rgbScale = (C.maxCoeff() <= 1.0)?1.0:1.0/255.0; + Eigen::MatrixXd RGB = rgbScale * C; + + s<, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template bool igl::writeWRL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template bool igl::writeWRL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +// generated by autoexplicit.sh +template bool igl::writeWRL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeWRL, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +template bool igl::writeWRL, Eigen::Matrix, Eigen::Matrix >(std::basic_string, std::allocator > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::MatrixBase > const&); +#endif diff --git a/vendor/libigl/include/igl/writeWRL.h b/vendor/libigl/include/igl/writeWRL.h new file mode 100644 index 0000000000000000000000000000000000000000..3b01c277fd59cda15c7d1e205d0dce1715c9c637 --- /dev/null +++ b/vendor/libigl/include/igl/writeWRL.h @@ -0,0 +1,46 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2015 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WRITE_WRL_H +#define IGL_WRITE_WRL_H +#include "igl_inline.h" +#include +#include +namespace igl +{ + // Write mesh to a .wrl file + // + // Inputs: + // str path to .wrl file + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices + // Returns true iff succes + template + IGL_INLINE bool writeWRL( + const std::string & str, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F); + + // Write mesh to a .wrl file + // + // Inputs: + // str path to .wrl file + // V #V by 3 list of vertex positions + // F #F by 3 list of triangle indices + // C double matrix of rgb values per vertex #V by 3 + // Returns true iff succes + template + IGL_INLINE bool writeWRL( + const std::string & str, + const Eigen::MatrixBase & V, + const Eigen::MatrixBase & F, + const Eigen::MatrixBase & C); +} +#ifndef IGL_STATIC_LIBRARY +#include "writeWRL.cpp" +#endif +#endif diff --git a/vendor/libigl/include/igl/write_triangle_mesh.h b/vendor/libigl/include/igl/write_triangle_mesh.h new file mode 100644 index 0000000000000000000000000000000000000000..e3ec6ee7a425bbb0a06fb1a3b6c5566d182ccadf --- /dev/null +++ b/vendor/libigl/include/igl/write_triangle_mesh.h @@ -0,0 +1,43 @@ +// This file is part of libigl, a simple c++ geometry processing library. +// +// Copyright (C) 2013 Alec Jacobson +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#ifndef IGL_WRITE_TRIANGLE_MESH_H +#define IGL_WRITE_TRIANGLE_MESH_H +#include "igl_inline.h" +#include + +#include +#include + +namespace igl +{ + // write mesh to a file with automatic detection of file format. supported: + // obj, off, stl, wrl, ply, mesh). + // + // Templates: + // Scalar type for positions and vectors (will be read as double and cast + // to Scalar) + // Index type for indices (will be read as int and cast to Index) + // Inputs: + // str path to file + // V eigen double matrix #V by 3 + // F eigen int matrix #F by 3 + // encoding set file encoding (ascii or binary) when both are available + // Returns true iff success + template + IGL_INLINE bool write_triangle_mesh( + const std::string str, + const Eigen::MatrixBase& V, + const Eigen::MatrixBase& F, + FileEncoding encoding = FileEncoding::Ascii); +} + +#ifndef IGL_STATIC_LIBRARY +# include "write_triangle_mesh.cpp" +#endif + +#endif