forked from libigl/libigl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial.html
3839 lines (3030 loc) · 198 KB
/
tutorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>libigl Tutorial</title>
<meta name="author" content="Daniele Panozzo and Alec Jacobson"/>
<meta name="date" content="07 November 2015"/>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css">
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<h1 id="libigltutorialnotes">libigl tutorial notes</h1>
<h4 id="originallypresentedbydanielepanozzoandalecjacobsonatsgpgraduateschool2014">originally presented by Daniele Panozzo and Alec Jacobson at SGP Graduate School 2014</h4>
<figure>
<img src="images/libigl-logo.jpg" alt="" />
</figure>
<p>Libigl is an open source C++ library for geometry processing research and
development. Dropping the heavy data structures of tradition geometry
libraries, libigl is a simple header-only library of encapsulated functions.
This combines the rapid prototyping familiar to Matlab or Python programmers
with the performance and versatility of C++. The tutorial is a self-contained,
hands-on introduction to libigl. Via interactive, step-by-step examples, we
demonstrate how to accomplish common geometry processing tasks such as
computation of differential quantities and operators, real-time deformation,
parametrization, numerical optimization and remeshing. Each section of the
lecture notes links to a cross-platform example application.</p>
<h1 id="tableofcontents">Table of contents</h1>
<ul>
<li><a href="#chapter1:introductiontolibigl">Chapter 1: Introduction to libigl</a>
<ul>
<li><a href="#libigldesignprinciples">Libigl design principles</a></li>
<li><a href="#meshrepresentation">101 Mesh representation</a></li>
<li><a href="#visualizingsurfaces">102 Visualizing surfaces</a></li>
<li><a href="#interactionwithkeyboardandmouse">103 Interaction with keyboard and mouse</a></li>
<li><a href="#scalarfieldvisualization">104 Scalar field visualization</a></li>
<li><a href="#overlays">105 Overlays</a></li>
<li><a href="#viewermenu">106 Viewer Menu</a></li>
</ul></li>
<li><a href="#chapter2:discretegeometricquantitiesandoperators">Chapter 2: Discrete Geometric Quantities and
Operators</a>
<ul>
<li><a href="#normals">201 Normals</a>
<ul>
<li><a href="#per-face">Per-face</a></li>
<li><a href="#per-vertex">Per-vertex</a></li>
<li><a href="#per-corner">Per-corner</a></li>
</ul></li>
<li><a href="#gaussiancurvature">202 Gaussian Curvature</a></li>
<li><a href="#curvaturedirections">203 Curvature Directions</a></li>
<li><a href="#gradient">204 Gradient</a></li>
<li><a href="#laplacian">204 Laplacian</a>
<ul>
<li><a href="#massmatrix">Mass matrix</a></li>
<li><a href="#alternativeconstructionoflaplacian">Alternative construction of
Laplacian</a></li>
</ul></li>
</ul></li>
<li><a href="#chapter3:matricesandlinearalgebra">Chapter 3: Matrices and Linear Algebra</a>
<ul>
<li><a href="#slice">301 Slice</a></li>
<li><a href="#sort">302 Sort</a>
<ul>
<li><a href="#othermatlab-stylefunctions">Other Matlab-style functions</a></li>
</ul></li>
<li><a href="#laplaceequation">303 Laplace Equation</a>
<ul>
<li><a href="#quadraticenergyminimization">Quadratic energy minimization</a></li>
</ul></li>
<li><a href="#linearequalityconstraints">304 Linear Equality Constraints</a></li>
<li><a href="#quadraticprogramming">305 Quadratic Programming</a></li>
<li><a href="#eigendecomposition">306 Eigen Decomposition</a></li>
</ul></li>
<li><a href="#chapter4:shapedeformation">Chapter 4: Shape Deformation</a>
<ul>
<li><a href="#biharmonicdeformation">401 Biharmonic Deformation</a></li>
<li><a href="#polyharmonicdeformation">402 Polyharmonic Deformation</a></li>
<li><a href="#boundedbiharmonicweights">403 Bounded Biharmonic Weights</a></li>
<li><a href="#dualquaternionskinning">404 Dual Quaternion Skinning</a></li>
<li><a href="#as-rigid-as-possible">405 As-rigid-as-possible</a></li>
<li><a href="#fastautomaticskinningtransformations">406 Fast automatic skinning
transformations</a>
<ul>
<li><a href="#arapwithgroupededge-sets">ARAP with grouped edge-sets</a></li>
</ul></li>
<li><a href="#biharmoniccoordinates">407 Biharmonic Coordinates</a></li>
</ul></li>
<li><a href="#chapter5:parametrization">Chapter 5: Parametrization</a>
<ul>
<li><a href="#harmonicparametrization">501 Harmonic parametrization</a></li>
<li><a href="#leastsquareconformalmaps">502 Least-Square Conformal Maps</a></li>
<li><a href="#asrigidaspossible">503 As-Rigid-As-Possible</a></li>
<li><a href="#nrotationallysymmetrictangetfields">504 N-Rotationally symmetric tangent fields</a></li>
<li><a href="#globalseamlessintegergridparametrization">505 Global, seamless integer-grid parametrization</a></li>
<li><a href="#anisotropicremeshingusingframefields">506 Anisotropic remeshing using frame fields</a></li>
<li><a href="#npolyvectorfields">507 N-PolyVector fields</a></li>
<li><a href="#conjugatevectorfields">508 Conjugate vector fields</a></li>
<li><a href="#planarization">509 Planarization</a></li>
<li><a href="#integrable">510 Integrable PolyVector Fields</a></li>
<li><a href="#npolyvectorfields_general">511 General N-PolyVector Fields</a></li>
</ul></li>
<li><a href="#chapter6:externallibraries">Chapter 6: External libraries</a>
<ul>
<li><a href="#stateserialization">601 State serialization</a></li>
<li><a href="#mixingmatlabcode">602 Mixing Matlab code</a>
<ul>
<li><a href="#savingamatlabworkspace">Saving a Matlab workspace</a></li>
<li><a href="#dumpingeigenmatricestocopyandpasteintomatlab">Dumping Eigen matrices to copy and paste into
Matlab</a></li>
</ul></li>
<li><a href="#callinglibiglfunctionsfrommatlab">603 Calling libigl functions from Matlab</a></li>
<li><a href="#triangulationofclosedpolygons">604 Triangulation of closed polygons</a></li>
<li><a href="#tetrahedralizationofclosedsurfaces">605 Tetrahedralization of closed surfaces</a></li>
<li><a href="#bakingambientocclusion">606 Baking ambient occlusion</a></li>
<li><a href="#screencapture">607 Screen Capture</a></li>
<li><a href="#locallyinjectivemaps">608 Locally Injective Maps</a></li>
<li><a href="#booleanoperationsonmeshes">609 Boolean Operations on Meshes</a></li>
<li><a href="#csgtree">610 CSG Tree</a></li>
</ul></li>
<li><a href="#chapter7:miscellaneous">Chapter 7: Miscellaneous</a>
<ul>
<li><a href="#meshstatistics">701 Mesh Statistics</a></li>
<li><a href="#generalizedwindingnumber">702 Generalized Winding Number</a></li>
<li><a href="#meshdecimation">703 Mesh Decimation</a></li>
<li><a href="#signeddistances">704 Signed Distances</a></li>
<li><a href="#marchingcubes">705 Marching Cubes</a></li>
<li><a href="#facetorientation">706 Facet Orientation</a></li>
<li><a href="#sweptvolume">707 Swept Volume</a></li>
<li><a href="#pickingverticesandfaces">708 Picking Vertices and Faces</a></li>
<li><a href="#vectorfieldvisualizer">709 Vector Field Visualization</a></li>
<li><a href="#slim">710 Scalable Locally Injective Maps</a></li>
<li><a href="#subdivision">711 Subdivision surfaces</a></li>
</ul></li>
<li><a href="#future">Chapter 8: Outlook for continuing development</a></li>
</ul>
<h1 id="chapter1:introductiontolibigl">Chapter 1</h1>
<p>We introduce libigl with a series of self-contained examples. The purpose of
each example is to showcase a feature of libigl while applying to a practical
problem in geometry processing. In this chapter, we will present the basic
concepts of libigl and introduce a simple mesh viewer that allows to
visualize a surface mesh and its attributes. All the tutorial examples are
cross-platform and can be compiled on MacOSX, Linux and Windows.</p>
<h2 id="libigldesignprinciples"><a href="#libigldesignprinciples">libigl design principles</a></h2>
<p>Before getting into the examples, we summarize the main design principles in
libigl:</p>
<ol>
<li><p><strong>No complex data types.</strong> We mostly use matrices and vectors. This greatly
favors code reusability and forces the function authors to expose all the
parameters used by the algorithm. </p></li>
<li><p><strong>Minimal dependencies.</strong> We use external libraries only when necessary and
we wrap them in a small set of functions.</p></li>
<li><p><strong>Header-only.</strong> It is straight forward to use our library since it is only
one additional include directory in your project. (if you are worried about
compilation speed, it is also possible to build the library as a <a href="../optional/">static
library</a>)</p></li>
<li><p><strong>Function encapsulation.</strong> Every function (including its full
implementation) is contained in a pair of .h/.cpp files with the same name of
the function.</p></li>
</ol>
<h3 id="downloadinglibigl">Downloading libigl</h3>
<p>libigl can be downloaded from our <a href="https://github.com/libigl/libigl">github
repository</a> or cloned with git:</p>
<pre><code class="bash">git clone --recursive https://github.com/libigl/libigl.git
</code></pre>
<p>The core libigl functionality only depends on the C++ Standard Library and
Eigen.</p>
<p>To build all the examples in the tutorial, you can use the CMakeLists.txt in
the tutorial folder:</p>
<pre><code class="bash">cd tutorial
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../
make
</code></pre>
<p>The examples can also be built independently using the CMakeLists.txt
inside each example folder.</p>
<p><em>Note for linux users</em>: Many linux distributions do not include gcc and the basic development tools
in their default installation. On Ubuntu, you need to install the following packages:</p>
<pre><code class="bash">sudo apt-get install git
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install libx11-dev
sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev
sudo apt-get install libxrandr-dev
sudo apt-get install libxi-dev
sudo apt-get install libxmu-dev
sudo apt-get install libblas-dev
</code></pre>
<p><em>Note for windows users</em>: libigl only supports the Microsoft Visual Studio 2015 compiler in 64bit mode. It will not work with a 32bit build and it will not work
with older versions of visual studio.</p>
<p>A few examples in Chapter 5 requires the <a href="http://www.graphics.rwth-aachen.de/software/comiso">CoMiSo
solver</a>. We provide a
mirror of CoMISo that works out of the box with libigl. To install it:</p>
<pre><code class="bash">cd libigl/external
git clone --recursive https://github.com/libigl/CoMISo.git
</code></pre>
<p>You can then build the tutorials again and it libigl will automatically find and
compile CoMISo.</p>
<p><em>Note 1</em>: CoMISo is distributed under the GPL3 license, it does impose restrictions on commercial usage.</p>
<p><em>Note 2</em>: CoMISo requires a blas implementation. We use the built-in blas in macosx and linux, and we bundle a precompiled binary for VS2015 64 bit. Do NOT compile the tutorials
in 32 bit on windows.</p>
<h3 id="libiglexampleproject">libigl example project</h3>
<p>We provide a <a href="https://github.com/libigl/libigl-example-project">blank project example</a> showing how to use libigl and cmake. Feel free and encouraged to copy or fork this project as a way of starting a new personal project using libigl.</p>
<h2 id="meshrepresentation"><a href="#meshrepresentation">Mesh representation</a></h2>
<p>libigl uses the <a href="http://eigen.tuxfamily.org/">Eigen</a> library to encode vector
and matrices. We suggest that you keep the
<a href="http://eigen.tuxfamily.org/dox/group__QuickRefPage.html">dense</a> and
<a href="http://eigen.tuxfamily.org/dox/group__SparseQuickRefPage.html">sparse</a> quick
reference guides at hand while you read the examples in this tutorial.</p>
<p>A triangular mesh is encoded as a pair of matrices:</p>
<pre><code class="cpp">Eigen::MatrixXd V;
Eigen::MatrixXi F;
</code></pre>
<p><code>V</code> is a #N by 3 matrix which stores the coordinates of the vertices. Each
row stores the coordinate of a vertex, with its x,y and z coordinates in the first,
second and third column, respectively. The matrix <code>F</code> stores the triangle
connectivity: each line of <code>F</code> denotes a triangle whose 3 vertices are
represented as indices pointing to rows of <code>V</code>.</p>
<figure>
<img src="images/VF.png" alt="A simple mesh made of 2 triangles and 4 vertices." />
<figcaption>A simple mesh made of 2 triangles and 4 vertices.</figcaption>
</figure>
<p>Note that the order of the vertex indices in <code>F</code> determines the orientation of
the triangles and it should thus be consistent for the entire surface.
This simple representation has many advantages:</p>
<ol>
<li>it is memory efficient and cache friendly</li>
<li>the use of indices instead of pointers greatly simplifies debugging</li>
<li>the data can be trivially copied and serialized</li>
</ol>
<p>libigl provides input [output] functions to read [write] many common mesh formats.
The IO functions are contained in the files read*.h and write*.h. As a general
rule each libigl function is contained in a pair of .h/.cpp files with the same name.
By default, the .h files include the corresponding cpp files, making the library header-only.</p>
<p>Reading a mesh from a file requires a single libigl function call:</p>
<pre><code class="cpp">igl::readOFF(TUTORIAL_SHARED_PATH "/cube.off", V, F);
</code></pre>
<p>The function reads the mesh cube.off and it fills the provided <code>V</code> and <code>F</code> matrices.
Similarly, a mesh can be written in an OBJ file using:</p>
<pre><code class="cpp">igl::writeOBJ("cube.obj",V,F);
</code></pre>
<p><a href="101_FileIO/main.cpp">Example 101</a> contains a simple mesh
converter from OFF to OBJ format.</p>
<h2 id="visualizingsurfaces"><a href="#visualizingsurfaces">Visualizing surfaces</a></h2>
<p>Libigl provides an glfw-based OpenGL 3.2 viewer to visualize surfaces, their
properties and additional debugging informations.</p>
<p>The following code (<a href="102_DrawMesh/main.cpp">Example 102</a>) is a basic skeleton
for all the examples that will be used in the tutorial.
It is a standalone application that loads a mesh and uses the viewer to
render it.</p>
<pre><code class="cpp">#include <igl/readOFF.h>
#include <igl/viewer/Viewer.h>
Eigen::MatrixXd V;
Eigen::MatrixXi F;
int main(int argc, char *argv[])
{
// Load a mesh in OFF format
igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
// Plot the mesh
igl::viewer::Viewer viewer;
viewer.data.set_mesh(V, F);
viewer.launch();
}
</code></pre>
<p>The function <code>set_mesh</code> copies the mesh into the viewer.
<code>Viewer.launch()</code> creates a window, an OpenGL context and it starts the draw loop.
Additional properties can be plotted on the mesh (as we will see later),
and it is possible to extend the viewer with standard OpenGL code.
Please see the documentation in
<a href="../include/igl/Viewer/Viewer.h">Viewer.h</a> for more details.</p>
<figure>
<img src="images/102_DrawMesh.png" alt="(Example 102) loads and draws a
mesh." />
<figcaption>(<a href="102_DrawMesh/main.cpp">Example 102</a>) loads and draws a
mesh.</figcaption>
</figure>
<h2 id="interactionwithkeyboardandmouse"><a href="#interactionwithkeyboardandmouse">Interaction with keyboard and mouse</a></h2>
<p>Keyboard and mouse events triggers callbacks that can be registered in the
viewer. The viewer supports the following callbacks:</p>
<pre><code class="cpp">bool (*callback_pre_draw)(Viewer& viewer);
bool (*callback_post_draw)(Viewer& viewer);
bool (*callback_mouse_down)(Viewer& viewer, int button, int modifier);
bool (*callback_mouse_up)(Viewer& viewer, int button, int modifier);
bool (*callback_mouse_move)(Viewer& viewer, int mouse_x, int mouse_y);
bool (*callback_mouse_scroll)(Viewer& viewer, float delta_y);
bool (*callback_key_down)(Viewer& viewer, unsigned char key, int modifiers);
bool (*callback_key_up)(Viewer& viewer, unsigned char key, int modifiers);
</code></pre>
<p>A keyboard callback can be used to visualize multiple meshes or different
stages of an algorithm, as demonstrated in <a href="103_Events/main.cpp">Example 103</a>, where
the keyboard callback changes the visualized mesh depending on the key pressed:</p>
<pre><code class="cpp">bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
{
if (key == '1')
{
viewer.data.clear();
viewer.data.set_mesh(V1, F1);
viewer.core.align_camera_center(V1,F1);
}
else if (key == '2')
{
viewer.data.clear();
viewer.data.set_mesh(V2, F2);
viewer.core.align_camera_center(V2,F2);
}
return false;
}
</code></pre>
<p>The callback is registered in the viewer as follows:</p>
<pre><code class="cpp">viewer.callback_key_down = &key_down;
</code></pre>
<p>Note that the mesh is cleared before using set_mesh. This has to be called
every time the number of vertices or faces of the plotted mesh changes. Every
callback returns a boolean value that tells the viewer if the event has been
handled by the plugin, or if the viewer should process it normally. This is
useful, for example, to disable the default mouse event handling if you want to
control the camera directly in your code.</p>
<p>The viewer can be extended using plugins, which are classes that implements all
the viewer’s callbacks. See the
<a href="../include/igl/viewer/ViewerPlugin.h">Viewer_plugin</a> for more details.</p>
<h2 id="scalarfieldvisualization"><a href="#scalarfieldvisualization">Scalar field visualization</a></h2>
<p>Colors and normals can be associated to faces or vertices using the
set_colors function:</p>
<pre><code class="cpp">viewer.data.set_colors(C);
</code></pre>
<p><code>C</code> is a #C by 3 matrix with one RGB color per row. <code>C</code> must have as many
rows as the number of faces <strong>or</strong> the number of vertices of the mesh.
Depending on the size of <code>C</code>, the viewer applies the color to the faces or to
the vertices.</p>
<p>Colors can be used to visualize a scalar function defined on a surface. The
scalar function is converted to colors using a color transfer function, which
maps a scalar value between 0 and 1 to a color. A simple example of a scalar
field defined on a surface is the z coordinate of each point, which can be
extract from our mesh representation by taking the last column of <code>V</code>
(<a href="104_Colors/main.cpp">Example 104</a>). The function <code>igl::jet</code> can be used to
convert it to colors:</p>
<pre><code class="cpp">Eigen::VectorXd Z = V.col(2);
igl::jet(Z,true,C);
</code></pre>
<p>The first row extracts the third column from <code>V</code> (the z coordinate of each
vertex) and the second calls a libigl functions that converts a scalar field to colors. The second parameter of jet normalizes the scalar field to lie between 0 and 1 before applying the transfer function.</p>
<figure>
<img src="images/104_Colors.png" alt="(Example 104) igl::jet converts a scalar field to a
color field." />
<figcaption>(<a href="104_Colors/main.cpp">Example 104</a>) igl::jet converts a scalar field to a
color field.</figcaption>
</figure>
<p><code>igl::jet</code> is an example of a standard function in libigl: it takes simple
types and can be easily reused for many different tasks. Not committing to
heavy data structures types favors simplicity, ease of use and reusability.</p>
<h2 id="overlays"><a href="#overlays">Overlays</a></h2>
<p>In addition to plotting the surface, the viewer supports the visualization of points, lines and text labels: these overlays can be very helpful while developing geometric processing algorithms to plot debug informations.</p>
<pre><code class="cpp">viewer.data.add_points(P,Eigen::RowVector3d(r,g,b));
</code></pre>
<p>Draws a point of color r,g,b for each row of P. The point is placed at the coordinates specified in each row of P, which is a #P by 3 matrix.</p>
<pre><code class="cpp">viewer.data.add_edges(P1,P2,Eigen::RowVector3d(r,g,b);
</code></pre>
<p>Draws a line of color r,g,b for each row of P1 and P2, which connects the 3D point in to the point in P2. Both P1 and P2 are of size #P by 3.</p>
<pre><code class="cpp">viewer.data.add_label(p,str);
</code></pre>
<p>Draws a label containing the string str at the position p, which is a vector of length 3.</p>
<p>These functions are demonstrate in <a href="105_Overlays/main.cpp">Example 105</a> where
the bounding box of a mesh is plotted using lines and points.
Using matrices to encode the mesh and its attributes allows to write short and
efficient code for many operations, avoiding to write for loops. For example,
the bounding box of a mesh can be found by taking the colwise maximum and minimum of <code>V</code>:</p>
<pre><code class="cpp">Eigen::Vector3d m = V.colwise().minCoeff();
Eigen::Vector3d M = V.colwise().maxCoeff();
</code></pre>
<figure>
<img src="images/105_Overlays.png" alt="(Example 105) The bounding box of a mesh is shown
using overlays." />
<figcaption>(<a href="105_Overlays/main.cpp">Example 105</a>) The bounding box of a mesh is shown
using overlays.</figcaption>
</figure>
<h2 id="viewermenu"><a href="#viewermenu">Viewer Menu</a></h2>
<p>As of version 1.2 the viewer uses a new menu and completely replaces
<a href="http://anttweakbar.sourceforge.net/doc/">AntTweakBar</a>. It is based on the
open-source projects <a href="https://github.com/memononen/nanovg">nanovg</a> and
<a href="https://github.com/wjakob/nanogui">nanogui</a>. To extend the default menu of the
viewer and to expose more user defined variables you have to define a callback
function:</p>
<pre><code class="cpp">igl::viewer::Viewer viewer;
bool boolVariable = true;
float floatVariable = 0.1f;
enum Orientation { Up=0,Down,Left,Right } dir = Up;
// Extend viewer menu
viewer.callback_init = [&](igl::viewer::Viewer& viewer)
{
// Add new group
viewer.ngui->addGroup("New Group");
// Expose a variable directly ...
viewer.ngui->addVariable("float",floatVariable);
// Expose an enumaration type
viewer.ngui->addVariable<Orientation>("Direction",dir)->setItems({"Up","Down","Left","Right"});
// Add a button
viewer.ngui->addButton("Print Hello",[](){ std::cout << "Hello\n"; });
// call to generate menu
viewer.screen->performLayout();
return false;
};
// start viewer
viewer.launch();
</code></pre>
<p>If you need a separate new menu window use:</p>
<pre><code class="cpp">viewer.ngui->addWindow(Eigen::Vector2i(220,10),"New Window");
</code></pre>
<p>If you do not want to expose variables directly but rather use the get/set functionality:</p>
<pre><code class="cpp">// ... or using a custom callback
viewer.ngui->addVariable<bool>("bool",[&](bool val) {
boolVariable = val; // setter
},[&]() {
return boolVariable; // getter
});
</code></pre>
<figure>
<img src="images/106_ViewerMenu.png" alt="(Example 106) The UI of the viewer can be easily customized." />
<figcaption>(<a href="106_ViewerMenu/main.cpp">Example 106</a>) The UI of the viewer can be easily customized.</figcaption>
</figure>
<h1 id="chapter2:discretegeometricquantitiesandoperators">Chapter 2: Discrete Geometric Quantities and Operators</h1>
<p>This chapter illustrates a few discrete quantities that libigl can compute on a
mesh and the libigl functions that construct popular discrete differential
geometry operators. It also provides an introduction to basic drawing and coloring routines of our viewer.</p>
<h2 id="normals">Normals</h2>
<p>Surface normals are a basic quantity necessary for rendering a surface. There
are a variety of ways to compute and store normals on a triangle mesh. <a href="201_Normals/main.cpp">Example 201</a> demonstrates how to compute and visualize normals with libigl.</p>
<h3 id="per-face">Per-face</h3>
<p>Normals are well defined on each triangle of a mesh as the vector orthogonal to
triangle’s plane. These piecewise-constant normals produce piecewise-flat
renderings: the surface appears non-smooth and reveals its underlying
discretization.</p>
<h3 id="per-vertex">Per-vertex</h3>
<p>Normals can be computed and stored on vertices, and interpolated in the interior of the triangles to produce smooth renderings (<a href="http://en.wikipedia.org/wiki/Phong_shading">Phong shading</a>).
Most techniques for computing per-vertex normals take an average of incident face normals. The main difference between these techniques is their weighting scheme: Uniform
weighting is heavily biased by the discretization choice, whereas area-based
or angle-based weighting is more forgiving.</p>
<p>The typical half-edge style computation of area-based weights has this structure:</p>
<pre><code class="cpp">N.setZero(V.rows(),3);
for(int i : vertices)
{
for(face : incident_faces(i))
{
N.row(i) += face.area * face.normal;
}
}
N.rowwise().normalize();
</code></pre>
<p>At first glance, it might seem inefficient to loop over incident faces—and thus constructing the per-vertex normals— without using an half-edge data structure. However, per-vertex normals may be <em>throwing</em> each face normal to
running sums on its corner vertices:</p>
<pre><code class="cpp">N.setZero(V.rows(),3);
for(int f = 0; f < F.rows();f++)
{
for(int c = 0; c < 3;c++)
{
N.row(F(f,c)) += area(f) * face_normal.row(f);
}
}
N.rowwise().normalize();
</code></pre>
<h3 id="per-corner">Per-corner</h3>
<p>Storing normals per-corner is an efficient and convenient way of supporting both
smooth and sharp (e.g. creases and corners) rendering. This format is common to
OpenGL and the .obj mesh file format. Often such normals are tuned by the mesh
designer, but creases and corners can also be computed automatically. Libigl
implements a simple scheme which computes corner normals as averages of
normals of faces incident on the corresponding vertex which do not deviate by more than a specified dihedral angle (e.g. 20°).</p>
<figure>
<img src="images/fandisk-normals.jpg" alt="The Normals example computes per-face (left), per-vertex (middle) and
per-corner (right) normals" />
<figcaption>The <code>Normals</code> example computes per-face (left), per-vertex (middle) and
per-corner (right) normals</figcaption>
</figure>
<h2 id="gaussiancurvature">Gaussian curvature</h2>
<p>Gaussian curvature on a continuous surface is defined as the product of the
principal curvatures:</p>
<p><span class="math">\(k_G = k_1 k_2.\)</span></p>
<p>As an <em>intrinsic</em> measure, it depends on the metric and
not the surface’s embedding.</p>
<p>Intuitively, Gaussian curvature tells how locally spherical or <em>elliptic</em> the
surface is ( <span class="math">\(k_G>0\)</span> ), how locally saddle-shaped or <em>hyperbolic</em> the surface
is ( <span class="math">\(k_G<0\)</span> ), or how locally cylindrical or <em>parabolic</em> ( <span class="math">\(k_G=0\)</span> ) the
surface is.</p>
<p>In the discrete setting, one definition for a “discrete Gaussian curvature”
on a triangle mesh is via a vertex’s <em>angular deficit</em>:</p>
<p><span class="math">\(k_G(v_i) = 2π - \sum\limits_{j\in N(i)}θ_{ij},\)</span></p>
<p>where <span class="math">\(N(i)\)</span> are the triangles incident on vertex <span class="math">\(i\)</span> and <span class="math">\(θ_{ij}\)</span> is the angle
at vertex <span class="math">\(i\)</span> in triangle <span class="math">\(j\)</span> <a class="citation" href="#fn:1" title="Jump to citation">[1]<span class="citekey" style="display:none">meyer_2003</span></a>.</p>
<p>Just like the continuous analog, our discrete Gaussian curvature reveals
elliptic, hyperbolic and parabolic vertices on the domain, as demonstrated in <a href="202GaussianCurvature/main.cpp">Example 202</a>.</p>
<figure>
<img src="images/bumpy-gaussian-curvature.jpg" alt="The GaussianCurvature example computes discrete Gaussian curvature and
visualizes it in pseudocolor." />
<figcaption>The <code>GaussianCurvature</code> example computes discrete Gaussian curvature and
visualizes it in pseudocolor.</figcaption>
</figure>
<h2 id="curvaturedirections">Curvature directions</h2>
<p>The two principal curvatures <span class="math">\((k_1,k_2)\)</span> at a point on a surface measure how
much the surface bends in different directions. The directions of maximum and
minimum (signed) bending are called principal directions and are always
orthogonal.</p>
<p>Mean curvature is defined as the average of principal curvatures:</p>
<p><span class="math">\(H = \frac{1}{2}(k_1 + k_2).\)</span></p>
<p>One way to extract mean curvature is by examining the Laplace-Beltrami operator
applied to the surface positions. The result is a so-called mean-curvature
normal:</p>
<p><span class="math">\(-\Delta \mathbf{x} = H \mathbf{n}.\)</span></p>
<p>It is easy to compute this on a discrete triangle mesh in libigl using the
cotangent Laplace-Beltrami operator <a class="citation" href="#fn:1" title="Jump to citation">[1]<span class="citekey" style="display:none">meyer_2003</span></a>.</p>
<pre><code class="cpp">#include <igl/cotmatrix.h>
#include <igl/massmatrix.h>
#include <igl/invert_diag.h>
...
MatrixXd HN;
SparseMatrix<double> L,M,Minv;
igl::cotmatrix(V,F,L);
igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_VORONOI,M);
igl::invert_diag(M,Minv);
HN = -Minv*(L*V);
H = HN.rowwise().norm(); //up to sign
</code></pre>
<p>Combined with the angle defect definition of discrete Gaussian curvature, one
can define principal curvatures and use least squares fitting to find
directions <a class="citation" href="#fn:1" title="Jump to citation">[1]<span class="citekey" style="display:none">meyer_2003</span></a>.</p>
<p>Alternatively, a robust method for determining principal curvatures is via
quadric fitting <a class="citation" href="#fn:2" title="Jump to citation">[2]<span class="citekey" style="display:none">panozzo_2010</span></a>. In the neighborhood around every vertex, a
best-fit quadric is found and principal curvature values and directions are
analytically computed on this quadric (<a href="203_curvatureDirections/main.cpp">Example
203</a>).</p>
<figure>
<img src="images/fertility-principal-curvature.jpg" alt="The CurvatureDirections example computes principal curvatures via quadric
fitting and visualizes mean curvature in pseudocolor and principal directions
with a cross field." />
<figcaption>The <code>CurvatureDirections</code> example computes principal curvatures via quadric
fitting and visualizes mean curvature in pseudocolor and principal directions
with a cross field.</figcaption>
</figure>
<h2 id="gradient">Gradient</h2>
<p>Scalar functions on a surface can be discretized as a piecewise linear function
with values defined at each mesh vertex:</p>
<p><span class="math">\(f(\mathbf{x}) \approx \sum\limits_{i=1}^n \phi_i(\mathbf{x})\, f_i,\)</span></p>
<p>where <span class="math">\(\phi_i\)</span> is a piecewise linear hat function defined by the mesh so that
for each triangle <span class="math">\(\phi_i\)</span> is <em>the</em> linear function which is one only at
vertex <span class="math">\(i\)</span> and zero at the other corners.</p>
<figure>
<img src="images/hat-function.jpg" alt="Hat function $\phi_i$ is one at vertex $i$, zero at all other vertices, and
linear on incident triangles." />
<figcaption>Hat function <span class="math">\(\phi_i\)</span> is one at vertex <span class="math">\(i\)</span>, zero at all other vertices, and
linear on incident triangles.</figcaption>
</figure>
<p>Thus gradients of such piecewise linear functions are simply sums of gradients
of the hat functions:</p>
<p><span class="math">\(\nabla f(\mathbf{x}) \approx
\nabla \sum\limits_{i=1}^n \phi_i(\mathbf{x})\, f_i =
\sum\limits_{i=1}^n \nabla \phi_i(\mathbf{x})\, f_i.\)</span></p>
<p>This reveals that the gradient is a linear function of the vector of <span class="math">\(f_i\)</span>
values. Because the <span class="math">\(\phi_i\)</span> are linear in each triangle, their gradients are
<em>constant</em> in each triangle. Thus our discrete gradient operator can be written
as a matrix multiplication taking vertex values to triangle values:</p>
<p><span class="math">\(\nabla f \approx \mathbf{G}\,\mathbf{f},\)</span></p>
<p>where <span class="math">\(\mathbf{f}\)</span> is <span class="math">\(n\times 1\)</span> and <span class="math">\(\mathbf{G}\)</span> is an <span class="math">\(md\times n\)</span> sparse
matrix. This matrix <span class="math">\(\mathbf{G}\)</span> can be derived geometrically, e.g.
<a class="citation" href="#fn:3" title="Jump to citation">[<span class="locator">ch. 2</span>, 3]<span class="citekey" style="display:none">jacobson_thesis_2013</span></a>.
Libigl’s <code>grad</code> function computes <span class="math">\(\mathbf{G}\)</span> for
triangle and tetrahedral meshes (<a href="204_Gradient/main.cpp">Example 204</a>):</p>
<figure>
<img src="images/cheburashka-gradient.jpg" alt="The Gradient example computes gradients of an input function on a mesh and
visualizes the vector field." />
<figcaption>The <code>Gradient</code> example computes gradients of an input function on a mesh and
visualizes the vector field.</figcaption>
</figure>
<h2 id="laplacian">Laplacian</h2>
<p>The discrete Laplacian is an essential geometry processing tool. Many
interpretations and flavors of the Laplace and Laplace-Beltrami operator exist.</p>
<p>In open Euclidean space, the <em>Laplace</em> operator is the usual divergence of
gradient (or equivalently the Laplacian of a function is the trace of its
Hessian):</p>
<p><span class="math">\(\Delta f =
\frac{\partial^2 f}{\partial x^2} +
\frac{\partial^2 f}{\partial y^2} +
\frac{\partial^2 f}{\partial z^2}.\)</span></p>
<p>The <em>Laplace-Beltrami</em> operator generalizes this to surfaces.</p>
<p>When considering piecewise-linear functions on a triangle mesh, a discrete
Laplacian may be derived in a variety of ways. The most popular in geometry
processing is the so-called “cotangent Laplacian” <span class="math">\(\mathbf{L}\)</span>, arising
simultaneously from FEM, DEC and applying divergence theorem to vertex
one-rings. As a linear operator taking vertex values to vertex values, the
Laplacian <span class="math">\(\mathbf{L}\)</span> is a <span class="math">\(n\times n\)</span> matrix with elements:</p>
<p><span class="math">\(L_{ij} = \begin{cases}j \in N(i) &\cot \alpha_{ij} + \cot \beta_{ij},\\
j \notin N(i) & 0,\\
i = j & -\sum\limits_{k\neq i} L_{ik},
\end{cases}\)</span></p>
<p>where <span class="math">\(N(i)\)</span> are the vertices adjacent to (neighboring) vertex <span class="math">\(i\)</span>, and
<span class="math">\(\alpha_{ij},\beta_{ij}\)</span> are the angles opposite to edge <span class="math">\({ij}\)</span>.
This formula leads to a typical half-edge style implementation for
constructing <span class="math">\(\mathbf{L}\)</span>:</p>
<pre><code class="cpp">for(int i : vertices)
{
for(int j : one_ring(i))
{
for(int k : triangle_on_edge(i,j))
{
L(i,j) = cot(angle(i,j,k));
L(i,i) -= cot(angle(i,j,k));
}
}
}
</code></pre>
<p>Similarly as before, it may seem to loop over one-rings without having an half-edge data structure. However, this is not the case, since the Laplacian may be built by summing together contributions for each triangle, much in spirit with its FEM discretization
of the Dirichlet energy (sum of squared gradients):</p>
<pre><code class="cpp">for(triangle t : triangles)
{
for(edge i,j : t)
{
L(i,j) += cot(angle(i,j,k));
L(j,i) += cot(angle(i,j,k));
L(i,i) -= cot(angle(i,j,k));
L(j,j) -= cot(angle(i,j,k));
}
}
</code></pre>
<p>Libigl implements discrete “cotangent” Laplacians for triangles meshes and
tetrahedral meshes, building both with fast geometric rules rather than “by the
book” FEM construction which involves many (small) matrix inversions, cf.
<a class="citation" href="#fn:4" title="Jump to citation">[4]<span class="citekey" style="display:none">sharf_2007</span></a>.</p>
<p>The operator applied to mesh vertex positions amounts to smoothing by <em>flowing</em>
the surface along the mean curvature normal direction (<a href="205_Laplacian/main.cpp">Example 205</a>). Note that this is equivalent to minimizing surface area.</p>
<figure>
<img src="images/cow-curvature-flow.jpg" alt="The Laplacian example computes conformalized mean curvature flow using the
cotangent Laplacian ." />
<figcaption>The <code>Laplacian</code> example computes conformalized mean curvature flow using the
cotangent Laplacian <a class="citation" href="#fn:5" title="Jump to citation">[5]<span class="citekey" style="display:none">kazhdan_2012</span></a>.</figcaption>
</figure>
<h3 id="massmatrix">Mass matrix</h3>
<p>The mass matrix <span class="math">\(\mathbf{M}\)</span> is another <span class="math">\(n \times n\)</span> matrix which takes vertex
values to vertex values. From an FEM point of view, it is a discretization of
the inner-product: it accounts for the area around each vertex. Consequently,
<span class="math">\(\mathbf{M}\)</span> is often a diagonal matrix, such that <span class="math">\(M_{ii}\)</span> is the barycentric
or voronoi area around vertex <span class="math">\(i\)</span> in the mesh <a class="citation" href="#fn:1" title="Jump to citation">[1]<span class="citekey" style="display:none">meyer_2003</span></a>. The inverse of
this matrix is also very useful as it transforms integrated quantities into
point-wise quantities, e.g.:</p>
<p><span class="math">\(\Delta f \approx \mathbf{M}^{-1} \mathbf{L} \mathbf{f}.\)</span></p>
<p>In general, when encountering squared quantities integrated over the surface,
the mass matrix will be used as the discretization of the inner product when
sampling function values at vertices:</p>
<p><span class="math">\(\int_S x\, y\ dA \approx \mathbf{x}^T\mathbf{M}\,\mathbf{y}.\)</span></p>
<p>An alternative mass matrix <span class="math">\(\mathbf{T}\)</span> is a <span class="math">\(md \times md\)</span> matrix which takes
triangle vector values to triangle vector values. This matrix represents an
inner-product accounting for the area associated with each triangle (i.e. the
triangles true area).</p>
<h3 id="alternativeconstructionoflaplacian">Alternative construction of Laplacian</h3>
<p>An alternative construction of the discrete cotangent Laplacian is by
“squaring” the discrete gradient operator. This may be derived by applying
Green’s identity (ignoring boundary conditions for the moment):</p>
<p><span class="math">\(\int_S \|\nabla f\|^2 dA = \int_S f \Delta f dA\)</span></p>
<p>Or in matrix form which is immediately translatable to code:</p>
<p><span class="math">\(\mathbf{f}^T \mathbf{G}^T \mathbf{T} \mathbf{G} \mathbf{f} =
\mathbf{f}^T \mathbf{M} \mathbf{M}^{-1} \mathbf{L} \mathbf{f} =
\mathbf{f}^T \mathbf{L} \mathbf{f}.\)</span></p>
<p>So we have that <span class="math">\(\mathbf{L} = \mathbf{G}^T \mathbf{T} \mathbf{G}\)</span>. This also
hints that we may consider <span class="math">\(\mathbf{G}^T\)</span> as a discrete <em>divergence</em> operator,
since the Laplacian is the divergence of the gradient. Naturally, <span class="math">\(\mathbf{G}^T\)</span> is
a <span class="math">\(n \times md\)</span> sparse matrix which takes vector values stored at triangle faces
to scalar divergence values at vertices.</p>
<h1 id="chapter3:matricesandlinearalgebra">Chapter 3: Matrices and linear algebra</h1>
<p>Libigl relies heavily on the Eigen library for dense and sparse linear algebra
routines. Besides geometry processing routines, libigl has linear algebra
routines which bootstrap Eigen and make it feel even more similar to a high-level
algebra library such as Matlab.</p>
<h2 id="slice">Slice</h2>
<p>A very familiar and powerful routine in Matlab is array slicing. This allows
reading from or writing to a possibly non-contiguous sub-matrix. Let’s consider
the Matlab code:</p>
<pre><code class="matlab">B = A(R,C);
</code></pre>
<p>If <code>A</code> is a <span class="math">\(m \times n\)</span> matrix and <code>R</code> is a <span class="math">\(j\)</span>-long list of row-indices
(between 1 and <span class="math">\(m\)</span>) and <code>C</code> is a <span class="math">\(k\)</span>-long list of column-indices, then as a
result <code>B</code> will be a <span class="math">\(j \times k\)</span> matrix drawing elements from <code>A</code> according to
<code>R</code> and <code>C</code>. In libigl, the same functionality is provided by the <code>slice</code>
function (<a href="301_Slice/main.cpp">Example 301</a>):</p>
<pre><code class="cpp">VectorXi R,C;
MatrixXd A,B;
...
igl::slice(A,R,C,B);
</code></pre>
<p>Note that <code>A</code> and <code>B</code> could also be sparse matrices.</p>
<p>Similarly, consider the Matlab code:</p>
<pre><code class="matlab">A(R,C) = B;
</code></pre>
<p>Now, the selection is on the left-hand side so the <span class="math">\(j \times k\)</span> matrix <code>B</code> is
being <em>written into</em> the submatrix of <code>A</code> determined by <code>R</code> and <code>C</code>. This
functionality is provided in libigl using <code>slice_into</code>:</p>
<pre><code class="cpp">igl::slice_into(B,R,C,A);
</code></pre>
<figure>
<img src="images/decimated-knight-slice-color.jpg" alt="The example Slice shows how to use igl::slice to change the colors for
triangles on a mesh." />
<figcaption>The example <code>Slice</code> shows how to use <code>igl::slice</code> to change the colors for
triangles on a mesh.</figcaption>
</figure>
<h2 id="sort">Sort</h2>
<p>Matlab and other higher-level languages make it very easy to extract indices of
sorting and comparison routines. For example in Matlab, one can write:</p>
<pre><code class="matlab">[Y,I] = sort(X,1,'ascend');
</code></pre>
<p>so if <code>X</code> is a <span class="math">\(m \times n\)</span> matrix then <code>Y</code> will also be an <span class="math">\(m \times n\)</span> matrix
with entries sorted along dimension <code>1</code> in <code>'ascend'</code>ing order. The second
output <code>I</code> is a <span class="math">\(m \times n\)</span> matrix of indices such that <code>Y(i,j) =
X(I(i,j),j);</code>. That is, <code>I</code> reveals how <code>X</code> is sorted into <code>Y</code>.</p>
<p>This same functionality is supported in libigl:</p>
<pre><code class="cpp">igl::sort(X,1,true,Y,I);
</code></pre>
<p>Similarly, sorting entire rows can be accomplished in Matlab using:</p>
<pre><code class="matlab">[Y,I] = sortrows(X,'ascend');
</code></pre>
<p>where now <code>I</code> is a <span class="math">\(m\)</span> vector of indices such that <code>Y = X(I,:)</code>.</p>
<p>In libigl, this is supported with</p>
<pre><code class="cpp">igl::sortrows(X,true,Y,I);
</code></pre>
<p>where again <code>I</code> reveals the index of sort so that it can be reproduced with
<code>igl::slice(X,I,1,Y)</code>.</p>
<p>Analogous functions are available in libigl for: <code>max</code>, <code>min</code>, and <code>unique</code>.</p>
<figure>
<img src="images/decimated-knight-sort-color.jpg" alt="The example Sort shows how to use igl::sortrows to
pseudocolor triangles according to their barycenters' sorted
order (Example 302)." />
<figcaption>The example <code>Sort</code> shows how to use <code>igl::sortrows</code> to
pseudocolor triangles according to their barycenters’ sorted
order (<a href="302_Sort/main.cpp">Example 302</a>).</figcaption>
</figure>
<h3 id="othermatlab-stylefunctions">Other Matlab-style functions</h3>
<p>Libigl implements a variety of other routines with the same api and
functionality as common Matlab functions.</p>
<table>
<colgroup>
<col style="text-align:left;"/>
<col style="text-align:left;"/>
</colgroup>
<thead>
<tr>
<th style="text-align:left;">Name</th>
<th style="text-align:left;">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"><code>igl::any_of</code></td>
<td style="text-align:left;">Whether any elements are non-zero (true)</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::cat</code></td>
<td style="text-align:left;">Concatenate two matrices (especially useful for dealing with Eigen sparse matrices)</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::ceil</code></td>
<td style="text-align:left;">Round entries up to nearest integer</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::cumsum</code></td>
<td style="text-align:left;">Cumulative sum of matrix elements</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::colon</code></td>
<td style="text-align:left;">Act like Matlab’s <code>:</code>, similar to Eigen’s <code>LinSpaced</code></td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::cross</code></td>
<td style="text-align:left;">Cross product per-row</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::dot</code></td>
<td style="text-align:left;">dot product per-row</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::find</code></td>
<td style="text-align:left;">Find subscripts of non-zero entries</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::floor</code></td>
<td style="text-align:left;">Round entries down to nearest integer</td>
</tr>
<tr>
<td style="text-align:left;"><code>igl::histc</code></td>
<td style="text-align:left;">Counting occurrences for building a histogram</td>
</tr>
<tr>