|
16 | 16 | #include <GA/GA_Types.h> |
17 | 17 | #include <GU/GU_ConvertParms.h> |
18 | 18 | #include <GU/GU_PrimPoly.h> |
19 | | -#include <OBJ/OBJ_Camera.h> |
20 | 19 | #include <UT/UT_BoundingBox.h> |
21 | 20 | #include <UT/UT_String.h> |
22 | 21 | #include <UT/UT_UniquePtr.h> |
@@ -196,7 +195,72 @@ drawFrustum( |
196 | 195 |
|
197 | 196 | //////////////////////////////////////// |
198 | 197 |
|
| 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())); |
199 | 245 |
|
| 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 |
200 | 264 | openvdb::math::Transform::Ptr |
201 | 265 | frustumTransformFromCamera( |
202 | 266 | OP_Node& node, OP_Context& context, OBJ_Camera& cam, |
@@ -281,7 +345,7 @@ frustumTransformFromCamera( |
281 | 345 | openvdb::math::MapBase::Ptr(new openvdb::math::NonlinearFrustumMap( |
282 | 346 | bbox, taper, depth/nearPlaneSize.x(), linearMap)))); |
283 | 347 | } |
284 | | - |
| 348 | +#endif |
285 | 349 |
|
286 | 350 | //////////////////////////////////////// |
287 | 351 |
|
|
0 commit comments