[Insight-users] Changes to Fltk Image Viewer for better overlay/color support

Martin Styner martin_styner@ieee.org
Mon, 25 Nov 2002 11:30:47 +0100


Hi

I adjusted the fltkImageViewer Auxiliary code for better support of 
overlays (unsigned short overlays, more than 255 different colors) and 
color tables. Also, fltkImageViewer does not crash when it has an 
overlay with a value outside of the colortable. I think these changes 
are worth taking into the itk source. E.g. with the changes, I can 
display an overlay with my own colormap using fltkImageViewer:

typedef fltk::ImageViewer< ImagePixelType, OverlayPixelType > 
ImageViewerType;
typedef MyOwnColorTable<float>   ColorTableType;

ImageViewerType imageViewer;
imageViewer.SetLabel(" Image");
imageViewer.SetImage( image );
imageViewer.SetOverlay( outputImage );
imageViewer.SetOverlayOpacity(0.8);
ColorTableType::Pointer colorTable = ColorTableType::New();
colorTable->useMSColorTable(1900);
imageViewer.SetOverlayColorTable( (ImageViewerType::ColorTablePointer) 
colorTable);
imageViewer.Show();
Fl::run();


Below are the diffs of the file changes,
Best regards
Martin

Index: Auxiliary/FltkImageViewer/fltkImageViewer.h
===================================================================
RCS file: 
/cvsroot/Insight/Insight/Auxiliary/FltkImageViewer/fltkImageViewer.h,v
retrieving revision 1.8
diff -r1.8 fltkImageViewer.h
43a44
 >   typedef GLSliceViewType::ColorTablePointer ColorTablePointer;
80a82,92
 >   /*! Specify the opacity of the overlay */
 >   virtual void  SetOverlayOpacity(float newOverlayOpacity);
 >
 >   /*! Get the opacity of the overlay */
 >   virtual float GetOverlayOpacity(void);
 >
 >   /*! Get the ColorTable for the Overlay */
 >   virtual ColorTablePointer GetOverlayColorTable(void);
 >   /*! Set the ColorTable for the Overlay */
 >   virtual void SetOverlayColorTable(ColorTablePointer newColorTable);

Index: Auxiliary/FltkImageViewer/GLSliceView.h
===================================================================
RCS file: /cvsroot/Insight/Insight/Auxiliary/FltkImageViewer/GLSliceView.h,v
retrieving revision 1.6
diff -r1.6 GLSliceView.h
97c97,98
<   ColorTableType * GetColorTable(void);
---
 >   ColorTablePointer GetColorTable(void);
 >   void SetColorTable(ColorTablePointer newColorTable);
402,404c403,404
< template <class ImagePixelType, class OverlayPixelType>
< typename GLSliceView<ImagePixelType, OverlayPixelType>::ColorTableType
< *
---
 > template <class ImagePixelType, class OverlayPixelType>
 > typename GLSliceView<ImagePixelType, OverlayPixelType>::ColorTablePointer
407c407
<   return &cColorTable;
---
 >   return cColorTable;
410a411,417
 > template <class ImagePixelType, class OverlayPixelType>
 > void
 > GLSliceView<ImagePixelType, OverlayPixelType>::SetColorTable(typename 
GLSliceView<ImagePixelType, OverlayPixelType>::ColorTablePointer 
newColorTable)
 >   {
 >   cColorTable = newColorTable;
 >   }
 >
643c650
<         if( sizeof( OverlayPixelType ) == 1 )
---
 >         if( sizeof( OverlayPixelType ) == 1 ||  sizeof( 
OverlayPixelType ) == 2 )
645c652,660
<           m = (int)*((unsigned char *)&(cOverlayData->GetPixel(ind)));
---
 >           if (sizeof( OverlayPixelType ) == 1)
 >             {
 >               m = (int)*((unsigned char 
*)&(cOverlayData->GetPixel(ind)));
 >             }
 >           else
 >             {
 >               m = (int)*((unsigned short 
*)&(cOverlayData->GetPixel(ind)));
 >             }
 >         if( m >= cColorTable->size() ) { m = cColorTable->size() - 1; };


Index: Auxiliary/FltkImageViewer/fltkImageViewer.txx
===================================================================
RCS file: 
/cvsroot/Insight/Insight/Auxiliary/FltkImageViewer/fltkImageViewer.txx,v
retrieving revision 1.9
diff -r1.9 fltkImageViewer.txx
63a64,98
 > /*! Specify the opacity of the overlay */
 > template <class ImagePixelType, class OverlayPixelType>
 > void
 > ImageViewer<ImagePixelType,OverlayPixelType>
 > ::SetOverlayOpacity(float newOverlayOpacity)
 > {
 >   glSliceView->OverlayOpacity( newOverlayOpacity );
 > }
 >
 > /*! Get the opacity of the overlay */
 > template <class ImagePixelType, class OverlayPixelType>
 > float
 > ImageViewer<ImagePixelType,OverlayPixelType>
 > ::GetOverlayOpacity(void)
 > {
 >   return glSliceView->OverlayOpacity();
 > }
 >
 > /*! Get the ColorTable for the Overlay */
 > template <class ImagePixelType, class OverlayPixelType>
 > typename ImageViewer<ImagePixelType, OverlayPixelType>::ColorTablePointer
 > ImageViewer<ImagePixelType,OverlayPixelType>
 > ::GetOverlayColorTable(void)
 > {
 >   return glSliceView->GetColorTable();
 > }
 >
 > /*! Set the ColorTable for the Overlay */
 > template <class ImagePixelType, class OverlayPixelType>
 > void
 > ImageViewer<ImagePixelType,OverlayPixelType>
 > ::SetOverlayColorTable(ColorTablePointer newColorTable)
 > {
 >   glSliceView->SetColorTable(newColorTable);
 > }

-- 
Martin Styner, PhD. Ing. ETH
Group Head Medical Image Analysis for Orthopiaedics
M.E. Mueller Institute for Biomechanics
Center for Computed Assisted Surgery
University of Bern
Murtenstrasse 35
P.O.Box 30
CH - 3010 Bern
Switzerland
Tel office: ++41-31-632-0940 , FAX: ++41-31-632-4951
email: Martin.Styner@memot.unibe.ch, martin_styner@ieee.org
WWW: http://cranium.unibe.ch/~mstyner