Skip to content

Commit 7ebe25f

Browse files
authored
Merge pull request #2059 from sideeffects/send_upstream_houdini21sync
Synchronize with Houdini 21.
2 parents d008d49 + 6d238d4 commit 7ebe25f

39 files changed

+360
-47
lines changed

openvdb_houdini/openvdb_houdini/GEO_VDBTranslator.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include <UT/UT_ErrorManager.h>
1515
#include <UT/UT_IOTable.h>
1616
#include <UT/UT_IStream.h>
17+
#include <UT/UT_OFStream.h>
1718
#include <UT/UT_Version.h>
1819

1920
#include <FS/FS_IStreamDevice.h>
21+
#include <FS/FS_WriterStream.h>
2022
#include <GA/GA_Stat.h>
2123
#include <GU/GU_Detail.h>
2224
#include <SOP/SOP_Node.h>
@@ -306,6 +308,16 @@ GEO_VDBTranslator::fileSave(const GEO_Detail *geogdp, std::ostream &os)
306308
GA_Detail::IOStatus
307309
GEO_VDBTranslator::fileSaveToFile(const GEO_Detail *geogdp, const char *fname)
308310
{
311+
// When HOUDINI_VDB_FORCE_STREAM_SAVE is enabled, force saving via a stream
312+
// that will NOT save grid offsets, disabling the ability to partial
313+
// reading on the saved files. This is for reported performance issues with
314+
// Qumulo file systems, that apparently Isilon file systems do not suffer
315+
// from.
316+
if (UT_EnvControl::getInt(ENV_HOUDINI_VDB_FORCE_STREAM_SAVE)) {
317+
FS_WriterStream os(fname);
318+
return fileSaveVDB<openvdb::io::Stream, std::ostream &>(geogdp, *os.getStream());
319+
}
320+
309321
// Saving via io::File will save grid offsets that allow for partial
310322
// reading.
311323
return fileSaveVDB<openvdb::io::File, const char *>(geogdp, fname);

openvdb_houdini/openvdb_houdini/GeometryUtil.cc

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <GA/GA_Types.h>
1717
#include <GU/GU_ConvertParms.h>
1818
#include <GU/GU_PrimPoly.h>
19-
#include <OBJ/OBJ_Camera.h>
2019
#include <UT/UT_BoundingBox.h>
2120
#include <UT/UT_String.h>
2221
#include <UT/UT_UniquePtr.h>
@@ -196,7 +195,72 @@ drawFrustum(
196195

197196
////////////////////////////////////////
198197

198+
#if SYS_VERSION_MAJOR_INT >= 21
199+
openvdb::math::Transform::Ptr
200+
frustumTransformFromCamera(
201+
const OBJ_CameraParms& camparms,
202+
const UT_Matrix4D &cameratosop,
203+
float offset, float nearPlaneDist, float farPlaneDist,
204+
float voxelDepthSize, int voxelCountX)
205+
{
206+
// Eval camera parms
207+
const fpreal camAspect = camparms.aspect;
208+
const fpreal camFocal = camparms.focal;
209+
const fpreal camAperture = camparms.aperture;
210+
const fpreal camXRes = camparms.xres;
211+
const fpreal camYRes = camparms.yres;
212+
213+
nearPlaneDist += offset;
214+
farPlaneDist += offset;
215+
216+
const fpreal depth = farPlaneDist - nearPlaneDist;
217+
const fpreal zoom = camAperture / camFocal;
218+
const fpreal aspectRatio = camYRes / (camXRes * camAspect);
219+
220+
openvdb::Vec2d nearPlaneSize;
221+
nearPlaneSize.x() = nearPlaneDist * zoom;
222+
nearPlaneSize.y() = nearPlaneSize.x() * aspectRatio;
223+
224+
openvdb::Vec2d farPlaneSize;
225+
farPlaneSize.x() = farPlaneDist * zoom;
226+
farPlaneSize.y() = farPlaneSize.x() * aspectRatio;
227+
228+
// Create the linear map
229+
openvdb::math::Mat4d xform(openvdb::math::Mat4d::identity());
230+
xform.setToTranslation(openvdb::Vec3d(0, 0, -(nearPlaneDist - offset)));
231+
232+
/// this will be used to scale the frust to the correct size, and orient the
233+
/// into the frustum as the negative z-direction
234+
xform.preScale(openvdb::Vec3d(nearPlaneSize.x(), nearPlaneSize.x(), -nearPlaneSize.x()));
235+
236+
openvdb::math::Mat4d camxform(openvdb::math::Mat4d::identity());
237+
for (unsigned i = 0; i < 4; ++i) {
238+
for (unsigned j = 0; j < 4; ++j) {
239+
camxform(i,j) = cameratosop(i,j);
240+
}
241+
}
242+
243+
openvdb::math::MapBase::Ptr linearMap(openvdb::math::simplify(
244+
openvdb::math::AffineMap(xform * camxform).getAffineMap()));
199245

246+
// Create the non linear map
247+
const int voxelCountY = int(std::ceil(float(voxelCountX) * aspectRatio));
248+
const int voxelCountZ = int(std::ceil(depth / voxelDepthSize));
249+
250+
// the frustum will be the image of the coordinate in this bounding box
251+
openvdb::BBoxd bbox(openvdb::Vec3d(0, 0, 0),
252+
openvdb::Vec3d(voxelCountX, voxelCountY, voxelCountZ));
253+
// define the taper
254+
const fpreal taper = nearPlaneSize.x() / farPlaneSize.x();
255+
256+
// note that the depth is scaled on the nearPlaneSize.
257+
// the linearMap will uniformly scale the frustum to the correct size
258+
// and rotate to align with the camera
259+
return openvdb::math::Transform::Ptr(new openvdb::math::Transform(
260+
openvdb::math::MapBase::Ptr(new openvdb::math::NonlinearFrustumMap(
261+
bbox, taper, depth/nearPlaneSize.x(), linearMap))));
262+
}
263+
#else
200264
openvdb::math::Transform::Ptr
201265
frustumTransformFromCamera(
202266
OP_Node& node, OP_Context& context, OBJ_Camera& cam,
@@ -281,7 +345,7 @@ frustumTransformFromCamera(
281345
openvdb::math::MapBase::Ptr(new openvdb::math::NonlinearFrustumMap(
282346
bbox, taper, depth/nearPlaneSize.x(), linearMap))));
283347
}
284-
348+
#endif
285349

286350
////////////////////////////////////////
287351

openvdb_houdini/openvdb_houdini/GeometryUtil.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#include <openvdb/util/NullInterrupter.h>
1515
#include <openvdb/util/Util.h> // for openvdb::util::COORD_OFFSETS
1616

17+
#include <OBJ/OBJ_Camera.h>
1718
#include <GU/GU_Detail.h>
1819
#include <GEO/GEO_Primitive.h>
20+
#include <UT/UT_Version.h>
1921

2022
#include <algorithm> // for std::max/min()
2123
#include <memory>
@@ -24,7 +26,6 @@
2426

2527

2628
class GA_SplittableRange;
27-
class OBJ_Camera;
2829
class OP_Context;
2930
class OP_Node;
3031

@@ -51,13 +52,20 @@ drawFrustum(GU_Detail&, const openvdb::math::Transform&,
5152

5253

5354
/// Construct a frustum transform from a Houdini camera.
55+
#if SYS_VERSION_MAJOR_INT >= 21
56+
openvdb::math::Transform::Ptr
57+
frustumTransformFromCamera(
58+
const OBJ_CameraParms&, const UT_Matrix4D&,
59+
float offset, float nearPlaneDist, float farPlaneDist,
60+
float voxelDepthSize = 1.0, int voxelCountX = 100);
61+
#else
5462
OPENVDB_HOUDINI_API
5563
openvdb::math::Transform::Ptr
5664
frustumTransformFromCamera(
5765
OP_Node&, OP_Context&, OBJ_Camera&,
5866
float offset, float nearPlaneDist, float farPlaneDist,
5967
float voxelDepthSize = 1.0, int voxelCountX = 100);
60-
68+
#endif
6169

6270
////////////////////////////////////////
6371

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Activate.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ enum OPERATION_NAMES
6060
class SOP_VDBActivate : public hvdb::SOP_NodeVDB
6161
{
6262
public:
63-
const char *inputLabel(unsigned idx) const override;
64-
int isRefInput(unsigned i) const override;
63+
const char *inputLabel(OP_InputIdx idx) const override;
64+
int isRefInput(OP_InputIdx i) const override;
6565

6666
bool updateParmsFlags() override;
6767

@@ -218,10 +218,10 @@ an inclusive range, so includes the maximum voxel.)"));
218218
support operation or setting of values.
219219
*/
220220
parms.add(hutil::ParmFactory(PRM_INT, "expand", "Expand Voxels")
221-
.setDefault(PRMoneDefaults)
221+
.setDefault(PRMoneDefaults)
222222
.setRange(PRM_RANGE_UI, -5, PRM_RANGE_UI, 5)
223223
.setTooltip("Expand the active area by at least the specified number of voxels.")
224-
.setDocumentation(
224+
.setDocumentation(
225225
R"(Expand the active area by at least the specified number of voxels. Does not support
226226
operation or setting of values.)"));
227227

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Advect.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ class SOP_OpenVDB_Advect: public hvdb::SOP_NodeVDB
4343

4444
static OP_Node* factory(OP_Network*, const char* name, OP_Operator*);
4545

46-
int isRefInput(unsigned i) const override { return (i > 0); }
46+
int isRefInput(OP_InputIdx i) const override
47+
{
48+
UT_ASSERT(i >= 0);
49+
return (i > 0);
50+
}
4751

4852
class Cache: public SOP_VDBCacheOptions { OP_ERROR cookVDBSop(OP_Context&) override; };
4953

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Advect_Points.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ class SOP_OpenVDB_Advect_Points: public hvdb::SOP_NodeVDB
626626

627627
static OP_Node* factory(OP_Network*, const char* name, OP_Operator*);
628628

629-
int isRefInput(unsigned i ) const override { return (i > 0); }
629+
int isRefInput(OP_InputIdx i) const override
630+
{
631+
UT_ASSERT(i >= 0);
632+
return (i > 0);
633+
}
630634

631635
class Cache: public SOP_VDBCacheOptions
632636
{

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Analysis.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ class SOP_OpenVDB_Analysis: public hvdb::SOP_NodeVDB
5050

5151
static OP_Node* factory(OP_Network*, const char* name, OP_Operator*);
5252

53-
int isRefInput(unsigned i) const override { return (i == 1); }
53+
int isRefInput(OP_InputIdx i) const override
54+
{
55+
UT_ASSERT(i >= 0);
56+
return (i == 1);
57+
}
5458

5559
static const char* sOpName[];
5660

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Clip.cc

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <openvdb/tools/Morphology.h> // for tools::dilateActiveValues(), tools::erodeActiveValues()
1818
#include <openvdb/points/PointDataGrid.h>
1919
#include <OBJ/OBJ_Camera.h>
20+
#include <UT/UT_Version.h>
2021
#include <cmath> // for std::abs(), std::round()
2122
#include <exception>
2223
#include <string>
@@ -35,7 +36,11 @@ class SOP_OpenVDB_Clip: public hvdb::SOP_NodeVDB
3536

3637
static OP_Node* factory(OP_Network*, const char* name, OP_Operator*);
3738

38-
int isRefInput(unsigned input) const override { return (input == 1); }
39+
int isRefInput(OP_InputIdx input) const override
40+
{
41+
UT_ASSERT(input >= 0);
42+
return (input == 1);
43+
}
3944

4045
class Cache: public SOP_VDBCacheOptions
4146
{
@@ -109,7 +114,11 @@ Mask VDB:\n\
109114

110115
parms.add(hutil::ParmFactory(PRM_STRING, "camera", "Camera")
111116
.setTypeExtended(PRM_TYPE_DYNAMIC_PATH)
117+
#if SYS_VERSION_MAJOR_INT >= 21
118+
.setSpareData(&PRM_SpareData::anyCameraPath)
119+
#else
112120
.setSpareData(&PRM_SpareData::objCameraPath)
121+
#endif
113122
.setTooltip("Specify the path to a reference camera")
114123
.setDocumentation(
115124
"The path to the camera whose frustum is to be used as a clipping region"
@@ -430,11 +439,32 @@ SOP_OpenVDB_Clip::Cache::getFrustum(OP_Context& context)
430439
const auto time = context.getTime();
431440

432441
UT_String cameraPath;
442+
OBJ_CameraParms cameraParms;
433443
evalString(cameraPath, "camera", 0, time);
434444
if (!cameraPath.isstring()) {
435445
throw std::runtime_error{"no camera path was specified"};
436446
}
437447

448+
#if SYS_VERSION_MAJOR_INT >= 21
449+
UT_Matrix4D cameratosop;
450+
OBJ_Node *meobj = cookparms()->getNode()
451+
? cookparms()->getNode()->getCreator()->castToOBJNode()
452+
: nullptr;
453+
UT_StringHolder errstr;
454+
455+
OP_Node::getCameraInfoAndRelativeTransform(
456+
cameraPath,
457+
meobj ? meobj->getFullPath() : UT_StringHolder::theEmptyString,
458+
cookparms()->getCwd(),
459+
false, // get_inverse_xform
460+
context,
461+
cookparms()->depnode(),
462+
cameraParms,
463+
cameratosop,
464+
errstr);
465+
if (errstr.isstring())
466+
throw std::runtime_error{"camera \"" + cameraPath.toStdString() + "\" was not found"};
467+
#else
438468
OBJ_Camera* camera = nullptr;
439469
if (auto* obj = cookparms()->getCwd()->findOBJNode(cameraPath)) {
440470
camera = obj->castToOBJCamera();
@@ -446,8 +476,9 @@ SOP_OpenVDB_Clip::Cache::getFrustum(OP_Context& context)
446476
}
447477
self->addExtraInput(camera, OP_INTEREST_DATA);
448478

449-
OBJ_CameraParms cameraParms;
450479
camera->getCameraParms(cameraParms, time);
480+
#endif
481+
451482
if (cameraParms.projection != OBJ_PROJ_PERSPECTIVE) {
452483
throw std::runtime_error{cameraPath.toStdString() + " is not a perspective camera"};
453484
/// @todo support ortho and other cameras?
@@ -458,13 +489,18 @@ SOP_OpenVDB_Clip::Cache::getFrustum(OP_Context& context)
458489

459490
const float nearPlane = (evalInt("setnear", 0, time)
460491
? static_cast<float>(evalFloat("near", 0, time))
461-
: static_cast<float>(camera->getNEAR(time))) - padding[2];
492+
: static_cast<float>(cameraParms.mynear)) - padding[2];
462493
const float farPlane = (evalInt("setfar", 0, time)
463494
? static_cast<float>(evalFloat("far", 0, time))
464-
: static_cast<float>(camera->getFAR(time))) + padding[2];
495+
: static_cast<float>(cameraParms.myfar)) + padding[2];
465496

497+
#if SYS_VERSION_MAJOR_INT >= 21
498+
mFrustum = hvdb::frustumTransformFromCamera(cameraParms, cameratosop,
499+
/*offset=*/0.f, nearPlane, farPlane, /*voxelDepth=*/1.f, /*voxelCountX=*/100);
500+
#else
466501
mFrustum = hvdb::frustumTransformFromCamera(*self, context, *camera,
467502
/*offset=*/0.f, nearPlane, farPlane, /*voxelDepth=*/1.f, /*voxelCountX=*/100);
503+
#endif
468504

469505
if (!mFrustum || !mFrustum->constMap<openvdb::math::NonlinearFrustumMap>()) {
470506
throw std::runtime_error{

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Combine.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ asResampleMode(exint i, ResampleMode defaultMode = RESAMPLE_B)
129129
? static_cast<ResampleMode>(i) : defaultMode;
130130
}
131131

132-
133132
//
134133
// Collation options
135134
//

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Convert.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ class SOP_OpenVDB_Convert: public hvdb::SOP_NodeVDB
5959

6060
// Return true for a given input if the connector to the input
6161
// should be drawn dashed rather than solid.
62-
int isRefInput(unsigned idx) const override { return (idx == 1); }
62+
int isRefInput(OP_InputIdx idx) const override
63+
{
64+
UT_ASSERT(idx >= 0);
65+
return (idx == 1);
66+
}
6367

6468
protected:
6569
bool updateParmsFlags() override;

0 commit comments

Comments
 (0)