OGS
VtkVisHelper Class Reference

Detailed Description

Some data conversion helper functions.

Definition at line 13 of file VtkVisHelper.h.

#include <VtkVisHelper.h>

Static Public Member Functions

static vtkImageData * QImageToVtkImageData (QImage &img)
 Converts a QImage to vtkImageData.
static vtkTexture * QImageToVtkTexture (QImage &img)
 Converts a QImage-object into a vtkTexture-object.

Member Function Documentation

◆ QImageToVtkImageData()

vtkImageData * VtkVisHelper::QImageToVtkImageData ( QImage & img)
static

Converts a QImage to vtkImageData.

Definition at line 15 of file VtkVisHelper.cpp.

16{
17 std::size_t imgWidth = img.width();
18 std::size_t imgHeight = img.height();
19 vtkSmartPointer<vtkUnsignedCharArray> data =
20 vtkSmartPointer<vtkUnsignedCharArray>::New();
21 data->SetNumberOfComponents(3);
22 data->SetNumberOfTuples(imgWidth * imgHeight);
23
24 for (std::size_t j = 0; j < imgHeight; j++)
25 {
26 for (std::size_t i = 0; i < imgWidth; i++)
27 {
28 QRgb pix = img.pixel(i, j);
29 const float color[3] = {static_cast<float>(qRed(pix)),
30 static_cast<float>(qGreen(pix)),
31 static_cast<float>(qBlue(pix))};
32 data->SetTuple(j * imgWidth + i, color);
33 }
34 }
35
36 vtkImageData* imgData = vtkImageData::New();
37 imgData->SetExtent(0, imgWidth - 1, 0, imgHeight - 1, 0, 0);
38 imgData->SetOrigin(0, 0, 0);
39 imgData->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
40 imgData->GetPointData()->SetScalars(data);
41
42 return imgData;
43}

Referenced by QImageToVtkTexture().

◆ QImageToVtkTexture()

vtkTexture * VtkVisHelper::QImageToVtkTexture ( QImage & img)
static

Converts a QImage-object into a vtkTexture-object.

Definition at line 45 of file VtkVisHelper.cpp.

46{
47 vtkSmartPointer<vtkImageData> imgData = QImageToVtkImageData(img);
48
49 vtkTexture* texture = vtkTexture::New();
50 texture->InterpolateOff();
51 texture->RepeatOff();
52 // texture->EdgeClampOff();
53 // texture->SetBlendingMode(0);
54 texture->SetInputData(imgData);
55
56 return texture;
57}
static vtkImageData * QImageToVtkImageData(QImage &img)
Converts a QImage to vtkImageData.

References QImageToVtkImageData().


The documentation for this class was generated from the following files: