Skip to content

Commit d04279d

Browse files
authored
Added check for channel count during compression (#101)
1 parent 01ace6e commit d04279d

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

.github/workflows/build-custom.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ jobs:
104104
merge-packages:
105105
runs-on: macos-14
106106
needs: [select-houdini-build, build-plugin]
107+
if: ${{ fromJson(needs.select-houdini-build.outputs.build-matrix-json).include.length > 1 }}
107108
name: Merge packages
108109

109110
steps:

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ jobs:
124124
merge-packages:
125125
runs-on: macos-14
126126
needs: [select-houdini-build, build-plugin]
127+
# Only run merge if there is more than one build in matrix
128+
if: ${{ fromJson(needs.select-houdini-build.outputs.build-matrix-json).include[1] != null }}
127129
name: Merge packages ${{ github.event_name == 'pull_request' && '(PR)' || ' (Push)' }}
128130

129131
steps:

src/ROP/ROP_ZibraVDBCompressor.cpp

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,22 +375,42 @@ namespace Zibra::ZibraVDBCompressor
375375
}
376376

377377
m_OrderedChannelNames.clear();
378+
m_CurrentChannelCount = 0;
378379
m_OrderedChannelNames.reserve(8);
379380
const GEO_Primitive* prim;
380381
GA_FOR_ALL_PRIMITIVES(gdp, prim)
381382
{
382383
if (prim->getTypeId() == GEO_PRIMVDB)
383384
{
384-
auto vdbPrim = dynamic_cast<const GEO_PrimVDB*>(prim);
385-
auto gridName = vdbPrim->getGridName();
386-
if (m_OrderedChannelNames.size() >= 8)
385+
const GEO_PrimVDB* vdbPrim = dynamic_cast<const GEO_PrimVDB*>(prim);
386+
const char* gridName = vdbPrim->getGridName();
387+
const openvdb::GridBase& baseGrid = vdbPrim->getConstGrid();
388+
389+
int underlyingChannels = 0;
390+
391+
if (baseGrid.baseTree().isType<openvdb::Vec3STree>())
392+
{
393+
underlyingChannels = 3;
394+
}
395+
else if (baseGrid.baseTree().isType<openvdb::FloatTree>())
396+
{
397+
underlyingChannels = 1;
398+
}
399+
else
400+
{
401+
std::string m = "Grid "s + gridName + " has unsupported grid type.";
402+
addError(ROP_MESSAGE, m.c_str());
403+
return ROP_ABORT_RENDER;
404+
}
405+
406+
if (m_CurrentChannelCount + underlyingChannels > CE::MAX_CHANNEL_COUNT)
387407
{
388-
std::string m = "Input has quantity of VDB primitives greater than 8 supported. Skipping '"s + gridName + "'.";
408+
std::string m = "Can not compress more than " + std::to_string(CE::MAX_CHANNEL_COUNT) + " channels.";
389409
addError(ROP_MESSAGE, m.c_str());
390-
break;
410+
return ROP_ABORT_RENDER;
391411
}
392412

393-
const auto voxelSize = openvdb::Vec3f(vdbPrim->getGrid().voxelSize());
413+
const auto voxelSize = openvdb::Vec3f(baseGrid.voxelSize());
394414
const auto hasUniformVoxelSize = (std::abs(voxelSize[0] - voxelSize[1]) < std::numeric_limits<float>::epsilon()) &&
395415
(std::abs(voxelSize[1] - voxelSize[2]) < std::numeric_limits<float>::epsilon());
396416
if (!hasUniformVoxelSize)
@@ -400,6 +420,7 @@ namespace Zibra::ZibraVDBCompressor
400420
return ROP_ABORT_RENDER;
401421
}
402422
m_OrderedChannelNames.emplace_back(gridName);
423+
m_CurrentChannelCount += underlyingChannels;
403424
}
404425
}
405426

@@ -456,22 +477,35 @@ namespace Zibra::ZibraVDBCompressor
456477
{
457478
if (prim->getTypeId() == GEO_PRIMVDB)
458479
{
459-
auto vdbPrim = dynamic_cast<const GEO_PrimVDB*>(prim);
480+
const GEO_PrimVDB* vdbPrim = dynamic_cast<const GEO_PrimVDB*>(prim);
460481
const char* gridName = vdbPrim->getGridName();
461-
if (channelNamesUniqueStorage.find(gridName) != channelNamesUniqueStorage.cend())
482+
const openvdb::GridBase::ConstPtr baseGrid = vdbPrim->getConstGridPtr();
483+
484+
int underlyingChannels = 0;
485+
486+
if (baseGrid->baseTree().isType<openvdb::Vec3STree>())
462487
{
463-
std::string m = "ZibraVDB uses grid name as unique key. Node input contains duplicate of '"s + gridName + "' VDB prim.";
488+
underlyingChannels = 3;
489+
}
490+
else if (baseGrid->baseTree().isType<openvdb::FloatTree>())
491+
{
492+
underlyingChannels = 1;
493+
}
494+
else
495+
{
496+
std::string m = "Grid "s + gridName + " has unsupported grid type.";
464497
addError(ROP_MESSAGE, m.c_str());
465498
return ROP_ABORT_RENDER;
466499
}
467-
if (vdbPrim->getStorageType() != UT_VDB_FLOAT && vdbPrim->getStorageType() != UT_VDB_VEC3F)
500+
501+
if (channelNamesUniqueStorage.find(gridName) != channelNamesUniqueStorage.cend())
468502
{
469-
std::string m = "Unsupported value type for '"s + gridName + "' prim. Only float grids supported.";
503+
std::string m = "ZibraVDB uses grid name as unique key. Node input contains duplicate of '"s + gridName + "' VDB prim.";
470504
addError(ROP_MESSAGE, m.c_str());
471505
return ROP_ABORT_RENDER;
472506
}
473507

474-
const auto gridDimensions = vdbPrim->getGrid().evalActiveVoxelBoundingBox().dim();
508+
const auto gridDimensions = baseGrid->evalActiveVoxelBoundingBox().dim();
475509
constexpr size_t MAX_GRID_DIMENSION = 4096;
476510
if (gridDimensions.x() > MAX_GRID_DIMENSION || gridDimensions.y() > MAX_GRID_DIMENSION ||
477511
gridDimensions.z() > MAX_GRID_DIMENSION)
@@ -480,9 +514,23 @@ namespace Zibra::ZibraVDBCompressor
480514
return ROP_ABORT_RENDER;
481515
}
482516

483-
volumes.emplace_back(vdbPrim->getGridPtr());
517+
volumes.emplace_back(std::move(baseGrid));
484518
orderedChannelNames.push_back(gridName);
485519
channelNamesUniqueStorage.insert(gridName);
520+
521+
auto iter = std::find(m_OrderedChannelNames.begin(), m_OrderedChannelNames.end(), gridName);
522+
if (iter != m_OrderedChannelNames.end())
523+
{
524+
if (m_CurrentChannelCount + underlyingChannels > CE::MAX_CHANNEL_COUNT)
525+
{
526+
std::string m = "Can not compress more than " + std::to_string(CE::MAX_CHANNEL_COUNT) + " channels.";
527+
addError(ROP_MESSAGE, m.c_str());
528+
return ROP_ABORT_RENDER;
529+
}
530+
531+
m_OrderedChannelNames.emplace_back(gridName);
532+
m_CurrentChannelCount += underlyingChannels;
533+
}
486534
}
487535
}
488536

src/ROP/ROP_ZibraVDBCompressor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace Zibra::ZibraVDBCompressor
8686
SOP_Node* m_InputSOP = nullptr;
8787

8888
std::vector<std::string> m_OrderedChannelNames{};
89+
int m_CurrentChannelCount = 0;
8990

9091
ContextType m_ContextType;
9192

0 commit comments

Comments
 (0)