Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkShaderProperty.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 "mitkShaderProperty.h"
18 #include <vtkAbstractMapper.h>
19 
20 #include "mitkCoreServices.h"
21 #include "mitkIShaderRepository.h"
22 
23 #include <itkDirectory.h>
24 #include <itksys/SystemTools.hxx>
25 
27 {
29  SetShader((IdType)0);
30 }
31 
33  : mitk::EnumerationProperty(other), shaderList(other.shaderList)
34 {
35 }
36 
38 {
39  AddShaderTypes();
40  SetShader(value);
41 }
42 
43 mitk::ShaderProperty::ShaderProperty(const std::string &value)
44 {
45  AddShaderTypes();
46  SetShader(value);
47 }
48 
50 {
51  if (IsValidEnumerationValue(value))
52  SetValue(value);
53  else
54  SetValue((IdType)0);
55 }
56 
57 void mitk::ShaderProperty::SetShader(const std::string &value)
58 {
59  if (IsValidEnumerationValue(value))
60  SetValue(value);
61  else
62  SetValue((IdType)0);
63 }
64 
66 {
67  return GetValueAsId();
68 }
69 
71 {
72  return GetValueAsString();
73 }
74 
76 {
77  AddEnum("fixed");
78 
80  if (shaderRepo == NULL)
81  return;
82 
83  std::list<mitk::IShaderRepository::Shader::Pointer> l = shaderRepo->GetShaders();
84  std::list<mitk::IShaderRepository::Shader::Pointer>::const_iterator i = l.begin();
85 
86  while (i != l.end())
87  {
88  AddEnum((*i)->GetName());
89  ++i;
90  }
91 }
92 
93 bool mitk::ShaderProperty::AddEnum(const std::string &name, const IdType & /*id*/)
94 {
95  Element e;
96 
97  e.name = name;
98 
99  bool success = Superclass::AddEnum(e.name, (IdType)shaderList.size());
100 
101  shaderList.push_back(e);
102 
103  return success;
104 }
105 
106 bool mitk::ShaderProperty::Assign(const BaseProperty &property)
107 {
108  Superclass::Assign(property);
109  this->shaderList = static_cast<const Self &>(property).shaderList;
110  return true;
111 }
112 
113 itk::LightObject::Pointer mitk::ShaderProperty::InternalClone() const
114 {
115  itk::LightObject::Pointer result(new Self(*this));
116  result->UnRegister();
117  return result;
118 }
void SetShader(const IdType &i)
itk::SmartPointer< Self > Pointer
static IShaderRepository * GetShaderRepository()
Get an IShaderRepository instance.
DataCollection - Class to facilitate loading/accessing structured data.
Abstract base class for properties.
Management class for vtkShader XML descriptions.
virtual std::list< Shader::Pointer > GetShaders() const =0
bool AddEnum(const std::string &name, const IdType &id=0) override