From 4eb5b743650fafae19543fa057919f94adb97718 Mon Sep 17 00:00:00 2001
From: Tim Behrens <behrens@fmrib.ox.ac.uk>
Date: Mon, 8 Aug 2005 09:26:42 +0000
Subject: [PATCH] *** empty log message ***

---
 fibre.h              |   5 +-
 probtrackxOptions.cc | 211 ++++++++++++++++++++++++++++++++++++++
 probtrackxOptions.h  | 239 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 453 insertions(+), 2 deletions(-)
 create mode 100644 probtrackxOptions.cc
 create mode 100644 probtrackxOptions.h

diff --git a/fibre.h b/fibre.h
index 488b77d..a6d5ba7 100644
--- a/fibre.h
+++ b/fibre.h
@@ -227,8 +227,9 @@ namespace FIBRE{
 	}
 	else{
 	  if(m_lam_jump)
-	    m_f_prior=log(1-m_f)+2*log(fabs(log(1-m_f))); //marginalised with uniform prior on lambda
-	  else
+	    // m_f_prior=log(1-m_f)+2*log(fabs(log(1-m_f))); //marginalised with uniform prior on lambda
+	    m_f_prior=std::log(m_f);
+	    else
 	    m_f_prior=0;
 	}
 	m_f_prior=opts.fudge.value()*m_f_prior;
diff --git a/probtrackxOptions.cc b/probtrackxOptions.cc
new file mode 100644
index 0000000..150531c
--- /dev/null
+++ b/probtrackxOptions.cc
@@ -0,0 +1,211 @@
+/*  probtrackxOptions.cc
+
+    Tim Behrens, FMRIB Image Analysis Group
+
+    Copyright (C) 2004 University of Oxford  */
+
+/*  CCOPYRIGHT  */
+
+#define WANT_STREAM
+#define WANT_MATH
+
+#include <iostream.h>
+#include <fstream.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "probtrackxOptions.h"
+#include "utils/options.h"
+//#include "newmat.h"
+using namespace Utilities;
+
+namespace TRACT {
+
+probtrackxOptions* probtrackxOptions::gopt = NULL;
+
+  void probtrackxOptions::parse_command_line(int argc, char** argv, Log& logger)
+  {
+    //Do the parsing;
+    try{
+      for(int a = options.parse_command_line(argc, argv); a < argc; a++) ;
+      // setup logger directory
+      if( mode.value()=="help"){
+	modehelp();
+	exit(2);
+      }
+      else if(help.value() || ! options.check_compulsory_arguments())
+	{
+	  options.usage();
+	  exit(2);
+	}   
+
+      else{
+	modecheck(); // check all the correct options are set for this mode.
+	if(mode.value()!="simple"){  
+	  if(forcedir.value())
+	    logger.setthenmakeDir(logdir.value(),"probtrack.log");
+	  else
+	    logger.makeDir(logdir.value(),"probtrack.log");
+	  
+	  cout << "Log directory is: " << logger.getDir() << endl;
+	  
+	  // do again so that options are logged
+	  for(int a = 0; a < argc; a++)
+	    logger.str() << argv[a] << " ";
+	  logger.str() << endl << "---------------------------------------------" << endl << endl;
+	}
+	
+      }
+    
+      
+    }
+    catch(X_OptionError& e){
+      cerr<<e.what()<<endl;
+      cerr<<"try: probtrack --help"<<endl;
+      exit(0);
+    }
+    
+    
+    
+    
+  }
+  
+  
+  void probtrackxOptions::modecheck()
+  {
+    bool check=true;
+    string mesg="";
+    if(mode.value()=="simple"){
+      if(outfile.value()==""){
+	mesg+="You must set an output name in simple mode: -o\n";
+	check=false;
+      }
+    }
+    if(mode.value()=="seedmask"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in seedmask mode: --dir\n";
+	check=false;
+      }
+      if(outfile.value()==""){
+	mesg+="You must set an output name in seedmask mode: -o\n";
+	check=false;
+      }
+    }
+    if(mode.value()=="twomasks_symm"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in twomasks_symm mode: --dir\n";
+	check=false;
+      }
+      if(mask2.value()==""){
+	mesg+="You must set a second mask in twomasks_symm mode: --mask2\n";
+	check=false;
+      }
+      if(outfile.value()==""){
+	mesg+="You must set an output name in twomasks_symm mode: -o\n";
+	check=false;
+      }
+    }
+    if(mode.value()=="waypoints"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in waypoints mode: --dir\n";
+	check=false;
+      }
+      if(mask2.value()==""){
+	mesg+="You must set a waypoint mask or list of waypoint masks in waypoints mode: --mask2\n";
+	  check=false;
+      }
+      if(outfile.value()==""){
+	mesg+="You must set output name in waypoints mode: -o\n";
+	check=false;
+      }
+    }
+    if(mode.value()=="seeds_to_targets"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in seeds_to_targets mode: --dir\n";
+	check=false;
+      }
+      if(targetfile.value()==""){
+	mesg+="You must set a targetmasks file in seeds_to_targets mode: --targetmasks\n";
+	check=false;
+      }
+    }
+    if(mode.value()=="matrix1"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in matrix1 mode: --dir\n";
+	check=false;
+      }
+      if(outfile.value()==""){
+	mesg+="You must set an output name in matrix1 mode: -o\n";
+	check=false;
+      }
+    }
+    
+    if(mode.value()=="matrix2"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in matrix2 mode: --dir\n";
+	check=false;
+      }
+      if(outfile.value()==""){
+	mesg+="You must set an output name in matrix2 mode: -o\n";
+	check=false;
+      }
+      if(lrmask.value()==""){
+	mesg+="You must set a low resolution mask file in matrix2 mode: --lrmask\n";
+	check=false;
+      }
+    }
+    
+    if(mode.value()=="maskmatrix"){
+      if(logdir.value()==""){
+	mesg+="You must set an output directory name in maskmatrix mode: --dir\n";
+	check=false;
+      }
+      if(outfile.value()==""){
+	mesg+="You must set an output name in maskmatrix mode: -o\n";
+	check=false;
+      }
+    }
+    if(!check){
+      cerr<<mesg;
+      exit(2);
+    }
+    
+  }
+
+
+  
+  void probtrackxOptions::modehelp()
+  {
+    cout<<"tracking mode -  Options are:\n\n simple (default)\n    Input is text file defining start point.\n    Output is dti space volume with connectivity values at each voxel.\n   If your seed voxel is not in diffusion space\n    you need to specify a volume in yuour input\n    space (--seedref)\n   and a matrix taking this space to diffusion space(--xfm).\n\n seeds_to_targets\n    Inputs are a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    and a text file with the name of a single target mask\n    on each new line (--targetmasks).\n    Output is a single volume for each target mask where the value of each\n    volume within the seed mask corresponds to the number of particles \n    seeded from this voxel reaching this target mask.\n\n seedmask\n    Input is a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is seed space volume with connectivity values at each voxel\n    summed from every seed.\n\n twomasks_symm\n    Input is a binary volume for first mask (-x)\n    also requires a binary volume for second mask (--mask2)\n    (requires a matrix taking both seeds to DTI space (--xfm))\n    Output is the sum of all paths the from first mask which pass\n    through the second and vice-versa  i.e. only paths\n    which pass through both masks are retained.\n\n waypoints\n    Input is a binary volume for seed mask (-x)\n    also requires a binary waypoint mask or ascii list\n    of waypoint masks (--mask2)\n    (requires a matrix taking both seeds to DTI space (--xfm))\n    Output is a volume containing all the paths from the\n    seedmask which pass through ALL of the waypoint masks.\n"<<endl;
+    if ( getenv("FSLINFMRIB"))
+      matrixmodehelp(); 
+ }
+  
+  void probtrackxOptions::matrixmodehelp(){
+    cout<<" matrix1\n    Input is a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is an avw format nseeds x nseeds matrix \n    where element ij contains the number of particles leaving seed \n    voxel i and passing through seed voxel j. \n    Second output is an nsees x 3 matrix containing the \n    anatomical locations in Seed space of each matrix node.\n\n matrix2\n    Inputs are a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    and a low resolution binary mask in register with the\n    seed volume (--lrmask)\n    Output is a matrix of size nseeds x nlowres \n    which contains the connectivity distributions from every seed voxel.\n    Auxiliary outputs are index matrices for each axis \n    of this matrix containing the anatomical location of each\n    node in seed space (x-axis) and low res space (y-axis)\n\n maskmatrix\n    Input is volume with integers in each seed location\n    Integer values distinguish different clusters\n    (e.g. output of Feat clustering)\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is two matrices whose ij^th element is the\n     mean and max number of particles seeded from cluster i which pass \n    through cluster j\n"<<endl;
+  }
+  
+  
+  void probtrackxOptions::status()
+  {
+    cerr<<"basename   "<<basename.value()<<endl;
+    cerr<<"maskfile   "<<maskfile.value()<<endl;
+    cerr<<"seeds      "<<seedfile.value()<<endl;
+    cerr<<"output     "<<outfile.value()<<endl;
+    cerr<<"verbose    "<<verbose.value()<<endl;
+    cerr<<"nparticles "<<nparticles.value()<<endl;
+    cerr<<"nsteps     "<<nsteps.value()<<endl;
+    cerr<<"usef       "<<usef.value()<<endl;
+    cerr<<"rseed      "<<rseed.value()<<endl; 
+  }
+  
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/probtrackxOptions.h b/probtrackxOptions.h
new file mode 100644
index 0000000..72aac7a
--- /dev/null
+++ b/probtrackxOptions.h
@@ -0,0 +1,239 @@
+/*  probtrackxOptions.h
+
+    Tim Behrens, FMRIB Image Analysis Group
+
+    Copyright (C) 2004 University of Oxford  */
+
+/*  CCOPYRIGHT  */
+
+#if !defined(probtrackxOptions_h)
+#define probtrackxOptions_h
+
+#include <string>
+#include <iostream.h>
+#include <fstream.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "utils/options.h"
+#include "utils/log.h"
+
+//#include "newmatall.h"
+using namespace Utilities;
+
+namespace TRACT {
+
+class probtrackxOptions {
+ public:
+  static probtrackxOptions& getInstance();
+  ~probtrackxOptions() { delete gopt; }
+  
+  Option<int> verbose;
+  Option<bool> help;
+  Option<string> basename;
+  Option<string> maskfile;
+  Option<string> seedfile; 
+  Option<string> mode;
+  Option<string> targetfile;
+  Option<bool> simpleout;
+  Option<bool> s2tout;
+  FmribOption<bool> matrix1out;
+  FmribOption<bool> matrix2out;
+  FmribOption<bool> maskmatrixout;
+  Option<string> outfile;
+  Option<string> rubbishfile;
+  Option<string> seeds_to_dti;
+  FmribOption<string> skipmask;
+  Option<string> seedref;
+  Option<string> mask2;
+  Option<string> waypoints;
+  Option<string> meshfile;
+  FmribOption<string> lrmask;
+  Option<string> logdir; 
+  Option<bool> forcedir;
+  Option<int> nparticles;
+  Option<int> nsteps;
+  Option<float> c_thr;
+  FmribOption<float> fibthresh;
+  Option<float> steplength;
+  Option<bool> loopcheck;
+  Option<bool> usef;
+  Option<bool> modeuler;
+  Option<int> rseed;
+  void parse_command_line(int argc, char** argv,Log& logger);
+  void modecheck();
+  void modehelp();
+  void matrixmodehelp();
+  void status();
+ private:
+  probtrackxOptions();  
+  const probtrackxOptions& operator=(probtrackxOptions&);
+  probtrackxOptions(probtrackxOptions&);
+
+  OptionParser options; 
+      
+  static probtrackxOptions* gopt;
+  
+};
+
+
+ inline probtrackxOptions& probtrackxOptions::getInstance(){
+   if(gopt == NULL)
+     gopt = new probtrackxOptions();
+   
+   return *gopt;
+ }
+
+ inline probtrackxOptions::probtrackxOptions() :
+  verbose(string("-V,--verbose"), 0, 
+	  string("verbose level, [0-2]"), 
+	  false, requires_argument),
+   help(string("-h,--help"), false,
+	string("display this message"),
+	false, no_argument),
+   basename(string("-s,--samples"), string("DTI"),
+	       string("basename for samples files"),
+	       true, requires_argument),  
+   maskfile(string("-m,--mask"), string("mask"),
+	    string("Bet binary mask file in diffusion space"),
+	    true, requires_argument),
+   seedfile(string("-x,--seed"), string("Seed"),
+	    string("Seed volume or voxel depending on mode"),
+	    true, requires_argument),
+   mode(string("--mode"), string("simple"),
+	string("tracking mode -  To see list of options and explanations, use --mode=help"),
+	    true, requires_argument),
+   targetfile(string("--targetmasks"), string("cmasks"),
+	    string("File containing a list of target masks - required for seeds_to_targets mode"),
+	    false, requires_argument),
+  simpleout(string("--opd"), false,
+	    string("output path distribution"),
+	    false, no_argument), 
+  s2tout(string("--os2t"), false,
+	 string("output seeds to targets"),
+	 false, no_argument),
+  matrix1out(string("--omatrix1"), false,
+	  string("output matrix1"),
+	  false, no_argument), 
+  matrix2out(string("--omatrix2"), false,
+	  string("output matrix2"),
+	  false, no_argument), 
+  maskmatrixout(string("--omaskmatrix"), false,
+	    string("output maskmatrix"),
+	  false, no_argument), 
+
+  outfile(string("-o,--out"), string(""),
+	    string("Output file"),
+	    false, requires_argument),
+   rubbishfile(string("--rubbish"), string(""),
+	    string("Rubbish file"),
+	    false, requires_argument),
+   seeds_to_dti(string("--xfm"), string(""),
+	      string("Transform Matrix taking seed space to DTI space default is to use the identity"),false, requires_argument),
+  skipmask(string("--no_integrity"), string(""),
+	   string("no explanation needed"),
+	   false, requires_argument),
+  seedref(string("--seedref"), string(""),
+	 string("Reference vol to define seed space in simple mode - diffusion space assumed if absent"),
+	 false, requires_argument),
+  mask2(string("--mask2"), string(""),
+	 string("second mask in twomask_symm mode."),
+       false, requires_argument),
+ waypoints(string("--waypoints"), string(""),
+	 string("Waypoint mask or ascii list of waypoint masks."),
+       false, requires_argument), 
+ meshfile(string("--mesh"), string(""),
+	 string(""),
+       false, requires_argument),
+  lrmask(string("--lrmask"), string(""),
+	 string("low resolution binary brain mask for stroring connectivity distribution in matrix2 mode."),
+       false, requires_argument),
+  logdir(string("--dir"), string(""),
+	    string("Directory to put the final volumes in - code makes this directory"),
+	    false, requires_argument),
+  forcedir(string("--forcedir"), false,
+	 string("Use the actual directory name given - i.e. don't add + to make a new directory"),
+	 false, no_argument),
+  nparticles(string("-P,--nsamples"), 5000,
+	 string("Number of samples"),
+	 false, requires_argument),
+   nsteps(string("-S,--nsteps"), 2000,
+	    string("Number of steps per sample"),
+	    false, requires_argument),
+   c_thr(string("-c,--cthr"), 0.2, 
+	 string("Curvature threshold"), 
+	 false, requires_argument),
+  fibthresh(string("--fibthresh"), 0.01, 
+	    string("volume fraction before subsidary fibre orientations are considered (def 0.01)"), 
+	 false, requires_argument),
+   steplength(string("--steplength"), 0.5, 
+	 string("steplength"), 
+	 false, requires_argument),
+   loopcheck(string("-l,--loopcheck"), false, 
+	 string("perform loopchecks on paths - slower, but allows lower curvature threshold"), 
+	 false, no_argument),
+   usef(string("-f,--usef"), false, 
+	 string("Use anisotropy to constrain tracking"), 
+	 false, no_argument),
+  modeuler(string("--modeuler"), false, 
+	   string("Use modified euler streamlining"), 
+	   false, no_argument),
+   rseed(string("--rseed"), 12345,
+	 string("Random seed"),
+	 false, requires_argument), 
+   options("probtrack","probtrack -s <basename> -m <maskname> -x <seedfile> -o <output> --targetmasks=<textfile>\n probtrack --help\n")
+   {
+     
+    
+     try {
+       options.add(verbose);
+       options.add(help);
+       options.add(basename);
+       options.add(maskfile);
+       options.add(seedfile); 
+       options.add(mode);
+       options.add(targetfile);
+       options.add(skipmask);
+       options.add(mask2);
+       options.add(waypoints);
+       options.add(meshfile);
+       options.add(lrmask);
+       options.add(seedref);
+       options.add(logdir); 
+       options.add(forcedir); 
+       options.add(simpleout);
+       options.add(s2tout);
+       options.add(matrix1out);
+       options.add(matrix2out);
+       options.add(maskmatrixout);
+       options.add(outfile);
+       options.add(rubbishfile);
+       options.add(seeds_to_dti);
+       options.add(nparticles);
+       options.add(nsteps);
+       options.add(c_thr);
+       options.add(fibthresh);
+       options.add(steplength);
+       options.add(loopcheck);
+       options.add(usef);
+       options.add(modeuler);
+       options.add(rseed);
+     }
+     catch(X_OptionError& e) {
+       options.usage();
+       cerr << endl << e.what() << endl;
+     } 
+     catch(std::exception &e) {
+       cerr << e.what() << endl;
+     }    
+     
+   }
+}
+
+#endif
+
+
+
+
+
+
+
-- 
GitLab