Prechádzať zdrojové kódy

ENH: DICOMDatasetView updated to use ctkDICOMImage as input

Stephen R. Aylward 14 rokov pred
rodič
commit
1b9a0c2ad5

+ 15 - 4
Applications/ctkDICOMObjectViewer/ctkDICOMObjectViewerMain.cpp

@@ -25,6 +25,13 @@
 // CTK Widgets
 #include "ctkDICOMDatasetView.h"
 
+// CTK DICOM Core
+#include "ctkDICOMImage.h"
+
+// DCMTK includes
+#include <dcmimage.h>
+
+
 // Qt includes
 #include <QApplication>
 #include <QFileDialog>
@@ -47,15 +54,19 @@ int main(int argv, char** argc)
     {
     s = QFileDialog::getOpenFileName( 0,
      "Choose an image file", ".",
-     "JPG (*.jpg *.jpep);; PNG (*.png);; BMP (*.bmp);; TIFF (*.tif *.tiff)" 
+     "DCM (*.*)" 
      );
+    if( s.size() == 0 )
+      {
+      return EXIT_SUCCESS;
+      }
     }
 
-  QImage image( s );
-  std::cout << "Loading image _" << s.toStdString() << "_" << std::endl;
+  DicomImage dcmImage( s.toStdString().c_str() );
+  ctkDICOMImage ctkImage( & dcmImage );
 
   ctkDICOMDatasetView imageView;
-  imageView.addImage( & image );
+  imageView.addImage( ctkImage );
   imageView.show();
   imageView.raise();
 

+ 5 - 23
Libs/DICOM/Widgets/ctkDICOMDatasetView.cpp

@@ -95,35 +95,17 @@ ctkDICOMDatasetView::~ctkDICOMDatasetView()
 }
 
 // -------------------------------------------------------------------------
-//void ctkDICOMDatasetView::addImage( const QImage * image )
-//{
-  //Q_D( ctkQImageView );
-  //d->ImageList.push_back( image );
-  //d->TmpXMin = 0;
-  //d->TmpXMax = image->width();
-  //d->TmpYMin = 0;
-  //d->TmpYMax = image->height();
-  //this->update( true, false );
-  //this->setCenter( image->width()/2.0, image->height()/2.0 );
-//}
-
-// -------------------------------------------------------------------------
-void ctkDICOMDatasetView::mousePressEvent( QMouseEvent * event )
+void ctkDICOMDatasetView::addImage( const ctkDICOMImage & image )
 {
-  event->ignore();
-}
-
-// -------------------------------------------------------------------------
-void ctkDICOMDatasetView::mouseMoveEvent( QMouseEvent * event )
-{
-  event->ignore();
+  for( unsigned int i=0; i<image.frameCount(); ++i )
+    {
+    Superclass::addImage( image.getImage( i ) );
+    }
 }
 
 // -------------------------------------------------------------------------
 void ctkDICOMDatasetView::update( bool zoomChanged,
   bool sizeChanged )
 {
-  std::cout << "DICOM Updating.." << std::endl;
-
   Superclass::update( zoomChanged, sizeChanged );
 }

+ 2 - 4
Libs/DICOM/Widgets/ctkDICOMDatasetView.h

@@ -28,6 +28,7 @@
 /// CTK includes
 #include "ctkQImageView.h"
 #include "ctkPimpl.h"
+#include "ctkDICOMImage.h"
 #include "ctkDICOMWidgetsExport.h"
 
 class ctkDICOMDatasetViewPrivate;
@@ -53,10 +54,7 @@ public:
 
 public slots:
 
-  //void add( const QImage * image );
-
-  void mousePressEvent( QMouseEvent * event );
-  void mouseMoveEvent( QMouseEvent * event );
+  void addImage( const ctkDICOMImage & image );
 
   virtual void update( bool zoomChanged=false, bool sizeChanged=false );
 

+ 38 - 31
Libs/Widgets/ctkQImageView.cpp

@@ -64,7 +64,7 @@ public:
   bool FlipYAxis;
   bool TransposeXY;
 
-  QList< const QImage * > ImageList;
+  QList< QImage > ImageList;
 
   QPixmap TmpImage;
   int     TmpXMin;
@@ -163,13 +163,13 @@ void ctkQImageViewPrivate::fitImageRectangle( double x0,
   if( this->SliceNumber >= 0 && this->SliceNumber < this->ImageList.size() )
     {
     this->TmpXMin = this->clamp( x0, 0,
-      this->ImageList[ this->SliceNumber ]->width() );
+      this->ImageList[ this->SliceNumber ].width() );
     this->TmpXMax = this->clamp( x1, this->TmpXMin,
-      this->ImageList[ this->SliceNumber ]->width() );
+      this->ImageList[ this->SliceNumber ].width() );
     this->TmpYMin = this->clamp( y0, 0,
-      this->ImageList[ this->SliceNumber ]->height() );
+      this->ImageList[ this->SliceNumber ].height() );
     this->TmpYMax = this->clamp( y1, this->TmpYMin,
-      this->ImageList[ this->SliceNumber ]->height() );
+      this->ImageList[ this->SliceNumber ].height() );
 
     this->CenterX = ( this->TmpXMax + this->TmpXMin ) / 2.0;
     this->CenterY = ( this->TmpYMax + this->TmpYMin ) / 2.0;
@@ -204,16 +204,16 @@ ctkQImageView::~ctkQImageView()
 }
 
 // -------------------------------------------------------------------------
-void ctkQImageView::addImage( const QImage * image )
+void ctkQImageView::addImage( const QImage & image )
 {
   Q_D( ctkQImageView );
   d->ImageList.push_back( image );
   d->TmpXMin = 0;
-  d->TmpXMax = image->width();
+  d->TmpXMax = image.width();
   d->TmpYMin = 0;
-  d->TmpYMax = image->height();
+  d->TmpYMax = image.height();
   this->update( true, false );
-  this->setCenter( image->width()/2.0, image->height()/2.0 );
+  this->setCenter( image.width()/2.0, image.height()/2.0 );
 }
 
 // -------------------------------------------------------------------------
@@ -230,7 +230,7 @@ double ctkQImageView::xSpacing( void )
   Q_D( ctkQImageView );
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
-    return( 1000.0 / d->ImageList[ d->SliceNumber ]->dotsPerMeterX() );
+    return( 1000.0 / d->ImageList[ d->SliceNumber ].dotsPerMeterX() );
     }
   else
     {
@@ -244,7 +244,7 @@ double ctkQImageView::ySpacing( void )
   Q_D( ctkQImageView );
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
-    return( 1000.0 / d->ImageList[ d->SliceNumber ]->dotsPerMeterY() );
+    return( 1000.0 / d->ImageList[ d->SliceNumber ].dotsPerMeterY() );
     }
   else
     {
@@ -285,7 +285,7 @@ double ctkQImageView::positionValue( void )
   Q_D( ctkQImageView );
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
-    QColor vc( d->ImageList[ d->SliceNumber ]->pixel( d->PositionX,
+    QColor vc( d->ImageList[ d->SliceNumber ].pixel( d->PositionX,
       d->PositionY ) );
     return vc.value();
     }
@@ -429,14 +429,14 @@ void ctkQImageView::setCenter( double x, double y )
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
 	  int tmpXRange = d->TmpXMax - d->TmpXMin;
-    if( tmpXRange > d->ImageList[ d->SliceNumber ]->width() )
+    if( tmpXRange > d->ImageList[ d->SliceNumber ].width() )
       {
-      tmpXRange = d->ImageList[ d->SliceNumber ]->width();
+      tmpXRange = d->ImageList[ d->SliceNumber ].width();
       }
     int tmpYRange = d->TmpYMax - d->TmpYMin;
-    if( tmpYRange > d->ImageList[ d->SliceNumber ]->height() )
+    if( tmpYRange > d->ImageList[ d->SliceNumber ].height() )
       {
-      tmpYRange = d->ImageList[ d->SliceNumber ]->height();
+      tmpYRange = d->ImageList[ d->SliceNumber ].height();
       }
   
     int xMin2 = static_cast<int>(x) - tmpXRange/2.0;
@@ -445,9 +445,9 @@ void ctkQImageView::setCenter( double x, double y )
       xMin2 = 0;
       }
     int xMax2 = xMin2 + tmpXRange;
-    if( xMax2 > d->ImageList[ d->SliceNumber ]->width() )
+    if( xMax2 > d->ImageList[ d->SliceNumber ].width() )
       {
-      xMax2 = d->ImageList[ d->SliceNumber ]->width();
+      xMax2 = d->ImageList[ d->SliceNumber ].width();
       xMin2 = xMax2 - tmpXRange;
       }
     int yMin2 = static_cast<int>(y) - tmpYRange/2.0;
@@ -456,9 +456,9 @@ void ctkQImageView::setCenter( double x, double y )
       yMin2 = 0;
       }
     int yMax2 = yMin2 + tmpYRange;
-    if( yMax2 > d->ImageList[ d->SliceNumber ]->height() )
+    if( yMax2 > d->ImageList[ d->SliceNumber ].height() )
       {
-      yMax2 = d->ImageList[ d->SliceNumber ]->height();
+      yMax2 = d->ImageList[ d->SliceNumber ].height();
       yMin2 = yMax2 - tmpYRange;
       }
     d->fitImageRectangle( xMin2, xMax2, yMin2, yMax2 );
@@ -504,7 +504,7 @@ void ctkQImageView::setZoom( double factor )
   Q_D( ctkQImageView );
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
-    const QImage * img = d->ImageList[ d->SliceNumber ];
+    const QImage * img = & d->ImageList[ d->SliceNumber ];
     if( factor < 2.0 / img->width() )
       {
       factor = 2.0 / img->width();
@@ -528,9 +528,9 @@ void ctkQImageView::setZoom( double factor )
       xMin2 = 0;
       }
     int xMax2 = xMin2 + x2;
-    if( xMax2 > d->ImageList[ d->SliceNumber ]->width() )
+    if( xMax2 > d->ImageList[ d->SliceNumber ].width() )
       {
-      xMax2 = d->ImageList[ d->SliceNumber ]->width();
+      xMax2 = d->ImageList[ d->SliceNumber ].width();
       xMin2 = xMax2 - x2;
       }
     int yMin2 = static_cast<int>(cy) - y2 / 2.0;
@@ -539,9 +539,9 @@ void ctkQImageView::setZoom( double factor )
       yMin2 = 0;
       }
     int yMax2 = yMin2 + y2;
-    if( yMax2 > d->ImageList[ d->SliceNumber ]->height() )
+    if( yMax2 > d->ImageList[ d->SliceNumber ].height() )
       {
-      yMax2 = d->ImageList[ d->SliceNumber ]->height();
+      yMax2 = d->ImageList[ d->SliceNumber ].height();
       yMin2 = yMax2 - y2;
       }
     d->fitImageRectangle( xMin2, xMax2, yMin2, yMax2 );
@@ -555,10 +555,20 @@ void ctkQImageView::reset( )
 {
   Q_D( ctkQImageView );
 
+  if( d->ImageList.size() > 0 )
+    {
+    if( d->SliceNumber < 0 )
+      {
+      this->setSliceNumber( 0 );
+      }
+    }
+
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
-    d->fitImageRectangle( 0, 0, d->ImageList[ d->SliceNumber ]->width(),
-      d->ImageList[ d->SliceNumber ]->height() );
+    d->fitImageRectangle( 0, 0, d->ImageList[ d->SliceNumber ].width(),
+      d->ImageList[ d->SliceNumber ].height() );
+
+	  this->update( true, true );
     }
 }
 
@@ -715,15 +725,12 @@ void ctkQImageView::resizeEvent( QResizeEvent* event )
 void ctkQImageView::update( bool zoomChanged,
   bool sizeChanged )
 {
-  std::cout << "Updating.." << std::endl;
-
   Q_D( ctkQImageView );
   if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() )
     {
-    const QImage * img = d->ImageList[ d->SliceNumber ];
+    const QImage * img = & ( d->ImageList[ d->SliceNumber ] );
     if( zoomChanged || sizeChanged )
       {
-      std::cout << "Update: Changed" << std::endl;
       if( this->width() > 0 &&  this->height() > 0 
         && d->TmpXMax > d->TmpXMin && d->TmpYMax > d->TmpYMin)
         {

+ 1 - 1
Libs/Widgets/ctkQImageView.h

@@ -75,7 +75,7 @@ public:
 
 public slots:
 
-  void addImage( const QImage * image );
+  void addImage( const QImage & image );
   void clearImages( void );
 
   void setSliceNumber( int slicenum );