Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkLabeledImageLookupTable.cpp
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 
14 #include <cstdlib>
15 #include <vtkLookupTable.h>
16 
21 {
22  if (m_LookupTable == nullptr)
23  {
24  itkWarningMacro(
25  "LookupTable is nullptr, it should have been initialized by the default constructor of mitk::LookupTable");
26  m_LookupTable = vtkLookupTable::New();
27  }
28  m_LookupTable->SetNumberOfTableValues(256);
29 
30  // set the background to black and fully transparent
31  m_LookupTable->SetTableValue(0, 0.0, 0.0, 0.0, 0.0);
32 
33  // initialize the remaining 255 colors with random values and
34  // an alpha value of 1.0
35  double r, g, b;
36 
37  //
38  // Initialize the random number generator with an arbitrary seed.
39  // This way, the generated colors are random, but always the same...
40  std::srand(2);
41  for (vtkIdType index = 1; index < 256; ++index)
42  {
43  GenerateRandomColor(r, g, b);
44  m_LookupTable->SetTableValue(index, r, g, b);
45  }
46 
47  // initialize the default level/window settings,
48  // which can be accessed via GetLevelWindow();
51  m_LevelWindow.SetFixed(true);
52 }
53 
55  : LookupTable(other), m_LevelWindow(other.m_LevelWindow)
56 {
57 }
58 
63 {
64 }
65 
67 {
69  if (const auto *lut = dynamic_cast<const LabeledImageLookupTable *>(&other))
70  {
71  this->m_LevelWindow = lut->m_LevelWindow;
72  }
73  return *this;
74 }
75 
85  const double &r,
86  const double &g,
87  const double &b,
88  const double a)
89 {
90  if (m_LookupTable == nullptr)
91  {
92  itkWarningMacro("LookupTable is nullptr, but it should have been initialized by the constructor");
93  return;
94  }
95  m_LookupTable->SetTableValue(label, r, g, b, a);
96 }
97 
105 {
106  if (m_LookupTable == nullptr)
107  {
108  itkWarningMacro("LookupTable is nullptr, but it should have been initialized by the constructor");
109  return nullptr;
110  }
111  return m_LookupTable->GetTableValue(label);
112 }
113 
118 void mitk::LabeledImageLookupTable::GenerateRandomColor(double &r, double &g, double &b)
119 {
120  r = GenerateRandomNumber();
121  g = GenerateRandomNumber();
122  b = GenerateRandomNumber();
123 }
124 
130 {
131  return (((double)(std::rand())) / ((double)(RAND_MAX)));
132 }
133 
134 itk::LightObject::Pointer mitk::LabeledImageLookupTable::InternalClone() const
135 {
136  itk::LightObject::Pointer result(new Self(*this));
137  result->UnRegister();
138  return result;
139 }
void SetWindowBounds(ScalarType lowerBound, ScalarType upperBound, bool expandRangesIfNecessary=true)
void SetFixed(bool fixed)
virtual void SetColorForLabel(const LabelType &label, const double &r, const double &g, const double &b, const double a=1.0)
virtual double * GetColorForLabel(const LabelType &label)
void SetRangeMinMax(ScalarType min, ScalarType max)
virtual void GenerateRandomColor(double &r, double &g, double &b)
virtual LookupTable & operator=(const LookupTable &LookupTable)
implementation necessary because operator made private in itk::Object
vtkSmartPointer< vtkLookupTable > m_LookupTable
LabeledImageLookupTable & operator=(const LookupTable &other) override
implementation necessary because operator made private in itk::Object
The LookupTable class mitk wrapper for a vtkLookupTableThis class can be used to color images with a ...