// 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 #ifdef ENABLE_SERIALIZATION #include namespace igl { namespace serialization { IGL_INLINE void serialization(bool s,igl::viewer::ViewerData& obj,std::vector& buffer) { SERIALIZE_MEMBER(V); SERIALIZE_MEMBER(F); SERIALIZE_MEMBER(F_normals); SERIALIZE_MEMBER(F_material_ambient); SERIALIZE_MEMBER(F_material_diffuse); SERIALIZE_MEMBER(F_material_specular); SERIALIZE_MEMBER(V_normals); SERIALIZE_MEMBER(V_material_ambient); SERIALIZE_MEMBER(V_material_diffuse); SERIALIZE_MEMBER(V_material_specular); SERIALIZE_MEMBER(V_uv); SERIALIZE_MEMBER(F_uv); SERIALIZE_MEMBER(texture_R); SERIALIZE_MEMBER(texture_G); SERIALIZE_MEMBER(texture_B); SERIALIZE_MEMBER(lines); SERIALIZE_MEMBER(points); SERIALIZE_MEMBER(labels_positions); SERIALIZE_MEMBER(labels_strings); SERIALIZE_MEMBER(dirty); SERIALIZE_MEMBER(face_based); } template<> IGL_INLINE void serialize(const igl::viewer::ViewerData& obj,std::vector& buffer) { serialization(true,const_cast(obj),buffer); } template<> IGL_INLINE void deserialize(igl::viewer::ViewerData& obj,const std::vector& buffer) { serialization(false,obj,const_cast&>(buffer)); obj.dirty = igl::viewer::ViewerData::DIRTY_ALL; } } } #endif 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."<MatrixXd { return 0.1*C; }; // Specular color should be a less saturated and darker color: dampened // highlights const auto specular = [](const MatrixXd & C)->MatrixXd { const double grey = 0.3; return grey+0.1*(C.array()-grey); }; 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; 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; dirty |= DIRTY_TEXTURE; }