ctkExampleDicomAppLogic.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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(stateChanged(int)), this, SLOT(changeState(int)), Qt::QueuedConnection);
  33. emit stateChanged(ctkDicomAppHosting::IDLE);
  34. }
  35. //----------------------------------------------------------------------------
  36. ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
  37. {
  38. ctkPluginContext* context = ctkExampleDicomAppPlugin::getPluginContext();
  39. QList <QSharedPointer<ctkPlugin> > plugins = context->getPlugins();
  40. for (int i = 0; i < plugins.size(); ++i)
  41. {
  42. qDebug() << plugins.at(i)->getSymbolicName ();
  43. }
  44. }
  45. //----------------------------------------------------------------------------
  46. ctkDicomAppHosting::State ctkExampleDicomAppLogic::getState()
  47. {
  48. return ctkDicomAppHosting::IDLE;
  49. }
  50. //----------------------------------------------------------------------------
  51. bool ctkExampleDicomAppLogic::setState(ctkDicomAppHosting::State newState)
  52. {
  53. qDebug() << "setState called";
  54. emit stateChanged(newState);
  55. return true;
  56. }
  57. //----------------------------------------------------------------------------
  58. bool ctkExampleDicomAppLogic::bringToFront(const QRect& /*requestedScreenArea*/)
  59. {
  60. return false;
  61. }
  62. //----------------------------------------------------------------------------
  63. void ctkExampleDicomAppLogic::do_something()
  64. {
  65. this->Button = new QPushButton("Button from App");
  66. connect(this->Button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
  67. try
  68. {
  69. QRect preferred(50,50,100,100);
  70. qDebug() << " Asking:getAvailableScreen";
  71. QRect rect = getHostInterface()->getAvailableScreen(preferred);
  72. qDebug() << " got sth:" << rect.top();
  73. this->Button->move(rect.topLeft());
  74. this->Button->resize(rect.size());
  75. }
  76. catch (const std::runtime_error& e)
  77. {
  78. qCritical() << e.what();
  79. return;
  80. }
  81. this->Button->show();
  82. }
  83. //----------------------------------------------------------------------------
  84. void ctkExampleDicomAppLogic::changeState(int anewstate)
  85. {
  86. ctkDicomAppHosting::State newstate = static_cast<ctkDicomAppHosting::State>(anewstate);
  87. if (newstate == ctkDicomAppHosting::INPROGRESS)
  88. {
  89. do_something();
  90. }
  91. try
  92. {
  93. getHostInterface()->notifyStateChanged(newstate);
  94. }
  95. catch (const std::runtime_error& e)
  96. {
  97. qCritical() << e.what();
  98. return;
  99. }
  100. if (newstate == ctkDicomAppHosting::CANCELED)
  101. {
  102. qDebug() << " Received changeState(CANCELED) ... now releasing all resources and afterwards changing to state IDLE.";
  103. qDebug() << " Changing to state IDLE.";
  104. try
  105. {
  106. getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  107. }
  108. catch (const std::runtime_error& e)
  109. {
  110. qCritical() << e.what();
  111. return;
  112. }
  113. }
  114. if (newstate == ctkDicomAppHosting::EXIT)
  115. {
  116. qDebug() << " Received changeState(EXIT) ... exiting.";
  117. this->getHostInterface()->notifyStateChanged(ctkDicomAppHosting::EXIT);
  118. qApp->exit(0);
  119. }
  120. }
  121. //----------------------------------------------------------------------------
  122. bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
  123. {
  124. Q_UNUSED(lastData)
  125. QString s;
  126. if(this->Button == 0)
  127. {
  128. qCritical() << "Button is null!";
  129. return false;
  130. }
  131. s = "Received notifyDataAvailable with patients.count()= " + QString().setNum(data.patients.count());
  132. if(data.patients.count()>0)
  133. {
  134. s=s+" name:"+data.patients.begin()->name+" studies.count(): "+QString().setNum(data.patients.begin()->studies.count());
  135. if(data.patients.begin()->studies.count()>0)
  136. {
  137. s=s+" series.count():" + QString().setNum(data.patients.begin()->studies.begin()->series.count());
  138. if(data.patients.begin()->studies.begin()->series.count()>0)
  139. {
  140. s=s+" uid:" + data.patients.begin()->studies.begin()->series.begin()->seriesUID;
  141. // QUuid uuid("93097dc1-caf9-43a3-a814-51a57f8d861d");//data.patients.begin()->studies.begin()->series.begin()->seriesUID);
  142. uuid = data.patients.begin()->studies.begin()->series.begin()->objectDescriptors.begin()->descriptorUUID;
  143. s=s+" uuid:"+uuid.toString();
  144. }
  145. }
  146. }
  147. this->Button->setText(s);
  148. return false;
  149. }
  150. //----------------------------------------------------------------------------
  151. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  152. const QList<QUuid>& objectUUIDs,
  153. const QList<QString>& acceptableTransferSyntaxUIDs,
  154. bool includeBulkData)
  155. {
  156. Q_UNUSED(objectUUIDs)
  157. Q_UNUSED(acceptableTransferSyntaxUIDs)
  158. Q_UNUSED(includeBulkData)
  159. return QList<ctkDicomAppHosting::ObjectLocator>();
  160. }
  161. //----------------------------------------------------------------------------
  162. void ctkExampleDicomAppLogic::releaseData(const QList<QUuid>& objectUUIDs)
  163. {
  164. Q_UNUSED(objectUUIDs)
  165. }
  166. void ctkExampleDicomAppLogic::buttonClicked()
  167. {
  168. QList<QUuid> uuidlist;
  169. uuidlist.append(uuid);
  170. QString transfersyntax("1.2.840.10008.1.2.1");
  171. QList<QString> transfersyntaxlist;
  172. transfersyntaxlist.append(transfersyntax);
  173. QList<ctkDicomAppHosting::ObjectLocator> locators;
  174. locators = getHostInterface()->getData(uuidlist, transfersyntaxlist, false);
  175. qDebug() << "got locators! " << QString().setNum(locators.count());
  176. QString s;
  177. s=s+" loc.count:"+QString().setNum(locators.count());
  178. if(locators.count()>0)
  179. {
  180. s=s+" URI: "+locators.begin()->URI;
  181. qDebug() << "URI: " << locators.begin()->URI;
  182. QString filename = locators.begin()->URI;
  183. if(filename.startsWith("file:/",Qt::CaseInsensitive))
  184. filename=filename.remove(0,6);
  185. qDebug()<<filename;
  186. DicomImage dcmtkImage(filename.toLatin1().data());
  187. ctkDICOMImage ctkImage(&dcmtkImage);
  188. QLabel* qtImage = new QLabel;
  189. qtImage->setPixmap(ctkImage.getPixmap(0));
  190. qtImage->show();
  191. }
  192. this->Button->setText(s);
  193. }