Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QMITKPIECEWISEFUNCTIONCANVAS_H_INCLUDED
00019 #define QMITKPIECEWISEFUNCTIONCANVAS_H_INCLUDED
00020
00021 #include "QmitkTransferFunctionCanvas.h"
00022 #include "QmitkExtExports.h"
00023
00024 #include <vtkPiecewiseFunction.h>
00025
00026 class QmitkExt_EXPORT QmitkPiecewiseFunctionCanvas: public QmitkTransferFunctionCanvas
00027 {
00028 Q_OBJECT
00029
00030 public:
00031
00032 QmitkPiecewiseFunctionCanvas( QWidget * parent=0, Qt::WindowFlags f = 0 );
00033 virtual void paintEvent( QPaintEvent* e );
00034 void SetTitle(std::string title);
00035 int GetNearHandle(int x,int y,unsigned int maxSquaredDistance = 32);
00036
00037 void SetPiecewiseFunction(vtkPiecewiseFunction* piecewiseFunction)
00038 {
00039 this->m_PiecewiseFunction = piecewiseFunction;
00040 this->SetMin(m_PiecewiseFunction->GetRange()[0]);
00041 this->SetMax(m_PiecewiseFunction->GetRange()[1]);
00042 setEnabled(true);
00043
00044 update();
00045
00046 };
00047
00048 void AddFunctionPoint(vtkFloatingPointType x,vtkFloatingPointType val)
00049 {
00050 m_PiecewiseFunction->AddPoint(x,val);
00051 };
00052
00053 void RemoveFunctionPoint(vtkFloatingPointType x)
00054 {
00055 int old_size = GetFunctionSize();
00056 m_PiecewiseFunction->RemovePoint(x);
00057 if (GetFunctionSize() + 1 != old_size)
00058 {
00059 std::cout << "old/new size" << old_size << "/" << GetFunctionSize() << std::endl;
00060 std::cout << "called with x=" << x << std::endl;
00061 }
00062 };
00063
00064 vtkFloatingPointType GetFunctionX(int index)
00065 {
00066 return m_PiecewiseFunction->GetDataPointer()[index*2];
00067 }
00068
00069 float GetFunctionY(int index)
00070 {
00071 return m_PiecewiseFunction->GetValue(m_PiecewiseFunction->GetDataPointer()[index*2]);
00072 }
00073
00074 int GetFunctionSize()
00075 {
00076 return m_PiecewiseFunction->GetSize();
00077 }
00078
00079 void DoubleClickOnHandle(int )
00080 {};
00081 void MoveFunctionPoint(int index, std::pair<vtkFloatingPointType,vtkFloatingPointType> pos);
00082
00083 double GetFunctionMax()
00084 {
00085 return m_PiecewiseFunction->GetRange()[1];
00086 }
00087
00088 double GetFunctionMin()
00089 {
00090 return m_PiecewiseFunction->GetRange()[0];
00091 }
00092
00093 double GetFunctionRange()
00094 {
00095 double range;
00096 if((m_PiecewiseFunction->GetRange()[0])<0)
00097 {
00098 range = (m_PiecewiseFunction->GetRange()[1])-(m_PiecewiseFunction->GetRange()[0]);
00099 return range;
00100 }
00101 else
00102 {
00103 range = m_PiecewiseFunction->GetRange()[1];
00104 return range;
00105 }
00106 }
00107
00108 void RemoveAllFunctionPoints()
00109 {
00110 m_PiecewiseFunction->AddSegment(this->GetFunctionMin(),0,this->GetFunctionMax(),1);
00111 m_PiecewiseFunction->AddPoint(0.0,0.0);
00112 }
00113
00114 void ResetGO()
00115 {
00116 m_PiecewiseFunction->AddSegment(this->GetFunctionMin(),0,0,1);
00117 m_PiecewiseFunction->AddSegment(0,1,((this->GetFunctionRange())*0.125),1);
00118 m_PiecewiseFunction->AddSegment(((this->GetFunctionRange())*0.125),1,((this->GetFunctionRange())*0.2),1);
00119 m_PiecewiseFunction->AddSegment(((this->GetFunctionRange())*0.2),1,((this->GetFunctionRange())*0.25),1);
00120 }
00121
00122 protected:
00123
00124 vtkPiecewiseFunction* m_PiecewiseFunction;
00125 std::string m_Title;
00126
00127 };
00128 #endif
00129