Commit 40ec94e5 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri

Interactively adjust sample distance for vtkSmartVolumeMapper

Added new flag called InteractiveAdjustSampleDistances that
essentially controls whether the internal volume mappers compute
or use a set sample distance. The decision is based on whether
the render is interactive or still depending on the difference
between the DesiredUpdateRate of the vtkRenderWindow and the
InteractiveUpdateRate of the vtkSmartVolumeMapper
parent 1013a56f
......@@ -55,6 +55,9 @@ vtkSmartVolumeMapper::vtkSmartVolumeMapper()
// If the render window has a desired update rate of at least 1 frame
// per second or more, we'll consider this interactive
this->InteractiveUpdateRate = 1.0;
// Enable checking whether the render is interactive and use the appropriate
// sample distance for rendering
this->InteractiveAdjustSampleDistances = 1;
// Initial sample distance
this->AutoAdjustSampleDistances = 1;
......@@ -165,6 +168,17 @@ void vtkSmartVolumeMapper::Render( vtkRenderer *ren, vtkVolume *vol )
switch ( this->CurrentRenderMode )
{
case vtkSmartVolumeMapper::RayCastRenderMode:
if (this->InteractiveAdjustSampleDistances)
{
this->RayCastMapper->SetAutoAdjustSampleDistances(
ren->GetRenderWindow()->GetDesiredUpdateRate()>=
this->InteractiveUpdateRate);
}
else
{
this->RayCastMapper->SetAutoAdjustSampleDistances(
this->AutoAdjustSampleDistances);
}
this->RayCastMapper->Render(ren,vol);
break;
case vtkSmartVolumeMapper::GPURenderMode:
......@@ -176,6 +190,17 @@ void vtkSmartVolumeMapper::Render( vtkRenderer *ren, vtkVolume *vol )
{
usedMapper=this->GPUMapper;
}
if (this->InteractiveAdjustSampleDistances)
{
usedMapper->SetAutoAdjustSampleDistances(
ren->GetRenderWindow()->GetDesiredUpdateRate()>=
this->InteractiveUpdateRate);
}
else
{
usedMapper->SetAutoAdjustSampleDistances(
this->AutoAdjustSampleDistances);
}
usedMapper->Render(ren, vol);
break;
case vtkSmartVolumeMapper::InvalidRenderMode:
......@@ -363,8 +388,6 @@ void vtkSmartVolumeMapper::ComputeRenderMode(vtkRenderer *ren, vtkVolume *vol)
this->RayCastMapper->SetBlendMode( this->GetBlendMode() );
this->RayCastMapper->SetFinalColorWindow(this->FinalColorWindow);
this->RayCastMapper->SetFinalColorLevel(this->FinalColorLevel);
this->RayCastMapper->SetAutoAdjustSampleDistances(
this->AutoAdjustSampleDistances);
this->RayCastMapper->SetSampleDistance(this->SampleDistance);
break;
......@@ -391,8 +414,6 @@ void vtkSmartVolumeMapper::ComputeRenderMode(vtkRenderer *ren, vtkVolume *vol)
this->GPUMapper->SetBlendMode( this->GetBlendMode() );
this->GPUMapper->SetFinalColorWindow(this->FinalColorWindow);
this->GPUMapper->SetFinalColorLevel(this->FinalColorLevel);
this->GPUMapper->SetAutoAdjustSampleDistances(
this->AutoAdjustSampleDistances);
this->GPUMapper->SetSampleDistance(this->SampleDistance);
// Make the window current because we need the OpenGL context
......@@ -428,8 +449,6 @@ void vtkSmartVolumeMapper::ComputeRenderMode(vtkRenderer *ren, vtkVolume *vol)
this->GPULowResMapper->SetBlendMode( this->GetBlendMode() );
this->GPULowResMapper->SetFinalColorWindow(this->FinalColorWindow);
this->GPULowResMapper->SetFinalColorLevel(this->FinalColorLevel);
this->GPULowResMapper->SetAutoAdjustSampleDistances(
this->AutoAdjustSampleDistances);
this->GPULowResMapper->SetSampleDistance(this->SampleDistance);
}
else
......@@ -636,6 +655,8 @@ void vtkSmartVolumeMapper::PrintSelf(ostream& os, vtkIndent indent)
os << "FinalColorLevel: " << this->FinalColorLevel << endl;
os << "RequestedRenderMode: " << this->RequestedRenderMode << endl;
os << "InteractiveUpdateRate: " << this->InteractiveUpdateRate << endl;
os << "InteractiveAdjustSampleDistances: " <<
this->InteractiveAdjustSampleDistances << endl;
os << "InterpolationMode: " << this->InterpolationMode << endl;
os << "MaxMemoryInBytes:" << this->MaxMemoryInBytes << endl;
os << "MaxMemoryFraction:" << this->MaxMemoryFraction << endl;
......
......@@ -214,10 +214,26 @@ public:
vtkGetMacro( InteractiveUpdateRate, double );
// Description:
// If AutoAdjustSampleDistances is on, the the ImageSampleDistance
// If the InteractiveAdjustSampleDistances flag is enabled,
// vtkSmartVolumeMapper interactively sets and resets the
// AutoAdjustSampleDistances flag on the internal volume mapper. This flag
// along with InteractiveUpdateRate is useful to adjust volume mapper sample
// distance based on whether the render is interactive or still.
// Note that, if this flag is enabled,
// vtkSmartVolumeMapper::AutoAdjustSampleDistances flag is ignored.
// By default, InteractiveAdjustSampleDistances is enabled.
vtkSetClampMacro( InteractiveAdjustSampleDistances, int, 0, 1);
vtkGetMacro( InteractiveAdjustSampleDistances, int);
vtkBooleanMacro( InteractiveAdjustSampleDistances, int);
// Description:
// If AutoAdjustSampleDistances is on, the ImageSampleDistance
// will be varied to achieve the allocated render time of this
// prop (controlled by the desired update rate and any culling in
// use).
// Note that, this flag is ignored when InteractiveAdjustSampleDistances is
// enabled. To explicitly set and use this flag, one must disable
// InteractiveAdjustSampleDistances.
vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
vtkGetMacro( AutoAdjustSampleDistances, int );
vtkBooleanMacro( AutoAdjustSampleDistances, int );
......@@ -313,6 +329,9 @@ protected:
// The distance between sample points along the ray
float SampleDistance;
// Set whether or not the sample distance should be automatically calculated
// within the internal volume mapper
int AutoAdjustSampleDistances;
// If the DesiredUpdateRate of the vtkRenderWindow causing the Render is at
......@@ -320,6 +339,15 @@ protected:
// considered still.
double InteractiveUpdateRate;
// If the InteractiveAdjustSampleDistances flag is enabled,
// vtkSmartVolumeMapper interactively sets and resets the
// AutoAdjustSampleDistances flag on the internal volume mapper. This flag
// along with InteractiveUpdateRate is useful to adjust volume mapper sample
// distance based on whether the render is interactive or still.
// Note that, if this flag is enabled,
// vtkSmartVolumeMapper::AutoAdjustSampleDistances flag is ignored.
int InteractiveAdjustSampleDistances;
private:
vtkSmartVolumeMapper(const vtkSmartVolumeMapper&); // Not implemented.
void operator=(const vtkSmartVolumeMapper&); // Not implemented.
......
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