--- /dev/null
+#include"Math.h"
+#include"CreaImage.h"
+
+//-------------------------------------------------------------------------------------------
+CreaImage::CreaImage()
+{
+ orgImage = NULL;
+ matrixrotation = new matrixRotation();
+ transform = vtkTransform::New();
+}
+
+//-------------------------------------------------------------------------------------------
+CreaImage::~CreaImage()
+{
+ delete matrixrotation;
+ transform->Delete();
+}
+
+//-------------------------------------------------------------------------------------------
+void CreaImage::SetvtkImageData(vtkImageData *image)
+{
+ if (image!=NULL)
+ {
+ if (orgImage!=NULL)
+ {
+ // orgImage->Delete();
+ }
+ orgImage = vtkImageData::New();
+ orgImage->ShallowCopy(image);
+ orgImage = image;
+// orgImage->SetSpacing(1,1,1);
+ } else {
+ orgImage = NULL;
+ }
+}
+
+//-------------------------------------------------------------------------------------------
+void CreaImage::SetImagePositionPatient(double x,double y,double z)
+{
+ matrixrotation->SetOrigin(x,y,z);
+}
+
+//-------------------------------------------------------------------------------------------
+void CreaImage::SetImageSpacing(double sx, double sy, double sz)
+{
+ matrixrotation->SetSpacing(sx,sy,sz);
+}
+
+//-------------------------------------------------------------------------------------------
+void CreaImage::SetImageOrientation(double v1x,double v1y,double v1z, double v2x,double v2y,double v2z)
+{
+ matrixrotation->SetVector1( v1x , v1y , v1z );
+ matrixrotation->SetVector2( v2x , v2y , v2z );
+}
+
+//-------------------------------------------------------------------------------------------
+void CreaImage::Update()
+{
+ matrixrotation->GetTransformation(transform);
+}
+
+//-------------------------------------------------------------------------------------------
+vtkImageData *CreaImage::GetImage()
+{
+ return orgImage;
+}
+
+//-------------------------------------------------------------------------------------------
+vtkTransform *CreaImage::GetvtkTransform()
+{
+ return transform;
+}
+
+//-------------------------------------------------------------------------------------------
+double CreaImage::GetVoxelInIRMUniverse(double x,double y, double z)
+{
+ double result=0;
+ double pIn[3];
+ double pOut[3];
+
+ pIn[0]=x;
+ pIn[1]=y;
+ pIn[2]=z;
+
+ transform->TransformPoint( pIn , pOut );
+
+ int ext[6];
+ orgImage->GetExtent(ext);
+ int px=round(pOut[0]);
+ int py=round(pOut[1]);
+ int pz=round(pOut[2]);
+ if ( (px>=ext[0]) && (px<ext[1]) &&
+ (py>=ext[2]) && (py<ext[3]) &&
+ (pz>=ext[4]) && (pz<ext[5]) )
+ {
+ unsigned short *p = (unsigned short*) orgImage->GetScalarPointer( px,py,pz );
+ result = *p;
+ }
+ return result;
+
+}
+
+//-------------------------------------------------------------------------------------------
+double CreaImage::GetVoxelInImageUniverse(double x,double y, double z)
+{
+ double result=0;
+ int ext[6];
+ orgImage->GetExtent(ext);
+ int px=round(x);
+ int py=round(y);
+ int pz=round(z);
+ if ( (px>=ext[0]) && (px<ext[1]) &&
+ (py>=ext[2]) && (py<ext[3]) &&
+ (pz>=ext[4]) && (pz<ext[5]) )
+ {
+ unsigned short *p = (unsigned short*) orgImage->GetScalarPointer( px,py,pz );
+ result = *p;
+ }
+ return result;
+}
+