added backgroundimage transformation
This commit is contained in:
parent
5f6b88b34c
commit
507d0065f0
|
|
@ -62,9 +62,8 @@ void CameraMoveCallback::zoom(const bool in) {
|
||||||
double scale = this->cam->GetParallelScale();
|
double scale = this->cam->GetParallelScale();
|
||||||
|
|
||||||
if (in) {
|
if (in) {
|
||||||
if (scale >= 0.2) {
|
if (scale >= 0.2)
|
||||||
scale -= 0.1;
|
scale -= 0.1;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (scale <= 0.9)
|
if (scale <= 0.9)
|
||||||
scale += 0.1;
|
scale += 0.1;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), t
|
||||||
TimerCallbackCommand* TimerCallbackCommand::New(Program *program) {
|
TimerCallbackCommand* TimerCallbackCommand::New(Program *program) {
|
||||||
TimerCallbackCommand *cb = new TimerCallbackCommand();
|
TimerCallbackCommand *cb = new TimerCallbackCommand();
|
||||||
cb->setProgram(program);
|
cb->setProgram(program);
|
||||||
cb->setPaused(false);
|
cb->setPaused(true);
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "BackgroundImage.h"
|
#include "BackgroundImage.h"
|
||||||
|
#include <vtkImageDataGeometryFilter.h>
|
||||||
#include <vtkImageChangeInformation.h>
|
#include <vtkImageChangeInformation.h>
|
||||||
|
#include <vtkImageSliceMapper.h>
|
||||||
#include <vtkCamera.h>
|
#include <vtkCamera.h>
|
||||||
#include <vtkImageActor.h>
|
#include <vtkImageActor.h>
|
||||||
#include <vtkImageData.h>
|
#include <vtkImageData.h>
|
||||||
|
|
@ -7,6 +9,7 @@
|
||||||
#include <vtkImageReader2.h>
|
#include <vtkImageReader2.h>
|
||||||
#include <vtkImageShiftScale.h>
|
#include <vtkImageShiftScale.h>
|
||||||
#include <vtkMatrix4x4.h>
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
#include <vtkTransform.h>
|
#include <vtkTransform.h>
|
||||||
#include <vtkTransformFilter.h>
|
#include <vtkTransformFilter.h>
|
||||||
|
|
||||||
|
|
@ -19,56 +22,62 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) {
|
||||||
updateImage();
|
updateImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> BackgroundImage::getMatrix(const double x0, const double y0, const int xMax, const int yMax) {
|
||||||
|
double eyeTransform[] = {
|
||||||
|
2/(xMax-x0), 0, 0, -(xMax+x0)/(xMax-x0),
|
||||||
|
0, 2/(yMax-y0), 0, -(yMax+y0)/(yMax-y0),
|
||||||
|
0, 0, 1, 0,
|
||||||
|
0, 0, 0, 1
|
||||||
|
};
|
||||||
|
auto matrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
matrix->DeepCopy(eyeTransform);
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BackgroundImage::updateImage() {
|
void BackgroundImage::updateImage() {
|
||||||
|
|
||||||
|
// read image data
|
||||||
vtkSmartPointer<vtkImageReader2> imageReader;
|
vtkSmartPointer<vtkImageReader2> imageReader;
|
||||||
|
|
||||||
imageReader.TakeReference(this->readerFactory->CreateImageReader2(this->imagePath.c_str()));
|
imageReader.TakeReference(this->readerFactory->CreateImageReader2(this->imagePath.c_str()));
|
||||||
imageReader->SetFileName(this->imagePath.c_str());
|
imageReader->SetFileName(this->imagePath.c_str());
|
||||||
imageReader->Update();
|
imageReader->Update();
|
||||||
|
|
||||||
|
// translate image such that the middle is at (0,0)
|
||||||
vtkNew<vtkImageChangeInformation> imageCenterer;
|
vtkNew<vtkImageChangeInformation> imageCenterer;
|
||||||
imageCenterer->SetInputConnection(imageReader->GetOutputPort());
|
imageCenterer->SetInputConnection(imageReader->GetOutputPort());
|
||||||
imageCenterer->CenterImageOn();
|
imageCenterer->CenterImageOn();
|
||||||
imageCenterer->Update();
|
imageCenterer->Update();
|
||||||
|
|
||||||
|
// get some info from the data we'll need in a second
|
||||||
vtkSmartPointer<vtkImageData> imageData = imageCenterer->GetOutput();
|
vtkSmartPointer<vtkImageData> imageData = imageCenterer->GetOutput();
|
||||||
|
double origin[3];
|
||||||
|
int extent[6];
|
||||||
|
imageData->GetOrigin(origin);
|
||||||
|
imageData->GetExtent(extent);
|
||||||
|
|
||||||
// TODO: transform the image to the range [-1,1]
|
// map the imageData to a vtkPolydata so we can use a vtkTransform
|
||||||
// This will allow the backgorundImage to share a camera with our other layers.
|
vtkNew<vtkImageDataGeometryFilter> imageDataGeometryFilter;
|
||||||
// Facilitating the cameraMovement callback.
|
imageDataGeometryFilter->SetInputData(imageData);
|
||||||
vtkNew<vtkImageActor> imageActor;
|
imageDataGeometryFilter->Update();
|
||||||
imageActor->SetInputData(imageData);
|
|
||||||
|
|
||||||
this->ren->AddActor(imageActor);
|
// setup the vtkTransform - this is where use the data from imageData we got earlier
|
||||||
|
vtkNew<vtkTransform> transform;
|
||||||
|
transform->SetMatrix(getMatrix(origin[0], origin[1], extent[1]+origin[0], extent[3]+origin[1]));
|
||||||
|
vtkSmartPointer<vtkTransformFilter> transformFilter = vtkSmartPointer<vtkTransformFilter>::New();
|
||||||
|
transformFilter->SetTransform(transform);
|
||||||
|
transformFilter->SetInputConnection(imageDataGeometryFilter->GetOutputPort());
|
||||||
|
transformFilter->Update();
|
||||||
|
|
||||||
|
// Create a mapper and actor
|
||||||
|
vtkNew<vtkPolyDataMapper> mapper;
|
||||||
|
mapper->SetInputConnection(transformFilter->GetOutputPort());
|
||||||
|
|
||||||
// // camera stuff
|
vtkNew<vtkActor> actor;
|
||||||
// // essentially sets the camera to the middle of the background, and points it at the background
|
actor->SetMapper(mapper);
|
||||||
// // TODO: extract this to its own function, separate from the background class.
|
|
||||||
// double origin[3], spacing[3];
|
this->ren->AddActor(actor);
|
||||||
// int extent[6];
|
|
||||||
// imageData->GetOrigin(origin);
|
|
||||||
// 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]);
|
|
||||||
//
|
|
||||||
// vtkCamera *camera = this->ren->GetActiveCamera();
|
|
||||||
// camera->ParallelProjectionOn();
|
|
||||||
//
|
|
||||||
// double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0];
|
|
||||||
// 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);
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,8 +90,3 @@ void BackgroundImage::setImagePath(string imagePath) {
|
||||||
updateImage();
|
updateImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BackgroundImage::setCamera(vtkCamera *cam) {
|
|
||||||
this->getLayer()->SetActiveCamera(cam);
|
|
||||||
// TODO: fix the camera for this layer so this intentionally empty override can be removed.
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,15 @@ private:
|
||||||
*/
|
*/
|
||||||
void updateImage();
|
void updateImage();
|
||||||
|
|
||||||
|
/** This function returns a 4x4matrix which maps the given square of [x0,w] x [y0,h] to the range [-1,1].
|
||||||
|
* @param x0 : x coordinate of leftmost edge of image
|
||||||
|
* @param y0 : y coordinate of bottommost edge of image
|
||||||
|
* @param xMax : x coordinate of rightmost edge of image
|
||||||
|
* @param yMax : y coordinate of topmost edge of image
|
||||||
|
* @return a 4x4 matrix which transforms the image from its original geometry to the range [-1,1]
|
||||||
|
*/
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> getMatrix(const double x0, const double y0, const int xMax, const int yMax);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Constructor.
|
/** Constructor.
|
||||||
|
|
@ -32,9 +41,6 @@ public:
|
||||||
* @param imagePath : String to the path of the new image to use.
|
* @param imagePath : String to the path of the new image to use.
|
||||||
*/
|
*/
|
||||||
void setImagePath(std::string imagePath);
|
void setImagePath(std::string imagePath);
|
||||||
|
|
||||||
|
|
||||||
void setCamera(vtkCamera *cam) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <vtkGlyphSource2D.h>
|
#include <vtkGlyphSource2D.h>
|
||||||
#include <vtkNamedColors.h>
|
#include <vtkNamedColors.h>
|
||||||
#include <vtkPolyDataMapper2D.h>
|
#include <vtkPolyDataMapper2D.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
#include <vtkProperty2D.h>
|
#include <vtkProperty2D.h>
|
||||||
#include <vtkVertexGlyphFilter.h>
|
#include <vtkVertexGlyphFilter.h>
|
||||||
#include <vtkInteractorStyle.h>
|
#include <vtkInteractorStyle.h>
|
||||||
|
|
@ -50,7 +51,7 @@ LGlyphLayer::LGlyphLayer() {
|
||||||
|
|
||||||
vtkNew<vtkGlyphSource2D> circleSource;
|
vtkNew<vtkGlyphSource2D> circleSource;
|
||||||
circleSource->SetGlyphTypeToCircle();
|
circleSource->SetGlyphTypeToCircle();
|
||||||
circleSource->SetScale(0.05);
|
circleSource->SetScale(0.01);
|
||||||
circleSource->Update();
|
circleSource->Update();
|
||||||
|
|
||||||
vtkNew<vtkGlyph2D> glyph2D;
|
vtkNew<vtkGlyph2D> glyph2D;
|
||||||
|
|
@ -65,6 +66,7 @@ LGlyphLayer::LGlyphLayer() {
|
||||||
|
|
||||||
vtkNew<vtkActor> actor;
|
vtkNew<vtkActor> actor;
|
||||||
actor->SetMapper(mapper);
|
actor->SetMapper(mapper);
|
||||||
|
actor->GetProperty()->SetOpacity(0.8);
|
||||||
|
|
||||||
this->ren->AddActor(actor);
|
this->ren->AddActor(actor);
|
||||||
}
|
}
|
||||||
|
|
@ -72,10 +74,16 @@ LGlyphLayer::LGlyphLayer() {
|
||||||
// creates a few points so we can test the updateData function
|
// creates a few points so we can test the updateData function
|
||||||
void LGlyphLayer::spoofPoints() {
|
void LGlyphLayer::spoofPoints() {
|
||||||
this->points->InsertNextPoint(-4.125, 61.375 , 0);
|
this->points->InsertNextPoint(-4.125, 61.375 , 0);
|
||||||
this->points->InsertNextPoint(6.532949683882039, 53.24308582564463, 0); // Coordinates of Zernike
|
// this->points->InsertNextPoint(6.532949683882039, 53.24308582564463, 0); // Coordinates of Zernike
|
||||||
this->points->InsertNextPoint(5.315307819255385, 60.40001057122271, 0); // Coordinates of Bergen
|
// this->points->InsertNextPoint(5.315307819255385, 60.40001057122271, 0); // Coordinates of Bergen
|
||||||
this->points->InsertNextPoint( 6.646210231365825, 46.52346296009023, 0); // Coordinates of Lausanne
|
// this->points->InsertNextPoint( 6.646210231365825, 46.52346296009023, 0); // Coordinates of Lausanne
|
||||||
this->points->InsertNextPoint(-6.553894313570932, 62.39522131195857, 0); // Coordinates of the top of the Faroe islands
|
// this->points->InsertNextPoint(-6.553894313570932, 62.39522131195857, 0); // Coordinates of the top of the Faroe islands
|
||||||
|
|
||||||
|
for (int i=0; i < 330; i+=5) {
|
||||||
|
for (int j=0; j < 330; j+=5) {
|
||||||
|
this->points->InsertNextPoint(-15.875+(12.875+15.875)/330*j, 46.125+(62.625-46.125)/330*i, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->points->Modified();
|
this->points->Modified();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue