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);
35 for (std::size_t j = 0; j < imgHeight; j++)
37 for (std::size_t i = 0; i < imgWidth; i++)
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);
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);