[vtkusers] Volume raycast cause exception in C++
mathieu coursolle
mcoursolle at gmail.com
Mon May 23 15:12:47 EDT 2005
Hi everbody,
I want to display an MRI image using a raycast function. It works fine
except that it works only if I use a plane widget at the same time, which
I can not explain. If I comment the line enabling the widget, I throws an
exception when rendered. I can see the result less than a second before
the exception is thrown.
Here is my code, maybe someone might see what I am doing wrong.
Thanks a lot!
Mathieu
//DICOM.
vtkDICOMImageReader* reader_ptr = vtkDICOMImageReader::New();
vtkSmartPointer<vtkDICOMImageReader> reader(reader_ptr);
reader_ptr->Delete();
//reader->SetFileName("D:\\DICOM\\0-3-35.dcm");
reader->SetDirectoryName("D:\\DICOM");
reader->Update();
vtkSmartPointer<vtkImageData> data = reader->GetOutput();
vtkSmartPointer<vtkImageShiftScale> scale = vtkImageShiftScale::New();
scale->SetInput(data.GetPointer());
scale->SetOutputScalarTypeToUnsignedChar();
scale->Update();
vtkSmartPointer<vtkPiecewiseFunction> opacity = vtkPiecewiseFunction::New();
opacity->AddPoint(0, 0);
opacity->AddPoint(255, 0.2);
vtkSmartPointer<vtkColorTransferFunction> color =
vtkColorTransferFunction::New();
color->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
color->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
color->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
color->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
color->AddRGBPoint(255.0, 0.0, 0.2, 0.0);
vtkSmartPointer<vtkVolumeProperty> property = vtkVolumeProperty::New();
property->SetColor(color.GetPointer());
property->SetScalarOpacity(opacity.GetPointer());
property->ShadeOn();
property->SetInterpolationTypeToLinear();
vtkSmartPointer<vtkVolumeRayCastCompositeFunction> function =
vtkVolumeRayCastCompositeFunction::New();
vtkSmartPointer<vtkVolumeRayCastMapper> volume_mapper =
vtkVolumeRayCastMapper::New();
volume_mapper->SetVolumeRayCastFunction(function.GetPointer());
volume_mapper->SetInput(scale->GetOutput());
vtkSmartPointer<vtkVolume> volume = vtkVolume::New();
volume->SetMapper(volume_mapper.GetPointer());
volume->SetProperty(property.GetPointer());
m_Window.GetRenderer()->AddVolume(volume.GetPointer());
double* origin = data->GetOrigin();
vtkCellPicker* picker = vtkCellPicker::New();
picker->SetTolerance(0.005);
vtkLookupTable* lut = vtkLookupTable::New();
lut->SetTableRange(0, 255);
lut->SetRampToSQRT();
lut->SetSaturationRange(0, 0);
lut->SetValueRange(0, 1);
lut->SetHueRange(0, 0);
lut->Build();
vtkImagePlaneWidget* plane_x = vtkImagePlaneWidget::New();
plane_x->SetInput(data.GetPointer());
plane_x->SetPicker(picker);
plane_x->SetPlaneOrientationToXAxes();
plane_x->SetLookupTable(lut);
plane_x->SetInteractor(m_Window.GetInteractor());
plane_x->SetCurrentRenderer(m_Window.GetRenderer());
plane_x->SetOrigin(origin);
plane_x->SetPlaceFactor(1);
plane_x->DisplayTextOn();
vtkImagePlaneWidget* plane_y = vtkImagePlaneWidget::New();
plane_y->SetInput(data.GetPointer());
plane_y->SetPicker(picker);
plane_y->SetPlaneOrientationToYAxes();
plane_y->SetLookupTable(plane_x->GetLookupTable());
plane_y->SetInteractor(m_Window.GetInteractor());
plane_y->SetCurrentRenderer(m_Window.GetRenderer());
plane_y->SetOrigin(origin);
plane_y->SetPlaceFactor(1);
plane_y->DisplayTextOn();
vtkImagePlaneWidget* plane_z = vtkImagePlaneWidget::New();
plane_z->SetInput(data.GetPointer());
plane_z->SetPicker(picker);
plane_z->SetPlaneOrientationToZAxes();
plane_z->SetLookupTable(plane_x->GetLookupTable());
plane_z->SetInteractor(m_Window.GetInteractor());
plane_z->SetCurrentRenderer(m_Window.GetRenderer());
plane_z->SetOrigin(origin);
plane_z->SetPlaceFactor(1);
plane_z->DisplayTextOn();
plane_x->SetWindowLevel(255, 128);
plane_y->SetWindowLevel(255, 128);
plane_z->SetWindowLevel(255, 128);
plane_x->PlaceWidget();
plane_y->PlaceWidget();
plane_z->PlaceWidget();
//plane_x->On(); //CRASHES IF COMMENTED HERE!
//plane_y->On();
//plane_z->On();
m_Window.GetRenderer()->Render();
m_Window.GetRenderer()->ResetCamera();
More information about the vtkusers
mailing list