Pārlūkot izejas kodu

Merge branch 'image-integration' into dah

Ivo Wolf 14 gadi atpakaļ
vecāks
revīzija
a9cf1bd134

+ 4 - 0
Libs/DICOM/Core/CMakeLists.txt

@@ -9,8 +9,11 @@ SET(KIT_export_directive "CTK_DICOM_CORE_EXPORT")
   
 # Source files
 SET(KIT_SRCS
+
   ctkDICOM.cpp
   ctkDICOM.h
+  ctkDICOMImage.cpp
+  ctkDICOMImage.h
   ctkDICOMIndexer.cpp
   ctkDICOMIndexer.h
   ctkDICOMIndexerBase.cpp
@@ -27,6 +30,7 @@ SET(KIT_SRCS
 SET(KIT_MOC_SRCS
   ctkDICOM.h
   ctkDICOMIndexerBase.h
+  ctkDICOMImage.h
   ctkDICOMModel.h
   ctkDICOMQuery.h
   ctkDICOMRetrieve.h

+ 6 - 1
Libs/DICOM/Core/Testing/Cpp/CMakeLists.txt

@@ -1,8 +1,9 @@
 SET(KIT ${PROJECT_NAME})
 
 CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cpp
-  ctkDICOMModelTest1.cpp
+  ctkDICOMImageTest1.cpp
   ctkDICOMTest1.cpp
+  ctkDICOMImageTest1.cpp
   )
 
 SET (TestsToRun ${Tests})
@@ -23,6 +24,10 @@ ENDMACRO( SIMPLE_TEST  )
 #
 # Add Tests
 #
+ADD_TEST( ctkDICOMImageTest1 ${KIT_TESTS}
+          ctkDICOMImageTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA)
+SET_PROPERTY(TEST ctkDICOMImageTest1 PROPERTY LABELS ${PROJECT_NAME})
+
 
 ADD_TEST( ctkDICOMModelTest1 ${KIT_TESTS}
           ctkDICOMModelTest1 ${CMAKE_CURRENT_BINARY_DIR}/dicom.db

+ 40 - 0
Libs/DICOM/Core/Testing/Cpp/ctkDICOMImageTest1.cpp

@@ -0,0 +1,40 @@
+
+// Qt includes
+#include <QApplication>
+#include <QLabel>
+
+
+// ctkDICOMCore includes
+#include "ctkDICOMImage.h"
+
+// DCMTK includes
+#include <dcmimage.h>
+
+// STD includes
+#include <iostream>
+
+
+int ctkDICOMImageTest1( int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  if (argc <= 1)
+    {
+    std::cerr << "Warning, no dicom file given. Test stops" << std::endl;
+    std::cerr << "Usage: qctkDICOMImageTest1 <dicom file>" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  DicomImage dcmtkImage(argv[1]);
+  ctkDICOMImage ctkImage(&dcmtkImage);
+
+  QLabel qtImage;
+  qtImage.setPixmap(ctkImage.getPixmap(0));
+  qtImage.show();
+
+  if (argc > 2 && QString(argv[2]) == "-I")
+    {
+      return app.exec();
+    }
+  return EXIT_SUCCESS;
+}

+ 124 - 0
Libs/DICOM/Core/ctkDICOMImage.cpp

@@ -0,0 +1,124 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QString>
+
+// ctkDICOMCore includes
+#include "ctkDICOMImage.h"
+#include "ctkLogger.h"
+
+// DCMTK includes
+#include "dcmimage.h"
+#include <ofbmanip.h>
+
+static ctkLogger logger ( "org.commontk.dicom.DICOMImage" );
+struct Node;
+
+//------------------------------------------------------------------------------
+class ctkDICOMImagePrivate
+{
+  Q_DECLARE_PUBLIC(ctkDICOMImage);
+protected:
+  ctkDICOMImage* const q_ptr;
+  
+public:
+  ctkDICOMImagePrivate(ctkDICOMImage&);
+  virtual ~ctkDICOMImagePrivate();
+
+  ::DicomImage* DicomImage;
+};
+
+//------------------------------------------------------------------------------
+ctkDICOMImagePrivate::ctkDICOMImagePrivate(ctkDICOMImage& o):q_ptr(&o)
+{
+
+}
+
+//------------------------------------------------------------------------------
+ctkDICOMImagePrivate::~ctkDICOMImagePrivate()
+{
+
+}
+
+
+//------------------------------------------------------------------------------
+ctkDICOMImage::ctkDICOMImage(DicomImage* dicomImage, QObject* parentValue): d_ptr(new ctkDICOMImagePrivate(*this))
+{
+  Q_UNUSED(parentValue);
+  Q_D(ctkDICOMImage);
+  d->DicomImage = dicomImage;
+  // select first window by default
+  d->DicomImage->setWindow(0);
+}
+
+//------------------------------------------------------------------------------
+ctkDICOMImage::~ctkDICOMImage()
+{
+}
+
+unsigned long ctkDICOMImage::frameCount() const
+{
+  Q_D(const ctkDICOMImage);
+  if (d->DicomImage)
+  {
+    return d->DicomImage->getFrameCount();
+  }
+  return 0;
+}
+DicomImage* ctkDICOMImage::getDicomImage() const
+{
+  Q_D(const ctkDICOMImage);
+  return d->DicomImage;
+}
+QPixmap ctkDICOMImage::getPixmap(int frame) const
+{
+  Q_D(const ctkDICOMImage);
+
+  // this way of converting the dicom image to a qpixmap was adopted from some code from
+  // the DCMTK forum, posted by Joerg Riesmayer, see http://forum.dcmtk.org/viewtopic.php?t=120
+  QPixmap pixmap;
+  if ((d->DicomImage != NULL) && (d->DicomImage->getStatus() == EIS_Normal))
+  {
+    /* get image extension */
+    const unsigned long width = d->DicomImage->getWidth();
+    const unsigned long height = d->DicomImage->getHeight();
+    QString header = QString("P5 %1 %2 255\n").arg(width).arg(height);
+    const unsigned long offset = header.length();
+    const unsigned long length = width * height + offset;
+    /* create output buffer for DicomImage class */
+    QByteArray buffer;
+    buffer.append(header);
+    buffer.resize(length);
+
+    /* copy PGM header to buffer */
+
+    if (d->DicomImage->getOutputData(static_cast<void *>(buffer.data() + offset), length - offset, 8, frame))
+    {
+      if (!pixmap.loadFromData(buffer, "PGM", Qt::AvoidDither))
+      {
+        logger.error("Pixmap couldn't created");
+      }
+    }
+  }
+  return pixmap;
+}

+ 53 - 0
Libs/DICOM/Core/ctkDICOMImage.h

@@ -0,0 +1,53 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkDICOMImage_h
+#define __ctkDICOMImage_h
+
+// Qt includes 
+#include <QObject>
+#include <QPixmap>
+
+#include "ctkDICOMCoreExport.h"
+
+class ctkDICOMImagePrivate;
+class DicomImage;
+
+class CTK_DICOM_CORE_EXPORT ctkDICOMImage : public QObject
+{
+  Q_OBJECT
+public:
+  explicit ctkDICOMImage(DicomImage* dicomImage, QObject* parent = 0);
+  virtual ~ctkDICOMImage();
+  DicomImage* getDicomImage() const;
+  QPixmap getPixmap(int frame = 0) const;
+  unsigned long frameCount() const;
+  Q_PROPERTY(unsigned long frameCount READ frameCount);
+
+protected:
+  QScopedPointer<ctkDICOMImagePrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkDICOMImage);
+  Q_DISABLE_COPY(ctkDICOMImage);
+};
+
+#endif

+ 19 - 0
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp

@@ -23,11 +23,19 @@
 #include "ctkExampleDicomAppLogic_p.h"
 #include "ctkExampleDicomAppPlugin_p.h"
 
+// Qt includes
 #include <QtPlugin>
 #include <QRect>
 #include <QDebug>
 #include <QPushButton>
 #include <QApplication>
+#include <QLabel>
+
+// ctkDICOMCore includes
+#include "ctkDICOMImage.h"
+
+// DCMTK includes
+#include <dcmimage.h>
 
 ctkExampleDicomAppLogic::ctkExampleDicomAppLogic()
   : hostTracker(ctkExampleDicomAppPlugin::getPluginContext()), button(NULL)
@@ -198,6 +206,17 @@ void ctkExampleDicomAppLogic::buttonClicked()
   {
     s=s+" URI: "+locators.begin()->URI;
     qDebug() << "URI: " << locators.begin()->URI;
+    QString filename = locators.begin()->URI;
+    if(filename.startsWith("file:/",Qt::CaseInsensitive))
+      filename=filename.remove(0,6);
+    qDebug()<<filename;
+    DicomImage dcmtkImage(filename.toLatin1().data());
+    ctkDICOMImage ctkImage(&dcmtkImage);
+
+    QLabel* qtImage = new QLabel;
+    qtImage->setPixmap(ctkImage.getPixmap(0));
+    qtImage->show();
   }
   button->setText(s);
+
 }