libigl v2.5.0
Loading...
Searching...
No Matches
ViewerData.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
4//
5// This Source Code Form is subject to the terms of the Mozilla Public License
6// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7// obtain one at http://mozilla.org/MPL/2.0/.
8#ifndef IGL_VIEWERDATA_H
9#define IGL_VIEWERDATA_H
10
11#include "MeshGL.h"
12#include "../igl_inline.h"
13#include "../colormap.h"
14#include <cassert>
15#include <cstdint>
16#include <Eigen/Core>
17#include <memory>
18#include <vector>
19
20namespace igl
21{
22
23namespace opengl
24{
25
26class ViewerCore;
27
39{
40public:
42
45
50 IGL_INLINE void set_face_based(bool newvalue);
51
57 IGL_INLINE void set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
62 IGL_INLINE void set_vertices(const Eigen::MatrixXd& V);
68 IGL_INLINE void set_normals(const Eigen::MatrixXd& N);
72 IGL_INLINE void set_visible(bool value, unsigned int core_id = 1);
73
78 IGL_INLINE void set_colors(const Eigen::MatrixXd &C);
79
83 IGL_INLINE void set_uv(const Eigen::MatrixXd& UV);
84
89 IGL_INLINE void set_uv(const Eigen::MatrixXd& UV_V, const Eigen::MatrixXi& UV_F);
90
99 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
100 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
101 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
102 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
105 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
106 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
107 const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B);
108
117 const Eigen::VectorXd & D,
118 double caxis_min,
119 double caxis_max,
121 int num_steps = 21);
122
125 IGL_INLINE void set_data(const Eigen::VectorXd & D,
127 int num_steps = 21);
128
133 IGL_INLINE void set_colormap(const Eigen::MatrixXd & CM);
134
141 const Eigen::MatrixXd& P,
142 const Eigen::MatrixXd& C);
143
148 IGL_INLINE void add_points(const Eigen::MatrixXd& P, const Eigen::MatrixXd& C);
149
152
159 IGL_INLINE void set_edges (const Eigen::MatrixXd& P, const Eigen::MatrixXi& E, const Eigen::MatrixXd& C);
167 IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C);
174 const Eigen::MatrixXd& P,
175 const Eigen::MatrixXd& V,
176 const Eigen::MatrixXd& C);
177
180
185 IGL_INLINE void set_labels (const Eigen::MatrixXd& P, const std::vector<std::string>& str);
189 IGL_INLINE void add_label (const Eigen::VectorXd& P, const std::string& str);
190
193
196
202 const Eigen::Vector3d& ambient,
203 const Eigen::Vector3d& diffuse,
204 const Eigen::Vector3d& specular);
207 const Eigen::Vector4d& ambient,
208 const Eigen::Vector4d& diffuse,
209 const Eigen::Vector4d& specular);
210
213
216
220 IGL_INLINE void copy_options(const ViewerCore &from, const ViewerCore &to);
221
223 Eigen::MatrixXd V;
225 Eigen::MatrixXi F;
226
227 // Per face attributes
229 Eigen::MatrixXd F_normals;
230
232 Eigen::MatrixXd F_material_ambient;
234 Eigen::MatrixXd F_material_diffuse;
236 Eigen::MatrixXd F_material_specular;
237
238 // Per vertex attributes
240 Eigen::MatrixXd V_normals;
241
243 Eigen::MatrixXd V_material_ambient;
245 Eigen::MatrixXd V_material_diffuse;
247 Eigen::MatrixXd V_material_specular;
248
249 // UV parametrization
251 Eigen::MatrixXd V_uv;
253 Eigen::MatrixXi F_uv;
254
255 // Texture
257 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_R;
259 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_G;
261 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_B;
263 Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_A;
264
265 // Overlays
266
269 // with S and T the coordinates of the two vertices of the line in global coordinates, and C the color in floating point rgb format
270 Eigen::MatrixXd lines;
271
275 Eigen::MatrixXd points;
276
277 // Text labels plotted over the scene
278 // Textp contains, in the i-th row, the position in global coordinates where the i-th label should be anchored
279 // Texts contains in the i-th position the text of the i-th label
281 Eigen::MatrixXd vertex_labels_positions;
283 Eigen::MatrixXd face_labels_positions;
285 Eigen::MatrixXd labels_positions;
287 std::vector<std::string> vertex_labels_strings;
289 std::vector<std::string> face_labels_strings;
291 std::vector<std::string> labels_strings;
292
294 uint32_t dirty;
295
298
301
304
308 unsigned int is_visible;
309 unsigned int show_custom_labels;
310 unsigned int show_face_labels;
311 unsigned int show_faces;
312 unsigned int show_lines;
313 unsigned int show_overlay;
314 unsigned int show_overlay_depth;
315 unsigned int show_texture;
316 unsigned int show_vertex_labels;
317 unsigned int use_matcap;
318
326 Eigen::Matrix<float, 4, 1, Eigen::DontAlign> line_color;
328 Eigen::Matrix<float, 4, 1, Eigen::DontAlign> label_color;
329
333
335 int id;
336
339
347 const Eigen::MatrixXd& positions,
348 const std::vector<std::string>& strings
349 );
355 const igl::opengl::ViewerData& data,
356 const bool invert_normals,
358 };
359
360} // namespace opengl
361} // namespace igl
362
364
365#include "../serialize.h"
366namespace igl
367{
368 namespace serialization
369 {
370 inline void serialization(bool s, igl::opengl::ViewerData& obj, std::vector<char>& buffer)
371 {
374 SERIALIZE_MEMBER(F_normals);
375 SERIALIZE_MEMBER(F_material_ambient);
376 SERIALIZE_MEMBER(F_material_diffuse);
377 SERIALIZE_MEMBER(F_material_specular);
378 SERIALIZE_MEMBER(V_normals);
379 SERIALIZE_MEMBER(V_material_ambient);
380 SERIALIZE_MEMBER(V_material_diffuse);
381 SERIALIZE_MEMBER(V_material_specular);
382 SERIALIZE_MEMBER(V_uv);
383 SERIALIZE_MEMBER(F_uv);
384 SERIALIZE_MEMBER(texture_R);
385 SERIALIZE_MEMBER(texture_G);
386 SERIALIZE_MEMBER(texture_B);
387 SERIALIZE_MEMBER(texture_A);
388 SERIALIZE_MEMBER(lines);
389 SERIALIZE_MEMBER(points);
390 SERIALIZE_MEMBER(labels_positions);
391 SERIALIZE_MEMBER(labels_strings);
392 SERIALIZE_MEMBER(dirty);
393 SERIALIZE_MEMBER(face_based);
394 SERIALIZE_MEMBER(show_faces);
395 SERIALIZE_MEMBER(show_lines);
396 SERIALIZE_MEMBER(invert_normals);
397 SERIALIZE_MEMBER(show_overlay);
398 SERIALIZE_MEMBER(show_overlay_depth);
399 SERIALIZE_MEMBER(show_vertex_labels);
400 SERIALIZE_MEMBER(show_face_labels);
401 SERIALIZE_MEMBER(show_custom_labels);
402 SERIALIZE_MEMBER(show_texture);
403 SERIALIZE_MEMBER(double_sided);
404 SERIALIZE_MEMBER(point_size);
405 SERIALIZE_MEMBER(line_width);
406 SERIALIZE_MEMBER(line_color);
407 SERIALIZE_MEMBER(shininess);
409 }
410 template<>
411 inline void serialize(const igl::opengl::ViewerData& obj, std::vector<char>& buffer)
412 {
413 serialization(true, const_cast<igl::opengl::ViewerData&>(obj), buffer);
414 }
415 template<>
416 inline void deserialize(igl::opengl::ViewerData& obj, const std::vector<char>& buffer)
417 {
418 serialization(false, obj, const_cast<std::vector<char>&>(buffer));
420 }
421 }
422}
423
424#ifndef IGL_STATIC_LIBRARY
425# include "ViewerData.cpp"
426#endif
427
428#endif
Coverts mesh data inside a igl::ViewerData class in an OpenGL compatible format The class includes a ...
Definition MeshGL.h:24
@ DIRTY_ALL
Definition MeshGL.h:48
Basic class of the 3D mesh viewer.
Definition ViewerCore.h:27
Object being drawn (i.e., mesh and its accessories) by the ViewerCore.
Definition ViewerData.h:39
bool double_sided
Enable double-sided lighting on faces.
Definition ViewerData.h:300
void clear()
Empty all fields.
Eigen::MatrixXd points
Points plotted over the scene (Every row contains 6 doubles in the following format P_x,...
Definition ViewerData.h:275
void set_colormap(const Eigen::MatrixXd &CM)
Not to be confused with set_colors, this creates a texture that will be referenced to pseudocolor acc...
void normal_matcap()
Generate a normal image matcap.
void updateGL(const igl::opengl::ViewerData &data, const bool invert_normals, igl::opengl::MeshGL &meshgl)
Update the meshgl object.
void uniform_colors(const Eigen::Vector3d &ambient, const Eigen::Vector3d &diffuse, const Eigen::Vector3d &specular)
Assigns uniform colors to all faces/vertices.
std::vector< std::string > face_labels_strings
Text strings of labels at faces.
Definition ViewerData.h:289
Eigen::MatrixXd V_material_specular
Per vertex specular color.
Definition ViewerData.h:247
void set_edges(const Eigen::MatrixXd &P, const Eigen::MatrixXi &E, const Eigen::MatrixXd &C)
Sets edges given a list of edge vertices and edge indices.
Eigen::MatrixXd V
Vertices of the current mesh (V x 3)
Definition ViewerData.h:223
bool invert_normals
Invert mesh normals.
Definition ViewerData.h:303
void set_edges_from_vector_field(const Eigen::MatrixXd &P, const Eigen::MatrixXd &V, const Eigen::MatrixXd &C)
Sets edges given a list of points and eminating vectors.
void update_labels(igl::opengl::MeshGL::TextGL &GL_labels, const Eigen::MatrixXd &positions, const std::vector< std::string > &strings)
Update contents from a 'Data' instance.
void set_uv(const Eigen::MatrixXd &UV_V, const Eigen::MatrixXi &UV_F)
Set per-corner UV coordinates.
uint32_t dirty
Marks dirty buffers that need to be uploaded to OpenGL.
Definition ViewerData.h:294
void 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)
Set the texture associated with the mesh.
unsigned int show_faces
Definition ViewerData.h:311
float shininess
Shape material shininess.
Definition ViewerData.h:332
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_G
Texture green colors.
Definition ViewerData.h:259
igl::opengl::MeshGL meshgl
OpenGL representation of the mesh.
Definition ViewerData.h:338
Eigen::Matrix< float, 4, 1, Eigen::DontAlign > label_color
Color of labels.
Definition ViewerData.h:328
Eigen::MatrixXd V_material_ambient
Per vertex ambient color.
Definition ViewerData.h:243
float label_size
Size of lables.
Definition ViewerData.h:324
void add_points(const Eigen::MatrixXd &P, const Eigen::MatrixXd &C)
Add points given a list of point vertices.
Eigen::MatrixXd V_normals
One normal per vertex.
Definition ViewerData.h:240
std::vector< std::string > vertex_labels_strings
Text strings of labels at vertices.
Definition ViewerData.h:287
void set_uv(const Eigen::MatrixXd &UV)
Set per-vertex UV coordinates.
Eigen::MatrixXd V_material_diffuse
Per vertex diffuse color.
Definition ViewerData.h:245
void compute_normals()
Computes the normals of the mesh.
void 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)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void add_label(const Eigen::VectorXd &P, const std::string &str)
Sets / Adds text labels at the given positions in 3D.
bool face_based
Enable per-face or per-vertex properties.
Definition ViewerData.h:297
void set_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
Set the current mesh.
Eigen::MatrixXd F_material_diffuse
Per face diffuse color.
Definition ViewerData.h:234
unsigned int use_matcap
Definition ViewerData.h:317
void set_face_based(bool newvalue)
Change whether drawing per-vertex or per-face; invalidating cache if necessary.
Eigen::MatrixXd vertex_labels_positions
Text positions of vertices.
Definition ViewerData.h:281
void clear_points()
Clear the point data.
void set_vertices(const Eigen::MatrixXd &V)
Set just the vertices.
void set_labels(const Eigen::MatrixXd &P, const std::vector< std::string > &str)
Sets / Adds text labels at the given positions in 3D.
unsigned int show_overlay_depth
Definition ViewerData.h:314
float line_width
line_width is NOT SUPPORTED on Mac OS and Windows
Definition ViewerData.h:322
Eigen::Matrix< float, 4, 1, Eigen::DontAlign > line_color
Color of lines.
Definition ViewerData.h:326
void set_data(const Eigen::VectorXd &D, double caxis_min, double caxis_max, igl::ColorMapType cmap=igl::COLOR_MAP_TYPE_VIRIDIS, int num_steps=21)
Set pseudo-color-able scalar data associated with the mesh.
Eigen::MatrixXd face_labels_positions
Text positions of faces.
Definition ViewerData.h:283
unsigned int show_custom_labels
Definition ViewerData.h:309
unsigned int show_texture
Definition ViewerData.h:315
void copy_options(const ViewerCore &from, const ViewerCore &to)
Copy visualization options from one viewport to another.
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_R
Texture red colors.
Definition ViewerData.h:257
Eigen::MatrixXd F_material_specular
Per face specular color.
Definition ViewerData.h:236
void set_colors(const Eigen::MatrixXd &C)
Set the diffuse color of the mesh.
int id
Unique identifier.
Definition ViewerData.h:335
void add_edges(const Eigen::MatrixXd &P1, const Eigen::MatrixXd &P2, const Eigen::MatrixXd &C)
Add edges given a list of edge start and end positions and colors.
void clear_labels()
Clear the label data.
Eigen::MatrixXd labels_positions
Text positions of labels.
Definition ViewerData.h:285
void grid_texture()
Generates a default grid texture (without uvs)
Eigen::MatrixXi F
Faces of the mesh (F x 3)
Definition ViewerData.h:225
Eigen::MatrixXd V_uv
UV vertices.
Definition ViewerData.h:251
Eigen::MatrixXi F_uv
optional faces for UVs
Definition ViewerData.h:253
void set_normals(const Eigen::MatrixXd &N)
Set the normals of a mesh.
void set_points(const Eigen::MatrixXd &P, const Eigen::MatrixXd &C)
Sets points given a list of point vertices.
unsigned int show_overlay
Definition ViewerData.h:313
std::vector< std::string > labels_strings
Text strings of labels.
Definition ViewerData.h:291
void set_visible(bool value, unsigned int core_id=1)
Set whether this object is visible.
unsigned int show_vertex_labels
Definition ViewerData.h:316
float point_size
Point size / line width.
Definition ViewerData.h:320
Eigen::MatrixXd F_normals
One normal per face.
Definition ViewerData.h:229
unsigned int show_face_labels
Definition ViewerData.h:310
void clear_edges()
Clear the edge data.
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_B
Texture blue colors.
Definition ViewerData.h:261
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_A
Texture alpha values.
Definition ViewerData.h:263
void uniform_colors(const Eigen::Vector4d &ambient, const Eigen::Vector4d &diffuse, const Eigen::Vector4d &specular)
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int show_lines
Definition ViewerData.h:312
void set_data(const Eigen::VectorXd &D, igl::ColorMapType cmap=igl::COLOR_MAP_TYPE_VIRIDIS, int num_steps=21)
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int is_visible
Visualization options Each option is a binary mask specifying on which viewport each option is set.
Definition ViewerData.h:308
Eigen::MatrixXd F_material_ambient
Per face ambient color.
Definition ViewerData.h:232
Eigen::MatrixXd lines
Lines plotted over the scene (Every row contains 9 doubles in the following format S_x,...
Definition ViewerData.h:270
#define IGL_INLINE
Definition igl_inline.h:15
void serialization(bool s, igl::opengl::ViewerCore &obj, std::vector< char > &buffer)
Definition ViewerCore.h:244
void deserialize(igl::opengl::ViewerCore &obj, const std::vector< char > &buffer)
Definition ViewerCore.h:286
void serialize(const igl::opengl::ViewerCore &obj, std::vector< char > &buffer)
Definition ViewerCore.h:280
Definition AABB.h:17
ColorMapType
Definition colormap.h:19
@ COLOR_MAP_TYPE_VIRIDIS
Definition colormap.h:25
#define SERIALIZE_MEMBER(Object)
Definition serialize.h:68
Definition MeshGL.h:106