Is pretty hard to reproduce right here, but I will try to give here more details:
My goal is to transfer the VTK data to SimpleITK, apply some filters, and then transfer data back to VTK in order to visualize the data.
I have a vtkDICOMReader to read input data (CT dicom), and a vtkVolume to visualize data, and the result is:
(see window level)
Now, I intend to import VTK data to SimpleITK , my purpose is to do some segmentation:
//// **importing data from VTK to SimpleITK** ///////////////////////////////////
int* nDim = **m_pDICOMReader** ->GetOutput()->GetDimensions();
TRACE(">>>>%d|%d|%d\n", nDim[0], nDim[1], nDim[2]); // **result: >>>>512|512|102**
uint8_t* in = new uint8_t[nDim[0] * nDim[1] * nDim[2]];
double* dSpacing = **m_pDICOMReader** ->GetOutput()->GetSpacing();
std::vector<double> spacing;
spacing.push_back(dSpacing[0]);
spacing.push_back(dSpacing[1]);
spacing.push_back(dSpacing[2]);
importer.SetSpacing(spacing);
double* dOrigin = **m_pDICOMReader** ->GetOutput()->GetOrigin();
std::vector<double> origin;
origin.push_back(dOrigin[0]);
origin.push_back(dOrigin[1]);
origin.push_back(dOrigin[2]);
importer.SetOrigin(origin);
std::vector<unsigned int> size;
size.push_back((unsigned int)nDim[0]);
size.push_back((unsigned int)nDim[1]);
size.push_back((unsigned int)nDim[2]);
importer.SetSize(size);
importer.SetBufferAsUInt8(in);
sitk::Image **img** = importer.Execute();
///////////////////////////////////////////////////////////////////////////
to check if the conversion is ok, I apply no SimpleITK filter for now …
//// now I want to import data back from SimpleITK to VTK ///////////////////
std::vector<double> spacing = img.GetSpacing();
img = sitk::Cast(img, sitk::PixelIDValueEnum::sitkUInt8);
pImageImport->SetImportVoidPointer((void*)img.GetBufferAsUInt8());
pImageImport->SetDataScalarTypeToUnsignedChar();
pImageImport->SetDataExtent(0, (int)size[0] - 1, 0, (int)size[1] - 1, 0, size[2] - 1);
pImageImport->SetWholeExtent(0, (int)size[0] - 1, 0, (int)size[1] - 1, 0, size[2] - 1);
pImageImport->SetDataSpacing(spacing[0], spacing[1], spacing[2]);
pImageImport->Update();
nDim = pImageImport->GetOutput()->GetDimensions();
TRACE(">>>>%d|%d|%d\n", nDim[0], nDim[1], nDim[2]); // result >>>>512|512|102, which is correct
m_pDICOMReader->GetOutput()->DeepCopy(pImageImport->GetOutput());
m_pDICOMReader->Update();
/////////////////////////////////////////////////////////////////////////////
But the result is a diffuse cube:
(see window level)
Why this conversion is not alright ? How can I check what part of conversion is not working correctly ?