Skip to content

Commit

Permalink
u8string for filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyeh committed Jul 25, 2024
1 parent f9cc774 commit 6b0b38b
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions SliceModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool CustomSliceModel::load_slices(const std::vector<std::string>& files,bool is
name = QFileInfo(files[0].c_str()).completeBaseName().remove(".nii").toStdString();
to_dif.identity();
to_slice.identity();
tipl::progress prog("open ",std::filesystem::path(files[0]).filename().string().c_str());
tipl::progress prog("open ",std::filesystem::path(files[0]).filename().u8string().c_str());
// picture as slice
if(QFileInfo(files[0].c_str()).suffix() == "bmp" ||
QFileInfo(files[0].c_str()).suffix() == "jpg" ||
Expand Down Expand Up @@ -360,7 +360,7 @@ bool CustomSliceModel::load_slices(const std::vector<std::string>& files,bool is
{
if(QFileInfo(files[0].c_str()).fileName().toLower().contains("mni"))
{
tipl::out() << std::filesystem::path(files[0]).filename().string() <<
tipl::out() << std::filesystem::path(files[0]).filename().u8string() <<
" has 'mni' in the file name and has a different image size from DWI. It will be spatially normalized from template space to native space." << std::endl;
is_mni = true;
}
Expand Down
6 changes: 3 additions & 3 deletions auto_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ auto_track::auto_track(QWidget *parent) :
// populate tractography atlas list
ui->template_list->clear();
for(const auto& each : fa_template_list)
ui->template_list->addItem(tipl::split(std::filesystem::path(each).filename().string(),'.').front().c_str());
ui->template_list->addItem(tipl::split(std::filesystem::path(each).filename().u8string(),'.').front().c_str());
ui->template_list->setCurrentIndex(0);
timer = std::make_shared<QTimer>(this);
timer->stop();
Expand Down Expand Up @@ -206,7 +206,7 @@ std::string run_auto_track(tipl::program_option<tipl::out>& po,const std::vector
{
prog = int(i);
std::string fib_file_name = file_list[i];
std::string cur_file_base_name = std::filesystem::path(fib_file_name).filename().string();
std::string cur_file_base_name = std::filesystem::path(fib_file_name).filename().u8string();
scan_names.push_back(cur_file_base_name);
tipl::out() << "processing " << cur_file_base_name << std::endl;
std::shared_ptr<fib_data> handle;
Expand Down Expand Up @@ -470,7 +470,7 @@ std::string run_auto_track(tipl::program_option<tipl::out>& po,const std::vector
if(lines.size() < metrics_names.size())
{
std::string error("inconsistent stat file (remove it and rerun): ");
error += std::filesystem::path(stat_files[t][s]).filename().string();
error += std::filesystem::path(stat_files[t][s]).filename().u8string();
error += " metrics count: ";
error += std::to_string(lines.size());
error += " others: ";
Expand Down
4 changes: 2 additions & 2 deletions cmd/ana.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int ana_region(tipl::program_option<tipl::out>& po,std::shared_ptr<fib_data> han
{
std::string output = po.get("output");
if(QFileInfo(output.c_str()).isDir())
file_name = output + std::string("/") + std::filesystem::path(file_name).filename().string();
file_name = output + std::string("/") + std::filesystem::path(file_name).filename().u8string();
else
file_name = output;
if(file_name.find(".txt") == std::string::npos)
Expand Down Expand Up @@ -209,7 +209,7 @@ int ana_tract(tipl::program_option<tipl::out>& po,std::shared_ptr<fib_data> hand
tracts.push_back(std::make_shared<TractModel>(handle));
if(!load_tracts(tract_files[i].c_str(),handle,tracts.back(),roi_mgr))
return 1;
tract_name.push_back(std::filesystem::path(tract_files[i]).filename().string());
tract_name.push_back(std::filesystem::path(tract_files[i]).filename().u8string());
}
tipl::out() << "a total of " << tract_files.size() << " tract file(s) loaded" << std::endl;

Expand Down
2 changes: 1 addition & 1 deletion cmd/img.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool variant_image::load_from_file(const char* file_name,std::string& info)
tipl::io::dicom dicom;
is_mni = false;
T.identity();
tipl::progress prog("open image file ",std::filesystem::path(file_name).filename().string().c_str());
tipl::progress prog("open image file ",std::filesystem::path(file_name).filename().u8string().c_str());
if(QString(file_name).endsWith(".nhdr"))
{
tipl::io::nrrd<tipl::progress> nrrd;
Expand Down
2 changes: 1 addition & 1 deletion cmd/rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ int rec(tipl::program_option<tipl::out>& po)
{
std::string output = po.get("output");
if(QFileInfo(output.c_str()).isDir())
src.file_name = output + "/" + std::filesystem::path(src.file_name).filename().string();
src.file_name = output + "/" + std::filesystem::path(src.file_name).filename().u8string();
else
src.file_name = output;
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/reg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool dual_reg<3>::apply_warping(const char* from,const char* to) const
}
if(I[0].shape() != I_list[0].shape())
{
error_msg = std::filesystem::path(from).filename().string();
error_msg = std::filesystem::path(from).filename().u8string();
error_msg += " has an image size or srow matrix from that of the original --from image.";
return false;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ bool dual_reg<3>::apply_warping(const char* from,const char* to) const
if(I[0].shape() != I3.shape())
{
tipl::out() << "--from dim: " << I[0].shape();
error_msg = std::filesystem::path(from).filename().string();
error_msg = std::filesystem::path(from).filename().u8string();
error_msg += " has an image size or srow matrix from that of the original --from image.";
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/ren.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ void dicom2src_and_nii(std::string dir_);
int ren(tipl::program_option<tipl::out>& po)
{
tipl::progress prog("run ren");
auto source = std::filesystem::path(po.get("source")).string();
auto output = std::filesystem::path(po.get("output",po.get("source"))).string();
auto source = std::filesystem::path(po.get("source")).u8string();
auto output = std::filesystem::path(po.get("output",po.get("source"))).u8string();
auto subject_dir = rename_dicom_at_dir(source.c_str(),output.c_str());
if(po.get("to_src_nii",0))
{
Expand Down
10 changes: 5 additions & 5 deletions cmd/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool handle_bids_folder(const std::vector<std::string>& dwi_nii_files,
phase_dir.push_back(phase_str);

dwi_file.push_back(each);
tipl::out() << std::filesystem::path(dwi_file.back()).filename().string();
tipl::out() << std::filesystem::path(dwi_file.back()).filename().u8string();
tipl::out() << "image size: " << image_size.back();
tipl::out() << "dwi count: " << dwi_count.back();
tipl::out() << "phase encoding: " << phase_dir.back();
Expand Down Expand Up @@ -180,8 +180,8 @@ bool handle_bids_folder(const std::vector<std::string>& dwi_nii_files,
}
image_size[i] = tipl::shape<3>();
dwi_file[i].erase(dwi_file[i].length() - 7, 7); // remove .nii.gz
auto src_name = output_dir + "/" + std::filesystem::path(dwi_file[i]).filename().string() + ".src.gz";
auto rsrc_name = output_dir + "/" + std::filesystem::path(dwi_file[i]).filename().string() + ".rsrc.gz";
auto src_name = output_dir + "/" + std::filesystem::path(dwi_file[i]).filename().u8string() + ".src.gz";
auto rsrc_name = output_dir + "/" + std::filesystem::path(dwi_file[i]).filename().u8string() + ".rsrc.gz";
if(!overwrite && std::filesystem::exists(src_name))
tipl::out() << "skipping " << src_name << " already exists";
else
Expand Down Expand Up @@ -227,7 +227,7 @@ bool nii2src(const std::vector<std::string>& dwi_nii_files,
}
else
{
auto src_name = output_dir + "/" + std::filesystem::path(dwi_nii_files[i]).filename().string() + ".src.gz";
auto src_name = output_dir + "/" + std::filesystem::path(dwi_nii_files[i]).filename().u8string() + ".src.gz";
if(!overwrite && std::filesystem::exists(src_name))
tipl::out() << "skipping " << src_name << " already exists";
else
Expand Down Expand Up @@ -372,7 +372,7 @@ int src(tipl::program_option<tipl::out>& po)
auto output = po.get("output",file_list.front() + ".src.gz");

if(std::filesystem::is_directory(output))
output += std::string("/") + std::filesystem::path(file_list[0]).filename().string() + ".src.gz";
output += std::string("/") + std::filesystem::path(file_list[0]).filename().u8string() + ".src.gz";
if(!tipl::ends_with(output,".src.gz"))
output += ".src.gz";

Expand Down
2 changes: 1 addition & 1 deletion cmd/trk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ void set_template(std::shared_ptr<fib_data> handle,tipl::program_option<tipl::ou
if(po.has("template"))
{
for(size_t id = 0;id < fa_template_list.size();++id)
tipl::out() << "template " << id << ": " << tipl::split(std::filesystem::path(fa_template_list[id]).filename().string(),'.').front() << std::endl;
tipl::out() << "template " << id << ": " << tipl::split(std::filesystem::path(fa_template_list[id]).filename().u8string(),'.').front() << std::endl;
handle->set_template_id(po.get("template",size_t(0)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion connectometry/db_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void db_window::on_actionSave_DB_as_triggered()
"Database files (*db?fib.gz *fib.gz);;All files (*)");
if (filename.isEmpty())
return;
tipl::progress prog_("saving ",std::filesystem::path(filename.toStdString()).filename().string().c_str());
tipl::progress prog_("saving ",std::filesystem::path(filename.toStdString()).filename().u8string().c_str());
if(!vbc->handle->db.demo.empty() && !vbc->handle->db.parse_demo())
QMessageBox::information(this,QApplication::applicationName(),
QString("demographics not saved due to mismatch: ") + vbc->handle->db.error_msg.c_str());
Expand Down
14 changes: 7 additions & 7 deletions connectometry/group_connectometry_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ void group_connectometry_analysis::generate_report(std::string& output)
{
if(fdr.empty())
return;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+"."+name+"_map.jpg").filename().string() << "\" width=\"600\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+"."+name+"_map2.jpg").filename().string() << "\" width=\"600\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+"."+name+".jpg").filename().string() << "\" width=\"1200\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+"."+name+"_map.jpg").filename().u8string() << "\" width=\"600\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+"."+name+"_map2.jpg").filename().u8string() << "\" width=\"600\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+"."+name+".jpg").filename().u8string() << "\" width=\"1200\"/>" << std::endl;
html_report << "<p><b>Fig.</b> Tracks with " << hypo << " " << fdr << "</p>" << std::endl;
};
auto report_fdr = [&](bool sig,std::string hypo,std::string result){
Expand Down Expand Up @@ -687,7 +687,7 @@ void group_connectometry_analysis::generate_report(std::string& output)
{
if(fdr_inc[length_threshold_voxels] < 0.2f || fdr_dec[length_threshold_voxels] < 0.2f)
{
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".pos_neg.jpg").filename().string() << "\" width=\"1200\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".pos_neg.jpg").filename().u8string() << "\" width=\"1200\"/>" << std::endl;
html_report << "<p><b>Fig.</b> Correlational tractography showing " << hypothesis_inc << " (red)" << fdr_result_pos
<< " and " << hypothesis_dec << " (blue)" << fdr_result_neg << ".</p>" << std::endl;
}
Expand All @@ -701,15 +701,15 @@ void group_connectometry_analysis::generate_report(std::string& output)

html_report << "<h3>False discovery rate analysis</h3>" << std::endl;

html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".inc.dist.jpg").filename().string() << "\" width=\"320\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".inc.dist.jpg").filename().u8string() << "\" width=\"320\"/>" << std::endl;
html_report << "<p><b>Fig.</b> Permutation test showing the histograms of track counts with "<< hypothesis_inc << ".</p>";


html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".dec.dist.jpg").filename().string() << "\" width=\"320\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".dec.dist.jpg").filename().u8string() << "\" width=\"320\"/>" << std::endl;
html_report << "<p><b>Fig.</b> Permutation test showing the histograms of track counts with "<< hypothesis_dec << ".</p>";

html_report << permutation_explained << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".fdr.jpg").filename().string() << "\" width=\"320\"/>" << std::endl;
html_report << "<p></p><img src = \""<< std::filesystem::path(output_file_name+".fdr.jpg").filename().u8string() << "\" width=\"320\"/>" << std::endl;
html_report << "<p><b>Fig.</b> The False discovery rate (FDR) at different track length </p>";
}

Expand Down
2 changes: 1 addition & 1 deletion dicom/dicom_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ std::vector<QStringList> split_by_path(const QStringList &files)
bool parse_dwi(QStringList file_list,
std::vector<std::shared_ptr<DwiHeader> >& dwi_files)
{
tipl::progress prog("opening ",std::filesystem::path(file_list[0].toStdString()).stem().string().c_str());
tipl::progress prog("opening ",std::filesystem::path(file_list[0].toStdString()).stem().u8string().c_str());
if(QFileInfo(file_list.front()).absolutePath() != QFileInfo(file_list.back()).absolutePath())
{
auto dwi_groups = split_by_path(file_list);
Expand Down
22 changes: 11 additions & 11 deletions libs/dsi/image_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ bool src_data::command(std::string cmd,std::string param)
error_msg = " please assign file name ";
return false;
}
tipl::progress prog_("saving ",std::filesystem::path(param).filename().string().c_str());
tipl::progress prog_("saving ",std::filesystem::path(param).filename().u8string().c_str());
return save_to_file(param.c_str());
}
if(cmd == "[Step T2a][Open]")
Expand Down Expand Up @@ -1989,13 +1989,13 @@ bool src_data::run_eddy(std::string exec)
}

std::vector<std::string> param = {
std::string("--imain=") + std::filesystem::path(temp_nifti).filename().string(),
std::string("--mask=") + std::filesystem::path(mask_nifti).filename().string(),
std::string("--imain=") + std::filesystem::path(temp_nifti).filename().u8string(),
std::string("--mask=") + std::filesystem::path(mask_nifti).filename().u8string(),
std::string("--acqp=") + acqparam_file,
std::string("--index=") + std::filesystem::path(index_file.c_str()).filename().string(),
std::string("--bvecs=") + std::filesystem::path(bvec_file.c_str()).filename().string(),
std::string("--bvals=") + std::filesystem::path(bval_file.c_str()).filename().string(),
std::string("--out=") + std::filesystem::path(corrected_file.c_str()).filename().string(),
std::string("--index=") + std::filesystem::path(index_file.c_str()).filename().u8string(),
std::string("--bvecs=") + std::filesystem::path(bvec_file.c_str()).filename().u8string(),
std::string("--bvals=") + std::filesystem::path(bval_file.c_str()).filename().u8string(),
std::string("--out=") + std::filesystem::path(corrected_file.c_str()).filename().u8string(),
"--verbose=1"
};
if(has_topup)
Expand Down Expand Up @@ -2244,7 +2244,7 @@ void src_data::get_report(std::string& report)
}
bool src_data::save_to_file(const char* dwi_file_name)
{
tipl::progress prog_("saving ",std::filesystem::path(dwi_file_name).filename().string().c_str());
tipl::progress prog_("saving ",std::filesystem::path(dwi_file_name).filename().u8string().c_str());
std::string filename(dwi_file_name);
if(!tipl::ends_with(filename,".gz"))
filename += ".gz";
Expand Down Expand Up @@ -2347,19 +2347,19 @@ void save_idx(const char* file_name,std::shared_ptr<tipl::io::gz_istream> in)
idx_name += ".idx";
if(in->has_access_points() && in->sample_access_point && !std::filesystem::exists(idx_name))
{
tipl::out() << "saving index file for accelerated loading: " << std::filesystem::path(idx_name).filename().string() << std::endl;
tipl::out() << "saving index file for accelerated loading: " << std::filesystem::path(idx_name).filename().u8string() << std::endl;
in->save_index(idx_name.c_str());
}
}
size_t match_volume(float volume);
QImage read_qimage(QString filename,std::string& error);
bool src_data::load_from_file(const char* dwi_file_name)
{
tipl::progress prog("open SRC file ",std::filesystem::path(dwi_file_name).filename().string().c_str());
tipl::progress prog("open SRC file ",std::filesystem::path(dwi_file_name).filename().u8string().c_str());
if(voxel.steps.empty())
{
voxel.steps = "[Step T2][Reconstruction] open ";
voxel.steps += std::filesystem::path(dwi_file_name).filename().string();
voxel.steps += std::filesystem::path(dwi_file_name).filename().u8string();
voxel.steps += "\n";
}

Expand Down
4 changes: 2 additions & 2 deletions libs/tracking/fib_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void prepare_idx(const char* file_name,std::shared_ptr<tipl::io::gz_istream> in)
void save_idx(const char* file_name,std::shared_ptr<tipl::io::gz_istream> in);
bool fib_data::load_from_file(const char* file_name)
{
tipl::progress prog("opening ",std::filesystem::path(file_name).filename().string().c_str());
tipl::progress prog("opening ",std::filesystem::path(file_name).filename().u8string().c_str());
tipl::image<3> I;
tipl::io::gz_nifti header;
fib_file_name = file_name;
Expand Down Expand Up @@ -994,7 +994,7 @@ void fib_data::match_template(void)
tipl::out() << "image volume smaller than human young adult. try matching a template...";
set_template_id(match_volume(std::count_if(dir.fa[0],dir.fa[0]+dim.size(),[](float v){return v > 0.0f;})*2.0f*vs[0]*vs[1]*vs[2]));
}
tipl::out() << "matched template: " << tipl::split(std::filesystem::path(fa_template_list[template_id]).filename().string(),'.').front();
tipl::out() << "matched template: " << tipl::split(std::filesystem::path(fa_template_list[template_id]).filename().u8string(),'.').front();
}

const tipl::image<3,tipl::vector<3,float> >& fib_data::get_native_position(void) const
Expand Down
Loading

0 comments on commit 6b0b38b

Please sign in to comment.