Commit 87dc572c authored by Julien Finet's avatar Julien Finet

Support user bounds to vtkScalarsToColorsItem

By default vtkScalarsToColorsItem uses the bounds defined by the transfer
function range. The user might want to use different bounds.
parent a8f1a022
......@@ -62,9 +62,9 @@ void vtkColorTransferFunctionItem::PrintSelf(ostream &os, vtkIndent indent)
}
//-----------------------------------------------------------------------------
void vtkColorTransferFunctionItem::GetBounds(double* bounds)
void vtkColorTransferFunctionItem::ComputeBounds(double* bounds)
{
this->Superclass::GetBounds(bounds);
this->Superclass::ComputeBounds(bounds);
if (this->ColorTransferFunction)
{
double* range = this->ColorTransferFunction->GetRange();
......
......@@ -31,10 +31,6 @@ public:
vtkTypeMacro(vtkColorTransferFunctionItem, vtkScalarsToColorsItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Reimplemented to return the range of the lookup table
virtual void GetBounds(double bounds[4]);
void SetColorTransferFunction(vtkColorTransferFunction* t);
vtkGetObjectMacro(ColorTransferFunction, vtkColorTransferFunction);
......@@ -42,6 +38,10 @@ protected:
vtkColorTransferFunctionItem();
virtual ~vtkColorTransferFunctionItem();
// Description:
// Reimplemented to return the range of the lookup table
virtual void ComputeBounds(double bounds[4]);
virtual void ComputeTexture();
vtkColorTransferFunction* ColorTransferFunction;
private:
......
......@@ -65,9 +65,9 @@ void vtkCompositeTransferFunctionItem::PrintSelf(ostream &os, vtkIndent indent)
}
//-----------------------------------------------------------------------------
void vtkCompositeTransferFunctionItem::GetBounds(double* bounds)
void vtkCompositeTransferFunctionItem::ComputeBounds(double* bounds)
{
this->Superclass::GetBounds(bounds);
this->Superclass::ComputeBounds(bounds);
if (this->OpacityFunction)
{
double* opacityRange = this->OpacityFunction->GetRange();
......
......@@ -29,10 +29,6 @@ public:
vtkTypeMacro(vtkCompositeTransferFunctionItem, vtkColorTransferFunctionItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Reimplemented to return the range of the piecewise function
virtual void GetBounds(double bounds[4]);
void SetOpacityFunction(vtkPiecewiseFunction* opacity);
vtkGetObjectMacro(OpacityFunction, vtkPiecewiseFunction);
......@@ -40,6 +36,10 @@ protected:
vtkCompositeTransferFunctionItem();
virtual ~vtkCompositeTransferFunctionItem();
// Description:
// Reimplemented to return the range of the piecewise function
virtual void ComputeBounds(double bounds[4]);
virtual void ComputeTexture();
vtkPiecewiseFunction* OpacityFunction;
......
......@@ -87,6 +87,7 @@ void vtkControlPointsItem::PrintSelf(ostream &os, vtkIndent indent)
//-----------------------------------------------------------------------------
void vtkControlPointsItem::GetBounds(double bounds[4])
{
// valid user bounds ? use them
if (this->UserBounds[0] <= this->UserBounds[1] &&
this->UserBounds[2] <= this->UserBounds[3])
{
......@@ -96,8 +97,9 @@ void vtkControlPointsItem::GetBounds(double bounds[4])
bounds[3] = this->UserBounds[3];
return;
}
if (this->Bounds[0] > this->Bounds[1] ||
this->Bounds[2] > this->Bounds[3])
// invalid bounds ? compute them
if (!(this->Bounds[0] <= this->Bounds[1] &&
this->Bounds[2] > this->Bounds[3]))
{
this->ComputeBounds();
}
......@@ -119,17 +121,36 @@ void vtkControlPointsItem::ResetBounds()
//-----------------------------------------------------------------------------
void vtkControlPointsItem::ComputeBounds()
{
this->Bounds[0] = this->Bounds[2] = VTK_DOUBLE_MAX;
this->Bounds[1] = this->Bounds[3] = -VTK_DOUBLE_MAX;
double oldBounds[4];
oldBounds[0] = this->Bounds[0];
oldBounds[1] = this->Bounds[1];
oldBounds[2] = this->Bounds[2];
oldBounds[3] = this->Bounds[3];
this->ComputeBounds(this->Bounds);
if (this->Bounds[0] != oldBounds[0] ||
this->Bounds[1] != oldBounds[1] ||
this->Bounds[2] != oldBounds[2] ||
this->Bounds[3] != oldBounds[3])
{
this->Modified();
}
}
//-----------------------------------------------------------------------------
void vtkControlPointsItem::ComputeBounds( double* bounds)
{
bounds[0] = bounds[2] = VTK_DOUBLE_MAX;
bounds[1] = bounds[3] = -VTK_DOUBLE_MAX;
for (vtkIdType i=0; i < this->GetNumberOfPoints(); ++i)
{
double point[4];
this->GetControlPoint(i, point);
this->Bounds[0] = std::min(this->Bounds[0], point[0]);
this->Bounds[1] = std::max(this->Bounds[1], point[0]);
this->Bounds[2] = std::min(this->Bounds[2], point[1]);
this->Bounds[3] = std::max(this->Bounds[3], point[1]);
this->Modified();
bounds[0] = std::min(bounds[0], point[0]);
bounds[1] = std::max(bounds[1], point[0]);
bounds[2] = std::min(bounds[2], point[1]);
bounds[3] = std::max(bounds[3], point[1]);
}
}
......
......@@ -242,6 +242,7 @@ private:
vtkIdType RemovePointId(vtkIdType pointId);
void ComputeBounds();
void ComputeBounds(double* bounds);
};
#endif
......@@ -60,9 +60,9 @@ void vtkLookupTableItem::PrintSelf(ostream &os, vtkIndent indent)
}
//-----------------------------------------------------------------------------
void vtkLookupTableItem::GetBounds(double* bounds)
void vtkLookupTableItem::ComputeBounds(double* bounds)
{
this->Superclass::GetBounds(bounds);
this->Superclass::ComputeBounds(bounds);
if (this->LookupTable)
{
double* range = this->LookupTable->GetRange();
......
......@@ -30,10 +30,6 @@ public:
vtkTypeMacro(vtkLookupTableItem, vtkScalarsToColorsItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Reimplemented to return the range of the lookup table
virtual void GetBounds(double bounds[4]);
void SetLookupTable(vtkLookupTable* t);
vtkGetObjectMacro(LookupTable, vtkLookupTable);
......@@ -41,6 +37,11 @@ protected:
vtkLookupTableItem();
virtual ~vtkLookupTableItem();
// Description:
// Reimplemented to return the range of the lookup table
virtual void ComputeBounds(double bounds[4]);
virtual void ComputeTexture();
vtkLookupTable* LookupTable;
......
......@@ -64,9 +64,9 @@ void vtkPiecewiseFunctionItem::PrintSelf(ostream &os, vtkIndent indent)
}
//-----------------------------------------------------------------------------
void vtkPiecewiseFunctionItem::GetBounds(double* bounds)
void vtkPiecewiseFunctionItem::ComputeBounds(double* bounds)
{
this->Superclass::GetBounds(bounds);
this->Superclass::ComputeBounds(bounds);
if (this->PiecewiseFunction)
{
double* range = this->PiecewiseFunction->GetRange();
......@@ -74,6 +74,7 @@ void vtkPiecewiseFunctionItem::GetBounds(double* bounds)
bounds[1] = range[1];
}
}
//-----------------------------------------------------------------------------
void vtkPiecewiseFunctionItem::SetPiecewiseFunction(vtkPiecewiseFunction* t)
{
......
......@@ -29,10 +29,6 @@ public:
vtkTypeMacro(vtkPiecewiseFunctionItem, vtkScalarsToColorsItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Reimplemented to return the range of the piecewise function
virtual void GetBounds(double bounds[4]);
void SetPiecewiseFunction(vtkPiecewiseFunction* t);
vtkGetObjectMacro(PiecewiseFunction, vtkPiecewiseFunction);
......@@ -40,6 +36,10 @@ protected:
vtkPiecewiseFunctionItem();
virtual ~vtkPiecewiseFunctionItem();
// Description:
// Reimplemented to return the range of the piecewise function
virtual void ComputeBounds(double bounds[4]);
// Description
// Compute the texture from the PiecewiseFunction
virtual void ComputeTexture();
......
......@@ -84,6 +84,21 @@ void vtkScalarsToColorsItem::PrintSelf(ostream &os, vtkIndent indent)
//-----------------------------------------------------------------------------
void vtkScalarsToColorsItem::GetBounds(double bounds[4])
{
if (this->UserBounds[1] > this->UserBounds[0] &&
this->UserBounds[3] > this->UserBounds[2])
{
bounds[0] = this->UserBounds[0];
bounds[1] = this->UserBounds[1];
bounds[2] = this->UserBounds[2];
bounds[3] = this->UserBounds[3];
return;
}
this->ComputeBounds(bounds);
}
//-----------------------------------------------------------------------------
void vtkScalarsToColorsItem::ComputeBounds(double bounds[4])
{
bounds[0] = 0.;
bounds[1] = 1.;
......
......@@ -40,10 +40,16 @@ public:
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Bounds of the item, by default (0, 1, 0, 1) but it mainly depends on the
// range of the ScalarsToColors function.
// Need to be reimplemented by subclasses if the range is != [0,1]
virtual void GetBounds(double bounds[4]);
// Bounds of the item, use the UserBounds if valid otherwise compute
// the bounds of the item (based on the transfer function range).
void GetBounds(double bounds[4]);
// Description:
// Set custom bounds, except if bounds are invalid, bounds will be
// automatically computed based on the range of the control points
// Invalid bounds by default.
vtkSetVector4Macro(UserBounds, double);
vtkGetVector4Macro(UserBounds, double)
// Description:
// Paint the texture into a rectangle defined by the bounds. If
......@@ -70,6 +76,12 @@ protected:
vtkScalarsToColorsItem();
virtual ~vtkScalarsToColorsItem();
// Description:
// Bounds of the item, by default (0, 1, 0, 1) but it depends on the
// range of the ScalarsToColors function.
// Need to be reimplemented by subclasses if the range is != [0,1]
virtual void ComputeBounds(double* bounds);
// Description:
// Need to be reimplemented by subclasses, ComputeTexture() is called at
// paint time if the texture is not up to date compared to vtkScalarsToColorsItem
......@@ -82,6 +94,8 @@ protected:
virtual void ScalarsToColorsModified(vtkObject* caller, unsigned long eid, void* calldata);
static void OnScalarsToColorsModified(vtkObject* caller, unsigned long eid, void *clientdata, void* calldata);
double UserBounds[4];
vtkImageData* Texture;
bool Interpolate;
vtkPoints2D* Shape;
......
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