Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
vtkUnstructuredGridMapper.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 ===================================================================*/
17 
18 #include "vtkExecutive.h"
19 #include "vtkGarbageCollector.h"
20 #include "vtkGeometryFilter.h"
21 #include "vtkInformation.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkPolyData.h"
24 #include "vtkPolyDataMapper.h"
25 #include "vtkScalarsToColors.h"
26 #include "vtkUnstructuredGrid.h"
27 
29 
30 //----------------------------------------------------------------------------
32 {
33  this->GeometryExtractor = 0;
34  this->PolyDataMapper = 0;
35 }
36 
37 //----------------------------------------------------------------------------
39 {
40  // delete internally created objects.
41  if (this->GeometryExtractor)
42  {
43  this->GeometryExtractor->Delete();
44  }
45  if (this->PolyDataMapper)
46  {
47  this->PolyDataMapper->Delete();
48  }
49 }
50 
52 {
53  m_BoundingObject = bo;
54 }
55 
56 //----------------------------------------------------------------------------
57 void vtkUnstructuredGridMapper::SetInput(vtkUnstructuredGrid *input)
58 {
59  this->SetInputDataObject(input);
60 }
61 
62 //----------------------------------------------------------------------------
64 {
65  // return this->Superclass::GetInputAsDataSet();
66  return vtkUnstructuredGrid::SafeDownCast(this->GetExecutive()->GetInputData(0, 0));
67 }
68 
69 //----------------------------------------------------------------------------
71 {
72  if (this->PolyDataMapper)
73  {
74  this->PolyDataMapper->ReleaseGraphicsResources(renWin);
75  }
76 }
77 
78 //----------------------------------------------------------------------------
80 {
81  if (this->PolyDataMapper)
82  {
83  this->PolyDataMapper->ReleaseGraphicsResources(renderer->GetVtkRenderer()->GetRenderWindow());
84  }
85 }
86 
87 //----------------------------------------------------------------------------
88 // Receives from Actor -> maps data to primitives
89 //
90 void vtkUnstructuredGridMapper::Render(vtkRenderer *ren, vtkActor *act)
91 {
92  // make sure that we've been properly initialized
93  //
94  if (!this->GetInput())
95  {
96  vtkErrorMacro(<< "No input!\n");
97  return;
98  }
99 
100  // Need a lookup table
101  //
102  if (this->LookupTable == 0)
103  {
104  this->CreateDefaultLookupTable();
105  }
106  this->LookupTable->Build();
107 
108  // Now can create appropriate mapper
109  //
110  if (this->PolyDataMapper == 0)
111  {
112  vtkGeometryFilter *gf = vtkGeometryFilter::New();
113  vtkPolyDataMapper *pm = vtkPolyDataMapper::New();
114  pm->SetInputConnection(gf->GetOutputPort());
115 
116  this->GeometryExtractor = gf;
117  this->PolyDataMapper = pm;
118  }
119 
120  // share clipping planes with the PolyDataMapper
121  //
122  if (this->ClippingPlanes != this->PolyDataMapper->GetClippingPlanes())
123  {
124  this->PolyDataMapper->SetClippingPlanes(this->ClippingPlanes);
125  }
126 
127  if (this->m_BoundingObject)
128  {
130  this->m_BoundingObject->GetGeometry()->CalculateBoundingBoxRelativeToTransform(0)->GetBounds();
131  this->GeometryExtractor->SetExtent(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
132  this->GeometryExtractor->ExtentClippingOn();
133  }
134  else
135  {
136  this->GeometryExtractor->ExtentClippingOff();
137  }
138 
139  this->GeometryExtractor->SetInputData(this->GetInput());
140  this->PolyDataMapper->SetInputConnection(this->GeometryExtractor->GetOutputPort());
141 
142  // update ourselves in case something has changed
143  this->PolyDataMapper->SetLookupTable(this->GetLookupTable());
144  this->PolyDataMapper->SetScalarVisibility(this->GetScalarVisibility());
145  this->PolyDataMapper->SetUseLookupTableScalarRange(this->GetUseLookupTableScalarRange());
146  this->PolyDataMapper->SetScalarRange(this->GetScalarRange());
147  this->PolyDataMapper->SetImmediateModeRendering(this->GetImmediateModeRendering());
148  this->PolyDataMapper->SetColorMode(this->GetColorMode());
149  this->PolyDataMapper->SetInterpolateScalarsBeforeMapping(this->GetInterpolateScalarsBeforeMapping());
150 
151  this->PolyDataMapper->SetScalarMode(this->GetScalarMode());
152  if (this->ScalarMode == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA ||
153  this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA)
154  {
155  if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_ID)
156  {
157  this->PolyDataMapper->ColorByArrayComponent(this->ArrayId, ArrayComponent);
158  }
159  else
160  {
161  this->PolyDataMapper->ColorByArrayComponent(this->ArrayName, ArrayComponent);
162  }
163  }
164 
165  this->PolyDataMapper->Render(ren, act);
166  this->TimeToDraw = this->PolyDataMapper->GetTimeToDraw();
167 }
168 
169 //----------------------------------------------------------------------------
170 void vtkUnstructuredGridMapper::PrintSelf(ostream &os, vtkIndent indent)
171 {
172  this->Superclass::PrintSelf(os, indent);
173 
174  if (this->PolyDataMapper)
175  {
176  os << indent << "Poly Mapper: (" << this->PolyDataMapper << ")\n";
177  }
178  else
179  {
180  os << indent << "Poly Mapper: (none)\n";
181  }
182 
183  if (this->GeometryExtractor)
184  {
185  os << indent << "Geometry Extractor: (" << this->GeometryExtractor << ")\n";
186  }
187  else
188  {
189  os << indent << "Geometry Extractor: (none)\n";
190  }
191 }
192 
193 //----------------------------------------------------------------------------
195 {
196  unsigned long mTime = this->vtkMapper::GetMTime();
197  unsigned long time;
198 
199  if (this->LookupTable != NULL)
200  {
201  time = this->LookupTable->GetMTime();
202  mTime = (time > mTime ? time : mTime);
203  }
204 
205  return mTime;
206 }
207 
208 //----------------------------------------------------------------------------
209 int vtkUnstructuredGridMapper::FillInputPortInformation(int vtkNotUsed(port), vtkInformation *info)
210 {
211  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid");
212  return 1;
213 }
214 
215 //----------------------------------------------------------------------------
216 void vtkUnstructuredGridMapper::ReportReferences(vtkGarbageCollector *collector)
217 {
218  this->Superclass::ReportReferences(collector);
219  // These filters share our input and are therefore involved in a
220  // reference loop.
221  vtkGarbageCollectorReport(collector, this->GeometryExtractor, "GeometryExtractor");
222  vtkGarbageCollectorReport(collector, this->PolyDataMapper, "PolyDataMapper");
223 }
mitk::BoundingObject::Pointer m_BoundingObject
void SetInput(vtkUnstructuredGrid *input)
vtkStandardNewMacro(vtkUnstructuredGridMapper)
Organizes the rendering process.
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void ReportReferences(vtkGarbageCollector *) override
static void info(const char *fmt,...)
Definition: svm.cpp:100
void Render(vtkRenderer *ren, vtkActor *act) override
superclass of all bounding objects (cylinder, cuboid,...)
void ReleaseGraphicsResources(vtkWindow *) override
void SetBoundingObject(mitk::BoundingObject *bo)
virtual int FillInputPortInformation(int port, vtkInformation *info) override
vtkRenderer * GetVtkRenderer() const
BoundingBoxType::BoundsArrayType BoundsArrayType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.