[vtkusers] 3D array to vtkImageData
ylongwu
236459294 at qq.com
Sun Mar 11 00:03:37 EST 2012
hi,evryone,
I want to use vtkImageData read a raw datasets 26*180*280, and I followed
an example from the internet. and i have made some changes.But it show a
26*180 image,and the color of the image is all red. Could anyone help me?
thanks.
code:
void vtkImageShow(float *3DArray, int*dims, int*shrinkFactor)
{
int i,j,k;
float *rawData = new float[26*180*280];
for (i = 0; i < dims[0]; i++)
{
for (j = 0; j < dims[1]; j++)
{
for (k = 0; k < dims[2]; k++)
{
rawData[i*dims[1]*dims[2]+j*dims[2]+k]=3DArray[i*dims[1]*dims[2]+j*dims[2]+k];
}
}
}
//Volume Rendeing
vtkImageData* id = vtkImageData::New() ;
id->SetDimensions(dims[0], dims[1], dims[2]);
id->SetScalarTypeToFloat();
id->SetNumberOfScalarComponents(3);
id->AllocateScalars();
vtkImageShrink3D *mask = vtkImageShrink3D::New();
mask->SetInput(id);
//mask->SetShrinkFactors(shrinkFactor[0], shrinkFactor[1],
shrinkFactor[2]);
float* a = (float*)(id->GetScalarPointer());
for (i = 0; i < dims[0]; i++)
{
for (j = 0; j < dims[1]; j++)
{
for (k = 0; k < dims[2]; k++)
{
*a++ =
rawData[i*dims[1]*dims[2]+j*dims[2]+k];
}
}
}
vtkContourFilter *cf = vtkContourFilter::New();
cf->SetInputConnection(mask->GetOutputPort());
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(cf->GetOutputPort());
mapper->SetScalarRange(0, 5000000);
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
vtkCamera *aCamera = vtkCamera::New();
aCamera->SetViewUp(0, 5, 0);
aCamera->SetPosition(5, 0, 0);
aCamera->SetFocalPoint(0, 0, 0);
aCamera->ComputeViewPlaneNormal();
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(actor);
ren->ResetCamera();
//aCamera->Dolly(1.5);
ren->ResetCameraClippingRange();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
ren->SetBackground(0.0f, 0.0f, 0.0f);
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->Initialize();
iren->Start();
}
http://vtk.1045678.n5.nabble.com/file/n5554141/QQ%E6%88%AA%E5%9B%BE20120309100328.jpg
http://vtk.1045678.n5.nabble.com/file/n5554141/QQ%E6%88%AA%E5%9B%BE20120309100400.jpg
--
View this message in context: http://vtk.1045678.n5.nabble.com/3D-array-to-vtkImageData-tp5554141p5554141.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list