OGS
VtkVisHelper Class Reference

Detailed Description

Some data conversion helper functions.

Definition at line 24 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 26 of file VtkVisHelper.cpp.

27{
28 std::size_t imgWidth = img.width();
29 std::size_t imgHeight = img.height();
30 vtkSmartPointer<vtkUnsignedCharArray> data =
31 vtkSmartPointer<vtkUnsignedCharArray>::New();
32 data->SetNumberOfComponents(3);
33 data->SetNumberOfTuples(imgWidth * imgHeight);
34
35 for (std::size_t j = 0; j < imgHeight; j++)
36 {
37 for (std::size_t i = 0; i < imgWidth; i++)
38 {
39 QRgb pix = img.pixel(i, j);
40 const float color[3] = {static_cast<float>(qRed(pix)),
41 static_cast<float>(qGreen(pix)),
42 static_cast<float>(qBlue(pix))};
43 data->SetTuple(j * imgWidth + i, color);
44 }
45 }
46
47 vtkImageData* imgData = vtkImageData::New();
48 imgData->SetExtent(0, imgWidth - 1, 0, imgHeight - 1, 0, 0);
49 imgData->SetOrigin(0, 0, 0);
50 imgData->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
51 imgData->GetPointData()->SetScalars(data);
52
53 return imgData;
54}

Referenced by QImageToVtkTexture().

◆ QImageToVtkTexture()

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

Converts a QImage-object into a vtkTexture-object.

Definition at line 56 of file VtkVisHelper.cpp.

57{
58 vtkSmartPointer<vtkImageData> imgData = QImageToVtkImageData(img);
59
60 vtkTexture* texture = vtkTexture::New();
61 texture->InterpolateOff();
62 texture->RepeatOff();
63 // texture->EdgeClampOff();
64 // texture->SetBlendingMode(0);
65 texture->SetInputData(imgData);
66
67 return texture;
68}
static vtkImageData * QImageToVtkImageData(QImage &img)
Converts a QImage to vtkImageData.

References QImageToVtkImageData().


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