// Load our vtkImageData object from a list of DICOM image filenames... // http://www.vtk.org/pipermail/vtkusers/2007-August/042635.html void vtkDicom::load_dcmFiles(QStringList dcm_fileList) { DcmFileFormat dcm; std::string imgFname; std::cout << "vtkdicom: Files/Images(?): " << dcm_fileList.size() << "\n"; for (int sei = 0; sei < dcm_fileList.size(); ++sei) { imgFname = dcm_fileList.at(sei).toLocal8Bit().constData(); OFCondition status = dcm.loadFile(imgFname.c_str()); if (!status.good()) { std::cout << " vtkdicom: Error: cannot read file (" << status.text() << ")" << "\n"; return; } if (sei == 0) { OFString acquisitionNumber, instanceNumber, imagePositionPatient, patientsName; DcmDataset *dcmDs = dcm.getDataset(); dcmDs->findAndGetOFStringArray(DCM_ImagePositionPatient, imagePositionPatient); dcmDs->findAndGetOFString(DCM_AcquisitionNumber, acquisitionNumber); dcmDs->findAndGetOFString(DCM_InstanceNumber, instanceNumber); dcmDs->findAndGetOFString(DCM_PatientName, patientsName); std::cout << "vtkdicom: I#, IPP: " << instanceNumber << " - " << imagePositionPatient << "\n"; } dcm.loadAllDataIntoMemory(); const unsigned short* p = NULL; dcm.getDataset()->findAndGetUint16Array(DCM_PixelData, p); } }
bool DicomImporter::IsFileValid(const String& _file) { try { // // create the dicom fileformat and check if this is possible // DcmFileFormat ff; OFCondition cond = ff.loadFile(_file.c_str()); if (cond.bad()) return false; // // ist it in part 10 format (does meta-header exist)? // DcmMetaInfo *m = ff.getMetaInfo(); if (m == NULL || m->card() == 0) return false; // // does the file contain data (does the dataset exist)? // DcmDataset *d = ff.getDataset(); if (d == NULL) return false; // // yes, it is a valid dicom file! // return true; } catch (...) { throw; } }
bool ParserDicom::isValidFile(string filename) { DcmFileFormat dcm; OFCondition cond = dcm.loadFile(filename.c_str()); return cond.good(); }
OFCondition Internals::moveScp(T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID, IMoveRequestHandler& handler, const std::string& remoteIp, const std::string& remoteAet, const std::string& calledAet) { MoveScpData data; data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination); data.lastRequest_ = NULL; data.handler_ = &handler; data.remoteIp_ = &remoteIp; data.remoteAet_ = &remoteAet; data.calledAet_ = &calledAet; OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, MoveScpCallback, &data, /*opt_blockMode*/ DIMSE_BLOCKING, /*opt_dimse_timeout*/ 0); // if some error occured, dump corresponding information and remove the outfile if necessary if (cond.bad()) { OFString temp_str; LOG(ERROR) << "Move SCP Failed: " << cond.text(); } return cond; }
// copy optional string value from dataset to directory record static void copyStringWithDefault(DcmItem& dataset, const DcmTagKey &key, DcmDirectoryRecord& record, const char *defaultValue, const OFBool printWarning) { OFCondition status; if (dataset.tagExistsWithValue(key)) { OFString stringValue; /* retrieve string value from source dataset and put it into the destination dataset */ status = dataset.findAndGetOFStringArray(key, stringValue); if (status.good()) status = record.putAndInsertString(key, stringValue.c_str()); } else { if (printWarning && (defaultValue != NULL)) { /* create warning message */ LOG(WARNING) << "DICOMDIR: " << DcmTag(key).getTagName() << " " << key << " missing, using alternative: " << defaultValue; } /* put default value */ status = record.putAndInsertString(key, defaultValue); } }
// copy element from dataset to directory record static void copyElement(DcmItem& dataset, const DcmTagKey &key, DcmDirectoryRecord& record, const OFBool optional, const OFBool copyEmpty) { /* check whether tag exists in source dataset (if optional) */ if (!optional || (copyEmpty && dataset.tagExists(key)) || dataset.tagExistsWithValue(key)) { DcmElement *delem = NULL; /* get copy of element from source dataset */ OFCondition status = dataset.findAndGetElement(key, delem, OFFalse /*searchIntoSub*/, OFTrue /*createCopy*/); if (status.good()) { /* ... and insert it into the destination dataset (record) */ status = record.insert(delem, OFTrue /*replaceOld*/); if (status.good()) { DcmTag tag(key); /* check for correct VR in the dataset */ if (delem->getVR() != tag.getEVR()) { /* create warning message */ LOG(WARNING) << "DICOMDIR: possibly wrong VR: " << tag.getTagName() << " " << key << " with " << DcmVR(delem->getVR()).getVRName() << " found, expected " << tag.getVRName() << " instead"; } } else delete delem; } else if (status == EC_TagNotFound) status = record.insertEmptyElement(key); printAttributeErrorMessage(key, status, "insert"); } }
PACSRequestStatus::RetrieveRequestStatus RetrieveDICOMFilesFromPACS::retrieve(const QString &studyInstanceUID, const QString &seriesInstanceUID, const QString &sopInstanceUID) { T_ASC_PresentationContextID presentationContextID; T_DIMSE_C_MoveRSP moveResponse; DcmDataset *statusDetail = NULL; m_pacsConnection = new PACSConnection(m_pacs); PACSRequestStatus::RetrieveRequestStatus retrieveRequestStatus; MoveSCPCallbackData moveSCPCallbackData; DcmDataset *dcmDatasetToRetrieve = getDcmDatasetOfImagesToRetrieve(studyInstanceUID, seriesInstanceUID, sopInstanceUID); m_numberOfImagesRetrieved = 0; // TODO S'hauria de comprovar que es tracti d'un PACS amb el servei de retrieve configurat if (!m_pacsConnection->connectToPACS(PACSConnection::RetrieveDICOMFiles)) { ERROR_LOG("S'ha produit un error al intentar connectar al PACS per fer un retrieve. AE Title: " + m_pacs.getAETitle()); return PACSRequestStatus::RetrieveCanNotConnectToPACS; } // Which presentation context should be used, It's important that the connection has MoveStudyRoot level T_ASC_Association *association = m_pacsConnection->getConnection(); presentationContextID = ASC_findAcceptedPresentationContextID(association, MoveAbstractSyntax); if (presentationContextID == 0) { ERROR_LOG("No s'ha trobat cap presentation context valid"); return PACSRequestStatus::RetrieveFailureOrRefused; } moveSCPCallbackData.association = association; moveSCPCallbackData.presentationContextId = presentationContextID; moveSCPCallbackData.retrieveDICOMFilesFromPACS = this; // Set the destination of the images to us T_DIMSE_C_MoveRQ moveRequest = getConfiguredMoveRequest(association); ASC_getAPTitles(association->params, moveRequest.MoveDestination, NULL, NULL); OFCondition condition = DIMSE_moveUser(association, presentationContextID, &moveRequest, dcmDatasetToRetrieve, moveCallback, &moveSCPCallbackData, DIMSE_BLOCKING, 0, m_pacsConnection->getNetwork(), subOperationCallback, this, &moveResponse, &statusDetail, NULL /*responseIdentifiers*/); if (condition.bad()) { ERROR_LOG(QString("El metode descarrega no ha finalitzat correctament. Codi error: %1, descripcio error: %2").arg(condition.code()) .arg(condition.text())); } m_pacsConnection->disconnect(); retrieveRequestStatus = getDIMSEStatusCodeAsRetrieveRequestStatus(moveResponse.DimseStatus); processServiceClassProviderResponseStatus(moveResponse.DimseStatus, statusDetail); // Dump status detail information if there is some if (statusDetail != NULL) { delete statusDetail; } delete dcmDatasetToRetrieve; return retrieveRequestStatus; }
void RetrieveDICOMFilesFromPACS::subOperationCallback(void *subOperationCallbackData, T_ASC_Network *associationNetwork, T_ASC_Association **subAssociation) { RetrieveDICOMFilesFromPACS *retrieveDICOMFilesFromPACS = (RetrieveDICOMFilesFromPACS*)subOperationCallbackData; if (associationNetwork == NULL) { // Help no net ! return; } if (*subAssociation == NULL) { OFCondition condition = retrieveDICOMFilesFromPACS->acceptSubAssociation(associationNetwork, subAssociation); if (!condition.good()) { ERROR_LOG("S'ha produit un error negociant l'associacio de la connexio DICOM entrant, descripcio error: " + QString(condition.text())); } else { INFO_LOG("Rebuda solicitud de connexio pel port de connexions DICOM entrants del PACS."); } } else { retrieveDICOMFilesFromPACS->subOperationSCP(subAssociation); } }
void LocalService::SolveFile( const boost::filesystem::path & fileName, const boost::filesystem::path & path, ResultSet &result) { OFString ofStr; DcmFileFormat dfile; OFCondition cond = dfile.loadFile( fileName.string().data()); if (! cond.good()) { LOG( "Loading of " << fileName << " failed. (" << cond.text() << ")" ); return; } DcmDataset *dataSet = dfile.getDataset(); TableRow row; SerieInfo serInfo; // load data and check if it is already in tree CheckDataSet( dataSet, serInfo, row, path.string()); // look if this row is already in resultSet FoundStudiesSet::iterator found = m_alreadyFoundInRun.find(row.studyID); // if not, add it if( found == m_alreadyFoundInRun.end() ) { m_alreadyFoundInRun.insert( FoundStudiesSet::value_type( row.studyID) ); result.push_back( row); } }
//------------------------------------------------------------------------------ void ctkDICOMDatabase::loadFileHeader (QString fileName) { Q_D(ctkDICOMDatabase); DcmFileFormat fileFormat; OFCondition status = fileFormat.loadFile(fileName.toLatin1().data()); if (status.good()) { DcmDataset *dataset = fileFormat.getDataset(); DcmStack stack; while (dataset->nextObject(stack, true) == EC_Normal) { DcmObject *dO = stack.top(); if (dO->isaString()) { QString tag = QString("%1,%2").arg( dO->getGTag(),4,16,QLatin1Char('0')).arg( dO->getETag(),4,16,QLatin1Char('0')); std::ostringstream s; dO->print(s); d->LoadedHeader[tag] = QString(s.str().c_str()); } } } return; }
// Caller is responsible for deallocating returned object AnnotationCollection* DcmModel::ReadAnnotationCollectionFromFile(const std::string& fileName){ DcmModelInternal dcmModelInternal(_uidPrefix); AnnotationCollection* pCollection = NULL; try { OFCondition ofCondition = dcmModelInternal.ReadDocFromFile(&pCollection, fileName); if (!ofCondition.good()) { if (pCollection){ delete pCollection; pCollection = NULL; } std::string err = std::string("Failed to load SR from file <").append(fileName).append(">:"); err += ofCondition.text(); dcmModelInternal.printDebug(std::string(__FILE__).append(": ").append(err).c_str()); } } catch(const std::exception& ex) { std::string err = std::string("Error loading SR from file<").append(fileName).append(">:"); err += ex.what(); dcmModelInternal.printDebug(err.c_str()); } return pCollection; }
OFCondition Internals::findScp(T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID, IFindRequestHandler* findHandler, IWorklistRequestHandler* worklistHandler, const std::string& remoteIp, const std::string& remoteAet, const std::string& calledAet) { FindScpData data; data.lastRequest_ = NULL; data.findHandler_ = findHandler; data.worklistHandler_ = worklistHandler; data.remoteIp_ = &remoteIp; data.remoteAet_ = &remoteAet; data.calledAet_ = &calledAet; OFCondition cond = DIMSE_findProvider(assoc, presID, &msg->msg.CFindRQ, FindScpCallback, &data, /*opt_blockMode*/ DIMSE_BLOCKING, /*opt_dimse_timeout*/ 0); // if some error occured, dump corresponding information and remove the outfile if necessary if (cond.bad()) { OFString temp_str; LOG(ERROR) << "Find SCP Failed: " << cond.text(); } return cond; }
bool DCMTKImageIO::CanReadFile(const char* filename) { DcmFileFormat dicomFile; OFCondition condition = dicomFile.loadFile( filename ); if ( !condition.good() ) { return false; } E_TransferSyntax xfer = dicomFile.getDataset()->getOriginalXfer(); if( xfer == EXS_JPEG2000LosslessOnly || xfer == EXS_JPEG2000 || xfer == EXS_JPEG2000MulticomponentLosslessOnly || xfer == EXS_JPEG2000Multicomponent ) { return false; } // search for mandatory tags DcmStack stack; DcmTagKey searchKey; unsigned int group = 0x0028; // samples per pixel unsigned int elem = 0x0002; // samples per pixel searchKey.set(group, elem); if (dicomFile.search(searchKey, stack, ESM_fromHere, OFTrue) != EC_Normal) return false; group = 0x0028; // pixel type elem = 0x0100; // pixel type searchKey.set(group, elem); if (dicomFile.search(searchKey, stack, ESM_fromHere, OFTrue) != EC_Normal) return false; return true; }
Series::InstanceUIDContainer Series::toSeriesInstanceUIDContainer(OFList< QRResponse* > responses) { InstanceUIDContainer instanceUIDContainer; OFIterator< QRResponse* > it; DcmDataset dataset; OFCondition result; // Every while loop run will get all image for a specific study for (it = responses.begin(); it != responses.end(); ++it) { // Be sure we are not in the last response which does not have a dataset if ((*it)->m_dataset != NULL) { OFString seriesInstanceUID; result = (*it)->m_dataset->findAndGetOFStringArray(DCM_SeriesInstanceUID, seriesInstanceUID); // Only try to get study if we actually have study instance uid, otherwise skip it if (result.good()) { instanceUIDContainer.push_back(seriesInstanceUID.c_str()); } else { const std::string msg = "There is no \"SeriersInstanceUID\" tag in the selected series :" + std::string(result.text()); throw ::fwPacsIO::exceptions::TagMissing(msg); } } } return instanceUIDContainer; }
bool DicomdirLoader::load(const std::string &studyinstanceuid, const Glib::ustring &dicomdir) { DcmDicomDir dir(dicomdir.c_str()); OFCondition ret; if (busy() ) { return false; } if ( (ret=dir.error()) != EC_Normal ) { std::cout << "DicomdirLoader::load Error: " << ret.text() << std::endl; return false; } // Open DICOMDIR and look for StudyInstanceUID // Add all IMAGE record types to m_FileList and fill cache // FileLoader::Start DcmDirectoryRecord *studyRec = find_study(studyinstanceuid, dir); if ( !studyRec ) { std::cout << "DicomdirLoader::load Error: cannot find study" << std::endl; return false; } m_filelist = new std::list< Glib::ustring >; m_cache.clear(); if ( !scan_study(studyinstanceuid, studyRec, dicomdir) ) { std::cout << "DicomdirLoader::load: no visible images" << std::endl; return false; } FileLoader::start(); return true; }
bool EchoToPACS::echo(PacsDevice pacsDevice) { PACSConnection pacsConnection(pacsDevice); /// Es fa la connexió connexió if (connectToPACS(&pacsConnection)) { /// Es fa un echo al pacs OFCondition condition = echoToPACS(&pacsConnection); /// Desconnexió disconnectFromPACS(&pacsConnection); if (condition.good()) { m_lastError = EchoOk; } else { ERROR_LOG("Doing echo to " + pacsDevice.getAETitle() + " does not respond correctly. Error description: " + condition.text()); m_lastError = EchoFailed; } } else { INFO_LOG("Doing echo to " + pacsDevice.getAETitle() + " does not respond."); m_lastError = EchoCanNotConnectToPACS; } return m_lastError == EchoOk; }
OFCondition GIL::DICOM::DCMTK::Network::InitializeNetwork(int timeout, Association::RoleType role, int port) { if (m_pDCMTKNetwork != NULL) { LOG_WARN("DICOMNetwork", "Shutting down previous initiallized network"); DropNetwork(); } OFCondition cond; switch (role) { case Association::RT_Acceptor: cond = ASC_initializeNetwork(NET_ACCEPTOR, 0, timeout, &m_pDCMTKNetwork); break; case Association::RT_Requestor: cond = ASC_initializeNetwork(NET_REQUESTOR, port, timeout, &m_pDCMTKNetwork); break; case Association::RT_AcceptorRequestor: cond = ASC_initializeNetwork(NET_ACCEPTORREQUESTOR, port, timeout, &m_pDCMTKNetwork); break; default: cond = EC_IllegalParameter; break; } m_Initiallized = cond.good(); return cond; }
OFCondition Association::Drop(OFCondition cond) { // tear down association if(cond == EC_Normal) { /* release association */ cond = ASC_releaseAssociation(assoc); } else if(cond == DUL_PEERREQUESTEDRELEASE) { cond = ASC_abortAssociation(assoc); if (cond.good()) { return cond; } } else if(cond == DUL_PEERABORTEDASSOCIATION) { return cond; } else { cond = ASC_abortAssociation(assoc); if (cond.good()) { return cond; } } Destroy(); return cond; }
void FindAssociation::OnAddPresentationContext(T_ASC_Parameters* params) { OFCondition cond = ASC_addPresentationContext(params, 1, m_abstractSyntax.c_str(), AllTransferSyntaxes, 3); if (cond.bad()) { LOG_ERROR(ambitolog, "Unable to add default presentation context"); } }
OFCondition Network::addAllStoragePresentationContexts(T_ASC_Parameters *params, bool bProposeCompression, int lossy) { OFCondition cond = EC_Normal; int i; int pid = 1; /* ** We prefer to accept Explicitly encoded transfer syntaxes. ** If we are running on a Little Endian machine we prefer ** LittleEndianExplicitTransferSyntax to BigEndianTransferSyntax. ** Some SCP implementations will just select the first transfer ** syntax they support (this is not part of the standard) so ** organise the proposed transfer syntaxes to take advantage ** of such behaviour. */ const char** transferSyntaxes; int transferSyntaxes_count; const char* const_transferSyntaxes[] = {UID_JPEGProcess14SV1TransferSyntax, NULL, NULL, UID_LittleEndianImplicitTransferSyntax }; if(bProposeCompression) { if(lossy == 8) { const_transferSyntaxes[0] = UID_JPEGProcess1TransferSyntax; } if(lossy == 12) { const_transferSyntaxes[0] = UID_JPEGProcess2_4TransferSyntax; } } /* gLocalByteOrder is defined in dcxfer.h */ if (gLocalByteOrder == EBO_LittleEndian) { /* we are on a little endian machine */ const_transferSyntaxes[1] = UID_LittleEndianExplicitTransferSyntax; const_transferSyntaxes[2] = UID_BigEndianExplicitTransferSyntax; } else { /* we are on a big endian machine */ const_transferSyntaxes[1] = UID_BigEndianExplicitTransferSyntax; const_transferSyntaxes[2] = UID_LittleEndianExplicitTransferSyntax; } if(bProposeCompression) { transferSyntaxes = &const_transferSyntaxes[0]; transferSyntaxes_count = DIM_OF(const_transferSyntaxes); } else { transferSyntaxes = &const_transferSyntaxes[1]; transferSyntaxes_count = DIM_OF(const_transferSyntaxes)-1; } /* the array of Storage SOP Class UIDs comes from dcuid.h */ for (i=0; i<numberOfAllDcmStorageSOPClassUIDs && cond.good(); i++) { cond = ASC_addPresentationContext(params, pid, dcmAllStorageSOPClassUIDs[i], transferSyntaxes, transferSyntaxes_count); pid += 2; /* only odd presentation context id's */ } return cond; }
OFCondition RetrieveDICOMFilesFromPACS::acceptSubAssociation(T_ASC_Network *associationNetwork, T_ASC_Association **association) { const char *knownAbstractSyntaxes[] = { UID_VerificationSOPClass }; const char *transferSyntaxes[] = { NULL, NULL, NULL, NULL }; int numTransferSyntaxes; OFCondition condition = ASC_receiveAssociation(associationNetwork, association, ASC_DEFAULTMAXPDU); if (condition.good()) { #ifndef DISABLE_COMPRESSION_EXTENSION // Si disposem de compressió la demanem, i podrem accelerar el temps de descàrrega considerablement // De moment demanem la compressió lossless que tot PACS que suporti compressió ha // de proporcionar: JPEGLossless:Non-Hierarchical-1stOrderPrediction transferSyntaxes[0] = UID_JPEGProcess14SV1TransferSyntax; transferSyntaxes[1] = UID_LittleEndianExplicitTransferSyntax; transferSyntaxes[2] = UID_BigEndianExplicitTransferSyntax; transferSyntaxes[3] = UID_LittleEndianImplicitTransferSyntax; numTransferSyntaxes = 4; #else // Defined in dcxfer.h if (gLocalByteOrder == EBO_LittleEndian) { transferSyntaxes[0] = UID_LittleEndianExplicitTransferSyntax; transferSyntaxes[1] = UID_BigEndianExplicitTransferSyntax; } else { transferSyntaxes[0] = UID_BigEndianExplicitTransferSyntax; transferSyntaxes[1] = UID_LittleEndianExplicitTransferSyntax; } transferSyntaxes[2] = UID_LittleEndianImplicitTransferSyntax; numTransferSyntaxes = 3; #endif // Accept the Verification SOP Class if presented condition = ASC_acceptContextsWithPreferredTransferSyntaxes((*association)->params, knownAbstractSyntaxes, DIM_OF(knownAbstractSyntaxes), transferSyntaxes, numTransferSyntaxes); if (condition.good()) { // The array of Storage SOP Class UIDs comes from dcuid.h condition = ASC_acceptContextsWithPreferredTransferSyntaxes((*association)->params, dcmAllStorageSOPClassUIDs, numberOfAllDcmStorageSOPClassUIDs, transferSyntaxes, numTransferSyntaxes); } } if (condition.good()) { condition = ASC_acknowledgeAssociation(*association); } else { ASC_dropAssociation(*association); ASC_destroyAssociation(association); } return condition; }
BOOST_FIXTURE_TEST_CASE(SetEmpty, Fixture) { odil::dcmtk::ElementAccessor<std::string>::set(this->dataset, DCM_PatientName, "FOO"); OFString value; OFCondition const condition = this->dataset.findAndGetOFString(DCM_PatientName, value); BOOST_REQUIRE(condition.good()); BOOST_CHECK_EQUAL(std::string(value.c_str()), "FOO"); }
bool ctkDICOMDataset::CheckCondition(const OFCondition& condition) { if ( condition.bad() ) { //std::cerr << "Bad return code (" << condition.code() << "): " << condition.text() << std::endl; } return condition.good(); }
Examen* ParserDicom::loadFile(string dirName) { // Open directory DIR* dir = opendir(dirName.c_str()); if (dir == NULL) { return NULL; } // Get examen informations ExamenParams* params = getInfos(dir, dirName); if (params == NULL) { return NULL; } // Create struct examen Volume* img = new Volume(params->width, params->height, params->depth); Examen* exam = new Examen(img, params); // Read data int index = 0; struct dirent* file; rewinddir(dir); string pathDirectory = dirName + PATH_SEPARATOR; int tabSize = params->width * params->height; float tab[tabSize]; while ((file = readdir(dir)) != NULL) { if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0) { string fullpath = pathDirectory + file->d_name; DcmFileFormat dcm; OFCondition cond = dcm.loadFile(fullpath.c_str()); if (cond.bad()) { delete img; delete params; return NULL; } DiDocument* didoc = new DiDocument(fullpath.c_str()); DiMono2Image* dimg = new DiMono2Image(didoc, EIS_Normal); OFString s; dcm.getDataset()->findAndGetOFString(DCM_BitsStored, s); int bitsStored = atoi(s.c_str()); short* slice = (short*) dimg->getOutputData(0, bitsStored, 0); for(int i=0; i<tabSize; ++i) { tab[i] = (float) slice[i]; } img->setSlice(tab, index++); delete dimg; delete didoc; } } closedir(dir); return exam; }
void ctkDICOMDataset::Deserialize() { Q_D(ctkDICOMDataset); // read attribute m_ctkDICOMDataset // construct a DcmDataset from it // calls InitializeData(DcmDataset*) // this method can be called both from sub-classes when they get the InitializeData signal from the persistence framework // and from EnsureDcmDataSetIsInitialized() when a GetElement.. or SetElement.. method is called. if (d->m_DICOMDataSetInitialized) return; // only need to do this once QString stringbuffer = this->GetStoredSerialization(); if ( stringbuffer.isEmpty() ) { d->m_DICOMDataSetInitialized = true; return; // TODO nicer: hold three states: newly created / loaded but not initialized / restored from DB } //std::cerr << "** " << (void*)this << " ctkDICOMDataset: Deserialize Dataset from string of size " << stringbuffer.size() << "\n" << stringbuffer.toStdString() << std::endl; QByteArray qtArray = QByteArray::fromBase64( stringbuffer.toAscii() ); //std::cerr << "** " << (void*)this << " ctkDICOMDataset: Deserialize Dataset from byte array of size " << qtArray.size() << std::endl; DcmInputBufferStream dcmbuffer; dcmbuffer.setBuffer( qtArray.data(), qtArray.size() ); //std::cerr << "** Buffer state: " << dcmbuffer.status().code() << " " << dcmbuffer.good() << " " << dcmbuffer.eos() << " tell " << dcmbuffer.tell() << " avail " << dcmbuffer.avail() << std::endl; DcmDataset dataset; dataset.transferInit(); //std::cerr << "** Dataset state: " << dataset.transferState() << std::endl << std::endl; OFCondition condition = dataset.read( dcmbuffer, EXS_LittleEndianImplicit ); dataset.transferEnd(); // do this in all cases, even when reading reported an error this->InitializeFromDataset(&dataset); if ( condition.bad() ) { std::cerr << "** Condition code of Dataset::read() is " << condition.code() << std::endl; std::cerr << "** Buffer state: " << dcmbuffer.status().code() << " " << dcmbuffer.good() << " " << dcmbuffer.eos() << " tell " << dcmbuffer.tell() << " avail " << dcmbuffer.avail() << std::endl; std::cerr << "** Dataset state: " << static_cast<int>(dataset.transferState()) << std::endl; std::cerr << "Could not DcmDataset::read(..): " << condition.text() << std::endl; //throw std::invalid_argument( std::string("Could not DcmDataset::read(..): ") + condition.text() ); } }
mitk::DataNode::Pointer RTDoseReader:: LoadRTDose(const char* filename) { DcmFileFormat fileformat; OFCondition outp = fileformat.loadFile(filename, EXS_Unknown); if(outp.bad()) { MITK_ERROR << "Cant read the file" << std::endl; } DcmDataset *dataset = fileformat.getDataset(); std::string name = filename; itk::FilenamesContainer file; file.push_back(name); mitk::DicomSeriesReader* reader = new mitk::DicomSeriesReader; mitk::DataNode::Pointer originalNode = reader->LoadDicomSeries(file,false); if(originalNode.IsNull()) { MITK_ERROR << "Error reading the dcm file" << std::endl; return 0; } mitk::Image::Pointer originalImage = dynamic_cast<mitk::Image*>(originalNode->GetData()); DRTDoseIOD doseObject; OFCondition result = doseObject.read(*dataset); if(result.bad()) { MITK_ERROR << "Error reading the Dataset" << std::endl; return 0; } OFString gridScaling; Float32 gridscale; doseObject.getDoseGridScaling(gridScaling); gridscale = OFStandard::atof(gridScaling.c_str()); AccessByItk_1(originalImage, MultiplayGridScaling, gridscale); double prescripeDose = this->GetMaxDoseValue(dataset); originalNode->SetName("RT Dose"); originalNode->SetFloatProperty(mitk::Constants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(),prescripeDose); originalNode->SetFloatProperty(mitk::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), 40); originalNode->SetBoolProperty(mitk::Constants::DOSE_PROPERTY_NAME.c_str(),true); return originalNode; }
OFCondition RetrieveDICOMFilesFromPACS::echoSCP(T_ASC_Association *association, T_DIMSE_Message *dimseMessage, T_ASC_PresentationContextID presentationContextID) { // The echo succeeded OFCondition condition = DIMSE_sendEchoResponse(association, presentationContextID, &dimseMessage->msg.CEchoRQ, STATUS_Success, NULL); if (condition.bad()) { ERROR_LOG("El PACS ens ha sol.licitat un echo durant la descarrega pero la resposta a aquest ha fallat"); } return condition; }
int main(void) { DcmFileFormat fileformat; OFCondition oc = fileformat.loadFile("D:\\021A3C1C.dcm"); if(oc.good()) { OFString patientName; if(fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good()) { std::cout<<"Patient Name:"<<patientName<<std::endl; } } return 0; }
bool CDicomHeader::LoadFromFile(const char *fileName) { OFCondition status = iDicomFile->loadFile(fileName); if ( status.good() ) { iDcmFileFormatLoaded=true; return true; } iDcmFileFormatLoaded=false; return false; }
OFCondition EchoScp( T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID) { OFString temp_str; LOG(INFO) << "Received Echo Request"; //LOG(DEBUG) << DIMSE_dumpMessage(temp_str, msg->msg.CEchoRQ, DIMSE_INCOMING, NULL, presID)); /* the echo succeeded !! */ OFCondition cond = DIMSE_sendEchoResponse(assoc, presID, &msg->msg.CEchoRQ, STATUS_Success, NULL); if (cond.bad()) { LOG(ERROR) << "Echo SCP Failed: " << cond.text(); } return cond; }