diff --git a/include/igl/isolines.cpp b/include/igl/isolines.cpp new file mode 100644 index 000000000..629aed36d --- /dev/null +++ b/include/igl/isolines.cpp @@ -0,0 +1,117 @@ +// 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 "sort.h" +#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), + 1e-12, 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/include/igl/isolines.h b/include/igl/isolines.h new file mode 100644 index 000000000..a8b78fe78 --- /dev/null +++ b/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 ecaluated at vertices + // n the number of desired isolines + // Outputs: + // isoV #isoV by dim list of isoline vertex positions + // isoE #isoE by dim 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/tutorial/712_DataSmoothing/isolines.h b/tutorial/712_DataSmoothing/isolines.h deleted file mode 100644 index e7c807749..000000000 --- a/tutorial/712_DataSmoothing/isolines.h +++ /dev/null @@ -1,90 +0,0 @@ - -#include -#include -#include - -#include - - -static void isolines(const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::VectorXd& z, - const int grads, - Eigen::MatrixXd& isoV, - Eigen::MatrixXi& isoE) -{ - const double min = z.minCoeff(), max = z.maxCoeff(); - - //Following http://www.alecjacobson.com/weblog/?p=2529 - Eigen::VectorXd iso(grads+1); - for(int i=0; i1) - t12(i,j) = std::numeric_limits::quiet_NaN(); - if(t23(i,j)<0 || t23(i,j)>1) - t23(i,j) = std::numeric_limits::quiet_NaN(); - if(t31(i,j)<0 || t31(i,j)>1) - t31(i,j) = std::numeric_limits::quiet_NaN(); - } - } - - std::vector F12, F23, F31, I12, I23, I31; - for(int i=0; i int main(int argc, char * argv[]) @@ -90,7 +90,7 @@ int main(int argc, char * argv[]) Eigen::MatrixXd isoV; Eigen::MatrixXi isoE; if(key!='2') - isolines(V, F, *z, 30, isoV, isoE); + igl::isolines(V, F, *z, 30, isoV, isoE); viewer.data.set_edges(isoV,isoE,Eigen::RowVector3d(0,0,0)); Eigen::MatrixXd colors; igl::jet(*z, true, colors);