Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMaterial.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 
17 #include "mitkMaterial.h"
18 #include "mitkBaseRenderer.h"
19 #include "mitkDataNode.h"
20 #include "mitkProperties.h"
23 #include <vtkProperty.h>
24 
25 mitk::Material::Material(Color color, double opacity)
26 {
28  SetColor(color);
33  SetOpacity(opacity);
37  m_Name = "";
38 }
39 
40 mitk::Material::Material(double red, double green, double blue, double opacity)
41 {
42  InitializeStandardValues();
43  SetColor(red, green, blue);
44  SetColorCoefficient(GetColorCoefficient());
45  SetSpecularColor(GetSpecularColor());
46  SetSpecularCoefficient(GetSpecularCoefficient());
47  SetSpecularPower(GetSpecularPower());
48  SetOpacity(opacity);
49  SetInterpolation(GetInterpolation());
50  SetRepresentation(GetRepresentation());
51  SetLineWidth(GetLineWidth());
52  m_Name = "";
53 }
54 
56  double green,
57  double blue,
58  double colorCoefficient,
59  double specularCoefficient,
60  double specularPower,
61  double opacity)
62 {
63  InitializeStandardValues();
64  SetColor(red, green, blue);
65  SetColorCoefficient(colorCoefficient);
66  SetSpecularColor(GetSpecularColor());
67  SetSpecularCoefficient(specularCoefficient);
68  SetSpecularPower(specularPower);
69  SetOpacity(opacity);
70  SetInterpolation(GetInterpolation());
71  SetRepresentation(GetRepresentation());
72  SetLineWidth(GetLineWidth());
73  m_Name = "";
74 }
75 
77  double colorCoefficient,
78  double specularCoefficient,
79  double specularPower,
80  double opacity)
81 {
82  InitializeStandardValues();
83  SetColor(color);
84  SetColorCoefficient(colorCoefficient);
85  SetSpecularColor(GetSpecularColor());
86  SetSpecularCoefficient(specularCoefficient);
87  SetSpecularPower(specularPower);
88  SetOpacity(opacity);
89  SetInterpolation(GetInterpolation());
90  SetRepresentation(GetRepresentation());
91  SetLineWidth(GetLineWidth());
92 }
93 
95 {
96  InitializeStandardValues();
97  SetColor(GetColor());
98  SetColorCoefficient(GetColorCoefficient());
99  SetSpecularColor(GetSpecularColor());
100  SetSpecularCoefficient(GetSpecularCoefficient());
101  SetSpecularPower(GetSpecularPower());
102  SetOpacity(GetOpacity());
103  SetInterpolation(GetInterpolation());
104  SetRepresentation(GetRepresentation());
105  SetLineWidth(GetLineWidth());
106 }
107 
108 mitk::Material::Material(const Material &property) : itk::Object()
109 {
110  Initialize(property);
111 }
112 
114  const Material &property, double red, double green, double blue, double opacity, std::string name)
115 {
116  Initialize(property);
117  SetColor(red, green, blue);
118  SetOpacity(opacity);
119  SetName(name);
120 }
121 
122 bool mitk::Material::Assignable(const Material &other) const
123 {
124  try
125  {
126  const Material &otherinstance =
127  dynamic_cast<const Self &>(other); // dear compiler, please don't optimize this away! Thanks.
128  otherinstance.GetOpacity();
129  return true;
130  }
131  catch (std::bad_cast)
132  {
133  }
134  return false;
135 }
136 
138 {
139  try
140  {
141  const Self &otherProp(dynamic_cast<const Self &>(other));
142 
143  Initialize(otherProp);
144  }
145  catch (std::bad_cast)
146  {
147  // nothing to do then
148  }
149 
150  return *this;
151 }
152 
154 {
155  m_Color = color;
156  Modified();
157 }
158 
159 void mitk::Material::SetColor(double red, double green, double blue)
160 {
161  m_Color.Set(red, green, blue);
162  Modified();
163 }
164 
165 void mitk::Material::SetColorCoefficient(double coefficient)
166 {
167  m_ColorCoefficient = coefficient;
168  Modified();
169 }
170 
172 {
173  m_SpecularColor = specularColor;
174  Modified();
175 }
176 
177 void mitk::Material::SetSpecularColor(double red, double green, double blue)
178 {
179  m_SpecularColor.Set(red, green, blue);
180  Modified();
181 }
182 
183 void mitk::Material::SetSpecularCoefficient(double specularCoefficient)
184 {
185  m_SpecularCoefficient = specularCoefficient;
186  Modified();
187 }
188 
189 void mitk::Material::SetSpecularPower(double specularPower)
190 {
191  m_SpecularPower = specularPower;
192  Modified();
193 }
194 
195 void mitk::Material::SetOpacity(double opacity)
196 {
197  m_Opacity = opacity;
198  Modified();
199 }
200 
202 {
203  m_Interpolation = interpolation;
204  Modified();
205 }
206 
208 {
209  m_Representation = representation;
210  Modified();
211 }
212 
213 void mitk::Material::SetLineWidth(float lineWidth)
214 {
215  m_LineWidth = lineWidth;
216  Modified();
217 }
218 
220 {
221  return m_Color;
222 }
223 
225 {
226  return m_ColorCoefficient;
227 }
228 
230 {
231  return m_SpecularColor;
232 }
233 
235 {
236  return m_SpecularCoefficient;
237 }
238 
240 {
241  return m_SpecularPower;
242 }
243 
245 {
246  return m_Opacity;
247 }
248 
250 {
251  return m_Interpolation;
252 }
253 
255 {
256  return m_Representation;
257 }
258 
260 {
261  switch (m_Interpolation)
262  {
263  case (Flat):
264  return VTK_FLAT;
265  case (Gouraud):
266  return VTK_GOURAUD;
267  case (Phong):
268  return VTK_PHONG;
269  }
270  return VTK_GOURAUD;
271 }
272 
274 {
275  switch (m_Representation)
276  {
277  case (Points):
278  return VTK_POINTS;
279  case (Wireframe):
280  return VTK_WIREFRAME;
281  case (Surface):
282  return VTK_SURFACE;
283  }
284  return VTK_SURFACE;
285 }
286 
288 {
289  return m_LineWidth;
290 }
291 
293 {
294  this->SetColor(property.GetColor());
295  this->SetColorCoefficient(property.GetColorCoefficient());
296  this->SetSpecularColor(property.GetSpecularColor());
297  this->SetSpecularCoefficient(property.GetSpecularCoefficient());
298  this->SetSpecularPower(property.GetSpecularPower());
299  this->SetOpacity(property.GetOpacity());
300  this->SetInterpolation(property.GetInterpolation());
301  this->SetRepresentation(property.GetRepresentation());
302  this->SetLineWidth(property.GetLineWidth());
303  this->SetName(property.GetName());
304 }
305 
306 bool mitk::Material::operator==(const Material &property) const
307 {
308  const Self *other = dynamic_cast<const Self *>(&property);
309 
310  if (other == NULL)
311  return false;
312  else
313  return (m_Color == other->GetColor() && m_ColorCoefficient == other->GetColorCoefficient() &&
314  m_SpecularColor == other->GetSpecularColor() && m_SpecularCoefficient == other->GetSpecularCoefficient() &&
315  m_SpecularPower == other->GetSpecularPower() && m_Opacity == other->GetOpacity() &&
316  m_Interpolation == other->GetInterpolation() && m_Name == other->GetName() &&
317  m_Representation == other->GetRepresentation() && m_LineWidth == other->GetLineWidth());
318 }
319 
321 {
322  m_Color.Set(0.5, 0.5, 0.0);
323  m_ColorCoefficient = 0.5;
324  m_SpecularColor.Set(1.0, 1.0, 1.0);
325  m_SpecularCoefficient = 0.5;
326  m_SpecularPower = 10.0;
327  m_Opacity = 1.0;
328  m_Interpolation = Gouraud;
329  m_Representation = Surface;
330  m_LineWidth = 1.0;
331  m_Name = "";
332 }
333 
335 {
336  this->SetColor(this->GetColor());
337  this->SetColorCoefficient(this->GetColorCoefficient());
338  this->SetSpecularColor(this->GetSpecularColor());
339  this->SetSpecularCoefficient(this->GetSpecularCoefficient());
340  this->SetSpecularPower(this->GetSpecularPower());
341  this->SetOpacity(this->GetOpacity());
342  this->SetInterpolation(this->GetInterpolation());
343  this->SetRepresentation(this->GetRepresentation());
344 }
345 
346 void mitk::Material::PrintSelf(std::ostream &os, itk::Indent /* unused */) const
347 {
348  os << "Name: " << GetName() << std::endl;
349  os << "Color: " << GetColor() << std::endl;
350  os << "ColorCoefficient" << GetColorCoefficient() << std::endl;
351  os << "SpecularColor: " << GetSpecularColor() << std::endl;
352  os << "SpecularCoefficient: " << GetSpecularCoefficient() << std::endl;
353  os << "SpecularPower: " << GetSpecularPower() << std::endl;
354  os << "Opacity: " << GetOpacity() << std::endl;
355  os << "Line width: " << GetLineWidth() << std::endl;
356  switch (GetInterpolation())
357  {
358  case (Flat):
359  os << "Interpolation: Flat" << std::endl;
360  break;
361  case (Gouraud):
362  os << "Interpolation: Gouraud" << std::endl;
363  break;
364  case (Phong):
365  os << "Interpolation: Phong" << std::endl;
366  break;
367  }
368  switch (GetRepresentation())
369  {
370  case (Points):
371  os << "Representation: Points" << std::endl;
372  break;
373  case (Wireframe):
374  os << "Representation: Wireframe" << std::endl;
375  break;
376  case (Surface):
377  os << "Representation: Surface" << std::endl;
378  break;
379  }
380 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
void PrintSelf(std::ostream &os, itk::Indent) const override
virtual double GetSpecularPower() const
virtual void SetColor(Color color)
virtual Color GetSpecularColor() const
virtual void SetLineWidth(float lineWidth)
virtual bool Assignable(const Material &other) const
virtual bool operator==(const Material &property) const
virtual void SetRepresentation(RepresentationType representation)
virtual void SetSpecularCoefficient(double specularCoefficient)
virtual int GetVtkRepresentation() const
virtual double GetOpacity() const
virtual void Initialize(const Material &property)
virtual InterpolationType GetInterpolation() const
virtual void InitializeStandardValues()
virtual RepresentationType GetRepresentation() const
virtual void Update()
virtual void SetInterpolation(InterpolationType interpolation)
virtual double GetSpecularCoefficient() const
virtual int GetVtkInterpolation() const
virtual Material & operator=(const Material &other)
virtual void SetSpecularColor(Color color)
virtual void SetColorCoefficient(double coefficient)
virtual void SetSpecularPower(double specularPower)
std::string m_Name
Definition: mitkMaterial.h:463
static std::string GetName(std::string fileName, std::string suffix)
itk::RGBPixel< double > Color
Definition: mitkMaterial.h:41
virtual float GetLineWidth() const
virtual Color GetColor() const
virtual double GetColorCoefficient() const
virtual void SetOpacity(double opacity)
virtual std::string GetName() const