File: vtkITKImageToImageRegionFilter.h

package info (click to toggle)
volview 3.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 25,204 kB
  • sloc: cpp: 132,585; ansic: 11,612; tcl: 236; sh: 64; makefile: 25; xml: 8
file content (106 lines) | stat: -rw-r--r-- 2,919 bytes parent folder | download
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
/*=========================================================================

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/VolViewCopyright.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.

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

// .NAME vtkITKImageToImageRegionFilter - 

#ifndef __vtkITKImageToImageRegionFilter_h
#define __vtkITKImageToImageRegionFilter_h


#include "vtkITKImageToImageFilter.h"
#include "vtkImageClip.h"

class VTK_EXPORT vtkITKImageToImageRegionFilter : public vtkITKImageToImageFilter
{
public:
  static vtkITKImageToImageFilter *New()
    {
    return new vtkITKImageToImageRegionFilter;
    };
  
  vtkTypeMacro(vtkITKImageToImageRegionFilter, vtkITKImageToImageFilter);

  // Description:
  // Set the Input of the filter.
  virtual void SetInput(vtkImageData *input)
    {
    this->ImageClip->SetInput(input);
    this->ImageClip->ResetOutputWholeExtent();
    };

  // Description:
  // Return the input to the filter
  virtual vtkDataObject* GetInput()
    {
    return (vtkDataObject::SafeDownCast( this->vtkCast->GetInput() ));
    };

  virtual void SetROIExtent( int extent[6] )
    {
    this->ImageClip->SetOutputWholeExtent(extent);
    }

  virtual void SetROIBounds( double bounds[6] )
    {
    vtkImageData *image = vtkImageData::SafeDownCast(this->ImageClip->GetInput());
    if (image)
      {
      double inputVolumeOrigin[3], inputVolumeSpacing[3];
      int inputVolumeDimensions[3], idx[6];
      image->GetOrigin(inputVolumeOrigin);
      image->GetSpacing(inputVolumeSpacing);
      image->GetDimensions(inputVolumeDimensions);
    
      // convert bounds into indices that represent VTK extents
      for ( unsigned int j = 0; j < 6; ++j )
        {
        idx[j] = (int)( (bounds[j]-inputVolumeOrigin[j/2])/
                                 inputVolumeSpacing[j/2] + 0.5);

        // Truncate them if they go out of bounds
        if (idx[j] < 0) 
          {
          idx[j] = 0;
          }
        if (idx[j] >= inputVolumeDimensions[j/2])
          {
          idx[j] = inputVolumeDimensions[j/2] -1;
          }
        }

      this->SetROIExtent(idx);
      }
    }

 protected:

  vtkITKImageToImageRegionFilter()
    {
    // Need an import, export, and a ITK pipeline
    this->ImageClip = vtkImageClip::New();
    this->vtkCast->SetInput( this->ImageClip->GetOutput() );
    }

  ~vtkITKImageToImageRegionFilter()
    {
    this->ImageClip->Delete();
    }

  vtkImageClip * ImageClip;
  
private:
  vtkITKImageToImageRegionFilter(const vtkITKImageToImageRegionFilter&);  // Not implemented.
  void operator=(const vtkITKImageToImageRegionFilter&);  // Not implemented.
};

#endif