Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include <cstdlib>
19 #include <vtkLookupTable.h>
20 
25 {
26  if (m_LookupTable == nullptr)
27  {
28  itkWarningMacro(
29  "LookupTable is NULL, it should have been initialized by the default constructor of mitk::LookupTable");
31  }
32  m_LookupTable->SetNumberOfTableValues(256);
33 
34  // set the background to black and fully transparent
35  m_LookupTable->SetTableValue(0, 0.0, 0.0, 0.0, 0.0);
36 
37  // initialize the remaining 255 colors with random values and
38  // an alpha value of 1.0
39  double r, g, b;
40 
41  //
42  // Initialize the random number generator with an arbitrary seed.
43  // This way, the generated colors are random, but always the same...
44  std::srand(2);
45  for (vtkIdType index = 1; index < 256; ++index)
46  {
47  GenerateRandomColor(r, g, b);
48  m_LookupTable->SetTableValue(index, r, g, b);
49  }
50 
51  // initialize the default level/window settings,
52  // which can be accessed via GetLevelWindow();
55  m_LevelWindow.SetFixed(true);
56 }
57 
59  : LookupTable(other), m_LevelWindow(other.m_LevelWindow)
60 {
61 }
62 
67 {
68 }
69 
71 {
73  if (const LabeledImageLookupTable *lut = dynamic_cast<const LabeledImageLookupTable *>(&other))
74  {
75  this->m_LevelWindow = lut->m_LevelWindow;
76  }
77  return *this;
78 }
79 
89  const double &r,
90  const double &g,
91  const double &b,
92  const double a)
93 {
94  if (m_LookupTable == nullptr)
95  {
96  itkWarningMacro("LookupTable is NULL, but it should have been initialized by the constructor");
97  return;
98  }
99  m_LookupTable->SetTableValue(label, r, g, b, a);
100 }
101 
109 {
110  if (m_LookupTable == nullptr)
111  {
112  itkWarningMacro("LookupTable is NULL, but it should have been initialized by the constructor");
113  return nullptr;
114  }
115  return m_LookupTable->GetTableValue(label);
116 }
117 
122 void mitk::LabeledImageLookupTable::GenerateRandomColor(double &r, double &g, double &b)
123 {
124  r = GenerateRandomNumber();
125  g = GenerateRandomNumber();
126  b = GenerateRandomNumber();
127 }
128 
134 {
135  return (((double)(std::rand())) / ((double)(RAND_MAX)));
136 }
137 
138 itk::LightObject::Pointer mitk::LabeledImageLookupTable::InternalClone() const
139 {
140  itk::LightObject::Pointer result(new Self(*this));
141  result->UnRegister();
142  return result;
143 }
void SetWindowBounds(ScalarType lowerBound, ScalarType upperBound, bool expandRangesIfNecessary=true)
itk::SmartPointer< Self > Pointer
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 ...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.