diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index e6da7b5..6aa63f6 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -17,6 +19,24 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) { updateImage(); } +vtkSmartPointer getMatrix() { + const double XMin = 0; + const double XMax = 661; + const double YMin = 0; + const double YMax = 661; + + double eyeTransform[] = { + 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), + 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + + auto matrix = vtkSmartPointer::New(); + matrix->DeepCopy(eyeTransform); + return matrix; +} + void BackgroundImage::updateImage() { @@ -26,16 +46,16 @@ void BackgroundImage::updateImage() { imageReader->SetFileName(this->imagePath.c_str()); imageReader->Update(); - // TODO: transform the iamge to the range [-1,1] and center it on (0,0) + vtkNew imageCenterer; + imageCenterer->SetInputConnection(imageReader->GetOutputPort()); + imageCenterer->CenterImageOn(); + imageCenterer->Update(); + + vtkSmartPointer imageData = imageCenterer->GetOutput(); + + // TODO: transform the iamge to the range [-1,1] // This will allow the backgorundImage to share a camera with our other layers. // Facilitating the cameraMovement callback. - vtkNew changeInformation; - changeInformation->SetInputConnection(imageReader->GetOutputPort()); - changeInformation->CenterImageOn(); - changeInformation->Update(); - - vtkSmartPointer imageData = changeInformation->GetOutput(); - vtkNew imageActor; imageActor->SetInputData(imageData); @@ -51,10 +71,10 @@ void BackgroundImage::updateImage() { imageData->GetSpacing(spacing); imageData->GetExtent(extent); - // printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); - // printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); - // printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); - // printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); + printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); + printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); + printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); + printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); vtkCamera *camera = this->ren->GetActiveCamera(); camera->ParallelProjectionOn(); @@ -63,9 +83,9 @@ void BackgroundImage::updateImage() { double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; double yd = (extent[3] - extent[2] + 1) * spacing[1]; - // printf("%lf, %lf, %lf\n", xc, yc, yd); + printf("%lf, %lf, %lf\n", xc, yc, yd); - camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> resize image. + camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> transform camera->SetFocalPoint(xc, yc, 0.0); // sets to 0,0,0; isnice camera->SetPosition(xc, yc, 1000); // sets to 0,0,1000; isnice }