merge conflic
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
#include "BackgroundImage.h"
|
||||
#include <vtkImageDataGeometryFilter.h>
|
||||
#include <vtkImageChangeInformation.h>
|
||||
#include <vtkImageSliceMapper.h>
|
||||
#include <vtkCamera.h>
|
||||
#include <vtkImageActor.h>
|
||||
#include <vtkImageData.h>
|
||||
#include <vtkImageMapper3D.h>
|
||||
#include <vtkImageReader2.h>
|
||||
#include <vtkImageShiftScale.h>
|
||||
#include <vtkMatrix4x4.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkTransform.h>
|
||||
#include <vtkTransformFilter.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -14,41 +23,61 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) {
|
||||
}
|
||||
|
||||
|
||||
void BackgroundImage::updateImage() {
|
||||
vtkSmartPointer<vtkImageData> imageData;
|
||||
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() {
|
||||
|
||||
// read image data
|
||||
vtkSmartPointer<vtkImageReader2> imageReader;
|
||||
|
||||
imageReader.TakeReference(this->readerFactory->CreateImageReader2(this->imagePath.c_str()));
|
||||
imageReader->SetFileName(this->imagePath.c_str());
|
||||
imageReader->Update();
|
||||
imageData = imageReader->GetOutput();
|
||||
|
||||
vtkNew<vtkImageActor> imageActor;
|
||||
imageActor->SetInputData(imageData);
|
||||
// translate image such that the middle is at (0,0)
|
||||
vtkNew<vtkImageChangeInformation> imageCenterer;
|
||||
imageCenterer->SetInputConnection(imageReader->GetOutputPort());
|
||||
imageCenterer->CenterImageOn();
|
||||
imageCenterer->Update();
|
||||
|
||||
this->ren->AddActor(imageActor);
|
||||
|
||||
|
||||
// camera stuff
|
||||
// essentially sets the camera to the middle of the background, and points it at the background
|
||||
// TODO: extract this to its own function, separate from the background class.
|
||||
double origin[3], spacing[3];
|
||||
// get some info from the data we'll need in a second
|
||||
vtkSmartPointer<vtkImageData> imageData = imageCenterer->GetOutput();
|
||||
double origin[3];
|
||||
int extent[6];
|
||||
imageData->GetOrigin(origin);
|
||||
imageData->GetSpacing(spacing);
|
||||
imageData->GetExtent(extent);
|
||||
|
||||
vtkCamera *camera = this->ren->GetActiveCamera();
|
||||
camera->ParallelProjectionOn();
|
||||
// map the imageData to a vtkPolydata so we can use a vtkTransform
|
||||
vtkNew<vtkImageDataGeometryFilter> imageDataGeometryFilter;
|
||||
imageDataGeometryFilter->SetInputData(imageData);
|
||||
imageDataGeometryFilter->Update();
|
||||
|
||||
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];
|
||||
double d = camera->GetDistance();
|
||||
camera->SetParallelScale(0.5 * yd);
|
||||
camera->SetFocalPoint(xc, yc, 0.0);
|
||||
camera->SetPosition(xc, yc, d);
|
||||
// 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());
|
||||
|
||||
vtkNew<vtkActor> actor;
|
||||
actor->SetMapper(mapper);
|
||||
|
||||
this->ren->AddActor(actor);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,3 +89,4 @@ void BackgroundImage::setImagePath(string imagePath) {
|
||||
this->imagePath = imagePath;
|
||||
updateImage();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,15 @@ private:
|
||||
*/
|
||||
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:
|
||||
/** Constructor.
|
||||
|
||||
@@ -41,9 +41,6 @@ void EGlyphLayer::readCoordinates() {
|
||||
this->direction->SetNumberOfTuples(numLats * numLons);
|
||||
points->Allocate(numLats * numLons);
|
||||
|
||||
auto camera = createNormalisedCamera();
|
||||
ren->SetActiveCamera(camera);
|
||||
|
||||
int i = 0;
|
||||
int latIndex = 0;
|
||||
for (double lat: uvGrid->lats) {
|
||||
@@ -77,11 +74,7 @@ void EGlyphLayer::readCoordinates() {
|
||||
glyph2D->SetVectorModeToUseVector();
|
||||
glyph2D->Update();
|
||||
|
||||
// vtkNew<vtkCoordinate> coordinate;
|
||||
// coordinate->SetCoordinateSystemToWorld();
|
||||
|
||||
vtkNew<vtkPolyDataMapper>(mapper);
|
||||
// mapper->SetTransformCoordinate(coordinate);
|
||||
mapper->SetInputConnection(glyph2D->GetOutputPort());
|
||||
mapper->Update();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define EGLYPHLAYER_H
|
||||
|
||||
#include "Layer.h"
|
||||
#include <memory>
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
#include "../advection/UVGrid.h"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <vtkGlyphSource2D.h>
|
||||
#include <vtkNamedColors.h>
|
||||
#include <vtkPolyDataMapper2D.h>
|
||||
#include <vtkProperty.h>
|
||||
#include <vtkProperty2D.h>
|
||||
#include <vtkVertexGlyphFilter.h>
|
||||
#include <vtkInteractorStyle.h>
|
||||
@@ -41,9 +42,6 @@ LGlyphLayer::LGlyphLayer(std::shared_ptr<UVGrid> uvGrid, std::unique_ptr<Advecti
|
||||
advector = std::move(advectionKernel);
|
||||
this->uvGrid = uvGrid;
|
||||
|
||||
auto camera = createNormalisedCamera();
|
||||
ren->SetActiveCamera(camera);
|
||||
|
||||
vtkSmartPointer<vtkTransformFilter> transformFilter = createCartographicTransformFilter(uvGrid);
|
||||
transformFilter->SetInputData(data);
|
||||
|
||||
@@ -61,7 +59,7 @@ LGlyphLayer::LGlyphLayer(std::shared_ptr<UVGrid> uvGrid, std::unique_ptr<Advecti
|
||||
vtkNew<vtkPolyDataMapper> mapper;
|
||||
mapper->SetInputConnection(glyph2D->GetOutputPort());
|
||||
mapper->Update();
|
||||
|
||||
|
||||
vtkNew<vtkActor> actor;
|
||||
actor->SetMapper(mapper);
|
||||
|
||||
@@ -70,11 +68,17 @@ LGlyphLayer::LGlyphLayer(std::shared_ptr<UVGrid> uvGrid, std::unique_ptr<Advecti
|
||||
|
||||
// creates a few points so we can test the updateData function
|
||||
void LGlyphLayer::spoofPoints() {
|
||||
this->points->InsertNextPoint(-4.125, 61.375, 0);
|
||||
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(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(-4.125, 61.375 , 0);
|
||||
// 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( 6.646210231365825, 46.52346296009023, 0); // Coordinates of Lausanne
|
||||
// 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();
|
||||
}
|
||||
|
||||
@@ -15,3 +15,8 @@ void Layer::updateData(int t) {
|
||||
void Layer::addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor) {
|
||||
// By default, do nothing
|
||||
}
|
||||
|
||||
|
||||
void Layer::setCamera(vtkCamera *camera) {
|
||||
this->getLayer()->SetActiveCamera(camera);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ public:
|
||||
* @param interactor : pointer to the interactor that observers can be added to.
|
||||
*/
|
||||
virtual void addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor);
|
||||
|
||||
/** Sets the active camera for the vtkRenderer associated with this layer.
|
||||
* Used to share one camera between multiple layers.
|
||||
*/
|
||||
virtual void setCamera(vtkCamera *camera);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user