[vtkusers] vtkResliceImageViewer: changing Window/Level contrast question
Daniel Mirota
dan at cs.jhu.edu
Thu Apr 25 10:16:52 EDT 2013
Hi, Audrius,
I figured out what is going on. There is a conflict between the
vtkResliceImageViewer base class vtkImageViewer2 and the
vtkInteractorStyleImage. The vtkImageViewer2 registers a callback
function on the window/level events, specifically
vtkCommand::WindowLevelEvent, vtkCommand::StartWindowLevelEvent,
vtkCommand::ResetWindowLevelEvent. The vtkInteractorStyleImage
delegates the StartWindowLevelEvent and ResetWindowLevelEvent events.
However, it does not delegate the WindowLevelEvent, which is the
source of the issue. In not delegating this event it starts the
window/level process with an initial window/level of 1 and 0.5. The
delegation do not occur because a vtkImageSlice is found and on
window/level start which set the CurrentImageProperty member of the
vtkInteractorStyleImage. If this member was not set the
vtkInteractorStyleImage would delegate this event.
I was able to reproduce this with VTK 5.10.1 on xubuntu 12.04 64-bit
and Windows 7 64-bit using the QtVTKRenderWindows example.
I don't know if this is the expected functionality or bug.
I'm looking into a workaround without changing VTK.
Dan
On Wed, Apr 24, 2013 at 8:21 AM, Daniel Mirota <dan at cs.jhu.edu> wrote:
> Hi, Audrius,
>
> I have run into the same issue as well. I know this is solved in CTK
> or Slicer. I'm just not too sure where. I've been skimming through
> the source but haven't tracked down the exact lines of code that fix
> this yet. Perhaps the Slicer folks could help. I've added their list
> to the email.
>
> Dan
>
> On Mon, Jan 14, 2013 at 12:50 AM, Audrius Stundzia
> <audrius at tomographix.com> wrote:
>> Hello vtk users,
>>
>> Have run into a problem/puzzle with regards to the Window/Level adjustment
>> settings in vtkResliceImageViewer.
>> [It's a very useful class, btw, so thanks to it's developers.]
>>
>> I've attached 2 example images that illustrate the issue. PET as the effect
>> is most dramatic ;-)
>> The same issue occurs for other modalities: MR and CT.
>>
>> The code [relevant fragment is below] reads the DICOM data and displays it
>> as expected [re PT_before.jpg].
>>
>> However, when the left mouse button is pressed and the icon is moved, rather
>> then the expected minor change
>> in the Window/Level settings, there is a very large change [re
>> PT_after.jpg].
>>
>> So,
>>
>> Is there something missing or wrong from the code below?
>>
>> Is the Window/Level change functionality missing from vtkResliceImageViewer?
>>
>> Is there a callback that I need to add? If so, is there a sample code
>> fragment somewhere?
>>
>> Any insight would be appreciated.
>>
>> Audrius
>>
>>
>> OS: Windows 7 x64
>> vtk: 5.10.1
>> compiler: VS 2008 version 9 [x64]
>>
>> Code fragment:
>>
>> vtkSmartPointer<vtkGDCMImageReader> imageReader =
>> vtkSmartPointer<vtkGDCMImageReader>::New();
>>
>> // . . . gets the DICOM data here
>>
>> // Scalar image data display
>> vtkSmartPointer<vtkResliceImageViewer> resliceImageViewer =
>> vtkSmartPointer<vtkResliceImageViewer>::New();
>> resliceImageViewer->SetInput( imageReader->GetOutput()); //
>>
>> std::string dicomModality =
>> imageReader->GetMedicalImageProperties()->GetModality();
>>
>> if( dicomModality == "PT" ||
>> dicomModality == "NM" ||
>> dicomModality == "ST" )
>> {
>> std::cout << "DICOM modality: " << dicomModality << std::endl;
>>
>> double window;
>> double level;
>>
>> imageReader->GetMedicalImageProperties()->GetNthWindowLevelPreset ( 0,
>> &window, &level );
>>
>> // A colour map of {r, g, b} triplets
>> boost::scoped_ptr<aRainbowColourMap> rainbowColourMapPtr(new
>> aRainbowColourMap);
>>
>> const vtkIdType nColours =
>> static_cast<vtkIdType>(rainbowColourMapPtr->GetNColours()); // 256 colours
>>
>> vtkSmartPointer<vtkWindowLevelLookupTable> windowLevelLookupTable =
>> vtkSmartPointer<vtkWindowLevelLookupTable>::New();
>> windowLevelLookupTable->SetWindow( window);
>> windowLevelLookupTable->SetLevel( level);
>> windowLevelLookupTable->SetNumberOfTableValues( nColours);
>>
>> for( vtkIdType iC = 0; iC < nColours; ++iC)
>> {
>> double r; double g; double b;
>>
>> rainbowColourMapPtr->GetRGB( iC, r, g, b );
>>
>> windowLevelLookupTable->SetTableValue( iC, r, g, b, 1.0 );
>> }
>>
>> windowLevelLookupTable->SetRampToLinear();
>> windowLevelLookupTable->Build();
>>
>> resliceImageViewer->SetLookupTable( windowLevelLookupTable);
>> }
>> else
>> if( dicomModality == "MR" )
>> {
>>
>> // . . . Analogous code for MR here
>>
>> }
>> else
>> if( dicomModality == "CT" )
>> {
>> // . . . Analogous code for CT here
>> }
>>
>> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>>
>> // Callback functions
>> // 1/ Close and exit vtk window
>> vtkSmartPointer<vtkCallbackCommand> keypressCallback =
>> vtkSmartPointer<vtkCallbackCommand>::New();
>> keypressCallback->SetCallback( KeypressCallbackFunction);
>> renderWindowInteractor->AddObserver( vtkCommand::KeyPressEvent,
>> keypressCallback );
>>
>> resliceImageViewer->SetupInteractor( renderWindowInteractor);
>>
>> // Initialize rendering and interaction
>> resliceImageViewer->GetRenderWindow()->SetSize( 900, 900 );
>> resliceImageViewer->GetRenderer()->SetBackground( 0.0, 0.0, 0.0 );
>>
>> resliceImageViewer->GetRenderer()->ResetCamera();
>> resliceImageViewer->SliceScrollOnMouseWheelOn();
>> resliceImageViewer->Render();
>>
>> renderWindowInteractor->Initialize();
>> renderWindowInteractor->Start();
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
More information about the vtkusers
mailing list