Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
igl::opengl::ViewerData Class Reference

#include <src/libigl/igl/opengl/ViewerData.h>

+ Collaboration diagram for igl::opengl::ViewerData:

Public Member Functions

 ViewerData ()
 
IGL_INLINE void clear ()
 
IGL_INLINE void set_face_based (bool newvalue)
 
IGL_INLINE void set_mesh (const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
 
IGL_INLINE void set_vertices (const Eigen::MatrixXd &V)
 
IGL_INLINE void set_normals (const Eigen::MatrixXd &N)
 
IGL_INLINE void set_colors (const Eigen::MatrixXd &C)
 
IGL_INLINE void set_uv (const Eigen::MatrixXd &UV)
 
IGL_INLINE void set_uv (const Eigen::MatrixXd &UV_V, const Eigen::MatrixXi &UV_F)
 
IGL_INLINE 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)
 
IGL_INLINE 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)
 
IGL_INLINE void set_points (const Eigen::MatrixXd &P, const Eigen::MatrixXd &C)
 
IGL_INLINE void add_points (const Eigen::MatrixXd &P, const Eigen::MatrixXd &C)
 
IGL_INLINE void set_edges (const Eigen::MatrixXd &P, const Eigen::MatrixXi &E, const Eigen::MatrixXd &C)
 
IGL_INLINE void add_edges (const Eigen::MatrixXd &P1, const Eigen::MatrixXd &P2, const Eigen::MatrixXd &C)
 
IGL_INLINE void add_label (const Eigen::VectorXd &P, const std::string &str)
 
IGL_INLINE void compute_normals ()
 
IGL_INLINE void uniform_colors (const Eigen::Vector3d &diffuse, const Eigen::Vector3d &ambient, const Eigen::Vector3d &specular)
 
IGL_INLINE void uniform_colors (const Eigen::Vector4d &ambient, const Eigen::Vector4d &diffuse, const Eigen::Vector4d &specular)
 
IGL_INLINE void grid_texture ()
 
IGL_INLINE void updateGL (const igl::opengl::ViewerData &data, const bool invert_normals, igl::opengl::MeshGL &meshgl)
 

Public Attributes

Eigen::MatrixXd V
 
Eigen::MatrixXi F
 
Eigen::MatrixXd F_normals
 
Eigen::MatrixXd F_material_ambient
 
Eigen::MatrixXd F_material_diffuse
 
Eigen::MatrixXd F_material_specular
 
Eigen::MatrixXd V_normals
 
Eigen::MatrixXd V_material_ambient
 
Eigen::MatrixXd V_material_diffuse
 
Eigen::MatrixXd V_material_specular
 
Eigen::MatrixXd V_uv
 
Eigen::MatrixXi F_uv
 
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamictexture_R
 
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamictexture_G
 
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamictexture_B
 
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamictexture_A
 
Eigen::MatrixXd lines
 
Eigen::MatrixXd points
 
Eigen::MatrixXd labels_positions
 
std::vector< std::string > labels_strings
 
uint32_t dirty
 
bool face_based
 
bool show_overlay
 
bool show_overlay_depth
 
bool show_texture
 
bool show_faces
 
bool show_lines
 
bool show_vertid
 
bool show_faceid
 
bool invert_normals
 
float point_size
 
float line_width
 
Eigen::Vector4f line_color
 
float shininess
 
int id
 
igl::opengl::MeshGL meshgl
 

Detailed Description

Constructor & Destructor Documentation

◆ ViewerData()

IGL_INLINE igl::opengl::ViewerData::ViewerData ( )
21 show_faces(true),
22 show_lines(true),
23 invert_normals(false),
24 show_overlay(true),
26 show_vertid(false),
27 show_faceid(false),
28 show_texture(false),
29 point_size(30),
30 line_width(0.5f),
31 line_color(0,0,0,1),
32 shininess(35.0f),
33 id(-1)
34{
35 clear();
36};
@ DIRTY_ALL
Definition MeshGL.h:42
bool invert_normals
Definition ViewerData.h:187
uint32_t dirty
Definition ViewerData.h:174
bool show_faceid
Definition ViewerData.h:186
float shininess
Definition ViewerData.h:195
bool show_texture
Definition ViewerData.h:182
bool show_overlay
Definition ViewerData.h:180
float line_width
Definition ViewerData.h:191
bool show_vertid
Definition ViewerData.h:185
int id
Definition ViewerData.h:198
Eigen::Vector4f line_color
Definition ViewerData.h:192
bool show_overlay_depth
Definition ViewerData.h:181
float point_size
Definition ViewerData.h:190
bool show_lines
Definition ViewerData.h:184
IGL_INLINE void clear()
Definition ViewerData.cpp:340
bool show_faces
Definition ViewerData.h:183

References clear().

+ Here is the call graph for this function:

Member Function Documentation

◆ add_edges()

IGL_INLINE void igl::opengl::ViewerData::add_edges ( const Eigen::MatrixXd &  P1,
const Eigen::MatrixXd &  P2,
const Eigen::MatrixXd &  C 
)
296{
297 Eigen::MatrixXd P1_temp,P2_temp;
298
299 // If P1 only has two columns, pad with a column of zeros
300 if (P1.cols() == 2)
301 {
302 P1_temp = Eigen::MatrixXd::Zero(P1.rows(),3);
303 P1_temp.block(0,0,P1.rows(),2) = P1;
304 P2_temp = Eigen::MatrixXd::Zero(P2.rows(),3);
305 P2_temp.block(0,0,P2.rows(),2) = P2;
306 }
307 else
308 {
309 P1_temp = P1;
310 P2_temp = P2;
311 }
312
313 int lastid = lines.rows();
314 lines.conservativeResize(lines.rows() + P1_temp.rows(),9);
315 for (unsigned i=0; i<P1_temp.rows(); ++i)
316 lines.row(lastid+i) << P1_temp.row(i), P2_temp.row(i), i<C.rows() ? C.row(i) : C.row(C.rows()-1);
317
319}
@ DIRTY_OVERLAY_LINES
Definition MeshGL.h:40
Eigen::MatrixXd lines
Definition ViewerData.h:160

References igl::opengl::MeshGL::DIRTY_OVERLAY_LINES.

◆ add_label()

IGL_INLINE void igl::opengl::ViewerData::add_label ( const Eigen::VectorXd &  P,
const std::string &  str 
)
322{
323 Eigen::RowVectorXd P_temp;
324
325 // If P only has two columns, pad with a column of zeros
326 if (P.size() == 2)
327 {
328 P_temp = Eigen::RowVectorXd::Zero(3);
329 P_temp << P.transpose(), 0;
330 }
331 else
332 P_temp = P;
333
334 int lastid = labels_positions.rows();
335 labels_positions.conservativeResize(lastid+1, 3);
336 labels_positions.row(lastid) = P_temp;
337 labels_strings.push_back(str);
338}
Eigen::MatrixXd labels_positions
Definition ViewerData.h:170
std::vector< std::string > labels_strings
Definition ViewerData.h:171

◆ add_points()

IGL_INLINE void igl::opengl::ViewerData::add_points ( const Eigen::MatrixXd &  P,
const Eigen::MatrixXd &  C 
)
252{
253 Eigen::MatrixXd P_temp;
254
255 // If P only has two columns, pad with a column of zeros
256 if (P.cols() == 2)
257 {
258 P_temp = Eigen::MatrixXd::Zero(P.rows(),3);
259 P_temp.block(0,0,P.rows(),2) = P;
260 }
261 else
262 P_temp = P;
263
264 int lastid = points.rows();
265 points.conservativeResize(points.rows() + P_temp.rows(),6);
266 for (unsigned i=0; i<P_temp.rows(); ++i)
267 points.row(lastid+i) << P_temp.row(i), i<C.rows() ? C.row(i) : C.row(C.rows()-1);
268
270}
@ DIRTY_OVERLAY_POINTS
Definition MeshGL.h:41
Eigen::MatrixXd points
Definition ViewerData.h:165

References igl::opengl::MeshGL::DIRTY_OVERLAY_POINTS.

◆ clear()

IGL_INLINE void igl::opengl::ViewerData::clear ( )
341{
342 V = Eigen::MatrixXd (0,3);
343 F = Eigen::MatrixXi (0,3);
344
345 F_material_ambient = Eigen::MatrixXd (0,4);
346 F_material_diffuse = Eigen::MatrixXd (0,4);
347 F_material_specular = Eigen::MatrixXd (0,4);
348
349 V_material_ambient = Eigen::MatrixXd (0,4);
350 V_material_diffuse = Eigen::MatrixXd (0,4);
351 V_material_specular = Eigen::MatrixXd (0,4);
352
353 F_normals = Eigen::MatrixXd (0,3);
354 V_normals = Eigen::MatrixXd (0,3);
355
356 V_uv = Eigen::MatrixXd (0,2);
357 F_uv = Eigen::MatrixXi (0,3);
358
359 lines = Eigen::MatrixXd (0,9);
360 points = Eigen::MatrixXd (0,6);
361 labels_positions = Eigen::MatrixXd (0,3);
362 labels_strings.clear();
363
364 face_based = false;
365}
Eigen::MatrixXd V_material_specular
Definition ViewerData.h:143
Eigen::MatrixXd V
Definition ViewerData.h:128
Eigen::MatrixXd V_material_ambient
Definition ViewerData.h:141
Eigen::MatrixXd V_normals
Definition ViewerData.h:139
Eigen::MatrixXd V_material_diffuse
Definition ViewerData.h:142
bool face_based
Definition ViewerData.h:177
Eigen::MatrixXd F_material_diffuse
Definition ViewerData.h:135
Eigen::MatrixXd F_material_specular
Definition ViewerData.h:136
Eigen::MatrixXi F
Definition ViewerData.h:129
Eigen::MatrixXd V_uv
Definition ViewerData.h:146
Eigen::MatrixXi F_uv
Definition ViewerData.h:147
Eigen::MatrixXd F_normals
Definition ViewerData.h:132
Eigen::MatrixXd F_material_ambient
Definition ViewerData.h:134

Referenced by ViewerData(), and igl::opengl::glfw::Viewer::load_mesh_from_file().

+ Here is the caller graph for this function:

◆ compute_normals()

IGL_INLINE void igl::opengl::ViewerData::compute_normals ( )
368{
372}
@ DIRTY_NORMAL
Definition MeshGL.h:33
IGL_INLINE void per_vertex_normals(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedF > &F, const igl::PerVertexNormalsWeightingType weighting, Eigen::PlainObjectBase< DerivedN > &N)
Definition per_vertex_normals.cpp:20
IGL_INLINE void per_face_normals(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedF > &F, const Eigen::MatrixBase< DerivedZ > &Z, Eigen::PlainObjectBase< DerivedN > &N)
Definition per_face_normals.cpp:13

References igl::opengl::MeshGL::DIRTY_NORMAL, igl::per_face_normals(), and igl::per_vertex_normals().

Referenced by igl::opengl::glfw::Viewer::load_mesh_from_file().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grid_texture()

IGL_INLINE void igl::opengl::ViewerData::grid_texture ( )
420{
421 // Don't do anything for an empty mesh
422 if(V.rows() == 0)
423 {
424 V_uv.resize(V.rows(),2);
425 return;
426 }
427 if (V_uv.rows() == 0)
428 {
429 V_uv = V.block(0, 0, V.rows(), 2);
430 V_uv.col(0) = V_uv.col(0).array() - V_uv.col(0).minCoeff();
431 V_uv.col(0) = V_uv.col(0).array() / V_uv.col(0).maxCoeff();
432 V_uv.col(1) = V_uv.col(1).array() - V_uv.col(1).minCoeff();
433 V_uv.col(1) = V_uv.col(1).array() / V_uv.col(1).maxCoeff();
434 V_uv = V_uv.array() * 10;
436 }
437
438 unsigned size = 128;
439 unsigned size2 = size/2;
440 texture_R.resize(size, size);
441 for (unsigned i=0; i<size; ++i)
442 {
443 for (unsigned j=0; j<size; ++j)
444 {
445 texture_R(i,j) = 0;
446 if ((i<size2 && j<size2) || (i>=size2 && j>=size2))
447 texture_R(i,j) = 255;
448 }
449 }
450
455}
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
Definition PlainObjectBase.h:153
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition PlainObjectBase.h:279
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
Definition PlainObjectBase.h:151
@ DIRTY_TEXTURE
Definition MeshGL.h:37
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_G
Definition ViewerData.h:151
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_R
Definition ViewerData.h:150
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_B
Definition ViewerData.h:152
Eigen::Matrix< unsigned char, Eigen::Dynamic, Eigen::Dynamic > texture_A
Definition ViewerData.h:153
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183

References igl::opengl::MeshGL::DIRTY_TEXTURE.

Referenced by igl::opengl::glfw::Viewer::load_mesh_from_file().

+ Here is the caller graph for this function:

◆ set_colors()

IGL_INLINE void igl::opengl::ViewerData::set_colors ( const Eigen::MatrixXd &  C)
116{
117 using namespace std;
118 using namespace Eigen;
119 if(C.rows()>0 && C.cols() == 1)
120 {
121 Eigen::MatrixXd C3;
122 igl::parula(C,true,C3);
123 return set_colors(C3);
124 }
125 // Ambient color should be darker color
126 const auto ambient = [](const MatrixXd & C)->MatrixXd
127 {
128 MatrixXd T = 0.1*C;
129 T.col(3) = C.col(3);
130 return T;
131 };
132 // Specular color should be a less saturated and darker color: dampened
133 // highlights
134 const auto specular = [](const MatrixXd & C)->MatrixXd
135 {
136 const double grey = 0.3;
137 MatrixXd T = grey+0.1*(C.array()-grey);
138 T.col(3) = C.col(3);
139 return T;
140 };
141 if (C.rows() == 1)
142 {
143 for (unsigned i=0;i<V_material_diffuse.rows();++i)
144 {
145 if (C.cols() == 3)
146 V_material_diffuse.row(i) << C.row(0),1;
147 else if (C.cols() == 4)
148 V_material_diffuse.row(i) << C.row(0);
149 }
152
153 for (unsigned i=0;i<F_material_diffuse.rows();++i)
154 {
155 if (C.cols() == 3)
156 F_material_diffuse.row(i) << C.row(0),1;
157 else if (C.cols() == 4)
158 F_material_diffuse.row(i) << C.row(0);
159 }
162 }
163 else if (C.rows() == V.rows())
164 {
165 set_face_based(false);
166 for (unsigned i=0;i<V_material_diffuse.rows();++i)
167 {
168 if (C.cols() == 3)
169 V_material_diffuse.row(i) << C.row(i), 1;
170 else if (C.cols() == 4)
171 V_material_diffuse.row(i) << C.row(i);
172 }
175 }
176 else if (C.rows() == F.rows())
177 {
178 set_face_based(true);
179 for (unsigned i=0;i<F_material_diffuse.rows();++i)
180 {
181 if (C.cols() == 3)
182 F_material_diffuse.row(i) << C.row(i), 1;
183 else if (C.cols() == 4)
184 F_material_diffuse.row(i) << C.row(i);
185 }
188 }
189 else
190 cerr << "ERROR (set_colors): Please provide a single color, or a color per face or per vertex."<<endl;
192
193}
@ DIRTY_DIFFUSE
Definition MeshGL.h:35
IGL_INLINE void set_face_based(bool newvalue)
Definition ViewerData.cpp:38
IGL_INLINE void set_colors(const Eigen::MatrixXd &C)
Definition ViewerData.cpp:115
Definition LDLT.h:16
IGL_INLINE void parula(const T f, T *rgb)
Definition parula.cpp:12
STL namespace.

References igl::opengl::MeshGL::DIRTY_DIFFUSE, and igl::parula().

+ Here is the call graph for this function:

◆ set_edges()

IGL_INLINE void igl::opengl::ViewerData::set_edges ( const Eigen::MatrixXd &  P,
const Eigen::MatrixXi &  E,
const Eigen::MatrixXd &  C 
)
276{
277 using namespace Eigen;
278 lines.resize(E.rows(),9);
279 assert(C.cols() == 3);
280 for(int e = 0;e<E.rows();e++)
281 {
282 RowVector3d color;
283 if(C.size() == 3)
284 {
285 color<<C;
286 }else if(C.rows() == E.rows())
287 {
288 color<<C.row(e);
289 }
290 lines.row(e)<< P.row(E(e,0)), P.row(E(e,1)), color;
291 }
293}
@ E
Definition libslic3r.h:101

References igl::opengl::MeshGL::DIRTY_OVERLAY_LINES.

◆ set_face_based()

IGL_INLINE void igl::opengl::ViewerData::set_face_based ( bool  newvalue)
39{
40 if (face_based != newvalue)
41 {
42 face_based = newvalue;
44 }
45}

References igl::opengl::MeshGL::DIRTY_ALL.

Referenced by igl::opengl::glfw::Viewer::Viewer(), igl::opengl::glfw::imgui::ImGuiMenu::draw_viewer_menu(), and igl::opengl::glfw::Viewer::key_pressed().

+ Here is the caller graph for this function:

◆ set_mesh()

IGL_INLINE void igl::opengl::ViewerData::set_mesh ( const Eigen::MatrixXd &  V,
const Eigen::MatrixXi &  F 
)
50{
51 using namespace std;
52
53 Eigen::MatrixXd V_temp;
54
55 // If V only has two columns, pad with a column of zeros
56 if (_V.cols() == 2)
57 {
58 V_temp = Eigen::MatrixXd::Zero(_V.rows(),3);
59 V_temp.block(0,0,_V.rows(),2) = _V;
60 }
61 else
62 V_temp = _V;
63
64 if (V.rows() == 0 && F.rows() == 0)
65 {
66 V = V_temp;
67 F = _F;
68
71 Eigen::Vector3d(GOLD_AMBIENT[0], GOLD_AMBIENT[1], GOLD_AMBIENT[2]),
72 Eigen::Vector3d(GOLD_DIFFUSE[0], GOLD_DIFFUSE[1], GOLD_DIFFUSE[2]),
73 Eigen::Vector3d(GOLD_SPECULAR[0], GOLD_SPECULAR[1], GOLD_SPECULAR[2]));
74
76 }
77 else
78 {
79 if (_V.rows() == V.rows() && _F.rows() == F.rows())
80 {
81 V = V_temp;
82 F = _F;
83 }
84 else
85 cerr << "ERROR (set_mesh): The new mesh has a different number of vertices/faces. Please clear the mesh before plotting."<<endl;
86 }
88}
@ DIRTY_FACE
Definition MeshGL.h:38
@ DIRTY_POSITION
Definition MeshGL.h:31
IGL_INLINE void compute_normals()
Definition ViewerData.cpp:367
IGL_INLINE void grid_texture()
Definition ViewerData.cpp:419
IGL_INLINE void uniform_colors(const Eigen::Vector3d &diffuse, const Eigen::Vector3d &ambient, const Eigen::Vector3d &specular)
Definition ViewerData.cpp:374
const float GOLD_AMBIENT[4]
Definition material_colors.h:16
const float GOLD_SPECULAR[4]
Definition material_colors.h:18
const float GOLD_DIFFUSE[4]
Definition material_colors.h:17

References igl::opengl::MeshGL::DIRTY_FACE, igl::opengl::MeshGL::DIRTY_POSITION, igl::GOLD_AMBIENT, igl::GOLD_DIFFUSE, and igl::GOLD_SPECULAR.

Referenced by igl::opengl::glfw::Viewer::load_mesh_from_file().

+ Here is the caller graph for this function:

◆ set_normals()

IGL_INLINE void igl::opengl::ViewerData::set_normals ( const Eigen::MatrixXd &  N)
98{
99 using namespace std;
100 if (N.rows() == V.rows())
101 {
102 set_face_based(false);
103 V_normals = N;
104 }
105 else if (N.rows() == F.rows() || N.rows() == F.rows()*3)
106 {
107 set_face_based(true);
108 F_normals = N;
109 }
110 else
111 cerr << "ERROR (set_normals): Please provide a normal per face, per corner or per vertex."<<endl;
113}

References igl::opengl::MeshGL::DIRTY_NORMAL.

◆ set_points()

IGL_INLINE void igl::opengl::ViewerData::set_points ( const Eigen::MatrixXd &  P,
const Eigen::MatrixXd &  C 
)
245{
246 // clear existing points
247 points.resize(0,0);
248 add_points(P,C);
249}
IGL_INLINE void add_points(const Eigen::MatrixXd &P, const Eigen::MatrixXd &C)
Definition ViewerData.cpp:251

◆ set_texture() [1/2]

IGL_INLINE void igl::opengl::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 
)

References Eigen::PlainObjectBase< Derived >::cols(), igl::opengl::MeshGL::DIRTY_TEXTURE, and Eigen::PlainObjectBase< Derived >::rows().

+ Here is the call graph for this function:

◆ set_texture() [2/2]

IGL_INLINE void igl::opengl::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 
)
234{
235 texture_R = R;
236 texture_G = G;
237 texture_B = B;
238 texture_A = A;
240}

References igl::opengl::MeshGL::DIRTY_TEXTURE.

◆ set_uv() [1/2]

IGL_INLINE void igl::opengl::ViewerData::set_uv ( const Eigen::MatrixXd &  UV)
196{
197 using namespace std;
198 if (UV.rows() == V.rows())
199 {
200 set_face_based(false);
201 V_uv = UV;
202 }
203 else
204 cerr << "ERROR (set_UV): Please provide uv per vertex."<<endl;;
206}
@ DIRTY_UV
Definition MeshGL.h:32

References igl::opengl::MeshGL::DIRTY_UV.

Referenced by igl::opengl::glfw::Viewer::load_mesh_from_file().

+ Here is the caller graph for this function:

◆ set_uv() [2/2]

IGL_INLINE void igl::opengl::ViewerData::set_uv ( const Eigen::MatrixXd &  UV_V,
const Eigen::MatrixXi &  UV_F 
)
209{
210 set_face_based(true);
211 V_uv = UV_V.block(0,0,UV_V.rows(),2);
212 F_uv = UV_F;
214}

References igl::opengl::MeshGL::DIRTY_UV.

◆ set_vertices()

IGL_INLINE void igl::opengl::ViewerData::set_vertices ( const Eigen::MatrixXd &  V)
91{
92 V = _V;
93 assert(F.size() == 0 || F.maxCoeff() < V.rows());
95}

References igl::opengl::MeshGL::DIRTY_POSITION.

◆ uniform_colors() [1/2]

IGL_INLINE void igl::opengl::ViewerData::uniform_colors ( const Eigen::Vector3d &  diffuse,
const Eigen::Vector3d &  ambient,
const Eigen::Vector3d &  specular 
)
378{
379 Eigen::Vector4d ambient4;
380 Eigen::Vector4d diffuse4;
381 Eigen::Vector4d specular4;
382
383 ambient4 << ambient, 1;
384 diffuse4 << diffuse, 1;
385 specular4 << specular, 1;
386
387 uniform_colors(ambient4,diffuse4,specular4);
388}

Referenced by igl::opengl::glfw::Viewer::load_mesh_from_file().

+ Here is the caller graph for this function:

◆ uniform_colors() [2/2]

IGL_INLINE void igl::opengl::ViewerData::uniform_colors ( const Eigen::Vector4d &  ambient,
const Eigen::Vector4d &  diffuse,
const Eigen::Vector4d &  specular 
)
394{
395 V_material_ambient.resize(V.rows(),4);
396 V_material_diffuse.resize(V.rows(),4);
397 V_material_specular.resize(V.rows(),4);
398
399 for (unsigned i=0; i<V.rows();++i)
400 {
401 V_material_ambient.row(i) = ambient;
402 V_material_diffuse.row(i) = diffuse;
403 V_material_specular.row(i) = specular;
404 }
405
406 F_material_ambient.resize(F.rows(),4);
407 F_material_diffuse.resize(F.rows(),4);
408 F_material_specular.resize(F.rows(),4);
409
410 for (unsigned i=0; i<F.rows();++i)
411 {
412 F_material_ambient.row(i) = ambient;
413 F_material_diffuse.row(i) = diffuse;
414 F_material_specular.row(i) = specular;
415 }
417}
@ DIRTY_SPECULAR
Definition MeshGL.h:36
@ DIRTY_AMBIENT
Definition MeshGL.h:34

References igl::opengl::MeshGL::DIRTY_AMBIENT, igl::opengl::MeshGL::DIRTY_DIFFUSE, and igl::opengl::MeshGL::DIRTY_SPECULAR.

◆ updateGL()

IGL_INLINE void igl::opengl::ViewerData::updateGL ( const igl::opengl::ViewerData data,
const bool  invert_normals,
igl::opengl::MeshGL meshgl 
)
462{
464 {
465 meshgl.init();
466 }
467
468 bool per_corner_uv = (data.F_uv.rows() == data.F.rows());
469 bool per_corner_normals = (data.F_normals.rows() == 3 * data.F.rows());
470
471 meshgl.dirty |= data.dirty;
472
473 // Input:
474 // X #F by dim quantity
475 // Output:
476 // X_vbo #F*3 by dim scattering per corner
477 const auto per_face = [&data](
478 const Eigen::MatrixXd & X,
479 MeshGL::RowMatrixXf & X_vbo)
480 {
481 assert(X.cols() == 4);
482 X_vbo.resize(data.F.rows()*3,4);
483 for (unsigned i=0; i<data.F.rows();++i)
484 for (unsigned j=0;j<3;++j)
485 X_vbo.row(i*3+j) = X.row(i).cast<float>();
486 };
487
488 // Input:
489 // X #V by dim quantity
490 // Output:
491 // X_vbo #F*3 by dim scattering per corner
492 const auto per_corner = [&data](
493 const Eigen::MatrixXd & X,
494 MeshGL::RowMatrixXf & X_vbo)
495 {
496 X_vbo.resize(data.F.rows()*3,X.cols());
497 for (unsigned i=0; i<data.F.rows();++i)
498 for (unsigned j=0;j<3;++j)
499 X_vbo.row(i*3+j) = X.row(data.F(i,j)).cast<float>();
500 };
501
502 if (!data.face_based)
503 {
504 if (!(per_corner_uv || per_corner_normals))
505 {
506 // Vertex positions
508 meshgl.V_vbo = data.V.cast<float>();
509
510 // Vertex normals
512 {
513 meshgl.V_normals_vbo = data.V_normals.cast<float>();
514 if (invert_normals)
516 }
517
518 // Per-vertex material settings
520 meshgl.V_ambient_vbo = data.V_material_ambient.cast<float>();
522 meshgl.V_diffuse_vbo = data.V_material_diffuse.cast<float>();
524 meshgl.V_specular_vbo = data.V_material_specular.cast<float>();
525
526 // Face indices
528 meshgl.F_vbo = data.F.cast<unsigned>();
529
530 // Texture coordinates
532 {
533 meshgl.V_uv_vbo = data.V_uv.cast<float>();
534 }
535 }
536 else
537 {
538
539 // Per vertex properties with per corner UVs
541 {
542 per_corner(data.V,meshgl.V_vbo);
543 }
544
546 {
547 meshgl.V_ambient_vbo.resize(data.F.rows()*3,4);
548 for (unsigned i=0; i<data.F.rows();++i)
549 for (unsigned j=0;j<3;++j)
550 meshgl.V_ambient_vbo.row(i*3+j) = data.V_material_ambient.row(data.F(i,j)).cast<float>();
551 }
553 {
554 meshgl.V_diffuse_vbo.resize(data.F.rows()*3,4);
555 for (unsigned i=0; i<data.F.rows();++i)
556 for (unsigned j=0;j<3;++j)
557 meshgl.V_diffuse_vbo.row(i*3+j) = data.V_material_diffuse.row(data.F(i,j)).cast<float>();
558 }
560 {
561 meshgl.V_specular_vbo.resize(data.F.rows()*3,4);
562 for (unsigned i=0; i<data.F.rows();++i)
563 for (unsigned j=0;j<3;++j)
564 meshgl.V_specular_vbo.row(i*3+j) = data.V_material_specular.row(data.F(i,j)).cast<float>();
565 }
566
568 {
569 meshgl.V_normals_vbo.resize(data.F.rows()*3,3);
570 for (unsigned i=0; i<data.F.rows();++i)
571 for (unsigned j=0;j<3;++j)
572 meshgl.V_normals_vbo.row(i*3+j) =
574 data.F_normals.row(i*3+j).cast<float>() :
575 data.V_normals.row(data.F(i,j)).cast<float>();
576
577
578 if (invert_normals)
580 }
581
583 {
584 meshgl.F_vbo.resize(data.F.rows(),3);
585 for (unsigned i=0; i<data.F.rows();++i)
586 meshgl.F_vbo.row(i) << i*3+0, i*3+1, i*3+2;
587 }
588
590 {
591 meshgl.V_uv_vbo.resize(data.F.rows()*3,2);
592 for (unsigned i=0; i<data.F.rows();++i)
593 for (unsigned j=0;j<3;++j)
594 meshgl.V_uv_vbo.row(i*3+j) =
595 data.V_uv.row(per_corner_uv ?
596 data.F_uv(i,j) : data.F(i,j)).cast<float>();
597 }
598 }
599 }
600 else
601 {
603 {
604 per_corner(data.V,meshgl.V_vbo);
605 }
607 {
608 per_face(data.F_material_ambient,meshgl.V_ambient_vbo);
609 }
611 {
612 per_face(data.F_material_diffuse,meshgl.V_diffuse_vbo);
613 }
615 {
616 per_face(data.F_material_specular,meshgl.V_specular_vbo);
617 }
618
620 {
621 meshgl.V_normals_vbo.resize(data.F.rows()*3,3);
622 for (unsigned i=0; i<data.F.rows();++i)
623 for (unsigned j=0;j<3;++j)
624 meshgl.V_normals_vbo.row(i*3+j) =
626 data.F_normals.row(i*3+j).cast<float>() :
627 data.F_normals.row(i).cast<float>();
628
629 if (invert_normals)
631 }
632
634 {
635 meshgl.F_vbo.resize(data.F.rows(),3);
636 for (unsigned i=0; i<data.F.rows();++i)
637 meshgl.F_vbo.row(i) << i*3+0, i*3+1, i*3+2;
638 }
639
641 {
642 meshgl.V_uv_vbo.resize(data.F.rows()*3,2);
643 for (unsigned i=0; i<data.F.rows();++i)
644 for (unsigned j=0;j<3;++j)
645 meshgl.V_uv_vbo.row(i*3+j) = data.V_uv.row(per_corner_uv ? data.F_uv(i,j) : data.F(i,j)).cast<float>();
646 }
647 }
648
650 {
651 meshgl.tex_u = data.texture_R.rows();
652 meshgl.tex_v = data.texture_R.cols();
653 meshgl.tex.resize(data.texture_R.size()*4);
654 for (unsigned i=0;i<data.texture_R.size();++i)
655 {
656 meshgl.tex(i*4+0) = data.texture_R(i);
657 meshgl.tex(i*4+1) = data.texture_G(i);
658 meshgl.tex(i*4+2) = data.texture_B(i);
659 meshgl.tex(i*4+3) = data.texture_A(i);
660 }
661 }
662
664 {
665 meshgl.lines_V_vbo.resize(data.lines.rows()*2,3);
666 meshgl.lines_V_colors_vbo.resize(data.lines.rows()*2,3);
667 meshgl.lines_F_vbo.resize(data.lines.rows()*2,1);
668 for (unsigned i=0; i<data.lines.rows();++i)
669 {
670 meshgl.lines_V_vbo.row(2*i+0) = data.lines.block<1, 3>(i, 0).cast<float>();
671 meshgl.lines_V_vbo.row(2*i+1) = data.lines.block<1, 3>(i, 3).cast<float>();
672 meshgl.lines_V_colors_vbo.row(2*i+0) = data.lines.block<1, 3>(i, 6).cast<float>();
673 meshgl.lines_V_colors_vbo.row(2*i+1) = data.lines.block<1, 3>(i, 6).cast<float>();
674 meshgl.lines_F_vbo(2*i+0) = 2*i+0;
675 meshgl.lines_F_vbo(2*i+1) = 2*i+1;
676 }
677 }
678
680 {
681 meshgl.points_V_vbo.resize(data.points.rows(),3);
682 meshgl.points_V_colors_vbo.resize(data.points.rows(),3);
683 meshgl.points_F_vbo.resize(data.points.rows(),1);
684 for (unsigned i=0; i<data.points.rows();++i)
685 {
686 meshgl.points_V_vbo.row(i) = data.points.block<1, 3>(i, 0).cast<float>();
687 meshgl.points_V_colors_vbo.row(i) = data.points.block<1, 3>(i, 3).cast<float>();
688 meshgl.points_F_vbo(i) = i;
689 }
690 }
691}
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). *‍/.
Definition BlockMethods.h:859
EIGEN_DEVICE_FUNC CastXpr< NewType >::Type cast() const
Definition CommonCwiseUnaryOps.h:62
RowMatrixXf V_normals_vbo
Definition MeshGL.h:73
Eigen::Matrix< unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > F_vbo
Definition MeshGL.h:87
RowMatrixXf lines_V_colors_vbo
Definition MeshGL.h:79
uint32_t dirty
Definition MeshGL.h:92
Eigen::Matrix< char, Eigen::Dynamic, 1 > tex
Definition MeshGL.h:85
RowMatrixXf V_uv_vbo
Definition MeshGL.h:77
RowMatrixXf V_diffuse_vbo
Definition MeshGL.h:75
int tex_v
Definition MeshGL.h:84
Eigen::Matrix< unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > lines_F_vbo
Definition MeshGL.h:88
RowMatrixXf V_ambient_vbo
Definition MeshGL.h:74
Eigen::Matrix< unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > points_F_vbo
Definition MeshGL.h:89
RowMatrixXf points_V_vbo
Definition MeshGL.h:80
RowMatrixXf lines_V_vbo
Definition MeshGL.h:78
IGL_INLINE void init()
Definition MeshGL.cpp:160
RowMatrixXf V_vbo
Definition MeshGL.h:72
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > RowMatrixXf
Definition MeshGL.h:71
bool is_initialized
Definition MeshGL.h:45
RowMatrixXf V_specular_vbo
Definition MeshGL.h:76
int tex_u
Definition MeshGL.h:83
RowMatrixXf points_V_colors_vbo
Definition MeshGL.h:81
igl::opengl::MeshGL meshgl
Definition ViewerData.h:201
@ X
Definition libslic3r.h:98
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195
IGL_INLINE void per_corner_normals(const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F, const double corner_threshold, Eigen::PlainObjectBase< DerivedCN > &CN)
Definition per_corner_normals.cpp:15

References igl::opengl::MeshGL::dirty, igl::opengl::MeshGL::DIRTY_AMBIENT, igl::opengl::MeshGL::DIRTY_DIFFUSE, igl::opengl::MeshGL::DIRTY_FACE, igl::opengl::MeshGL::DIRTY_NORMAL, igl::opengl::MeshGL::DIRTY_OVERLAY_LINES, igl::opengl::MeshGL::DIRTY_OVERLAY_POINTS, igl::opengl::MeshGL::DIRTY_POSITION, igl::opengl::MeshGL::DIRTY_SPECULAR, igl::opengl::MeshGL::DIRTY_TEXTURE, igl::opengl::MeshGL::DIRTY_UV, igl::opengl::MeshGL::F_vbo, igl::opengl::MeshGL::init(), igl::opengl::MeshGL::is_initialized, igl::opengl::MeshGL::lines_F_vbo, igl::opengl::MeshGL::lines_V_colors_vbo, igl::opengl::MeshGL::lines_V_vbo, igl::per_corner_normals(), igl::opengl::MeshGL::points_F_vbo, igl::opengl::MeshGL::points_V_colors_vbo, igl::opengl::MeshGL::points_V_vbo, Eigen::PlainObjectBase< Derived >::resize(), igl::opengl::MeshGL::tex, igl::opengl::MeshGL::tex_u, igl::opengl::MeshGL::tex_v, igl::opengl::MeshGL::V_ambient_vbo, igl::opengl::MeshGL::V_diffuse_vbo, igl::opengl::MeshGL::V_normals_vbo, igl::opengl::MeshGL::V_specular_vbo, igl::opengl::MeshGL::V_uv_vbo, and igl::opengl::MeshGL::V_vbo.

+ Here is the call graph for this function:

Member Data Documentation

◆ dirty

◆ F

Eigen::MatrixXi igl::opengl::ViewerData::F

◆ F_material_ambient

Eigen::MatrixXd igl::opengl::ViewerData::F_material_ambient

◆ F_material_diffuse

Eigen::MatrixXd igl::opengl::ViewerData::F_material_diffuse

◆ F_material_specular

Eigen::MatrixXd igl::opengl::ViewerData::F_material_specular

◆ F_normals

Eigen::MatrixXd igl::opengl::ViewerData::F_normals

◆ F_uv

Eigen::MatrixXi igl::opengl::ViewerData::F_uv

◆ face_based

bool igl::opengl::ViewerData::face_based

◆ id

int igl::opengl::ViewerData::id

◆ invert_normals

bool igl::opengl::ViewerData::invert_normals

◆ labels_positions

Eigen::MatrixXd igl::opengl::ViewerData::labels_positions

◆ labels_strings

std::vector<std::string> igl::opengl::ViewerData::labels_strings

◆ line_color

Eigen::Vector4f igl::opengl::ViewerData::line_color

◆ line_width

float igl::opengl::ViewerData::line_width

◆ lines

Eigen::MatrixXd igl::opengl::ViewerData::lines

◆ meshgl

igl::opengl::MeshGL igl::opengl::ViewerData::meshgl

◆ point_size

float igl::opengl::ViewerData::point_size

◆ points

Eigen::MatrixXd igl::opengl::ViewerData::points

◆ shininess

float igl::opengl::ViewerData::shininess

◆ show_faceid

bool igl::opengl::ViewerData::show_faceid

◆ show_faces

bool igl::opengl::ViewerData::show_faces

◆ show_lines

bool igl::opengl::ViewerData::show_lines

◆ show_overlay

bool igl::opengl::ViewerData::show_overlay

◆ show_overlay_depth

bool igl::opengl::ViewerData::show_overlay_depth

◆ show_texture

bool igl::opengl::ViewerData::show_texture

◆ show_vertid

bool igl::opengl::ViewerData::show_vertid

◆ texture_A

Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> igl::opengl::ViewerData::texture_A

◆ texture_B

Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> igl::opengl::ViewerData::texture_B

◆ texture_G

Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> igl::opengl::ViewerData::texture_G

◆ texture_R

Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> igl::opengl::ViewerData::texture_R

◆ V

Eigen::MatrixXd igl::opengl::ViewerData::V

◆ V_material_ambient

Eigen::MatrixXd igl::opengl::ViewerData::V_material_ambient

◆ V_material_diffuse

Eigen::MatrixXd igl::opengl::ViewerData::V_material_diffuse

◆ V_material_specular

Eigen::MatrixXd igl::opengl::ViewerData::V_material_specular

◆ V_normals

Eigen::MatrixXd igl::opengl::ViewerData::V_normals

◆ V_uv

Eigen::MatrixXd igl::opengl::ViewerData::V_uv

The documentation for this class was generated from the following files: