Commit a2ddcbf6 authored by David E. DeMarle's avatar David E. DeMarle
Browse files

fleshing out caching

now reuses ospgeom when it can and respects visibility
does not yet comply with temporal cache
parent 1123dd0e
......@@ -17,6 +17,7 @@
#include "vtkInformation.h"
#include "vtkMolecule.h"
#include "vtkMoleculeMapper.h"
#include "vtkOSPRayActorNode.h"
#include "vtkOSPRayCache.h"
#include "vtkOSPRayRendererNode.h"
#include "vtkObjectFactory.h"
......@@ -32,14 +33,21 @@ vtkStandardNewMacro(vtkOSPRayMoleculeMapperNode);
//----------------------------------------------------------------------------
vtkOSPRayMoleculeMapperNode::vtkOSPRayMoleculeMapperNode()
{
cerr << "CREATE OSPMOLMAPPERNODE " << this << endl;
this->OSPMesh = nullptr;
}
//----------------------------------------------------------------------------
vtkOSPRayMoleculeMapperNode::~vtkOSPRayMoleculeMapperNode()
{
cerr << "DESTROY OSPMOLMAPPERNODE " << this << endl;
vtkOSPRayRendererNode* orn = vtkOSPRayRendererNode::GetRendererNode(this);
if (orn)
{
RTW::Backend* backend = orn->GetBackend();
if (backend != nullptr)
{
ospRelease(this->OSPMesh);
}
}
delete this->Cache;
}
......@@ -52,57 +60,53 @@ void vtkOSPRayMoleculeMapperNode::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkOSPRayMoleculeMapperNode::Render(bool prepass)
{
if (prepass)
if (!prepass)
{
vtkOSPRayRendererNode* orn =
static_cast<vtkOSPRayRendererNode*>(this->GetFirstAncestorOfType("vtkOSPRayRendererNode"));
RTW::Backend* backend = orn->GetBackend();
if (backend == nullptr)
{
return;
}
return;
}
else
vtkOSPRayActorNode* aNode = vtkOSPRayActorNode::SafeDownCast(this->Parent);
vtkActor* act = vtkActor::SafeDownCast(aNode->GetRenderable());
if (act->GetVisibility() == false)
{
vtkOSPRayRendererNode* orn =
static_cast<vtkOSPRayRendererNode*>(this->GetFirstAncestorOfType("vtkOSPRayRendererNode"));
RTW::Backend* backend = orn->GetBackend();
if (backend == nullptr)
{
return;
}
auto oModel = orn->GetOModel();
return;
}
vtkOSPRayRendererNode* orn =
static_cast<vtkOSPRayRendererNode*>(this->GetFirstAncestorOfType("vtkOSPRayRendererNode"));
RTW::Backend* backend = orn->GetBackend();
if (backend == nullptr)
{
return;
}
vtkMoleculeMapper* mapper = vtkMoleculeMapper::SafeDownCast(this->GetRenderable());
vtkMolecule* molecule = mapper->GetInput();
auto oModel = orn->GetOModel();
vtkMoleculeMapper* mapper = vtkMoleculeMapper::SafeDownCast(this->GetRenderable());
vtkMolecule* molecule = mapper->GetInput();
if (mapper->GetMTime() > this->BuildTime || molecule->GetMTime() > this->BuildTime)
{
ospRelease(this->OSPMesh);
if (mapper->GetRenderAtoms())
{
std::vector<double> _vertices;
vtkPoints* allPoints = molecule->GetAtomicPositionArray();
for (vtkIdType i = 0; i < molecule->GetNumberOfAtoms(); i++)
{
_vertices.push_back(allPoints->GetPoint(i)[0]);
_vertices.push_back(allPoints->GetPoint(i)[1]);
_vertices.push_back(allPoints->GetPoint(i)[2]);
}
osp::vec3f* vertices = new osp::vec3f[molecule->GetNumberOfAtoms()];
for (size_t i = 0; i < molecule->GetNumberOfAtoms(); i++)
{
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]) };
vertices[i] = osp::vec3f{ static_cast<float>(allPoints->GetPoint(i)[0]),
static_cast<float>(allPoints->GetPoint(i)[1]),
static_cast<float>(allPoints->GetPoint(i)[2]) };
}
OSPData position = ospNewData(molecule->GetNumberOfAtoms(), OSP_FLOAT3, &vertices[0]);
ospCommit(position);
_vertices.clear();
OSPGeometry ospMesh = ospNewGeometry("spheres");
ospSetObject(ospMesh, "spheres", position);
ospSet1i(ospMesh, "bytes_per_sphere", 3 * sizeof(float));
ospSet1i(ospMesh, "offset_center", 0 * sizeof(float));
ospSet1f(ospMesh, "radius", 1.0);
ospCommit(ospMesh);
this->OSPMesh = ospNewGeometry("spheres");
ospSetObject(this->OSPMesh, "spheres", position);
ospSet1i(this->OSPMesh, "bytes_per_sphere", 3 * sizeof(float));
ospSet1i(this->OSPMesh, "offset_center", 0 * sizeof(float));
ospSet1f(this->OSPMesh, "radius", 1.0);
ospCommit(this->OSPMesh);
ospRelease(position);
ospAddGeometry(oModel, ospMesh);
}
OSPModel OSPRayModel = orn->GetOModel();
this->BuildTime.Modified();
}
ospAddGeometry(oModel, this->OSPMesh);
}
......@@ -45,6 +45,8 @@ protected:
~vtkOSPRayMoleculeMapperNode() override;
vtkOSPRayCache<vtkOSPRayCacheItemObject>* Cache;
OSPGeometry OSPMesh;
vtkTimeStamp BuildTime;
private:
vtkOSPRayMoleculeMapperNode(const vtkOSPRayMoleculeMapperNode&) = delete;
......
Supports Markdown
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