Commit 1edd8801 authored by Carson Brownlee's avatar Carson Brownlee
Browse files

adding back color for ospraypolydatamapper

parent fd6ac300
......@@ -441,7 +441,6 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
int numPointColors, osp::vec4f* PointColors, int numPointValueTextureCoords,
float* pointValueTextureCoords, RTW::Backend* backend)
{
std::cout << "ospPDMN::RenderAsTriangles begin\n";
if (backend == nullptr)
return OSPGeometry();
OSPGeometry ospMesh = ospNewGeometry("mesh");
......@@ -465,16 +464,16 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
OSPData _normals = nullptr;
if (numNormals)
{
// _normals = ospNewCopyData1D(numNormals, OSP_VEC3F, normals.data());
// ospSetObject(ospMesh, "vertex.normal", _normals);
// ospRelease(_normals);
_normals = ospNewCopyData1D(numNormals, OSP_VEC3F, normals.data());
ospSetObject(ospMesh, "vertex.normal", _normals);
ospRelease(_normals);
}
// send the texture map and texture coordinates over
bool _hastm = false;
OSPData tcs = nullptr;
std::vector<osp::vec2f> tc;
if (0) // numTextureCoordinates || numPointValueTextureCoords)
if (numTextureCoordinates || numPointValueTextureCoords)
{
_hastm = true;
......@@ -516,7 +515,7 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
int* ids = nullptr;
if (!useCustomMaterial)
{
if (0) // vNormalTextureMap && _hastm)
if (vNormalTextureMap && _hastm)
{
OSPTexture t2d = vtkOSPRayMaterialHelpers::VTKToOSPTexture(backend, vNormalTextureMap);
if (interpolationType == VTK_PBR)
......@@ -535,7 +534,7 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
ospCommit(actorMaterial);
}
if (0) // interpolationType == VTK_PBR && vMaterialTextureMap && _hastm)
if (interpolationType == VTK_PBR && vMaterialTextureMap && _hastm)
{
vtkNew<vtkImageExtractComponents> extractRoughness;
extractRoughness->SetInputData(vMaterialTextureMap);
......@@ -565,7 +564,7 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
ospCommit(actorMaterial);
}
if (0) // vColorTextureMap && _hastm)
if (vColorTextureMap && _hastm)
{
std::cout << "has vcolortexturmap\n";
// Note: this will only have an affect on OBJMaterials
......@@ -602,9 +601,9 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
else if (numPointColors)
{
std::cout << "numpointcolors\n";
// _PointColors = ospNewCopyData1D(numPointColors, OSP_VEC4F, &PointColors[0]);
// ospSetObject(ospMesh, "vertex.color", _PointColors);
// ospRelease(_PointColors);
_PointColors = ospNewCopyData1D(numPointColors, OSP_VEC4F, &PointColors[0]);
ospSetObject(ospMesh, "vertex.color", _PointColors);
ospRelease(_PointColors);
std::cout << "numpointcolors end\n";
}
}
......@@ -791,9 +790,7 @@ void vtkOSPRayPolyDataMapperNode::ORenderPoly(void* renderer, vtkOSPRayActorNode
vertices[i] = osp::vec3f{ static_cast<float>(_vertices[i * 3 + 0]),
static_cast<float>(_vertices[i * 3 + 1]), static_cast<float>(_vertices[i * 3 + 2]) };
}
std::cout << "creating position data\n";
OSPData position = ospNewCopyData1D(numPositions, OSP_VEC3F, &vertices[0]);
std::cout << "done creating position data\n";
ospCommit(position);
_vertices.clear();
......@@ -868,6 +865,8 @@ void vtkOSPRayPolyDataMapperNode::ORenderPoly(void* renderer, vtkOSPRayActorNode
if (texture)
{
vColorTextureMap = texture->GetInput();
ospSetVec3f(oMaterial, "kd", 1.0f, 1.0f, 1.0f);
ospCommit(oMaterial);
}
// colors from point and cell arrays
......@@ -964,12 +963,15 @@ void vtkOSPRayPolyDataMapperNode::ORenderPoly(void* renderer, vtkOSPRayActorNode
pointColors[i] = osp::vec4f{ color[0] / 255.0f, color[1] / 255.0f, color[2] / 255.0f,
(color[3] / 255.0f) * static_cast<float>(opacity) };
}
ospSetVec3f(oMaterial, "kd", 1.0f, 1.0f, 1.0f);
ospCommit(oMaterial);
}
}
else
{
if (vColorCoordinates && pColorTextureMap)
{
std::cout << "vcolorcoordinates\n";
// color on point interpolated values (subsequently colormapped via 1D LUT)
numPointValueTextureCoords = vColorCoordinates->GetNumberOfTuples();
pointValueTextureCoords.resize(numPointValueTextureCoords);
......@@ -982,6 +984,8 @@ void vtkOSPRayPolyDataMapperNode::ORenderPoly(void* renderer, vtkOSPRayActorNode
tc += 2;
}
vColorTextureMap = pColorTextureMap;
ospSetVec3f(oMaterial, "kd", 1.0f, 1.0f, 1.0f);
ospCommit(oMaterial);
}
}
......@@ -1321,7 +1325,6 @@ void vtkOSPRayPolyDataMapperNode::PopulateCache()
//----------------------------------------------------------------------------
void vtkOSPRayPolyDataMapperNode::RenderGeometricModels()
{
std::cout << "ospPDMN::RenderGeometric Models begin\n";
vtkOSPRayRendererNode* orn =
static_cast<vtkOSPRayRendererNode*>(this->GetFirstAncestorOfType("vtkOSPRayRendererNode"));
double tstep = vtkOSPRayRendererNode::GetViewTime(orn->GetRenderer());
......@@ -1336,7 +1339,6 @@ void vtkOSPRayPolyDataMapperNode::RenderGeometricModels()
if (cacheEntry->size > 0)
{
OSPGeometricModel instance = static_cast<OSPGeometricModel>(cacheEntry->object);
// ospAddGeometricModel(oWorld, instance);
}
return;
}
......@@ -1359,39 +1361,21 @@ void vtkOSPRayPolyDataMapperNode::RenderGeometricModels()
ospRelease(&(*g));
ospCommit(data);
ospSetObject(group, "geometry", data);
std::cout << "vtkOPDMN: commit group\n";
ospCommit(group);
std::cout << "vtkOPDMN: done commit group\n";
ospRelease(data);
// ospRelease(instance);
orn->Instances.emplace_back(instance);
this->Instances.emplace_back(instance);
}
// this->GeometricModels.clear();
std::cout << "vtkOPDMN(" << this
<< ")::RenderGeometry added num instances: " << this->Instances.size() << std::endl;
std::cout << "ospPDMN::RenderGeometric Models end\n";
}
//----------------------------------------------------------------------------
void vtkOSPRayPolyDataMapperNode::ClearGeometricModels()
{
std::cout << "vtkOPDMN(" << this << ")::ClearGeometricModels\n";
vtkOSPRayRendererNode* orn =
static_cast<vtkOSPRayRendererNode*>(this->GetFirstAncestorOfType("vtkOSPRayRendererNode"));
RTW::Backend* backend = orn->GetBackend();
for (auto g : this->GeometricModels)
{
// ospRelease(g);
}
std::cout << "num instances: " << this->Instances.size() << std::endl;
for (auto i : this->Instances)
{
// std::cout << "vtkOPDMN::ClearGeometricModels: releasing instance\n";
// ospRelease(i);
}
this->GeometricModels.clear();
this->Instances.clear();
}
......@@ -448,16 +448,21 @@ vtkOSPRayRendererNode::vtkOSPRayRendererNode()
//----------------------------------------------------------------------------
vtkOSPRayRendererNode::~vtkOSPRayRendererNode()
{
std::cout << "vtkORN::delete\n";
if (this->Internal->Backend != nullptr)
{
RTW::Backend* backend = this->Internal->Backend;
if (this->ODummyInstanceData)
ospRelease(this->ODummyInstanceData);
if (this->OWorld)
ospRelease(this->OWorld);
// if (this->ORenderer)
// ospRelease(this->ORenderer);
if (this->ORenderer)
ospRelease(this->ORenderer);
if (this->OFrameBuffer)
ospRelease(this->OFrameBuffer);
if (this->OLightArray)
ospRelease(this->OLightArray);
if (this->OCamera)
ospRelease(this->OCamera);
}
this->AccumulateMatrix->Delete();
delete this->Internal;
......@@ -1083,17 +1088,14 @@ void vtkOSPRayRendererNode::Traverse(int operation)
}
bool enable_cache = true; // turn off to force rebuilds for debugging
if (!this->OWorld || !enable_cache || (recent > this->RenderTime) || (numAct != this->NumActors))
if (!enable_cache || (recent > this->RenderTime) || (numAct != this->NumActors))
{
for (auto i : this->Instances)
{
std::cout << "vtkORN: removing instance " << &(*i) << std::endl;
ospRelease(&(*i));
// ospRelease(&(*i)); // TODO: DEBUG: instance is not freeing unless calling this twice...?
}
this->Instances.clear();
this->NumActors = numAct;
// ospRelease((OSPWorld)this->OWorld);
it->InitTraversal();
while (!it->IsDoneWithTraversal())
{
......@@ -1110,28 +1112,6 @@ void vtkOSPRayRendererNode::Traverse(int operation)
it->GoToNextItem();
}
this->RenderTime = recent;
// if (this->OWorld)
// ospRelease(this->OWorld);
// if (this->OWorld)
// {
// ospRelease(this->OWorld);
// }
// std::cout << "creating new world " << this->OWorld << ", vtkORN: " << this << "\n";
// this->OWorld = ospNewWorld();
// ospCommit(this->OWorld);
// ospCommit(this->OWorld);
// ospSetObject(oRenderer,"model", oWorld);
// ospCommit(oRenderer);
for (auto i : this->Instances)
{
std::cout << "vtkORN: found new instance " << &(*i) << std::endl;
}
}
else
{
// oWorld = (OSPWorld)this->OWorld;
// ospSetObject(oRenderer,"world", oWorld);
// ospCommit(oRenderer);
}
it->Delete();
......@@ -1254,12 +1234,6 @@ void vtkOSPRayRendererNode::Render(bool prepass)
}
else
{
std::cout << "vtkORN: render pass" << std::endl;
// if (this->OWorld)
// ospRelease(this->OWorld);
// this->OWorld = ospNewWorld();
// ospCommit(this->OWorld);
std::cout << "creating new world " << this->OWorld << ", vtkORN: " << this << "\n";
this->OWorld = ospNewWorld();
ospCommit(this->OWorld);
OSPWorld oWorld = this->OWorld;
......@@ -1273,61 +1247,33 @@ void vtkOSPRayRendererNode::Render(bool prepass)
ospSetObject(oWorld, "light", data);
ospRelease(data);
}
std::cout << "vtkORN: create instanceData" << std::endl;
// auto instanceData = ospNewSharedData1D(this->Instances.data(), OSP_INSTANCE,
// this->Instances.size());
auto instanceData =
ospNewCopyData1D(this->Instances.size(), OSP_INSTANCE, this->Instances.data());
ospCommit(instanceData);
// ospSetParam(oWorld, "instance", OSP_DATA, &instanceData);
ospSetObject(oWorld, "instance", instanceData);
std::cout << "vtkORN: create instanceData done" << std::endl;
ospRelease(instanceData);
// ospRelease(instanceData);
// if (this->OInstanceData)
// ospRelease(this->OInstanceData);
this->OInstanceData = instanceData;
}
else // commenting else makes the mem leak dissapear. baffling. something in oworld commit
// likely cause
else
{
// ospray crashes with empty scene, create dummy instance
static OSPData dummyInstanceData = nullptr;
if (!dummyInstanceData)
if (!this->ODummyInstanceData)
{
std::cout << "vtkORN: creating dummy group\n";
OSPGroup group = ospNewGroup();
std::cout << "vtkORN: creating dummy instance\n";
auto instance = ospNewInstance(group);
ospCommit(group);
ospCommit(instance);
std::cout << "vtkORN: setting dummy instance\n";
dummyInstanceData = ospNewCopyData1D(1, OSP_INSTANCE, &instance);
ospCommit(dummyInstanceData);
// auto instanceData = ospNewCopyData1D(1, OSP_INSTANCE, &instance);
ospSetObject(oWorld, "instance", dummyInstanceData);
// this->OInstanceData = dummyInstanceData;
// ospRelease(dummyInstanceData);
// ospRelease(instance);
// ospRelease(group);
std::cout << "vtkORN: done creating dummies\n";
this->ODummyInstanceData = ospNewCopyData1D(1, OSP_INSTANCE, &instance);
ospCommit(this->ODummyInstanceData);
ospSetObject(oWorld, "instance", this->ODummyInstanceData);
}
else
{
if (this->OInstanceData)
{
// ospRelease(this->OInstanceData);
// ospRelease(this->OInstanceData); //TODO: Carson: ospray seems to need 2 defrecs to
// free.
}
ospSetObject(oWorld, "instance", dummyInstanceData);
// this->OInstanceData = dummyInstanceData;
ospSetObject(oWorld, "instance", this->ODummyInstanceData);
}
}
std::cout << "vtkORN: world commit\n";
ospCommit(oWorld);
std::cout << "vtkORN: world committed\n";
OSPRenderer oRenderer = this->ORenderer;
ospCommit(oRenderer);
......@@ -1557,7 +1503,6 @@ void vtkOSPRayRendererNode::Render(bool prepass)
ospSetObject(oRenderer, "map_maxDepth", 0);
}
// Enable VisRTX denoiser
this->AccumulateCount += this->GetSamplesPerPixel(ren);
bool useDenoiser =
this->GetEnableDenoiser(ren) && (this->AccumulateCount >= this->GetDenoiserThreshold(ren));
......@@ -1578,6 +1523,8 @@ void vtkOSPRayRendererNode::Render(bool prepass)
#pragma GCC diagnostic ignored "-Wextra"
ospRenderFrame(this->OFrameBuffer, oRenderer, this->OCamera, this->OWorld);
#pragma GCC diagnostic pop
// release data used to store instances and clear world
if (this->OInstanceData)
{
ospRelease(this->OInstanceData);
......@@ -1585,15 +1532,6 @@ void vtkOSPRayRendererNode::Render(bool prepass)
}
ospRelease(this->OWorld);
this->OWorld = nullptr;
// ospRelease(this->OWorld);
// for(auto i : this->Instances)
// {
// std::cout << "vtkORN: release instance3 " << &(*i) << std::endl;
// ospRelease(i);
// std::cout << "vtkORN: release instance3 done " << &(*i) << std::endl;
// }
// this->Instances.clear();
// Check if backend can do direct OpenGL display using textures
bool useOpenGLInterop = backend->IsSupported(RTW_OPENGL_INTEROP);
......
......@@ -366,6 +366,7 @@ protected:
OSPData OLightArray{ nullptr };
OSPCamera OCamera{ nullptr };
OSPData OInstanceData{ nullptr };
OSPData ODummyInstanceData{ nullptr };
int ImageX, ImageY;
std::vector<OSPLight> Lights;
int NumActors;
......
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