void Plugin::start() { ::fwMemory::BufferManager::sptr manager = ::fwMemory::BufferManager::getDefault(); const std::string modeKey = "loading_mode"; if ( this->getBundle()->hasParameter(modeKey) ) { ::fwCore::mt::WriteLock lock( manager->getMutex() ); std::string mode = this->getBundle()->getParameterValue(modeKey); if (mode == "lazy") { manager->setLoadingMode(::fwMemory::BufferManager::LAZY); SLM_INFO("Enabled lazy loading mode"); } else if (mode == "direct") { manager->setLoadingMode(::fwMemory::BufferManager::DIRECT); SLM_INFO("Enabled direct loading mode"); } else { SLM_ERROR("Unknown loading mode : '" + mode + "'"); } } }
/** * Dumps the backtrace on a stream */ void printDump(std::list<std::string> &loadedModules, std::list<std::string> &callStack, std::list<std::string> &fileStack) { std::stringstream stream; // Dumps the loaded modules on the stream stream << "-----------------------------------------" << std::endl; stream << "\nLoaded Modules\n"; for(std::list<std::string>::const_iterator it = loadedModules.begin(); it != loadedModules.end(); ++it) { stream << "> " << *it << std::endl; } stream << "-----------------------------------------" << std::endl; // Dumps the call stack on the stream stream << "\nCallStack\n"; for(std::list<std::string>::const_iterator it = callStack.begin(), it2 = fileStack.begin(); it != callStack.end() && it2 != fileStack.end(); ++it, ++it2) { stream << "> " << *it << std::endl; stream << " " << *it2 << std::endl; } stream << "-----------------------------------------" << std::endl; SLM_ERROR(stream.str() ); }
void SSliceIndexDicomPullerEditor::triggerNewSlice() { // DicomSeries ::fwMedData::DicomSeries::csptr dicomSeries = this->getInOut< ::fwMedData::DicomSeries >("series"); SLM_ASSERT("DicomSeries should not be null !", dicomSeries); // Compute slice index std::size_t selectedSliceIndex = m_sliceIndexSlider->value() + dicomSeries->getFirstInstanceNumber(); OSLM_TRACE("triggered new slice : " << selectedSliceIndex); if(!dicomSeries->isInstanceAvailable(selectedSliceIndex)) { if(m_pacsConfiguration) { m_pullSeriesWorker->post(std::bind(&::ioPacs::SSliceIndexDicomPullerEditor::pullInstance, this)); } else { SLM_ERROR("There is no instance available for selected slice index."); } } else { //m_slotReadImage->asyncRun(selectedSliceIndex); this->readImage(selectedSliceIndex); } }
void bt_sighandler(int sig, siginfo_t *info, void *secret) { void *trace[16]; char **messages = (char **)NULL; int i, trace_size = 0; ucontext_t *uc = (ucontext_t *)secret; std::stringstream ss; ss << "Got signal " << sig; /* Do something useful with siginfo_t */ if (sig == SIGSEGV) { ss << " faulty address is " << info->si_addr; #ifndef __MACOSX__ ss << " from " << uc->uc_mcontext.gregs[REG_EIP]; #endif } ss << std::endl; trace_size = backtrace(trace, 16); /* overwrite sigaction with caller's address */ #ifndef __MACOSX__ trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP]; #endif messages = backtrace_symbols(trace, trace_size); /* skip first stack frame (points here) */ ss << " [bt] Execution path:" << std::endl; for (i = 1; i<trace_size; ++i) { ss << " [bt] " << decode(messages[i]) << std::endl; } if (sig == SIGSEGV) { SLM_FATAL("SIGSEV signal " + ss.str() ); exit(0); } else { SLM_ERROR("SIGUSR1 signal " + ss.str() ); } }
SeriesDBLazyReader::MapSeriesType buildMapSeriesFromScanner( ::gdcm::Scanner & scanner ) { ::gdcm::Directory::FilenamesType keys = scanner.GetKeys(); ::gdcm::Directory::FilenamesType::const_iterator it = keys.begin(); SeriesDBLazyReader::MapSeriesType mapSeries; for(; it != keys.end() ; ++it) { const char *filename = it->c_str(); assert( scanner.IsKey( filename ) ); const char *seriesUID = scanner.GetValue( filename, seriesUIDTag ); const char *acqDate = scanner.GetValue( filename, acquisitionDateTag ); if (seriesUID) { std::string fileSetId = seriesUID; if (acqDate) { fileSetId += "_"; fileSetId += acqDate; } const char *imageTypeStr = scanner.GetValue(filename, imageTypeTag); if(imageTypeStr) { // Treatment of secondary capture dicom file. std::string imageType(imageTypeStr); SLM_TRACE("Image Type : " + imageType); fileSetId += "_"; fileSetId += imageTypeStr; } mapSeries[fileSetId].push_back(filename); } else { SLM_ERROR ( "Error in vtkGdcmIO : No serie name found in : " + *it ); } } return mapSeries; }
void SServerSender::starting() { try { const std::uint16_t port = ::ioIGTL::helper::getPreferenceKey<std::uint16_t>(m_portConfig); m_server->start(port); m_serverFuture = std::async(std::launch::async, std::bind(&::igtlNetwork::Server::runServer, m_server) ); m_sigConnected->asyncEmit(); } catch (::fwCore::Exception& e) { ::fwGui::dialog::MessageDialog::showMessageDialog("Error", "Cannot start the server: " + std::string(e.what()), ::fwGui::dialog::IMessageDialog::CRITICAL); // Only report the error on console (this normally happens only if we have requested the disconnection) SLM_ERROR(e.what()); this->slot(s_STOP_SLOT)->asyncRun(); } }
void SCameraConfigLauncher::onImportClicked() { auto sdb = ::fwMedData::SeriesDB::New(); ::fwServices::IService::sptr readerService = ::fwServices::add("::ioAtoms::SReader"); readerService->registerInOut(sdb, ::fwIO::s_DATA_KEY); try { ::fwIO::IReader::sptr reader = ::fwIO::IReader::dynamicCast(readerService); reader->start(); reader->configureWithIHM(); reader->update(); reader->stop(); } catch(std::exception const& e) { ::fwGui::dialog::MessageDialog dlg; const auto msg = "Cannot read file: " + std::string(e.what()); dlg.setTitle("Read error"); dlg.setMessage(msg); dlg.setIcon(::fwGui::dialog::IMessageDialog::Icons::CRITICAL); SLM_ERROR(msg); throw; } ::fwServices::OSR::unregisterService(readerService); auto series = sdb->getContainer(); auto cameraSeries = std::vector< ::arData::CameraSeries::sptr>(); for (auto& series_ : series) { auto cameraSeries_ = ::arData::CameraSeries::dynamicCast(series_); if (cameraSeries_ != nullptr) { cameraSeries.push_back(cameraSeries_); } } if (cameraSeries.size() == 0) { ::fwGui::dialog::MessageDialog::showMessageDialog( "No CameraSeries in SDB", "There are no CameraSeries present in the loaded SeriesDB", ::fwGui::dialog::IMessageDialog::CRITICAL); } else { QStringList cameras; std::map< std::string, ::arData::Camera::sptr> map; for (auto nSeries = 0; nSeries != cameraSeries.size(); ++nSeries) { auto cameraSeries_ = cameraSeries[nSeries]; for (auto nCam = 0; nCam != cameraSeries_->getNumberOfCameras(); ++nCam) { auto cam = cameraSeries_->getCamera(nCam); auto cameraID = cam->getCameraID() + " [" + std::to_string(nSeries) + ", " + std::to_string(nCam) + "]"; map.insert(std::make_pair(cameraID, cam)); cameras << QString(cameraID.data()); } } if (cameras.size() == 0) { ::fwGui::dialog::MessageDialog::showMessageDialog( "No Cameras in SDB", "There are CameraSeries present in the loaded SeriesDB, but no Cameras were found", ::fwGui::dialog::IMessageDialog::CRITICAL); } else { auto qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(this->getContainer()); bool ok = false; auto selected = QInputDialog::getItem( qtContainer->getQtContainer(), "Please select a camera", "Camera", cameras, 0, false, &ok); if (ok) { const auto selectedStd = selected.toStdString(); const auto selectedCamera = map[selectedStd]; const auto camIdx = m_cameraComboBox->currentIndex(); auto camera = m_cameraSeries->getCamera(camIdx); camera->deepCopy(selectedCamera); camera->signal< ::arData::Camera::IntrinsicCalibratedSignalType>( ::arData::Camera::s_INTRINSIC_CALIBRATED_SIG) ->asyncEmit(); } } } }
void SSliceIndexDicomPullerEditor::pullInstance() { SLM_ASSERT("Pacs not configured.", m_pacsConfiguration); if( m_pacsConfiguration ) { // Catch any errors try { // DicomSeries ::fwMedData::DicomSeries::sptr dicomSeries = this->getInOut< ::fwMedData::DicomSeries >("series"); SLM_ASSERT("DicomSeries should not be null !", dicomSeries); // Get selected slice std::size_t selectedSliceIndex = m_sliceIndexSlider->value() + dicomSeries->getFirstInstanceNumber(); m_seriesEnquirer->initialize(m_pacsConfiguration->getLocalApplicationTitle(), m_pacsConfiguration->getPacsHostName(), m_pacsConfiguration->getPacsApplicationPort(), m_pacsConfiguration->getPacsApplicationTitle(), m_pacsConfiguration->getMoveApplicationTitle()); m_seriesEnquirer->connect(); std::string seriesInstanceUID = dicomSeries->getInstanceUID(); std::string sopInstanceUID = m_seriesEnquirer->findSOPInstanceUID(seriesInstanceUID, static_cast<unsigned int>(selectedSliceIndex)); // Check if an instance with the selected Instance Number is found on the PACS if(!sopInstanceUID.empty()) { // Pull Selected Series using C-GET Requests m_seriesEnquirer->pullInstanceUsingGetRetrieveMethod(seriesInstanceUID, sopInstanceUID); // Add path and trigger reading ::boost::filesystem::path path = ::fwTools::System::getTemporaryFolder() / "dicom/"; ::boost::filesystem::path filePath = path.string() + seriesInstanceUID + "/" + sopInstanceUID; dicomSeries->addDicomPath(selectedSliceIndex, filePath); //m_slotReadImage->asyncRun(selectedSliceIndex); this->readImage(selectedSliceIndex); } else { std::stringstream ss; ss << "The selected series does not have an instance matching the selected instance number (" << selectedSliceIndex << ")."; m_slotDisplayMessage->asyncRun(ss.str()); } // Close connection m_seriesEnquirer->disconnect(); } catch (::fwPacsIO::exceptions::Base& exception) { std::stringstream ss; ss << "Unable to connect to the pacs. Please check your configuration: \n" << "Pacs host name: " << m_pacsConfiguration->getPacsHostName() << "\n" << "Pacs application title: " << m_pacsConfiguration->getPacsApplicationTitle() << "\n" << "Pacs port: " << m_pacsConfiguration->getPacsApplicationPort() << "\n"; m_slotDisplayMessage->asyncRun(ss.str()); SLM_WARN(exception.what()); } } else { SLM_ERROR("Pacs pull aborted : no pacs configuration found."); } }
void Logger::critical(const std::string& message) { ::fwLog::Log log(::fwLog::Log::CRITICAL, message); m_logContainer.push_back(log); SLM_ERROR(message); }
void SeriesDBReader::addSeries( const ::fwMedData::SeriesDB::sptr& seriesDB, const std::vector< std::string >& filenames) { //gdcm::Trace::SetDebug( 1 ); //gdcm::Trace::SetWarning( 1 ); //gdcm::Trace::SetError( 1 ); ::gdcm::Scanner scanner; const ::gdcm::Tag seriesUIDTag(0x0020, 0x000e); const ::gdcm::Tag seriesDateTag(0x0008, 0x0021); const ::gdcm::Tag seriesTimeTag(0x0008, 0x0031); const ::gdcm::Tag seriesTypeTag(0x0008, 0x0060); const ::gdcm::Tag seriesDescriptionTag(0x0008, 0x103e); const ::gdcm::Tag seriesPhysicianNamesTag(0x0008, 0x1050); const ::gdcm::Tag equipmentInstitutionNameTag(0x0008, 0x0080); const ::gdcm::Tag patientNameTag(0x0010, 0x0010); const ::gdcm::Tag patientIDTag(0x0010, 0x0020); const ::gdcm::Tag patientBirthdateTag(0x0010, 0x0030); const ::gdcm::Tag patientSexTag(0x0010, 0x0040); const ::gdcm::Tag studyUIDTag(0x0020, 0x000d); const ::gdcm::Tag studyDateTag(0x0008, 0x0020); const ::gdcm::Tag studyTimeTag(0x0008, 0x0030); const ::gdcm::Tag studyReferingPhysicianNameTag(0x0008, 0x0090); const ::gdcm::Tag studyDescriptionTag(0x0008, 0x1030); const ::gdcm::Tag studyPatientAgeTag(0x0010, 0x1010); const ::gdcm::Tag imageTypeTag(0x0008, 0x0008); const ::gdcm::Tag acquisitionDateTag(0x0008, 0x0022); const ::gdcm::Tag acquisitionTimeTag(0x0008, 0x0032); scanner.AddTag( seriesUIDTag ); scanner.AddTag( seriesDateTag ); scanner.AddTag( seriesTimeTag ); scanner.AddTag( seriesTypeTag ); scanner.AddTag( seriesDescriptionTag ); scanner.AddTag( seriesPhysicianNamesTag ); scanner.AddTag( equipmentInstitutionNameTag ); scanner.AddTag( studyUIDTag ); scanner.AddTag( patientNameTag ); scanner.AddTag( patientIDTag ); scanner.AddTag( patientBirthdateTag ); scanner.AddTag( patientSexTag ); scanner.AddTag( studyUIDTag ); scanner.AddTag( studyDateTag ); scanner.AddTag( studyTimeTag ); scanner.AddTag( studyReferingPhysicianNameTag ); scanner.AddTag( studyDescriptionTag ); scanner.AddTag( studyPatientAgeTag ); scanner.AddTag( imageTypeTag ); scanner.AddTag( acquisitionDateTag ); scanner.AddTag( acquisitionTimeTag ); try { const bool isScanned = scanner.Scan( filenames ); if( !isScanned ) { SLM_ERROR("Scanner failed"); return; } const ::gdcm::Directory::FilenamesType keys = scanner.GetKeys(); typedef std::map< std::string, std::vector< std::string > > MapSeriesType; MapSeriesType mapSeries; for(const std::string& filename : keys) { SLM_ASSERT("'"+filename+"' is not a key in the mapping table", scanner.IsKey(filename.c_str())); const char* seriesUID = scanner.GetValue( filename.c_str(), seriesUIDTag ); const char* acqDate = scanner.GetValue( filename.c_str(), acquisitionDateTag ); if (seriesUID) { std::string fileSetId = seriesUID; if (acqDate) { fileSetId += "_"; fileSetId += acqDate; } const char* imageType = scanner.GetValue(filename.c_str(), imageTypeTag); if(imageType) { // Treatment of secondary capture dicom file. SLM_TRACE("Image Type : " + std::string(imageType)); fileSetId += "_"; fileSetId += imageType; } mapSeries[fileSetId].push_back(filename); } else { SLM_ERROR("No series name found in : " + filename ); } } for(const auto& elt : mapSeries) { ::fwMedData::ImageSeries::sptr series = ::fwMedData::ImageSeries::New(); ::fwMedData::Patient::sptr patient = series->getPatient(); ::fwMedData::Study::sptr study = series->getStudy(); ::fwMedData::Equipment::sptr equipment = series->getEquipment(); seriesDB->getContainer().push_back(series); SLM_TRACE( "Processing: '" + elt.first + "' file set."); const MapSeriesType::mapped_type& files = elt.second; if ( !files.empty() ) { vtkSmartPointer< vtkStringArray > fileArray = vtkSmartPointer< vtkStringArray >::New(); vtkSmartPointer< vtkGDCMImageReader > reader = vtkSmartPointer< vtkGDCMImageReader >::New(); reader->FileLowerLeftOn(); ::gdcm::IPPSorter ippSorter; ippSorter.SetComputeZSpacing( true ); ippSorter.SetZSpacingTolerance( 1e-3 ); bool isSorted = ippSorter.Sort( files ); std::vector<std::string> sorted; double zspacing = 0.; if(isSorted) { sorted = ippSorter.GetFilenames(); zspacing = ippSorter.GetZSpacing(); OSLM_TRACE("Found z-spacing:" << ippSorter.GetZSpacing()); } else { // Else an error has been encountered. // We fall back to a more trivial sorting based on the InstanceNumber DICOM tag. SLM_WARN("IPP Sorting failed. Falling back to Instance Number sorting."); ::gdcm::Sorter sorter; sorter.SetSortFunction(sortByInstanceNumber); isSorted = sorter.StableSort( filenames); if(isSorted) { // If the custom sorted returns true, it worked // and the filenames are sorted by InstanceNumber (ASC). sorted = sorter.GetFilenames(); } else { // There is nothing more we can do to sort DICOM files. SLM_ERROR("Failed to sort '"+elt.first+"'"); } } fileArray->Initialize(); if(isSorted) { SLM_TRACE("Success to sort '" + elt.first+"'"); if (!zspacing && sorted.size() > 1) { SLM_TRACE( "Guessing zspacing ..." ); if (!sorted.empty()) { ::gdcm::Reader localReader1; ::gdcm::Reader localReader2; const std::string& f1 = *(sorted.begin()); const std::string& f2 = *(sorted.begin() + 1); SLM_TRACE( "Search spacing in: '" + f1 +"'"); SLM_TRACE( "Search spacing in: '" + f2 +"'"); localReader1.SetFileName( f1.c_str() ); localReader2.SetFileName( f2.c_str() ); const bool canRead = localReader1.Read() && localReader2.Read(); if(canRead) { const std::vector<double> vOrigin1 = ::gdcm::ImageHelper::GetOriginValue(localReader1.GetFile()); const std::vector<double> vOrigin2 = ::gdcm::ImageHelper::GetOriginValue(localReader2.GetFile()); zspacing = vOrigin2[2] - vOrigin1[2]; OSLM_TRACE( "Found z-spacing:" << zspacing << " from : << " << vOrigin2[2] << " | " << vOrigin1[2]); } SLM_ERROR_IF("Cannot read: '" + f1 + "' or: '" + f2 +"'", !canRead); } } } for(const std::string& file : sorted) { SLM_TRACE("Add '" + file + "' to vtkGdcmReader"); fileArray->InsertNextValue(file.c_str()); } ::fwData::Image::sptr pDataImage = ::fwData::Image::New(); bool res = false; if (fileArray->GetNumberOfValues() > 0) { reader->SetFileNames( fileArray ); try { SLM_TRACE("Read Series: '" + elt.first + "'"); //add progress observation vtkSmartPointer< ::fwVtkIO::helper::vtkLambdaCommand > progressCallback = vtkSmartPointer< ::fwVtkIO::helper::vtkLambdaCommand >::New(); progressCallback->SetCallback([this](vtkObject* caller, long unsigned int, void* ) { auto filter = static_cast<vtkGDCMImageReader*>(caller); m_job->doneWork( filter->GetProgress()*100 ); }); reader->AddObserver(vtkCommand::ProgressEvent, progressCallback); m_job->addSimpleCancelHook( [&]() { reader->AbortExecuteOn(); } ); reader->Update(); reader->UpdateInformation(); reader->PropagateUpdateExtent(); try { ::fwVtkIO::fromVTKImage(reader->GetOutput(), pDataImage); res = true; } catch(std::exception& e) { OSLM_ERROR("VTKImage to fwData::Image failed : "<<e.what()); } } catch (std::exception& e) { OSLM_ERROR( "Error during conversion : " << e.what() ); } catch (...) { SLM_ERROR( "Unexpected error during conversion" ); } m_job->finish(); } if (res) { SLM_ASSERT("No file to read", !files.empty()); // Read medical info vtkMedicalImageProperties* medprop = reader->GetMedicalImageProperties(); const std::string patientName = medprop->GetPatientName(); //"0010|0010" const std::string patientId = medprop->GetPatientID(); const std::string patientBirthdate = medprop->GetPatientBirthDate(); //"0010|0030" const std::string patientSex = medprop->GetPatientSex(); //"0010|0040" const ::gdcm::Scanner::ValuesType gdcmPhysicianNames = scanner.GetValues( seriesPhysicianNamesTag ); const char* seriesUIDStr = scanner.GetValue( files[0].c_str(), seriesUIDTag ); const char* seriesTimeStr = scanner.GetValue( files[0].c_str(), seriesTimeTag ); const char* seriesDateStr = scanner.GetValue( files[0].c_str(), seriesDateTag ); const std::string seriesModality = medprop->GetModality(); //"0008|0060" const std::string seriesDescription = medprop->GetSeriesDescription(); const std::string seriesDate = ( seriesDateStr ? seriesDateStr : "" ); const std::string seriesTime = ( seriesTimeStr ? seriesTimeStr : "" ); ::fwMedData::DicomValuesType seriesPhysicianNames; for(const std::string& name : gdcmPhysicianNames) { ::fwMedData::DicomValuesType result; ::boost::split( result, name, ::boost::is_any_of("\\")); seriesPhysicianNames.reserve(seriesPhysicianNames.size() + result.size()); seriesPhysicianNames.insert(seriesPhysicianNames.end(), result.begin(), result.end()); } const char* studyUIDStr = scanner.GetValue( files[0].c_str(), studyUIDTag ); const char* studyReferingPhysicianNameStr = scanner.GetValue( files[0].c_str(), studyReferingPhysicianNameTag ); const std::string studyDate = medprop->GetStudyDate(); const std::string studyTime = medprop->GetStudyTime(); const std::string studyDescription = medprop->GetStudyDescription(); //"0008|1030" const std::string studyPatientAge = medprop->GetPatientAge(); const std::string equipementInstitution = medprop->GetInstitutionName(); //"0008|0080" const std::string studyReferingPhysicianName = ( studyReferingPhysicianNameStr ? studyReferingPhysicianNameStr : "" ); const double thickness = medprop->GetSliceThicknessAsDouble();//"0018|0050" double center = 0.0; double width = 0.0; if (medprop->GetNumberOfWindowLevelPresets())//FIXME : Multiple preset !!! { medprop->GetNthWindowLevelPreset(0, &width, ¢er); //0028|1050,1051 } // Image must have 3 dimensions if(pDataImage->getNumberOfDimensions() == 2) { ::fwData::Image::SizeType imgSize = pDataImage->getSize(); imgSize.resize(3); imgSize[2] = 1; pDataImage->setSize(imgSize); ::fwData::Image::OriginType imgOrigin = pDataImage->getOrigin(); imgOrigin.resize(3); imgOrigin[2] = 0.; pDataImage->setOrigin(imgOrigin); } ::fwData::Image::SpacingType vPixelSpacing = pDataImage->getSpacing(); vPixelSpacing.resize(3); // assume z-spacing = 1 if not guessed vPixelSpacing[2] = zspacing ? zspacing : (thickness ? thickness : 1.); pDataImage->setSpacing(vPixelSpacing); pDataImage->setWindowCenter(center); pDataImage->setWindowWidth(width); // Get the series instance UID. SLM_ASSERT("No series UID", seriesUIDStr); series->setInstanceUID(( seriesUIDStr ? seriesUIDStr : "UNKNOWN-UID" )); series->setModality( seriesModality ); series->setDescription( seriesDescription ); series->setDate( seriesDate ); series->setTime( seriesTime ); series->setPerformingPhysiciansName( seriesPhysicianNames ); series->setImage(pDataImage); SLM_ASSERT("No study UID", studyUIDStr); study->setInstanceUID(( studyUIDStr ? studyUIDStr : "UNKNOWN-UID" )); study->setDate(studyDate); study->setTime(studyTime); study->setDescription(studyDescription); study->setPatientAge(studyPatientAge); study->setReferringPhysicianName(studyReferingPhysicianName); patient->setName(patientName); patient->setPatientId(patientId); patient->setBirthdate(patientBirthdate); patient->setSex(patientSex); equipment->setInstitutionName(equipementInstitution); } // if res } // if !files.empty() } } // try catch (std::exception& e) { OSLM_ERROR( "Try with another reader or retry with this reader on a specific subfolder : " << e.what() ); for(const auto filename : filenames) { SLM_ERROR("file error : " + filename ); } } }