ctkDICOMIndexer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkDICOMIndexer_h
  15. #define __ctkDICOMIndexer_h
  16. // Qt includes
  17. #include <QObject>
  18. #include <QSqlDatabase>
  19. #include "ctkDICOMCoreExport.h"
  20. #include "ctkDICOMDatabase.h"
  21. class ctkDICOMIndexerPrivate;
  22. /// \ingroup DICOM_Core
  23. ///
  24. /// \brief Indexes DICOM images located in local directory into an Sql database
  25. ///
  26. class CTK_DICOM_CORE_EXPORT ctkDICOMIndexer : public QObject
  27. {
  28. Q_OBJECT
  29. public:
  30. explicit ctkDICOMIndexer(QObject *parent = 0);
  31. virtual ~ctkDICOMIndexer();
  32. ///
  33. /// \brief Adds directory to database and optionally copies files to
  34. /// destinationDirectory.
  35. ///
  36. /// Scan the directory using Dcmtk and populate the database with all the
  37. /// DICOM images accordingly.
  38. ///
  39. /// If includeHidden is set to false then hidden files and folders are not added.
  40. /// DICOM folders may be created based on series or study name, which sometimes start
  41. /// with a . character, therefore it is advisable to include hidden files and folders.
  42. ///
  43. Q_INVOKABLE void addDirectory(ctkDICOMDatabase& database, const QString& directoryName,
  44. const QString& destinationDirectoryName = "", bool includeHidden = true);
  45. ///
  46. /// \brief Adds directory to database by using DICOMDIR and optionally copies files to
  47. /// destinationDirectory.
  48. /// Scan the directory using Dcmtk and populate the database with all the
  49. /// DICOM images accordingly.
  50. /// \return Returns false if there was an error while processing the DICOMDIR file.
  51. ///
  52. Q_INVOKABLE bool addDicomdir(ctkDICOMDatabase& database, const QString& directoryName,
  53. const QString& destinationDirectoryName = "");
  54. ///
  55. /// \brief Adds a QStringList containing the file path to database and optionally copies files to
  56. /// destinationDirectory.
  57. ///
  58. /// Scan the directory using Dcmtk and populate the database with all the
  59. /// DICOM images accordingly.
  60. ///
  61. Q_INVOKABLE void addListOfFiles(ctkDICOMDatabase& database, const QStringList& listOfFiles,
  62. const QString& destinationDirectoryName = "");
  63. ///
  64. /// \brief Adds a file to database and optionally copies the file to
  65. /// destinationDirectory.
  66. ///
  67. /// Scan the file using Dcmtk and populate the database with all the
  68. /// DICOM fields accordingly.
  69. ///
  70. Q_INVOKABLE void addFile(ctkDICOMDatabase& database, const QString filePath,
  71. const QString& destinationDirectoryName = "");
  72. Q_INVOKABLE void refreshDatabase(ctkDICOMDatabase& database, const QString& directoryName);
  73. ///
  74. /// \brief Deprecated - no op.
  75. /// \deprecated
  76. /// Previously ensured that the QFuture threads have all finished indexing
  77. /// before returning control.
  78. ///
  79. Q_INVOKABLE void waitForImportFinished();
  80. /// Call this before performing multiple add...() calls in one batch
  81. /// to slightly increase indexing performance and to make only a single
  82. /// indexingComplete() signal emitted for multiple add...() operations.
  83. ///
  84. /// If startIndexing() is called before a batch of insertions, then
  85. /// endIndexing() method must be called after the insertions are completed.
  86. ///
  87. /// It is recommended to use ScopedIndexing helper class to call startIndexing
  88. /// and endIndexing automatically.
  89. Q_INVOKABLE void startIndexing(ctkDICOMDatabase& database);
  90. /// Call this method after batch insertion is completed, and only if startIndexing()
  91. /// was called before batch insertion was started.
  92. Q_INVOKABLE void endIndexing();
  93. /// Helper class to automatically call startIndexing and endIndexing.
  94. /// Its constructor calls startIndexing and its destructor calls endIndexing.
  95. ///
  96. /// Example:
  97. /// ...
  98. /// {
  99. /// ctkDICOMIndexer::ScopedIndexing indexingBatch(indexer, database); // this calls startIndexing
  100. /// indexer.addDirectory(database, dir1);
  101. /// indexer.addDirectory(database, dir2);
  102. /// indexer.addDirectory(database, dir3);
  103. /// } // endIndexing is called when indexingBatch goes out of scope
  104. ///
  105. class ScopedIndexing
  106. {
  107. public:
  108. ScopedIndexing(ctkDICOMIndexer& indexer, ctkDICOMDatabase& database)
  109. {
  110. this->Indexer = &indexer;
  111. this->Indexer->startIndexing(database);
  112. }
  113. ~ScopedIndexing()
  114. {
  115. this->Indexer->endIndexing();
  116. }
  117. private:
  118. ctkDICOMIndexer* Indexer;
  119. };
  120. Q_SIGNALS:
  121. void foundFilesToIndex(int);
  122. void indexingFileNumber(int);
  123. void indexingFilePath(QString);
  124. void progress(int);
  125. void indexingComplete();
  126. public Q_SLOTS:
  127. void cancel();
  128. protected:
  129. QScopedPointer<ctkDICOMIndexerPrivate> d_ptr;
  130. private:
  131. Q_DECLARE_PRIVATE(ctkDICOMIndexer);
  132. Q_DISABLE_COPY(ctkDICOMIndexer);
  133. };
  134. #endif