Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 (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 #include "mitkMaterial.h"
14 #include "mitkBaseRenderer.h"
15 #include "mitkDataNode.h"
16 #include "mitkProperties.h"
19 #include <vtkProperty.h>
20 
21 mitk::Material::Material(Color color, double opacity)
22 {
24  SetColor(color);
29  SetOpacity(opacity);
33  m_Name = "";
34 }
35 
36 mitk::Material::Material(double red, double green, double blue, double opacity)
37 {
39  SetColor(red, green, blue);
44  SetOpacity(opacity);
48  m_Name = "";
49 }
50 
52  double green,
53  double blue,
54  double colorCoefficient,
55  double specularCoefficient,
56  double specularPower,
57  double opacity)
58 {
60  SetColor(red, green, blue);
61  SetColorCoefficient(colorCoefficient);
63  SetSpecularCoefficient(specularCoefficient);
64  SetSpecularPower(specularPower);
65  SetOpacity(opacity);
69  m_Name = "";
70 }
71 
73  double colorCoefficient,
74  double specularCoefficient,
75  double specularPower,
76  double opacity)
77 {
79  SetColor(color);
80  SetColorCoefficient(colorCoefficient);
82  SetSpecularCoefficient(specularCoefficient);
83  SetSpecularPower(specularPower);
84  SetOpacity(opacity);
88 }
89 
91 {
93  SetColor(GetColor());
102 }
103 
104 mitk::Material::Material(const Material &property) : itk::Object()
105 {
106  Initialize(property);
107 }
108 
110  const Material &property, double red, double green, double blue, double opacity, std::string name)
111 {
112  Initialize(property);
113  SetColor(red, green, blue);
114  SetOpacity(opacity);
115  SetName(name);
116 }
117 
118 bool mitk::Material::Assignable(const Material &other) const
119 {
120  try
121  {
122  const auto &otherinstance =
123  dynamic_cast<const Self &>(other); // dear compiler, please don't optimize this away! Thanks.
124  otherinstance.GetOpacity();
125  return true;
126  }
127  catch (const std::bad_cast &)
128  {
129  }
130  return false;
131 }
132 
134 {
135  try
136  {
137  const auto &otherProp(dynamic_cast<const Self &>(other));
138 
139  Initialize(otherProp);
140  }
141  catch (const std::bad_cast &)
142  {
143  // nothing to do then
144  }
145 
146  return *this;
147 }
148 
150 {
151  m_Color = color;
152  Modified();
153 }
154 
155 void mitk::Material::SetColor(double red, double green, double blue)
156 {
157  m_Color.Set(red, green, blue);
158  Modified();
159 }
160 
161 void mitk::Material::SetColorCoefficient(double coefficient)
162 {
163  m_ColorCoefficient = coefficient;
164  Modified();
165 }
166 
168 {
169  m_SpecularColor = specularColor;
170  Modified();
171 }
172 
173 void mitk::Material::SetSpecularColor(double red, double green, double blue)
174 {
175  m_SpecularColor.Set(red, green, blue);
176  Modified();
177 }
178 
179 void mitk::Material::SetSpecularCoefficient(double specularCoefficient)
180 {
181  m_SpecularCoefficient = specularCoefficient;
182  Modified();
183 }
184 
185 void mitk::Material::SetSpecularPower(double specularPower)
186 {
187  m_SpecularPower = specularPower;
188  Modified();
189 }
190 
191 void mitk::Material::SetOpacity(double opacity)
192 {
193  m_Opacity = opacity;
194  Modified();
195 }
196 
198 {
199  m_Interpolation = interpolation;
200  Modified();
201 }
202 
204 {
205  m_Representation = representation;
206  Modified();
207 }
208 
209 void mitk::Material::SetLineWidth(float lineWidth)
210 {
211  m_LineWidth = lineWidth;
212  Modified();
213 }
214 
216 {
217  return m_Color;
218 }
219 
221 {
222  return m_ColorCoefficient;
223 }
224 
226 {
227  return m_SpecularColor;
228 }
229 
231 {
232  return m_SpecularCoefficient;
233 }
234 
236 {
237  return m_SpecularPower;
238 }
239 
241 {
242  return m_Opacity;
243 }
244 
246 {
247  return m_Interpolation;
248 }
249 
251 {
252  return m_Representation;
253 }
254 
256 {
257  switch (m_Interpolation)
258  {
259  case (Flat):
260  return VTK_FLAT;
261  case (Gouraud):
262  return VTK_GOURAUD;
263  case (Phong):
264  return VTK_PHONG;
265  }
266  return VTK_GOURAUD;
267 }
268 
270 {
271  switch (m_Representation)
272  {
273  case (Points):
274  return VTK_POINTS;
275  case (Wireframe):
276  return VTK_WIREFRAME;
277  case (Surface):
278  return VTK_SURFACE;
279  }
280  return VTK_SURFACE;
281 }
282 
284 {
285  return m_LineWidth;
286 }
287 
289 {
290  this->SetColor(property.GetColor());
291  this->SetColorCoefficient(property.GetColorCoefficient());
292  this->SetSpecularColor(property.GetSpecularColor());
294  this->SetSpecularPower(property.GetSpecularPower());
295  this->SetOpacity(property.GetOpacity());
296  this->SetInterpolation(property.GetInterpolation());
297  this->SetRepresentation(property.GetRepresentation());
298  this->SetLineWidth(property.GetLineWidth());
299  this->SetName(property.GetName());
300 }
301 
302 bool mitk::Material::operator==(const Material &property) const
303 {
304  const auto *other = dynamic_cast<const Self *>(&property);
305 
306  if (other == nullptr)
307  return false;
308  else
309  return (m_Color == other->GetColor() && m_ColorCoefficient == other->GetColorCoefficient() &&
310  m_SpecularColor == other->GetSpecularColor() && m_SpecularCoefficient == other->GetSpecularCoefficient() &&
311  m_SpecularPower == other->GetSpecularPower() && m_Opacity == other->GetOpacity() &&
312  m_Interpolation == other->GetInterpolation() && m_Name == other->GetName() &&
313  m_Representation == other->GetRepresentation() && m_LineWidth == other->GetLineWidth());
314 }
315 
317 {
318  m_Color.Set(0.5, 0.5, 0.0);
319  m_ColorCoefficient = 0.5;
320  m_SpecularColor.Set(1.0, 1.0, 1.0);
321  m_SpecularCoefficient = 0.5;
322  m_SpecularPower = 10.0;
323  m_Opacity = 1.0;
326  m_LineWidth = 1.0;
327  m_Name = "";
328 }
329 
331 {
332  this->SetColor(this->GetColor());
334  this->SetSpecularColor(this->GetSpecularColor());
336  this->SetSpecularPower(this->GetSpecularPower());
337  this->SetOpacity(this->GetOpacity());
338  this->SetInterpolation(this->GetInterpolation());
339  this->SetRepresentation(this->GetRepresentation());
340 }
341 
342 void mitk::Material::PrintSelf(std::ostream &os, itk::Indent /* unused */) const
343 {
344  os << "Name: " << GetName() << std::endl;
345  os << "Color: " << GetColor() << std::endl;
346  os << "ColorCoefficient" << GetColorCoefficient() << std::endl;
347  os << "SpecularColor: " << GetSpecularColor() << std::endl;
348  os << "SpecularCoefficient: " << GetSpecularCoefficient() << std::endl;
349  os << "SpecularPower: " << GetSpecularPower() << std::endl;
350  os << "Opacity: " << GetOpacity() << std::endl;
351  os << "Line width: " << GetLineWidth() << std::endl;
352  switch (GetInterpolation())
353  {
354  case (Flat):
355  os << "Interpolation: Flat" << std::endl;
356  break;
357  case (Gouraud):
358  os << "Interpolation: Gouraud" << std::endl;
359  break;
360  case (Phong):
361  os << "Interpolation: Phong" << std::endl;
362  break;
363  }
364  switch (GetRepresentation())
365  {
366  case (Points):
367  os << "Representation: Points" << std::endl;
368  break;
369  case (Wireframe):
370  os << "Representation: Wireframe" << std::endl;
371  break;
372  case (Surface):
373  os << "Representation: Surface" << std::endl;
374  break;
375  }
376 }
virtual void SetName(std::string _arg)
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:28
double m_ColorCoefficient
Definition: mitkMaterial.h:465
void PrintSelf(std::ostream &os, itk::Indent) const override
virtual RepresentationType GetRepresentation() const
virtual Color GetColor() const
virtual void SetColor(Color color)
double m_SpecularPower
Definition: mitkMaterial.h:469
InterpolationType m_Interpolation
Definition: mitkMaterial.h:475
Color m_SpecularColor
Definition: mitkMaterial.h:463
virtual void SetLineWidth(float lineWidth)
virtual Color GetSpecularColor() const
virtual void SetRepresentation(RepresentationType representation)
virtual void SetSpecularCoefficient(double specularCoefficient)
virtual double GetOpacity() const
double m_SpecularCoefficient
Definition: mitkMaterial.h:467
virtual bool Assignable(const Material &other) const
virtual double GetSpecularCoefficient() const
virtual InterpolationType GetInterpolation() const
virtual void Initialize(const Material &property)
virtual float GetLineWidth() const
virtual void InitializeStandardValues()
virtual int GetVtkInterpolation() const
virtual void Update()
virtual double GetSpecularPower() const
virtual void SetInterpolation(InterpolationType interpolation)
virtual bool operator==(const Material &property) const
virtual Material & operator=(const Material &other)
virtual void SetSpecularColor(Color color)
virtual void SetColorCoefficient(double coefficient)
virtual void SetSpecularPower(double specularPower)
RepresentationType m_Representation
Definition: mitkMaterial.h:477
std::string m_Name
Definition: mitkMaterial.h:459
itk::RGBPixel< double > Color
Definition: mitkMaterial.h:37
virtual int GetVtkRepresentation() const
virtual std::string GetName() const
virtual double GetColorCoefficient() const
virtual void SetOpacity(double opacity)