[vtkusers] Volume raycast cause exception in C++

Santiago Rodríguez santiagorodriguez at fibertel.com.ar
Thu Jul 6 01:34:44 EDT 2006


Hi Mathieu, I think your problem is in the SetDirectoryName,
SetFilePrefix and SetFilePattern calls.
 
Try this my example code:
*The dicom files are in the directory E:/DICOM Series/Serie_0001 (only
.dcm files in this directory)
*The name of the files are like this: 
        1.2.840.113619.2.134.1762902044.2015.1135868556.001.dcm
        1.2.840.113619.2.134.1762902044.2015.1135868556.002.dcm
        1.2.840.113619.2.134.1762902044.2015.1135868556.003.dcm
        ......
You have to see this very well to write the correct file prefix and
pattern.
 
vtkDICOMImageReader* reader = vtkDICOMImageReader::New();
reader->SetDirectoryName("E:/DICOM Series/Serie_0001");
reader->SetFilePrefix("1.2.840.113619.2.134.1762902044.2015.1135868556")
;
reader->SetFilePattern("%s.%3d.dcm");
reader->SetDataByteOrderToLittleEndian();
reader->SetDataScalarTypeToUnsignedChar();
reader->SetDataOrigin(0,0,0);
reader->Update();
 
I hope this help you.
Santiago Rodriguez
 
 
------------------------------------------------------------------------
----------------
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();
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.9/382 - Release Date:
04/07/2006
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060706/561cfa1d/attachment.htm>


More information about the vtkusers mailing list