From 03486a0ea42fc3ec016d4510b72ef54835285af9 Mon Sep 17 00:00:00 2001 From: Saad Jbabdi <saad@fmrib.ox.ac.uk> Date: Thu, 5 Mar 2009 18:40:57 +0000 Subject: [PATCH] added possibility of saving seed-to-target counter as a text file --- probtrackxOptions.h | 6 +++++- streamlines.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ streamlines.h | 3 +++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/probtrackxOptions.h b/probtrackxOptions.h index 83ed8ab..fa2f5f7 100644 --- a/probtrackxOptions.h +++ b/probtrackxOptions.h @@ -66,7 +66,7 @@ class probtrackxOptions { Option<int> fibst; Option<bool> modeuler; Option<int> rseed; - + Option<bool> seedcountastext; void parse_command_line(int argc, char** argv,Log& logger); void modecheck(); @@ -206,6 +206,9 @@ class probtrackxOptions { rseed(string("--rseed"), 12345, string("Random seed"), false, requires_argument), + seedcountastext(string("--seedcountastext"), false, + string("Output seed-to-target counts as a text file"), + false, no_argument), options("probtrackx","probtrackx -s <basename> -m <maskname> -x <seedfile> -o <output> --targetmasks=<textfile>\n probtrackx --help\n") { @@ -249,6 +252,7 @@ class probtrackxOptions { options.add(fibst); options.add(modeuler); options.add(rseed); + options.add(seedcountastext); } catch(X_OptionError& e) { options.usage(); diff --git a/streamlines.cc b/streamlines.cc index ed69306..a0f71fb 100644 --- a/streamlines.cc +++ b/streamlines.cc @@ -299,6 +299,33 @@ namespace TRACT{ m_seedcounts.push_back(tmpint); //m_particle_numbers.push_back(tmpvec); } + + // where we save the seed counts in text files + if(opts.seedcountastext.value()){ + + int numseeds=0; + if(opts.meshfile.value()==""){ + for(int Wz=m_seeds.minz();Wz<=m_seeds.maxz();Wz++) + for(int Wy=m_seeds.miny();Wy<=m_seeds.maxy();Wy++) + for(int Wx=m_seeds.minx();Wx<=m_seeds.maxx();Wx++) + if(m_seeds.value(Wx,Wy,Wz)!=0) + numseeds++; + } + else{ + ifstream fs(opts.seedfile.value().c_str()); + if(fs){ + char buffer[1024]; + fs.getline(buffer,1024); + fs >>numseeds; + cout<<numseeds<<endl; + } + } + + m_SeedCountMat.ReSize(numseeds,m_targetmasknames.size()); + m_SeedCountMat=0; + m_SeedRow=1; + } + } @@ -426,6 +453,9 @@ namespace TRACT{ if(opts.matrix2out.value()){ next_matrix2_row(); } + if(opts.seedcountastext.value()){ + m_SeedRow++; + } } @@ -499,6 +529,10 @@ namespace TRACT{ m_seedcounts[m](xseedvox,yseedvox,zseedvox)=m_seedcounts[m](xseedvox,yseedvox,zseedvox)+1; m_targflags[m]=1; //m_particle_numbers[m].push_back(particle_number); + + if(opts.seedcountastext.value()) + m_SeedCountMat(m_SeedRow,m+1) += 1; + } } } @@ -515,6 +549,10 @@ namespace TRACT{ m_seedcounts[m](xseedvox,yseedvox,zseedvox)+=(int)d; m_targflags[m]=1; //m_particle_numbers[m].push_back(particle_number); + + if(opts.seedcountastext.value()) + m_SeedCountMat(m_SeedRow,m+1) += d; + } } @@ -678,6 +716,11 @@ namespace TRACT{ save_volume(m_seedcounts[m],logger.appendDir("seeds_to_"+tmpname)); } + + if(opts.seedcountastext.value()){ + write_ascii_matrix(m_SeedCountMat,logger.appendDir("matrix_seeds_to_all_targets")); + } + } // the following is a helper function for save_matrix* diff --git a/streamlines.h b/streamlines.h index 2f9d912..39748fc 100644 --- a/streamlines.h +++ b/streamlines.h @@ -98,6 +98,9 @@ namespace TRACT{ vector<ColumnVector> m_path; vector<volume<int> > m_seedcounts; + Matrix m_SeedCountMat; + int m_SeedRow; + vector<volume<float> > m_targetmasks; vector<string> m_targetmasknames; vector<int> m_targflags; -- GitLab