13 #ifndef QmitkPiecewiseFunctionCanvas_h
14 #define QmitkPiecewiseFunctionCanvas_h
19 #include <vtkPiecewiseFunction.h>
58 int GetNearHandle(
int x,
int y,
unsigned int maxSquaredDistance = 100)
override;
66 this->m_PiecewiseFunction = piecewiseFunction;
67 this->
SetMin(m_PiecewiseFunction->GetRange()[0]);
68 this->
SetMax(m_PiecewiseFunction->GetRange()[1]);
80 int AddFunctionPoint(
double x,
double val)
override {
return m_PiecewiseFunction->AddPoint(x, val); }
89 m_PiecewiseFunction->RemovePoint(x);
92 std::cout <<
"old/new size" << old_size <<
"/" <<
GetFunctionSize() << std::endl;
93 std::cout <<
"called with x=" << x << std::endl;
102 double GetFunctionX(
int index)
override {
return m_PiecewiseFunction->GetDataPointer()[index * 2]; }
111 return m_PiecewiseFunction->GetValue(m_PiecewiseFunction->GetDataPointer()[index * 2]);
149 if ((m_PiecewiseFunction->GetRange()[0]) < 0)
151 range = (m_PiecewiseFunction->GetRange()[1]) - (m_PiecewiseFunction->GetRange()[0]);
156 range = m_PiecewiseFunction->GetRange()[1];
164 m_PiecewiseFunction->AddSegment(this->GetFunctionMin(), 0, this->GetFunctionMax(), 1);
165 m_PiecewiseFunction->AddPoint(0.0, 0.0);
171 m_PiecewiseFunction->AddSegment(this->GetFunctionMin(), 0, 0, 1);
172 m_PiecewiseFunction->AddSegment(0, 1, ((this->GetFunctionRange()) * 0.125), 1);
173 m_PiecewiseFunction->AddSegment(((this->GetFunctionRange()) * 0.125), 1, ((this->GetFunctionRange()) * 0.2), 1);
174 m_PiecewiseFunction->AddSegment(((this->GetFunctionRange()) * 0.2), 1, ((this->GetFunctionRange()) * 0.25), 1);
Canvas widget for editing a vtkPiecewiseFunction (opacity transfer function).
void SetTitle(const QString &title)
Set the title text displayed on the canvas.
void DoubleClickOnHandle(int) override
No-op for piecewise functions (double-click does not change values).
int GetFunctionSize() override
Get the number of points in the piecewise function.
double GetFunctionY(int index) override
Get the y (opacity) value of a function point by index.
double GetFunctionMax()
Get the maximum scalar value of the function range.
QmitkPiecewiseFunctionCanvas(QWidget *parent=nullptr, Qt::WindowFlags f={})
Construct the piecewise function canvas.
vtkPiecewiseFunction * m_PiecewiseFunction
int GetNearHandle(int x, int y, unsigned int maxSquaredDistance=100) override
Find a handle near the given canvas position.
void RemoveFunctionPoint(double x) override
Remove the function point at position x.
void SetPiecewiseFunction(vtkPiecewiseFunction *piecewiseFunction)
Set the vtkPiecewiseFunction to edit.
double GetFunctionRange()
Get the span of the function range.
void RemoveAllFunctionPoints()
Reset the function to a default ramp from 0 to 1 with a zero-point at origin.
double GetFunctionX(int index) override
Get the x (scalar) value of a function point by index.
void MoveFunctionPoint(int index, std::pair< double, double > pos) override
Move a function point to a new position.
void paintEvent(QPaintEvent *e) override
Paint the histogram, function lines, handles, title, and range labels.
int AddFunctionPoint(double x, double val) override
Add a function point at position (x, val).
double GetFunctionMin()
Get the minimum scalar value of the function range.
void ResetGO()
Reset the function to a default gradient opacity configuration.
Abstract base class for transfer function editing canvases.
void SetMin(double min)
Set the minimum scalar value and update the lower display bound.
virtual int GetFunctionSize()=0
Get the number of function points.
void SetMax(double max)
Set the maximum scalar value and update the upper display bound.