ctkExampleDicomAppLogic.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. setInternalState(ctkDicomAppHosting::INPROGRESS);
  80. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  81. do_something();
  82. }
  83. //----------------------------------------------------------------------------
  84. void ctkExampleDicomAppLogic::onResumeProgress()
  85. {
  86. //reclame all resources.
  87. //notify state changed
  88. setInternalState(ctkDicomAppHosting::INPROGRESS);
  89. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  90. //we're rolling
  91. //do something else normally, but this is an example
  92. this->Button->setEnabled(true);
  93. }
  94. //----------------------------------------------------------------------------
  95. void ctkExampleDicomAppLogic::onSuspendProgress()
  96. {
  97. //release resources it can reclame later to resume work
  98. this->Button->setEnabled(false);
  99. //notify state changed
  100. setInternalState(ctkDicomAppHosting::SUSPENDED);
  101. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::SUSPENDED);
  102. //we're rolling
  103. //do something else normally, but this is an example
  104. }
  105. //----------------------------------------------------------------------------
  106. void ctkExampleDicomAppLogic::onCancelProgress()
  107. {
  108. //release all resources
  109. onReleaseResources();
  110. //update state
  111. setInternalState(ctkDicomAppHosting::IDLE);
  112. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  113. }
  114. //----------------------------------------------------------------------------
  115. void ctkExampleDicomAppLogic::onExitHostedApp()
  116. {
  117. //useless move, but correct:
  118. setInternalState(ctkDicomAppHosting::EXIT);
  119. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::EXIT);
  120. //die
  121. qApp->exit(0);
  122. }
  123. //----------------------------------------------------------------------------
  124. void ctkExampleDicomAppLogic::onReleaseResources()
  125. {
  126. this->Button->hide();
  127. delete (this->Button);
  128. this->Button = 0 ;
  129. }
  130. //----------------------------------------------------------------------------
  131. bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
  132. {
  133. Q_UNUSED(lastData)
  134. QString s;
  135. if(this->Button == 0)
  136. {
  137. qCritical() << "Button is null!";
  138. return false;
  139. }
  140. s = "Received notifyDataAvailable with patients.count()= " + QString().setNum(data.patients.count());
  141. if(data.patients.count()>0)
  142. {
  143. s=s+" name:"+data.patients.begin()->name+" studies.count(): "+QString().setNum(data.patients.begin()->studies.count());
  144. if(data.patients.begin()->studies.count()>0)
  145. {
  146. s=s+" series.count():" + QString().setNum(data.patients.begin()->studies.begin()->series.count());
  147. if(data.patients.begin()->studies.begin()->series.count()>0)
  148. {
  149. s=s+" uid:" + data.patients.begin()->studies.begin()->series.begin()->seriesUID;
  150. // QUuid uuid("93097dc1-caf9-43a3-a814-51a57f8d861d");//data.patients.begin()->studies.begin()->series.begin()->seriesUID);
  151. uuid = data.patients.begin()->studies.begin()->series.begin()->objectDescriptors.begin()->descriptorUUID;
  152. s=s+" uuid:"+uuid.toString();
  153. }
  154. }
  155. }
  156. this->Button->setText(s);
  157. return false;
  158. }
  159. //----------------------------------------------------------------------------
  160. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  161. const QList<QUuid>& objectUUIDs,
  162. const QList<QString>& acceptableTransferSyntaxUIDs,
  163. bool includeBulkData)
  164. {
  165. Q_UNUSED(objectUUIDs)
  166. Q_UNUSED(acceptableTransferSyntaxUIDs)
  167. Q_UNUSED(includeBulkData)
  168. return QList<ctkDicomAppHosting::ObjectLocator>();
  169. }
  170. //----------------------------------------------------------------------------
  171. void ctkExampleDicomAppLogic::releaseData(const QList<QUuid>& objectUUIDs)
  172. {
  173. Q_UNUSED(objectUUIDs)
  174. }
  175. void ctkExampleDicomAppLogic::buttonClicked()
  176. {
  177. QList<QUuid> uuidlist;
  178. uuidlist.append(uuid);
  179. QString transfersyntax("1.2.840.10008.1.2.1");
  180. QList<QString> transfersyntaxlist;
  181. transfersyntaxlist.append(transfersyntax);
  182. QList<ctkDicomAppHosting::ObjectLocator> locators;
  183. locators = getHostInterface()->getData(uuidlist, transfersyntaxlist, false);
  184. qDebug() << "got locators! " << QString().setNum(locators.count());
  185. QString s;
  186. s=s+" loc.count:"+QString().setNum(locators.count());
  187. if(locators.count()>0)
  188. {
  189. s=s+" URI: "+locators.begin()->URI;
  190. qDebug() << "URI: " << locators.begin()->URI;
  191. QString filename = locators.begin()->URI;
  192. if(filename.startsWith("file:/",Qt::CaseInsensitive))
  193. filename=filename.remove(0,6);
  194. qDebug()<<filename;
  195. DicomImage dcmtkImage(filename.toLatin1().data());
  196. ctkDICOMImage ctkImage(&dcmtkImage);
  197. QLabel* qtImage = new QLabel;
  198. qtImage->setPixmap(ctkImage.getPixmap(0));
  199. qtImage->show();
  200. }
  201. this->Button->setText(s);
  202. }