I would like to create a volume from an std::vector of cv::Mat. I save all values in an std::vector in a linear way at first and then I import the pointer to data with imageimport. My problem is that my images are truncated. Here is my code:
//std::vectorcv::Mat volume; // was allocated with some data
const int width = volume[0].cols;
const int height = volume[0].rows;
const int depth = (int)volume.size();
std::vector volume_cv_mat;
for (unsigned int z = 0; z < depth; ++z)
{
for (unsigned int row = 0; row < height; ++row)
{
for (unsigned int col = 0; col <width ; ++col)
{
volume_cv_mat.push_back(volume[z].at(height-row, col));
}
}
}
vtkSmartPointer imageImport = vtkSmartPointer::New();
imageImport->SetImportVoidPointer(volume_cv_mat.data(),volume_cv_mat.size());
imageImport->SetDataScalarTypeToUnsignedChar();
imageImport->SetNumberOfScalarComponents(1);
imageImport->SetDataSpacing(0.12, 0.15, 1);
imageImport->SetDataOrigin(0, 0, 0);
imageImport->SetWholeExtent(0, width - 1, 0, height - 1, 0, depth - 1);
imageImport->SetDataExtentToWholeExtent();
imageImport->Update();
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// Create transfer mapping scalar value to opacity
vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint(0.0, 1.0);
opacityTransferFunction->AddPoint(255.0, 1.0);
// Create transfer mapping scalar value to color
vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(255.0, 1.0, 1.0, 1.0);
// The property describes how the data will look
vtkNew volumeProperty;
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->ShadeOn();
volumeProperty->SetAmbient(0.4);
volumeProperty->SetDiffuse(0.6);
volumeProperty->SetSpecular(0.2);
// The mapper / ray cast function know how to render the data
vtkGPUVolumeRayCastMapper *volumeMapper = vtkGPUVolumeRayCastMapper::New();
volumeMapper->SetInputConnection(imageImport->GetOutputPort());
// The volume holds the mapper and the property and
// can be used to position/orient the volume
vtkVolume *volumeVTK = vtkVolume::New();
volumeVTK->SetMapper(volumeMapper);
volumeVTK->SetProperty(volumeProperty);
ren->AddViewProp(volumeVTK);
ren->SetBackground(1, 1, 1);
renWin->SetSize(1000, 1000);
iren->Initialize();
renWin->Render();
iren->Start();
Here you can see my question in stackoverflow stdvector - VTK volume from std::vector and opencv images - Stack Overflow
My problem is, why is my image truncated in my volume, but all voxel values are given?
Thank you