]> Creatis software - creaImageIO.git/blob - lib/TransformDicom3D/CreaImage.cxx
#3326 bbtk_Transform3Ddicom_PKG
[creaImageIO.git] / lib / TransformDicom3D / CreaImage.cxx
1 #include"Math.h"
2 #include"CreaImage.h"
3
4 //-------------------------------------------------------------------------------------------
5 CreaImage::CreaImage()
6 {
7         orgImage                        = NULL;
8         matrixrotation          = new matrixRotation();
9         transform                       = vtkTransform::New();  
10 }
11
12 //-------------------------------------------------------------------------------------------
13 CreaImage::~CreaImage()
14 {
15         delete matrixrotation;
16         transform->Delete();
17 }
18
19 //-------------------------------------------------------------------------------------------
20 void CreaImage::SetvtkImageData(vtkImageData *image)
21 {
22         if (image!=NULL)
23         {
24                 if (orgImage!=NULL)
25                 {
26                 //      orgImage->Delete();
27                 }
28                 orgImage = vtkImageData::New();
29                 orgImage->ShallowCopy(image);
30                 orgImage = image;
31 //              orgImage->SetSpacing(1,1,1);
32         } else {
33                 orgImage = NULL;
34         }
35 }
36
37 //-------------------------------------------------------------------------------------------
38 void CreaImage::SetImagePositionPatient(double x,double y,double z)
39 {
40         matrixrotation->SetOrigin(x,y,z);
41 }
42
43 //-------------------------------------------------------------------------------------------
44 void CreaImage::SetImageSpacing(double sx, double sy, double sz)
45 {
46         matrixrotation->SetSpacing(sx,sy,sz);
47 }
48
49 //-------------------------------------------------------------------------------------------
50 void CreaImage::SetImageOrientation(double v1x,double v1y,double v1z, double v2x,double v2y,double v2z)
51 {
52         matrixrotation->SetVector1( v1x , v1y , v1z );
53         matrixrotation->SetVector2( v2x , v2y , v2z );
54 }
55
56 //-------------------------------------------------------------------------------------------
57 void CreaImage::Update()
58 {
59         matrixrotation->GetTransformation(transform);   
60 }
61
62 //-------------------------------------------------------------------------------------------
63 vtkImageData *CreaImage::GetImage()
64 {
65         return orgImage;
66 }
67
68 //-------------------------------------------------------------------------------------------
69 vtkTransform *CreaImage::GetvtkTransform()
70 {
71         return transform;
72 }
73
74 //-------------------------------------------------------------------------------------------
75 double CreaImage::GetVoxelInIRMUniverse(double x,double y, double z)
76 {
77         double result=0;
78         double pIn[3];
79         double pOut[3];
80         
81         pIn[0]=x;
82         pIn[1]=y;
83         pIn[2]=z;
84
85     transform->TransformPoint( pIn , pOut );
86
87         int ext[6];
88         orgImage->GetExtent(ext);
89         int px=round(pOut[0]);
90         int py=round(pOut[1]);
91         int pz=round(pOut[2]);
92         if ( (px>=ext[0]) && (px<ext[1]) &&  
93                  (py>=ext[2]) && (py<ext[3]) && 
94                  (pz>=ext[4]) && (pz<ext[5])  ) 
95         {
96                 unsigned short *p = (unsigned short*) orgImage->GetScalarPointer( px,py,pz );
97                 result = *p;
98         }
99         return result;
100         
101 }
102
103 //-------------------------------------------------------------------------------------------
104 double CreaImage::GetVoxelInImageUniverse(double x,double y, double z)
105 {
106         double result=0;
107         int ext[6];
108         orgImage->GetExtent(ext);
109         int px=round(x);
110         int py=round(y);
111         int pz=round(z);
112         if ( (px>=ext[0]) && (px<ext[1]) &&  
113                  (py>=ext[2]) && (py<ext[3]) && 
114                  (pz>=ext[4]) && (pz<ext[5])  ) 
115         {
116                 unsigned short *p = (unsigned short*) orgImage->GetScalarPointer( px,py,pz );
117                 result = *p;
118         }
119         return result;
120 }
121