OGS
VtkBGImageSource.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4// ** INCLUDES **
5#include "VtkBGImageSource.h"
6
7#include <vtkImageAlgorithm.h>
8#include <vtkImageData.h>
9#include <vtkImageShiftScale.h>
10#include <vtkInformation.h>
11#include <vtkInformationVector.h>
12#include <vtkObjectFactory.h>
13#include <vtkPlaneSource.h>
14#include <vtkPointData.h>
15#include <vtkSmartPointer.h>
16#include <vtkStreamingDemandDrivenPipeline.h>
17#include <vtkTexture.h>
18
19#include "VtkVisHelper.h"
20
22
25
26void VtkBGImageSource::SetRaster(vtkImageAlgorithm* img, double x0, double y0,
27 double scalingFactor)
28{
29 double range[2];
30 img->Update();
31 img->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
32 vtkSmartPointer<vtkImageShiftScale> scale =
33 vtkSmartPointer<vtkImageShiftScale>::New();
34 scale->SetInputConnection(img->GetOutputPort());
35 scale->SetShift(-range[0]);
36 scale->SetScale(255.0 / (range[1] - range[0]));
37 scale->SetOutputScalarTypeToUnsignedChar();
38 scale->Update();
39
40 vtkImageData* imageData = scale->GetOutput();
41 int dims[3];
42 imageData->GetDimensions(dims);
43 vtkTexture* texture = vtkTexture::New();
44 texture->InterpolateOff();
45 texture->RepeatOff();
46 // texture->EdgeClampOn(); // does not work
47 texture->SetInputData(imageData);
48 this->SetTexture(texture);
49
50 _origin =
51 std::pair<float, float>(static_cast<float>(x0), static_cast<float>(y0));
52 _cellsize = scalingFactor;
53
54 vtkSmartPointer<vtkPlaneSource> plane =
55 vtkSmartPointer<vtkPlaneSource>::New();
56 plane->SetOrigin(_origin.first, _origin.second, -1);
57 plane->SetPoint1(_origin.first + dims[0] * _cellsize, _origin.second, -1);
58 plane->SetPoint2(_origin.first, _origin.second + dims[1] * _cellsize, -1);
59
60 this->SetInputConnection(0, plane->GetOutputPort(0));
61 this->SetTexture(texture);
62}
63
64void VtkBGImageSource::SetUserProperty(QString name, QVariant value)
65{
67}
vtkStandardNewMacro(VtkBGImageSource)
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