index.html 14 KB

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