index.html 16 KB

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