ctkExampleDicomAppLogic.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. // Qt includes
  16. #include <QtPlugin>
  17. #include <QRect>
  18. #include <QDebug>
  19. #include <QPushButton>
  20. #include <QApplication>
  21. #include <QLabel>
  22. // CTK includes
  23. #include "ctkDICOMImage.h"
  24. #include "ctkExampleDicomAppLogic_p.h"
  25. #include "ctkExampleDicomAppPlugin_p.h"
  26. // DCMTK includes
  27. #include <dcmimage.h>
  28. //----------------------------------------------------------------------------
  29. ctkExampleDicomAppLogic::ctkExampleDicomAppLogic():
  30. ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), Button(0)
  31. {
  32. connect(this, SIGNAL(startProgress()), this, SLOT(onStartProgress()), Qt::QueuedConnection);
  33. connect(this, SIGNAL(resumeProgress()), this, SLOT(onResumeProgress()), Qt::QueuedConnection);
  34. connect(this, SIGNAL(SuspendProgress()), this, SLOT(onSuspendProgress()), Qt::QueuedConnection);
  35. connect(this, SIGNAL(cancelProgress()), this, SLOT(onCancelProgress()), Qt::QueuedConnection);
  36. connect(this, SIGNAL(exitHostedApp()), this, SLOT(onExitHostedApp()), Qt::QueuedConnection);
  37. //notify Host we are ready.
  38. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  39. }
  40. //----------------------------------------------------------------------------
  41. ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
  42. {
  43. ctkPluginContext* context = ctkExampleDicomAppPlugin::getPluginContext();
  44. QList <QSharedPointer<ctkPlugin> > plugins = context->getPlugins();
  45. for (int i = 0; i < plugins.size(); ++i)
  46. {
  47. qDebug() << plugins.at(i)->getSymbolicName ();
  48. }
  49. }
  50. //----------------------------------------------------------------------------
  51. bool ctkExampleDicomAppLogic::bringToFront(const QRect& /*requestedScreenArea*/)
  52. {
  53. return false;
  54. }
  55. //----------------------------------------------------------------------------
  56. void ctkExampleDicomAppLogic::do_something()
  57. {
  58. this->Button = new QPushButton("Button from App");
  59. connect(this->Button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
  60. try
  61. {
  62. QRect preferred(50,50,100,100);
  63. qDebug() << " Asking:getAvailableScreen";
  64. QRect rect = getHostInterface()->getAvailableScreen(preferred);
  65. qDebug() << " got sth:" << rect.top();
  66. this->Button->move(rect.topLeft());
  67. this->Button->resize(rect.size());
  68. }
  69. catch (const std::runtime_error& e)
  70. {
  71. qCritical() << e.what();
  72. return;
  73. }
  74. this->Button->show();
  75. }
  76. //----------------------------------------------------------------------------
  77. void ctkExampleDicomAppLogic::onStartProgress()
  78. {
  79. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  80. do_something();
  81. }
  82. //----------------------------------------------------------------------------
  83. void ctkExampleDicomAppLogic::onResumeProgress()
  84. {
  85. //reclame all resources.
  86. //notify state changed
  87. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  88. //we're rolling
  89. //do something else normally, but this is an example
  90. this->Button->setEnabled(true);
  91. }
  92. //----------------------------------------------------------------------------
  93. void ctkExampleDicomAppLogic::onSuspendProgress()
  94. {
  95. //release resources it can reclame later to resume work
  96. this->Button->setEnabled(false);
  97. //notify state changed
  98. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  99. //we're rolling
  100. //do something else normally, but this is an example
  101. }
  102. //----------------------------------------------------------------------------
  103. void ctkExampleDicomAppLogic::onCancelProgress()
  104. {
  105. //release all resources
  106. onReleaseResources();
  107. //update state
  108. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  109. }
  110. //----------------------------------------------------------------------------
  111. void ctkExampleDicomAppLogic::onExitHostedApp()
  112. {
  113. qApp->exit(0);
  114. }
  115. //----------------------------------------------------------------------------
  116. bool ctkExampleDicomAppLogic::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
  117. {
  118. Q_UNUSED(lastData)
  119. QString s;
  120. if(this->Button == 0)
  121. {
  122. qCritical() << "Button is null!";
  123. return false;
  124. }
  125. s = "Received notifyDataAvailable with patients.count()= " + QString().setNum(data.patients.count());
  126. if(data.patients.count()>0)
  127. {
  128. s=s+" name:"+data.patients.begin()->name+" studies.count(): "+QString().setNum(data.patients.begin()->studies.count());
  129. if(data.patients.begin()->studies.count()>0)
  130. {
  131. s=s+" series.count():" + QString().setNum(data.patients.begin()->studies.begin()->series.count());
  132. if(data.patients.begin()->studies.begin()->series.count()>0)
  133. {
  134. s=s+" uid:" + data.patients.begin()->studies.begin()->series.begin()->seriesUID;
  135. // QUuid uuid("93097dc1-caf9-43a3-a814-51a57f8d861d");//data.patients.begin()->studies.begin()->series.begin()->seriesUID);
  136. uuid = data.patients.begin()->studies.begin()->series.begin()->objectDescriptors.begin()->descriptorUUID;
  137. s=s+" uuid:"+uuid.toString();
  138. }
  139. }
  140. }
  141. this->Button->setText(s);
  142. return false;
  143. }
  144. //----------------------------------------------------------------------------
  145. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  146. QList<QUuid> objectUUIDs,
  147. QList<QString> acceptableTransferSyntaxUIDs,
  148. bool includeBulkData)
  149. {
  150. Q_UNUSED(objectUUIDs)
  151. Q_UNUSED(acceptableTransferSyntaxUIDs)
  152. Q_UNUSED(includeBulkData)
  153. return QList<ctkDicomAppHosting::ObjectLocator>();
  154. }
  155. //----------------------------------------------------------------------------
  156. void ctkExampleDicomAppLogic::releaseData(QList<QUuid> objectUUIDs)
  157. {
  158. Q_UNUSED(objectUUIDs)
  159. }
  160. void ctkExampleDicomAppLogic::buttonClicked()
  161. {
  162. QList<QUuid> uuidlist;
  163. uuidlist.append(uuid);
  164. QString transfersyntax("1.2.840.10008.1.2.1");
  165. QList<QString> transfersyntaxlist;
  166. transfersyntaxlist.append(transfersyntax);
  167. QList<ctkDicomAppHosting::ObjectLocator> locators;
  168. locators = getHostInterface()->getData(uuidlist, transfersyntaxlist, false);
  169. qDebug() << "got locators! " << QString().setNum(locators.count());
  170. QString s;
  171. s=s+" loc.count:"+QString().setNum(locators.count());
  172. if(locators.count()>0)
  173. {
  174. s=s+" URI: "+locators.begin()->URI;
  175. qDebug() << "URI: " << locators.begin()->URI;
  176. QString filename = locators.begin()->URI;
  177. if(filename.startsWith("file:/",Qt::CaseInsensitive))
  178. filename=filename.remove(0,6);
  179. qDebug()<<filename;
  180. DicomImage dcmtkImage(filename.toLatin1().data());
  181. ctkDICOMImage ctkImage(&dcmtkImage);
  182. QLabel* qtImage = new QLabel;
  183. qtImage->setPixmap(ctkImage.getPixmap(0));
  184. qtImage->show();
  185. }
  186. this->Button->setText(s);
  187. }