diff --git a/include/igl/ceil.cpp b/include/igl/ceil.cpp new file mode 100644 index 000000000..9fefb29fe --- /dev/null +++ b/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 = Eigen::PlainObjectBase::Zero(m,n); +//#pragma omp parallel for + //for(int i = 0;iScalar{return std::ceil(x);}).template cast(); +} + +#ifndef IGL_HEADER_ONLY +// Explicit instanciation +template void igl::ceil, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); +#endif diff --git a/include/igl/ceil.h b/include/igl/ceil.h new file mode 100644 index 000000000..349e86024 --- /dev/null +++ b/include/igl/ceil.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_CEIL_H +#define IGL_CEIL_H +#include "igl_inline.h" +#include +namespace igl +{ + // Ceil a given matrix to nearest integers + // + // Inputs: + // X m by n matrix of scalars + // Outputs: + // Y m by n matrix of ceiled integers + template < typename DerivedX, typename DerivedY> + IGL_INLINE void ceil( + const Eigen::PlainObjectBase& X, + Eigen::PlainObjectBase& Y); +} + +#ifdef IGL_HEADER_ONLY +# include "ceil.cpp" +#endif + +#endif diff --git a/include/igl/diag.h b/include/igl/diag.h index 325eccf81..73bcb28f5 100644 --- a/include/igl/diag.h +++ b/include/igl/diag.h @@ -16,8 +16,9 @@ namespace igl // http://forum.kde.org/viewtopic.php?f=74&t=117476&p=292388#p292388 // // This is superceded by - // VectorXd d = X.diagonal() and - // SparseVector d = X.diagonal().sparseView() + // VectorXd V = X.diagonal() and + // SparseVector V = X.diagonal().sparseView() + // SparseMatrix X = V.asDiagonal().sparseView() // // // Either extracts the main diagonal of a matrix as a vector OR converts a diff --git a/include/igl/floor.cpp b/include/igl/floor.cpp new file mode 100644 index 000000000..37abe6922 --- /dev/null +++ b/include/igl/floor.cpp @@ -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/. +#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 = Eigen::PlainObjectBase::Zero(m,n); +//#pragma omp parallel for + //for(int i = 0;iScalar{return std::floor(x);}).template cast(); +} + +#ifndef IGL_HEADER_ONLY +// Explicit instanciation +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/include/igl/floor.h b/include/igl/floor.h new file mode 100644 index 000000000..7f0b8013c --- /dev/null +++ b/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); +} + +#ifdef IGL_HEADER_ONLY +# include "floor.cpp" +#endif + +#endif diff --git a/include/igl/jet.cpp b/include/igl/jet.cpp index dff881774..e7d9a8606 100644 --- a/include/igl/jet.cpp +++ b/include/igl/jet.cpp @@ -111,7 +111,7 @@ IGL_INLINE void igl::jet( const double max_z = (normalize?Z.maxCoeff():-1); for(int r = 0;r(double, double*); template void igl::jet(double, double&, double&, double&); template void igl::jet(float, float*); template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, bool, Eigen::PlainObjectBase >&); +template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, bool, Eigen::PlainObjectBase >&); #endif diff --git a/include/igl/reorder.h b/include/igl/reorder.h index 2a8474252..399fef2ed 100644 --- a/include/igl/reorder.h +++ b/include/igl/reorder.h @@ -15,7 +15,7 @@ namespace igl { - // Act like matlab's Y = X[I] for std vectors + // Act like matlab's Y = X(I) for std vectors // where I contains a vector of indices so that after, // Y[j] = X[I[j]] for index j // this implies that Y.size() == I.size() diff --git a/include/igl/slice_into.cpp b/include/igl/slice_into.cpp index fbc682085..b80878fb7 100644 --- a/include/igl/slice_into.cpp +++ b/include/igl/slice_into.cpp @@ -6,6 +6,7 @@ // v. 2.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_into.h" +#include "colon.h" // Bug in unsupported/Eigen/SparseExtra needs iostream first #include @@ -79,6 +80,40 @@ IGL_INLINE void igl::slice_into( } } +template +IGL_INLINE void igl::slice_into( + const Mat& X, + const Eigen::Matrix & R, + const int dim, + Mat& Y) +{ + Eigen::VectorXi C; + switch(dim) + { + case 1: + assert(R.size() == X.rows()); + // boring base case + if(X.cols() == 0) + { + return; + } + igl::colon(0,X.cols()-1,C); + return slice_into(X,R,C,Y); + case 2: + assert(R.size() == X.cols()); + // boring base case + if(X.rows() == 0) + { + return; + } + igl::colon(0,X.rows()-1,C); + return slice_into(X,C,R,Y); + default: + assert(false && "Unsupported dimension"); + return; + } +} + template IGL_INLINE void igl::slice_into( const Eigen::PlainObjectBase & X, @@ -97,4 +132,6 @@ IGL_INLINE void igl::slice_into( // generated by autoexplicit.sh template void igl::slice_into >(Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::PlainObjectBase >&); template void igl::slice_into >(Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::PlainObjectBase >&); +template void igl::slice_into >(Eigen::Matrix const&, Eigen::Matrix const&, int, Eigen::Matrix&); +template void igl::slice_into >(Eigen::PlainObjectBase > const&, Eigen::Matrix const&, Eigen::PlainObjectBase >&); #endif diff --git a/include/igl/slice_into.h b/include/igl/slice_into.h index 339b14283..e534c0fad 100644 --- a/include/igl/slice_into.h +++ b/include/igl/slice_into.h @@ -36,6 +36,18 @@ namespace igl const Eigen::Matrix & R, const Eigen::Matrix & 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 Mat& X, + const Eigen::Matrix & R, + const int dim, + Mat& Y); template IGL_INLINE void slice_into( diff --git a/include/igl/viewer/Viewer.cpp.REMOVED.git-id b/include/igl/viewer/Viewer.cpp.REMOVED.git-id index 873d557a6..54a63a673 100644 --- a/include/igl/viewer/Viewer.cpp.REMOVED.git-id +++ b/include/igl/viewer/Viewer.cpp.REMOVED.git-id @@ -1 +1 @@ -5381ba4d384ee8a7bda552c5bf95a26335b93b48 \ No newline at end of file +be827c7827ae18c27874d6e620ad13f84f9b37de \ No newline at end of file diff --git a/include/igl/viewer/Viewer.h b/include/igl/viewer/Viewer.h index 3a346f1fa..c1cb5b401 100644 --- a/include/igl/viewer/Viewer.h +++ b/include/igl/viewer/Viewer.h @@ -31,7 +31,7 @@ namespace igl { public: - void launch(std::string filename = ""); + int launch(std::string filename = ""); void init(Plugin_manager* pm); class Options diff --git a/matlab-to-eigen.html b/matlab-to-eigen.html index 9c06307a6..0308b01e3 100644 --- a/matlab-to-eigen.html +++ b/matlab-to-eigen.html @@ -11,7 +11,7 @@ -
[Y,IX] = sort(Y,dim,mode)
+
[Y,IX] = sort(X,dim,mode)
igl::sort(X,dim,mode,Y,IX)
MATLAB version allows Y to be a multidimensional matrix, but the Eigen version is only for 1D or 2D matrices. @@ -45,7 +45,7 @@
A(i:(i+w),j:(j+h)) = eye(w,h)
-
A.setIdentity()
+
A.block(i,j,w,h).setIdentity()
diff --git a/tutorial/205_Laplacian/main.cpp b/tutorial/205_Laplacian/main.cpp index 27b4d061f..b6522de29 100755 --- a/tutorial/205_Laplacian/main.cpp +++ b/tutorial/205_Laplacian/main.cpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -24,6 +27,20 @@ int main(int argc, char *argv[]) // Compute Laplace-Beltrami operator: #V by #V igl::cotmatrix(V,F,L); + // Alternative construction of same Laplacian + SparseMatrix G,K; + // Gradient/Divergence + igl::gradMat(V,F,G); + // Diagonal per-triangle "mass matrix" + VectorXd dblA; + igl::doublearea(V,F,dblA); + // Place areas along diagonal #dim times + const auto & T = 1.*(dblA.replicate(3,1)*0.5).asDiagonal(); + // Laplacian K built as discrete divergence of gradient or equivalently + // discrete Dirichelet energy Hessian + K = -G.transpose() * T * G; + cout<<"|K-L|: "<<(K-L).norm()<bool { switch(key) @@ -70,5 +87,5 @@ int main(int argc, char *argv[]) cout<<"Press [space] to smooth."< +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + using namespace Eigen; + using namespace std; + MatrixXd V; + MatrixXi F; + igl::readOFF("../shared/decimated-knight.off",V,F); + + // 100 random indicies into rows of F + VectorXi I; + igl::floor((0.5*(VectorXd::Random(100,1).array()+1.)*F.rows()).eval(),I); + + // 50 random indicies into rows of I + VectorXi J; + igl::floor((0.5*(VectorXd::Random(50,1).array()+1.)*I.rows()).eval(),J); + + // K = I(J); + VectorXi K; + igl::slice(I,J,K); + + // default green for all faces + MatrixXd C = RowVector3d(0.4,0.8,0.3).replicate(F.rows(),1); + // Red for each in K + MatrixXd R = RowVector3d(1.0,0.3,0.3).replicate(K.rows(),1); + // C(K,:) = R + igl::slice_into(R,K,1,C); + + // Plot the mesh with pseudocolors + igl::Viewer viewer; + viewer.set_mesh(V, F); + viewer.set_colors(C); + viewer.launch(); +} diff --git a/tutorial/302_Sort/CMakeLists.txt b/tutorial/302_Sort/CMakeLists.txt new file mode 100644 index 000000000..15b4dd6fd --- /dev/null +++ b/tutorial/302_Sort/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.6) +project(302_Sort) + +include("../CMakeLists.shared") + +set(SOURCES +${PROJECT_SOURCE_DIR}/main.cpp +) + +add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES}) +target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES}) diff --git a/tutorial/302_Sort/main.cpp b/tutorial/302_Sort/main.cpp new file mode 100644 index 000000000..b1bc086ad --- /dev/null +++ b/tutorial/302_Sort/main.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + using namespace Eigen; + using namespace std; + MatrixXd V; + MatrixXi F; + igl::readOFF("../shared/decimated-knight.off",V,F); + + // Sort barycenters lexicographically + MatrixXd BC,sorted_BC; + igl::barycenter(V,F,BC); + VectorXi I,J; + igl::sortrows(BC,true,sorted_BC,I); + // Get sorted "place" from sorted indices + J.resize(I.rows()); + // J(I) = 1:numel(I) + igl::slice_into(igl::colon(0,I.size()-1),I,J); + + // Pseudo-color based on sorted place + MatrixXd C; + igl::jet(J,true,C); + + // Plot the mesh with pseudocolors + igl::Viewer viewer; + viewer.set_mesh(V, F); + viewer.set_colors(C); + viewer.launch(); +} diff --git a/tutorial/images/decimated-knight-slice-color.jpg.REMOVED.git-id b/tutorial/images/decimated-knight-slice-color.jpg.REMOVED.git-id new file mode 100644 index 000000000..d0e9d40a6 --- /dev/null +++ b/tutorial/images/decimated-knight-slice-color.jpg.REMOVED.git-id @@ -0,0 +1 @@ +480151754ff0e57c7111cc288fd6c0b6b163f404 \ No newline at end of file diff --git a/tutorial/images/decimated-knight-sort-color.jpg.REMOVED.git-id b/tutorial/images/decimated-knight-sort-color.jpg.REMOVED.git-id new file mode 100644 index 000000000..cfc0f73ad --- /dev/null +++ b/tutorial/images/decimated-knight-sort-color.jpg.REMOVED.git-id @@ -0,0 +1 @@ +7172cceb268b1fb836116ae527caa912200b416c \ No newline at end of file diff --git a/tutorial/readme.md b/tutorial/readme.md index d04e8e5c6..c9edcd267 100644 --- a/tutorial/readme.md +++ b/tutorial/readme.md @@ -9,35 +9,39 @@ html header: