#include "DicomScanService.h" /*_________________________________________________________- Patient loader for gLocalize. no wrkDir behaviour. just load data ____________________________________________________________*/ DicomScanService::DicomScanService(){ patientInfos = new gPatientRTGeneralInfos; readRT=0; m_rtIsocenter=0; initialized=false; virtualIso=false; //cout<< "DicomScanService::gLoadPatient" <parse(p_loadDir); if(patientInfos->CTfiles .size()!=0){ cout<< "this->load2VTK(patientInfos)" <rtIonPlanPath.isEmpty()){ readRT = new RTPlan; readRT->fillRTPlan(patientInfos->rtIonPlanPath.toLatin1().data() ); m_rtIsocenter = new double[3]; if (readRT->NumberOfBeams > 0){ { const auto& iso = readRT->Beams.at(0)->IsocenterPosition; m_rtIsocenter[0] = iso[0]; m_rtIsocenter[1] = iso[1]; m_rtIsocenter[2] = iso[2]; } if (readRT->PatientOrientation.rfind("HFS", 0) == 0) m_patientOrientation = SUPINE; else if (readRT->PatientOrientation.rfind("HFP", 0) == 0) m_patientOrientation = PRONE; else m_patientOrientation = NOTDEFINED; if (callbacks.loadedRTIso) callbacks.loadedRTIso(m_rtIsocenter); //for (int ii=0;iiNumberOfBeams; ii++){ // cout<< readRT->Beams[ii]->IsocenterPosition[0]<<" "; // cout<< readRT->Beams[ii]->IsocenterPosition[1]<<" "; // cout<< readRT->Beams[ii]->IsocenterPosition[2]<<" "<NumberOfBeams <Beams.at(0)->IsocenterPosition[0] <Beams.at(2)->IsocenterPosition[0]<Beams.at(0)->IsocenterPosition[1] <Beams.at(2)->IsocenterPosition[1]<Beams.at(0)->IsocenterPosition[2] <Beams.at(2)->IsocenterPosition[2]<NumberOfBeams > 2 && (readRT->Beams.at(0)->IsocenterPosition[0] != readRT->Beams.at(2)->IsocenterPosition[0] || readRT->Beams.at(0)->IsocenterPosition[1] != readRT->Beams.at(2)->IsocenterPosition[1] || readRT->Beams.at(0)->IsocenterPosition[2] != readRT->Beams.at(2)->IsocenterPosition[2]) ) virtualIso=true; else virtualIso=false; //cout << "virtual Iso: "<loadDICOM(patientInfos->CTfiles); this->connectToVTK(); // this->changeRef(GOTSREF); /* use DCM as default */ this->changeRef(DCMREF); //trueOffset_rot_prev=trueOffset_rot; //this->load2VTK(patientInfos); } else { //DO NOTHING. THE folderisempty signal was already emitted. } cout<< " DicomScanService::load _ END" <SetDirection( /*imageDir*/directionToWCS ); myImage->SetOrigin( trueOffset_rot ); myImage->Update(); in->SetInput(myImage); this->connectToVTK(); this->actualizeOut(); /*calculate deltas for marker representation update*/ if(initialized){ if (callbacks.referenceChange) callbacks.referenceChange( trueOffset_rot_prev[0]-trueOffset_rot[0], trueOffset_rot_prev[1]-trueOffset_rot[1], trueOffset_rot_prev[2]-trueOffset_rot[2]); trueOffset_rot_prev=trueOffset_rot; } else { trueOffset_rot_prev=trueOffset_rot; initialized=true; } } void DicomScanService::loadDICOM(std::vector CTfilenames){ myImage = myImageType::New(); rDICOM = itk::ImageSeriesReader::New(); iGDCMimage = itk::GDCMImageIO::New(); myDICOMseries = itk::GDCMSeriesFileNames::New(); rDICOM->SetImageIO(iGDCMimage); rDICOM->SetFileNames(CTfilenames); // rDICOM->SetReverseOrder(true); try{ rDICOM->Update(); } catch (itk::ExceptionObject &ex){ std::cout << ex << std::endl; return; // error! } myImage=rDICOM->GetOutput(); imageDir = myImage->GetDirection( ); origin = myImage->GetOrigin( ); sizeOfImage = myImage->GetLargestPossibleRegion().GetSize(); } void DicomScanService::connectToVTK(){ out = vtkSmartPointer::New(); in = itk::VTKImageExport ::New(); in->SetInput(myImage); out->SetUpdateInformationCallback(in->GetUpdateInformationCallback()); out->SetPipelineModifiedCallback(in->GetPipelineModifiedCallback()); out->SetWholeExtentCallback(in->GetWholeExtentCallback()); out->SetSpacingCallback(in->GetSpacingCallback()); out->SetOriginCallback(in->GetOriginCallback()); out->SetScalarTypeCallback(in->GetScalarTypeCallback()); out->SetNumberOfComponentsCallback(in->GetNumberOfComponentsCallback()); out->SetPropagateUpdateExtentCallback(in->GetPropagateUpdateExtentCallback()); out->SetUpdateDataCallback(in->GetUpdateDataCallback()); out->SetDataExtentCallback(in->GetDataExtentCallback()); out->SetBufferPointerCallback(in->GetBufferPointerCallback()); out->SetCallbackUserData(in->GetCallbackUserData()); } void DicomScanService::actualizeOut(){ //in->Update(); out->Update(); //vol3D = vtkSmartPointer ::New(); //vol3D->DeepCopy(out->GetOutput()); //vol3D->Update(); vol3D = out->GetOutput(); cout<GetSpacing()[0] <<" "<GetSpacing()[1] <<" "<GetSpacing()[2] <clearInfo() " <clearInfo(); std::cout<<"parsing dir: "<c_str()).fileName().split(".").last() != QString("raw") ) patientInfos->filenames.push_back( it->c_str() ); } patientInfos->filenames.size() == 0 ? result = PARSER_FOLDER_EMPTY : result = NOERRORS; } else { result=PARSER_FOLDER_NOTEXISTING; }; cout << " patientInfos->filenames.size() "<filenames.size() <filenames.size()-1);i>-1;i--) { //cout << gCheckDICOMModalityToInt(patientInfos->filenames.at(i).c_str()) <SetFileName (patientInfos->filenames.at(i).c_str()); if( !fileReader->Read() ) { cout<< "Error reading file: "<< patientInfos->filenames.at(i).data() <filenames.erase(patientInfos->filenames.begin()+i); continue; } //msStructRTIonPlan.SetFromFile( fileReader->GetFile() ); //if( msStructRTIonPlan == gdcm::MediaStorage::RTIonPlanStorage ) if( gCheckDICOMModalityToInt(patientInfos->filenames.at(i).c_str()) == RTPLAN ) { if(!patientInfos->rtIonPlanPath.isEmpty()) { // result=PARSER_RTPLAN_NOTUNIQUE; continue; } else { const gdcm::File &file = fileReader->GetFile(); const gdcm::DataSet &ds = file.GetDataSet(); //PATIENT NAME strcpy( patientInfos->PatientName,gGetStringValueFromTag( gdcm::Tag(0x0010,0x0010), ds)); // // // PATIENT ID For ex: DICOM (0010,0020) = 1933197 strcpy( patientInfos->PatientID , gGetStringValueFromTag( gdcm::Tag(0x0010,0x0020), ds)); // // // PATIENT AGE For ex: DICOM (0010,1010) = 031Y strcpy( patientInfos->PatientAge , gGetStringValueFromTag( gdcm::Tag(0x0010,0x1010), ds)) ; // // // PATIENT SEX For ex: DICOM (0010,0040) = M strcpy( patientInfos->PatientSex, gGetStringValueFromTag( gdcm::Tag(0x0010,0x0040), ds) ); // // // PATIENT BIRTHDATE For ex: DICOM (0010,0030) = 19680427 strcpy( patientInfos->PatientBirthDate, gGetStringValueFromTag( gdcm::Tag(0x0010,0x0030), ds) ); // // // SERIES NUMBER For ex: DICOM (0020,0011) = 902 strcpy( patientInfos->SeriesNumber, gGetStringValueFromTag( gdcm::Tag(0x0020,0x0011), ds) ); // // // SERIES DESCRIPTION For ex: DICOM (0008,103e) = SCOUT strcpy( patientInfos->SeriesDescription , gGetStringValueFromTag( gdcm::Tag(0x0008,0x103e), ds) ); // // // STUDY ID For ex: DICOM (0020,0010) = 37481 strcpy( patientInfos->StudyID, gGetStringValueFromTag( gdcm::Tag(0x0020,0x0010), ds) ); // // // STUDY DESCRIPTION For ex: DICOM (0008,1030) = BRAIN/C-SP/FACIAL strcpy( patientInfos->StudyDescription, gGetStringValueFromTag( gdcm::Tag(0x0008,0x1030), ds) ); const gdcm::DataElement &gSetupSequence=ds.GetDataElement(gdcm::Tag(0x300a,0x0180)); //LOOK FOR PATIENT ORIENTATION gdcm::SmartPointer sqiPS = gSetupSequence.GetValueAsSQ(); const gdcm::DataSet& gPatSetupNest = sqiPS->GetItem(1).GetNestedDataSet(); //SET PATIENT ORIENTATION STRING strcpy(patientInfos->PatientOrientation, gGetStringValueFromTag(gdcm::Tag(0x0018, 0x5100),gPatSetupNest)); patientInfos->rtIonPlanPath=QString(patientInfos->filenames.at(i).c_str()); cout<< "RTPlan import success" <filenames.erase(patientInfos->filenames.begin()+i); delete fileReader; continue; } } // msStructRTStruct.SetFromFile( fileReader->GetFile() ); // if( msStructRTStruct == gdcm::MediaStorage::RTStructureSetStorage ) { if( gCheckDICOMModalityToInt(patientInfos->filenames.at(i).c_str()) == RTSTRUCT ){ if(!patientInfos->rtStructurePath.isEmpty()) { patientInfos->rtStructurePath.clear(); // result=PARSER_RTSTRUCT_NOTUNIQUE; continue; } else { patientInfos->rtStructurePath=QString(patientInfos->filenames.at(i).c_str()); cout<< "RTStruct import success" <filenames.erase(patientInfos->filenames.begin()+i); delete fileReader; continue; } } delete fileReader; } //OK //if(result == NOERRORS && patientInfos->rtIonPlanPath.isEmpty() ) // result= PARSER_RTPLAN_MISSING; //if(result == NOERRORS && patientInfos->rtStructurePath.isEmpty()) // result=PARSER_RTSTRUCT_MISSING; s.SetComputeZSpacing( true ); s.SetZSpacingTolerance( 1e-2 ); if (result == NOERRORS) { if (!s.Sort(patientInfos->filenames)) { result = PARSER_CT_FAILED_SORTING; } else { s.GetFilenames().size() == 0 ? result = PARSER_CT_FILES_MISSING : result = NOERRORS; } } if(result == NOERRORS){ patientInfos->CTfiles=s.GetFilenames (); //cout<< "CT files sorting succeeded" <