|
@@ -15,60 +15,6 @@
|
|
#include <igl/parula.h>
|
|
#include <igl/parula.h>
|
|
#include <igl/per_vertex_normals.h>
|
|
#include <igl/per_vertex_normals.h>
|
|
|
|
|
|
-#ifdef ENABLE_SERIALIZATION
|
|
|
|
-#include <igl/serialize.h>
|
|
|
|
-namespace igl {
|
|
|
|
- namespace serialization {
|
|
|
|
-
|
|
|
|
- IGL_INLINE void serialization(bool s,igl::viewer::ViewerData& obj,std::vector<char>& 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<char>& buffer)
|
|
|
|
- {
|
|
|
|
- serialization(true,const_cast<igl::viewer::ViewerData&>(obj),buffer);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- template<>
|
|
|
|
- IGL_INLINE void deserialize(igl::viewer::ViewerData& obj,const std::vector<char>& buffer)
|
|
|
|
- {
|
|
|
|
- serialization(false,obj,const_cast<std::vector<char>&>(buffer));
|
|
|
|
- obj.dirty = igl::viewer::ViewerData::DIRTY_ALL;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
IGL_INLINE igl::viewer::ViewerData::ViewerData()
|
|
IGL_INLINE igl::viewer::ViewerData::ViewerData()
|
|
: dirty(DIRTY_ALL)
|
|
: dirty(DIRTY_ALL)
|
|
{
|
|
{
|
|
@@ -164,27 +110,31 @@ IGL_INLINE void igl::viewer::ViewerData::set_colors(const Eigen::MatrixXd &C)
|
|
// Ambient color should be darker color
|
|
// Ambient color should be darker color
|
|
const auto ambient = [](const MatrixXd & C)->MatrixXd
|
|
const auto ambient = [](const MatrixXd & C)->MatrixXd
|
|
{
|
|
{
|
|
- return 0.1*C;
|
|
|
|
|
|
+ MatrixXd T = 0.1*C;
|
|
|
|
+ T.col(3) = C.col(3);
|
|
|
|
+ return T;
|
|
};
|
|
};
|
|
// Specular color should be a less saturated and darker color: dampened
|
|
// Specular color should be a less saturated and darker color: dampened
|
|
// highlights
|
|
// highlights
|
|
const auto specular = [](const MatrixXd & C)->MatrixXd
|
|
const auto specular = [](const MatrixXd & C)->MatrixXd
|
|
{
|
|
{
|
|
const double grey = 0.3;
|
|
const double grey = 0.3;
|
|
- return grey+0.1*(C.array()-grey);
|
|
|
|
|
|
+ MatrixXd T = grey+0.1*(C.array()-grey);
|
|
|
|
+ T.col(3) = C.col(3);
|
|
|
|
+ return T;
|
|
};
|
|
};
|
|
if (C.rows() == 1)
|
|
if (C.rows() == 1)
|
|
{
|
|
{
|
|
for (unsigned i=0;i<V_material_diffuse.rows();++i)
|
|
for (unsigned i=0;i<V_material_diffuse.rows();++i)
|
|
{
|
|
{
|
|
- V_material_diffuse.row(i) = C.row(0);
|
|
|
|
|
|
+ V_material_diffuse.row(i) << C.row(0),1;
|
|
}
|
|
}
|
|
V_material_ambient = ambient(V_material_diffuse);
|
|
V_material_ambient = ambient(V_material_diffuse);
|
|
V_material_specular = specular(V_material_diffuse);
|
|
V_material_specular = specular(V_material_diffuse);
|
|
|
|
|
|
for (unsigned i=0;i<F_material_diffuse.rows();++i)
|
|
for (unsigned i=0;i<F_material_diffuse.rows();++i)
|
|
{
|
|
{
|
|
- F_material_diffuse.row(i) = C.row(0);
|
|
|
|
|
|
+ F_material_diffuse.row(i) << C.row(0),1;
|
|
}
|
|
}
|
|
F_material_ambient = ambient(F_material_diffuse);
|
|
F_material_ambient = ambient(F_material_diffuse);
|
|
F_material_specular = specular(F_material_diffuse);
|
|
F_material_specular = specular(F_material_diffuse);
|
|
@@ -192,14 +142,20 @@ IGL_INLINE void igl::viewer::ViewerData::set_colors(const Eigen::MatrixXd &C)
|
|
else if (C.rows() == V.rows())
|
|
else if (C.rows() == V.rows())
|
|
{
|
|
{
|
|
set_face_based(false);
|
|
set_face_based(false);
|
|
- V_material_diffuse = C;
|
|
|
|
|
|
+ for (unsigned i=0;i<V_material_diffuse.rows();++i)
|
|
|
|
+ {
|
|
|
|
+ V_material_diffuse.row(i) << C.row(i),1;
|
|
|
|
+ }
|
|
V_material_ambient = ambient(V_material_diffuse);
|
|
V_material_ambient = ambient(V_material_diffuse);
|
|
V_material_specular = specular(V_material_diffuse);
|
|
V_material_specular = specular(V_material_diffuse);
|
|
}
|
|
}
|
|
else if (C.rows() == F.rows())
|
|
else if (C.rows() == F.rows())
|
|
{
|
|
{
|
|
set_face_based(true);
|
|
set_face_based(true);
|
|
- F_material_diffuse = C;
|
|
|
|
|
|
+ for (unsigned i=0;i<F_material_diffuse.rows();++i)
|
|
|
|
+ {
|
|
|
|
+ F_material_diffuse.row(i) << C.row(i),1;
|
|
|
|
+ }
|
|
F_material_ambient = ambient(F_material_diffuse);
|
|
F_material_ambient = ambient(F_material_diffuse);
|
|
F_material_specular = specular(F_material_diffuse);
|
|
F_material_specular = specular(F_material_diffuse);
|
|
}
|
|
}
|
|
@@ -239,6 +195,20 @@ IGL_INLINE void igl::viewer::ViewerData::set_texture(
|
|
texture_R = R;
|
|
texture_R = R;
|
|
texture_G = G;
|
|
texture_G = G;
|
|
texture_B = B;
|
|
texture_B = B;
|
|
|
|
+ texture_A = Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>::Constant(R.rows(),R.cols(),255);
|
|
|
|
+ dirty |= DIRTY_TEXTURE;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+IGL_INLINE void igl::viewer::ViewerData::set_texture(
|
|
|
|
+ const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
|
|
|
|
+ const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
|
|
|
|
+ const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
|
|
|
|
+ const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A)
|
|
|
|
+{
|
|
|
|
+ texture_R = R;
|
|
|
|
+ texture_G = G;
|
|
|
|
+ texture_B = B;
|
|
|
|
+ texture_A = A;
|
|
dirty |= DIRTY_TEXTURE;
|
|
dirty |= DIRTY_TEXTURE;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -345,13 +315,13 @@ IGL_INLINE void igl::viewer::ViewerData::clear()
|
|
V = Eigen::MatrixXd (0,3);
|
|
V = Eigen::MatrixXd (0,3);
|
|
F = Eigen::MatrixXi (0,3);
|
|
F = Eigen::MatrixXi (0,3);
|
|
|
|
|
|
- F_material_ambient = Eigen::MatrixXd (0,3);
|
|
|
|
- F_material_diffuse = Eigen::MatrixXd (0,3);
|
|
|
|
- F_material_specular = Eigen::MatrixXd (0,3);
|
|
|
|
|
|
+ F_material_ambient = Eigen::MatrixXd (0,4);
|
|
|
|
+ F_material_diffuse = Eigen::MatrixXd (0,4);
|
|
|
|
+ F_material_specular = Eigen::MatrixXd (0,4);
|
|
|
|
|
|
- V_material_ambient = Eigen::MatrixXd (0,3);
|
|
|
|
- V_material_diffuse = Eigen::MatrixXd (0,3);
|
|
|
|
- V_material_specular = Eigen::MatrixXd (0,3);
|
|
|
|
|
|
+ V_material_ambient = Eigen::MatrixXd (0,4);
|
|
|
|
+ V_material_diffuse = Eigen::MatrixXd (0,4);
|
|
|
|
+ V_material_specular = Eigen::MatrixXd (0,4);
|
|
|
|
|
|
F_normals = Eigen::MatrixXd (0,3);
|
|
F_normals = Eigen::MatrixXd (0,3);
|
|
V_normals = Eigen::MatrixXd (0,3);
|
|
V_normals = Eigen::MatrixXd (0,3);
|
|
@@ -376,9 +346,22 @@ IGL_INLINE void igl::viewer::ViewerData::compute_normals()
|
|
|
|
|
|
IGL_INLINE void igl::viewer::ViewerData::uniform_colors(Eigen::Vector3d ambient, Eigen::Vector3d diffuse, Eigen::Vector3d specular)
|
|
IGL_INLINE void igl::viewer::ViewerData::uniform_colors(Eigen::Vector3d ambient, Eigen::Vector3d diffuse, Eigen::Vector3d specular)
|
|
{
|
|
{
|
|
- V_material_ambient.resize(V.rows(),3);
|
|
|
|
- V_material_diffuse.resize(V.rows(),3);
|
|
|
|
- V_material_specular.resize(V.rows(),3);
|
|
|
|
|
|
+ Eigen::Vector4d ambient4;
|
|
|
|
+ Eigen::Vector4d diffuse4;
|
|
|
|
+ Eigen::Vector4d specular4;
|
|
|
|
+
|
|
|
|
+ ambient4 << ambient, 1;
|
|
|
|
+ diffuse4 << diffuse, 1;
|
|
|
|
+ specular4 << specular, 1;
|
|
|
|
+
|
|
|
|
+ uniform_colors(ambient4,diffuse4,specular4);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+IGL_INLINE void igl::viewer::ViewerData::uniform_colors(Eigen::Vector4d ambient, Eigen::Vector4d diffuse, Eigen::Vector4d specular)
|
|
|
|
+{
|
|
|
|
+ V_material_ambient.resize(V.rows(),4);
|
|
|
|
+ V_material_diffuse.resize(V.rows(),4);
|
|
|
|
+ V_material_specular.resize(V.rows(),4);
|
|
|
|
|
|
for (unsigned i=0; i<V.rows();++i)
|
|
for (unsigned i=0; i<V.rows();++i)
|
|
{
|
|
{
|
|
@@ -387,9 +370,9 @@ IGL_INLINE void igl::viewer::ViewerData::uniform_colors(Eigen::Vector3d ambient,
|
|
V_material_specular.row(i) = specular;
|
|
V_material_specular.row(i) = specular;
|
|
}
|
|
}
|
|
|
|
|
|
- F_material_ambient.resize(F.rows(),3);
|
|
|
|
- F_material_diffuse.resize(F.rows(),3);
|
|
|
|
- F_material_specular.resize(F.rows(),3);
|
|
|
|
|
|
+ F_material_ambient.resize(F.rows(),4);
|
|
|
|
+ F_material_diffuse.resize(F.rows(),4);
|
|
|
|
+ F_material_specular.resize(F.rows(),4);
|
|
|
|
|
|
for (unsigned i=0; i<F.rows();++i)
|
|
for (unsigned i=0; i<F.rows();++i)
|
|
{
|
|
{
|
|
@@ -434,5 +417,6 @@ IGL_INLINE void igl::viewer::ViewerData::grid_texture()
|
|
|
|
|
|
texture_G = texture_R;
|
|
texture_G = texture_R;
|
|
texture_B = texture_R;
|
|
texture_B = texture_R;
|
|
|
|
+ texture_A = Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>::Constant(texture_R.rows(),texture_R.cols(),255);
|
|
dirty |= DIRTY_TEXTURE;
|
|
dirty |= DIRTY_TEXTURE;
|
|
}
|
|
}
|