File: vtkPainter.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (369 lines) | stat: -rw-r--r-- 10,794 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPainter.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

/*
 * Copyright 2004 Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the
 * U.S. Government. Redistribution and use in source and binary forms, with
 * or without modification, are permitted provided that this Notice and any
 * statement of authorship are reproduced on all copies.
 */

#include "vtkPainter.h"

#include "vtkCellData.h"
#include "vtkCommand.h"
#include "vtkDataSet.h"
#include "vtkDebugLeaks.h"
#include "vtkGarbageCollector.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkTimerLog.h"

vtkCxxSetObjectMacro(vtkPainter, Input, vtkDataObject);
vtkCxxSetObjectMacro(vtkPainter, Information, vtkInformation);
vtkInformationKeyMacro(vtkPainter, STATIC_DATA, Integer);
vtkInformationKeyMacro(vtkPainter, CONSERVE_MEMORY, Integer);
vtkInformationKeyMacro(vtkPainter, HIGH_QUALITY, Integer);
//-----------------------------------------------------------------------------
class vtkPainterObserver : public vtkCommand
{
public:
  static vtkPainterObserver* New()
    { return new vtkPainterObserver; }

  virtual void Execute(vtkObject *caller,
    unsigned long event, void* vtkNotUsed(v))
    {
    vtkPainter* delegate = vtkPainter::SafeDownCast(caller);
    if (delegate && event == vtkCommand::ProgressEvent && this->Self)
      {
      this->Self->UpdateDelegateProgress(delegate, delegate->GetProgress());
      }
    }

  vtkPainter* Self;
};

//-----------------------------------------------------------------------------
vtkPainter::vtkPainter()
{
  this->Input = 0;
  this->DelegatePainter = NULL;
  this->LastWindow = 0;

  this->Progress = 0.0;
  this->ProgressOffset = 0.0;
  this->ProgressScaleFactor = 1.0;

  this->Observer = vtkPainterObserver::New();
  this->Observer->Self = this;

  this->TimeToDraw = 0.0;
  this->Timer = vtkTimerLog::New();

  this->Information = NULL;
  vtkInformation* temp = vtkInformation::New();
  this->SetInformation(temp);
  temp->Delete();

  vtkPainter::STATIC_DATA()->Set(this->Information, 0);
  vtkPainter::CONSERVE_MEMORY()->Set(this->Information, 0);
  vtkPainter::HIGH_QUALITY()->Set(this->Information, 1);
}

//-----------------------------------------------------------------------------
vtkPainter::~vtkPainter()
{
  this->SetInput(0);
  this->Observer->Self = NULL;
  this->Observer->Delete();

  this->SetDelegatePainter(NULL);
  this->SetInformation(NULL);

  if (this->LastWindow)
    {
    this->ReleaseGraphicsResources(this->LastWindow);
    this->LastWindow = 0;
    }

  this->Timer->Delete();
}

//-----------------------------------------------------------------------------
void vtkPainter::UpdateProgress(double amount)
{
  this->Progress = amount;
  this->InvokeEvent(vtkCommand::ProgressEvent,
    reinterpret_cast<void *>(&amount));
}

//-----------------------------------------------------------------------------
void vtkPainter::UpdateDelegateProgress(vtkPainter* vtkNotUsed(delegate),
  double amount)
{
  double scaled_amount = this->ProgressOffset +
    this->ProgressScaleFactor * amount;
  this->UpdateProgress(scaled_amount);
}

//-----------------------------------------------------------------------------
double vtkPainter::GetTimeToDraw()
{
  double time = this->TimeToDraw;
  if (this->DelegatePainter)
    {
    time += this->DelegatePainter->GetTimeToDraw();
    }
  return time;
}
//-----------------------------------------------------------------------------
void vtkPainter::ReleaseGraphicsResources(vtkWindow *w)
{
  if (this->DelegatePainter)
    {
    this->DelegatePainter->ReleaseGraphicsResources(w);
    }
}

//-----------------------------------------------------------------------------
void vtkPainter::Register(vtkObjectBase *o)
{
  this->RegisterInternal(o, 1);
}

//-----------------------------------------------------------------------------
void vtkPainter::UnRegister(vtkObjectBase *o)
{
  this->UnRegisterInternal(o, 1);
}

//-----------------------------------------------------------------------------
void vtkPainter::SetDelegatePainter(vtkPainter* delegate)
{
  if (this->DelegatePainter)
    {
    this->DelegatePainter->RemoveObserver(this->Observer);
    }

  vtkSetObjectBodyMacro(DelegatePainter, vtkPainter, delegate);

  if (this->DelegatePainter)
    {
    this->ObserverPainterProgress(this->DelegatePainter);
    }
}

//-----------------------------------------------------------------------------
void vtkPainter::ObserverPainterProgress(vtkPainter* p)
{
  p->AddObserver(vtkCommand::ProgressEvent, this->Observer);
}

//-----------------------------------------------------------------------------
void vtkPainter::ReportReferences(vtkGarbageCollector *collector)
{
  this->Superclass::ReportReferences(collector);
  vtkGarbageCollectorReport(collector, this->DelegatePainter,
    "Delegate Painter");
  vtkGarbageCollectorReport(collector, this->Input, "Input");
}

//-----------------------------------------------------------------------------
void vtkPainter::Render(vtkRenderer* renderer, vtkActor* actor,
                        unsigned long typeflags, bool forceCompileOnly)
{
  this->TimeToDraw = 0.0;
  if (renderer->GetRenderWindow()->CheckAbortStatus())
    {
    return;
    }

  if (this->InformationProcessTime < this->Information->GetMTime())
    {
    // If the information object was modified, some subclass may
    // want to get the modified information.
    // Using ProcessInformation avoids the need to access the Information
    // object during each render, thus reducing unnecessary
    // expensive information key accesses.
    this->ProcessInformation(this->Information);
    this->InformationProcessTime.Modified();
    }

  this->PrepareForRendering(renderer, actor);
  this->RenderInternal(renderer, actor, typeflags,forceCompileOnly);
}

//-----------------------------------------------------------------------------
void vtkPainter::RenderInternal(vtkRenderer* renderer, vtkActor* actor,
                                unsigned long typeflags, bool forceCompileOnly)
{
  if (this->DelegatePainter)
    {
    this->UpdateDelegatePainter();
    this->DelegatePainter->Render(renderer, actor, typeflags,forceCompileOnly);
    }
}

//-----------------------------------------------------------------------------
void vtkPainter::UpdateDelegatePainter()
{
  this->PassInformation(this->DelegatePainter);
}

//-----------------------------------------------------------------------------
void vtkPainter::PassInformation(vtkPainter* toPainter)
{
  /*
  if (this->Information->GetMTime() >
  toPainter->GetInformation()->GetMTime())
  {
  // We have updated information, pass it on to
  // the delegate.
  // We do a shallow copy.
  toPainter->GetInformation()->Copy(this->Information);
  }
  */
  // TODO: I can't decide if the information must be copied
  // or referenced.
  if (this->Information !=  toPainter->GetInformation())
    {
    // We have updated information, pass it on to
    // the delegate.
    toPainter->SetInformation(this->Information);
    }

  // Propagate the data object through the painter chain.
  vtkDataObject* myoutput = this->GetOutput();
  if (myoutput != toPainter->GetInput())
    {
    toPainter->SetInput(myoutput);
    }
}

//-------------------------------------------------------------------------
void vtkPainter::UpdateBounds(double bounds[6])
{
  // only apply UpdateBounds on the delegate painter
  vtkPainter *painter = this->GetDelegatePainter();

  if(painter)
    {
    // delegate the task of updating the bounds
    painter->UpdateBounds(bounds);
    }
}

//-----------------------------------------------------------------------------
// Description:
// Helper method to get input array to process.
vtkAbstractArray* vtkPainter::GetInputArrayToProcess(int fieldAssociation,
  int fieldAttributeType,
  vtkDataSet* inputDS,
  bool *use_cell_data)
{
  if (use_cell_data)
    {
    *use_cell_data = false;
    }
  if (fieldAssociation == vtkDataObject::FIELD_ASSOCIATION_POINTS)
    {
    return inputDS->GetPointData()->GetAbstractAttribute(fieldAttributeType);
    }

  if (fieldAssociation == vtkDataObject::FIELD_ASSOCIATION_POINTS_THEN_CELLS)
    {
    vtkAbstractArray* array =
      inputDS->GetPointData()->GetAbstractAttribute(fieldAttributeType);
    if (array)
      {
      return array;
      }
    }

  if (use_cell_data)
    {
    *use_cell_data = true;
    }
  return inputDS->GetCellData()->GetAbstractAttribute(fieldAttributeType);
}

//-----------------------------------------------------------------------------
// Description:
// Helper method to get input array to process.
vtkAbstractArray* vtkPainter::GetInputArrayToProcess(int fieldAssociation,
  const char* name, vtkDataSet* inputDS, bool *use_cell_data)
{
  if (use_cell_data)
    {
    *use_cell_data = false;
    }
  if (fieldAssociation == vtkDataObject::FIELD_ASSOCIATION_POINTS)
    {
    return inputDS->GetPointData()->GetAbstractArray(name);
    }

  if (fieldAssociation == vtkDataObject::FIELD_ASSOCIATION_POINTS_THEN_CELLS)
    {
    vtkAbstractArray* array =
      inputDS->GetPointData()->GetAbstractArray(name);
    if (array)
      {
      return array;
      }
    }

  if (use_cell_data)
    {
    *use_cell_data = true;
    }
  return inputDS->GetCellData()->GetAbstractArray(name);
}

//-----------------------------------------------------------------------------
void vtkPainter::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "Input: " << this->Input << endl;
  os << indent << "TimeToDraw: " << this->TimeToDraw << endl;
  os << indent << "Progress: " << this->Progress << endl;
  os << indent << "Information: " ;
  if (this->Information)
    {
    os << endl;
    this->Information->PrintSelf(os, indent.GetNextIndent());
    }
  else
    {
    os << "(none)" << endl;
    }

  os << indent << "DelegatePainter: " ;
  if (this->DelegatePainter)
    {
    os << endl;
    this->DelegatePainter->PrintSelf(os, indent.GetNextIndent());
    }
  else
    {
    os << "(none)" << endl;
    }
}