Browse Source

added notes on using matlab with libigl

Former-commit-id: c4ca96f9f62f2ecc82bf63ff76a9316f3e0b16b1
Daniele Panozzo 11 years ago
parent
commit
9015ffe529

+ 2 - 2
tutorial/500_Parametrization.md

@@ -151,7 +151,7 @@ igl::nrosy(V,F,b,bc,b_soft,b_soft_weight,bc_soft,N,0.5,
            output_field,output_singularities);
 ```
 
-creates a smooth vector field (N=1) starting from a sparse set of constrained faces, whose indices are listed in b and their constrained value is specified in bc. The functions supports soft_constraints (b_soft,b_soft_weight,bc_soft), and returns the interpolated field for each face of the triangle mesh (output_field) plus the singularities of the field (output_field).
+creates a smooth vector field (N=1) starting from a sparse set of constrained faces, whose indices are listed in b and their constrained value is specified in bc. The functions supports soft_constraints (b_soft,b_soft_weight,bc_soft), and returns the interpolated field for each face of the triangle mesh (output_field) plus the singularities of the field (output_singularities).
 
 ![Design of a unit-lenght vector field](images/504_vector_field.png)
 
@@ -175,7 +175,7 @@ SIGGRAPH 2009
 
 The previous parametrization methods where focusing on generating parametrization of single patches, mainly aimed at texture mapping and baking of other surface properties like normals high-frequency details. Global, seamless parametrization aims at parametrizing complex shapes with a parametrization that is aligned with a given set of directions for the purpose of remeshing the surface. In libigl, we provide a reference  implementation of the pipeline of the  [MIQ](http://www-sop.inria.fr/members/David.Bommes/publications/miq.pdf) paper.
 
-## Gradient field design (up to rotation and trianslation) [505]
+### Global, seamless integer-grid parametrization [505]
 
 The first step involves the design of a 4-RoSy field (sometimes called cross field) that describes how the edges of the final quad remeshing should align. The field constraints are usually manually specified or extracted from curvature. In this example, we simply fix one face in a random direction.
 

+ 164 - 0
tutorial/600_External_libraries.md

@@ -0,0 +1,164 @@
+title: libigl Tutorial
+author: Daniele Panozzo, Alec Jacobson and others
+date: 20 June 2014
+css: style.css
+html header:   <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>
+
+* [Chapter 6: External libraries][600]
+    * [601 State serialization][601]
+    * [602 Mixing matlab code][602]
+    * [603 Calling igl functions from matlab][603]
+    * [604 Triangulation of closed polygons][604]
+    * [605 Tetrahedralization of closed surfaces][605]
+    * [606 Baking ambient occlusion][606]
+
+# Chapter 6: External libraries [600]
+
+An additional positive side effect of using matrices as basic types is that it is easy to exchange data between libigl and other softwares and libraries.
+
+## State serialization [601]
+
+Geometry processing applications often require a considerable amount of computational time and/or manual input. In order to make the development efficient it must be possible to serialize and deserialize the state of the application.
+
+Having a good serialization framework allows to quickly start debugging just before the crash happens, avoiding to wait for the precomputation to take place every time. It also makes it easier to define unit testing that can be used to find bugs in interactive applications: if the input is slightly different every time the algorithm is executed, it is very difficult to find bugs.
+
+Unfortunately, serialization is often not considered in geoemtry processing due to the extreme difficulty in serializing pointer-based data structures (like an helf-edge).
+
+In libigl, serialization is simpler, since the majority of the functions use basic types, and pointers are used in very rare cases (usually to interface with external libraries). libigl provides an extremely easy to use XML serialization framework, that drastically reduces the overhead required to add serialization to your applications.
+
+Assume that the state of your application is composed of a mesh and set of integer ids:
+``` cpp
+class State : public ::igl::XMLSerialization
+{
+public:
+  State() : XMLSerialization("dummy") {}
+
+  Eigen::MatrixXd V;
+  Eigen::MatrixXi F;
+  std::vector<int> ids;
+
+  void InitSerialization()
+  {
+    xmlSerializer->Add(V  , "V");
+    xmlSerializer->Add(F  , "F");
+    xmlSerializer->Add(ids, "ids");
+  }
+};
+```
+
+A class can be made serializable by inheriting from ::igl::XMLSerialization and trivially implementing the InitSerialization method. Note that you don't have to care the types, Add is able to serialize all basic stl types, all Eigen types and any class inheriting from ::igl::XMLSerialization.
+
+It is then possible to save the state to an xml file:
+
+``` cpp
+::igl::XMLSerializer serializer_save("601_Serialization");
+serializer_save.Add(state,"State");
+serializer_save.Save("temp.xml",true);
+```
+
+This code generates the following xml file (assuming V and F contains a simple mesh with two triangles, and ids contains the numbers 6 and 7):
+``` xml
+<:::601_Serialization>
+    <State>
+        <V rows="4" cols="3" matrix="
+0,0,0,
+1,0,0,
+1,1,1,
+2,1,0"/>
+        <F rows="2" cols="3" matrix="
+0,1,2,
+1,3,2"/>
+        <ids size="2" vector_int="
+6,7"/>
+    </State>
+</:::601_Serialization>
+```
+
+The xml file can then be loaded in a similar way:
+
+``` cpp
+State loaded_state;
+::igl::XMLSerializer serializer_load("601_Serialization");
+serializer_load.Add(loaded_state,"State");
+serializer_load.Load("temp.xml");
+```
+
+This can also be used as a convenient interface to provide parameters to command line applications, since the xml files can be directly edited with a standard text editor.
+
+We demonstrate the serialization framework in [Example 601](601_Serialization/main.cpp). We strongly suggest that you make the entire state of your application always serializable: this will save you a lot of troubles when you'll be making figures for a scientific publication. It is very common to have to do small changes to figures during the production of a paper, and being able to serialize the entire state just before you take screenshots will save you many painful hours before a submission deadline.
+
+## Mixing matlab code [602]
+
+libigl can be interfaced matlab, to offload some of the numerically heavy computation to a matlab script. This has the major advantage of allowing to develop efficient and complex UI in C++, while keeping the advantage of fast protototyping of matlab. In particular, using an external matlab script in a libigl application allows to change the algorithm in the matlab script without having to recompile the C++ part.
+
+We demonstrate how to integrate matlab in a libigl application in [Example 602](602_Matlab/main.cpp). The example uses matlab to compute the Eigenfunctions of the discrete Laplacian operator, relying on libigl for mesh IO, visualization and for computing the Laplacian operator.
+
+libigl can connect to an existing instance of matlab (or launching a new one on Linux/MacOSX) using:
+
+``` cpp
+igl::mlinit(&engine);
+```
+
+The cotangent laplacian is computed using igl::cotmatrix and uploaded to the matlab workspace:
+
+``` cpp
+igl::cotmatrix(V,F,L);
+igl::mlsetmatrix(&engine,"L",L);
+```
+
+It is now possible to use any matlab function on the data. For example, we can see the sparsity pattern of L using spy:
+
+``` cpp
+igl::mleval(&engine,"spy(L)");
+```
+
+![The matlab spy function is called from a libigl-based application.](images/602_Matlab_1.png)
+
+You can also do some computation and then return it back to the C++ application
+
+``` cpp
+igl::mleval(&engine,"[EV,~] = eigs(-L,10,'sm')");
+igl::mlgetmatrix(&engine,"EV",EV);
+```
+
+and then use libigl functions to plot the eigenfunctions.
+
+![4 Eigenfunctions of the Laplacian plotted in the libigl viewer.](images/602_Matlab_2.png)
+
+## Calling igl functions from matlab [603]
+
+It is also possible to call libigl functions from matlab, compiling them as MEX functions. This can be very useful to offload to C++ code the computationally intensive parts of a matlab application.
+
+We provide a wrapper for igl::readOBJ in [Example 603](603_MEX/compileMEX.m). We plan to provide wrappers for all our functions in the future, if you are interested in this feature (or if you want to help implementing it) please let us know.
+
+## Triangulation of closed polygons [604]
+
+
+
+* discretization are useful to solve PDE
+* to create a 2D triangulation we provide a convenient wrapper for triangle
+
+#Tetrahedralization of closed surfaces
+
+* the same in 3D, similar interface
+
+#Baking ambient occlusion
+
+* intro to ambinet occlusion
+* can be easily computed with raytracing
+* again a simple wrapper
+* then you multiply to the colors
+
+
+#Outlook for continuing development
+
+* better documentation
+* your contributions are welcome, using pull request
+* open things to do
+  * isotropic remeshing
+  * matlab wrappers
+  * mixed integer solvers
+  * fast spatial indices

+ 1 - 1
tutorial/601_Serialization/main.cpp

@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
   State state;
 
   // Load a mesh in OFF format
-  igl::readOFF("../shared/cube.off", state.V, state.F);
+  igl::readOFF("../shared/2triangles.off", state.V, state.F);
 
   // Save some integers in a vector
   state.ids.push_back(6);

+ 1 - 1
tutorial/602_Matlab/main.cpp

@@ -57,7 +57,7 @@ int main(int argc, char *argv[])
   // Send Laplacian matrix to matlab
   igl::mlsetmatrix(&engine,"L",L);
 
-  // Plot the laplacian matri using matlab spy
+  // Plot the laplacian matrix using matlab spy
   igl::mleval(&engine,"spy(L)");
 
   // Extract the first 10 eigenvectors

+ 1 - 1
tutorial/602_Matlab/run.sh

@@ -7,4 +7,4 @@
 
 export DYLD_LIBRARY_PATH=/Applications/MATLAB_R2012b.app/bin/maci64/
 
-./build/602_Matlab
+./build/602_Matlab_bin

BIN
tutorial/images/602_Matlab_1.png


+ 1 - 0
tutorial/images/602_Matlab_2.png.REMOVED.git-id

@@ -0,0 +1 @@
+2beb0ca7990862a5838a719ad3c13680f169ede3

+ 8 - 0
tutorial/shared/2triangles.off

@@ -0,0 +1,8 @@
+OFF
+4 2 5
+ 0.0   0.0   0.0
+ 1.0   0.0   0.0
+ 1.0   1.0   1.0
+ 2.0   1.0   0.0
+ 3  0 1 2
+ 3  1 3 2