// 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 "ViewerData.h" #include #include #include #include #include IGL_INLINE igl::viewer::ViewerData::ViewerData() : dirty(DIRTY_ALL) { clear(); }; IGL_INLINE void igl::viewer::ViewerData::set_face_based(bool newvalue) { if (face_based != newvalue) { face_based = newvalue; dirty = DIRTY_ALL; } } // Helpers that draws the most common meshes IGL_INLINE void igl::viewer::ViewerData::set_mesh(const Eigen::MatrixXd& _V, const Eigen::MatrixXi& _F) { using namespace std; Eigen::MatrixXd V_temp; // If V only has two columns, pad with a column of zeros if (_V.cols() == 2) { V_temp = Eigen::MatrixXd::Zero(_V.rows(),3); V_temp.block(0,0,_V.rows(),2) = _V; } else V_temp = _V; if (V.rows() == 0 && F.rows() == 0) { V = V_temp; F = _F; compute_normals(); uniform_colors( Eigen::Vector3d(GOLD_AMBIENT[0], GOLD_AMBIENT[1], GOLD_AMBIENT[2]), Eigen::Vector3d(GOLD_DIFFUSE[0], GOLD_DIFFUSE[1], GOLD_DIFFUSE[2]), Eigen::Vector3d(GOLD_SPECULAR[0], GOLD_SPECULAR[1], GOLD_SPECULAR[2])); grid_texture(); } else { if (_V.rows() == V.rows() && _F.rows() == F.rows()) { V = V_temp; F = _F; } else cerr << "ERROR (set_mesh): The new mesh has a different number of vertices/faces. Please clear the mesh before plotting."<0 && C.cols() == 1) { Eigen::MatrixXd C3; igl::parula(C,true,C3); return set_colors(C3); } // Ambient color should be darker color const auto ambient = [](const MatrixXd & C)->MatrixXd { MatrixXd T = 0.1*C; T.col(3) = C.col(3); return T; }; // Specular color should be a less saturated and darker color: dampened // highlights const auto specular = [](const MatrixXd & C)->MatrixXd { const double grey = 0.3; MatrixXd T = grey+0.1*(C.array()-grey); T.col(3) = C.col(3); return T; }; if (C.rows() == 1) { for (unsigned i=0;i& R, const Eigen::Matrix& G, const Eigen::Matrix& B) { texture_R = R; texture_G = G; texture_B = B; texture_A = Eigen::Matrix::Constant(R.rows(),R.cols(),255); dirty |= DIRTY_TEXTURE; } IGL_INLINE void igl::viewer::ViewerData::set_texture( const Eigen::Matrix& R, const Eigen::Matrix& G, const Eigen::Matrix& B, const Eigen::Matrix& A) { texture_R = R; texture_G = G; texture_B = B; texture_A = A; dirty |= DIRTY_TEXTURE; } IGL_INLINE void igl::viewer::ViewerData::set_points( const Eigen::MatrixXd& P, const Eigen::MatrixXd& C) { // clear existing points points.resize(0,0); add_points(P,C); } IGL_INLINE void igl::viewer::ViewerData::add_points(const Eigen::MatrixXd& P, const Eigen::MatrixXd& C) { Eigen::MatrixXd P_temp; // If P only has two columns, pad with a column of zeros if (P.cols() == 2) { P_temp = Eigen::MatrixXd::Zero(P.rows(),3); P_temp.block(0,0,P.rows(),2) = P; } else P_temp = P; int lastid = points.rows(); points.conservativeResize(points.rows() + P_temp.rows(),6); for (unsigned i=0; i=size2 && j>=size2)) texture_R(i,j) = 255; } } texture_G = texture_R; texture_B = texture_R; texture_A = Eigen::Matrix::Constant(texture_R.rows(),texture_R.cols(),255); dirty |= DIRTY_TEXTURE; }