Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFiberBundleMapper2D.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 <mitkBaseRenderer.h>
19 #include <vtkActor.h>
20 #include <vtkPolyDataMapper.h>
21 #include <vtkPlane.h>
22 #include <vtkPolyData.h>
23 #include <vtkPointData.h>
24 #include <vtkProperty.h>
25 #include <vtkLookupTable.h>
26 #include <vtkPoints.h>
27 #include <vtkCamera.h>
28 #include <vtkPolyLine.h>
29 #include <vtkRenderer.h>
30 #include <vtkCellArray.h>
31 #include <vtkMatrix4x4.h>
32 #include <vtkTubeFilter.h>
33 #include <mitkPlaneGeometry.h>
35 #include <mitkIShaderRepository.h>
36 #include <mitkShaderProperty.h>
37 #include <mitkCoreServices.h>
38 
40  : m_LineWidth(1)
41 {
42  m_lut = vtkLookupTable::New();
43  m_lut->Build();
44 
45 }
46 
48 {
49 }
50 
51 
53 {
54  return dynamic_cast< mitk::FiberBundle * > ( GetDataNode()->GetData() );
55 }
56 
57 
58 
60 {
61  bool visible = true;
62  GetDataNode()->GetVisibility(visible, renderer, "visible");
63  if ( !visible )
64  return;
65 
66  // Calculate time step of the input data for the specified renderer (integer value)
67  // this method is implemented in mitkMapper
68  this->CalculateTimeStep( renderer );
69 
70  //check if updates occured in the node or on the display
71  FBXLocalStorage *localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
72 
73  //set renderer independent shader properties
74  const DataNode::Pointer node = this->GetDataNode();
75  float thickness = 2.0;
76  if(!this->GetDataNode()->GetPropertyValue("Fiber2DSliceThickness",thickness))
77  MITK_INFO << "FIBER2D SLICE THICKNESS PROPERTY ERROR";
78 
79  bool fiberfading = false;
80  if(!this->GetDataNode()->GetPropertyValue("Fiber2DfadeEFX",fiberfading))
81  MITK_INFO << "FIBER2D SLICE FADE EFX PROPERTY ERROR";
82 
83  float fiberOpacity;
84  this->GetDataNode()->GetOpacity(fiberOpacity, NULL);
85  node->SetFloatProperty("shader.mitkShaderFiberClipping.fiberThickness",thickness);
86  node->SetIntProperty("shader.mitkShaderFiberClipping.fiberFadingON",fiberfading);
87  node->SetFloatProperty("shader.mitkShaderFiberClipping.fiberOpacity",fiberOpacity);
88 
89  mitk::FiberBundle* fiberBundle = this->GetInput();
90  if (fiberBundle==NULL)
91  return;
92 
93  int lineWidth = 0;
94  node->GetIntProperty("LineWidth", lineWidth);
95  if (m_LineWidth!=lineWidth)
96  {
97  m_LineWidth = lineWidth;
98  fiberBundle->RequestUpdate2D();
99  }
100 
101  if ( localStorage->m_LastUpdateTime<renderer->GetCurrentWorldPlaneGeometryUpdateTime() || localStorage->m_LastUpdateTime<fiberBundle->GetUpdateTime2D() )
102  {
103  this->UpdateShaderParameter(renderer);
104  this->GenerateDataForRenderer( renderer );
105  }
106 }
107 
109 {
110  //get information about current position of views
112  mitk::PlaneGeometry::ConstPointer planeGeo = sliceContr->GetCurrentPlaneGeometry();
113 
114  //generate according cutting planes based on the view position
115  float planeNormal[3];
116  planeNormal[0] = planeGeo->GetNormal()[0];
117  planeNormal[1] = planeGeo->GetNormal()[1];
118  planeNormal[2] = planeGeo->GetNormal()[2];
119 
120  float tmp1 = planeGeo->GetOrigin()[0] * planeNormal[0];
121  float tmp2 = planeGeo->GetOrigin()[1] * planeNormal[1];
122  float tmp3 = planeGeo->GetOrigin()[2] * planeNormal[2];
123  float thickness = tmp1 + tmp2 + tmp3; //attention, correct normalvector
124 
125  DataNode::Pointer node = this->GetDataNode();
126  node->SetFloatProperty("shader.mitkShaderFiberClipping.slicingPlane.w",thickness,renderer);
127  node->SetFloatProperty("shader.mitkShaderFiberClipping.slicingPlane.x",planeNormal[0],renderer);
128  node->SetFloatProperty("shader.mitkShaderFiberClipping.slicingPlane.y",planeNormal[1],renderer);
129  node->SetFloatProperty("shader.mitkShaderFiberClipping.slicingPlane.z",planeNormal[2],renderer);
130 }
131 
132 // vtkActors and Mappers are feeded here
134 {
135  mitk::FiberBundle* fiberBundle = this->GetInput();
136 
137  //the handler of local storage gets feeded in this method with requested data for related renderwindow
138  FBXLocalStorage *localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
139 
140  mitk::DataNode* node = this->GetDataNode();
141  if ( node == NULL )
142  return;
143 
144  vtkSmartPointer<vtkPolyData> fiberPolyData = fiberBundle->GetFiberPolyData();
145  if (fiberPolyData == NULL)
146  return;
147 
148  fiberPolyData->GetPointData()->AddArray(fiberBundle->GetFiberColors());
149  localStorage->m_FiberMapper->ScalarVisibilityOn();
150  localStorage->m_FiberMapper->SetScalarModeToUsePointFieldData();
151  localStorage->m_FiberMapper->SetLookupTable(m_lut); //apply the properties after the slice was set
152  localStorage->m_PointActor->GetProperty()->SetOpacity(0.999);
153  localStorage->m_FiberMapper->SelectColorArray("FIBER_COLORS");
154 
155  localStorage->m_FiberMapper->SetInputData(fiberPolyData);
156  localStorage->m_PointActor->SetMapper(localStorage->m_FiberMapper);
157  localStorage->m_PointActor->GetProperty()->ShadingOn();
158  localStorage->m_PointActor->GetProperty()->SetLineWidth(m_LineWidth);
159 
160  // Applying shading properties
161  this->ApplyShaderProperties(renderer);
162 
163  // We have been modified => save this for next Update()
164  localStorage->m_LastUpdateTime.Modified();
165 }
166 
167 
169 {
170  this->Update(renderer);
171  return m_LocalStorageHandler.GetLocalStorage(renderer)->m_PointActor;
172 }
173 
174 
176 {
177  Superclass::SetDefaultProperties(node, renderer, overwrite);
178  node->SetProperty("shader",mitk::ShaderProperty::New("mitkShaderFiberClipping"));
179 
180  // Shaders
182  if (shaderRepo)
183  {
184  shaderRepo->AddDefaultProperties(node, renderer, overwrite);
185  }
186 
187  //add other parameters to propertylist
188  node->AddProperty( "Fiber2DSliceThickness", mitk::FloatProperty::New(1.0f), renderer, overwrite );
189  node->AddProperty( "Fiber2DfadeEFX", mitk::BoolProperty::New(true), renderer, overwrite );
190  node->AddProperty( "color", mitk::ColorProperty::New(1.0,1.0,1.0), renderer, overwrite);
191 }
192 
193 
195 {
196  m_PointActor = vtkSmartPointer<vtkActor>::New();
197  m_FiberMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
198 }
std::string tmp3
#define MITK_INFO
Definition: mitkLogMacros.h:22
std::string tmp2
virtual void AddDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer, bool overwrite) const =0
Adds all parsed shader uniforms to property list of the given DataNode; used by mappers.
itk::TimeStamp m_LastUpdateTime
Timestamp of last update of stored data.
void UpdateShaderParameter(mitk::BaseRenderer *)
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=NULL, bool overwrite=false)
static Pointer New()
Organizes the rendering process.
virtual itk::TimeStamp GetUpdateTime2D()
static IShaderRepository * GetShaderRepository()
Get an IShaderRepository instance.
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:35
vtkSmartPointer< vtkPolyDataMapper > m_FiberMapper
Point Mapper of a 2D render window.
static Pointer New()
static Pointer New()
FBXLocalStorage()
Constructor of the local storage. Do as much actions as possible in here to avoid double executions...
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 ...
Management class for vtkShader XML descriptions.
vtkSmartPointer< vtkPolyData > GetFiberPolyData() const
virtual void GenerateDataForRenderer(mitk::BaseRenderer *) override
vtkSmartPointer< vtkActor > m_PointActor
Point Actor of a 2D render window.
Base Class for Fiber Bundles;.
vtkSmartPointer< vtkUnsignedCharArray > GetFiberColors() const
static Pointer New()
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
virtual SliceNavigationController * GetSliceNavigationController()
virtual void Update(mitk::BaseRenderer *renderer) override
Checks whether this mapper needs to update itself and generate data.
unsigned long GetCurrentWorldPlaneGeometryUpdateTime()
Get timestamp of last call of SetCurrentWorldPlaneGeometry.
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
US_USE_NAMESPACE std::string tmp1
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.