Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkTransferFunction.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkTransferFunction_h
14 #define mitkTransferFunction_h
15 
16 #include <mitkHistogramGenerator.h>
17 #include <mitkImage.h>
18 #include <MitkCoreExports.h>
19 
20 #include <itkHistogram.h>
21 #include <itkObject.h>
22 #include <itkRGBPixel.h>
23 
24 #include <vtkColorTransferFunction.h>
25 #include <vtkPiecewiseFunction.h>
26 #include <vtkSmartPointer.h>
27 
28 #include <algorithm>
29 #include <set>
30 #include <vector>
31 
32 namespace mitk
33 {
49  class MITKCORE_EXPORT TransferFunction : public itk::Object
50  {
51  public:
53  typedef std::vector<std::pair<double, double>> ControlPoints;
54 
56  typedef std::vector<std::pair<double, itk::RGBPixel<double>>> RGBControlPoints;
57 
59 
60  itkFactorylessNewMacro(Self);
61 
62  itkCloneMacro(Self);
63 
65  itkSetMacro(Min, int);
66 
68  itkSetMacro(Max, int);
69 
71  itkGetMacro(Min, int);
72 
74  itkGetMacro(Max, int);
75 
77  itkGetMacro(ScalarOpacityFunction, vtkPiecewiseFunction *);
78 
80  itkGetMacro(GradientOpacityFunction, vtkPiecewiseFunction *);
81 
83  itkGetMacro(ColorTransferFunction, vtkColorTransferFunction *);
84  itkSetMacro(ColorTransferFunction, vtkSmartPointer<vtkColorTransferFunction>);
85 
87  itkGetConstObjectMacro(Histogram, HistogramGenerator::HistogramType);
88 
93  void InitializeByMitkImage(const mitk::Image *image);
94 
99  void InitializeByItkHistogram(const itk::Statistics::Histogram<double> *histogram);
100 
105  void InitializeHistogram(const mitk::Image *image);
106 
112 
118 
124 
130  void AddScalarOpacityPoint(double x, double value);
131 
137  void AddGradientOpacityPoint(double x, double value);
138 
146  void AddRGBPoint(double x, double r, double g, double b);
147 
153 
159 
165 
172 
179 
185  int RemoveRGBPoint(double x);
186 
189 
192 
195 
201  bool operator==(Self &other);
202 
203  protected:
205  ~TransferFunction() override;
206 
207  TransferFunction(const Self &other);
208 
210 
211  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
212 
215 
218 
221 
223  int m_Min;
224 
226  int m_Max;
227 
229  mitk::HistogramGenerator::HistogramType::ConstPointer m_Histogram;
230 
231  private:
233  TransferFunction::ControlPoints m_ScalarOpacityPoints;
234 
236  TransferFunction::ControlPoints m_GradientOpacityPoints;
237 
240  };
241 }
242 
243 #endif
#define MITKCORE_EXPORT
itk::Statistics::Histogram< double > HistogramType
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
Wrapper for VTK scalar opacity, gradient opacity, and color transfer functions.
int RemoveRGBPoint(double x)
Remove a control point from the color transfer function.
void SetScalarOpacityPoints(TransferFunction::ControlPoints points)
Replace all scalar opacity control points.
void ClearGradientOpacityPoints()
Remove all control points from the gradient opacity function.
mitk::HistogramGenerator::HistogramType::ConstPointer m_Histogram
TransferFunction::RGBControlPoints & GetRGBPoints()
Get the color transfer function control points.
void InitializeByMitkImage(const mitk::Image *image)
Initialize all three transfer functions from an mitk::Image histogram.
int RemoveGradientOpacityPoint(double x)
Remove a control point from the gradient opacity function.
TransferFunction::ControlPoints & GetGradientOpacityPoints()
Get the gradient opacity control points.
std::vector< std::pair< double, itk::RGBPixel< double > > > RGBControlPoints
Type for color transfer function control points (x, RGB).
void ClearScalarOpacityPoints()
Remove all control points from the scalar opacity function.
std::vector< std::pair< double, double > > ControlPoints
Type for scalar opacity or gradient opacity control points (x, value).
vtkSmartPointer< vtkPiecewiseFunction > m_GradientOpacityFunction
~TransferFunction() override
void SetRGBPoints(TransferFunction::RGBControlPoints rgbpoints)
Replace all color transfer function control points.
int RemoveScalarOpacityPoint(double x)
Remove a control point from the scalar opacity function.
void SetGradientOpacityPoints(TransferFunction::ControlPoints points)
Replace all gradient opacity control points.
TransferFunction(const Self &other)
void AddGradientOpacityPoint(double x, double value)
Add a single control point to the gradient opacity function.
TransferFunction::ControlPoints & GetScalarOpacityPoints()
Get the scalar opacity control points.
mitkClassMacroItkParent(TransferFunction, itk::DataObject)
void AddScalarOpacityPoint(double x, double value)
Add a single control point to the scalar opacity function.
void AddRGBPoint(double x, double r, double g, double b)
Add a single control point to the color transfer function.
void InitializeHistogram(const mitk::Image *image)
Compute and store the histogram and min/max range from an image.
void ClearRGBPoints()
Remove all control points from the color transfer function.
void InitializeByItkHistogram(const itk::Statistics::Histogram< double > *histogram)
Initialize all three transfer functions from an ITK histogram.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
vtkSmartPointer< vtkColorTransferFunction > m_ColorTransferFunction
bool operator==(Self &other)
Compare two TransferFunction objects for equality.
vtkSmartPointer< vtkPiecewiseFunction > m_ScalarOpacityFunction
Find image slices visible on a given plane.