[vtkusers] volume rendering a data with multiple components
chenjianfeng
379231717 at qq.com
Mon Mar 3 04:19:54 EST 2014
I have been doing volume rendering using vtkImageData with one component. Now I want to make a new vtkImageData based on the existing one. The new vtkImageData has two components and the first component store the scalar data the same as the existing one, the second component store the data which I will assign. A fragment of my code is like this:
vtkImageData *originalData = reader->GetOutput(); // I read a series of dicom file.
int dim[3];
double spa[3], ori[3];
originalData->GetDimensions(dim);
originalData->GetSpacing(spa);
originalData->GetOrigin(ori);
vtkImageData *newData = vtkImagaData::New();//newData is created based on the originalData's dimensions spacing and origin.
newData->SetDimensions(dim);
newData->SetScalarTypeToShort();
newData->SetSpacing(spa);
newData->SetNumberOfScalarComponents(2);//newData's component is two
newData->SetOrigin(ori);
newData->AllocateScalars();
//Now I have some puzzles:How does the vtkImageData store multiple components, I think it store data one point by one point, because each point now have two components, so it looks like this in memory: Ponit1(component1, component2), Ponit2(component1, component2), Ponit3.... is it right???
//Then I traverse the new data and assign each component of each point
short *originalDataPointer = (short *)originalData->GetScalarPointer();
short *newDataPointer = (short *)newData->GetScalarPointer();
for(int i = 0; i < dim[0]*dim[1]*dim[2]; i++){
//I assign each point's first component and second component the same data as the original data.
originalDataPointer[i*2] = newDataPointer[i];
originalDataPointer[i*2 + 1] = newDataPointer[i];
}
vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
vtkSmartPointer<vtkColorTransferFunction>::New();
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.5, 0.0);
colorTransferFunction->AddRGBPoint(60.0, 1.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(128.0, 0.2, 0.1, 0.9);
colorTransferFunction->AddRGBPoint(196.0, 0.27, 0.21, 0.1);
colorTransferFunction->AddRGBPoint(255.0, 0.8, 0.8, 0.8);
vtkSmartPointer<vtkPiecewiseFunction> piecewiseFunction =
vtkSmartPointer<vtkPiecewiseFunction>::New();
piecewiseFunction->AddPoint(20, 0.0);
piecewiseFunction->AddPoint(120, 0.1);
piecewiseFunction->AddPoint(255, 0.2);
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> fixedPointVolumeRayCastMapper =
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
fixedPointVolumeRayCastMapper->SetNumberOfThreads(1);
fixedPointVolumeRayCastMapper->SetInput(newData);
vtkSmartPointer<vtkVolumeProperty> volumeProperty =
vtkSmartPointer<vtkVolumeProperty>::New();
volumeProperty->SetScalarOpacity(0, piecewiseFunction);//I want to use the first component as the input of opacity transfer function
volumeProperty->SetColor(1, colorTransferFunction);// I want to use the second component as the input of color transfer function
vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(fixedPointVolumeRayCastMapper);
volume->SetProperty(volumeProperty);
vtkSmartPointer<vtkOpenGLRenderer> renderer =
vtkSmartPointer<vtkOpenGLRenderer>::New();
renderer->AddVolume(volume);
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
renWin->Render();
[the result of the volume rendering is diffrent from the result of the original data which only has one component with the same transfer function. Shouldn't the result be the same?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140303/ffec579e/attachment.html>
More information about the vtkusers
mailing list