Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVectorImageVtkGlyphMapper3D.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 
19 #include <vtkMaskedGlyph3D.h>
20 #include <vtkActor.h>
21 #include <vtkPolyDataMapper.h>
22 #include <vtkArrowSource.h>
23 #include <vtkLineSource.h>
24 #include <vtkImageData.h>
25 #include <vtkPolyData.h>
26 #include <vtkPointData.h>
27 #include <vtkLookupTable.h>
28 #include <mitkLookupTable.h>
30 
31 
32 /*
33 * Constructor. Doesn't do anything...
34 */
36 {
37  m_RandomMode = true;
38  m_UseMaskPoints = true;
44 }
45 
47 {
48  return m_Glyph3DActor;
49 }
50 
51 /*
52 * Destructor
53 */
55 {
56  if ( m_Glyph3DMapper != NULL )
57  m_Glyph3DMapper->Delete();
58  if ( m_Glyph3DGenerator != NULL )
59  m_Glyph3DGenerator->Delete();
60 }
61 
62 /*
63 * Generate a vtkPolyData by creating vectors as glyphs
64 * This method is called, each time a specific renderer is updated.
65 */
67 {
68 
69  bool visible = true;
70  GetDataNode()->GetVisibility(visible, renderer, "visible");
71 
72  if ( !visible )
73  {
74  if ( m_Glyph3DActor != NULL )
75  m_Glyph3DActor->VisibilityOff();
76  return ;
77  }
78  else
79  {
80  if ( m_Glyph3DActor != NULL )
81  m_Glyph3DActor->VisibilityOn();
82  }
83 
84  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);
85  bool needGenerateData = ls->IsGenerateDataRequired( renderer, this, GetDataNode() );
86 
87  if(!needGenerateData)
88  {
89  return;
90  }
91 
93 
94  //
95  // get the input image...
96  //
97  mitk::Image::Pointer mitkImage = this->GetInput();
98  if ( mitkImage.GetPointer() == NULL )
99  {
100  itkWarningMacro( << "VectorImage is null !" );
101  return;
102  }
103 
104  //
105  // make sure, that the input image is an vector image
106  //
107  if ( mitkImage->GetPixelType().GetNumberOfComponents() <= 1 )
108  {
109  itkWarningMacro( << "VectorImage has only one scalar component!" );
110  return ;
111  }
112 
113  vtkImageData* vtkImage = mitkImage->GetVtkImageData();
114 
115  //
116  // make sure, that we have point data with more than 1 component (as vectors)
117  //
118  vtkPointData* pointData = vtkImage->GetPointData();
119  if ( pointData == NULL )
120  {
121  itkWarningMacro( << "vtkImage->GetPointData() returns NULL!" );
122  return ;
123  }
124  if ( pointData->GetNumberOfArrays() == 0 )
125  {
126  itkWarningMacro( << "vtkImage->GetPointData()->GetNumberOfArrays() is 0!" );
127  return ;
128  }
129  else if ( pointData->GetArrayName( 0 ) == NULL )
130  {
131  vtkImage->GetPointData() ->GetArray( 0 ) ->SetName( "vector" );
132  }
133 
134  if ( vtkImage->GetNumberOfPoints() != 0 )
135  {
136 
137  //
138  // create the glyph, which has to be shown at each point
139  // of the masked image
140  //
141  vtkPolyData* glyph;
142  if ( m_GlyphType == LineGlyph )
143  {
144  vtkLineSource * lineSource = vtkLineSource::New();
145  lineSource->Update();
146  glyph = lineSource->GetOutput();
147  }
148  else if ( m_GlyphType == ArrowGlyph )
149  {
150  vtkArrowSource * arrowSource = vtkArrowSource::New();
151  arrowSource->Update();
152  glyph = arrowSource->GetOutput();
153  }
154  else
155  {
156  // Use a vtkLineSource as default, if the GlyphType is
157  // unknown
158  itkWarningMacro( << "unknown glyph type!" );
159  vtkLineSource * lineSource = vtkLineSource::New();
160  lineSource->Update();
161  glyph = lineSource->GetOutput();
162  }
163 m_RandomMode = false;
164 m_UseMaskPoints = false;
165 m_MaximumNumberOfPoints = 80*80*80;
166  //
167  // set up the actual glyphing filter
168  //
169  m_Glyph3DGenerator->SetSourceData( glyph );
170  m_Glyph3DGenerator->SetInput( vtkImage );
171  //m_Glyph3DGenerator->SetInputConnection(m_Cutter->GetOutputPort());
172  m_Glyph3DGenerator->SetInputArrayToProcess (1, 0,0, vtkDataObject::FIELD_ASSOCIATION_POINTS , "vector");
173 
174  //m_Glyph3DGenerator->SelectInputVectors( vtkImage->GetPointData() ->GetArray( 0 ) ->GetName() );
175  m_Glyph3DGenerator->OrientOn();
176  m_Glyph3DGenerator->SetVectorModeToUseVector();
177  m_Glyph3DGenerator->SetScaleFactor( 0.00392156862745 );
178  m_Glyph3DGenerator->SetScaleModeToScaleByVector();
179  m_Glyph3DGenerator->SetUseMaskPoints( m_UseMaskPoints );
180  m_Glyph3DGenerator->SetRandomMode( m_RandomMode );
181  m_Glyph3DGenerator->SetMaximumNumberOfPoints( m_MaximumNumberOfPoints );
182  m_Glyph3DGenerator->Update();
183  m_Glyph3DMapper->SetInputConnection( m_Glyph3DGenerator->GetOutputPort() );
184  m_Glyph3DActor->SetMapper( m_Glyph3DMapper );
185 
186  if (GetDataNode()->GetProperty("LookupTable"))
187  {
189  m_Glyph3DMapper->Update();
190  mitkLookupTable->SetVtkLookupTable(dynamic_cast<vtkLookupTable*>(m_Glyph3DMapper->GetLookupTable()));
191  mitk::LookupTableProperty::Pointer LookupTableProp = mitk::LookupTableProperty::New( mitkLookupTable );
192  GetDataNode()->SetProperty( "LookupTable", LookupTableProp );
193  }
194  else
195  {
196  mitk::LookupTableProperty::Pointer mitkLutProp = dynamic_cast<mitk::LookupTableProperty*>(GetDataNode()->GetProperty("LookupTable"));
197  if (mitkLutProp.IsNotNull())
198  m_Glyph3DMapper->SetLookupTable( mitkLutProp->GetLookupTable()->GetVtkLookupTable() );
199 
200  }
201 
202  //vtkDataSetWriter* writer = vtkDataSetWriter::New();
203  //writer->SetInput( vtkImage );
204  //writer->SetFileName( "out.vtk" );
205  //writer->Update();
206  }
207 
208 }
209 
210 
211 /*
212 * Returns the input data object of the given filter. In this
213 * case, a mitk::Image is returned.
214 */
216 {
217  return const_cast<mitk::Image*>( dynamic_cast<mitk::Image*>( GetDataNode()->GetData() ) );
218 }
219 
Base class for mapper specific rendering ressources.
Definition: mitkMapper.h:200
Organizes the rendering process.
static vtkMaskedGlyph3D * New()
void SetLookupTable(const mitk::LookupTable::Pointer aLookupTable)
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
Definition: mitkMapper.cpp:129
The LookupTableProperty class Property to associate mitk::LookupTable to an mitk::DataNode.
static Pointer New()
Image class for storing images.
Definition: mitkImage.h:76
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
static Pointer New()
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.