浏览代码

Class name changed to ctkDICOMObjectModel and some stylistic modifications

Alireza Mehrtash 12 年之前
父节点
当前提交
ee32e6766e

+ 2 - 3
Libs/DICOM/Core/CMakeLists.txt

@@ -40,8 +40,8 @@ set(KIT_SRCS
   ctkDICOMItem.h
   ctkDICOMModel.cpp
   ctkDICOMModel.h
-  ctkDICOMModelObject.cpp
-  ctkDICOMModelObject.h
+  ctkDICOMObjectModel.cpp
+  ctkDICOMObjectModel.h
   ctkDICOMPersonName.cpp
   ctkDICOMPersonName.h
   ctkDICOMQuery.cpp
@@ -50,7 +50,6 @@ set(KIT_SRCS
   ctkDICOMRetrieve.h
   ctkDICOMTester.cpp
   ctkDICOMTester.h
-
 )
 
 if(DCMTK_VERSION_IS_360)

+ 14 - 18
Libs/DICOM/Core/Testing/Cpp/ctkDICOMModelObjectTest1.cpp

@@ -23,15 +23,15 @@
 #include <algorithm>
 #include <limits>
 
-// CTK Core
-#include "ctkDICOMModelObject.h"
-
 // Qt includes
 #include <QApplication>
 #include <QFileDialog>
+#include <QHeaderView>
 #include <QString>
 #include <QTreeView>
-#include <QHeaderView>
+
+// CTK Core
+#include "ctkDICOMObjectModel.h"
 
 int main(int argv, char** argc)
 {
@@ -41,25 +41,20 @@ int main(int argv, char** argc)
 
   if( QApplication::argc() > 1)
     {
-      fileName = QApplication::argv()[1];
+    fileName = QApplication::argv()[1];
     }
   else
     {
-      fileName = QFileDialog::getOpenFileName( 0,
-       "Choose an image file", ".",
-       "DCM (*)" 
-       );
-      if( fileName.size() == 0 )
-	{
-	  return EXIT_SUCCESS;
-	}
+    fileName = QFileDialog::getOpenFileName( 0,
+    "Choose an image file", ".","DCM (*)" );
+    if( fileName.size() == 0 )
+	    {
+	    return EXIT_SUCCESS;
+	    }
     }
-  
-
-  ctkDICOMModelObject dcmInfoModel;
+  ctkDICOMObjectModel dcmInfoModel;
   dcmInfoModel.setFile(fileName);
-    
-
+  
   QTreeView *viewer = new QTreeView();
   viewer->setModel( &dcmInfoModel);
   viewer->expandAll();
@@ -68,5 +63,6 @@ int main(int argv, char** argc)
   viewer->header()->setResizeMode( QHeaderView::Stretch);
   viewer->show();
   viewer->raise();
+  
   return app.exec();
 }

+ 0 - 274
Libs/DICOM/Core/ctkDICOMModelObject.cpp

@@ -1,274 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) University of Sheffield
-
-  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.apache.org/licenses/LICENSE-2.0
-
-  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 include
-#include <QSharedData>
-#include <QStandardItem>
-#include <QString>
-#include <QStringList>
-
-// DCMTK includes
-#include "dcmtk/dcmdata/dcfilefo.h"
-#include "dcmtk/dcmdata/dcmetinf.h"
-#include "dcmtk/dcmdata/dcdeftag.h"
-#include "dcmtk/dcmdata/dcdatset.h"
-#include "dcmtk/dcmdata/dcitem.h"
-#include "dcmtk/ofstd/ofcond.h"
-#include "dcmtk/ofstd/ofstring.h"
-#include "dcmtk/ofstd/ofstd.h"        /* for class OFStandard */
-
-// CTK DICOM Core
-#include "ctkDICOMModelObject.h"
-
-//------------------------------------------------------------------------------
-class ctkDICOMModelObjectPrivate
-{
-  
-  Q_DECLARE_PUBLIC(ctkDICOMModelObject);
-protected:
-  ctkDICOMModelObject* const q_ptr;
-
-public:
-  ctkDICOMModelObjectPrivate(ctkDICOMModelObject&);
-  virtual ~ctkDICOMModelObjectPrivate();
-  void init();
-  void ctkDICOMModelObjectPrivate::itemInsert( DcmItem *dataset, QStandardItem *parent);
-  void ctkDICOMModelObjectPrivate::seqInsert( DcmSequenceOfItems *dataset, QStandardItem *parent);
-  QString ctkDICOMModelObjectPrivate::getTagValue( DcmElement *dcmElem);
-  QStandardItem* ctkDICOMModelObjectPrivate::populateModelRow(const QString& tagName,const QString& tagValue, QStandardItem *parent);
-
-  DcmFileFormat fileFormat;
-  QStandardItem *rootItem;
-};
-//------------------------------------------------------------------------------
-ctkDICOMModelObjectPrivate::ctkDICOMModelObjectPrivate(ctkDICOMModelObject& o):q_ptr(&o)
-{
-
-}
-
-//------------------------------------------------------------------------------
-ctkDICOMModelObjectPrivate::~ctkDICOMModelObjectPrivate()
-{
-
-}
-//------------------------------------------------------------------------------
-void ctkDICOMModelObjectPrivate::init()
-{
-Q_Q(ctkDICOMModelObject);
-QStringList horizontalHeaderLabels;
-horizontalHeaderLabels.append( QString("Tag"));
-horizontalHeaderLabels.append( QString("Value"));
-q->setHorizontalHeaderLabels(horizontalHeaderLabels);
-	
-}
-//------------------------------------------------------------------------------
-#undef max
-#undef min
-void ctkDICOMModelObjectPrivate::itemInsert( DcmItem *dataset, QStandardItem *parent)
-{
-  DcmStack stack;
-  dataset->nextObject( stack, OFTrue);
-
-  for( ; stack.top(); dataset->nextObject( stack, OFFalse))
-    {
-      DcmObject *dO =  stack.top();
-      // DcmElement *dcmElem = dataset->getElement( idx);
-      DcmElement *dcmElem = dynamic_cast<DcmElement *> (dO);
-      QString tagValue = "";
-
-      DcmTag tag = dO->getTag();
-      QString tagName = tag.getTagName();
-      if( tag.getXTag() == DCM_SequenceDelimitationItem
-	  || tag.getXTag() == DCM_ItemDelimitationItem
-	  || "Item" == tagName)
-	{
-	  return;
-	}
-
-        //    std::cerr << "node is dcmElem=" << dcmElem << "\n";
-
-      if( dcmElem)
-	{
-     
-	  tagValue = getTagValue(dcmElem);
-	}
-      // create items ...
-     QStandardItem *tagItem = populateModelRow(tagName,tagValue,parent);
-
-
-           // std::cerr << "    "
-     	//	<< tagName.toStdString() << " " << tagValue.toStdString();
-
-
-      if( dcmElem)
-	{
-	  // 	  std::cerr << " >> l=" << dcmElem->isLeaf() 
-	  //		    << "  nx=" << dataset->nextInContainer( dcmElem);
-	  if( !dcmElem->isLeaf())
-	    {
-	      // now dcmElem  points to a sequenceOfItems
-	      ctkDICOMModelObjectPrivate::seqInsert( dynamic_cast<DcmSequenceOfItems*> (dcmElem), tagItem);	 
-	    }
-	}
-
-      //      std::cerr  << "\n";
-    }
-
-}
-
-//------------------------------------------------------------------------------
-void ctkDICOMModelObjectPrivate::seqInsert( DcmSequenceOfItems *dataset, QStandardItem *parent)
-{
-
-  // std::clog << "Entering seqInsert" << "\n";
-  
-  DcmObject *dO = dataset->nextInContainer( NULL);
-
-  //std::clog << "Entered nested level   d0=" << dO << "\n";
-  //std::clog << "First node is dcmElem=" << dynamic_cast<DcmElement *> (dO) << "\n";
-
-  for( ; dO; dO = dataset->nextInContainer(dO))
-    {
-      // DcmElement *dcmElem = dataset->getElement( idx);
-      DcmElement *dcmElem = dynamic_cast<DcmElement *> (dO);
-      QString tagValue = "";
-
-      DcmTag tag = dO->getTag();
-      if( tag.getXTag() == DCM_SequenceDelimitationItem
-	  || tag.getXTag() == DCM_ItemDelimitationItem)
-	{
-	  return;
-	}
-
-      QString tagName = tag.getTagName();
-
-      //      std::cerr << "node is dcmElem=" << dcmElem << "\n";
-
-      if( dcmElem)
-	{
-	  tagValue = getTagValue(dcmElem);
-	}
-      
-      QStandardItem *tagItem = populateModelRow(tagName,tagValue,parent);
-
-      //      std::cerr << "    "
-      //		<< tagName.toStdString() << " " << tagValue.toStdString();
-
-
-      if( dcmElem)
-	{
-	  // 	  std::cerr << " >> l=" << dcmElem->isLeaf() 
-	  //		    << "  nx=" << dataset->nextInContainer( dcmElem);
-	  if( !dcmElem->isLeaf())
-	    {
-	      // now dcmElem  points to a sequenceOfItems
-			ctkDICOMModelObjectPrivate::seqInsert( dynamic_cast<DcmSequenceOfItems*> (dcmElem), tagItem);	 
-	    }
-	}
-      else if( tag.getXTag() == DCM_Item)
-	{
-	      itemInsert( dynamic_cast<DcmItem*> (dO), tagItem);	 
-	}
-      //      std::cerr  << "\n";
-    }
-}
-//------------------------------------------------------------------------------
-QString ctkDICOMModelObjectPrivate::getTagValue( DcmElement *dcmElem)
-{
-	QString tagValue = "";
-    std::ostringstream value;
-	  OFString part;
-	  std::string sep;
-	  int mult = dcmElem->getVM();
-	  int pos;
-	  if( mult>1)
-	    {
-	      value << "[" << mult << "] ";
-	    }
-	  // TODO define max elem per line
-	  for( pos=0; pos < std::min(mult,10); pos++)
-	    {
-	      value << sep;
-	      OFCondition status = dcmElem->getOFString( part, pos);
-	      if( status.good())
-		{
-		  value << part.c_str();
-		  sep = ", ";
-		}
-	    }
-	  if( pos < mult-1)
-	    {
-	      value << " ...";
-	    }
-	  tagValue = value.str().c_str();
-	  return tagValue;
-}
-
-//------------------------------------------------------------------------------
- QStandardItem* ctkDICOMModelObjectPrivate::populateModelRow(const QString& tagName,const QString& tagValue, QStandardItem *parent)
- {
-     // create items ...
-      QStandardItem *tagItem = new QStandardItem( tagName);
-      QStandardItem *valItem = new QStandardItem( tagValue);
-      // ... and insert them
-      QList<QStandardItem *> modelRow;
-      modelRow.append( tagItem);
-      modelRow.append( valItem);
-      parent->appendRow( modelRow);
-	  return tagItem;
- }
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-ctkDICOMModelObject::ctkDICOMModelObject(QObject* parentObject)
-  : Superclass(parentObject)
-  , d_ptr(new ctkDICOMModelObjectPrivate(*this))
-{
-Q_D(ctkDICOMModelObject);
-d->init();
- }
-
-//------------------------------------------------------------------------------
-ctkDICOMModelObject::ctkDICOMModelObject(const ctkDICOMModelObject& other)
-{
-}
-
-//------------------------------------------------------------------------------
-ctkDICOMModelObject::~ctkDICOMModelObject()
-{
-}
-
-//------------------------------------------------------------------------------
-
-void ctkDICOMModelObject::setFile(const QString &fileName)
-{
-  Q_D(ctkDICOMModelObject);
- 
-  OFCondition status = d->fileFormat.loadFile( fileName.toLatin1().data());
-  if( !status.good())
-    {
-		// TODO: Add through error
-    }
-  
-  DcmDataset *dataset = d->fileFormat.getDataset();
-  d->rootItem = ctkDICOMModelObject::invisibleRootItem();
-  d->itemInsert( dataset, d->rootItem);
-}

+ 234 - 0
Libs/DICOM/Core/ctkDICOMObjectModel.cpp

@@ -0,0 +1,234 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) University of Sheffield
+
+  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.apache.org/licenses/LICENSE-2.0
+
+  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 include
+#include <QSharedData>
+#include <QStandardItem>
+#include <QString>
+#include <QStringList>
+
+// DCMTK includes
+#include "dcmtk/dcmdata/dcdeftag.h"
+#include "dcmtk/dcmdata/dcdatset.h"
+#include "dcmtk/dcmdata/dcfilefo.h"
+#include "dcmtk/dcmdata/dcmetinf.h"
+#include "dcmtk/dcmdata/dcitem.h"
+#include "dcmtk/ofstd/ofcond.h"
+#include "dcmtk/ofstd/ofstring.h"
+#include "dcmtk/ofstd/ofstd.h"        /* for class OFStandard */
+
+// CTK DICOM Core
+#include "ctkDICOMObjectModel.h"
+
+//------------------------------------------------------------------------------
+class ctkDICOMObjectModelPrivate
+{
+  Q_DECLARE_PUBLIC(ctkDICOMObjectModel);
+protected:
+  ctkDICOMObjectModel* const q_ptr;
+
+public:
+  ctkDICOMObjectModelPrivate(ctkDICOMObjectModel&);
+  virtual ~ctkDICOMObjectModelPrivate();
+  void init();
+  void ctkDICOMObjectModelPrivate::itemInsert( DcmItem *dataset, QStandardItem *parent);
+  void ctkDICOMObjectModelPrivate::seqInsert( DcmSequenceOfItems *dataset, QStandardItem *parent);
+  QString ctkDICOMObjectModelPrivate::getTagValue( DcmElement *dcmElem);
+  QStandardItem* ctkDICOMObjectModelPrivate::populateModelRow(const QString& tagName,const QString& tagValue, QStandardItem *parent);
+
+  DcmFileFormat fileFormat;
+  QStandardItem *rootItem;
+};
+//------------------------------------------------------------------------------
+ctkDICOMObjectModelPrivate::ctkDICOMObjectModelPrivate(ctkDICOMObjectModel& o):q_ptr(&o)
+{
+}
+
+//------------------------------------------------------------------------------
+ctkDICOMObjectModelPrivate::~ctkDICOMObjectModelPrivate()
+{
+}
+//------------------------------------------------------------------------------
+void ctkDICOMObjectModelPrivate::init()
+{
+  Q_Q(ctkDICOMObjectModel);
+  QStringList horizontalHeaderLabels;
+  horizontalHeaderLabels.append( QString("Tag"));
+  horizontalHeaderLabels.append( QString("Value"));
+  q->setHorizontalHeaderLabels(horizontalHeaderLabels);
+	
+}
+//------------------------------------------------------------------------------
+void ctkDICOMObjectModelPrivate::itemInsert( DcmItem *dataset, QStandardItem *parent)
+{
+  DcmStack stack;
+  dataset->nextObject( stack, OFTrue);
+  for( ; stack.top(); dataset->nextObject( stack, OFFalse))
+    {
+    DcmObject *dO =  stack.top();
+    // DcmElement *dcmElem = dataset->getElement( idx);
+    DcmElement *dcmElem = dynamic_cast<DcmElement *> (dO);
+    QString tagValue = "";
+
+    DcmTag tag = dO->getTag();
+	// std::cout<<tag;
+    QString tagName = tag.getTagName();
+    DcmTag tagKey = tag.getXTag();
+	// std::cout<< tagName.toUtf8().constData()<<std::endl;
+    if( tagKey == DCM_SequenceDelimitationItem
+    || tagKey == DCM_ItemDelimitationItem
+    || "Item" == tagName)
+      {
+	    return;
+	    }
+  
+    tagValue = getTagValue(dcmElem);
+  
+    // Create items
+    QStandardItem *tagItem = populateModelRow(tagName,tagValue,parent);
+
+    if( dcmElem && !dcmElem->isLeaf())
+      {
+      // now dcmElem  points to a sequenceOfItems
+      ctkDICOMObjectModelPrivate::seqInsert( dynamic_cast<DcmSequenceOfItems*> (dcmElem), tagItem);	 
+      }
+    }
+}
+
+//------------------------------------------------------------------------------
+void ctkDICOMObjectModelPrivate::seqInsert( DcmSequenceOfItems *dataset, QStandardItem *parent)
+{
+  DcmObject *dO = dataset->nextInContainer( NULL);
+  
+  for( ; dO; dO = dataset->nextInContainer(dO))
+    {
+    DcmElement *dcmElem = dynamic_cast<DcmElement *> (dO);
+    QString tagValue = "";
+    DcmTag tag = dO->getTag();
+	DcmTag tagKey = tag.getXTag();
+
+    if( tagKey == DCM_SequenceDelimitationItem
+	  || tagKey == DCM_ItemDelimitationItem)
+	   {
+	   return;
+	    }
+  
+  QString tagName = tag.getTagName();
+  if( dcmElem)
+	  {
+	  tagValue = getTagValue(dcmElem);
+	  }
+  QStandardItem *tagItem = populateModelRow(tagName,tagValue,parent);
+  
+  if( dcmElem && !dcmElem->isLeaf())
+	  {
+	  ctkDICOMObjectModelPrivate::seqInsert( dynamic_cast<DcmSequenceOfItems*> (dcmElem), tagItem);	 
+    }
+  else if( tag.getXTag() == DCM_Item)
+	  {
+	  itemInsert( dynamic_cast<DcmItem*> (dO), tagItem);	 
+	  }
+    }
+}
+
+//------------------------------------------------------------------------------
+QString ctkDICOMObjectModelPrivate::getTagValue( DcmElement *dcmElem)
+{
+  QString tagValue = "";
+  std::ostringstream value;
+  OFString part;
+  std::string sep;
+  int mult = dcmElem->getVM();
+  int pos;
+  
+  if( mult>1)
+    {
+    value << "[" << mult << "] ";
+    }
+ 
+  // TODO define max elem per line
+  
+  for( pos=0; pos < mult; pos++)
+    {
+    value << sep;
+    OFCondition status = dcmElem->getOFString( part, pos);
+    if( status.good())
+		  {
+		  value << part.c_str();
+		  sep = ", ";
+		  }
+    }
+    if( pos < mult-1)
+      {
+       value << " ...";
+      }
+  tagValue = value.str().c_str();
+  
+  return tagValue;
+}
+
+//------------------------------------------------------------------------------
+ QStandardItem* ctkDICOMObjectModelPrivate::populateModelRow(const QString& tagName,const QString& tagValue, QStandardItem *parent)
+ {
+  // Create items
+  QStandardItem *tagItem = new QStandardItem( tagName);
+  QStandardItem *valItem = new QStandardItem( tagValue);
+  // Insert items
+  QList<QStandardItem *> modelRow;
+  modelRow.append( tagItem);
+  modelRow.append( valItem);
+  parent->appendRow( modelRow);
+  return tagItem;
+ }
+
+//------------------------------------------------------------------------------
+ctkDICOMObjectModel::ctkDICOMObjectModel(QObject* parentObject)
+  : Superclass(parentObject)
+  , d_ptr(new ctkDICOMObjectModelPrivate(*this))
+{
+  Q_D(ctkDICOMObjectModel);
+  d->init();
+ }
+
+//------------------------------------------------------------------------------
+ctkDICOMObjectModel::ctkDICOMObjectModel(const ctkDICOMObjectModel& other)
+{
+}
+
+//------------------------------------------------------------------------------
+ctkDICOMObjectModel::~ctkDICOMObjectModel()
+{
+}
+
+//------------------------------------------------------------------------------
+void ctkDICOMObjectModel::setFile(const QString &fileName)
+{
+  Q_D(ctkDICOMObjectModel);
+ 
+ OFCondition status = d->fileFormat.loadFile( fileName.toLatin1().data());
+  if( !status.good())
+    {
+		// TODO: Add through error
+    }
+  
+  DcmDataset *dataset = d->fileFormat.getDataset();
+  d->rootItem = ctkDICOMObjectModel::invisibleRootItem();
+  d->itemInsert( dataset, d->rootItem);
+}

+ 14 - 16
Libs/DICOM/Core/ctkDICOMModelObject.h

@@ -18,45 +18,43 @@
 
 =============================================================================*/
 
-#ifndef __ctkDICOMModelObject_h
-#define __ctkDICOMModelObject_h
+#ifndef __ctkDICOMObjectModel_h
+#define __ctkDICOMObjectModel_h
+
+// STD includes
+#include <string>
 
 // Qt includes
+#include <QMetaType>
 #include <QStandardItemModel>
 #include <QString>
 #include <QStringList>
-#include <QMetaType>
 
 #include "ctkDICOMCoreExport.h"
 
-#include <string>
-
-//class ctkDICOMModelObjectData;
-class ctkDICOMModelObjectPrivate;
+class ctkDICOMObjectModelPrivate;
 /// \ingroup DICOM_Core
 ///
 /// \brief .
 ///
-class CTK_DICOM_CORE_EXPORT ctkDICOMModelObject
-//class  ctkDICOMModelObject
+class CTK_DICOM_CORE_EXPORT ctkDICOMObjectModel
 	: public QStandardItemModel
 {
-
   typedef QStandardItemModel Superclass;
 
 public:
 
-  explicit ctkDICOMModelObject(QObject* parent = 0);
-  ctkDICOMModelObject(const ctkDICOMModelObject& other);
-  virtual ~ctkDICOMModelObject();
+  explicit ctkDICOMObjectModel(QObject* parent = 0);
+  ctkDICOMObjectModel(const ctkDICOMObjectModel& other);
+  virtual ~ctkDICOMObjectModel();
   void setFile (const QString& fileName);
 
 protected:
-  QScopedPointer<ctkDICOMModelObjectPrivate> d_ptr;
+  QScopedPointer<ctkDICOMObjectModelPrivate> d_ptr;
 
 private:
-Q_DECLARE_PRIVATE(ctkDICOMModelObject);
+Q_DECLARE_PRIVATE(ctkDICOMObjectModel);
 };
 
 
-#endif // ctkDICOMModelObject_h
+#endif // ctkDICOMObjectModel_h