OGS
VtkBGImageSource.cpp
Go to the documentation of this file.
1
15// ** INCLUDES **
16#include "VtkBGImageSource.h"
17
18#include <vtkImageAlgorithm.h>
19#include <vtkImageData.h>
20#include <vtkImageShiftScale.h>
21#include <vtkInformation.h>
22#include <vtkInformationVector.h>
23#include <vtkObjectFactory.h>
24#include <vtkPlaneSource.h>
25#include <vtkPointData.h>
26#include <vtkSmartPointer.h>
27#include <vtkStreamingDemandDrivenPipeline.h>
28#include <vtkTexture.h>
29
30#include "VtkVisHelper.h"
31
33
36
37void VtkBGImageSource::SetRaster(vtkImageAlgorithm* img, double x0, double y0,
38 double scalingFactor)
39{
40 double range[2];
41 img->Update();
42 img->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
43 vtkSmartPointer<vtkImageShiftScale> scale =
44 vtkSmartPointer<vtkImageShiftScale>::New();
45 scale->SetInputConnection(img->GetOutputPort());
46 scale->SetShift(-range[0]);
47 scale->SetScale(255.0 / (range[1] - range[0]));
48 scale->SetOutputScalarTypeToUnsignedChar();
49 scale->Update();
50
51 vtkImageData* imageData = scale->GetOutput();
52 int dims[3];
53 imageData->GetDimensions(dims);
54 vtkTexture* texture = vtkTexture::New();
55 texture->InterpolateOff();
56 texture->RepeatOff();
57 // texture->EdgeClampOn(); // does not work
58 texture->SetInputData(imageData);
59 this->SetTexture(texture);
60
61 _origin =
62 std::pair<float, float>(static_cast<float>(x0), static_cast<float>(y0));
63 _cellsize = scalingFactor;
64
65 vtkSmartPointer<vtkPlaneSource> plane =
66 vtkSmartPointer<vtkPlaneSource>::New();
67 plane->SetOrigin(_origin.first, _origin.second, -1);
68 plane->SetPoint1(_origin.first + dims[0] * _cellsize, _origin.second, -1);
69 plane->SetPoint2(_origin.first, _origin.second + dims[1] * _cellsize, -1);
70
71 this->SetInputConnection(0, plane->GetOutputPort(0));
72 this->SetTexture(texture);
73}
74
75void VtkBGImageSource::SetUserProperty(QString name, QVariant value)
76{
78}
vtkStandardNewMacro(VtkBGImageSource)
Definition of the VtkBGImageSource class.
Definition of the VtkVisHelper class.
void SetTexture(vtkTexture *t)
Sets a texture for the VtkVisPipelineItem.
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.
Uses an image source to create a plane in the 3D with the given image texture mapped on it.
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
void SetRaster(vtkImageAlgorithm *img, double x0, double y0, double scalingFactor)
Sets the raster/image to be used as a texture map.
~VtkBGImageSource() override
std::pair< double, double > _origin