Example #1
0
dicom_parser::dicom_parser(QStringList file_list,QWidget *parent) :
        QDialog(parent),
        ui(new Ui::dicom_parser)
{
    ui->setupUi(this);
    cur_path = QFileInfo(file_list[0]).absolutePath();
    std::sort(file_list.begin(),file_list.end(),compare_qstring());
    load_files(file_list);

    if (!dwi_files.empty())
    {
        ui->SrcName->setText(get_src_name(file_list[0]));
        image::io::dicom header;
        if (header.load_from_file(file_list[0].toLocal8Bit().begin()))
        {
            slice_orientation.resize(9);
            header.get_image_orientation(slice_orientation.begin());
        }
    }
}
Example #2
0
void MainWindow::on_batch_src_clicked()
{
    QString dir = QFileDialog::getExistingDirectory(
                                this,
                                "Open directory",
                                ui->workDir->currentText());
    if(dir.isEmpty())
        return;
    add_work_dir(dir);

    {
        QStringList dir_list;
        dir_list << dir;
        bool all = false;
        bool choice = false;
        begin_prog("batch creating src");
        for(unsigned int i = 0;check_prog(i,dir_list.size()) && !prog_aborted();++i)
        {
            QDir cur_dir = dir_list[i];
            QStringList new_list = cur_dir.entryList(QStringList(""),QDir::AllDirs|QDir::NoDotAndDotDot);
            for(unsigned int index = 0;index < new_list.size();++index)
                dir_list << cur_dir.absolutePath() + "/" + new_list[index];


            std::vector<std::shared_ptr<DwiHeader> > dwi_files;


            if(QFileInfo(dir_list[i] + "/data.nii.gz").exists() &&
               QFileInfo(dir_list[i] + "/bvals").exists() &&
               QFileInfo(dir_list[i] + "/bvecs").exists() &&
               load_4d_nii(QString(dir_list[i] + "/data.nii.gz").toLocal8Bit().begin(),dwi_files))
            {
                DwiHeader::output_src(QString(dir_list[i] + "/data.src.gz").toLocal8Bit().begin(),dwi_files,0);
                continue;
            }

            QStringList nifti_file_list = cur_dir.entryList(QStringList("*.nii.gz"),QDir::Files|QDir::NoSymLinks);
            for (unsigned int index = 0;index < nifti_file_list.size();++index)
            {
                if(QFileInfo(dir_list[i] + "/" + QFileInfo(nifti_file_list[index]).baseName()+".bval").exists() &&
                   QFileInfo(dir_list[i] + "/" + QFileInfo(nifti_file_list[index]).baseName()+".bvec").exists() &&
                    load_4d_nii(QString(dir_list[i] + "/" + nifti_file_list[index]).toLocal8Bit().begin(),dwi_files))
                {
                    DwiHeader::output_src(QString(dir_list[i] + "/" +
                        QFileInfo(nifti_file_list[index]).baseName() + ".src.gz").toLocal8Bit().begin(),dwi_files,0);
                    continue;
                }
            }

            QStringList dicom_file_list = cur_dir.entryList(QStringList("*.dcm"),QDir::Files|QDir::NoSymLinks);
            if(dicom_file_list.empty())
                continue;
            for (unsigned int index = 0;index < dicom_file_list.size();++index)
                dicom_file_list[index] = dir_list[i] + "/" + dicom_file_list[index];
            QString output = dir_list[i] + "/" + QFileInfo(get_src_name(dicom_file_list[0])).baseName()+".src.gz";
            if(QFileInfo(output).exists())
            {
                if(!all)
                {
                    QMessageBox msgBox;
                    msgBox.setText(QString("Existing SRC file ") + output);
                    msgBox.setInformativeText("Overwrite?");
                    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoAll);
                    msgBox.setDefaultButton(QMessageBox::Save);
                    switch(msgBox.exec())
                    {
                    case QMessageBox::YesToAll:
                        all = true;
                    case QMessageBox::Yes:
                        choice = true;
                        break;
                    case QMessageBox::NoAll:
                        all = true;
                    case QMessageBox::No:
                        choice = false;
                        break;
                    }
                }
                if(!choice)
                    continue;
            }
            if(!load_all_files(dicom_file_list,dwi_files) || prog_aborted())
                continue;
            if(dwi_files.size() == 1) //MPRAGE or T2W
            {
                std::sort(dicom_file_list.begin(),dicom_file_list.end(),compare_qstring());
                image::io::volume v;
                image::io::dicom header;
                std::vector<std::string> file_list;
                for(unsigned int index = 0;index < dicom_file_list.size();++index)
                    file_list.push_back(dicom_file_list[index].toLocal8Bit().begin());
                if(!v.load_from_files(file_list,file_list.size()) ||
                   !header.load_from_file(dicom_file_list[0].toLocal8Bit().begin()))
                    continue;
                image::basic_image<float,3> I;
                image::vector<3> vs;
                v >> I;
                v.get_voxel_size(vs.begin());
                gz_nifti nii_out;
                image::flip_xy(I);
                nii_out << I;
                nii_out.set_voxel_size(vs);


                std::string manu,make,seq,report;
                header.get_text(0x0008,0x0070,manu);//Manufacturer
                header.get_text(0x0008,0x1090,make);
                header.get_text(0x0018,0x1030,seq);
                std::replace(manu.begin(),manu.end(),' ',(char)0);
                make.erase(std::remove(make.begin(),make.end(),' '),make.end());
                std::ostringstream out;
                out << manu.c_str() << " " << make.c_str() << " " << seq
                    << ".TE=" << header.get_float(0x0018,0x0081) << ".TR=" << header.get_float(0x0018,0x0080)  << ".";
                report = out.str();
                std::copy(report.begin(),report.begin() + std::min<int>(80,report.length()+1),nii_out.nif_header.descrip);

                QString output_name = QFileInfo(get_src_name(dicom_file_list[0])).absolutePath() + "/" +
                                      QFileInfo(get_src_name(dicom_file_list[0])).baseName()+ "."+seq.c_str() + ".nii.gz";
                nii_out.save_to_file(output_name.toLocal8Bit().begin());
            }
            else
            {
                for(unsigned int index = 0;index < dwi_files.size();++index)
                    if(dwi_files[index]->get_bvalue() < 100)
                    {
                        dwi_files[index]->set_bvalue(0);
                        dwi_files[index]->set_bvec(0,0,0);
                    }
                DwiHeader::output_src(output.toLocal8Bit().begin(),dwi_files,0);
            }
        }