index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>libigl</title>
  6. <meta name="author" content="Alec Jacobson and Daniele Panozzo and others"/>
  7. <link type="text/css" rel="stylesheet" href="../tutorial/style.css"/>
  8. <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
  9. <link rel='stylesheet' href='http://yandex.st/highlightjs/7.3/styles/default.min.css'>
  10. <script src='http://yandex.st/highlightjs/7.3/highlight.min.js'></script>
  11. <script>hljs.initHighlightingOnLoad();</script>
  12. </head>
  13. <body>
  14. <h1 id="compilinglibiglasastaticlibrary">Compiling libigl as a static library</h1>
  15. <blockquote>
  16. <p>Warning: compiling libigl as a static library is considerably more difficult
  17. than using it as a header-only library (see <code>../README.md</code> instead). Do it
  18. only if you are experienced with C++ and you want to improve your compilation
  19. times.</p>
  20. </blockquote>
  21. <p>Libigl is developed most often on Mac OS X, though has current users in Linux
  22. and Windows.</p>
  23. <h3 id="linuxmacosxcygwin">Linux/Mac OS X/Cygwin</h3>
  24. <p>Libigl may also be compiled to a static library. This is advantageous when
  25. building a project with libigl, since when used as an header-only library can
  26. slow down compile times.</p>
  27. <p>To build the entire libigl library producing <code>lib/libigl.a</code>, issue:</p>
  28. <pre><code>cd build
  29. make lib
  30. </code></pre>
  31. <p>You may need to edit <code>Makefile.conf</code> accordingly. Best to give yourself an
  32. <code>IGL_USERNAME</code> and add a custom install suite for yourself. Then you can enable
  33. appropriate extras.</p>
  34. <h4 id="extras">Extras</h4>
  35. <p>Once you&#8217;ve set up an <code>IGL_USERNAME</code> and enabled extras within Makefile.conf.
  36. You can build the extra libraries (into <code>lib/ligiglpng.a</code>, <code>lib/libiglmatlab.a</code>,
  37. <code>lib/libigltetgen.a</code>, <code>lib/libiglmosek.a</code>, etc.) by issuing:</p>
  38. <pre><code>cd build
  39. make extras
  40. </code></pre>
  41. <h4 id="examples">Examples</h4>
  42. <p>You can make a slew of examples by issuing:</p>
  43. <pre><code>cd build
  44. make examples
  45. </code></pre>
  46. <h4 id="external">External</h4>
  47. <p>Finally there are a number of external libraries that we include in
  48. <code>./external/</code> because they are either difficult to obtain or they have been
  49. patched for easier use with libigl. Please see the respective readmes in those
  50. directories.</p>
  51. <h5 id="installinganttweakbar">Installing AntTweakBar</h5>
  52. <p>To build the a static AntTweakBar library on Mac OS X issue:</p>
  53. <pre><code>cd external/AntTweakBar/src
  54. make -f Makefile.osx.igl
  55. </code></pre>
  56. <h5 id="installingtetgen">Installing Tetgen</h5>
  57. <p>To build the tetgen library and executable on Mac OS X issue:</p>
  58. <pre><code>cd external/tetgen
  59. make clean
  60. rm -f obj/*.o
  61. make -f Makefile.igl tetgen
  62. rm -f obj/*.o
  63. make -f Makefile.igl tetlib
  64. </code></pre>
  65. <h5 id="installingmedit">Installing medit</h5>
  66. <p>To build the igl version of the medit executable on Mac OS X issue:</p>
  67. <pre><code>cd external/medit
  68. make -C libmesh
  69. make -f Makefile.igl medit
  70. </code></pre>
  71. <h5 id="installingembree2.0">Installing Embree 2.0</h5>
  72. <p>To build the embree library and executables on Mac OS X issue:</p>
  73. <pre><code>cd external/embree
  74. mkdir build
  75. cd build
  76. cmake ..
  77. # Or using a different compiler
  78. #cmake .. -DCMAKE_C_COMPILER=/opt/local/bin/gcc -DCMAKE_CXX_COMPILER=/opt/local/bin/g++
  79. make
  80. # Could also install embree to your root, but libigl examples don't expect
  81. # this
  82. #sudo make install
  83. </code></pre>
  84. <h5 id="installingtinyxml2">Installing tinyxml2</h5>
  85. <p>To build the a static tinyxml2 library on Mac OS X issue:</p>
  86. <pre><code>cd external/tinyxml2
  87. cmake .
  88. make
  89. </code></pre>
  90. <h5 id="installingyimg">Installing YImg</h5>
  91. <p>To build the a static YImg library on Mac OS X issue:</p>
  92. <pre><code>cd external/yimg
  93. make
  94. </code></pre>
  95. <p>You may need to install libpng. Systems with X11 might find this already
  96. installed at <code>/usr/X11/lib</code>.</p>
  97. <h3 id="windowsexperimental">Windows (Experimental)</h3>
  98. <p>To build a static library (.lib) on windows, open Visual Studio 2010.</p>
  99. <ul>
  100. <li>New &gt; Project &#8230;</li>
  101. <li>Visual C++ &gt; Win32</li>
  102. <li>Win32 Console Application</li>
  103. <li>Name: libiglVisualStudio</li>
  104. <li>Uncheck &#8220;Create directory for solution&#8221;</li>
  105. <li>Then hit OK, and then Next</li>
  106. <li>Check &#8220;Static Library&#8221;</li>
  107. <li>Uncheck &#8220;Precompiled headers&#8221;</li>
  108. <li>Add all include/igl/*.cpp to the sources directory</li>
  109. <li>Add all include/igl/*.h to the headers directory</li>
  110. <li>Open Project &gt; libigl Properties&#8230;</li>
  111. <li>Add the path to eigen3 to the include paths</li>
  112. <li>Change the target name to libigl</li>
  113. <li>Build and pray (this should create libigl.lib</li>
  114. </ul>
  115. <p><a href="http://msdn.microsoft.com/en-us/library/ms235627(v=vs.80).aspx">Source</a></p>
  116. <h2 id="examples">Examples</h2>
  117. <p>To get started, we advise that you take a look at a few examples:</p>
  118. <pre><code>./examples/hello-world/
  119. ./examples/meshio/
  120. ./examples/basic-topology/
  121. ./examples/ReAntTweakBar/
  122. </code></pre>
  123. <h2 id="extras">Extras</h2>
  124. <p>Libigl compartmentalizes dependences via its organization into a <em>main</em> libigl
  125. library and &#8220;extras.&#8221;</p>
  126. <h3 id="bbw">bbw</h3>
  127. <p>This library extra contains functions for computing Bounded Biharmonic Weights, can
  128. be used with and without the <a href="#mosek">mosek</a> extra via the <code>IGL_NO_MOSEK</code>
  129. macro.</p>
  130. <h3 id="boost">boost</h3>
  131. <p>This library extra utilizes the graph functions in the boost library for find
  132. connected components and performing breadth-first traversals.</p>
  133. <h3 id="cgal">cgal</h3>
  134. <p>This library extra utilizes CGAL&#8217;s efficient and exact intersection and
  135. proximity queries.</p>
  136. <h3 id="embree">embree</h3>
  137. <p>This library extra utilizes embree&#8217;s efficient ray tracing queries.</p>
  138. <h3 id="matlab">matlab</h3>
  139. <p>This library extra provides support for reading and writing <code>.mat</code> workspace
  140. files, interfacing with Matlab at run time and compiling mex functions.</p>
  141. <h3 id="mosek">mosek</h3>
  142. <p>This library extra utilizes mosek&#8217;s efficient interior-point solver for
  143. quadratic programs.</p>
  144. <h3 id="png">png</h3>
  145. <p>This library extra uses <code>libpng</code> and <code>YImage</code> to read and write <code>.png</code> files.</p>
  146. <h3 id="svd3x3">svd3x3</h3>
  147. <p>This library extra implements &#8220;as-rigid-as-possible&#8221; (ARAP) deformation
  148. techniques using the fast singular value decomposition routines
  149. written specifically for 3x3 matrices to use <code>SSE</code> intrinsics. This extra can
  150. still be compiled without sse support and support should be determined
  151. automatically at compile time via the <code>__SSE__</code> macro.</p>
  152. <h3 id="tetgen">tetgen</h3>
  153. <p>This library extra provides a simplified wrapper to the tetgen 3d tetrahedral meshing
  154. library.</p>
  155. <h3 id="viewer">viewer</h3>
  156. <p>This library extra utilizes glfw and glew to open an opengl context and launch
  157. a simple mesh viewer.</p>
  158. <h3 id="xml">xml</h3>
  159. <p>This library extra utilizes tinyxml2 to read and write serialized classes
  160. containing Eigen matrices and other standard simple data-structures.</p>
  161. <h2 id="development">Development</h2>
  162. <p>Further documentation for developers is listed in
  163. <a href="../style_guidelines.html">style_guidelines.html</a>.</p>
  164. <h2 id="license">License</h2>
  165. <p>See <code>LICENSE.txt</code></p>
  166. <h2 id="zipping">Zipping</h2>
  167. <p>Zip this directory without .git litter and binaries using:</p>
  168. <pre><code>git archive -prefix=libigl/ -o libigl.zip master
  169. </code></pre>
  170. <h2 id="explicitspecializationoftemplatedfunctions">Explicit specialization of templated functions</h2>
  171. <p>Special care must be taken by the developers of each function and
  172. class in the libigl library that uses C++ templates. If this function
  173. is intended to be compiled into the statically linked libigl library
  174. then function is only compiled for each <i>explicitly</i> specialized
  175. declaration. These should be added at the bottom of the corresponding
  176. .cpp file surrounded by a</p>
  177. <pre><code>#ifdef IGL_STATIC_LIBRARY
  178. </code></pre>
  179. <p>Of course, a developer may not know ahead of time which
  180. specializations should be explicitly included in the igl static lib.
  181. One way to find out is to add one explicit specialization for each
  182. call in one&#8217;s own project. This only ever needs to be done once for
  183. each template.</p>
  184. <p>The process is somewhat mechanical using a linker with reasonable error
  185. output.</p>
  186. <p>Supposed for example we have compiled the igl static lib, including the
  187. cat.h and cat.cpp functions, without any explicit instanciation. Say
  188. using the makefile in the <code>libigl</code> directory:</p>
  189. <pre><code>cd $LIBIGL
  190. make
  191. </code></pre>
  192. <p>Now if we try to compile a project and link against it we may get
  193. an error like:</p>
  194. <pre><code>Undefined symbols for architecture x86_64:
  195. &quot;Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; igl::cat&lt;Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; &gt;(int, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;)&quot;, referenced from:
  196. uniform_sample(Eigen::Matrix&lt;double, -1, -1, 0, -1, -1&gt; const&amp;, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;, int, double, Eigen::Matrix&lt;double, -1, -1, 0, -1, -1&gt;&amp;)in Skinning.o
  197. &quot;Eigen::SparseMatrix&lt;double, 0, int&gt; igl::cat&lt;Eigen::SparseMatrix&lt;double, 0, int&gt; &gt;(int, Eigen::SparseMatrix&lt;double, 0, int&gt; const&amp;, Eigen::SparseMatrix&lt;double, 0, int&gt; const&amp;)&quot;, referenced from:
  198. covariance_scatter_matrix(Eigen::Matrix&lt;double, -1, -1, 0, -1, -1&gt; const&amp;, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;, ArapEnergy, Eigen::SparseMatrix&lt;double, 0, int&gt;&amp;)in arap_dof.o
  199. arap_rhs(Eigen::Matrix&lt;double, -1, -1, 0, -1, -1&gt; const&amp;, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;, ArapEnergy, Eigen::SparseMatrix&lt;double, 0, int&gt;&amp;)in arap_dof.o
  200. </code></pre>
  201. <p>This looks like a mess, but luckily we don&#8217;t really need to read it
  202. all. Just copy the first part in quotes</p>
  203. <pre><code>Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; igl::cat&lt;Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; &gt;(int, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;)
  204. </code></pre>
  205. <p>, then append it
  206. to the list of explicit template specializations at the end of
  207. <code>cat.cpp</code> after the word
  208. <strong>template</strong> and followed by a semi-colon.
  209. Like this:</p>
  210. <pre><code>#ifdef IGL_STATIC_LIBRARY
  211. // Explicit template specialization
  212. template Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; igl::cat&lt;Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; &gt;(int, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;, Eigen::Matrix&lt;int, -1, -1, 0, -1, -1&gt; const&amp;);
  213. #endif
  214. </code></pre>
  215. <p>Then you must recompile the IGL static library.</p>
  216. <pre><code>cd $LIBIGL
  217. make
  218. </code></pre>
  219. <p>And try to compile your project again, potentially repeating this
  220. process until no more symbols are undefined.</p>
  221. <p><code>It may be useful to check that you code compiles with
  222. no errors first using the headers-only version to be sure that all errors are from missing template
  223. specializations.</code></p>
  224. <p>If you&#8217;re using make then the following command will
  225. reveal each missing symbol on its own line:</p>
  226. <pre><code>make 2&gt;&amp;1 | grep &quot;referenced from&quot; | sed -e &quot;s/, referenced from.*//&quot;
  227. </code></pre>
  228. <p>Alternatively you can use the <code>autoexplicit.sh</code> function
  229. which (for well organized .h/.cpp pairs in libigl) automatically
  230. create explicit instanciations from your compiler&#8217;s error messages.
  231. Repeat this process until convergence:</p>
  232. <pre><code>cd /to/your/project
  233. make 2&gt;$LIBIGL/make.err
  234. cd $LIBIGL
  235. cat make.err | ./autoexplicit.sh
  236. make clean
  237. make
  238. </code></pre>
  239. <h3 id="benefitsofstaticlibrary">Benefits of static library</h3>
  240. <ul>
  241. <li><strong>Faster compile time</strong>: Because the libigl library
  242. is already compiled, only the new code in ones project must be
  243. compiled and then linked to IGL. This means compile times are
  244. generally faster.</li>
  245. <li><strong>Debug or optimized</strong>: The IGL static
  246. library may be compiled in debug mode or optimized release mode
  247. regardless of whether one&#8217;s project is being optimized or
  248. debugged.</li>
  249. </ul>
  250. <h3 id="drawbacksofstaticlibrary">Drawbacks of static library</h3>
  251. <ul>
  252. <li><strong>Hard to use templates</strong>: Special
  253. care</a> (by the developers of the library) needs to be taken when
  254. exposing templated functions.</li>
  255. </ul>
  256. <h1 id="compressed.h.cpppair">Compressed .h/.cpp pair</h1>
  257. <p>Calling the script:</p>
  258. <pre><code>scripts/compress.sh igl.h igl.cpp
  259. </code></pre>
  260. <p>will create a single header <code>igl.h</code> and a single cpp file <code>igl.cpp</code>.</p>
  261. <p>Alternatively, you can also compress everything into a single header file:</p>
  262. <pre><code>scripts/compress.sh igl.h
  263. </code></pre>
  264. <h3 id="benefitsofcompressed.h.cpppair">Benefits of compressed .h/.cpp pair</h3>
  265. <ul>
  266. <li><strong>Easy incorporation</strong>: This can be easily incorporated
  267. into external projects.</li>
  268. </ul>
  269. <h3 id="drawbacksofcompressed.h.cpppair">Drawbacks of compressed .h/.cpp pair</h3>
  270. <ul>
  271. <li><p><strong>Hard to debug/edit</strong>: The compressed files are
  272. automatically generated. They&#8217;re huge and should not be edited. Thus
  273. debugging and editting are near impossible.</p></li>
  274. <li><p><strong>Compounded dependencies</strong>:
  275. An immediate disadvantage of this
  276. seems to be that even to use a single function (e.g.
  277. <code>cotmatrix</code>), compiling and linking against
  278. <code>igl.cpp</code> will require linking to all of <code>libigl</code>&#8217;s
  279. dependencies (<code>OpenGL</code>, <code>GLUT</code>,
  280. <code>AntTweakBar</code>, <code>BLAS</code>). However, because all
  281. depencies other than Eigen should be encapsulated between
  282. <code>#ifndef</code> guards (e.g. <code>#ifndef IGL_NO_OPENGL</code>, it
  283. is possible to ignore certain functions that have such dependencies.</li>
  284. <li><strong>Long compile:</strong> Compiling <code>igl.cpp</code> takes a long time and isn&#8217;t easily parallelized (no <code>make -j12</code> equivalent).</li>
  285. </ul></p></li>
  286. </ul>
  287. <p>Here&#8217;s a tiny test example using <code>igl.h</code> and <code>igl.cpp</code>. Save the following in <code>test.cpp</code>:</p>
  288. <pre><code>#include &lt;igl.h&gt;
  289. #include &lt;Eigen/Core&gt;
  290. int main(int argc, char * argv[])
  291. {
  292. Eigen::MatrixXd V;
  293. Eigen::MatrixXi F;
  294. return (argc&gt;=2 &amp;amp;&amp;amp; igl::read_triangle_mesh(argv[1],V,F)?0:1);
  295. }
  296. </code></pre>
  297. <p>Then compile <code>igl.cpp</code> with:</p>
  298. <pre><code>g++ -o igl.o -c igl.cpp -I/opt/local/include/eigen3 -DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR
  299. </code></pre>
  300. <p>Notice that we&#8217;re using <code>-DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR</code> to disable any libigl dependencies on OpenGL and AntTweakBar.</p>
  301. <p>Now compile <code>test.cpp</code> with:</p>
  302. <pre><code>g++ -g -I/opt/local/include/eigen3/ -I/usr/local/igl/libigl/ -L/usr/local/igl/libigl/ -ligl -DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR -o test
  303. </code></pre>
  304. <p>Try running it with:</p>
  305. <pre><code>./test path/to/mesh.obj
  306. </code></pre>
  307. <p>The following bash one-liner will find all source files that contain the string <code>OpenGL</code> but don&#8217;t contain and <code>IGL_NO_OPENGL</code> guard:</p>
  308. <pre><code>grep OpenGL `grep -L IGL_NO_OPENGL include/igl/*`
  309. </code></pre>
  310. <h3 id="optional">Optional</h3>
  311. <ul>
  312. <li>OpenGL (disable with <code>IGL_NO_OPENGL</code>)
  313. <ul>
  314. <li>OpenGL &gt;= 4 (enable with <code>IGL_OPENGL_4</code>)</li>
  315. </ul></li>
  316. <li>AntTweakBar (disable with <code>IGL_NO_ANTTWEAKBAR</code>) Last tested 1.16 (see
  317. <code>libigl/external/AntTweakBar</code>)</li>
  318. <li>GLEW Windows and Linux</li>
  319. <li>OpenMP</li>
  320. <li>libpng libiglpng extra only</li>
  321. <li>Mosek libiglmosek extra only</li>
  322. <li>Matlab libiglmatlab extra only</li>
  323. <li>boost libiglboost, libiglcgal extra only</li>
  324. <li>SSE/AVX libiglsvd3x3 extra only</li>
  325. <li>CGAL libiglcgal extra only
  326. <ul>
  327. <li>boost</li>
  328. <li>gmp</li>
  329. <li>mpfr</li>
  330. </ul></li>
  331. <li>CoMiSo libcomiso extra only</li>
  332. </ul>
  333. <h3 id="optionalincludedinexternal">Optional (included in external/)</h3>
  334. <ul>
  335. <li>TetGen libigltetgen extra only</li>
  336. <li>Embree libiglembree extra only</li>
  337. <li>tinyxml2 libiglxml extra only</li>
  338. <li>glfw libviewer extra only</li>
  339. <li>LIM liblim extra only</li>
  340. </ul>
  341. </body>
  342. </html>