Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFiberBundleMapper3D.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 
18 
20 #include <mitkProperties.h>
21 
22 #include <vtkPropAssembly.h>
23 #include <vtkPointData.h>
24 #include <vtkProperty.h>
25 #include <vtkCellArray.h>
26 #include <vtkDepthSortPolyData.h>
27 #include <vtkCamera.h>
28 #include <vtkTubeFilter.h>
29 #include <vtkRibbonFilter.h>
30 #include <vtkLookupTable.h>
31 
33  : m_TubeRadius(0.0)
34  , m_TubeSides(15)
35  , m_LineWidth(1)
36 {
37  m_lut = vtkLookupTable::New();
38  m_lut->Build();
39 }
40 
41 
43 {
44 
45 }
46 
47 
49 {
50  return static_cast<const mitk::FiberBundle * > ( GetDataNode()->GetData() );
51 }
52 
53 
54 /*
55  This method is called once the mapper gets new input,
56  for UI rotation or changes in colorcoding this method is NOT called
57  */
59 {
60  mitk::FiberBundle* fiberBundle = dynamic_cast<mitk::FiberBundle*> (GetDataNode()->GetData());
61  if (fiberBundle == NULL)
62  return;
63 
64  vtkSmartPointer<vtkPolyData> fiberPolyData = fiberBundle->GetFiberPolyData();
65  if (fiberPolyData == NULL)
66  return;
67 
68  fiberPolyData->GetPointData()->AddArray(fiberBundle->GetFiberColors());
69  float tmpopa;
70  this->GetDataNode()->GetOpacity(tmpopa, NULL);
71  FBXLocalStorage3D *localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
72 
73  if (m_TubeRadius>0.0)
74  {
75  vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkSmartPointer<vtkTubeFilter>::New();
76  tubeFilter->SetInputData(fiberPolyData);
77  tubeFilter->SetNumberOfSides(m_TubeSides);
78  tubeFilter->SetRadius(m_TubeRadius);
79  tubeFilter->Update();
80  fiberPolyData = tubeFilter->GetOutput();
81  }
82  else if (m_RibbonWidth>0.0)
83  {
84  vtkSmartPointer<vtkRibbonFilter> tubeFilter = vtkSmartPointer<vtkRibbonFilter>::New();
85  tubeFilter->SetInputData(fiberPolyData);
86  tubeFilter->SetWidth(m_RibbonWidth);
87  tubeFilter->Update();
88  fiberPolyData = tubeFilter->GetOutput();
89  }
90 
91  if (tmpopa<1)
92  {
93  vtkSmartPointer<vtkDepthSortPolyData> depthSort = vtkSmartPointer<vtkDepthSortPolyData>::New();
94  depthSort->SetInputData( fiberPolyData );
95  depthSort->SetCamera( renderer->GetVtkRenderer()->GetActiveCamera() );
96  depthSort->SetDirectionToFrontToBack();
97  depthSort->Update();
98  localStorage->m_FiberMapper->SetInputConnection(depthSort->GetOutputPort());
99  }
100  else
101  {
102  localStorage->m_FiberMapper->SetInputData(fiberPolyData);
103  }
104 
105  if (m_Lighting)
106  {
107  float floatProp = 1.0;
108  GetDataNode()->GetFloatProperty("light.ambient", floatProp);
109  localStorage->m_FiberActor->GetProperty()->SetAmbient(floatProp);
110  GetDataNode()->GetFloatProperty("light.diffuse", floatProp);
111  localStorage->m_FiberActor->GetProperty()->SetDiffuse(floatProp);
112  GetDataNode()->GetFloatProperty("light.specular", floatProp);
113  localStorage->m_FiberActor->GetProperty()->SetSpecular(floatProp);
114  GetDataNode()->GetFloatProperty("light.specularpower", floatProp);
115  localStorage->m_FiberActor->GetProperty()->SetSpecularPower( floatProp );
116 
117  mitk::ColorProperty* ambientC = dynamic_cast<mitk::ColorProperty*>(GetDataNode()->GetProperty("light.ambientcolor"));
118  mitk::ColorProperty* diffuseC = dynamic_cast<mitk::ColorProperty*>(GetDataNode()->GetProperty("light.diffusecolor"));
119  mitk::ColorProperty* specularC = dynamic_cast<mitk::ColorProperty*>(GetDataNode()->GetProperty("light.specularcolor"));
120 
121  localStorage->m_FiberActor->GetProperty()->SetAmbientColor( ambientC->GetColor()[0], ambientC->GetColor()[1], ambientC->GetColor()[2] );
122  localStorage->m_FiberActor->GetProperty()->SetDiffuseColor( diffuseC->GetColor()[0], diffuseC->GetColor()[1], diffuseC->GetColor()[2] );
123  localStorage->m_FiberActor->GetProperty()->SetSpecularColor( specularC->GetColor()[0], specularC->GetColor()[1], specularC->GetColor()[2] );
124  localStorage->m_FiberActor->GetProperty()->SetLighting(true);
125  }
126  else
127  {
128  localStorage->m_FiberActor->GetProperty()->SetLighting(false);
129  }
130 
131  localStorage->m_FiberMapper->SelectColorArray("FIBER_COLORS");
132  localStorage->m_FiberMapper->ScalarVisibilityOn();
133  localStorage->m_FiberMapper->SetScalarModeToUsePointFieldData();
134  localStorage->m_FiberActor->SetMapper(localStorage->m_FiberMapper);
135  localStorage->m_FiberMapper->SetLookupTable(m_lut);
136 
137  // set Opacity
138  localStorage->m_FiberActor->GetProperty()->SetOpacity((double) tmpopa);
139  localStorage->m_FiberActor->GetProperty()->SetLineWidth(m_LineWidth);
140 
141  localStorage->m_FiberAssembly->AddPart(localStorage->m_FiberActor);
142  localStorage->m_LastUpdateTime.Modified();
143 }
144 
145 
146 
148 {
149  bool visible = true;
150  GetDataNode()->GetVisibility(visible, renderer, "visible");
151  if ( !visible ) return;
152 
153  const DataNode* node = this->GetDataNode();
154  FBXLocalStorage3D* localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
155  mitk::FiberBundle* fiberBundle = dynamic_cast<mitk::FiberBundle*>(node->GetData());
156 
157  // did any rendering properties change?
158  float tubeRadius = 0;
159  node->GetFloatProperty("shape.tuberadius", tubeRadius);
160  if (m_TubeRadius!=tubeRadius)
161  {
162  m_TubeRadius = tubeRadius;
163  fiberBundle->RequestUpdate3D();
164  }
165 
166  int tubeSides = 0;
167  node->GetIntProperty("shape.tubesides", tubeSides);
168  if (m_TubeSides!=tubeSides)
169  {
170  m_TubeSides = tubeSides;
171  fiberBundle->RequestUpdate3D();
172  }
173 
174  int lineWidth = 0;
175  node->GetIntProperty("shape.linewidth", lineWidth);
176  if (m_LineWidth!=lineWidth)
177  {
178  m_LineWidth = lineWidth;
179  fiberBundle->RequestUpdate3D();
180  }
181 
182  float ribbonWidth = 0;
183  node->GetFloatProperty("shape.ribbonwidth", ribbonWidth);
184  if (m_RibbonWidth!=ribbonWidth)
185  {
186  m_RibbonWidth = ribbonWidth;
187  fiberBundle->RequestUpdate3D();
188  }
189 
190  bool lighting = false;
191  node->GetBoolProperty("light.enable", lighting);
192  if (m_Lighting!=lighting)
193  {
194  m_Lighting = lighting;
195  fiberBundle->RequestUpdate3D();
196  }
197 
198  if (localStorage->m_LastUpdateTime>=fiberBundle->GetUpdateTime3D())
199  return;
200 
201  // Calculate time step of the input data for the specified renderer (integer value)
202  // this method is implemented in mitkMapper
203  this->CalculateTimeStep( renderer );
204  this->InternalGenerateData(renderer);
205 }
206 
207 
209 {
210  Superclass::SetDefaultProperties(node, renderer, overwrite);
211  node->AddProperty( "opacity", mitk::FloatProperty::New( 1.0 ), renderer, overwrite);
212  node->AddProperty( "color", mitk::ColorProperty::New(1.0,1.0,1.0), renderer, overwrite);
213  node->AddProperty( "pickable", mitk::BoolProperty::New( true ), renderer, overwrite);
214 
215  node->AddProperty( "shape.linewidth", mitk::IntProperty::New( true ), renderer, overwrite );
216  node->AddProperty( "shape.tuberadius",mitk::FloatProperty::New( 0.0 ), renderer, overwrite);
217  node->AddProperty( "shape.tubesides",mitk::IntProperty::New( 15 ), renderer, overwrite);
218  node->AddProperty( "shape.ribbonwidth", mitk::FloatProperty::New( 0.0 ), renderer, overwrite);
219 
220  node->AddProperty( "light.enable", mitk::BoolProperty::New( true ), renderer, overwrite);
221  node->AddProperty( "light.ambient", mitk::FloatProperty::New( 0.0 ), renderer, overwrite);
222  node->AddProperty( "light.diffuse", mitk::FloatProperty::New( 1.0 ), renderer, overwrite);
223  node->AddProperty( "light.specular", mitk::FloatProperty::New( 0.0 ), renderer, overwrite);
224  node->AddProperty( "light.specularpower", mitk::FloatProperty::New( 1.0 ), renderer, overwrite);
225  node->AddProperty( "light.ambientcolor", mitk::ColorProperty::New(1,1,1), renderer, overwrite);
226  node->AddProperty( "light.diffusecolor", mitk::ColorProperty::New(1,1,1), renderer, overwrite);
227  node->AddProperty( "light.specularcolor", mitk::ColorProperty::New(1,1,1), renderer, overwrite);
228 }
229 
231 {
232  return m_LocalStorageHandler.GetLocalStorage(renderer)->m_FiberAssembly;
233 }
234 
236 {
237 
238 }
239 
241 {
242 
243 }
244 
246 {
247  m_FiberActor = vtkSmartPointer<vtkActor>::New();
248  m_FiberMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
249  m_FiberAssembly = vtkSmartPointer<vtkPropAssembly>::New();
250 }
251 
vtkSmartPointer< vtkPropAssembly > m_FiberAssembly
itk::TimeStamp m_LastUpdateTime
Timestamp of last update of stored data.
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=NULL, bool overwrite=false)
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for int properties (instances of IntProperty)
static Pointer New()
Organizes the rendering process.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
vtkSmartPointer< vtkActor > m_FiberActor
Point Actor of a 3D render window.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
vtkSmartPointer< vtkPolyDataMapper > m_FiberMapper
Point Mapper of a 3D render window.
static Pointer New()
The ColorProperty class RGB color property.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
static void SetVtkMapperImmediateModeRendering(vtkMapper *mapper)
void InternalGenerateData(mitk::BaseRenderer *renderer)
vtkSmartPointer< vtkPolyData > GetFiberPolyData() const
bool GetFloatProperty(const char *propertyKey, float &floatValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty)
Base Class for Fiber Bundles;.
vtkSmartPointer< vtkUnsignedCharArray > GetFiberColors() const
const mitk::Color & GetColor() const
FBXLocalStorage3D()
Constructor of the local storage. Do as much actions as possible in here to avoid double executions...
static Pointer New()
static Pointer New()
virtual itk::TimeStamp GetUpdateTime3D()
vtkRenderer * GetVtkRenderer() const
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.