// 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 "colon.h" #ifndef IGL_NO_EIGEN //void igl::jet(const int m, Eigen::MatrixXd & J) //{ // using namespace Eigen; // // Applications/MATLAB_R2012b.app/toolbox/matlab/graph3d/jet.m // const int n = ceil(m/4); // // resize output // J.resize(m,3); // // u = [(1:1:n)/n ones(1,n-1) (n:-1:1)/n]'; // VectorXd u(n*3-1); // u.block(0,0,n-1,1) = colon(1,n)/double(n); // VectorXd g; // colon(0,n*3-1-1,g); // g.array() = g.array() + ceil(n/2) - int((m%4)==1); // VectorXd r = (g.array() + n).eval().matrix(); // VectorXd b = (g.array() - n).eval().matrix(); // int ri = 0; // int gi = 0; // int sb = 0; // // count number of indices in b // for(int j = 0;j IGL_INLINE void igl::jet(const T x, T * rgb) { return jet(x,rgb[0],rgb[1],rgb[2]); } template IGL_INLINE void igl::jet(const T x_in, T & r, T & g, T & b) { // Only important if the number of colors is small. In which case the rest is // still wrong anyway // x = linspace(0,1,jj)' * (1-1/jj) + 1/jj; // const double rone = 0.8; const double gone = 1.0; const double bone = 1.0; T x = x_in; x = (x_in<0?0:(x>1?1:x)); if(x<1./8.) { r = 0; g = 0; b = bone*(0.5+(x)/(1./8.)*0.5); }else if(x<3./8.) { r = 0; g = gone*(x-1./8.)/(3./8.-1./8.); b = bone; }else if(x<5./8.) { r = rone*(x-3./8.)/(5./8.-3./8.); g = gone; b = (bone-(x-3./8.)/(5./8.-3./8.)); }else if(x<7./8.) { r = rone; g = (gone-(x-5./8.)/(7./8.-5./8.)); b = 0; }else { r = (rone-(x-7./8.)/(1.-7./8.)*0.5); g = 0; b = 0; } } template IGL_INLINE void igl::jet( const Eigen::PlainObjectBase & Z, const bool normalize, Eigen::PlainObjectBase & C) { const double min_z = (normalize?Z.minCoeff():0); const double max_z = (normalize?Z.maxCoeff():-1); return jet(Z,min_z,max_z,C); } template IGL_INLINE void igl::jet( const Eigen::PlainObjectBase & Z, const double min_z, const double max_z, Eigen::PlainObjectBase & C) { C.resize(Z.rows(),3); for(int r = 0;r, Eigen::Matrix >(Eigen::PlainObjectBase > 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::PlainObjectBase > const&, bool, Eigen::PlainObjectBase >&); template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, bool, Eigen::PlainObjectBase >&); template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, bool, Eigen::PlainObjectBase >&); template void igl::jet(float, float&, float&, float&); template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, double, double, Eigen::PlainObjectBase >&); template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, double, double, Eigen::PlainObjectBase >&); template void igl::jet, Eigen::Matrix >(Eigen::PlainObjectBase > const&, double, double, Eigen::PlainObjectBase >&); #endif