bool ValveDump::setParam(const std::string &name, const std::string &value) { OSLM_INFO("Set " << name << " to " << value); try { if(name == "min_free_mem") { m_minFreeMem = ::fwTools::ByteSize(value).getSize(); return true; } else if(name == "hysteresis_offet") { m_hysteresisOffset = ::fwTools::ByteSize(value).getSize(); return true; } } catch( ::fwTools::ByteSize::Exception const& ) { OSLM_ERROR("Bad value for " << name << " : " << value); return false; } OSLM_ERROR("Bad parameter name " << name ); return false; }
void SMesh::updateColorMode(std::uint8_t mode) { switch (mode) { case 0: { this->hideColors(); break; } case 1: { this->showPointColors(); break; } case 2: { this->showCellColors(); break; } default: { OSLM_ERROR("mode " << mode << " is not allowed"); break; } } }
void Activater::apply() { ::boost::shared_ptr< Bundle > bundle = Runtime::getDefault()->findBundle(m_identifier, m_version); OSLM_FATAL_IF("Unable to activate Bundle " << m_identifier << "_" << m_version << ". Not found.", bundle==0); bundle->setEnable( true ); // Managment of parameter configuration for( ParameterContainer::const_iterator i = m_parameters.begin(); i != m_parameters.end(); ++i ) { bundle->addParameter( i->first, i->second ); } // Disable extension point for this bundle for( DisableExtensionPointContainer::const_iterator id = m_disableExtensionPoints.begin(); id != m_disableExtensionPoints.end(); ++id ) { if( bundle->hasExtensionPoint(*id) ) { bundle->setEnableExtensionPoint( *id, false ); } else { OSLM_ERROR("Unable to disable Extension Point " << *id << " defined in the Bundle " << m_identifier << ". Not found."); } } // Disable extension for this bundle for( DisableExtensionContainer::const_iterator id = m_disableExtensions.begin(); id != m_disableExtensions.end(); ++id ) { if( bundle->hasExtension(*id) ) { bundle->setEnableExtension( *id, false ); } else { OSLM_ERROR("Unable to disable Extension " << *id << " defined in the Bundle " << m_identifier << ". Not found."); } } }
void Stopper::apply() { SLM_TRACE_FUNC(); ::boost::shared_ptr< Bundle > bundle = Runtime::getDefault()->findBundle(m_identifier); OSLM_FATAL_IF("Unable to stop bundle " << m_identifier << ". Not found.", bundle == 0); try { OSLM_INFO("Stopping bundle : " << m_identifier); bundle->stop(); } catch( const std::exception & e ) { OSLM_ERROR("Unable to stop bundle " << m_identifier << ". " << e.what()); } }
void DicomSearch::searchRecursivelyFiles(const ::boost::filesystem::path &dirPath, std::vector<std::string>& dicomFiles) { std::vector<std::string> vecStr; std::string strIgnoreFile = ".zip|.txt|.htm|.html|.xml|.exe|.gz|.dir|.gif|.jpeg|.jpg|dicomdir|.DS_Store"; ::boost::algorithm::split( vecStr, strIgnoreFile, ::boost::algorithm::is_any_of("|"), ::boost::algorithm::token_compress_on ); std::string lowerFilename; std::string filename; for( ::boost::filesystem::recursive_directory_iterator it(dirPath); it != ::boost::filesystem::recursive_directory_iterator(); ++it) { if(! ::boost::filesystem::is_directory(*it)) { #if BOOST_FILESYSTEM_VERSION > 2 lowerFilename = filename = it->path().string(); #else lowerFilename = filename = it->string(); #endif std::transform ( lowerFilename.begin(), lowerFilename.end(), lowerFilename.begin(), tolower ); if(DicomSearch::compare( lowerFilename, &vecStr) ) { try { ::gdcm::Reader reader; reader.SetFileName( filename.c_str() ); if( !reader.Read() )// with GDCM2.0.18 use !reader.CanRead() { OSLM_WARN("Failed to read: " << filename ); } else { dicomFiles.push_back( filename.c_str() ); } } catch (std::exception& e) { OSLM_ERROR ( "Try with another reader for this file : " << filename.c_str()); } } } } }
void SStringReader::updating() { SLM_TRACE_FUNC(); if ( this->hasLocationDefined() ) { // Read data.txt std::string line; std::string data(""); std::ifstream myfile( this->getFile().string().c_str() ); if ( myfile.is_open() ) { while ( myfile.good() ) { getline( myfile, line ); OSLM_DEBUG("Read line : " << line ); data += line; } myfile.close(); } else { OSLM_ERROR("Unable to open file : " << this->getFile() ); } OSLM_DEBUG("Loaded data : " << data ); // Set new string value in your associated object auto myAssociatedData = this->getInOut< ::fwData::String >("targetString"); SLM_ASSERT("Data not found", myAssociatedData); myAssociatedData->setValue( data ); } else { SLM_WARN("Be careful, reader failed because no file location is defined." ); } // Then, notifies listeners that the image has been modified this->notifyMessage(); }
Extension::Validity Extension::validate() { // Skips the validation if already done. if( m_validity != UnknownValidity ) { return m_validity; } // Retrieves the extension point. Runtime * rntm( Runtime::getDefault() ); ::boost::shared_ptr< ExtensionPoint > point( rntm->findExtensionPoint(m_point) ); // Checks that the point exists. if( !point ) { throw RuntimeException(m_point + " : invalid point reference."); } // Validates the extension. ::boost::shared_ptr< io::Validator > validator( point->getExtensionValidator() ); OSLM_ASSERT("Sorry, validator creation failed for point "<<point->getIdentifier(), validator ); // Check extension XML Node <extension id="xxx" implements="yyy" >...</extension> validator->clearErrorLog(); if( validator->validate( m_xmlNode ) == true ) { m_validity = Valid; } else { m_validity = Invalid; const std::string identifier = m_id.empty() ? "anonymous" : m_id; OSLM_ERROR("In bundle " << getBundle()->getIdentifier() << ". " << identifier << ": invalid extension XML element node does not respect schema. Verification error log is : " << std::endl << validator->getErrorLog() ); } return m_validity; }
void ExternalDataReaderService::updating() throw(::fwTools::Failed) { this->configureWithIHM(); std::string imageName; ::fwData::Composite::sptr dataComposite = this->getObject< ::fwData::Composite >(); ::fwComEd::helper::Composite compositeHelper(dataComposite); SLM_ASSERT("dataComposite not instanced", dataComposite); try { if (this->hasLocationDefined()) { // reading of the file std::fstream file; file.open(this->getFile().string().c_str(), std::fstream::in); if (!file.is_open()) { OSLM_ERROR( "External data file loading error for " << this->getFile()); std::string str = "Unable to open "; str+= this->getFile().string(); throw std::ios_base::failure(str); } file >> imageName; int readedValue = 0; double value; ::fwData::TransformationMatrix3D::sptr transformation1 = ::fwData::TransformationMatrix3D::New(); ::fwData::TransformationMatrix3D::sptr transformation2 = ::fwData::TransformationMatrix3D::New(); while(!file.eof()) { readedValue = 0; while ( !file.eof() && readedValue<32 ) { file >> value; if (readedValue<16) { transformation1->getRefCoefficients().push_back( value ); } else { transformation2->getRefCoefficients().push_back( value ); } readedValue++; } } file.close(); // TF1 contains the first and third transformations if(dataComposite->find("TF1") == dataComposite->end() ) { compositeHelper.add("TF1", transformation1); } else { compositeHelper.swap("TF1", transformation1); } // TF2 contains the first and third transformations if(dataComposite->find("TF2") == dataComposite->end() ) { compositeHelper.add("TF2", transformation2); } else { compositeHelper.swap("TF2", transformation2); } ::fwData::String::sptr imageNameStr = ::fwData::String::New(imageName); if(dataComposite->find("filename") == dataComposite->end() ) { compositeHelper.add("filename", imageNameStr); } else { compositeHelper.swap("filename", imageNameStr); } SLM_ASSERT("Unable to open '"+this->getFile().string()+"'.", readedValue == 32 ); } } catch(std::ios_base::failure &exception) { OSLM_ERROR( "External data file loading error for " << exception.what()); } }
bool DicomReaderTest::checkSeriesACHGenou( const ::fwMedData::ImageSeries::sptr &series ) { bool ok = true; bool notReallyChecked = true; ::fwMedData::Patient::sptr patient = series->getPatient(); ::fwMedData::Study::sptr study = series->getStudy(); ::fwMedData::Equipment::sptr equipment = series->getEquipment(); // Study, Acquisition ::fwData::Image::sptr img = series->getImage(); //# Dicom-File-Format // //# Dicom-Meta-Information-Header //# Used TransferSyntax: //(0002,0000) UL 224 # 4,1 File Meta Information Group Length //(0002,0001) OB 00\01 # 2,1 File Meta Information Version //(0002,0002) UI [1.2.840.10008.5.1.4.1.1.2] # 26,1 Media Storage SOP Class UID //(0002,0003) UI [1.2.392.200036.9116.2.6.1.48.1211418863.1225184712.380696] # 58,1 Media Storage SOP Instance UID //(0002,0010) UI [1.2.840.10008.1.2.1] # 20,1 Transfer Syntax UID //(0002,0012) UI [1.2.250.1.119.1.1.1.1.1.1.33.3.8.13.7] # 38,1 Implementation Class UID //(0002,0013) SH [scanplus_33 ] # 12,1 Implementation Version Name //(0002,0016) AE [scanplus] # 8,1 Source Application Entity Title // //# Dicom-Data-Set //# Used TransferSyntax: 1.2.840.10008.1.2.1 //(0008,0000) UL 426 # 4,1 Generic Group Length //(0008,0008) CS [ORIGINAL\PRIMARY\AXIAL] # 22,2-n Image Type //(0008,0016) UI [1.2.840.10008.5.1.4.1.1.2] # 26,1 SOP Class UID //(0008,0018) UI [1.2.392.200036.9116.2.6.1.48.1211418863.1225184712.380696] # 58,1 SOP Instance UID //(0008,0020) DA [20081028] # 8,1 Study Date CHECK_VALUE(ok,"Study Date doesn't match : ", "20081028",study->getDate()); //(0008,0021) DA [20081028] # 8,1 Series Date CHECK_VALUE(ok,"Series Modality doesn't match : ", "20081028", series->getDate() ); //(0008,0022) DA [20081028] # 8,1 Acquisition Date //(0008,0023) DA [20081028] # 8,1 Content Date //(0008,0030) TM [174327.000] # 10,1 Study Time CHECK_VALUE(ok,"Study Time doesn't match : ", "174327.000", study->getTime() ); //(0008,0031) TM [180156.734] # 10,1 Series Time CHECK_VALUE(ok,"Series Modality doesn't match : ", "180156.734", series->getTime() ); //(0008,0032) TM [174446.850] # 10,1 Acquisition Time //(0008,0033) TM [174502.095] # 10,1 Content Time //(0008,0050) SH [12514 ] # 6,1 Accession Number //(0008,0060) CS [CT] # 2,1 Modality CHECK_VALUE(ok,"Series Modality doesn't match : ", "CT", series->getModality() ); //(0008,0070) LO [TOSHIBA ] # 8,1 Manufacturer //(0008,0080) LO [SCANNER DE LA MODER ] # 20,1 Institution Name CHECK_VALUE(ok,"Equipment's Institution Name doesn't match : ", "SCANNER DE LA MODER ", equipment->getInstitutionName() ); //(0008,0090) PN [DR MOREL] # 8,1 Referring Physician's Name CHECK_VALUE(ok,"Study Referring Physician's Name doesn't match : ", "DR MOREL", study->getReferringPhysicianName() ); //(0008,1010) SH [00000000001 ] # 12,1 Station Name //(0008,103e) LO [ OS 0.5 ] # 10,1 Series Description CHECK_VALUE(ok,"Study Description doesn't match : ", " OS 0.5 ", series->getDescription() ); CHECK_VALUE(ok,"Study Description doesn't match : ", "", study->getDescription() ); // 0008,1030 //(0008,1040) LO [ID_DEPARTMENT ] # 14,1 Institutional Department Name { fwMedData::DicomValuesType physiciansName; ok &= (physiciansName == series->getPerformingPhysiciansName()); OSLM_ERROR_IF ("Name of the physician(s) administering the Series doesn't match : ", (physiciansName == series->getPerformingPhysiciansName())); } //(0008,1090) LO [Aquilion] # 8,1 Manufacturer's Model Name //(0010,0000) UL 104 # 4,1 Generic Group Length //(0010,0010) PN [CHARNOZ ARNAUD] # 14,1 Patient's Name CHECK_VALUE(ok,"Patient's Name doesn't match : ", "CHARNOZ ARNAUD", patient->getName() ); //(0010,0020) LO [12592 ARTHRO GENOU G ] # 22,1 Patient ID CHECK_VALUE(ok,"Patient ID doesn't match : ", "12592 ARTHRO GENOU G ", patient->getPatientId() ); //(0010,0030) DA [19790618] # 8,1 Patient's Birth Date CHECK_VALUE(ok,"Patient's Birth Date doesn't match : ", "19790618", patient->getBirthdate() ); //(0010,0040) CS [M ] # 2,1 Patient's Sex CHECK_VALUE(ok,"Patient's Sex doesn't match :", "M " , patient->getSex() ); //(0010,1010) AS [029Y] # 4,1 Patient's Age CHECK_VALUE(ok,"Study Patient's Age doesn't match :", "029Y" , study->getPatientAge() ); //(0010,4000) LT [ARTHRO] # 6,1 Patient Comments //(0018,0000) UL 284 # 4,1 Generic Group Length //(0018,0015) CS [DR MOREL] # 8,1 Body Part Examined //(0018,0022) CS [HELICAL_CT] # 10,1-n Scan Options //(0018,0050) DS [0.5 ] # 4,1 Slice Thickness //(0018,0060) DS [120 ] # 4,1 KVP //(0018,0090) DS [400.00] # 6,1 Data Collection Diameter //(0018,1000) LO [C4522344] # 8,1 Device Serial Number //(0018,1020) LO [V3.20ER005] # 10,1-n Software Version(s) //(0018,1030) LO [ARTHRO GENOU] # 12,1 Protocol Name //(0018,1100) DS [196.875 ] # 8,1 Reconstruction Diameter //(0018,1120) DS [+0.0] # 4,1 Gantry/Detector Tilt //(0018,1130) DS [+90.00] # 6,1 Table Height //(0018,1140) CS [CW] # 2,1 Rotation Direction //(0018,1150) IS [500 ] # 4,1 Exposure Time //(0018,1151) IS [200 ] # 4,1 X-Ray Tube Current //(0018,1152) IS [100 ] # 4,1 Exposure //(0018,1170) IS [24] # 2,1 Generator Power //(0018,1190) DS [0.9\0.8 ] # 8,1-n Focal Spot(s) //(0018,1210) SH [FC30] # 4,1-n Convolution Kernel //(0018,5100) CS [FFS ] # 4,1 Patient Position //(0018,9345) UN (FD) 23.1 # 8,1 CTDIvol //(0020,0000) UL 370 # 4,1 Generic Group Length //(0020,000d) UI [1.2.392.200036.9116.2.6.1.48.1211418863.1225183167.375775] # 58,1 Study Instance UID CHECK_VALUE(ok,"Study Instance UID doesn't match :", "1.2.392.200036.9116.2.6.1.48.1211418863.1225183167.375775" , study->getInstanceUID() ); //(0020,000e) UI [1.2.392.200036.9116.2.6.1.48.1211418863.1225184516.765855] # 58,1 Series Instance UID CHECK_VALUE(ok,"Series Instance UID doesn't match :", "1.2.392.200036.9116.2.6.1.48.1211418863.1225184516.765855" , series->getInstanceUID() ); //(0020,0010) SH [12514 ] # 6,1 Study ID //(0020,0011) IS [3 ] # 2,1 Series Number //(0020,0012) IS [3 ] # 2,1 Acquisition Number //(0020,0013) IS [404 ] # 4,1 Instance Number //(0020,0020) CS [L\P ] # 4,2 Patient Orientation //(0020,0032) DS [-36.71875\-88.28125\1350.300] # 28,3 Image Position (Patient) if(!img) { OSLM_ERROR( "Missing image." ); return false; } CHECK_VALUE_WITH_TOLERANCE(ok,"Image x origin doesn't match :", -36.71875 , img->getOrigin()[0], 0.01); CHECK_VALUE_WITH_TOLERANCE(ok,"Image y origin doesn't match :", -88.28125 , img->getOrigin()[1], 0.01); CHECK_VALUE_WITH_TOLERANCE(ok,"Image z origin doesn't match :", 1350.300 , img->getOrigin()[2], 0.01); //(0020,0037) DS [1.00000\0.00000\0.00000\0.00000\1.00000\0.00000 ] # 48,6 Image Orientation (Patient) //(0020,0052) UI [1.2.392.200036.9116.2.6.1.48.1211418863.1225183409.15274] # 56,1 Frame of Reference UID //(0020,1040) LO (no value) # 0,1 Position Reference Indicator //(0020,1041) DS [+161.20 ] # 8,1 Slice Location //(0028,0000) UL 158 # 4,1 Generic Group Length //(0028,0002) US 1 # 2,1 Samples per Pixel //(0028,0004) CS [MONOCHROME2 ] # 12,1 Photometric Interpretation //(0028,0010) US 512 # 2,1 Rows //(0028,0011) US 512 # 2,1 Columns CHECK_VALUE(ok,"Image x size doesn't match :", 512 , img->getSize()[0] ); CHECK_VALUE(ok,"Image y size doesn't match :", 512 , img->getSize()[1] ); CHECK_VALUE(ok,"Image z size doesn't match :", 404 , img->getSize()[2] ); //(0028,0030) DS [0.384\0.384 ] # 12,2 Pixel Spacing CHECK_VALUE_WITH_TOLERANCE(ok,"Image x spacing doesn't match :", 0.384 , img->getSpacing()[0], 0.001); CHECK_VALUE_WITH_TOLERANCE(ok,"Image y spacing doesn't match :", 0.384 , img->getSpacing()[1], 0.001); CHECK_VALUE_WITH_TOLERANCE(ok,"Image z spacing doesn't match :", 0.399 , img->getSpacing()[2], 0.001); //(0028,0100) US 16 # 2,1 Bits Allocated //(0028,0101) US 16 # 2,1 Bits Stored CHECK_VALUE(notReallyChecked,"Image Bits Allocated correspond :", 16, img->getType().sizeOf() * 8 ); //(0028,0102) US 15 # 2,1 High Bit //(0028,0103) US 1 # 2,1 Pixel Representation CHECK_VALUE(notReallyChecked,"Image Bits Allocated correspond :", false, img->getType().isSigned() ); //(0028,1050) DS [500 ] # 4,1-n Window Center CHECK_VALUE(ok,"Image Window Center correspond :", 500, img->getWindowCenter() ); //(0028,1051) DS [2500] # 4,1-n Window Width CHECK_VALUE(ok,"Image Window Width correspond :", 2500, img->getWindowWidth() ); //(0028,1052) DS [-1024 ] # 6,1 Rescale Intercept //(0028,1053) DS [1 ] # 2,1 Rescale Slope //(0040,0000) UL 116 # 4,1 Generic Group Length //(0040,0002) DA [20081028] # 8,1 Scheduled Procedure Step Start Date //(0040,0003) TM [174327.000] # 10,1 Scheduled Procedure Step Start Time //(0040,0004) DA [20081028] # 8,1 Scheduled Procedure Step End Date //(0040,0005) TM [181327.000] # 10,1 Scheduled Procedure Step End Time //(0040,0244) DA [20081028] # 8,1 Performed Procedure Step Start Date //(0040,0245) TM [174327.000] # 10,1 Performed Procedure Step Start Time //(0040,0253) SH [12325 ] # 6,1 Performed Procedure Step ID //(7005,0000) UL 546 # 4,1 Generic Group Length //(7005,0010) LO [TOSHIBA_MEC_CT3 ] # 16,1 Private Creator //(7005,1007) UN (DS) [335\269 ] # 8,2 Reconstruction Center //(7005,1008) UN (DS) [0.5 ] # 4,1 Detector Slice Thickness in mm //(7005,1009) UN (LO) [1111111111111111] # 16,1 Number of Detector rows to Reconstruct //(7005,100a) UN (DS) [+5.50 ] # 6,1 Table Speed in mm/rot //(7005,100b) UN (SH) [ORG ] # 4,1 Filter //(7005,100d) UN (CS) [DR MOREL] # 8,1 Organ //(7005,100e) UN (SH) [IMG ] # 4,1 File Type Remarks //(7005,100f) UN (SH) [FF] # 2,1 Direction //(7005,1011) UN (LT) [Vol.] # 4,1 Series Comment //(7005,1012) UN (SH) [SU] # 2,1 Position //(7005,1013) UN (US) 1 # 2,1 Expert Plan No. //(7005,1016) UN (UI) [1.2.392.200036.9116.2.6.1.48.1211418863.1225184516.747732] # 58,1 Volume UID //(7005,1017) UN (US) 404 # 2,1 Total Frame Count in the Volume //(7005,1018) UN (US) 404 # 2,1 Frame No. //(7005,1019) UN (UL) 1642763 # 4,1 Frame Sort Key //(7005,101a) UN (US) 1 # 2,1 Frame Sort Order //(7005,101b) UN (SH) [FC30] # 4,1 Convolution Kernel //(7005,101d) UN (UL) 9 # 4,1 Reconstruction Number //(7005,101e) UN (UL) 13 # 4,1 Raw Data Number //(7005,101f) UN (LO) [20081028180156768480] # 20,1 Volume Number //(7005,1020) UN (UL) 3 # 4,1 Local Series Number //(7005,1021) UN (LO) [BOOST ] # 6,1 Decrease in Artifact Filter //(7005,1022) UN (DS) [0.40] # 4,1 Reconstruction Interval //(7005,1023) UN (DS) [0.688 ] # 6,1 Pitch Factor //(7005,1024) UN (DA) [20081024] # 8,1 The Acquisition Date of NRA //(7005,1030) UN (CS) [CT] # 2,1 Main Modality in Study //(7005,1040) UN (FD) 402.4 # 8,1 DLP Dose Length Product return ok; }
void ItkLogger::DisplayErrorText(const char* _txt) { OSLM_ERROR("[ITK]: " << _txt); }
void DicomStudyReader::read() throw(::fwTools::Failed) { SLM_TRACE_FUNC(); ::fwData::Study::sptr study = this->getConcreteObject(); SLM_ASSERT("::fwData::Study not set", study); //***** Get all file names *****// std::vector< std::string > studyFiles = this->getFileNames(); // files which contain a common study OSLM_TRACE("Number of files for a study : " << studyFiles.size()); //***** Get group of file names for each series *****// const ::gdcm::Tag gTagSUID(0x0020,0x000e); // Series UID const ::gdcm::Tag gTagImageType(0x0008,0x0008); // ImageType gdcm::Scanner gScanner; gScanner.AddTag(gTagSUID); gScanner.AddTag(gTagImageType); if( !gScanner.Scan( studyFiles ) ) { throw ::fwTools::Failed("No series found"); } ::gdcm::Directory::FilenamesType keys = gScanner.GetKeys(); ::gdcm::Directory::FilenamesType::const_iterator it = keys.begin(); ::gdcm::Directory::FilenamesType::const_iterator itEnd = keys.end(); // Create a map to associate each series with its files. std::map< std::string, std::vector< std::string > > seriesMap; // Key : series UID ; Value : filenames found int secondaryCaptureCounter = 0; for(; it != itEnd; ++it) { const char * filename = it->c_str(); const char * seriesUID = gScanner.GetValue(filename, gTagSUID); if (seriesUID != 0) { std::string seriesKey(seriesUID); // Treatment of secondary capture dicom file. if(gScanner.GetValue(filename, gTagImageType)) { std::string imageType(gScanner.GetValue(filename, gTagImageType)); std::string::size_type idx = imageType.find("DERIVED\\SECONDARY"); if( idx != std::string::npos) { std::string::size_type endIdx = imageType.find_first_not_of("DERIVED\\SECONDARY"); std::string optionalInfo = imageType.substr(endIdx); std::ostringstream indice; if(!optionalInfo.empty()) { indice << optionalInfo; } else { // Tag as Secondary Capture indice << "_SC_" << secondaryCaptureCounter; secondaryCaptureCounter++; } seriesKey += indice.str(); } } seriesMap[seriesKey].push_back( filename ); } else { OSLM_ERROR ( "No study UID found in : " << filename ); } } //***** Read each patient (and so studies, series, ...) *****// DicomSeriesReader seriesReader; std::map< std::string, std::vector< std::string > >::iterator itMap = seriesMap.begin(); std::map< std::string, std::vector< std::string > >::iterator itMapEnd = seriesMap.end(); while (itMap != itMapEnd) { OSLM_TRACE ( "Series map key : " << itMap->first ); if ( itMap->second.size() > 0 ) { OSLM_TRACE ( "First series map value : " << *(itMap->second.begin()) ); seriesReader.setFileNames(itMap->second); ::fwData::Acquisition::NewSptr series; seriesReader.setObject(series); try { // Read one series seriesReader.read(); // Add a complete series study->addAcquisition(series); } catch (::fwTools::Failed & e) { OSLM_ERROR ("Reading error with series : " << itMap->first); // Acquisition skipped } } itMap++; } if(study->getNumberOfAcquisitions() == 0) throw ::fwTools::Failed("Study has no acquisition"); //***** Read study *****// this->setReader( seriesReader.getReader() ); this->readStudy(); }
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 ); } } }
void DicomSurfaceWriter::write() throw (::fwTools::Failed) { ::fwData::Acquisition::csptr series = this->getConcreteObject(); SLM_ASSERT("fwData::Acquisition not instanced", series); //***** Get the dictionary *****// // Reading of the dictionary ::fwData::StructureTraitsDictionary::NewSptr structDico; // Ready of the dictionary file. ::fwDataIO::reader::DictionaryReader::NewSptr dictionaryReader; dictionaryReader->setObject(structDico); std::string dictionaryPath("./share/fwDataIO_0-2/OrganDictionary.dic"); dictionaryReader->setFile(dictionaryPath); try { dictionaryReader->read(); } catch(const std::exception & e) { OSLM_ERROR(e.what()); } //***** Write surface segmentations *****// unsigned int skippedSegment = 0; // Number of segmentation not written const uint32_t nbSegmentation = series->getNumberOfReconstructions(); for (unsigned int i = 0; i < nbSegmentation; ++i) { try { // Get the info of the struture type ::fwData::Reconstruction::csptr reconstruction = series->getReconstructions()[i]; const std::string & segmentLabel = reconstruction->getStructureType(); ::fwData::StructureTraitsDictionary::StructureTypeNameContainer segmentLabels = structDico->getStructureTypeNames(); ::fwData::StructureTraitsDictionary::StructureTypeNameContainer::const_iterator itr = std::find(segmentLabels.begin(), segmentLabels.end(),segmentLabel); ::fwData::StructureTraits::sptr structure; ::fwData::StructureTraits::NewSptr emptyStructure; if(itr != segmentLabels.end()) { structure = structDico->getStructure(segmentLabel); } else { structure = emptyStructure; } // Write segmentation DicomSegmentWriter::writeSurfaceSegmentation(i, structure); // Here, the segment is identified and its surface can be written. this->writeSurfaceMesh(i); } catch(::fwTools::Failed & e) { ++skippedSegment; OSLM_ERROR(e.what()); } } if (skippedSegment == nbSegmentation) { throw ::fwTools::Failed("All 3D reconstructions have been rejected"); } else if (skippedSegment > 0) { OSLM_WARN(skippedSegment<<" 3D reconstruction(s) have been rejected"); } ::boost::shared_ptr< ::gdcm::SurfaceWriter > gSurfaceWriter = ::boost::static_pointer_cast< ::gdcm::SurfaceWriter >( this->getWriter() ); ::gdcm::DataSet & gDsRoot = this->getDataSet(); // Number of Surfaces Tag(0x0066,0x0001) gSurfaceWriter->SetNumberOfSurfaces( nbSegmentation - skippedSegment ); // Type 1 OSLM_TRACE("Number of Surfaces : " << nbSegmentation - skippedSegment); //***** Write Enhanced General Equipement Module *****// //See: PS 3.3 C.7.5.2 { DicomEquipmentWriter equipmentWriter; equipmentWriter.writeEnhancedGeneralEquipement(gDsRoot); } //***** Write Content Identification Module *****// //See: PS 3.3 Table 10-12 this->writeContentIdentification(); //***** Complete the file *****// // Set the instance to surface segmentation storage ::boost::shared_ptr< DicomInstance > dicomInstance = this->getDicomInstance(); const char * SOPClassUID = ::gdcm::MediaStorage::GetMSString( ::gdcm::MediaStorage::SurfaceSegmentationStorage ); std::string SOPClassUIDStr; if (SOPClassUID == 0) SOPClassUIDStr = "1.2.840.10008.5.1.4.1.1.66.5"; else SOPClassUIDStr = SOPClassUID; dicomInstance->setSOPClassUID( SOPClassUIDStr ); ::gdcm::UIDGenerator gUIDgen; gUIDgen.SetRoot( SOPClassUIDStr.c_str() ); dicomInstance->setSOPInstanceUID( gUIDgen.Generate() ); dicomInstance->setModality("SEG"); //***** Write the file *****// DicomRefInstanceWriter< ::fwData::Acquisition >::write(); }