vtk/vtk-9.3.1-ospray-3.1.0.patch

413 lines
19 KiB
Diff
Raw Normal View History

From 6fa86e668c67015e961e2c4667f2fbc719d6188b Mon Sep 17 00:00:00 2001
From: "David E. DeMarle" <david.demarle@intel.com>
Date: Tue, 19 Sep 2023 21:27:45 -0400
Subject: [PATCH 1/2] bump VTK to OSPRay 3 API
Change CMake script to look for 3.
Stop using previously deprecated OSPRay APIs, they are removed in 3.0.
Use new parameter signatures including:
uint for enums
box1f instead of vec2f for ranges
"valueRanges" TransferFunction parameter is now "value".
linear2d for texture transforms
ospNewMaterial no longer accepts renderertype first argument
Implicit isocontours now take their appearance settings from
GeometricModel instead of VolumetricModel.
---
Rendering/RayTracing/CMakeLists.txt | 2 +-
Rendering/RayTracing/RTWrapper/Backend.h | 5 ++-
.../RTWrapper/OSPRay/OSPRayBackend.h | 25 ++++++++++-----
Rendering/RayTracing/RTWrapper/RTWrapper.h | 3 ++
.../RayTracing/vtkOSPRayMaterialHelpers.cxx | 9 +++---
.../vtkOSPRayMoleculeMapperNode.cxx | 8 ++---
.../vtkOSPRayPointGaussianMapperNode.cxx | 2 +-
.../vtkOSPRayPolyDataMapperNode.cxx | 32 +++++++++----------
.../vtkOSPRayUnstructuredVolumeMapperNode.cxx | 2 +-
.../RayTracing/vtkOSPRayVolumeMapperNode.cxx | 24 ++++++++++++--
.../RayTracing/vtkOSPRayVolumeMapperNode.h | 1 +
11 files changed, 73 insertions(+), 40 deletions(-)
diff --git a/Rendering/RayTracing/CMakeLists.txt b/Rendering/RayTracing/CMakeLists.txt
index 9d5ad4dd828..baa3078065e 100644
--- a/Rendering/RayTracing/CMakeLists.txt
+++ b/Rendering/RayTracing/CMakeLists.txt
@@ -58,7 +58,7 @@ vtk_module_add_module(VTK::RenderingRayTracing
if (VTK_ENABLE_OSPRAY)
vtk_module_find_package(PRIVATE_IF_SHARED
PACKAGE ospray
- VERSION 2.1)
+ VERSION 3.0)
vtk_module_link(VTK::RenderingRayTracing
PRIVATE
diff --git a/Rendering/RayTracing/RTWrapper/Backend.h b/Rendering/RayTracing/RTWrapper/Backend.h
index e35e789f345..ba13a89cb7c 100644
--- a/Rendering/RayTracing/RTWrapper/Backend.h
+++ b/Rendering/RayTracing/RTWrapper/Backend.h
@@ -30,7 +30,7 @@ VTK_ABI_NAMESPACE_BEGIN
virtual RTWGroup NewGroup() = 0;
virtual RTWTexture NewTexture(const char* type) = 0;
virtual RTWLight NewLight(const char *light_type) = 0;
- virtual RTWMaterial NewMaterial(const char *renderer_type, const char *material_type) = 0;
+ virtual RTWMaterial NewMaterial(const char *material_type) = 0;
virtual RTWVolume NewVolume(const char *type) = 0;
virtual RTWVolumetricModel NewVolumetricModel(RTWVolume volume) = 0;
virtual RTWTransferFunction NewTransferFunction(const char *type) = 0;
@@ -49,13 +49,16 @@ VTK_ABI_NAMESPACE_BEGIN
virtual void SetObjectAsData(RTWObject target, const char *id, RTWDataType type, RTWObject obj) = 0;
virtual void SetParam(RTWObject, const char *id, RTWDataType type, const void* mem) = 0;
virtual void SetBool(RTWObject, const char *id, bool x) = 0;
+ virtual void SetBox1f(RTWObject, const char *id, float x, float y) = 0;
virtual void SetInt(RTWObject, const char *id, int32_t x) = 0;
+ virtual void SetUInt(RTWObject, const char *id, uint32_t x) = 0;
virtual void SetVec2i(RTWObject, const char *id, int32_t x, int32_t y) = 0;
virtual void SetFloat(RTWObject, const char *id, float x) = 0;
virtual void SetVec2f(RTWObject, const char *id, float x, float y) = 0;
virtual void SetVec3i(RTWObject, const char *id, int x, int y, int z) = 0;
virtual void SetVec3f(RTWObject, const char *id, float x, float y, float z) = 0;
virtual void SetVec4f(RTWObject, const char *id, float x, float y, float z, float w) = 0;
+ virtual void SetLinear2f(RTWObject, const char *id, float x, float y, float z, float w) = 0;
virtual void RemoveParam(RTWObject, const char *id) = 0;
diff --git a/Rendering/RayTracing/RTWrapper/OSPRay/OSPRayBackend.h b/Rendering/RayTracing/RTWrapper/OSPRay/OSPRayBackend.h
index 4ee1be32282..f3fe5209b7b 100644
--- a/Rendering/RayTracing/RTWrapper/OSPRay/OSPRayBackend.h
+++ b/Rendering/RayTracing/RTWrapper/OSPRay/OSPRayBackend.h
@@ -84,15 +84,9 @@ VTK_ABI_NAMESPACE_BEGIN
{
std::runtime_error("OSPRay device could not be fetched!");
}
-#if OSPRAY_VERSION_MINOR > 1
ospDeviceSetErrorCallback(device, [](void *, OSPError, const char *errorDetails) {
std::cerr << "OSPRay ERROR: " << errorDetails << std::endl;
}, nullptr);
-#else
- ospDeviceSetErrorFunc(device, [](OSPError, const char *errorDetails) {
- std::cerr << "OSPRay ERROR: " << errorDetails << std::endl;
- });
-#endif
once = true;
}
return ret;
@@ -199,9 +193,9 @@ VTK_ABI_NAMESPACE_BEGIN
return reinterpret_cast<RTWLight>(ospNewLight(light_type));
}
- RTWMaterial NewMaterial(const char *renderer_type, const char *material_type) override
+ RTWMaterial NewMaterial(const char *material_type) override
{
- return reinterpret_cast<RTWMaterial>(ospNewMaterial(renderer_type, material_type));
+ return reinterpret_cast<RTWMaterial>(ospNewMaterial(material_type));
}
RTWVolume NewVolume(const char *type) override
@@ -280,6 +274,11 @@ VTK_ABI_NAMESPACE_BEGIN
ospSetInt(reinterpret_cast<OSPObject>(object), id, x);
}
+ void SetUInt(RTWObject object, const char *id, uint32_t x) override
+ {
+ ospSetUInt(reinterpret_cast<OSPObject>(object), id, x);
+ }
+
void SetBool(RTWObject object, const char *id, bool x) override
{
ospSetBool(reinterpret_cast<OSPObject>(object), id, x);
@@ -290,6 +289,16 @@ VTK_ABI_NAMESPACE_BEGIN
ospSetFloat(reinterpret_cast<OSPObject>(object), id, x);
}
+ void SetLinear2f(RTWObject object, const char *id, float x, float y, float z, float w) override
+ {
+ ospSetLinear2f(reinterpret_cast<OSPObject>(object), id, x, y, z, w);
+ }
+
+ void SetBox1f(RTWObject object, const char *id, float x, float y) override
+ {
+ ospSetBox1f(reinterpret_cast<OSPObject>(object), id, x, y);
+ }
+
void SetVec2f(RTWObject object, const char *id, float x, float y) override
{
ospSetVec2f(reinterpret_cast<OSPObject>(object), id, x, y);
diff --git a/Rendering/RayTracing/RTWrapper/RTWrapper.h b/Rendering/RayTracing/RTWrapper/RTWrapper.h
index 1bbdb893a42..ebbe18aef99 100644
--- a/Rendering/RayTracing/RTWrapper/RTWrapper.h
+++ b/Rendering/RayTracing/RTWrapper/RTWrapper.h
@@ -140,7 +140,10 @@ std::set<RTWBackendType> rtwGetAvailableBackends();
#define ospSetFloat backend->SetFloat
#define ospSetBool backend->SetBool
+#define ospSetBox1f backend->SetBox1f
#define ospSetInt backend->SetInt
+#define ospSetLinear2f backend->SetLinear2f
+#define ospSetUInt backend->SetUInt
#define ospSetVec2i backend->SetVec2i
#define ospSetVec3i backend->SetVec3i
#define ospSetVec2f backend->SetVec2f
diff --git a/Rendering/RayTracing/vtkOSPRayMaterialHelpers.cxx b/Rendering/RayTracing/vtkOSPRayMaterialHelpers.cxx
index 12fb6aaf98d..e21a761253b 100644
--- a/Rendering/RayTracing/vtkOSPRayMaterialHelpers.cxx
+++ b/Rendering/RayTracing/vtkOSPRayMaterialHelpers.cxx
@@ -70,10 +70,10 @@ OSPTexture NewTexture2D(RTW::Backend* backend, const osp::vec2i& size, const OSP
ospSetObject(texture, "data", data_handle);
ospRelease(data_handle);
- ospSetInt(texture, "format", static_cast<int>(type));
+ ospSetUInt(texture, "format", type);
if (flags & OSP_TEXTURE_FILTER_NEAREST)
{
- ospSetInt(texture, "filter", OSP_TEXTURE_FILTER_NEAREST);
+ ospSetUInt(texture, "filter", OSP_TEXTURE_FILTER_NEAREST);
}
ospCommit(texture);
@@ -362,14 +362,13 @@ OSPMaterial NewMaterial(vtkOSPRayRendererNode* orn, OSPRenderer oRenderer, std::
return result;
(void)oRenderer;
- const std::string rendererType = vtkOSPRayRendererNode::GetRendererType(orn->GetRenderer());
- result = ospNewMaterial(rendererType.c_str(), ospMatName.c_str());
+ result = ospNewMaterial(ospMatName.c_str());
if (!result)
{
vtkGenericWarningMacro(
"OSPRay failed to create material: " << ospMatName << ". Trying obj instead.");
- result = ospNewMaterial(rendererType.c_str(), "obj");
+ result = ospNewMaterial("obj");
}
ospCommit(result);
diff --git a/Rendering/RayTracing/vtkOSPRayMoleculeMapperNode.cxx b/Rendering/RayTracing/vtkOSPRayMoleculeMapperNode.cxx
index 5c0f36de21b..3ae794ed0f0 100644
--- a/Rendering/RayTracing/vtkOSPRayMoleculeMapperNode.cxx
+++ b/Rendering/RayTracing/vtkOSPRayMoleculeMapperNode.cxx
@@ -292,8 +292,8 @@ void vtkOSPRayMoleculeMapperNode::Render(bool prepass)
ospRelease(oMaterial);
}
- ospSetInt(bonds, "type", OSP_ROUND);
- ospSetInt(bonds, "basis", OSP_BEZIER);
+ ospSetUInt(bonds, "type", OSP_ROUND);
+ ospSetUInt(bonds, "basis", OSP_BEZIER);
this->GeometricModels.emplace_back(bondsModel);
ospCommit(bonds);
@@ -394,8 +394,8 @@ void vtkOSPRayMoleculeMapperNode::Render(bool prepass)
ocolor[3] = opacity;
ospSetVec3f(latticeModel, "color", ocolor[0], ocolor[1], ocolor[2]);
- ospSetInt(lattice, "type", OSP_ROUND);
- ospSetInt(lattice, "basis", OSP_LINEAR);
+ ospSetUInt(lattice, "type", OSP_ROUND);
+ ospSetUInt(lattice, "basis", OSP_LINEAR);
this->GeometricModels.emplace_back(latticeModel);
ospCommit(lattice);
diff --git a/Rendering/RayTracing/vtkOSPRayPointGaussianMapperNode.cxx b/Rendering/RayTracing/vtkOSPRayPointGaussianMapperNode.cxx
index f294bf4b2f8..be040f627c5 100644
--- a/Rendering/RayTracing/vtkOSPRayPointGaussianMapperNode.cxx
+++ b/Rendering/RayTracing/vtkOSPRayPointGaussianMapperNode.cxx
@@ -280,7 +280,7 @@ OSPVolumetricModel RenderAsParticles(osp::vec3f* vertices, std::vector<unsigned
auto oTF = ospNewTransferFunction("piecewiseLinear");
ospSetObject(oTF, "color", _Colors);
ospSetObject(oTF, "opacity", _AlphaData);
- ospSetVec2f(oTF, "valueRange", static_cast<float>(wRange[0]), static_cast<float>(wRange[1]));
+ ospSetBox1f(oTF, "value", static_cast<float>(wRange[0]), static_cast<float>(wRange[1]));
ospCommit(oTF);
ospRelease(_Colors);
ospRelease(_AlphaData);
diff --git a/Rendering/RayTracing/vtkOSPRayPolyDataMapperNode.cxx b/Rendering/RayTracing/vtkOSPRayPolyDataMapperNode.cxx
index 8031b169f3f..3f5fb31fd17 100644
--- a/Rendering/RayTracing/vtkOSPRayPolyDataMapperNode.cxx
+++ b/Rendering/RayTracing/vtkOSPRayPolyDataMapperNode.cxx
@@ -304,8 +304,8 @@ OSPGeometricModel RenderAsCylinders(std::vector<osp::vec3f>& vertices,
_mdata = ospNewCopyData1D(mdata.data(), OSP_VEC4F, mdata.size());
ospCommit(_mdata);
ospSetObject(ospMesh, "vertex.position_radius", _mdata);
- ospSetInt(ospMesh, "type", OSP_ROUND);
- ospSetInt(ospMesh, "basis", OSP_BEZIER);
+ ospSetUInt(ospMesh, "type", OSP_ROUND);
+ ospSetUInt(ospMesh, "basis", OSP_BEZIER);
}
else
{
@@ -319,8 +319,8 @@ OSPGeometricModel RenderAsCylinders(std::vector<osp::vec3f>& vertices,
ospCommit(_mdata);
ospSetObject(ospMesh, "vertex.position", _mdata);
ospSetFloat(ospMesh, "radius", lineWidth);
- ospSetInt(ospMesh, "type", OSP_ROUND);
- ospSetInt(ospMesh, "basis", OSP_LINEAR);
+ ospSetUInt(ospMesh, "type", OSP_ROUND);
+ ospSetUInt(ospMesh, "basis", OSP_LINEAR);
}
std::vector<unsigned int> indices;
@@ -530,13 +530,13 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
if (interpolationType == VTK_PBR)
{
ospSetObject(actorMaterial, "map_normal", t2d);
- ospSetVec4f(actorMaterial, "map_normal.transform", textureTransform.x, textureTransform.y,
- textureTransform.z, textureTransform.w);
+ ospSetLinear2f(actorMaterial, "map_normal.transform", textureTransform.x,
+ textureTransform.y, textureTransform.z, textureTransform.w);
}
else
{
ospSetObject(actorMaterial, "map_Bump", t2d);
- ospSetVec4f(actorMaterial, "map_Bump.transform", textureTransform.x, textureTransform.y,
+ ospSetLinear2f(actorMaterial, "map_Bump.transform", textureTransform.x, textureTransform.y,
textureTransform.z, textureTransform.w);
}
ospCommit(actorMaterial);
@@ -562,13 +562,13 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
OSPTexture t2dR = vtkOSPRayMaterialHelpers::VTKToOSPTexture(backend, vRoughnessTextureMap);
ospSetObject(actorMaterial, "map_roughness", t2dR);
- ospSetVec4f(actorMaterial, "map_roughness.transform", textureTransform.x,
+ ospSetLinear2f(actorMaterial, "map_roughness.transform", textureTransform.x,
textureTransform.y, textureTransform.z, textureTransform.w);
OSPTexture t2dM = vtkOSPRayMaterialHelpers::VTKToOSPTexture(backend, vMetallicTextureMap);
ospSetObject(actorMaterial, "map_metallic", t2dM);
- ospSetVec4f(actorMaterial, "map_metallic.transform", textureTransform.x, textureTransform.y,
- textureTransform.z, textureTransform.w);
+ ospSetLinear2f(actorMaterial, "map_metallic.transform", textureTransform.x,
+ textureTransform.y, textureTransform.z, textureTransform.w);
ospCommit(actorMaterial);
ospRelease(t2dR);
@@ -593,14 +593,14 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
OSPTexture t2dA =
vtkOSPRayMaterialHelpers::VTKToOSPTexture(backend, vAnisotropyValueTextureMap);
ospSetObject(actorMaterial, "map_anisotropy", t2dA);
- ospSetVec4f(actorMaterial, "map_anisotropy.transform", textureTransform.x,
+ ospSetLinear2f(actorMaterial, "map_anisotropy.transform", textureTransform.x,
textureTransform.y, textureTransform.z, textureTransform.w);
OSPTexture t2dR =
vtkOSPRayMaterialHelpers::VTKToOSPTexture(backend, vAnisotropyRotationTextureMap);
ospSetObject(actorMaterial, "map_rotation", t2dR);
- ospSetVec4f(actorMaterial, "map_rotation.transform", textureTransform.x, textureTransform.y,
- textureTransform.z, textureTransform.w);
+ ospSetLinear2f(actorMaterial, "map_rotation.transform", textureTransform.x,
+ textureTransform.y, textureTransform.z, textureTransform.w);
ospCommit(actorMaterial);
ospRelease(t2dA);
ospRelease(t2dR);
@@ -610,7 +610,7 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
{
OSPTexture t2d = vtkOSPRayMaterialHelpers::VTKToOSPTexture(backend, vCoatNormalTextureMap);
ospSetObject(actorMaterial, "map_coatNormal", t2d);
- ospSetVec4f(actorMaterial, "map_coatNormal.transform", textureTransform.x,
+ ospSetLinear2f(actorMaterial, "map_coatNormal.transform", textureTransform.x,
textureTransform.y, textureTransform.z, textureTransform.w);
ospCommit(actorMaterial);
ospRelease(t2d);
@@ -624,13 +624,13 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
if (interpolationType == VTK_PBR)
{
ospSetObject(actorMaterial, "map_baseColor", ((OSPTexture)(t2d)));
- ospSetVec4f(actorMaterial, "map_baseColor.transform", textureTransform.x,
+ ospSetLinear2f(actorMaterial, "map_baseColor.transform", textureTransform.x,
textureTransform.y, textureTransform.z, textureTransform.w);
}
else
{
ospSetObject(actorMaterial, "map_kd", ((OSPTexture)(t2d)));
- ospSetVec4f(actorMaterial, "map_kd.transform", textureTransform.x, textureTransform.y,
+ ospSetLinear2f(actorMaterial, "map_kd.transform", textureTransform.x, textureTransform.y,
textureTransform.z, textureTransform.w);
}
ospCommit(actorMaterial);
diff --git a/Rendering/RayTracing/vtkOSPRayUnstructuredVolumeMapperNode.cxx b/Rendering/RayTracing/vtkOSPRayUnstructuredVolumeMapperNode.cxx
index 2662d7ac045..c764314c061 100644
--- a/Rendering/RayTracing/vtkOSPRayUnstructuredVolumeMapperNode.cxx
+++ b/Rendering/RayTracing/vtkOSPRayUnstructuredVolumeMapperNode.cxx
@@ -355,7 +355,7 @@ void vtkOSPRayUnstructuredVolumeMapperNode::Render(bool prepass)
OSPData tfAlphaData = ospNewCopyData1D(&tfOVals[0], OSP_FLOAT, NumColors);
ospCommit(tfAlphaData);
ospSetObject(oTF, "opacity", tfAlphaData);
- ospSetVec2f(oTF, "valueRange", range[0], range[1]);
+ ospSetBox1f(oTF, "value", (float)range[0], (float)range[1]);
ospCommit(oTF);
ospRelease(colorData);
diff --git a/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.cxx b/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.cxx
index 564a8be1eb4..dc65c5ac9a3 100644
--- a/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.cxx
+++ b/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.cxx
@@ -322,7 +322,7 @@ void vtkOSPRayVolumeMapperNode::Render(bool prepass)
ospCommit(isosurfaces);
ospSetObject(OSPRayIsosurface, "isovalue", isosurfaces);
- ospSetObject(OSPRayIsosurface, "volume", this->OSPRayVolumeModel);
+ ospSetObject(OSPRayIsosurface, "volume", this->OSPRayVolume);
ospCommit(OSPRayIsosurface);
ospRelease(isosurfaces);
@@ -330,12 +330,15 @@ void vtkOSPRayVolumeMapperNode::Render(bool prepass)
OSPInstance instance = ospNewInstance(group);
OSPGeometricModel OSPRayGeometricModel = ospNewGeometricModel(OSPRayIsosurface);
-
+ OSPData ospIsoColors = ospNewCopyData1D(this->IsoColors.data(), OSP_VEC4F, nbContours);
+ ospCommit(ospIsoColors);
+ ospSetObject(OSPRayGeometricModel, "color", ospIsoColors);
OSPMaterial material =
vtkOSPRayMaterialHelpers::NewMaterial(orn, orn->GetORenderer(), "obj");
ospCommit(material);
ospSetObjectAsData(OSPRayGeometricModel, "material", OSP_MATERIAL, material);
ospCommit(OSPRayGeometricModel);
+ ospRelease(ospIsoColors);
ospRelease(material);
ospRelease(OSPRayIsosurface);
@@ -417,7 +420,7 @@ void vtkOSPRayVolumeMapperNode::UpdateTransferFunction(
ospCommit(colorData);
ospSetObject(this->TransferFunction, "color", colorData);
- ospSetVec2f(this->TransferFunction, "valueRange", tfRange.x, tfRange.y);
+ ospSetBox1f(this->TransferFunction, "value", tfRange.x, tfRange.y);
OSPData tfAlphaData = ospNewCopyData1D(&this->TFOVals[0], OSP_FLOAT, this->NumColors);
ospCommit(tfAlphaData);
@@ -427,6 +430,21 @@ void vtkOSPRayVolumeMapperNode::UpdateTransferFunction(
ospRelease(colorData);
ospRelease(tfAlphaData);
+ vtkContourValues* contours = volProperty->GetIsoSurfaceValues();
+ this->IsoColors.clear();
+ if (contours)
+ {
+ double* p = contours->GetValues();
+ for (auto i = 0; i < contours->GetNumberOfContours(); ++i)
+ {
+ double* ncol = colorTF->GetColor(p[i]);
+ this->IsoColors.push_back(ncol[0]);
+ this->IsoColors.push_back(ncol[1]);
+ this->IsoColors.push_back(ncol[2]);
+ this->IsoColors.push_back(scalarTF->GetValue(p[i]));
+ }
+ }
+
this->PropertyTime.Modified();
}
VTK_ABI_NAMESPACE_END
diff --git a/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.h b/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.h
index 267875f057b..7769aece01c 100644
--- a/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.h
+++ b/Rendering/RayTracing/vtkOSPRayVolumeMapperNode.h
@@ -68,6 +68,7 @@ protected:
std::vector<float> TFVals;
std::vector<float> TFOVals;
+ std::vector<float> IsoColors;
vtkOSPRayCache<vtkOSPRayCacheItemObject>* Cache;
--
GitLab