-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
456 lines (453 loc) · 22 KB
/
index.html
File metadata and controls
456 lines (453 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<!DOCTYPE html>
<html lang="en">
<meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="../images/icon.png">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/code.css">
<link rel="stylesheet" href="../css/tabs.css">
<link rel="stylesheet" href="css/vdb.css">
<head>
<title>MH - OpenVDB</title>
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
</head>
<body>
<header class="pagehead">
<div> <a href="../"></a> </div>
<h1>E-Learning: OpenVDB</h1>
</header>
<div class="main">
<ul class="content-list">
<li>Introduction</li>
<li>Who is this for?</li>
<li>What do we need?</li>
<li>Basic Setup</li>
</ul>
<section class="ch">
<h2 class="chTitle">Introduction</h2>
<p class="chContent">
OpenVDB is a powerful open-source library for efficient manipulation of volumetric data, and CMake is a
versatile build system that can be used to manage and configure a project's dependencies and build
processes. In this documentation, we will explain how to use OpenVDB and CMake together to build and
configure your projects.
</p>
</section>
<section class="ch">
<h2 class="chTitle">Who is this for?</h2>
<div class="ch_double_content">
<div>
<p class="chContent">This is for you when:</p>
<ul class="content-list">
<li>You already have some experience with C++</li>
<li>You know how to use git</li>
<li>You want to start using CMake on Windows</li>
<li>You don't know where to start with openVDB</li>
</ul>
</div>
<div>
<p class="chContent">This isn't for you when:</p>
<ul class="content-list">
<li>You have no experience with programming</li>
<li>You are a master in CMake</li>
<li>You already worked with openVDB</li>
</ul>
</div>
</div>
<div class="ch_double_content">
</div>
</section>
<section class="ch">
<h2 class="chTitle">What do we need to start?</h2>
<p class="chContent">We'll need <a href="https://git-scm.com/">Git</a> to be installed, so we can use it
within the terminal.<br>
We also need to install <a href="https://cmake.org/">CMake</a>.
Please make sure to add CMake to the system path at least for the current user.
If you've done the steps above, let's open a new terminal and create a work folder:
</p>
<div class="pre">
<div class="console">mkdir D:\VDB
cd D:\VDB
</div>
</div>
</section>
<section class="ch">
<h2 class="chTitle">Dependencies</h2>
<p class="chContent">OpenVDB has many dependencies which we need to install first. There are two ways to do
this:
The first one is to painstakingly download every single library by hand.
The second and easier solution, which we use in this guide is with vcpkg.
</p>
<p class="chContent"><a href="https://www.openvdb.org/documentation/doxygen/dependencies.html">Vcpkg</a>
is a package manager for C++ libraries on Windows, Linux and macOS. It helps to manage
dependencies and install libraries on your system. Vcpkg uses a ports system, which is a collection of
scripts that define how to build and install a library. This allows us to easily install and use
multiple versions of a library and helps to ensure that the libraries are built and installed correctly.
Vcpkg also supports package integration with Visual Studio, making it easy to use installed libraries in
our C++ projects.
</p>
<p class="chContent">Note: If you intent to use vcpkg in general / globaly, it is recommend to install it
in a place like C:\vcpkg or C:\dev\vcpkg or similar high level place to quickly locate it. How longer
the path the more likely it is to run into errors.
For the sake of simplicity we install vcpkg locally in our project folder created before.
</p>
<p class="chContent">Let's clone vcpkg from GitHub:</p>
<div class="pre">
<div class="console">git clone https://github.com/microsoft/vcpkg</div>
</div>
<p class="chContent">Once it is done downloading, we need to execute the bootstrap to finalize:</p>
<div class="pre">
<div class="console">.\vcpkg\bootstrap-vcpkg.bat</div>
</div>
<p class="chContent">If the bootstrap completed successfully, we install all libraries we need for now:</p>
<div class="pre">
<div class="console">.\vcpkg\vcpkg install zlib:x64-windows
.\vcpkg\vcpkg install blosc:x64-windows
.\vcpkg\vcpkg install tbb:x64-windows
.\vcpkg\vcpkg install boost-iostreams:x64-windows
.\vcpkg\vcpkg install boost-any:x64-windows
.\vcpkg\vcpkg install boost-algorithm:x64-windows
.\vcpkg\vcpkg install boost-uuid:x64-windows
.\vcpkg\vcpkg install boost-interprocess:x64-windows
</div>
</div>
<p class="chContent">Breakdown: .\vcpkg\vcpkg install [packages]:[target]</p>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>.\vcpkg\vcpkg</td>
<td>the .exe file in the subfolder</td>
</tr>
<tr>
<td>install</td>
<td>command to install</td>
</tr>
<tr>
<td>[packages]:[target]</td>
<td>package name and target architecture</td>
</tr>
</table>
<p class="chContent">To make use of the libraries within a C++ project in Visual Studio<br>
All libraries we just downloaded and will be downloaded in the future will be available:</p>
<div class="pre">
<div class="console">.\vcpkg integrate install</div>
</div>
<p class="chContent">To remove the integration:</p>
<div class="pre">
<div class="console">.\vcpkg integrate remove</div>
</div>
</section>
<section class="ch">
<h2 class="chTitle">Build openVDB with CMake</h2>
<p class="chContent">Build openVDB with CMakeBuild openVDB with CMake</p>
<div class="pre">
<div class="console">git clone https://github.com/AcademySoftwareFoundation/openvdb</div>
</div>
<p class="chContent">Once it is done downloading, we can start with the configuration of CMake. But first
create new folder to build in:</p>
<div class="pre">
<div class="console">mkdir .\openvdb\build
cd .\openvdb\build
</div>
</div>
<p class="chContent">Before we can build the project, we need CMake to generate it's "cache".</p>
<p class="chContent">Generate the project buildsystem:</p>
<div class="pre">
<div class="console">cmake -DCMAKE_TOOLCHAIN_FILE="D:\VDB\vcpkg\scripts\buildsystems\vcpkg.cmake"
DVCPKG_TARGET_TRIPLET=x64-windows -A x64 ..</div>
</div>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>cmake</td>
<td>to execute code in cmake</td>
</tr>
<tr>
<td>-DCMAKE_TOOLCHAIN_FILE="path"</td>
<td>the path to the vcpkg.cmake file to access the libraries</td>
</tr>
<tr>
<td>DVCPKG_TARGET_TRIPLET=x64-windows</td>
<td>the architecture of the libraries vcpkg will use</td>
</tr>
<tr>
<td>-A x64</td>
<td>the target architecture to build to</td>
</tr>
<tr>
<td>..</td>
<td>where is the CMakeLists.txt to build from (.. means one folder up)</td>
</tr>
</table>
<p class="chContent">Build with:</p>
<div class="pre">
<div class="console">cmake --build . --parallel 4 --config Release --target install</div>
</div>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>cmake</td>
<td>to execute code in cmake</td>
</tr>
<tr>
<td>--build .</td>
<td>to tell cmake we want to build followed by a path,<br>
the point means where we are right now (D:/VDB/openvdb/build)</td>
</tr>
<tr>
<td>--parallel 4</td>
<td>How many parallel jobs should run</td>
</tr>
<tr>
<td>--config Release</td>
<td>X</td>
</tr>
<tr>
<td>--target install</td>
<td>X</td>
</tr>
</table>
<p class="chContent">If no error occurred while building openvdb, you should find the library and header
files at "C:\Program Files\OpenVDB".</p>
<p class="chContent">At this point we are ready to use openVDB.</p>
</section>
<section class="ch">
<h2 class="chTitle">First Project</h2>
<p class="chContent">Now we will setup our first project. To show the principle, we will use the “Hello
World” project from openVDB. From here on you have the opportunity to select your personal way to go.
Just select your preferred editor and read on. Of course, you also can use a simple text editor. In any
case we will work within the folder D:\VDB\Cookbook</p>
<!-- Tab Header -->
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'CMD')" id="defaultOpen">CMD</button>
<button class="tablinks" onclick="openTab(event, 'VSCode')">VS Code</button>
<button class="tablinks" onclick="openTab(event, 'VS')">Visual Studio</button>
</div>
<!-- Tab Content -->
<div class="tabcontent" id="CMD">
<h3>Without an IDE</h3>
<p>First create and enter a new folder:</p>
<div class="pre">
<div class="console">mkdir D:\VDB\Cookbook
cd D:\VDB\Cookbook\
</div>
</div>
<p>Then create the CMakeLists.txt file:</p>
<div class="pre">
<div class="console">notepad CMakeLists.txt</div>
</div>
<p>The Windows Notepad should open and prompt you to create the file. If the file already exist, it just opens it. In any case put the following text in the file:</p>
<div class="pre">
<div class="console">cmake_minimum_required(VERSION 3.10)
project("Cookbook")
add_executable(Cookbook "cookbook.cpp")
</div>
</div>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>cmake_minimum_required(VERSION <min>)</td>
<td>min version of cmake</td>
</tr>
<tr>
<td>project(<PROJECT-NAME>)</td>
<td>to name the project "Cookbook"</td>
</tr>
<tr>
<td>add_executable(<name> [source]")</td>
<td>On build crate e executable Cookbook<br>with the source cookbook.cpp</td>
</tr>
</table>
<p>Create a second file named "Cookbook.cpp"</p>
<div class="pre">
<div class="console">notepad Cookbook.cpp</div>
</div>
<p>And add the simple "Hello World" code to the file:</p>
<div class="pre">
<div class="console">#include <iostream>
int main() {
std::cout << "Hello World!";
std::cin.get();
return 0;
}
</div>
</div>
<p>Back in the console, we use CMake to generate it's build system:</p>
<div class="pre">
<div class="console">cmake -S . -B ./build</div>
</div>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>cmake</td>
<td>use a cmake command</td>
</tr>
<tr>
<td>-S [path]</td>
<td>path to source files<br>folder with CMakeLists.txt</td>
</tr>
<tr>
<td>-B [path]</td>
<td>path where to build</td>
</tr>
</table>
<p>To build:</p>
<div class="pre">
<div class="console">cmake --build ./build/</div>
</div>
<p>CMake will build to "<b>./build/Debug/</b>".</p>
</div>
<!-- Tab Content -->
<div class="tabcontent" id="VSCode">
<h3>Visual Studio Code</h3>
<p>First, create a new folder and open it in VS-Code:</p>
<div class="pre">
<div class="console">mkdir D:\VDB\Cookbook</div>
</div>
<p>Let's create a file and name it "CMakeLists.txt". at this point the editor should prompt you to
install the <a
href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools">CMake Tools</a>
for VS-Code. Install the extension either throw the prompt or by searching it within the extensions
tab of the editor. I also recomend you to install this <a
href="https://marketplace.visualstudio.com/items?itemName=twxs.cmake">CMake extension</a> for
syntax highliginting.
</p>
<img src="images/VSCode_1.png" alt="VS Code Extension for CMake">
<p>The extensions installed, the editor should prompt you to configure your project. Press Yes and
select your preferred x64 compiler. For this guide I'll use the <i>Visual Studio Community 2022
Release - amd64</i> compiler.
CMake will start generating the building system. If no prompt apears, you can start to process via
the searchbar of VS-Code ">cmake:
configure" or within the searchbar click: Run task --> cmake --> cmake: configure. CMake will create
by default it's build system in
".\build".<br>
</p>
<p>Write within the before created txt file:</p>
<div class="pre">
<div class="console">cmake_minimum_required(VERSION 3.10)
project("Cookbook")
add_executable(Cookbook "cookbook.cpp")
</div>
</div>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>cmake_minimum_required(VERSION <min>)</td>
<td>min version of cmake</td>
</tr>
<tr>
<td>project(<PROJECT-NAME>)</td>
<td>to name the project "Cookbook"</td>
</tr>
<tr>
<td>add_executable(<name> [source]")</td>
<td>On build crate e executable Cookbook<br>with the source cookbook.cpp</td>
</tr>
</table>
<p>Upon save, CMake should automaticaly reconfigure the project. Else, try the alternative steps I
explained above.</p>
<p>To test our setup we create a simple C++ file. Create a new file named "cookbook.cpp" and add
following code to it:</p>
<div class="pre">
<div class="console">#include <iostream>
int main() {
std::cout << "Hello World!";
std::cin.get();
return 0;
}
</div>
</div>
<p>If we done all the steps above, it should look similar like that:</p>
<img src="images/VSCode_2.png" alt="">
<p>Now we can finaly build our test. With <i>Ctrl+Shift+B --> CMake: build</i> or click <i>Terminal -->
Run Build Task --> CMake: build</i> we build our cmake project to
"<b>.\build\Debug\Cookbook.exe</b>".</p>
</div>
<!-- Tab Content -->
<div class="tabcontent" id="VS">
<h3>Visual Studio Community</h3>
<p>Please make sure you have the <b>C++ Tools for Windows</b> installed.</p>
<img src="images/VS_1.png" alt="">
<p>Then, open Visual Studio and create a new project of typ "CMake Project".</p>
<img src="images/VS_2.png" alt="">
<table>
<tr>
<td>Project name</td>
<td>Cookbook</td>
</tr>
<tr>
<td>Location</td>
<td>D:\VDB\</td>
</tr>
</table>
<p>Toggle the <i>Place solution and project in the same directory</i> option and click create. Visual
Studio will greet you with a overview page once all files are created.<br>
Let's look through what VS already created for us:
</p>
<p>Relevant entries within the CMakeLists.txt</p>
<table>
<tr>
<th>Syntax</th>
<th>Explanation</th>
</tr>
<tr>
<td>cmake_minimum_required(VERSION <min>)</td>
<td>min version of cmake</td>
</tr>
<tr>
<td>project(<PROJECT-NAME>)</td>
<td>to name the project "Cookbook"</td>
</tr>
<tr>
<td>add_executable(<name> [source1] [source2]")</td>
<td>On build crate a executable Cookbook<br>with the source "Cookbook.cpp" & "Cookbook.h"</td>
</tr>
</table>
<p>Within the Cookbook.cpp we already got a "Hello World" example but we'll add a line to it. At the end, it should look like this:</p>
<div class="pre">
<div class="console">#include "Cookbook.h"
using namespace std;
int main()
{
cout << "Hello CMake." << endl;
std::cin.get();
return 0;
}
</div>
</div>
<p>With <i>Ctrl+Shift+B</i> we build the CMake project. <b>Note:</b> Visual Studio does not use the default folder
structure of CMake, the build system and the executable will be generatet at "<b>.\out\build\x64-debug\</b>".</p>
</div>
</section>
<section class="ch">
<h2 class="chTitle">OpenVDB Hello World</h2>
<p class="chContent">You can now use the cookbook.cpp file to go through the Cookbooks of openVDB.
Be sure to switch your CMake config to release, otherwise you'll run into errors from the tbb library.
Also include the <openvdb/openvdb.h> like this:</p>
<div class="pre">
<div class="console">#include <C:\Program Files\OpenVDB\include\openvdb\openvdb.h>
</div>
</div>
</section>
</div>
<script src="../js/tabs.js"></script>
<script>document.getElementById("defaultOpen").click();</script>
</body>
</html>