index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 ../optional
  33. make
  34. </code></pre>
  35. <h4 id="warnings">Warnings</h4>
  36. <p>You should expect to see a few linker warnings of the form:</p>
  37. <pre><code>/opt/local/bin/ranlib: file: libigl.a(*.cpp.o) has no symbols
  38. </code></pre>
  39. <p>These are (admittedly unpopular) functions that have never been used by us
  40. statically so we haven&#8217;t explicit instantiations (yet).</p>
  41. <h4 id="external">External</h4>
  42. <p>Finally there are a number of external libraries that we include in
  43. <code>./external/</code> because they are either difficult to obtain or they have been
  44. patched for easier use with libigl. Please see the respective readmes in those
  45. directories or build the tutorial using cmake, which will recursively build all
  46. dependencies.</p>
  47. <h5 id="installingembree2.0">Installing Embree 2.0</h5>
  48. <p>To build the embree library and executables on Mac OS X issue:</p>
  49. <pre><code>cd external/embree
  50. mkdir build
  51. cd build
  52. cmake ..
  53. # Or using a different compiler
  54. #cmake .. -DCMAKE_C_COMPILER=/opt/local/bin/gcc -DCMAKE_CXX_COMPILER=/opt/local/bin/g++
  55. make
  56. # Could also install embree to your root, but libigl examples don't expect
  57. # this
  58. #sudo make install
  59. </code></pre>
  60. <h2 id="extras">Extras</h2>
  61. <h3 id="bbw">bbw</h3>
  62. <p>This library extra contains functions for computing Bounded Biharmonic Weights, can
  63. be used with and without the <a href="#mosek">mosek</a> extra via the <code>IGL_NO_MOSEK</code>
  64. macro.</p>
  65. <h3 id="boolean">boolean</h3>
  66. <p>This library extra contains functions for computing mesh-mesh booleans,
  67. depending on CGAL and optionally Cork.</p>
  68. <h3 id="cgal">cgal</h3>
  69. <p>This library extra utilizes CGAL&#8217;s efficient and exact intersection and
  70. proximity queries.</p>
  71. <h3 id="embree">embree</h3>
  72. <p>This library extra utilizes embree&#8217;s efficient ray tracing queries.</p>
  73. <h3 id="matlab">matlab</h3>
  74. <p>This library extra provides support for reading and writing <code>.mat</code> workspace
  75. files, interfacing with Matlab at run time and compiling mex functions.</p>
  76. <h3 id="mosek">mosek</h3>
  77. <p>This library extra utilizes mosek&#8217;s efficient interior-point solver for
  78. quadratic programs.</p>
  79. <h3 id="png">png</h3>
  80. <p>This library extra uses <code>libpng</code> and <code>YImage</code> to read and write <code>.png</code> files.</p>
  81. <h3 id="tetgen">tetgen</h3>
  82. <p>This library extra provides a simplified wrapper to the tetgen 3d tetrahedral
  83. meshing library.</p>
  84. <h3 id="triangle">Triangle</h3>
  85. <p>This library extra provides a simplified wrapper to the triangle 2d triangle
  86. meshing library.</p>
  87. <h3 id="viewer">viewer</h3>
  88. <p>This library extra utilizes glfw and glew to open an opengl context and launch
  89. a simple mesh viewer.</p>
  90. <h3 id="xml">xml</h3>
  91. <p>This library extra utilizes tinyxml2 to read and write serialized classes
  92. containing Eigen matrices and other standard simple data-structures.</p>
  93. <h2 id="development">Development</h2>
  94. <p>Further documentation for developers is listed in
  95. <a href="../style_guidelines.html">style_guidelines.html</a>.</p>
  96. <h2 id="license">License</h2>
  97. <p>See <code>LICENSE.txt</code></p>
  98. <h2 id="zipping">Zipping</h2>
  99. <p>Zip this directory without .git litter and binaries using:</p>
  100. <pre><code>git archive -prefix=libigl/ -o libigl.zip master
  101. </code></pre>
  102. <h2 id="explicitspecializationoftemplatedfunctions">Explicit specialization of templated functions</h2>
  103. <p>Special care must be taken by the developers of each function and
  104. class in the libigl library that uses C++ templates. If this function
  105. is intended to be compiled into the statically linked libigl library
  106. then function is only compiled for each <i>explicitly</i> specialized
  107. declaration. These should be added at the bottom of the corresponding
  108. .cpp file surrounded by a</p>
  109. <pre><code>#ifdef IGL_STATIC_LIBRARY
  110. </code></pre>
  111. <p>Of course, a developer may not know ahead of time which
  112. specializations should be explicitly included in the igl static lib.
  113. One way to find out is to add one explicit specialization for each
  114. call in one&#8217;s own project. This only ever needs to be done once for
  115. each template.</p>
  116. <p>The process is somewhat mechanical using a linker with reasonable error
  117. output.</p>
  118. <p>Supposed for example we have compiled the igl static lib, including the
  119. cat.h and cat.cpp functions, without any explicit instanciation. Say
  120. using the makefile in the <code>libigl</code> directory:</p>
  121. <pre><code>cd $LIBIGL
  122. make
  123. </code></pre>
  124. <p>Now if we try to compile a project and link against it we may get
  125. an error like:</p>
  126. <pre><code>Undefined symbols for architecture x86_64:
  127. &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:
  128. 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
  129. &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:
  130. 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
  131. 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
  132. </code></pre>
  133. <p>This looks like a mess, but luckily we don&#8217;t really need to read it
  134. all. Just copy the first part in quotes</p>
  135. <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;)
  136. </code></pre>
  137. <p>, then append it
  138. to the list of explicit template specializations at the end of
  139. <code>cat.cpp</code> after the word
  140. <strong>template</strong> and followed by a semi-colon.
  141. Like this:</p>
  142. <pre><code>#ifdef IGL_STATIC_LIBRARY
  143. // Explicit template specialization
  144. 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;);
  145. #endif
  146. </code></pre>
  147. <p>Then you must recompile the IGL static library.</p>
  148. <pre><code>cd $LIBIGL
  149. make
  150. </code></pre>
  151. <p>And try to compile your project again, potentially repeating this
  152. process until no more symbols are undefined.</p>
  153. <p><code>It may be useful to check that you code compiles with
  154. no errors first using the headers-only version to be sure that all errors are from missing template
  155. specializations.</code></p>
  156. <p>If you&#8217;re using make then the following command will
  157. reveal each missing symbol on its own line:</p>
  158. <pre><code>make 2&gt;&amp;1 | grep &quot;referenced from&quot; | sed -e &quot;s/, referenced from.*//&quot;
  159. </code></pre>
  160. <p>Alternatively you can use the <code>autoexplicit.sh</code> function
  161. which (for well organized .h/.cpp pairs in libigl) automatically
  162. create explicit instanciations from your compiler&#8217;s error messages.
  163. Repeat this process until convergence:</p>
  164. <pre><code>cd /to/your/project
  165. make 2&gt;$LIBIGL/make.err
  166. cd $LIBIGL
  167. cat make.err | ./autoexplicit.sh
  168. make clean
  169. make
  170. </code></pre>
  171. <h3 id="benefitsofstaticlibrary">Benefits of static library</h3>
  172. <ul>
  173. <li><strong>Faster compile time</strong>: Because the libigl library
  174. is already compiled, only the new code in ones project must be
  175. compiled and then linked to IGL. This means compile times are
  176. generally faster.</li>
  177. <li><strong>Debug or optimized</strong>: The IGL static
  178. library may be compiled in debug mode or optimized release mode
  179. regardless of whether one&#8217;s project is being optimized or
  180. debugged.</li>
  181. </ul>
  182. <h3 id="drawbacksofstaticlibrary">Drawbacks of static library</h3>
  183. <ul>
  184. <li><strong>Hard to use templates</strong>: Special
  185. care</a> (by the developers of the library) needs to be taken when
  186. exposing templated functions.</li>
  187. </ul>
  188. <h1 id="compressed.h.cpppair">Compressed .h/.cpp pair</h1>
  189. <p>Calling the script:</p>
  190. <pre><code>scripts/compress.sh igl.h igl.cpp
  191. </code></pre>
  192. <p>will create a single header <code>igl.h</code> and a single cpp file <code>igl.cpp</code>.</p>
  193. <p>Alternatively, you can also compress everything into a single header file:</p>
  194. <pre><code>scripts/compress.sh igl.h
  195. </code></pre>
  196. <h3 id="benefitsofcompressed.h.cpppair">Benefits of compressed .h/.cpp pair</h3>
  197. <ul>
  198. <li><strong>Easy incorporation</strong>: This can be easily incorporated
  199. into external projects.</li>
  200. </ul>
  201. <h3 id="drawbacksofcompressed.h.cpppair">Drawbacks of compressed .h/.cpp pair</h3>
  202. <ul>
  203. <li><p><strong>Hard to debug/edit</strong>: The compressed files are
  204. automatically generated. They&#8217;re huge and should not be edited. Thus
  205. debugging and editting are near impossible.</p></li>
  206. <li><p><strong>Compounded dependencies</strong>:
  207. An immediate disadvantage of this
  208. seems to be that even to use a single function (e.g.
  209. <code>cotmatrix</code>), compiling and linking against
  210. <code>igl.cpp</code> will require linking to all of <code>libigl</code>&#8217;s
  211. dependencies (<code>OpenGL</code>, <code>GLUT</code>,
  212. <code>AntTweakBar</code>, <code>BLAS</code>). However, because all
  213. depencies other than Eigen should be encapsulated between
  214. <code>#ifndef</code> guards (e.g. <code>#ifndef IGL_NO_OPENGL</code>, it
  215. is possible to ignore certain functions that have such dependencies.</p></li>
  216. <li><p><strong>Long compile</strong>:
  217. Compiling <code>igl.cpp</code> takes a long time and isn&#8217;t easily parallelized (no <code>make
  218. -j12</code> equivalent).</p></li>
  219. </ul>
  220. <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>
  221. <pre><code>#include &lt;igl.h&gt;
  222. #include &lt;Eigen/Core&gt;
  223. int main(int argc, char * argv[])
  224. {
  225. Eigen::MatrixXd V;
  226. Eigen::MatrixXi F;
  227. return (argc&gt;=2 &amp;&amp; igl::read_triangle_mesh(argv[1],V,F)?0:1);
  228. }
  229. </code></pre>
  230. <p>Then compile <code>igl.cpp</code> with:</p>
  231. <pre><code>g++ -o igl.o -c igl.cpp -I/opt/local/include/eigen3 -DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR
  232. </code></pre>
  233. <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>
  234. <p>Now compile <code>test.cpp</code> with:</p>
  235. <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
  236. </code></pre>
  237. <p>Try running it with:</p>
  238. <pre><code>./test path/to/mesh.obj
  239. </code></pre>
  240. <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>
  241. <pre><code>grep OpenGL `grep -L IGL_NO_OPENGL include/igl/*`
  242. </code></pre>
  243. <h3 id="optional">Optional</h3>
  244. <ul>
  245. <li>OpenGL (disable with <code>IGL_NO_OPENGL</code>)
  246. <ul>
  247. <li>OpenGL &gt;= 4 (enable with <code>IGL_OPENGL_4</code>)</li>
  248. </ul></li>
  249. <li>AntTweakBar (disable with <code>IGL_NO_ANTTWEAKBAR</code>) Last tested 1.16 (see
  250. <code>libigl/external/AntTweakBar</code>)</li>
  251. <li>GLEW Windows and Linux</li>
  252. <li>OpenMP</li>
  253. <li>libpng libiglpng extra only</li>
  254. <li>Mosek libiglmosek extra only</li>
  255. <li>Matlab libiglmatlab extra only</li>
  256. <li>boost libiglboost, libiglcgal extra only</li>
  257. <li>SSE/AVX libiglsvd3x3 extra only</li>
  258. <li>CGAL libiglcgal extra only
  259. <ul>
  260. <li>boost</li>
  261. <li>gmp</li>
  262. <li>mpfr</li>
  263. </ul></li>
  264. <li>CoMiSo libcomiso extra only</li>
  265. </ul>
  266. <h3 id="optionalincludedinexternal">Optional (included in external/)</h3>
  267. <ul>
  268. <li>TetGen libigltetgen extra only</li>
  269. <li>Embree libiglembree extra only</li>
  270. <li>tinyxml2 libiglxml extra only</li>
  271. <li>glfw libviewer extra only</li>
  272. <li>LIM liblim extra only</li>
  273. </ul>
  274. </body>
  275. </html>