(wip) progress on image transform
This commit is contained in:
parent
ab0916b9c7
commit
da20a2514c
|
|
@ -3,7 +3,9 @@
|
|||
#include <vtkCamera.h>
|
||||
#include <vtkImageActor.h>
|
||||
#include <vtkImageData.h>
|
||||
#include <vtkImageMapper3D.h>
|
||||
#include <vtkImageReader2.h>
|
||||
#include <vtkImageShiftScale.h>
|
||||
#include <vtkMatrix4x4.h>
|
||||
#include <vtkTransform.h>
|
||||
#include <vtkTransformFilter.h>
|
||||
|
|
@ -17,6 +19,24 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) {
|
|||
updateImage();
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> 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<vtkMatrix4x4>::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<vtkImageChangeInformation> imageCenterer;
|
||||
imageCenterer->SetInputConnection(imageReader->GetOutputPort());
|
||||
imageCenterer->CenterImageOn();
|
||||
imageCenterer->Update();
|
||||
|
||||
vtkSmartPointer<vtkImageData> 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<vtkImageChangeInformation> changeInformation;
|
||||
changeInformation->SetInputConnection(imageReader->GetOutputPort());
|
||||
changeInformation->CenterImageOn();
|
||||
changeInformation->Update();
|
||||
|
||||
vtkSmartPointer<vtkImageData> imageData = changeInformation->GetOutput();
|
||||
|
||||
vtkNew<vtkImageActor> 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue