vtkImageCache.cxx 16.2 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
/*=========================================================================
2
3

  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkImageCache.cxx
5
6
7
  Language:  C++
  Date:      $Date$
  Version:   $Revision$
8
  Thanks:    Thanks to C. Charles Law who developed this class.
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

Copyright (c) 1993-1995 Ken Martin, Will Schroeder, Bill Lorensen.

This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.

The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

=========================================================================*/
Charles Law's avatar
Charles Law committed
40
#include "vtkImageToStructuredPoints.h"
Charles Law's avatar
Charles Law committed
41
#include "vtkImageSource.h"
Ken Martin's avatar
Ken Martin committed
42
#include "vtkImageCache.h"
43
44
45

//----------------------------------------------------------------------------
// Description:
46
// Constructor:  By default caches ReleaseDataFlags are turned off. However,
Charles Law's avatar
Charles Law committed
47
// the vtkImageSource method CheckCache, which create a default cache, 
48
// turns this flag on.  If a cache is created and set explicitely, by 
49
// default it saves its data between generates.  But if the cache is created
Charles Law's avatar
Charles Law committed
50
// automatically by the vtkImageSource, it does not.
51
52
vtkImageCache::vtkImageCache()
{
53
54
  int idx;
  
Ken Martin's avatar
Ken Martin committed
55
  for (idx = 0; idx < 3; ++idx)
56
    {
Charles Law's avatar
Charles Law committed
57
58
    this->UpdateExtent[idx*2] = -VTK_LARGE_INTEGER;
    this->UpdateExtent[idx*2+1] = VTK_LARGE_INTEGER;
Ken Martin's avatar
Ken Martin committed
59
    this->WholeExtent[idx*2] = this->WholeExtent[idx*2+1] = 0;
Will Schroeder's avatar
Will Schroeder committed
60
    this->Spacing[idx] = 1.0;
61
62
    this->Origin[idx] = 0.0;
    }
Charles Law's avatar
Charles Law committed
63

64
  this->Source = NULL;
65
  
Charles Law's avatar
Charles Law committed
66
67
68
69
70
71
72
73
  // for automatic conversion
  this->ImageToStructuredPoints = NULL;

  // default is to save data,
  // (But caches automatically created by sources set ReleaseDataFlag to 1)
  this->ReleaseDataFlag = 0;
  this->DataReleased = 1;
  
74
  // Invalid data type
Charles Law's avatar
Charles Law committed
75
  // This will be changed when the filter gets updated or
Charles Law's avatar
Charles Law committed
76
77
  // the ScalarType is set explicitly
  this->ScalarType = VTK_VOID;
Ken Martin's avatar
Ken Martin committed
78
79
80
  this->NumberOfScalarComponents = 0;
  
  this->MemoryLimit = 500000;   // 500 MB
81
82
83
84
85
86
}


//----------------------------------------------------------------------------
vtkImageCache::~vtkImageCache()
{
Charles Law's avatar
Charles Law committed
87
88
89
90
  if (this->ImageToStructuredPoints)
    {
    this->ImageToStructuredPoints->Delete();
    }
Charles Law's avatar
Charles Law committed
91
  this->ReleaseData();
92
93
}

Charles Law's avatar
Charles Law committed
94
95
96
//----------------------------------------------------------------------------
void vtkImageCache::PrintSelf(ostream& os, vtkIndent indent)
{
97
98
  int idx;
  
99
  vtkReferenceCount::PrintSelf(os,indent);
Charles Law's avatar
Charles Law committed
100

Ken Martin's avatar
Ken Martin committed
101
102
103
  os << indent << "MemoryLimit: " << this->MemoryLimit << endl;
  os << indent << "NumberOfScalarComponents: " << 
    this->NumberOfScalarComponents << endl;
Charles Law's avatar
Charles Law committed
104
105
  os << indent << "Source: (" << this->Source << ").\n";
  os << indent << "ReleaseDataFlag: " << this->ReleaseDataFlag << "\n";
106
  os << indent << "ScalarType: "<<vtkImageScalarTypeNameMacro(this->ScalarType)
Charles Law's avatar
Charles Law committed
107
     << "\n";
108
109
  os << indent << "ImageToStructuredPoints: (" 
     << this->ImageToStructuredPoints << ")\n";
110
111
  
  os << indent << "Spacing: (" << this->Spacing[0];
Ken Martin's avatar
Ken Martin committed
112
  for (idx = 1; idx < 3; ++idx)
113
114
115
116
117
118
    {
    os << ", " << this->Spacing[idx];
    }
  os << ")\n";
  
  os << indent << "Origin: (" << this->Origin[0];
Ken Martin's avatar
Ken Martin committed
119
  for (idx = 1; idx < 3; ++idx)
120
121
122
123
124
    {
    os << ", " << this->Origin[idx];
    }
  os << ")\n";
  
Charles Law's avatar
Charles Law committed
125
  os << indent << "WholeExtent: (" << this->WholeExtent[0];
Ken Martin's avatar
Ken Martin committed
126
  for (idx = 1; idx < 6; ++idx)
127
    {
Charles Law's avatar
Charles Law committed
128
    os << ", " << this->WholeExtent[idx];
129
130
    }
  os << ")\n";
Charles Law's avatar
Charles Law committed
131
132

  os << indent << "UpdateExtent: (" << this->UpdateExtent[0];
Ken Martin's avatar
Ken Martin committed
133
  for (idx = 1; idx < 6; ++idx)
134
    {
Charles Law's avatar
Charles Law committed
135
    os << ", " << this->UpdateExtent[idx];
136
137
    }
  os << ")\n";
Ken Martin's avatar
Ken Martin committed
138
}
Charles Law's avatar
Charles Law committed
139
  
Ken Martin's avatar
Ken Martin committed
140
141
142
143
144
    
//----------------------------------------------------------------------------
void vtkImageCache::GetAxisUpdateExtent(int idx, int &min, int &max)
{
  if (idx > 2)
Charles Law's avatar
Charles Law committed
145
    {
Ken Martin's avatar
Ken Martin committed
146
147
    vtkWarningMacro("illegal axis!");
    return;
Charles Law's avatar
Charles Law committed
148
    }
Charles Law's avatar
Charles Law committed
149

Ken Martin's avatar
Ken Martin committed
150
151
  min = this->UpdateExtent[idx*2];
  max = this->UpdateExtent[idx*2+1];
Charles Law's avatar
Charles Law committed
152
}
Ken Martin's avatar
Ken Martin committed
153
154
155
156
157

//----------------------------------------------------------------------------
void vtkImageCache::SetAxisUpdateExtent(int idx, int min, int max)
{
  int modified = 0;
Charles Law's avatar
Charles Law committed
158
  
Ken Martin's avatar
Ken Martin committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  if (idx > 2)
    {
    vtkWarningMacro("illegal axis!");
    return;
    }
  
  if (this->UpdateExtent[idx*2] != min)
    {
    modified = 1;
    this->UpdateExtent[idx*2] = min;
    }
  if (this->UpdateExtent[idx*2+1] != max)
    {
    modified = 1;
    this->UpdateExtent[idx*2+1] = max;
    }

  if (modified)
    {
    this->Modified();
    }
}
181

Charles Law's avatar
Charles Law committed
182
//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
183
void vtkImageCache::SetUpdateExtent(int extent[6])
Charles Law's avatar
Charles Law committed
184
185
186
{
  int idx, modified = 0;
  
Ken Martin's avatar
Ken Martin committed
187
  for (idx = 0; idx < 6; ++idx)
Charles Law's avatar
Charles Law committed
188
189
190
191
192
193
194
195
196
197
198
199
200
201
    {
    if (this->UpdateExtent[idx] != extent[idx])
      {
      modified = 1;
      this->UpdateExtent[idx] = extent[idx];
      }
    }
  if (modified)
    {
    this->Modified();
    }
}
//----------------------------------------------------------------------------
void vtkImageCache::SetUpdateExtent(int xMin, int xMax, int yMin, int yMax,
Ken Martin's avatar
Ken Martin committed
202
				    int zMin, int zMax)
Charles Law's avatar
Charles Law committed
203
{
Ken Martin's avatar
Ken Martin committed
204
  int extent[6];
205

Charles Law's avatar
Charles Law committed
206
207
208
  extent[0] = xMin; extent[1] = xMax;
  extent[2] = yMin; extent[3] = yMax;
  extent[4] = zMin; extent[5] = zMax;
Charles Law's avatar
Charles Law committed
209
210
  
  this->SetUpdateExtent(extent);
Charles Law's avatar
Charles Law committed
211
}
Ken Martin's avatar
Ken Martin committed
212

Charles Law's avatar
Charles Law committed
213
214
215
//----------------------------------------------------------------------------
void vtkImageCache::SetUpdateExtentToWholeExtent()
{
Ken Martin's avatar
Ken Martin committed
216
217
218
219
220
221
222
223
  unsigned long pipelineMTime = this->GetPipelineMTime();
  
  // update if mtime indicates to do so
  if (pipelineMTime > this->ExecuteTime)
    {
    // Make sure image information is upto date
    this->UpdateImageInformation();
    }
Charles Law's avatar
Charles Law committed
224
225
  this->SetUpdateExtent(this->WholeExtent);
}
226
227
228


//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
229
void vtkImageCache::GetUpdateExtent(int extent[6])
230
{
Charles Law's avatar
Charles Law committed
231
232
  int idx;
  
Ken Martin's avatar
Ken Martin committed
233
  for (idx = 0; idx < 6; ++idx)
Charles Law's avatar
Charles Law committed
234
235
236
237
238
239
    {
    extent[idx] = this->UpdateExtent[idx];
    }
}
//----------------------------------------------------------------------------
void vtkImageCache::GetUpdateExtent(int &xMin, int &xMax, int &yMin, int &yMax,
Ken Martin's avatar
Ken Martin committed
240
				    int &zMin, int &zMax)
Charles Law's avatar
Charles Law committed
241
242
{
  xMin = this->UpdateExtent[0]; xMax = this->UpdateExtent[1];
Ken Martin's avatar
Ken Martin committed
243
244
  yMin = this->UpdateExtent[2]; yMax = this->UpdateExtent[3];
  zMin = this->UpdateExtent[4]; zMax = this->UpdateExtent[5];
245
246
}

247
248
//----------------------------------------------------------------------------
// Description:
Charles Law's avatar
Charles Law committed
249
250
251
252
253
254
// This method updates the instance variables "WholeExtent", "Spacing", 
// "Origin", "Bounds" etc.
// It needs to be separate from "Update" because the image information
// may be needed to compute the required UpdateExtent of the input
// (see "vtkImageFilter").
void vtkImageCache::UpdateImageInformation()
255
{
Ken Martin's avatar
Ken Martin committed
256
257
258
259
  unsigned long pipelineMTime = this->GetPipelineMTime();
  
  // update if mtime indicates to do so
  if (this->Source && pipelineMTime > this->ExecuteTime)
Charles Law's avatar
Charles Law committed
260
261
262
    {
    this->Source->UpdateImageInformation();
    }
263
264
265
266
}

//----------------------------------------------------------------------------
// Description:
Charles Law's avatar
Charles Law committed
267
268
// Clip updateExtent so it will nopt be larger than WHoleExtent
void vtkImageCache::ClipUpdateExtentWithWholeExtent()
269
{
270
  int idx;
Charles Law's avatar
Charles Law committed
271
272
  
  // Clip the UpdateExtent with the WholeExtent
Ken Martin's avatar
Ken Martin committed
273
  for (idx = 0; idx < 3; ++idx)
274
    {
Charles Law's avatar
Charles Law committed
275
276
    // min
    if (this->UpdateExtent[idx*2] < this->WholeExtent[idx*2])
277
      {
Charles Law's avatar
Charles Law committed
278
      this->UpdateExtent[idx*2] = this->WholeExtent[idx*2];
279
      }
Charles Law's avatar
Charles Law committed
280
    if (this->UpdateExtent[idx*2] > this->WholeExtent[idx*2+1])
281
      {
Charles Law's avatar
Charles Law committed
282
      this->UpdateExtent[idx*2] = this->WholeExtent[idx*2+1];
283
      }
Charles Law's avatar
Charles Law committed
284
285
    // max
    if (this->UpdateExtent[idx*2+1] < this->WholeExtent[idx*2])
286
      {
Charles Law's avatar
Charles Law committed
287
288
289
290
291
      this->UpdateExtent[idx*2+1] = this->WholeExtent[idx*2];
      }
    if (this->UpdateExtent[idx*2+1] > this->WholeExtent[idx*2+1])
      {
      this->UpdateExtent[idx*2+1] = this->WholeExtent[idx*2+1];
292
      }
293
    }
Charles Law's avatar
Charles Law committed
294
}
295

Charles Law's avatar
Charles Law committed
296
297
298
299
300
301
//----------------------------------------------------------------------------
// Description:
// Make this a separate method to avoid another GetPipelineMTime call.
unsigned long vtkImageCache::GetPipelineMTime()
{
  if (this->Source)
302
    {
Charles Law's avatar
Charles Law committed
303
304
305
    // We do not tak this objects MTime into consideration, 
    // but maybe we should.
    return this->Source->GetPipelineMTime();
306
    }
Charles Law's avatar
Charles Law committed
307
  return this->GetMTime();
308
309
}

Charles Law's avatar
Charles Law committed
310
311

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
312
void vtkImageCache::SetWholeExtent(int extent[6])
Charles Law's avatar
Charles Law committed
313
314
315
{
  int idx, modified = 0;
  
Ken Martin's avatar
Ken Martin committed
316
  for (idx = 0; idx < 6; ++idx)
317
    {
Charles Law's avatar
Charles Law committed
318
319
320
321
322
    if (this->WholeExtent[idx] != extent[idx])
      {
      modified = 1;
      this->WholeExtent[idx] = extent[idx];
      }
323
    }
Charles Law's avatar
Charles Law committed
324
  if (modified)
325
    {
Charles Law's avatar
Charles Law committed
326
    this->Modified();
327
328
    }
}
Charles Law's avatar
Charles Law committed
329
//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
330
331
void vtkImageCache::SetWholeExtent(int xMin, int xMax,
				   int yMin, int yMax, int zMin, int zMax)
Charles Law's avatar
Charles Law committed
332
{
Ken Martin's avatar
Ken Martin committed
333
  int extent[6];
334

Charles Law's avatar
Charles Law committed
335
336
337
338
339
  extent[0] = xMin; extent[1] = xMax;
  extent[2] = yMin; extent[3] = yMax;
  extent[4] = zMin; extent[5] = zMax;
  this->SetWholeExtent(extent);
}
340
341

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
342
void vtkImageCache::GetWholeExtent(int extent[6])
343
344
345
{
  int idx;
  
Ken Martin's avatar
Ken Martin committed
346
  for (idx = 0; idx < 6; ++idx)
347
    {
Charles Law's avatar
Charles Law committed
348
    extent[idx] = this->WholeExtent[idx];
349
    }
Charles Law's avatar
Charles Law committed
350
351
352
}
//----------------------------------------------------------------------------
void vtkImageCache::GetWholeExtent(int &xMin, int &xMax, int &yMin, int &yMax,
Ken Martin's avatar
Ken Martin committed
353
				   int &zMin, int &zMax)
Charles Law's avatar
Charles Law committed
354
355
{
  xMin = this->WholeExtent[0]; xMax = this->WholeExtent[1];
Ken Martin's avatar
Ken Martin committed
356
357
  yMin = this->WholeExtent[2]; yMax = this->WholeExtent[3];
  zMin = this->WholeExtent[4]; zMax = this->WholeExtent[5];
358
359
360
}

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
361
void vtkImageCache::GetDimensions(int dimensions[3])
362
363
364
{
  int idx;
  
Ken Martin's avatar
Ken Martin committed
365
  for (idx = 0; idx < 3; ++idx)
366
    {
Ken Martin's avatar
Ken Martin committed
367
368
    dimensions[idx] = this->WholeExtent[idx*2+1] - 
      this->WholeExtent[idx*2] + 1;
369
    }
Charles Law's avatar
Charles Law committed
370
371
}
//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
372
void vtkImageCache::GetDimensions(int &x, int &y, int &z)
Charles Law's avatar
Charles Law committed
373
{
Ken Martin's avatar
Ken Martin committed
374
375
376
  x = this->WholeExtent[1] - this->WholeExtent[0] + 1;
  y = this->WholeExtent[3] - this->WholeExtent[2] + 1;
  z = this->WholeExtent[5] - this->WholeExtent[4] + 1;
Charles Law's avatar
Charles Law committed
377
378
}

379
//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
380
void vtkImageCache::GetCenter(float center[3])
381
382
383
{
  int idx;
  
Ken Martin's avatar
Ken Martin committed
384
  for (idx = 0; idx < 3; ++idx)
385
    {
Ken Martin's avatar
Ken Martin committed
386
387
388
    center[idx] = this->Origin[idx] + 
      this->Spacing[idx] * (this->WholeExtent[idx*2+1] 
			    - this->WholeExtent[idx*2] + 1)/2.0;
389
    }
Charles Law's avatar
Charles Law committed
390
391
}
//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
392
void vtkImageCache::GetCenter(float &x, float &y, float &z)
Charles Law's avatar
Charles Law committed
393
{
Ken Martin's avatar
Ken Martin committed
394
395
396
397
398
399
  x = this->Origin[0] + 
    this->Spacing[0] * (this->WholeExtent[1] - this->WholeExtent[0] + 1)/2.0;
  y = this->Origin[1] + 
    this->Spacing[1] * (this->WholeExtent[3] - this->WholeExtent[2] + 1)/2.0;
  z = this->Origin[2] + 
    this->Spacing[2] * (this->WholeExtent[5] - this->WholeExtent[4] + 1)/2.0;
400
401
402
}

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
403
void vtkImageCache::GetBounds(float bounds[6])
404
405
406
{
  int idx;
  
Ken Martin's avatar
Ken Martin committed
407
  for (idx = 0; idx < 3; ++idx)
408
    {
Ken Martin's avatar
Ken Martin committed
409
410
411
412
    bounds[idx*2] = this->Origin[idx] + this->Spacing[idx] * 
      this->WholeExtent[idx*2];
    bounds[idx*2+1] = this->Origin[idx] + this->Spacing[idx] * 
      this->WholeExtent[idx*2+1];
413
    }
Charles Law's avatar
Charles Law committed
414
415
416
417
}
//----------------------------------------------------------------------------
void 
vtkImageCache::GetBounds(float &xMin, float &xMax, float &yMin, float &yMax,
Ken Martin's avatar
Ken Martin committed
418
			 float &zMin, float &zMax)
Charles Law's avatar
Charles Law committed
419
{
Ken Martin's avatar
Ken Martin committed
420
421
422
423
424
425
  xMin = this->Origin[0] + this->Spacing[0] * this->WholeExtent[0];
  xMax = this->Origin[0] + this->Spacing[0] * this->WholeExtent[1];
  yMin = this->Origin[1] + this->Spacing[1] * this->WholeExtent[2];
  yMax = this->Origin[1] + this->Spacing[1] * this->WholeExtent[3];
  zMin = this->Origin[2] + this->Spacing[2] * this->WholeExtent[4];
  zMax = this->Origin[2] + this->Spacing[2] * this->WholeExtent[5];
Charles Law's avatar
Charles Law committed
426
427
}

Charles Law's avatar
Charles Law committed
428
//----------------------------------------------------------------------------
Charles Law's avatar
Charles Law committed
429
430
void vtkImageCache::SetGlobalReleaseDataFlag(int val)
{
Ken Martin's avatar
Ken Martin committed
431
  vtkDataSet::SetGlobalReleaseDataFlag(val);
Charles Law's avatar
Charles Law committed
432
433
}

Charles Law's avatar
Charles Law committed
434
//----------------------------------------------------------------------------
Charles Law's avatar
Charles Law committed
435
436
int  vtkImageCache::GetGlobalReleaseDataFlag()
{
Ken Martin's avatar
Ken Martin committed
437
  return vtkDataSet::GetGlobalReleaseDataFlag();
Charles Law's avatar
Charles Law committed
438
439
440
441
442
}

//----------------------------------------------------------------------------
// Description:
// Return flag indicating whether data should be released after use  
Ken Martin's avatar
Ken Martin committed
443
// by a filter. 
Charles Law's avatar
Charles Law committed
444
445
int vtkImageCache::ShouldIReleaseData()
{
Ken Martin's avatar
Ken Martin committed
446
447
448
  if ( vtkDataSet::GetGlobalReleaseDataFlag() || 
       this->ReleaseDataFlag ) return 1;
  else return 0;
Charles Law's avatar
Charles Law committed
449
450
451
452
453
454
455
456
457
}

//----------------------------------------------------------------------------
// Description:
// This method returns the memory that would be required for scalars on update.
// The returned value is in units KBytes.
// This method is used for determining when to stream.
long vtkImageCache::GetUpdateExtentMemorySize()
{
Ken Martin's avatar
Ken Martin committed
458
  long size = this->NumberOfScalarComponents;
Charles Law's avatar
Charles Law committed
459
460
461
  int idx;
  
  // Compute the number of scalars.
Ken Martin's avatar
Ken Martin committed
462
  for (idx = 0; idx < 3; ++idx)
Charles Law's avatar
Charles Law committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
    {
    size *= (this->UpdateExtent[idx*2+1] - this->UpdateExtent[idx*2] + 1);
    }
  
  // Consider the size of each scalar.
  switch (this->ScalarType)
    {
    case VTK_FLOAT:
      size *= sizeof(float);
      break;
    case VTK_INT:
      size *= sizeof(int);
      break;
    case VTK_SHORT:
      size *= sizeof(short);
      break;
    case VTK_UNSIGNED_SHORT:
      size *= sizeof(unsigned short);
      break;
    case VTK_UNSIGNED_CHAR:
      size *= sizeof(unsigned char);
      break;
    default:
      vtkWarningMacro(<< "GetExtentMemorySize: "
        << "Cannot determine input scalar type");
    }  

  // In case the extent is set improperly
  if (size < 0)
    {
    vtkErrorMacro("GetExtentMemorySize: Computed value negative: " << size);
    return 0;
    }
  
  return size / 1000;
}


//----------------------------------------------------------------------------
// Description:  
// This method is used translparently by the "SetInput(vtkImageCache *)"
Charles Law's avatar
Charles Law committed
504
505
506
507
508
509
// method to connect the image pipeline to the visualization pipeline.
vtkImageToStructuredPoints *vtkImageCache::GetImageToStructuredPoints()
{
  if ( ! this->ImageToStructuredPoints)
    {
    this->ImageToStructuredPoints = vtkImageToStructuredPoints::New();
Charles Law's avatar
Charles Law committed
510
    this->ImageToStructuredPoints->SetInput(this);
Charles Law's avatar
Charles Law committed
511
512
513
514
    }
  
  return this->ImageToStructuredPoints;
}
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530

//----------------------------------------------------------------------------
// Check to see if we own an ImageToStructuredPoints which has registered
// this cache.
void vtkImageCache::UnRegister(vtkObject* o)
{
  // this is the special test. I own ImageToStructuredPoints, but it has registered me.
  if (this->GetReferenceCount() == 2 && this->ImageToStructuredPoints != NULL &&
      this->ImageToStructuredPoints->GetInput() == this)
    {
    vtkImageToStructuredPoints *temp = this->ImageToStructuredPoints;
    this->ImageToStructuredPoints = NULL;    
    temp->Delete();
    }

  this->vtkReferenceCount::UnRegister(o);  
531
}
532

533
534
535
536
537
538
539
//----------------------------------------------------------------------------
float *vtkImageCache::GetScalarRange()
{
  static float range[2];
  this->GetScalarRange(range);
  return range;
}
540
541
542
543