Esempio n. 1
0
int main(int argc, char **argv)
{
  if(argc < 4)
    {
      std:: cerr << "make templete volume with initial value:" << std::endl;
      std:: cerr << "Usage: " << argv[0] << "<ref. vol> <set val(float)> <out vol>" << std::endl;
      return 1;
    }

  try
    {
      VolMagick::Volume outputVol;

      VolMagick::VolumeFileInfo volinfo;
      volinfo.read(argv[1]);

      float setval = atof( argv[2] );

      outputVol.voxelType(volinfo.voxelType());
      outputVol.dimension(volinfo.dimension());
      outputVol.boundingBox(volinfo.boundingBox());
   
      int dimx = outputVol.XDim();
      int dimy = outputVol.YDim();
      int dimz = outputVol.ZDim();
      fprintf( stderr, "dim: %d %d %d\n", dimx, dimy, dimz );

      for( int kz = 0; kz<dimz; kz++)
        for( int jy = 0; jy<dimy; jy++)
          for( int ix = 0; ix<dimx; ix++)
 	    outputVol(ix,jy,kz, setval);
      
      VolMagick::createVolumeFile(outputVol, argv[argc-1]);

    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    if(argc < 3)
    {
        std:: cerr <<
                   "Usage: " << argv[0] <<


                   "  <first volume>  <output volume>.   \n";

        return 1;
    }

    try
    {
        VolMagick::Volume inputVol;


        VolMagick::Volume outputVol;

        VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume

        VolMagick::VolumeFileInfo volinfo1;
        volinfo1.read(argv[1]);
        std::cout << volinfo1.filename() << ":" <<std::endl;


        std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;


        VolMagick::BoundingBox bbox;
        bbox.minx = inputVol.XMin();
        bbox.maxx = inputVol.XMax();
        bbox.miny = inputVol.YMin();
        bbox.maxy = inputVol.YMax();
        bbox.minz = 2.0*inputVol.ZMin() - inputVol.ZMax();
        bbox.maxz = inputVol.ZMax();

        VolMagick::Dimension dim;
        dim.xdim = inputVol.XDim();
        dim.ydim = inputVol.YDim();
        dim.zdim = (int)((bbox.maxz -bbox.minz)/inputVol.ZSpan())+1;


//	 cout<<bbox.minz <<" " << bbox.maxz<<" "<< bbox.maxy <<endl;
//	 cout<<dim.zdim <<" " << dim.ydim << endl;

        outputVol.voxelType(inputVol.voxelType());
        outputVol.dimension(dim);
        outputVol.boundingBox(bbox);





        for( int kz = 0; kz<outputVol.ZDim()/2; kz++)
            for( int jy = 0; jy<inputVol.YDim(); jy++)
                for( int ix = 0; ix<inputVol.XDim(); ix++)
                    outputVol(ix, jy, kz, inputVol(inputVol.XDim()-1-ix, inputVol.YDim()-1-jy, inputVol.ZDim()-1-kz));

        for( int kz=outputVol.ZDim()/2; kz < outputVol.ZDim(); kz++)
            for( int jy = 0; jy<inputVol.YDim(); jy++)
                for( int ix = 0; ix<inputVol.XDim(); ix++)
                    outputVol(ix, jy, kz, inputVol(ix, jy, kz+1-inputVol.ZDim()));








        VolMagick::createVolumeFile(outputVol, argv[2]);


        cout<<"done!"<<endl;

    }

    catch(VolMagick::Exception &e)
    {
        std:: cerr << e.what() << std::endl;
    }
    catch(std::exception &e)
    {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}
int main(int argc, char **argv)
{
  if(argc < 4)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 
	"  first volume - second volume, output volume, threshold " << std::endl;
	      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is mask volume
      
	  float threshold = atof(argv[4]);

      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      VolMagick::VolumeFileInfo volinfo2;
      volinfo2.read(argv[2]);

      std::cout << volinfo2.filename() << ":" <<std::endl;
      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

      std::cout<<"minVol2 , maxVol2: "<<volinfo2.min()<<" "<<volinfo2.max()<<std::endl;

      
      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype "<<inputVol.voxelType()<<std::endl;
      	
	 // int step = 1;
   //   if(argc==5) step= atoi(argv[argc-1]);

	  outputVol= inputVol;

      
      for( int kz = 0; kz<inputVol2.ZDim(); kz++)
	{
	    for( int jy = 0; jy<inputVol2.YDim(); jy++)
	      for( int ix = 0; ix<inputVol2.XDim(); ix++)
		{
	//	  if(inputVol2(ix, jy, kz)<= inputVol(ix, jy, kz)) 
	//	  {
		     outputVol(ix, jy, kz, inputVol(ix,jy,kz)-inputVol2(ix,jy,kz));
					
	//	  }
	//	  else outputVol(ix,jy,kz, inputVol.min());
			  
		}
	}	
      

      VolMagick::createVolumeFile(outputVol, argv[3]);





    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
  if(argc < 3)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

	
	"<first volume>  <second volume> <output volume> <int Interpolate number> \n";

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;

      
      
      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is mask volume
      
	  int number = atoi(argv[4]);
	
	  VolMagick::Volume  outputVol;

	
      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      VolMagick::VolumeFileInfo volinfo2;
      volinfo2.read(argv[2]);
      std::cout << volinfo2.filename() << ":" <<std::endl;
      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

      std::cout<<"minVol2 , maxVol2: "<<volinfo2.min()<<" "<<volinfo2.max()<<std::endl;

      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      

      
      
	for (int num = 1; num < number; num ++)
    {
	  std::cout<<"\xd"<<(float)(num)/(float)(number-1)*100.00<<"% is finished";
	  for( int kz = 0; kz<inputVol.ZDim(); kz++)
	   for( int jy = 0; jy<inputVol.YDim(); jy++)
	     for( int ix = 0; ix<inputVol.XDim(); ix++)
		  	outputVol(ix,jy,kz, (inputVol(ix,jy,kz)*(1.0-(float)(num/(float)(number-1))) + inputVol2(ix,jy,kz))*(float)(num/(float)(number-1))  );
			stringstream s;
	 		s<<argv[3]<< num <<".rawiv";
	      VolMagick::createVolumeFile(outputVol, s.str());
    }

    std::cout<<"done!"<<std::endl;


    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
  if(argc < 4)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

	
	"  first volume - second volume = output volume, step  \n";

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is mask volume
      

      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      VolMagick::VolumeFileInfo volinfo2;
      volinfo2.read(argv[2]);

      std::cout << volinfo2.filename() << ":" <<std::endl;
      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

      std::cout<<"minVol2 , maxVol2: "<<volinfo2.min()<<" "<<volinfo2.max()<<std::endl;

      
      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype "<<inputVol.voxelType()<<std::endl;
      	
	  int step = 1;
      if(argc==5) step= atoi(argv[argc-1]);

	  outputVol= inputVol;

      
      for( int kz = 0; kz<inputVol2.ZDim(); kz++)
	{
	    for( int jy = 0; jy<inputVol2.YDim(); jy++)
	      for( int ix = 0; ix<inputVol2.XDim(); ix++)
		{
		  if(inputVol2(ix, jy, kz)> inputVol2.min()) 
		  {
		  	for(int k=kz-step; k<=kz+step; k++)
				for(int j=jy-step; j<= jy+step; j++)
					for(int i=ix-step; i<= ix+step; i++)
					{
					  if(i*j*k >=0 && i< inputVol2.XDim()-1  && j <inputVol2.YDim()-1 && k < inputVol2.ZDim()-1)
		  				outputVol(i, j, k, inputVol.min());
					}
		  }
			  
		}
	}	
      

      VolMagick::createVolumeFile(outputVol, argv[3]);





    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 6
0
int main(int argc, char **argv)
{
  if(argc < 2)
    {
      cerr << "Usage: " << argv[0] << " <volume file>" << endl;
      return 1;
    }

  try
    {
      VolMagick::VolumeFileInfo volinfo;
      VolMagick::VolumeCache volcache;
      VolMagickOpStatus status;

      VolMagick::setDefaultMessenger(&status);

#if 0
      VolMagick::Volume sphereVol;
      
      sphereVol.dimension(VolMagick::Dimension(128,128,128));//256,256,256));
      sphereVol.voxelType(VolMagick::UChar);

      double center_x = sphereVol.XDim()/2.0;
      double center_y = sphereVol.YDim()/2.0;      
      double center_z = sphereVol.ZDim()/2.0;
      double distance;

      for(unsigned int k=0; k<sphereVol.ZDim(); k++)
	for(unsigned int j=0; j<sphereVol.YDim(); j++)
	  for(unsigned int i=0; i<sphereVol.XDim(); i++)
	    {
	      distance = sqrt(double((i-center_x)*(i-center_x)+
				     (j-center_y)*(j-center_y)+
				     (k-center_z)*(k-center_z)));
	      //sphereVol(i,j,k, distance);
		
	      if((distance > 15.0) && (distance < 20.0))
		sphereVol(i,j,k, 20);//20.0+10*(distance-15.0)/(20.0-15.0));
	      if((distance >= 20.0) && (distance < 25.0))
		sphereVol(i,j,k, 30);//50.0+10*(distance-50.0)/(55.0-50.0));
	    }

      VolMagick::writeVolumeFile(sphereVol, argv[1]);

#endif

#if 0
      volinfo.read(argv[1]);
      cout << volinfo.filename() << ":" <<endl;
      cout << "Num Variables: " << volinfo.numVariables() << endl;
      cout << "Num Timesteps: " << volinfo.numTimesteps() << endl;
      cout << "Dimension: " << volinfo.XDim() << "x" << volinfo.YDim() << "x" << volinfo.ZDim() << endl;
      cout << "Bounding box: ";
      cout << "(" << volinfo.boundingBox().minx << "," << volinfo.boundingBox().miny << "," << volinfo.boundingBox().minz << ") ";
      cout << "(" << volinfo.boundingBox().maxx << "," << volinfo.boundingBox().maxy << "," << volinfo.boundingBox().maxz << ") ";
      cout << endl;
      double volmin = volinfo.min(), volmax = volinfo.max();
      cout << "Min voxel value: " << volmin << endl;
      cout << "Max voxel value: " << volmax << endl;
      cout << "Voxel type: " << volinfo.voxelTypeStr() << endl;
      cout << "Volume name: " << volinfo.name() << endl << endl;
#endif

      /*
      vol.dimension(VolMagick::Dimension(128,128,128));
      vol.voxelType(VolMagick::Float);
      for(unsigned int i=0; i<128; i++)
	for(unsigned int j=0; j<128; j++)
	  for(unsigned int k=0; k<128; k++)
	    vol(i,j,k,double(i)/128.0);
      */
     
#if 0 
      if(argc > 2)
	{
	  VolMagick::Volume vol;

	  readVolumeFile(vol,argv[1]);
	  vol.min(volinfo.min());
	  vol.max(volinfo.max());
	  //vol.map(0.0,255.0);
	  //vol.voxelType(VolMagick::UChar);
	  vol.resize(VolMagick::Dimension(512,512,512));
	  writeVolumeFile(vol,argv[2]);

	}
#endif

#if 0
      if(argc > 2)
	{
	  double realmin, realmax;
	  VolMagick::Volume vol;
	  std::vector<VolMagick::VolumeFileInfo> volinfos(argc-2);
	  volinfos[0].read(argv[1]);
	  realmin = volinfos[0].min();
	  realmax = volinfos[0].max();
	  for(unsigned int i=0; i<argc-2; i++)
	    {
	      volinfos[i].read(argv[i+1]);
	      if(realmin > volinfos[i].min()) realmin = volinfos[i].min();
	      if(realmax < volinfos[i].max()) realmax = volinfos[i].max();
	    }
	  
	  cout << "Realmin: " << realmin << endl;
	  cout << "Realmax: " << realmax << endl;

	  createVolumeFile(argv[argc-1],
			   volinfo.boundingBox(),
			   volinfo.dimension(),
			   std::vector<VolMagick::VoxelType>(1, VolMagick::UChar),
			   1, argc-2,
			   0.0, double(argc-3));

	  for(unsigned int i=0; i<argc-2; i++)
	    {
	      readVolumeFile(vol,argv[i+1]);
	      //so the mapping is correct across all timesteps, we must set the real min and max across time
	      vol.min(realmin);
	      vol.max(realmax);
	      vol.map(0.0,255.0);
	      vol.voxelType(VolMagick::UChar);
	      writeVolumeFile(vol,argv[argc-1],0,i);
	    }
	}
#endif

      //vector test
#if 0
      std::vector<VolMagick::Volume> vols(4);
      {
	char filename[256];

	cout << "Testing RawV!" << endl;
	vols[0].voxelType(VolMagick::UChar);
	vols[0].desc("red");
	vols[0].fill(130.0);
	vols[1].voxelType(VolMagick::UChar);
	vols[1].desc("green");
	vols[1].fill(20.0);
	vols[2].voxelType(VolMagick::UChar);
	vols[2].desc("blue");
	vols[2].fill(200.0);
	
	vols[3].voxelType(VolMagick::Float);
	vols[3].desc("alpha");
	for(unsigned int k=0; k<vols[3].ZDim(); k++)
	  for(unsigned int j=0; j<vols[3].YDim(); j++)
	    for(unsigned int i=0; i<vols[3].XDim(); i++)
	      vols[3](i,j,k,
		      sqrt(float((i - (vols[3].XDim()/2.0))*(i - (vols[3].XDim()/2.0)) + 
				 (j - (vols[3].YDim()/2.0))*(j - (vols[3].YDim()/2.0)) + 
				 (k - (vols[3].ZDim()/2.0))*(k - (vols[3].ZDim()/2.0)))));
	
	VolMagick::writeVolumeFile(vols,"test.rawv");
      }
#endif
      //cout << "std::streamoff size: " << sizeof(std::streamoff) << endl;

      //ifstream test("flkajlff");
    }
  catch(VolMagick::Exception &e)
    {
      cerr << e.what() << endl;
    }
  catch(std::exception &e)
    {
      cerr << e.what() << endl;
    }

  return 0;
}
Esempio n. 7
0
int main(int argc, char **argv)
{
  if(argc<4)
    {
      cerr <<
 
	"Usage: inputfile, projectionAngles, outputfile" << endl;


      return 1;
    }


  try
    {    
      typedef boost::int64_t int64_t;

      VolMagick::Volume inputVol;

      VolMagick::Volume outputVol;   

      VolMagick::Volume startPtVol;

     VolMagick::Volume endPtVol;

      VolMagick::Volume rotatedVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
    
      
	 
      static double PI = 3.14159265;
 
      std::cout<<"vol read\n";



       int numProcs = omp_get_num_procs();
      std::cout<<"Num of processors: "<< numProcs<<"\n";

      int64_t numAngles = 0;
	
      FILE* fp = fopen(argv[2],"r");
     
      std::cout<<"Counting angles \n";
	
      float tmp;	
	

	while(fscanf(fp, "%f", &tmp) != EOF)
		numAngles++;

	fclose(fp);


   // initialize projection output volume

//	 outputVol.dimension(VolMagick::Dimension(inputVol.XDim(), inputVol.YDim(), numAngles));

	 VolMagick::Dimension dim;

	 dim.xdim = inputVol.XDim();

	 dim.ydim = inputVol.YDim();

	 dim.zdim = numAngles;
	
	 VolMagick::VoxelType vox = VolMagick::Float;

	 outputVol.voxelType(vox);

         VolMagick::BoundingBox outputBB;

	 outputBB.minx = inputVol.boundingBox().minx;

	 outputBB.maxx = inputVol.boundingBox().maxx;
	 
	 outputBB.maxy = inputVol.boundingBox().maxy;	

	 outputBB.miny = inputVol.boundingBox().miny;

	 outputBB.minz = 0;

	 outputBB.maxz = numAngles-1;

	 outputVol.boundingBox(outputBB);

	 outputVol.dimension(dim);
	
		
	// check
	std::cout<<outputVol.XDim()<<" "<<outputVol.YDim()<<" "<<outputVol.ZDim()<<"\n";
	
	std::cout<<outputVol.boundingBox().maxx<<" "<<outputVol.boundingBox().maxy<<" "<<outputVol.boundingBox().maxz<<"\n";

	std::cout<<outputVol.boundingBox().minx<<" "<<outputVol.boundingBox().miny<<" "<<outputVol.boundingBox().minz<<"\n";

	std::cout<<outputVol.voxelType()<<"\n";
	
//	
//
//	VolMagick::createVolumeFile(argv[3], outputBB, dim, inputVol.voxelType());

      	VolMagick::createVolumeFile(argv[3], outputVol);
        
	std::cout<<"Total number of angles: "<<numAngles<<"\n";

    float *angles = new float[numAngles];
	
	FILE* fp1 = fopen(argv[2], "r");
	
	for(int64_t i=0; i<numAngles; i++) {

	float tempangle;
	
	fscanf(fp1, "%f", &tempangle);

	tempangle = tempangle*PI/180;

	angles[i] = tempangle;

	}

	fclose(fp1);

//        int startTime;
//        startTime = clock();
	time_t t0, t1;
	
	t0 = time(NULL);	


	/// Collect start points and end points for each ray. Start point will always be along the X axis and the End point will be along the Z axis.
	// The direction of the line does not matter since integration is the same startpoint to end point or vice versa.

	// The start point is -ve then it imples that the "Z" coordinate is at zero. Else it is assumed that the Z coordinate is at max ZDim and the 
	// only inded needed to be stored is the "X" coordinate.
	// Similarly if the end point (Z) is -ve then it implies that the "X" axis is at zero. Else if it is positive then the X axis is at max XDim.
	
	/// step size for search
	float delta = 0.5;

	#pragma omp parallel for schedule(static, numAngles/numProcs)           
	for(int64_t anum = 0; anum<numAngles; anum++)
	{
	std::cout<<"Current angle: "<<angles[anum]<<"\n"<<"Processor ID: "<<omp_get_thread_num()<<"\n";	
//	int anum = 1; 
	    for(int64_t y=0; y<inputVol.YDim(); y++)
		for(int64_t r=0; r<inputVol.XDim(); r++)
              {
		
		float tempangle = angles[anum];
//		float tempangle = 0;


		float MaxS = sqrt(inputVol.XDim()*inputVol.XDim()/4.0 + inputVol.ZDim()*inputVol.ZDim()/4.0);
		
		float MinS = -1*MaxS;

		for(float s = MinS; s<MaxS; s=s+delta)
		{
			float r_origShift =  r - (float)inputVol.XDim()/2;
			
			float xx = r_origShift*cos(tempangle) - s*sin(tempangle) + inputVol.XDim()/2;
		
			//std::cout<<r_origShift<<"..";
	
			float zz = r_origShift*sin(tempangle) + s*cos(tempangle) + inputVol.ZDim()/2;			
		
			int in_x = (int) xx;
			int in_z = (int) zz;
	
//			if(xx>inputVol.boundingBox().minx && xx<inputVol.boundingBox().maxx  &&  zz>inputVol.boundingBox().minz && zz<inputVol.boundingBox().maxz)
			if(in_x>0 && in_x<inputVol.XDim() && in_z>0 && in_z<inputVol.ZDim())
			
//			outputVol(r, y, anum, (outputVol(r, y, anum) + inputVol.interpolate(xx, y, zz)*delta ));
                        outputVol(r, y, anum, (outputVol(r, y, anum) + inputVol(in_x, y, in_z)*delta ));



		}

	     }
	
	}	
	
//        int endTime;

 //       endTime = clock();
		
	t1 = time(NULL);
	
	std::cout<<"Time elapsed: "<<(long)(t1-t0);

//        std::cout<<"Time elapsed: "<<(endTime-startTime)/(1000);
        std::cout<<"\n";

	
	std::cout<<"Created outputfile\n";
         
     VolMagick::writeVolumeFile(outputVol, argv[3]);

    }    
      
  catch(VolMagick::Exception &e)
    {
      cerr << e.what() << endl;
    }
  catch(std::exception &e)
    {
      cerr << e.what() << endl;
    }


  
      
       
  return 0;

}
Esempio n. 8
0
int main(int argc, char **argv)
{
  if(argc < 3)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 
"First argument is the mask volume (128), second argument is the input intensity map, third argument is the outputfile\n";
	

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is mask volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is input volume
      

      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      VolMagick::VolumeFileInfo volinfo2;
      volinfo2.read(argv[2]);
      std::cout << volinfo2.filename() << ":" <<std::endl;
      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

      std::cout<<"minVol2 , maxVol2: "<<volinfo2.min()<<" "<<volinfo2.max()<<std::endl;

      
      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype "<<inputVol.voxelType()<<std::endl;
      	
	if(volinfo1.max()!=0)
		float inputVol1Scaling = volinfo1.min()/volinfo1.max();
	
	if(volinfo2.max()!=0)
		float inputVol2Scaling = volinfo2.min()/volinfo2.max();
      
      
      for( int kz = 0; kz<inputVol.ZDim(); kz++)
	{
	//  std::cout<<kz<<"..";
	    for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		{
		
		outputVol(ix,jy,kz, 0);

               if(inputVol(ix,jy,kz))
//                outputVol(ix,jy, kz, inputVol2(ix,jy,kz));
		outputVol(ix,jy,kz, inputVol2(ix,jy,kz));

		
		  
		}
	}	
      std::cout<<"done !" <<std::endl;

      VolMagick::createVolumeFile(outputVol, argv[argc-1]);





    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
  if(argc < 6)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

	
	" <first volume>  <xmin> <ymin> <zmin> <output volume> \n";

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;


      
      
      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
	
	  VolMagick::Volume  outputVol;

	
      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;
 
	  float span[3];
	  span[0]=inputVol.XSpan(); 
	  span[1]=inputVol.YSpan(); 
	  span[2]=inputVol.ZSpan();
	
	  VolMagick::BoundingBox bbox;
	  bbox.minx = atof(argv[2]);
	  bbox.miny = atof(argv[3]);
	  bbox.minz = atof(argv[4]);
	  bbox.maxx = bbox.minx + volinfo1.XMax()-volinfo1.XMin();
	  bbox.maxy = bbox.miny + volinfo1.YMax()-volinfo1.YMin();
	  bbox.maxz = bbox.minz + volinfo1.ZMax()-volinfo1.ZMin();
	
/*	  VolMagick::Dimension dim;
	  dim.xdim = (int) ((bbox.maxx-bbox.minx)/ span[0])+1;
	  dim.ydim = (int) ((bbox.maxy-bbox.miny)/ span[1])+1;
	  dim.zdim = (int) ((bbox.maxz-bbox.minz)/ span[2])+1;
*/

 	
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(volinfo1.dimension());
      outputVol.boundingBox(bbox);
      
      
/*	 float temp;
	 int i, j, k;
     int xsh = (int)((bbox.minx - inputVol.XMin())/span[0]);
     int ysh = (int)((bbox.miny - inputVol.YMin())/span[1]);
     int zsh = (int)((bbox.minz - inputVol.ZMin())/span[2]);
*/	 

	  for( int kz = 0; kz<outputVol.ZDim(); kz++)
	   for( int jy = 0; jy<outputVol.YDim(); jy++)
	     for( int ix = 0; ix<outputVol.XDim(); ix++)
		    {
		//		i = ix + xsh;
		//		j = jy + ysh;
		//		k = kz + zsh;
		//		cout <<"ijk "<< i <<" " << j <<" " <<k <<endl;
		//		if(i<0 || i >= inputVol.XDim()|| j<0 || j>= inputVol.YDim() || k <0 || k>=inputVol.ZDim()) outputVol(ix, jy, kz, 0.0);
		//		else
				outputVol(ix,jy,kz, inputVol(ix,jy,kz)  );
			}
	//		stringstream s;
	//		s<<argv[3]<< num <<".rawiv";
	      VolMagick::createVolumeFile(outputVol, argv[5]);
    

    std::cout<<"done!"<<std::endl;


    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 10
0
int main(int argc, char **argv)
{
    if(argc < 3)
    {
        cerr << "Usage: " << argv[0] << " <volume file> <volume file>" << endl;
        return 1;
    }

    try
    {
        VolMagickOpStatus status;

        VolMagick::setDefaultMessenger(&status);

#if 0
        double realmin, realmax;
        VolMagick::Volume vol;
        std::vector<VolMagick::VolumeFileInfo> volinfos(argc-2);
        volinfos[0].read(argv[1]);
        realmin = volinfos[0].min();
        realmax = volinfos[0].max();
        for(unsigned int i=0; i<argc-2; i++)
        {
            volinfos[i].read(argv[i+1]);
            if(realmin > volinfos[i].min()) realmin = volinfos[i].min();
            if(realmax < volinfos[i].max()) realmax = volinfos[i].max();
        }

        cout << "Realmin: " << realmin << endl;
        cout << "Realmax: " << realmax << endl;

        createVolumeFile(argv[argc-1],
                         volinfos[0].boundingBox(),
                         volinfos[0].dimension(),
                         std::vector<VolMagick::VoxelType>(1, VolMagick::UChar),
                         1, argc-2,
                         0.0, double(argc-3));

        for(unsigned int i=0; i<argc-2; i++)
        {
            readVolumeFile(vol,argv[i+1]);
            //so the mapping is correct across all timesteps, we must set the real min and max across time
            vol.min(realmin);
            vol.max(realmax);
            vol.map(0.0,255.0);
            vol.voxelType(VolMagick::UChar);
            writeVolumeFile(vol,argv[argc-1],0,i);
        }
#endif

        const double errThresh = 0.01;

        VolMagick::Volume vols[2];
        VolMagick::readVolumeFile(vols[0],argv[1]);
        VolMagick::readVolumeFile(vols[1],argv[2]);

        if(vols[0].dimension() != vols[1].dimension()) throw VolMagick::VolumePropertiesMismatch("Volumes differ in dimension");
        if(vols[0].boundingBox() != vols[1].boundingBox()) throw VolMagick::VolumePropertiesMismatch("Volumes differ in bounding box");
        if(fabs(vols[0].min() - vols[1].min()) > errThresh) throw VolMagick::VolumePropertiesMismatch("Minimum voxel values differ");
        if(fabs(vols[0].max() - vols[1].max()) > errThresh) throw VolMagick::VolumePropertiesMismatch("Maximum voxel values differ");

        for(VolMagick::uint64 i = 0; i<vols[0].dimension().size(); i++)
            if(fabs(vols[0](i) - vols[1](i)) > errThresh) throw VolMagick::VolumePropertiesMismatch("Voxel values differ");

    }
    catch(VolMagick::Exception &e)
    {
        cerr << e.what() << endl;
    }
    catch(std::exception &e)
    {
        cerr << e.what() << endl;
    }

    return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
  if(argc < 5)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

"  inputfile NewMin NewMax outputFile \n";
      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      

  //    VolMagick::VolumeFileInfo volinfo1;
  //    volinfo1.read(argv[1]);
  //    std::cout << volinfo1.filename() << ":" <<std::endl;

      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype: "<<inputVol.voxelType()<<std::endl;
      std::cout<<"InputVol min, max: " << inputVol.min() << ", " << inputVol.max() << std::endl;

     float newMin = atof(argv[2]);
     float newMax = atof(argv[3]); 
      
      for( int kz = 0; kz<inputVol.ZDim(); kz++)
	{
	  std::cout<<kz<<"..";
	    for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		{
		  
		  outputVol(ix,jy,kz, newMin + (inputVol(ix,jy,kz)-inputVol.min())*newMax/(inputVol.max()-inputVol.min())  );
		  
		}
	}	
      

      VolMagick::createVolumeFile(argv[argc-1], outputVol);

  //    VolMagick::writeVolumeFile(outputVol, argv[argc-1]);



     std::cout<< std::endl;

    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 12
0
VolMagick::Volume signedDistanceFunction(const boost::shared_ptr<Geometry>& geom,
					 const VolMagick::Dimension& dim,
					 const VolMagick::BoundingBox& bbox)
{
  int dimx = dim[0], dimy = dim[1], dimz = dim[2];

  // read the annotated input file and
  Mesh mesh;
  cerr << "Reading input mesh ";
  read_labeled_mesh(mesh, geom);
  cerr << "done." << endl;

  // build a bounding box around the input and store the
  // origin, span etc.
  //  vector<double> bbox;
  //  construct_bbox(mesh, bbox);
  VolMagick::BoundingBox box(bbox);
  if(box.isNull())
    {
      geom->GetReadyToDrawWire(); //make sure we have calculated extents for this geometry already
      box[0] = geom->m_Min[0];
      box[1] = geom->m_Min[1];
      box[2] = geom->m_Min[2];
      box[3] = geom->m_Max[0];
      box[4] = geom->m_Max[1];
      box[5] = geom->m_Max[2];
    }

  // construct a kd-tree of all the non-isolated mesh_vertices.
  vector<VECTOR3> points;
  vector<Point> pts;
  for(int i = 0; i < mesh.get_nv(); i ++)
  {
     if( mesh.vert_list[i].iso() ) continue;
     Point p = mesh.vert_list[i].point();
     pts.push_back(p);
     points.push_back(VECTOR3(CGAL::to_double(p.x()),
                              CGAL::to_double(p.y()),
                              CGAL::to_double(p.z())));
  }
  KdTree kd_tree(points, 20);
  kd_tree.setNOfNeighbours(1);

  // Now perform a reconstruction to build a tetrahedralized solid
  // with in-out marked.
  Triangulation triang;
  recon(pts, triang);

  // assign weight to each triangle.
  vector<double> weights;
  // assign_sdf_weight(mesh, weights); // comment out for uniform weight.

  VolMagick::Volume vol;

  cerr << "SDF " << endl;
  try
    {
      vol.dimension(VolMagick::Dimension(dimx,dimy,dimz));
      vol.voxelType(VolMagick::Float);
      vol.boundingBox(box);

      for(unsigned int k=0; k<vol.ZDim(); k++)
      {
	for(unsigned int j=0; j<vol.YDim(); j++)
        {
	  for(unsigned int i=0; i<vol.XDim(); i++)
	    {
              double x = vol.XMin() + i*vol.XSpan();
              double y = vol.YMin() + j*vol.YSpan();
              double z = vol.ZMin() + k*vol.ZSpan();
              double fn_val = sdf(Point(x,y,z), mesh, weights, kd_tree, triang);
	      vol(i,j,k, fn_val);
	    }
        }
	fprintf(stderr,
		"%5.2f %%\r",
		(float(k)/float(vol.ZDim()-1))*100.0);
      }

      vol.desc("multi_sdf");
    }
  catch(VolMagick::Exception &e)
    {
      cerr << e.what() << endl;
    }
  catch(std::exception &e)
    {
      cerr << e.what() << endl;
    }

  cerr << endl << "done." << endl;

  return vol;
}
Esempio n. 13
0
int main(int argc, char **argv) {
  // Initialize log4cplus
  std::ifstream testfile("log4cplus.properties");
  if (testfile) {
    testfile.close();
    log4cplus::PropertyConfigurator::doConfigure("log4cplus.properties");
  }
  else {
    log4cplus::BasicConfigurator::doConfigure();
  }

  if(argc < 9) {
    std::cerr << "Usage: " << argv[0] << " <first volume>" <<
	"<xmin> <ymin> <zmin> <xmax> <ymax> <zmax>  <output volume> \n";
    return 1;
  }

  try {
    VolMagick::Volume inputVol;
    VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
	
    VolMagick::Volume  outputVol;
	
    VolMagick::VolumeFileInfo volinfo1;
    volinfo1.read(argv[1]);
    std::cout << volinfo1.filename() << ":" <<std::endl;

    std::cout << "minVol1 , maxVol1: " << volinfo1.min() << " " << 
        volinfo1.max() << std::endl;;
 
    float span[3];
    span[0]=inputVol.XSpan(); 
    span[1]=inputVol.YSpan(); 
    span[2]=inputVol.ZSpan();
	
    VolMagick::BoundingBox bbox;
    bbox.minx = atof(argv[2]);
    bbox.miny = atof(argv[3]);
    bbox.minz = atof(argv[4]);
    bbox.maxx = atof(argv[5]);
    bbox.maxy = atof(argv[6]);
    bbox.maxz = atof(argv[7]);
	
    VolMagick::Dimension dim;
    dim.xdim = (int) ((bbox.maxx-bbox.minx)/ span[0])+1;
    dim.ydim = (int) ((bbox.maxy-bbox.miny)/ span[1])+1;
    dim.zdim = (int) ((bbox.maxz-bbox.minz)/ span[2])+1;

    bbox.maxx = bbox.minx + (dim.xdim-1)*span[0];
    bbox.maxy = bbox.miny + (dim.ydim-1)*span[1];
    bbox.maxz = bbox.minz + (dim.zdim-1)*span[2];
 	
    outputVol.voxelType(inputVol.voxelType());
    outputVol.dimension(dim);
    outputVol.boundingBox(bbox);
      
    float temp;
    int i, j, k;
    int xsh = (int)((bbox.minx - inputVol.XMin())/span[0]);
    int ysh = (int)((bbox.miny - inputVol.YMin())/span[1]);
    int zsh = (int)((bbox.minz - inputVol.ZMin())/span[2]);

    for( int kz = 0; kz<outputVol.ZDim(); kz++) {
      for( int jy = 0; jy<outputVol.YDim(); jy++) {
        for( int ix = 0; ix<outputVol.XDim(); ix++) {
          i = ix + xsh;
          j = jy + ysh;
          k = kz + zsh;
          if (i<0 || i >= inputVol.XDim()|| j<0 || j>= inputVol.YDim() || k <0 || k>=inputVol.ZDim()) {
            outputVol(ix, jy, kz, 0.0);
          } else {
            outputVol(ix,jy,kz, inputVol(i,j,k));
          }
        }
      }
    }
    std::cout << "creating volume file..." << std::endl;
    VolMagick::createVolumeFile(outputVol, argv[8]);
    std::cout << "done!" << std::endl;
  } catch(VolMagick::Exception &e) {
    std:: cerr << e.what() << std::endl;
  } catch(std::exception &e) {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}
Esempio n. 14
0
int main(int argc, char **argv)
{
  if(argc < 3)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

	
	"  <first volume>  <output volume> [ bool 0/1 ].   \n"; 
	cerr<<"bool 1 keeps the original volume, bool 0 only the reflection, default 0."  << endl;

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

       
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

  
      VolMagick::BoundingBox bbox;
	  bbox.minx = inputVol.XMin();
	  bbox.maxx = inputVol.XMax();
	  bbox.miny = inputVol.YMin();
	  bbox.maxy = inputVol.YMax();
	  bbox.minz = inputVol.ZMin();
	  bbox.maxz = inputVol.ZMax();

	  VolMagick::Dimension dim;
	  dim.xdim = inputVol.XDim();
	  dim.ydim = inputVol.YDim();
	  dim.zdim = inputVol.ZDim();


//	 cout<<bbox.minz <<" " << bbox.maxz<<" "<< bbox.maxy <<endl;
//	 cout<<dim.zdim <<" " << dim.ydim << endl;
      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(dim);
      outputVol.boundingBox(bbox);

	
      
   
      //Works for GroEL4.2
      for( int kz = 0; kz<outputVol.ZDim(); kz++)
	   for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		       {
			        float temp=0.0;
					if(inputVol.ZDim() >= kz && inputVol.ZDim() - kz < inputVol.ZDim()
					&& inputVol.YDim() >= jy && inputVol.YDim() - jy < inputVol.YDim() )
					temp = inputVol(ix, inputVol.YDim()-jy, inputVol.ZDim()-kz);
	  				outputVol(ix, jy, kz, temp);
			   }	
	 
	 if(argc==4 && atoi(argv[3])== 1)
	 {
      for( int kz = 0; kz<inputVol.ZDim(); kz++)
	   for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		       {
			   		outputVol(ix, jy, kz, outputVol(ix,jy,kz)+inputVol(ix,jy,kz));
			   }		  
	 }
		  
			  
		 
	      

      VolMagick::createVolumeFile(outputVol, argv[2]);


      cout<<"done!"<<endl;

    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 15
0
/*using namespace std;

class VolMagickOpStatus : public VolMagick::VoxelOperationStatusMessenger
{
public:
  void start(const VolMagick::Voxels *vox, Operation op, VolMagick::uint64 numSteps) const
  {
    _numSteps = numSteps;
  }

  void step(const VolMagick::Voxels *vox, Operation op, VolMagick::uint64 curStep) const
  {
    const char *opStrings[] = { "CalculatingMinMax", "CalculatingMin", "CalculatingMax",
				"SubvolumeExtraction", "Fill", "Map", "Resize", "Composite",
				"BilateralFilter", "ContrastEnhancement"};

    fprintf(stderr,"%s: %5.2f %%\r",opStrings[op],(((float)curStep)/((float)((int)(_numSteps-1))))*100.0);
  }

  void end(const VolMagick::Voxels *vox, Operation op) const
  {
    printf("\n");
  }

private:
  mutable VolMagick::uint64 _numSteps;
};

typedef boost::tuple<double, double, double> Color;
*/
int main(int argc, char **argv)
{
  if(argc < 3)
    {
      std:: cerr << 
	"Usage: " << argv[0] << "[vol 1] [vol 2] [out vol] [threshold]";
      std:: cerr <<
	"first volume + second volume = output volume. The voxels are remapped giving two different intensity ranges for the volumes, and threshold will be used for the second volume if it was set \n";

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is mask volume
      

      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      VolMagick::VolumeFileInfo volinfo2;
      volinfo2.read(argv[2]);
      std::cout << volinfo2.filename() << ":" <<std::endl;
      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

      std::cout<<"minVol2 , maxVol2: "<<volinfo2.min()<<" "<<volinfo2.max()<<std::endl;

      
      double thold = 0.0001;
      if( argc > 3) thold = atof( argv[4] );
      if( thold < 0.0001 ) thold = 0.0001;

      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype "<<inputVol.voxelType()<<std::endl;
      double min1 = volinfo1.min(); 
      double range1 = volinfo1.max()-volinfo1.min(); 
      double min2 = volinfo2.min(); 
      double range2 = volinfo2.max()-volinfo2.min(); 
      
      for( int kz = 0; kz<inputVol.ZDim(); kz++)
	{
	  std::cout<<kz<<"..";
	    for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		{
		  
		  outputVol(ix,jy,kz, 0);
		  
		  if( (inputVol(ix,jy,kz)- min1 ) > 0.0001 )
		    
		    outputVol(ix,jy,kz, ( (inputVol(ix,jy,kz)-min1)/range1)*128.0 );
		  
		  if( (inputVol2(ix,jy,kz)-min2) > thold)
		    
		    outputVol(ix,jy,kz, ( (inputVol2(ix,jy,kz)-min2)/range2)*128.0 + 128.0);
		  
		}
	}	
     
      VolMagick::createVolumeFile(outputVol, argv[3]);

    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 16
0
/*using namespace std;

class VolMagickOpStatus : public VolMagick::VoxelOperationStatusMessenger
{
public:
  void start(const VolMagick::Voxels *vox, Operation op, VolMagick::uint64 numSteps) const
  {
    _numSteps = numSteps;
  }

  void step(const VolMagick::Voxels *vox, Operation op, VolMagick::uint64 curStep) const
  {
    const char *opStrings[] = { "CalculatingMinMax", "CalculatingMin", "CalculatingMax",
				"SubvolumeExtraction", "Fill", "Map", "Resize", "Composite",
				"BilateralFilter", "ContrastEnhancement"};

    fprintf(stderr,"%s: %5.2f %%\r",opStrings[op],(((float)curStep)/((float)((int)(_numSteps-1))))*100.0);
  }

  void end(const VolMagick::Voxels *vox, Operation op) const
  {
    printf("\n");
  }

private:
  mutable VolMagick::uint64 _numSteps;
};

typedef boost::tuple<double, double, double> Color;
*/
int main(int argc, char **argv)
{
  if(argc < 3)
    {
      std:: cerr << 
	"Usage: " << argv[0] << "[vol 1] [vol 2...] [out vol]";
      std:: cerr <<
	"vol1 + vol2 + .. + voln = output volume. The voxels are remapped giving n different intensity ranges for the volumes, <0~256/n, 0~2*256/n, ..., 0~256>, for example.\n";

      return 1;
    }

  try
    {
      int nInVols = argc - 2;
      VolMagick::Volume *inVols = new VolMagick::Volume[ nInVols ];
      double *minvols = new double[ nInVols ];
      double *ranges = new double[ nInVols ];
      double volrangeunit = 256.0 / (double)nInVols;

      // read volumes and compute min & range
      for( int i = 0; i < nInVols; i++ ) {
         VolMagick::readVolumeFile( inVols[i], argv[i+1] );
         minvols[i] = inVols[i].min();
         ranges[i] = inVols[i].max() - inVols[i].min();
         std::cout<< "volume " << i << ": min, max: "<<minvols[i]<<" "<<inVols[i].max()<<std::endl;
         std::cout<< "volume " << i << ": dim: "<<inVols[i].XDim()<<" "<<inVols[i].YDim()<<" "<<inVols[i].ZDim()<<std::endl;
      }
      double thold = 0.0001;

      VolMagick::Volume outputVol;
      outputVol.voxelType(inVols[0].voxelType());
      outputVol.dimension(inVols[0].dimension());
      outputVol.boundingBox(inVols[0].boundingBox());
     
      int dimx = inVols[0].XDim();
      int dimy = inVols[0].YDim();
      int dimz = inVols[0].ZDim();
 
      for( int kz = 0; kz<dimz; kz++)
	{
	  std::cout<<kz<<"..";
	    for( int jy = 0; jy<dimy; jy++)
	      for( int ix = 0; ix<dimx; ix++)
		{
		  
		  outputVol(ix,jy,kz, 0);
	
                  for( int i = 0; i < nInVols; i++ )
	   	     if( (inVols[i](ix,jy,kz)- minvols[i] ) > thold )
		        outputVol(ix,jy,kz, ( (inVols[i](ix,jy,kz)-minvols[i])/ranges[i])*((i+1)*volrangeunit) );
		}
	}	
     
      VolMagick::createVolumeFile(outputVol, argv[argc-1]);

    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 17
0
int main(int argc, char **argv)
{
  if(argc < 4)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

	
	"<input vol 1> <input vol 2> <output vol> \n";

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::VolumeFileInfo volinfo;
      volinfo.read(argv[1]);


      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is mask volume
      

      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      VolMagick::VolumeFileInfo volinfo2;
      volinfo2.read(argv[2]);
      std::cout << volinfo2.filename() << ":" <<std::endl;
      
      std::cout<<"minVol1 , maxVol1: "<<volinfo1.min()<<" "<<volinfo1.max()<<std::endl;;

      std::cout<<"minVol2 , maxVol2: "<<volinfo2.min()<<" "<<volinfo2.max()<<std::endl;

           

      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype "<<inputVol.voxelType()<<std::endl;
      

      double min=100000000.0;
      double max=-100000000.0;
      
      for( int kz = 0; kz<inputVol.ZDim(); kz++)
	{
	  std::cout<<kz<<"..";
	    for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		{		  
		  outputVol(ix,jy,kz, inputVol(ix,jy,kz)+inputVol2(ix,jy,kz));

		  if (inputVol(ix,jy,kz)+inputVol2(ix,jy,kz) < min) {
		    min = inputVol(ix,jy,kz)+inputVol2(ix,jy,kz);
		  }

		  if (inputVol(ix,jy,kz)+inputVol2(ix,jy,kz) >max) {
		    max = inputVol(ix,jy,kz)+inputVol2(ix,jy,kz);
		  }



		}
	}	
      

      std::cout << std::endl << "New Min/Max " << min << " " << max << std::endl;

      VolMagick::createVolumeFile(argv[3],volinfo);

      VolMagick::writeVolumeFile(outputVol, argv[3]);

    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 18
0
int main(int argc, char **argv)
{
  if(argc < 6)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

	
	"  <first volume>  <second volume> < threshold> <output volume left> <output volume masked> \n";
	std::cerr<<"second volume (son) is subset of first volume (mother), threshold is in [0,255], output masked is the volume in first volume with > threshold in the second volume. output volume left is the first volume - output volume masked. " << std::endl;

      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;

      
      
      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      VolMagick::readVolumeFile(inputVol2, argv[2]); /// second argument is mask volume
      
	  float threshold = atof(argv[3]);


	  VolMagick::Volume  outputLeft;
	  VolMagick::Volume  outputMasked;

      if(!inputVol2.boundingBox().isWithin(inputVol.boundingBox()) )
	  	throw VolMagick::SubVolumeOutOfBounds("The mask volume bounding box must be within the mother volume's bounding box.");



      outputLeft.voxelType(inputVol.voxelType());
      outputLeft.dimension(inputVol.dimension());
      outputLeft.boundingBox(inputVol.boundingBox());
      
      outputMasked.voxelType(inputVol.voxelType());
      outputMasked.dimension(inputVol.dimension());
      outputMasked.boundingBox(inputVol.boundingBox());
    
   

	  float x, y, z;
	  float fvalue;
	  float minvalue = (float)inputVol2.min();
	  float maxvalue = (float)inputVol2.max();

 	  for( int kz = 0; kz<inputVol.ZDim(); kz++)
	  {
	  	for( int jy = 0; jy<inputVol.YDim(); jy++)
	    {
			for( int ix = 0; ix<inputVol.XDim(); ix++)
		   	{
		     	z = inputVol.ZMin() + kz*inputVol.ZSpan();
			 	y = inputVol.YMin() + jy*inputVol.YSpan();
				x = inputVol.XMin() + ix*inputVol.XSpan();
				if((z >= (float)inputVol2.ZMin()) && (z <= (float)inputVol2.ZMax()) && ( y >=(float)inputVol2.YMin()) && (y <= (float)inputVol2.YMax()) &&(x >= (float)inputVol2.XMin()) && (x <= (float)inputVol2.XMax()) )
				{
				  fvalue = 255.0*(inputVol2.interpolate(x,y,z)-minvalue)/(maxvalue-minvalue);
				  if(fvalue > threshold)
				  {
				  	outputMasked(ix,jy,kz, inputVol(ix,jy,kz));
					outputLeft(ix,jy,kz, inputVol.min());
				  }	  
				  else
				  {
				  	outputMasked(ix,jy,kz, inputVol.min());
					outputLeft(ix,jy,kz, inputVol(ix,jy,kz));
				  }
				}
				else
				{
					outputMasked(ix,jy,kz, inputVol.min());
					outputLeft(ix,jy,kz, inputVol(ix,jy,kz));
				}
		     }		   
		  }	
		}



	VolMagick::createVolumeFile(outputLeft, argv[4]);
	VolMagick::createVolumeFile(outputMasked, argv[5]);

  
    std::cout<<"done!"<<std::endl;


    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
Esempio n. 19
0
int main(int argc, char **argv)
{
  if(argc < 5)
    {
      std:: cerr << 
	"Usage: " << argv[0] <<"  inputfile   t_low   t_high   outputFile \n";
      return 1;
    }

  try
    {
      VolMagick::Volume inputVol;

      VolMagick::Volume inputVol2;
      
      VolMagick::Volume outputVol;

      VolMagick::readVolumeFile(inputVol,argv[1]); ///first argument is input volume
      
      

      VolMagick::VolumeFileInfo volinfo1;
      volinfo1.read(argv[1]);
      std::cout << volinfo1.filename() << ":" <<std::endl;

      
      outputVol.voxelType(inputVol.voxelType());
      outputVol.dimension(inputVol.dimension());
      outputVol.boundingBox(inputVol.boundingBox());
      
      
      std::cout<<"voxeltype "<<inputVol.voxelType()<<std::endl;
      	
     float tlow = atof(argv[2]);
     float thigh = atof(argv[3]); 
     
	 if(tlow < 0)
	 {
	 	tlow = 0;
		std::cout<<"tlow should be bigger than 0, set to 0. "<<std::endl;
	}
	 if(thigh>255) 
	 {
	 	thigh = 255;
		std::cout<<"thigh should be smaller than 255, set to 255. " <<std::endl;
	 }

      for( int kz = 0; kz<inputVol.ZDim(); kz++)
	 {
	    for( int jy = 0; jy<inputVol.YDim(); jy++)
	      for( int ix = 0; ix<inputVol.XDim(); ix++)
		{
		  float temp = inputVol(ix, jy, kz);
		  float temp1 = 255.0*(temp-volinfo1.min())/(volinfo1.max()-volinfo1.min());
		  if( (temp1 >= tlow) && (temp1 < thigh))
		  	outputVol(ix, jy, kz, temp);
		  else outputVol(ix, jy, kz, volinfo1.min());

		}
	}	
      

      VolMagick::createVolumeFile(outputVol, argv[argc-1]);


	std::cout<<" done!" <<std::endl;


    }

  catch(VolMagick::Exception &e)
    {
      std:: cerr << e.what() << std::endl;
    }
  catch(std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}