Commit 65c678fb authored by Francois Bertel's avatar Francois Bertel
Browse files

ENH:In vtkDataSet, fixed the logic of the scalar range computation to match...

ENH:In vtkDataSet, fixed the logic of the scalar range computation to match the one of the bounding box computation (added ComputeScalarRange and ScalarRangeComputeTime).
BUG:In vtkUniformGrid, fixed scalar range computation. It was always performing the computation without caching the result.
ENH:In vtkHierarchicalBoxDataSet, added GetScalarRange, ComputeScalarRange and ScalarRangeComputeTime.
parent 2f8c7b26
......@@ -28,7 +28,7 @@
#include <math.h>
vtkCxxRevisionMacro(vtkDataSet, "1.10");
vtkCxxRevisionMacro(vtkDataSet, "1.11");
//----------------------------------------------------------------------------
// Constructor with default bounds (0,1, 0,1, 0,1).
......@@ -101,39 +101,54 @@ void vtkDataSet::ComputeBounds()
}
//----------------------------------------------------------------------------
void vtkDataSet::GetScalarRange(double range[2])
// Description:
// Compute the range of the scalars and cache it into ScalarRange
// only if the cache became invalid (ScalarRangeComputeTime).
void vtkDataSet::ComputeScalarRange()
{
vtkDataArray *ptScalars, *cellScalars;
ptScalars = this->PointData->GetScalars();
cellScalars = this->CellData->GetScalars();
if ( ptScalars && cellScalars)
{
double r1[2], r2[2];
ptScalars->GetRange(r1,0);
cellScalars->GetRange(r2,0);
range[0] = (r1[0] < r2[0] ? r1[0] : r2[0]);
range[1] = (r1[1] > r2[1] ? r1[1] : r2[1]);
}
else if ( ptScalars )
{
ptScalars->GetRange(range,0);
}
else if ( cellScalars )
{
cellScalars->GetRange(range,0);
}
else
if ( this->GetMTime() > this->ScalarRangeComputeTime )
{
range[0] = 0.0;
range[1] = 1.0;
vtkDataArray *ptScalars, *cellScalars;
ptScalars = this->PointData->GetScalars();
cellScalars = this->CellData->GetScalars();
if ( ptScalars && cellScalars)
{
double r1[2], r2[2];
ptScalars->GetRange(r1,0);
cellScalars->GetRange(r2,0);
this->ScalarRange[0] = (r1[0] < r2[0] ? r1[0] : r2[0]);
this->ScalarRange[1] = (r1[1] > r2[1] ? r1[1] : r2[1]);
}
else if ( ptScalars )
{
ptScalars->GetRange(this->ScalarRange,0);
}
else if ( cellScalars )
{
cellScalars->GetRange(this->ScalarRange,0);
}
else
{
this->ScalarRange[0] = 0.0;
this->ScalarRange[1] = 1.0;
}
this->ScalarRangeComputeTime.Modified();
}
}
//----------------------------------------------------------------------------
void vtkDataSet::GetScalarRange(double range[2])
{
this->ComputeScalarRange();
range[0]=this->ScalarRange[0];
range[1]=this->ScalarRange[1];
}
//----------------------------------------------------------------------------
double *vtkDataSet::GetScalarRange()
{
this->GetScalarRange(this->ScalarRange);
this->ComputeScalarRange();
return this->ScalarRange;
}
......@@ -340,9 +355,11 @@ void vtkDataSet::InternalDataSetCopy(vtkDataSet *src)
{
int idx;
this->ComputeTime = src->ComputeTime;
this->ScalarRangeComputeTime = src->ScalarRangeComputeTime;
this->ScalarRange[0] = src->ScalarRange[0];
this->ScalarRange[1] = src->ScalarRange[1];
this->ComputeTime = src->ComputeTime;
for (idx = 0; idx < 3; ++idx)
{
this->Bounds[2*idx] = src->Bounds[2*idx];
......
......@@ -329,13 +329,23 @@ protected:
vtkDataSet();
~vtkDataSet();
// Description:
// Compute the range of the scalars and cache it into ScalarRange
// only if the cache became invalid (ScalarRangeComputeTime).
virtual void ComputeScalarRange();
vtkCellData *CellData; // Scalars, vectors, etc. associated w/ each cell
vtkPointData *PointData; // Scalars, vectors, etc. associated w/ each point
vtkTimeStamp ComputeTime; // Time at which bounds, center, etc. computed
double Bounds[6]; // (xmin,xmax, ymin,ymax, zmin,zmax) geometric bounds
double ScalarRange[2];
double Center[3];
// Cached scalar range
double ScalarRange[2];
// Time at which scalar range is computed
vtkTimeStamp ScalarRangeComputeTime;
private:
void InternalDataSetCopy(vtkDataSet *src);
//BTX
......
......@@ -26,7 +26,7 @@
#include "vtkUniformGrid.h"
#include "vtkUnsignedCharArray.h"
vtkCxxRevisionMacro(vtkHierarchicalBoxDataSet, "1.15");
vtkCxxRevisionMacro(vtkHierarchicalBoxDataSet, "1.16");
vtkStandardNewMacro(vtkHierarchicalBoxDataSet);
vtkInformationKeyMacro(vtkHierarchicalBoxDataSet,BOX,IntegerVector);
......@@ -37,6 +37,8 @@ typedef vtkstd::vector<vtkAMRBox> vtkAMRBoxList;
vtkHierarchicalBoxDataSet::vtkHierarchicalBoxDataSet()
{
this->BoxInternal = new vtkHierarchicalBoxDataSetInternal;
this->ScalarRange[0]=VTK_DOUBLE_MAX;
this->ScalarRange[0]=VTK_DOUBLE_MIN;
}
//----------------------------------------------------------------------------
......@@ -385,3 +387,60 @@ vtkHierarchicalBoxDataSet* vtkHierarchicalBoxDataSet::GetData(
{
return vtkHierarchicalBoxDataSet::GetData(v->GetInformationObject(i));
}
//----------------------------------------------------------------------------
// Description:
// Copy the cached scalar range into range.
void vtkHierarchicalBoxDataSet::GetScalarRange(double range[2])
{
this->ComputeScalarRange();
range[0]=this->ScalarRange[0];
range[1]=this->ScalarRange[1];
}
//----------------------------------------------------------------------------
// Description:
// Return the cached range.
double *vtkHierarchicalBoxDataSet::GetScalarRange()
{
this->ComputeScalarRange();
return this->ScalarRange;
}
//----------------------------------------------------------------------------
// Description:
// Compute the range of the scalars and cache it into ScalarRange
// only if the cache became invalid (ScalarRangeComputeTime).
void vtkHierarchicalBoxDataSet::ComputeScalarRange()
{
if ( this->GetMTime() > this->ScalarRangeComputeTime )
{
double dataSetRange[2];
this->ScalarRange[0]=VTK_DOUBLE_MAX;
this->ScalarRange[1]=VTK_DOUBLE_MIN;
unsigned int level=0;
unsigned int levels=this->GetNumberOfLevels();
while(level<levels)
{
unsigned int dataset=0;
unsigned int datasets=this->GetNumberOfDataSets(level);
while(dataset<datasets)
{
vtkUniformGrid *ug;
ug=static_cast<vtkUniformGrid *>(this->GetDataSet(level,dataset));
ug->GetScalarRange(dataSetRange);
if(dataSetRange[0]<this->ScalarRange[0])
{
this->ScalarRange[0]=dataSetRange[0];
}
if(dataSetRange[1]>this->ScalarRange[1])
{
this->ScalarRange[1]=dataSetRange[1];
}
++dataset;
}
++level;
}
this->ScalarRangeComputeTime.Modified();
}
}
......@@ -121,11 +121,29 @@ public:
static vtkHierarchicalBoxDataSet* GetData(vtkInformationVector* v, int i=0);
//ETX
// Description:
// Copy the cached scalar range into range.
virtual void GetScalarRange(double range[2]);
// Description:
// Return the cached range.
virtual double *GetScalarRange();
protected:
vtkHierarchicalBoxDataSet();
~vtkHierarchicalBoxDataSet();
// Description:
// Compute the range of the scalars and cache it into ScalarRange
// only if the cache became invalid (ScalarRangeComputeTime).
virtual void ComputeScalarRange();
vtkHierarchicalBoxDataSetInternal* BoxInternal;
// Cached scalar range
double ScalarRange[2];
// Time at which scalar range is computed
vtkTimeStamp ScalarRangeComputeTime;
private:
vtkHierarchicalBoxDataSet(const vtkHierarchicalBoxDataSet&); // Not implemented.
......
......@@ -31,7 +31,7 @@
#include "vtkVertex.h"
#include "vtkVoxel.h"
vtkCxxRevisionMacro(vtkUniformGrid, "1.13");
vtkCxxRevisionMacro(vtkUniformGrid, "1.14");
vtkStandardNewMacro(vtkUniformGrid);
vtkCxxSetObjectMacro(vtkUniformGrid, PointVisibility,
......@@ -596,63 +596,65 @@ void vtkUniformGrid::DeepCopy(vtkDataObject *dataObject)
//----------------------------------------------------------------------------
// Override this method because of blanking
void vtkUniformGrid::GetScalarRange(double range[2])
void vtkUniformGrid::ComputeScalarRange()
{
vtkDataArray *ptScalars = this->PointData->GetScalars();
vtkDataArray *cellScalars = this->CellData->GetScalars();
double ptRange[2];
double cellRange[2];
double s;
int id, num;
ptRange[0] = VTK_DOUBLE_MAX;
ptRange[1] = -VTK_DOUBLE_MAX;
if ( ptScalars )
if ( this->GetMTime() > this->ScalarRangeComputeTime )
{
num = this->GetNumberOfPoints();
for (id=0; id < num; id++)
vtkDataArray *ptScalars = this->PointData->GetScalars();
vtkDataArray *cellScalars = this->CellData->GetScalars();
double ptRange[2];
double cellRange[2];
double s;
int id, num;
ptRange[0] = VTK_DOUBLE_MAX;
ptRange[1] = VTK_DOUBLE_MIN;
if ( ptScalars )
{
if ( this->IsPointVisible(id) )
num = this->GetNumberOfPoints();
for (id=0; id < num; id++)
{
s = ptScalars->GetComponent(id,0);
if ( s < ptRange[0] )
if ( this->IsPointVisible(id) )
{
ptRange[0] = s;
}
if ( s > ptRange[1] )
{
ptRange[1] = s;
s = ptScalars->GetComponent(id,0);
if ( s < ptRange[0] )
{
ptRange[0] = s;
}
if ( s > ptRange[1] )
{
ptRange[1] = s;
}
}
}
}
}
cellRange[0] = ptRange[0];
cellRange[1] = ptRange[1];
if ( cellScalars )
{
num = this->GetNumberOfCells();
for (id=0; id < num; id++)
cellRange[0] = ptRange[0];
cellRange[1] = ptRange[1];
if ( cellScalars )
{
if ( this->IsCellVisible(id) )
num = this->GetNumberOfCells();
for (id=0; id < num; id++)
{
s = cellScalars->GetComponent(id,0);
if ( s < cellRange[0] )
if ( this->IsCellVisible(id) )
{
cellRange[0] = s;
}
if ( s > cellRange[1] )
{
cellRange[1] = s;
s = cellScalars->GetComponent(id,0);
if ( s < cellRange[0] )
{
cellRange[0] = s;
}
if ( s > cellRange[1] )
{
cellRange[1] = s;
}
}
}
}
this->ScalarRange[0] = (cellRange[0] >= VTK_DOUBLE_MAX ? 0.0 : cellRange[0]);
this->ScalarRange[1] = (cellRange[1] <= VTK_DOUBLE_MIN ? 1.0 : cellRange[1]);
this->ScalarRangeComputeTime.Modified();
}
range[0] = (cellRange[0] >= VTK_DOUBLE_MAX ? 0.0 : cellRange[0]);
range[1] = (cellRange[1] <= -VTK_DOUBLE_MAX ? 1.0 : cellRange[1]);
this->ComputeTime.Modified();
}
//----------------------------------------------------------------------------
......
......@@ -66,7 +66,6 @@ public:
{vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());}
virtual void Initialize();
virtual int GetMaxCellSize() {return 8;}; //voxel is the largest
virtual void GetScalarRange(double range[2]);
// Description:
// Shallow and Deep copy.
......@@ -143,7 +142,11 @@ public:
protected:
vtkUniformGrid();
~vtkUniformGrid();
// Description:
// Override this method because of blanking.
virtual void ComputeScalarRange();
vtkStructuredVisibilityConstraint* PointVisibility;
void SetPointVisibility(vtkStructuredVisibilityConstraint *pointVisibility);
......
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