Ejemplo n.º 1
0
bool
OptionsCont::set(const std::string &name, const std::string &value) throw(InvalidArgument) {
    Option *o = getSecure(name);
    if (!o->isWriteable()) {
        reportDoubleSetting(name);
        return false;
    }
    try {
        if (!o->set(value)) {
            return false;
        }
    } catch (InvalidArgument &e) {
        MsgHandler::getErrorInstance()->inform("While processing option '" + name + "':\n " + e.what());
        return false;
    }
    return true;
}
Ejemplo n.º 2
0
bool
OptionsCont::set(const std::string& name, const std::string& value) {
    Option* o = getSecure(name);
    if (!o->isWriteable()) {
        reportDoubleSetting(name);
        return false;
    }
    try {
        if (!o->set(value)) {
            return false;
        }
    } catch (ProcessError& e) {
        WRITE_ERROR("While processing option '" + name + "':\n " + e.what());
        return false;
    }
    return true;
}
Ejemplo n.º 3
0
bool
OptionsCont::set(const std::string &name, bool value) throw(InvalidArgument) {
    Option *o = getSecure(name);
    if (!o->isBool()) {
        throw InvalidArgument("The option '" + name + "' is not a boolean attribute and requires an argument.");
    }
    if (!o->isWriteable()) {
        reportDoubleSetting(name);
        return false;
    }
    try {
        if (!o->set(value)) {
            return false;
        }
    } catch (InvalidArgument &e) {
        MsgHandler::getErrorInstance()->inform("While processing option '" + name + "':\n " + e.what());
        return false;
    }
    return true;
}
Ejemplo n.º 4
0
 bool operator()(Option & o)                 { return (o.set(_v))[Option::F_ADJUSTED]; };
int main ( int argc, char **argv )
{

        string appName ( argv[0] );
        string appExample ( "partitionConfigFile outputBaseName [ options] \
			    \n\nDetails:\n\
			    \tthis program reads a series of connectivity pattern files, and trains a connectomic profile for each ROI\n\
			    \tpartitionConfigFile contains the names of output from the pipeline.\n\
			    \tgrpProfile is the output for resultant profiles, written in arma format\n" );
        Option<bool> helpOpt ( string ( "-h" ),false,string ( "display this help information. " ),false,no_argument );
        Option<int> modeOpt ( "--mode",3,"the mode of engergy functions, e.g., L1COEFFS(0), L2ERROR(1), PENALTY(2), SPARSITY(3), L2ERROR2(4), PENALTY2(5), default: 3", false, requires_argument );
        Option<int> modeDOpt ( "--modeD",3,"the constraints on dictionary:  L2(0),  L1L2(1), L1L2FL(2), L1L2MU(3), default: 3",false,requires_argument );
        Option<int> modePOpt ( "--modeP",0,"the method to minimization:  AUTO(0), PARAM1(1), PARAM2(2), PARAM3(3), default: 0",false,requires_argument );
        Option<float> lambdaOpt ( "--lamda",1," lambda, default: 1", false,requires_argument );
        Option<float> lambda2Opt ( "--lamda2", 0.15, "lambda2, default: 0", false,requires_argument );
        Option<float> gamma1Opt ( "--gamma1",0.4,"gamma1, default:0.4",false,requires_argument );
        Option<float> gamma2Opt ( "--gamma2",0,"gamma2, default:0",false,requires_argument );
        Option<bool> posAlphaOpt ( "--posAlpha",true,"where or not constrain alpha to be positive, default: true",false,no_argument );
        Option<bool> posDOpt ( "--posD",false,"whether or not constrain Dictionary to be positive, default: false",false,no_argument );
        Option<int> iterOpt ( "--iter", 300,"the number of iteration, default: 300",false,requires_argument );
        Option<bool> verboseOpt ( "-v",false,"verbose or not,default, false",false,no_argument );
        Option<int> numDicOpt ( "-K",5,"the number of dic elems, default: 5",false,requires_argument );
        Option<int> batchSizeOpt ( "-b",30,"the number of batch, default: 30", false,requires_argument );
        Option<string> aplibFullNameOpt ( "--aplib","/home/kli/bin/apclusterunix64.so","the full path name of ap lib;", false,requires_argument );
        Option<float> prefrenceOpt ( "-p",0,"the prefrence of ap clustering, if not set, will use mean similarity.", false,requires_argument );
        Option<string> leftPartCenterSphereOpt ( "--leftParts","lh.resx.200.CentersonSphere.vtk","the name of left part centers at reg space, default: lh.parts.200.CentersonSphere.vtk",false,requires_argument );
        Option<string> rightPartCenterSphereOpt ( "--rightParts","rh.resx.200.CentersonSphere.vtk","the name of right part centers at reg space, default: rh.parts.200.CentersonSphere.vtk",false,requires_argument );
        Option<string> leftLabelMatchAtSubjOpt ( "--leftMatch","labelMatch.lh.resx.200.tmplAtSubj", "the name of left label match for tmpl at subject space, default: labelMatch.lh.resx.200.tmplAtSubj", false,requires_argument );
        Option<string> rightLabelMatchAtSubjOpt ( "--rightMatch","labelMatch.rh.resx.200.tmplAtSubj", "the name of right label match for tmpl at subject space, default: labelMatch.rh.resx.200.tmplAtSubj", false,requires_argument );
        Option<string> subjDirsListOpt ( "-L","","the list of allReg directory for subjects, no default, must be set", true, requires_argument );

        OptionParser cmdParser ( appName,appName+"\t"+appExample );
        cmdParser.add ( helpOpt );
        cmdParser.add ( verboseOpt );
        cmdParser.add ( numDicOpt );
        cmdParser.add ( batchSizeOpt );
        cmdParser.add ( prefrenceOpt );
        cmdParser.add ( modeOpt );
        cmdParser.add ( modePOpt );
        cmdParser.add ( modeDOpt );
        cmdParser.add ( lambdaOpt );
        cmdParser.add ( lambda2Opt );
        cmdParser.add ( gamma2Opt );
        cmdParser.add ( gamma1Opt );
        cmdParser.add ( posDOpt );
        cmdParser.add ( posAlphaOpt );
        cmdParser.add ( iterOpt );
        cmdParser.add ( aplibFullNameOpt );
        cmdParser.add ( leftLabelMatchAtSubjOpt );
        cmdParser.add ( rightLabelMatchAtSubjOpt );
        cmdParser.add ( leftPartCenterSphereOpt );
        cmdParser.add ( rightPartCenterSphereOpt );
        cmdParser.add ( subjDirsListOpt );

        cmdParser.parse_command_line ( argc,argv,2 );

        if ( 3 > argc || cmdParser.check_compulsory_arguments ( true ) == false ) {
                cmdParser.usage();
                exit ( EXIT_FAILURE );
        }


        //set up parameters for dic learning;
        ParamDictLearn<float> parameters;
        parameters.mode = SPAMS::constraint_type ( modeOpt.value() );
        parameters.posAlpha = posAlphaOpt.value();
        parameters.lambda= lambdaOpt.value();
        parameters.modeD=SPAMS::constraint_type_D ( modeDOpt.value() );
        parameters.gamma1=gamma1Opt.value();
        parameters.modeParam=SPAMS::mode_compute ( modePOpt.value() );
        parameters.gamma2 = gamma2Opt.value(); // for modeD=2;
        parameters.iter=iterOpt.value();
        parameters.verbose=verboseOpt.value();
	
	
	//setup input connectivity files; 
	vector<string> allConfigNames; 
	KML::ReadNameList(argv[1],allConfigNames);
 

        CfMRIDicccol objfMRIDicccol;
	objfMRIDicccol.SetConnectivityFileName(allConfigNames[8]);
	  objfMRIDicccol.SetNames4TmplLabelMatchAtSubj ( allConfigNames[6],allConfigNames[7]);
        objfMRIDicccol.SetNames4PartitionCenterSurfAtRegSpace ( allConfigNames[10],allConfigNames[11] );
	
        objfMRIDicccol.SetData ( subjDirsListOpt.value() );
        objfMRIDicccol.SetParamDicLearn ( parameters );
        objfMRIDicccol.SetTrainer ( numDicOpt.value(),batchSizeOpt.value(),-1 );
		
        objfMRIDicccol.LearnProfileAndCoordModels();
        objfMRIDicccol.SaveProfileAndCoordModels ( argv[2] );


        //now clustering profiles;
        list<int> v1,v2;
        list<float> sims;
        float meanSim = objfMRIDicccol.ComputeSims4Profiles ( v1,v2,sims,string ( argv[2] ) +".cluster.sims" );
        CAPClustering apc;
        apc.SetNPoints ( objfMRIDicccol.GetNROIs() );
        apc.SetAplibName ( aplibFullNameOpt.value() );
        apc.SetMaxIteration ( 4000 );
        apc.SetPreference ( prefrenceOpt.set() ? prefrenceOpt.value() : meanSim );
        apc.Clustering ( v1,v2,sims );
        std::vector< int > idx=apc.GetClusterResultIdx();
        std::vector< int > centers=apc.GetCenters();
        ivec armaIdx ( &idx[0],idx.size() );
        armaIdx.save ( string ( argv[2] ) +".cluster.idx" );


        return 0;
} //end of main function;
Ejemplo n.º 6
0
int main(int argc, char *argv[]) {

  //parsing options
  OptionParser options(title, examples);
  options.add(outline);
  options.add(mask);
  options.add(skull);
  options.add(no_output);
  options.add(fractional_threshold);
  options.add(gradient_threshold);
  options.add(radiusarg);
  options.add(centerarg);
  options.add(apply_thresholding);
  options.add(generate_mesh);
  options.add(verbose);
  options.add(help);
  
  if (argc < 3) {
    if (argc == 1) {options.usage(); exit(0);};
    if (argc>1)
      {
	string s = argv[1];
	if (s.find("-h")!=string::npos | s.find("--help")!=string::npos ) 
	  {options.usage(); exit (0);}
      }
    cerr<<"error: not enough arguments, use bet -h for help"<<endl;
    exit (-1);
  }
  
  vector<string> strarg;
  for (int i=0; i<argc; i++)
    strarg.push_back(argv[i]);
  
  string inputname=strarg[1];
  string outputname=strarg[2];
  
  if (inputname.find("-")==0 || outputname.find("-")==0 )
    {cerr<<"error : two first arguments should be input and output names, see bet -h for help"<<endl; exit(-1);};
 
  /*
  int c=0;
  for (int i=0; i<argc; i++)
    if (i!=1 & i!=2)
      {
	strcpy(argv[c], strarg[i].c_str());
	c++;
      }
  
  argc -=2;
  */

  try {
    options.parse_command_line(argc, argv, 2);  // skip first 2 argv
  }
  catch(X_OptionError& e) {
    options.usage();
    cerr << endl << e.what() << endl;
    exit(EXIT_FAILURE);
  } 
  catch(std::exception &e) {
    cerr << e.what() << endl;
  } 
  
  if (help.value()) {options.usage(); return 0;};

  string out = outputname;
  if (out.find(".hdr")!=string::npos) out.erase(out.find(".hdr"), 4);
  if (out.find(".img")!=string::npos) out.erase(out.find(".hdr"), 4);
  string in = inputname;
  if (in.find(".hdr")!=string::npos) in.erase(in.find(".hdr"), 4);
  if (in.find(".img")!=string::npos) in.erase(in.find(".hdr"), 4);
  if (out == "default__default") {out=in+"_brain";}
  

  //set a memory hanlder that displays an error message
  set_new_handler(noMoreMemory);


  //the real program

  double xarg = 0, yarg = 0, zarg = 0;
  if (centerarg.set())
    {
      /*
      if (centerarg.value().size()!=3)
	{
	  cerr<<"three parameters expected for center option !"<<endl;
	  cerr<<"please check there is no space after commas."<<endl;
	  exit (-1);
	}
      else
      */
	{
	  xarg = (double) centerarg.value(0);
	  yarg = (double) centerarg.value(1);
	  zarg = (double) centerarg.value(2);
	}
    }
  
  const double bet_main_parameter = pow(fractional_threshold.value(), .275);
  
  volume<float> testvol;
  
  if (read_volume(testvol,in.c_str())<0)  return -1;

  // 2D kludge (worked for bet, but not here in bet2, hohum)
  if (testvol.xsize()*testvol.xdim()<20) testvol.setxdim(200);
  if (testvol.ysize()*testvol.ydim()<20) testvol.setydim(200);
  if (testvol.zsize()*testvol.zdim()<20) testvol.setzdim(200);
  
  Mesh m;
  make_mesh_from_icosa(5, m); 
  
  
  bet_parameters bp = adjust_initial_mesh(testvol, m, radiusarg.value(), xarg, yarg, zarg);
  
  if (verbose.value())
    {
      cout<<"min "<<bp.min<<" thresh2 "<<bp.t2<<" thresh "<<bp.t<<" thresh98 "<<bp.t98<<" max "<<bp.max<<endl;
      cout<<"c-of-g "<<bp.cog.X<<" "<<bp.cog.Y<<" "<<bp.cog.Z<<" mm"<<endl;
      cout<<"radius "<<bp.radius<<" mm"<<endl;
      cout<<"median within-brain intensity "<<bp.tm<<endl;
    }
  

  Mesh moriginal=m;
  
  const double rmin=3.33;
  const double rmax=10;
  const double E = (1/rmin + 1/rmax)/2.;
  const double F = 6./(1/rmin - 1/rmax);
  const int nb_iter = 1000;
  const double self_intersection_threshold = 4000;
  
  double l = 0;
  for (int i=0; i<nb_iter; i++)
    {
      step_of_computation(testvol, m, bet_main_parameter, 0, 0, i, l, bp.t2, bp.tm, bp.t, E, F, bp.cog.Z, bp.radius, gradient_threshold.value());
    }
  
  double tmp = m.self_intersection(moriginal);
  if (verbose.value() && !generate_mesh.value())
    cout<<"self-intersection total "<<tmp<<" (threshold=4000.0) "<<endl;
  
  bool self_intersection;
  if (!generate_mesh.value()) self_intersection = (tmp > self_intersection_threshold);  
  else (self_intersection = m.real_self_intersection());
  int pass = 0;  

  if (verbose.value() && generate_mesh.value() && self_intersection)
    cout<<"the mesh is self-intersecting "<<endl;


  //self-intersection treatment
  while (self_intersection)
    {
      if (self_intersection && verbose.value()) {cout<<"thus will rerun with higher smoothness constraint"<<endl;};
      m = moriginal;
      l = 0;
      pass++;
      for (int i=0; i<nb_iter; i++)
	{
	  double incfactor = pow (10.0,(double) pass + 1);
	  if (i > .75 * (double)nb_iter)
	    incfactor = 4.*(1. - i/(double)nb_iter) * (incfactor - 1.) + 1.;
	  step_of_computation(testvol, m, bet_main_parameter, pass, incfactor, i, l, bp.t2, bp.tm, bp.t, E, F, bp.cog.Z, bp.radius, gradient_threshold.value());
	}
      double tmp = m.self_intersection(moriginal);
  
      self_intersection = (tmp > self_intersection_threshold);
      if (!generate_mesh.value()) self_intersection = (tmp > self_intersection_threshold);  
      else (self_intersection = m.real_self_intersection());
      
      if (verbose.value() && !generate_mesh.value())
	cout<<"self-intersection total "<<tmp<<" (threshold=4000.0) "<<endl;
      
      if (verbose.value() && generate_mesh.value() && self_intersection)
	cout<<"the mesh is self-intersecting"<<endl;
	
      if (pass==10) // give up
	self_intersection=0;
    }
  

  //display
  volume<short> brainmask = make_mask_from_mesh(testvol, m);
  
  if (apply_thresholding.value())
    {
      int xsize = testvol.xsize();
      int ysize = testvol.ysize();
      int zsize = testvol.zsize();
      for (int k=0; k<zsize; k++)
	for (int j=0; j<ysize; j++)
	  for (int i=0; i<xsize; i++)
	    if (testvol.value(i, j, k) < bp.t) brainmask.value(i, j, k) = 1;
    }
  
  if (!(no_output.value()))
    {
      int xsize = testvol.xsize();
      int ysize = testvol.ysize();
      int zsize = testvol.zsize();
      volume<float> output = testvol;
      for (int k=0; k<zsize; k++)
	for (int j=0; j<ysize; j++)
	  for (int i=0; i<xsize; i++)
	    output.value(i, j, k) = (1-brainmask.value(i, j, k)) * output.value(i, j, k);
      if (save_volume(output,out.c_str())<0)  return -1;
    }  
  
  if (mask.value())
    {
      string maskstr = out+"_mask";
      if (save_volume((short)1-brainmask, maskstr.c_str())<0)  return -1;
    }
  
  if (outline.value())
    {
      string outlinestr = out+"_overlay";
      volume<float> outline = draw_mesh_bis(testvol, m);
      if (save_volume(outline, outlinestr.c_str())<0)  return -1;
    }

  if (generate_mesh.value())
    {
      string meshstr = out+"_mesh.off";
      m.save(meshstr.c_str());
    }

  if (skull.value())
    {
      string skullstr = out+"_skull";
      volume<float> skull = find_skull(testvol, m, bp.t2, bp.t, bp.t98);

      volume<short> bskull;
      copyconvert(skull,bskull);

      if (save_volume(bskull, skullstr.c_str())<0)  return -1;
    }

  return 0;
  
}