コード例 #1
0
void ctkEAScenario2EventConsumer::handleEvent(const ctkEvent& event)
{
  QMutexLocker l(&mutex);
  try
  {
    /* get the topic from the event*/
//    QString eventTopic = event.getTopic();
    //TODO security topic permission
//    /* make a topic permission from the received topic in order to check it*/
//    TopicPermission permissionAccuired = new TopicPermission(eventTopic, "SUBSCRIBE");
//    /* make a topic permission from the topic to consume in order to check it*/
//    TopicPermission actualPermission = new TopicPermission(topicsToConsume[0], "SUBSCRIBE");
//    /* assert if the topic in the event is the same as the topic to listen fore including wildcard */
//    assertTrue("The topics was not equal", actualPermission.implies(permissionAccuired));

    /* try to get the message */
    QString message = event.getProperty("Synchronous message").toString();

    if(!message.isNull())
    {
      /* its a syncronous message */
      qDebug() << "received a synchronous event with message:" << message;
      /* assert that the messages of syncronous type are not too many */
      QVERIFY2(synchMessages < numSyncMessages, "too many synchronous messages");
      synchMessages++;
      qDebug() << "Max number of Sync messages is:" << numSyncMessages << "and number of received Sync messages is: " << synchMessages;
    }
    else
    {
      message = event.getProperty("Asynchronous message").toString();
      if(!message.isNull())
      {
        qDebug() << "received an asynchronous event with message:" << message;
        /* assert that the messsage of the asyncronous type are not too many */
        QVERIFY2(asynchMessages < numAsyncMessages, "too many asynchronous messages");
        asynchMessages++;
        qDebug() << "Max number of Async messages is:" << numAsyncMessages << "and number of received Async messages is:" << asynchMessages;
      }
    }
  }
  catch (const ctkRuntimeException& e)
  {
    error = true;
    exc = e;
    throw e;
  }
  catch (...)
  {
    error = true;
  }
}
コード例 #2
0
//----------------------------------------------------------------------------
void ctkEAScenario3EventConsumer::handleEvent(const ctkEvent& event)
{
  QMutexLocker l(&mutex);
  try
  {
    /* try to get the message */
    QString message = event.getProperty("Synchronous message").toString();

    if (!message.isNull())
    {
      /* its an asyncronous message */
      synchMessages++;
      qDebug() << "recived a Synchronous event with message:" << message;
    }
    else
    {
      message = event.getProperty("Asynchronous message").toString();
      if (!message.isNull())
      {
        asynchMessages++;
        qDebug() << "recived an Asynchronus event with message:" << message;
      }
    }

    /* assert that the messages property is not null */
    QVERIFY2(!message.isNull(), "Message should not be null in handleEvent()");

    /* assert that the messages of syncronous type are not too many */
    QVERIFY2(synchMessages < numSyncMessages + 1, "too many synchronous messages");
    /* assert that the messsage of the asyncronous type are not too many */
    QVERIFY2(asynchMessages < numAsyncMessages + 1, "too many asynchronous messages");
  }
  catch (const ctkRuntimeException& e)
  {
    error = true;
    exc = e;
    throw e;
  }
  catch (...)
  {
    error = true;
  }
}
コード例 #3
0
ファイル: DicomEventHandler.cpp プロジェクト: beneon/MITK
void DicomEventHandler::OnSignalAddSeriesToDataManager(const ctkEvent& ctkEvent)
{
    QStringList listOfFilesForSeries;
    mitk::DicomSeriesReader::StringContainer seriesToLoad;

    listOfFilesForSeries = ctkEvent.getProperty("FilesForSeries").toStringList();

    if (!listOfFilesForSeries.isEmpty()){

        QStringListIterator it(listOfFilesForSeries);

        while (it.hasNext())
        {
            seriesToLoad.push_back(it.next().toStdString());
        }


        mitk::DataNode::Pointer node = mitk::DicomSeriesReader::LoadDicomSeries(seriesToLoad);
        if (node.IsNull())
        {
            MITK_ERROR << "Error loading series: " << ctkEvent.getProperty("SeriesName").toString().toStdString()
                << " id: " <<ctkEvent.getProperty("SeriesUID").toString().toStdString();
        }
        else
        {
            //Get Reference for default data storage.
            ctkServiceReference serviceReference =mitk::PluginActivator::getContext()->getServiceReference<mitk::IDataStorageService>();
            mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService<mitk::IDataStorageService>(serviceReference);
            mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage();

            dataStorage->Add(node);

            // Initialize the RenderWindow
            mitk::TimeSlicedGeometry::Pointer geometry = dataStorage->ComputeBoundingGeometry3D(dataStorage->GetAll());
            mitk::RenderingManager::GetInstance()->InitializeViews(geometry);
        }
    }
    else
    {
        MITK_INFO << "There are no files for the current series";
    }
}
コード例 #4
0
ファイル: ctkEventBusImpl.cpp プロジェクト: trabs/CTK
void ctkEventBusImpl::dispatchEvent(const ctkEvent& event, bool isAsync)
{
  QString topic = event.topic();

  QSet<ctkEventHandlerWrapper*> eventHandlers = this->handlers(topic);
  if (eventHandlers.empty()) return;

  QSetIterator<ctkEventHandlerWrapper*> iter(eventHandlers);
  while (iter.hasNext())
  {
    iter.next()->handleEvent(event);
  }
}
コード例 #5
0
void DicomEventHandler::OnSignalAddSeriesToDataManager(const ctkEvent& ctkEvent)
{
  QStringList listOfFilesForSeries;
  listOfFilesForSeries = ctkEvent.getProperty("FilesForSeries").toStringList();

  if (!listOfFilesForSeries.isEmpty())
  {
    //for rt data, if the modality tag isn't defined or is "CT" the image is handled like before
    if(ctkEvent.containsProperty("Modality") &&
       (ctkEvent.getProperty("Modality").toString().compare("RTDOSE",Qt::CaseInsensitive) == 0 ||
        ctkEvent.getProperty("Modality").toString().compare("RTSTRUCT",Qt::CaseInsensitive) == 0 ||
        ctkEvent.getProperty("Modality").toString().compare("RTPLAN", Qt::CaseInsensitive) == 0))
    {
      QString modality = ctkEvent.getProperty("Modality").toString();

      if(modality.compare("RTDOSE",Qt::CaseInsensitive) == 0)
      {
          auto doseReader = mitk::RTDoseReaderService();
          doseReader.SetInput(listOfFilesForSeries.front().toStdString());
          std::vector<itk::SmartPointer<mitk::BaseData> > readerOutput = doseReader.Read();
          if (!readerOutput.empty()){
            mitk::Image::Pointer doseImage = dynamic_cast<mitk::Image*>(readerOutput.at(0).GetPointer());

            mitk::DataNode::Pointer doseImageNode = mitk::DataNode::New();
            doseImageNode->SetData(doseImage);
            doseImageNode->SetName("RTDose");

            if (doseImage != nullptr)
            {
                auto sopUIDProperty = doseImage->GetProperty("dicomseriesreader.SOPClassUID");
                if (sopUIDProperty.IsNotNull()){
                    auto sopUIDStringProperty = dynamic_cast<mitk::StringProperty*>(sopUIDProperty.GetPointer());
                    if (sopUIDStringProperty != nullptr){
                        std::string sopUID = sopUIDStringProperty->GetValue();
                        doseImageNode->SetName(sopUID);
                    }
                }

                berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService();
                berry::IPreferences::Pointer prefNode = prefService->GetSystemPreferences()->Node(mitk::RTUIConstants::ROOT_DOSE_VIS_PREFERENCE_NODE_ID.c_str());

                if (prefNode.IsNull())
                {
                    mitkThrow() << "Error in preference interface. Cannot find preset node under given name. Name: " << prefNode->ToString().toStdString();
                }

                //set some specific colorwash and isoline properties
                bool showColorWashGlobal = prefNode->GetBool(mitk::RTUIConstants::GLOBAL_VISIBILITY_COLORWASH_ID.c_str(), true);
                bool showIsolinesGlobal = prefNode->GetBool(mitk::RTUIConstants::GLOBAL_VISIBILITY_ISOLINES_ID.c_str(), true);

                //Set reference dose property
                double referenceDose = prefNode->GetDouble(mitk::RTUIConstants::REFERENCE_DOSE_ID.c_str(), mitk::RTUIConstants::DEFAULT_REFERENCE_DOSE_VALUE);

                mitk::ConfigureNodeAsDoseNode(doseImageNode, mitk::GeneratIsoLevels_Virtuos(), referenceDose, showColorWashGlobal);

                ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference<mitk::IDataStorageService>();
                mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService<mitk::IDataStorageService>(serviceReference);
                mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage();

                dataStorage->Add(doseImageNode);

                mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(dataStorage);
            }
        }//END DOSE
      }
      else if(modality.compare("RTSTRUCT",Qt::CaseInsensitive) == 0)
      {
          auto structReader = mitk::RTStructureSetReaderService();
          structReader.SetInput(listOfFilesForSeries.front().toStdString());
          std::vector<itk::SmartPointer<mitk::BaseData> > readerOutput = structReader.Read();

          if (readerOutput.empty()){
              MITK_ERROR << "No structure sets were created" << endl;
          }
          else {
              std::vector<mitk::DataNode::Pointer> modelVector;

              ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference<mitk::IDataStorageService>();
              mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService<mitk::IDataStorageService>(serviceReference);
              mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage();

              for (const auto& aStruct : readerOutput){
                  mitk::ContourModelSet::Pointer countourModelSet = dynamic_cast<mitk::ContourModelSet*>(aStruct.GetPointer());

                  mitk::DataNode::Pointer structNode = mitk::DataNode::New();
                  structNode->SetData(countourModelSet);
                  structNode->SetProperty("name", aStruct->GetProperty("name"));
                  structNode->SetProperty("color", aStruct->GetProperty("contour.color"));
                  structNode->SetProperty("contour.color", aStruct->GetProperty("contour.color"));
                  structNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false));
                  structNode->SetVisibility(true, mitk::BaseRenderer::GetInstance(
                      mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget1")));
                  structNode->SetVisibility(false, mitk::BaseRenderer::GetInstance(
                      mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget2")));
                  structNode->SetVisibility(false, mitk::BaseRenderer::GetInstance(
                      mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget3")));
                  structNode->SetVisibility(true, mitk::BaseRenderer::GetInstance(
                      mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4")));

                  dataStorage->Add(structNode);
              }
              mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(dataStorage);
          }
      }
      else if (modality.compare("RTPLAN", Qt::CaseInsensitive) == 0)
      {
          auto planReader = mitk::RTPlanReaderService();
          planReader.SetInput(listOfFilesForSeries.front().toStdString());
          std::vector<itk::SmartPointer<mitk::BaseData> > readerOutput = planReader.Read();
          if (!readerOutput.empty()){
              //there is no image, only the properties are interesting
              mitk::Image::Pointer planDummyImage = dynamic_cast<mitk::Image*>(readerOutput.at(0).GetPointer());

              mitk::DataNode::Pointer planImageNode = mitk::DataNode::New();
              planImageNode->SetData(planDummyImage);
              planImageNode->SetName("RTPlan");

              ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference<mitk::IDataStorageService>();
              mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService<mitk::IDataStorageService>(serviceReference);
              mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage();

              dataStorage->Add(planImageNode);
          }
      }
    }
    else
    {
      mitk::StringList seriesToLoad;
      QStringListIterator it(listOfFilesForSeries);

      while (it.hasNext())
      {
        seriesToLoad.push_back(it.next().toStdString());
      }

      //Get Reference for default data storage.
      ctkServiceReference serviceReference = mitk::PluginActivator::getContext()->getServiceReference<mitk::IDataStorageService>();
      mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService<mitk::IDataStorageService>(serviceReference);
      mitk::DataStorage* dataStorage = storageService->GetDefaultDataStorage().GetPointer()->GetDataStorage();

      std::vector<mitk::BaseData::Pointer> baseDatas = mitk::IOUtil::Load(seriesToLoad.front());
      for (const auto &data : baseDatas)
      {
        mitk::DataNode::Pointer node = mitk::DataNode::New();
        node->SetData(data);

        std::string nodeName = "Unnamed Dicom";

        std::string studyUID = "";
        std::string seriesUID = "";

        data->GetPropertyList()->GetStringProperty("DICOM.0020.000D", studyUID);
        data->GetPropertyList()->GetStringProperty("DICOM.0020.000E", seriesUID);

        if (!studyUID.empty())
        {
          nodeName = studyUID;
        }

        if (!seriesUID.empty())
        {
          if (!studyUID.empty())
          {
            nodeName += "/";
          }
          nodeName += seriesUID;
        }

        dataStorage->Add(node);
      }
    }
  }
  else
  {
    MITK_INFO << "There are no files for the current series";
  }
}