]> Creatis software - creaRigidRegistration.git/blob - lib/Convolution.cxx
*** empty log message ***
[creaRigidRegistration.git] / lib / Convolution.cxx
1 #include "Convolution.h"
2
3 /*
4 * Constructor
5 */
6 //------------------------------------------------------------
7 Convolution::Convolution()
8 {
9         _image=NULL;
10         _convolve = vtkImageConvolve::New();
11         _cast = vtkImageCast::New();
12 }
13
14 /*
15 * Destructor
16 */
17 //------------------------------------------------------------
18 Convolution::~Convolution()
19 {
20         if (_convolve != NULL ) { _convolve->Delete(); }
21         if (_cast != NULL ) { _cast->Delete(); }
22 }
23
24 vtkImageData *Convolution::getImage()
25 {
26         return _cast->GetOutput();
27 }
28
29 void Convolution::setImage(vtkImageData *image)
30 {
31         _image = image;
32         _convolve->SetInput(_image);
33 }
34
35 void Convolution::setFactor(double factor)
36 {
37         _factor = (factor/100.0)*5.0;   
38 }
39
40 void Convolution::setOn(bool on)
41 {
42         _on = on;
43 }
44
45 void Convolution::Run()
46 {
47         if(_on)
48         {
49                 double kernel[] = {0.0,1.0,0.0,1.0,-_factor,1.0,0.0,1.0,0.0};
50                 _convolve->SetKernel3x3(kernel);
51                 _convolve->Update();
52                 _cast->SetInput(_convolve->GetOutput());
53                 //_cast->SetOutputScalarTypeToDouble();
54                 _cast->Update();
55         }
56         else
57         {
58                 _cast->SetInput(_image);
59                 _cast->SetOutputScalarType(_image->GetScalarType());
60                 _cast->Update();
61         }       
62 }