예제 #1
0
// 04/06/2012 - transfix - added bounding box modification code
int main(int argc, char **argv)
{
  using namespace std;

  try
    {
      switch(argc)
        {
        case 8:
          {
            using namespace boost;
            vector<string> parts;
            for(int i = 0; i < 6; i++)
              parts.push_back(argv[i+2]);
            VolMagick::BoundingBox bbox(join(parts,","));
            VolMagick::writeBoundingBox(bbox,argv[1]);
          }
        case 2:
          {
            VolMagick::VolumeFileInfo volinfo;
            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;
            cout << "Span: " << "(" << volinfo.XSpan() << "," << volinfo.YSpan() << "," << volinfo.ZSpan() << ") " << endl;
            double volmin = volinfo.min(), volmax = volinfo.max();
            cout<<"volhead info: " << volmin <<" " << volmax<< endl;
            for(unsigned int i = 0; i<volinfo.numVariables(); i++)
              {
                cout << "Name of var " << i << ": " << volinfo.name(i) << endl;
                cout << "Voxel type of var " << i << ": " << volinfo.voxelTypeStr(i) << endl;
                for(unsigned int j = 0; j<volinfo.numTimesteps(); j++)
                  {
                    if(volmin > volinfo.min(i,j)) volmin = volinfo.min(i,j);
                    if(volmax < volinfo.max(i,j)) volmax = volinfo.max(i,j);
                    cout << "Min voxel value of var " << i << ", timestep " << j << ": " << volinfo.min(i,j) << endl;
                    cout << "Max voxel value of var " << i << ", timestep " << j << ": " << volinfo.max(i,j) << endl;
                  }
              }
            cout << "Min voxel value (of whole dataset): " << volmin << endl;
            cout << "Max voxel value (of whole dataset): " << volmax << endl;
            break;
          }
        default:
          {
            cerr << "Usage: " << endl;
            cerr << argv[0] << " <volume file>" << endl;
            cerr << argv[0] << " <volume file> [minx] [miny] [minz] [maxx] [maxy] [maxz] : set a volume's bounding box" << endl;
            return 1;
          }
        }
    }
  catch(VolMagick::Exception &e)
    {
      cerr << e.what() << endl;
    }
  catch(std::exception &e)
    {
      cerr << e.what() << endl;
    }

  return 0;
}
예제 #2
0
int main(int argc, char **argv)
{
  if(argc != 3)
    {
      cerr << "Usage: " << argv[0] << " <input volume file> <output volume file>" << endl;
      return 1;
    }

  try
    {
#ifndef OUT_OF_CORE
      cerr << "In-core convert" << endl;
      VolMagick::Volume vol;

      //TODO: read/write a slice at a time instead of reading the whole volume in memory then writing it out...
      VolMagick::readVolumeFile(vol,argv[1]/*,var,time*/);
      //VolMagick::writeVolumeFile(vol,argv[2]/*,var,time*/);
      VolMagick::createVolumeFile(vol,argv[2]);
#else
      cerr << "Out-of-core convert" << endl;
      VolMagick::VolumeFileInfo volinfo;
      volinfo.read(argv[1]);

	  //VolMagick::createVolumeFile in Utlity.h 
      VolMagick::createVolumeFile(argv[2],volinfo); 


	 // cout<<"convert volinfo:" << volinfo.boundingBox().minx <<" " << volinfo.boundingBox().maxx<< endl;
      //read in slice by slice
      for(unsigned int k = 0; k < volinfo.ZDim(); k++)
	{
	  for(unsigned int var=0; var<volinfo.numVariables(); var++)
	    for(unsigned int time=0; time<volinfo.numTimesteps(); time++)
	      {
		VolMagick::Volume vol;
		readVolumeFile(vol,argv[1],
			       var,time,
			       0,0,k,
			       VolMagick::Dimension(volinfo.XDim(),volinfo.YDim(),1));

		vol.desc(volinfo.name(var));
		writeVolumeFile(vol,argv[2],
				var,time,
				0,0,k);
	      }
	  fprintf(stderr,"Converting: %5.2f %%\r",(((float)k)/((float)((int)(volinfo.ZDim()-1))))*100.0);
	}
      fprintf(stderr,"\n");
#endif
    }
  catch(VolMagick::Exception &e)
    {
      cerr << e.what() << endl;
    }
  catch(std::exception &e)
    {
      cerr << e.what() << endl;
    }

  return 0;
}
예제 #3
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;
}