Commit f22f8f6c authored by Carson Brownlee's avatar Carson Brownlee Committed by Carson Brownlee
Browse files

restructuring renderer to use list of instances instead of models.

parent 36331372
......@@ -734,6 +734,7 @@ vtkOSPRayPolyDataMapperNode::~vtkOSPRayPolyDataMapperNode()
{
delete this->GeometryCache;
delete this->InstanceCache;
ClearGeometricModels();
}
//----------------------------------------------------------------------------
......@@ -1335,8 +1336,20 @@ void vtkOSPRayPolyDataMapperNode::RenderGeometricModels()
}
for (auto g : this->GeometricModels)
{
std::cout << "vtkpdm: adding geometric model to scene\n";
orn->GeometricModels.emplace_back(g);
// std::cout << "vtkpdm: adding geometric model to scene\n";
// orn->GeometricModels.emplace_back(g);
OSPGroup group = ospNewGroup();
OSPInstance instance = ospNewInstance(group);
ospCommit(instance);
OSPData data = ospNewCopyData1D(1, OSP_GEOMETRIC_MODEL, &g);
ospCommit(data);
ospSetObject(group, "geometry", data);
ospCommit(group);
orn->Instances.emplace_back(instance);
this->Instances.emplace_back(instance);
// ospRelease(data);
// ospRelease(group);
}
}
......@@ -1354,9 +1367,14 @@ void vtkOSPRayPolyDataMapperNode::ClearGeometricModels()
{
for (auto g : this->GeometricModels)
{
ospRelease(g);
std::cout << "vtkpdm: releasing geometricmodel\n";
// ospRelease(g);
// std::cout << "vtkpdm: releasing geometricmodel\n";
}
for (auto i : this->Instances)
{
ospRelease(i);
}
}
this->GeometricModels.clear();
this->Instances.clear();
}
......@@ -68,6 +68,7 @@ protected:
};
std::vector<OSPGeometricModel> GeometricModels;
std::vector<OSPInstance> Instances;
void ClearGeometricModels();
vtkOSPRayCache<vtkOSPRayCacheItemGeometricModels>* GeometryCache{ nullptr };
......
......@@ -1082,6 +1082,7 @@ void vtkOSPRayRendererNode::Traverse(int operation)
{
this->VolumetricModels.clear();
this->GeometricModels.clear();
this->Instances.clear();
this->NumActors = numAct;
// ospRelease((OSPWorld)this->OWorld);
it->InitTraversal();
......@@ -1107,6 +1108,7 @@ void vtkOSPRayRendererNode::Traverse(int operation)
{
std::cout << "new world\n";
this->OWorld = ospNewWorld();
ospCommit(this->OWorld);
}
// ospCommit(this->OWorld);
// ospSetObject(oRenderer,"model", oWorld);
......@@ -1244,29 +1246,41 @@ void vtkOSPRayRendererNode::Render(bool prepass)
if (this->VolumetricModels.size() || this->GeometricModels.size())
{
std::cout << "vtkrenderer populating world\n";
static OSPGroup group = ospNewGroup();
ospSetBool(group, "compactMode", true);
// static OSPGroup group = ospNewGroup();
// put the group into an instance (give the group a world transform)
// static OSPInstance instance = ospNewInstance(group);
if (this->VolumetricModels.size())
{
auto data = ospNewSharedData1D(
this->VolumetricModels.data(), OSP_VOLUMETRIC_MODEL, this->VolumetricModels.size());
ospCommit(data);
ospSetObject(group, "volume", data);
ospRelease(data);
// static bool once = false;
// if (!once)
// {
// once = true;
// auto data = ospNewSharedData1D(
// this->VolumetricModels.data(), OSP_VOLUMETRIC_MODEL, this->VolumetricModels.size());
// ospCommit(data);
// ospSetObject(group, "volume", data);
// ospRelease(data);
// }
}
if (this->GeometricModels.size())
{
auto data = ospNewSharedData1D(
this->GeometricModels.data(), OSP_GEOMETRIC_MODEL, this->GeometricModels.size());
ospCommit(data);
ospSetObject(group, "geometry", data);
ospRelease(data);
// static bool once = false;
// if (!once)
// {
// once = true;
// ospSetBool(group, "compactMode", true);
// auto data = ospNewCopyData1D(
// this->GeometricModels.size(), OSP_GEOMETRIC_MODEL, this->GeometricModels.data());
// ospCommit(data);
// ospSetObject(group, "geometry", data);
// ospRelease(data);
// ospCommit(group);
// ospCommit(instance);
// // this->Instances.emplace_back(instance);
// }
}
ospCommit(group);
// ospCommit(group);
// put the group into an instance (give the group a world transform)
OSPInstance instance = ospNewInstance(group);
ospCommit(instance);
// ospRelease(group);
if (this->Lights.size())
......@@ -1276,10 +1290,12 @@ void vtkOSPRayRendererNode::Render(bool prepass)
ospSetObject(oWorld, "light", data);
ospRelease(data);
}
ospSetObjectAsData(oWorld, "instance", OSP_INSTANCE, instance);
ospRelease(instance);
}
auto instanceData =
ospNewSharedData1D(this->Instances.data(), OSP_INSTANCE, this->Instances.size());
ospSetParam(oWorld, "instance", OSP_DATA, &instanceData);
ospRelease(instanceData);
ospCommit(oWorld);
OSPRenderer oRenderer = this->ORenderer;
......
......@@ -342,6 +342,7 @@ public:
std::vector<OSPGeometricModel> GeometricModels;
std::vector<OSPVolumetricModel> VolumetricModels;
std::vector<OSPInstance> Instances;
protected:
vtkOSPRayRendererNode();
......
......@@ -63,9 +63,14 @@ vtkOSPRayVolumeMapperNode::~vtkOSPRayVolumeMapperNode()
{
ospRelease(this->TransferFunction);
ospRelease(this->SharedData);
if (this->Cache->GetSize() == 0)
if (this->OSPRayVolumeModel)
{
ospRelease(this->OSPRayVolumeModel);
}
if (this->OSPRayInstance)
{
ospRelease(this->OSPRayVolume);
ospRelease(this->OSPRayInstance);
}
}
}
......@@ -275,6 +280,14 @@ void vtkOSPRayVolumeMapperNode::Render(bool prepass)
this->UpdateTransferFunction(backend, vol, sa->GetRange());
}
if (this->OSPRayVolumeModel)
{
ospRelease(this->OSPRayVolumeModel);
}
if (this->OSPRayInstance)
{
ospRelease(this->OSPRayInstance);
}
this->OSPRayVolumeModel = ospNewVolumetricModel(this->OSPRayVolume);
ospSetObject(this->OSPRayVolumeModel, "transferFunction", this->TransferFunction);
const float densityScale = 1.0f / volProperty->GetScalarOpacityUnitDistance();
......@@ -311,7 +324,17 @@ void vtkOSPRayVolumeMapperNode::Render(bool prepass)
// }
// else
// {
orn->VolumetricModels.emplace_back(this->OSPRayVolumeModel);
// orn->VolumetricModels.emplace_back(this->OSPRayVolumeModel);
OSPGroup group = ospNewGroup();
OSPInstance instance = ospNewInstance(group);
ospCommit(instance);
OSPData instanceData = ospNewCopyData1D(1, OSP_VOLUMETRIC_MODEL, &this->OSPRayVolumeModel);
ospCommit(instanceData);
ospSetObject(group, "volume", instanceData);
ospCommit(group);
orn->Instances.emplace_back(instance);
this->OSPRayInstance = instance;
// }
if (sca)
......
......@@ -73,8 +73,9 @@ protected:
vtkTimeStamp PropertyTime;
OSPGeometry OSPRayIsosurface;
OSPVolume OSPRayVolume;
OSPVolumetricModel OSPRayVolumeModel;
OSPVolume OSPRayVolume{ nullptr };
OSPVolumetricModel OSPRayVolumeModel{ nullptr };
OSPInstance OSPRayInstance{ nullptr };
OSPTransferFunction TransferFunction;
std::vector<float> TFVals;
std::vector<float> TFOVals;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment