Skip to content

Commit

Permalink
Added example how to visualize CLI file
Browse files Browse the repository at this point in the history
Also added the visualization to VDB to CLI example
  • Loading branch information
LinKayser committed Jul 31, 2024
1 parent 6ec3ec6 commit f93806e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
56 changes: 56 additions & 0 deletions Examples/Ex_ShowCLIFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// SPDX-License-Identifier: CC0-1.0
//
// This example code file is released to the public under Creative Commons CC0.
// See https://creativecommons.org/publicdomain/zero/1.0/legalcode
//
// To the extent possible under law, LEAP 71 has waived all copyright and
// related or neighboring rights to this PicoGK example code file.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using PicoGK;

namespace PicoGKExamples
{
class ShowCLI
{
public ShowCLI(string strCLIFile)
{
m_strCLIFile = strCLIFile;
}

public void Task()
{
// Load all CLI slices
CliIo.Result oResult = CliIo.oSlicesFromCliFile(m_strCLIFile);

// Add all slices to the viewer
oResult.oSlices.AddToViewer(Library.oViewer());

// Write out all slice as SVGs
// Create a subdirectory, to not spam the CLI file folder

string strDir = Path.GetDirectoryName(m_strCLIFile) ?? Library.strLogFolder;
string strName = Path.GetFileNameWithoutExtension(m_strCLIFile);
string strSubDir = Path.Combine(strDir, strName + "_SVGs");
Directory.CreateDirectory(strSubDir);

// Iterate throug all slices and save as SVGs
for (int n=0; n<oResult.oSlices.nCount(); n++)
{
PolySlice oSlice = oResult.oSlices.oSliceAt(n);
oSlice.SaveToSvgFile(Path.Combine(strSubDir, strName + $"_{n:00000}.svg"), true);
}
}

string m_strCLIFile;
}
}
15 changes: 13 additions & 2 deletions Examples/Ex_VDBtoCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public static void ConvertVdbToCli( string strVdbFile,

OpenVdbFile oFile = new OpenVdbFile(strVdbFile);

bool bFound = false;

for (int n=0; n<oFile.nFieldCount(); n++)
{
Voxels vox;
Expand All @@ -76,10 +78,19 @@ public static void ConvertVdbToCli( string strVdbFile,

// Save to CLI file
vox.SaveToCliFile(strCLIFile, fLayerHeight);
return;
bFound = true;
break;
}

throw new Exception($"No voxels found in VDB file {strVdbFile}");
if (!bFound)
throw new Exception($"No voxels found in VDB file {strVdbFile}");
}

// Lastly, let's visualize the CLI in the viewer, and output it to .SVG slices
// we can use the ShowCLIFile example for that
{
ShowCLI oShow = new(strCLIFile);
Library.Go(1, oShow.Task);
}
}
}
Expand Down

0 comments on commit f93806e

Please sign in to comment.