Skip to content

Commit f93806e

Browse files
committed
Added example how to visualize CLI file
Also added the visualization to VDB to CLI example
1 parent 6ec3ec6 commit f93806e

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

Examples/Ex_ShowCLIFile.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// SPDX-License-Identifier: CC0-1.0
3+
//
4+
// This example code file is released to the public under Creative Commons CC0.
5+
// See https://creativecommons.org/publicdomain/zero/1.0/legalcode
6+
//
7+
// To the extent possible under law, LEAP 71 has waived all copyright and
8+
// related or neighboring rights to this PicoGK example code file.
9+
//
10+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
11+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16+
// THE SOFTWARE.
17+
//
18+
19+
using PicoGK;
20+
21+
namespace PicoGKExamples
22+
{
23+
class ShowCLI
24+
{
25+
public ShowCLI(string strCLIFile)
26+
{
27+
m_strCLIFile = strCLIFile;
28+
}
29+
30+
public void Task()
31+
{
32+
// Load all CLI slices
33+
CliIo.Result oResult = CliIo.oSlicesFromCliFile(m_strCLIFile);
34+
35+
// Add all slices to the viewer
36+
oResult.oSlices.AddToViewer(Library.oViewer());
37+
38+
// Write out all slice as SVGs
39+
// Create a subdirectory, to not spam the CLI file folder
40+
41+
string strDir = Path.GetDirectoryName(m_strCLIFile) ?? Library.strLogFolder;
42+
string strName = Path.GetFileNameWithoutExtension(m_strCLIFile);
43+
string strSubDir = Path.Combine(strDir, strName + "_SVGs");
44+
Directory.CreateDirectory(strSubDir);
45+
46+
// Iterate throug all slices and save as SVGs
47+
for (int n=0; n<oResult.oSlices.nCount(); n++)
48+
{
49+
PolySlice oSlice = oResult.oSlices.oSliceAt(n);
50+
oSlice.SaveToSvgFile(Path.Combine(strSubDir, strName + $"_{n:00000}.svg"), true);
51+
}
52+
}
53+
54+
string m_strCLIFile;
55+
}
56+
}

Examples/Ex_VDBtoCLI.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public static void ConvertVdbToCli( string strVdbFile,
6060

6161
OpenVdbFile oFile = new OpenVdbFile(strVdbFile);
6262

63+
bool bFound = false;
64+
6365
for (int n=0; n<oFile.nFieldCount(); n++)
6466
{
6567
Voxels vox;
@@ -76,10 +78,19 @@ public static void ConvertVdbToCli( string strVdbFile,
7678

7779
// Save to CLI file
7880
vox.SaveToCliFile(strCLIFile, fLayerHeight);
79-
return;
81+
bFound = true;
82+
break;
8083
}
8184

82-
throw new Exception($"No voxels found in VDB file {strVdbFile}");
85+
if (!bFound)
86+
throw new Exception($"No voxels found in VDB file {strVdbFile}");
87+
}
88+
89+
// Lastly, let's visualize the CLI in the viewer, and output it to .SVG slices
90+
// we can use the ShowCLIFile example for that
91+
{
92+
ShowCLI oShow = new(strCLIFile);
93+
Library.Go(1, oShow.Task);
8394
}
8495
}
8596
}

0 commit comments

Comments
 (0)