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