Commit 8f2c237f authored by Charles Law's avatar Charles Law
Browse files

Added GetScalarRange to vtkImageCache

parent 37486216
......@@ -190,6 +190,7 @@ public:
// Convenience method to get the range of the scalar data (if there is any
// scalar data). Returns the (min/max) range of combined point and cell data.
// If there are no point or cell scalars the method will return (0,1).
// Note: Update needs to be called to create the scalars.
void GetScalarRange(float range[2]);
float *GetScalarRange();
......
......@@ -528,10 +528,15 @@ void vtkImageCache::UnRegister(vtkObject* o)
}
this->vtkReferenceCount::UnRegister(o);
}
}
//----------------------------------------------------------------------------
float *vtkImageCache::GetScalarRange()
{
static float range[2];
this->GetScalarRange(range);
return range;
}
......
......@@ -185,6 +185,14 @@ public:
void GlobalReleaseDataFlagOff() {this->SetGlobalReleaseDataFlag(0);};
int GetGlobalReleaseDataFlag();
// Description:
// Convenience method to get the range of the scalar data in the
// current "UpdateExtent". Returns the (min/max) range. The components
// are lumped into one range. If there are no scalars the method will
// return (0,1). Note: Update needs to be called first to create the scalars.
virtual void GetScalarRange(float range[2]) = 0;
float *GetScalarRange();
// Description:
// Needed because not all objects are reference counted.
void UnRegister(vtkObject* o);
......
......@@ -182,3 +182,117 @@ vtkImageData *vtkImageSimpleCache::GetData()
return this->CachedData;
}
//----------------------------------------------------------------------------
template <class T>
static void vtkImageSimpleCacheComputeRange(vtkImageData *data, int *ext,
float *range, T *ptr)
{
int idxR, idxY, idxZ;
int maxY, maxZ;
int incX, incY, incZ;
int rowLength;
T r0, r1;
r0 = r1 = *ptr;
// find the region to loop over
rowLength = (ext[1] - ext[0]+1)*data->GetNumberOfScalarComponents();
maxY = ext[3] - ext[2];
maxZ = ext[5] - ext[4];
// Get increments to march through data
data->GetContinuousIncrements(ext, incX, incY, incZ);
// Loop through ouput pixels
for (idxZ = 0; idxZ <= maxZ; idxZ++)
{
for (idxY = 0; idxY <= maxY; idxY++)
{
for (idxR = 0; idxR < rowLength; idxR++)
{
// Pixel operation
if (*ptr < r0)
{
r0 = *ptr;
}
if (*ptr > r1)
{
r1 = *ptr;
}
ptr++;
}
ptr += incY;
}
ptr += incZ;
}
range[0] = (float)r0;
range[1] = (float)r1;
}
//----------------------------------------------------------------------------
void vtkImageSimpleCache::GetScalarRange(float range[2])
{
int ext[6], *dataExt, idx;
void *ptr;
// make sure we have data cached
range[0] = 0.0;
range[1] = 1.0;
if (this->CachedData == NULL)
{
vtkWarningMacro("GetScalarRange: Extent is not in cache");
}
// make sure we have all the data (clip if not).
this->ClipUpdateExtentWithWholeExtent();
this->GetUpdateExtent(ext);
dataExt = this->CachedData->GetExtent();
for (idx = 0; idx < 3; ++idx)
{
if (ext[idx*2] < dataExt[idx*2])
{
vtkWarningMacro("GetScalarRange: All of the extent is not in cache");
ext[idx*2] = dataExt[idx*2];
}
if (ext[idx*2+1] > dataExt[idx*2+1])
{
vtkWarningMacro("GetScalarRange: All of the extent is not in cache");
ext[idx*2+1] = dataExt[idx*2+1];
}
}
// templated compue range function for each type
ptr = this->CachedData->GetScalarPointerForExtent(ext);
switch (this->CachedData->GetScalarType())
{
case VTK_FLOAT:
vtkImageSimpleCacheComputeRange(this->CachedData, ext, range,
(float *) ptr);
break;
case VTK_INT:
vtkImageSimpleCacheComputeRange(this->CachedData, ext, range,
(int *) ptr);
break;
case VTK_SHORT:
vtkImageSimpleCacheComputeRange(this->CachedData, ext, range,
(short *) ptr);
break;
case VTK_UNSIGNED_SHORT:
vtkImageSimpleCacheComputeRange(this->CachedData, ext, range,
(unsigned short *) ptr);
break;
case VTK_UNSIGNED_CHAR:
vtkImageSimpleCacheComputeRange(this->CachedData, ext, range,
(unsigned char *) ptr);
break;
default:
vtkErrorMacro("GetScalarRange: Could not handle scalar type.");
}
}
......@@ -68,7 +68,14 @@ public:
// Law: for vtkImageIterateFilter
vtkImageData *GetData();
// Description:
// Convenience method to get the range of the scalar data in the
// current "UpdateExtent". Returns the (min/max) range. The components
// are lumped into one range. If there are no scalars the method will
// return (0,1). Note: Update needs to be called first to create the scalars.
void GetScalarRange(float range[2]);
protected:
vtkImageData *CachedData;
vtkTimeStamp GenerateTime;
......
......@@ -140,3 +140,115 @@ unsigned long vtkImageStaticCache::GetPipelineMTime()
if (!this->CachedData) return 0;
return this->CachedData->GetMTime();
}
//----------------------------------------------------------------------------
// duplicated code from SimpleCache
template <class T>
static void vtkImageStaticCacheComputeRange(vtkImageData *data, int *ext,
float *range, T *ptr)
{
int idxR, idxY, idxZ;
int maxY, maxZ;
int incX, incY, incZ;
int rowLength;
T r0, r1;
r0 = r1 = *ptr;
// find the region to loop over
rowLength = (ext[1] - ext[0]+1)*data->GetNumberOfScalarComponents();
maxY = ext[3] - ext[2];
maxZ = ext[5] - ext[4];
// Get increments to march through data
data->GetContinuousIncrements(ext, incX, incY, incZ);
// Loop through ouput pixels
for (idxZ = 0; idxZ <= maxZ; idxZ++)
{
for (idxY = 0; idxY <= maxY; idxY++)
{
for (idxR = 0; idxR < rowLength; idxR++)
{
// Pixel operation
if (*ptr < r0)
{
r0 = *ptr;
}
if (*ptr > r1)
{
r1 = *ptr;
}
ptr++;
}
ptr += incY;
}
ptr += incZ;
}
range[0] = (float)r0;
range[1] = (float)r1;
}
//----------------------------------------------------------------------------
void vtkImageStaticCache::GetScalarRange(float range[2])
{
int ext[6], *dataExt, idx;
void *ptr;
// make sure we have data cached
range[0] = 0.0;
range[1] = 1.0;
if (this->CachedData == NULL)
{
vtkWarningMacro("GetScalarRange: Extent is not in cache");
}
// make sure we have all the data (clip if not).
this->ClipUpdateExtentWithWholeExtent();
this->GetUpdateExtent(ext);
dataExt = this->CachedData->GetExtent();
for (idx = 0; idx < 3; ++idx)
{
if (ext[idx*2] < dataExt[idx*2])
{
vtkWarningMacro("GetScalarRange: All of the extent is not in cache");
ext[idx*2] = dataExt[idx*2];
}
if (ext[idx*2+1] > dataExt[idx*2+1])
{
vtkWarningMacro("GetScalarRange: All of the extent is not in cache");
ext[idx*2+1] = dataExt[idx*2+1];
}
}
// templated compue range function for each type
ptr = this->CachedData->GetScalarPointerForExtent(ext);
switch (this->CachedData->GetScalarType())
{
case VTK_FLOAT:
vtkImageStaticCacheComputeRange(this->CachedData, ext, range,
(float *) ptr);
break;
case VTK_INT:
vtkImageStaticCacheComputeRange(this->CachedData, ext, range,
(int *) ptr);
break;
case VTK_SHORT:
vtkImageStaticCacheComputeRange(this->CachedData, ext, range,
(short *) ptr);
break;
case VTK_UNSIGNED_SHORT:
vtkImageStaticCacheComputeRange(this->CachedData, ext, range,
(unsigned short *) ptr);
break;
case VTK_UNSIGNED_CHAR:
vtkImageStaticCacheComputeRange(this->CachedData, ext, range,
(unsigned char *) ptr);
break;
default:
vtkErrorMacro("GetScalarRange: Could not handle scalar type.");
}
}
......@@ -68,6 +68,13 @@ public:
// Description:
// Set the vtkImageData for this cache to cache.
vtkSetObjectMacro(CachedData, vtkImageData);
// Description:
// Convenience method to get the range of the scalar data in the
// current "UpdateExtent". Returns the (min/max) range. The components
// are lumped into one range. If there are no scalars the method will
// return (0,1). Note: Update needs to be called first to create the scalars.
void GetScalarRange(float range[2]);
protected:
vtkImageData *CachedData;
......
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