예제 #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;
}
예제 #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
    {
      VolMagickOpStatus status;
      VolMagick::setDefaultMessenger(&status);

      VolMagick::VolumeFileInfo volinfo;

      volinfo.read(argv[1]);

      VolMagick::createVolumeFile(argv[2],
				  volinfo.boundingBox(),
				  volinfo.dimension(),
				  volinfo.voxelTypes(),
				  volinfo.numVariables(),
				  volinfo.numTimesteps(),
				  volinfo.TMin(),volinfo.TMax());

      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);
	    for(VolMagick::uint64 i = 0; i < vol.dimension().size(); i++)
	      vol(i, vol.min() + ((vol.max() - vol(i))/(vol.max() - vol.min()))*(vol.max() - vol.min()));
	    vol.desc(volinfo.name(var));
	    writeVolumeFile(vol,argv[2],var,time);
	  }
    }
  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 != 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;
}
예제 #4
0
  void operator()()
  {
    CVC::ThreadFeedback feedback;

    if (_output.empty()) {
      _output = _volSelected+"_gdtv";
    }
    if (_dataset.empty()) {
      _dataset = _volSelected+"_gdtv";
    }

    // read in the data if necessary
    if(cvcapp.isData<VolMagick::VolumeFileInfo>(_volSelected))
      {
        VolMagick::VolumeFileInfo vfi = cvcapp.data<VolMagick::VolumeFileInfo>(_volSelected);

        if (_currentIndex == 0) {

          if (_output.substr(_output.find_last_of(".")) != _fileType) {
            _output = _output + _fileType;   
          }

          VolMagick::createVolumeFile(_output,
                                      vfi.boundingBox(),
                                      vfi.dimension(),
                                      vfi.voxelTypes(),
                                      vfi.numVariables(),
                                      vfi.numTimesteps(),
                                      vfi.TMin(),
                                      vfi.TMax());
        }
      
        // run gdtv filter
        for(unsigned int var=0; var<vfi.numVariables(); var++) {
          for(unsigned int time=0; time<vfi.numTimesteps(); time++) {
            VolMagick::Volume vol;
	  
            readVolumeFile(vol,vfi.filename(),var,time);
            vol.gdtvFilter(2.0-_exp,_lambda,_iterations,_nhood-1.0);
	  
            if (_currentIndex == 0) {
              writeVolumeFile(vol,_output,var,time);
            } else if (_currentIndex == 1) {
              // put the dataset in the list
              cvcapp.data(_dataset,vol);		  
            }
          }
        }
      }
    else if(cvcapp.isData<VolMagick::Volume>(_volSelected))
      {
        VolMagick::Volume vol = cvcapp.data<VolMagick::Volume>(_volSelected);
	vol.gdtvFilter(2.0-_exp,_lambda,_iterations,_nhood-1.0);
      
        if (_currentIndex == 0) {
          //if _output not set, overwrite the input volume data
          if(_output.empty())
            cvcapp.data(_volSelected, vol);
          else {
            _output = _output + _fileType;
            cvcapp.data(_output, vol);
          }
        } else if (_currentIndex == 1) {
            cvcapp.data(_dataset,vol);
        }      
      }
  }
예제 #5
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;
}
예제 #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;
}
예제 #7
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;
}
예제 #8
0
namespace GenSeg {

//this hurts my soul -Joe R.
  VolMagick::VolumeFileInfo loadedVolumeInfo;
	
void swap_buffer(char *buffer, int count, int typesize)
{
		char sbuf[4];
		int i;
		int temp = 1;
		unsigned char* chartempf = (unsigned char*) &temp;
		if(chartempf[0] > '\0') {
			
			// swapping isn't necessary on single byte data
			if (typesize == 1)
				return;
			
			
			for (i=0; i < count; i++)
			{
				memcpy(sbuf, buffer+(i*typesize), typesize);
				
				switch (typesize)
				{
					case 2:
					{
						buffer[i*typesize] = sbuf[1];
						buffer[i*typesize+1] = sbuf[0];
						break;
					}
					case 4:
					{
						buffer[i*typesize] = sbuf[3];
						buffer[i*typesize+1] = sbuf[2];
						buffer[i*typesize+2] = sbuf[1];
						buffer[i*typesize+3] = sbuf[0];
						break;
					}
					default:
						break;
				}
			}
			
		}
}


void read_data(int *xd, int *yd, int *zd, float **data, 
			   /*float *span_t, float *orig_t,*/ const char *input_name)
{
	float c_float;
	unsigned char c_unchar;
	unsigned short c_unshort;
	int i,j,k;
	float *dataset;
	
	struct stat filestat;
	size_t size[3];
	int datatype = 0;
	int found;
	FILE *fp;
	
	size_t fread_return=0;
	
	
	
	if ((fp=fopen(input_name, "rb"))==NULL){
		printf("read error...\n");
		exit(0);
	}
	stat(input_name, &filestat);
	
	/* reading RAWIV header */
	fread_return = fread(minext, sizeof(float), 3, fp);
	fread_return = fread(maxext, sizeof(float), 3, fp);
	fread_return = fread(&nverts, sizeof(int), 1, fp);
	fread_return = fread(&ncells, sizeof(int), 1, fp);
	//#ifdef _LITTLE_ENDIAN
	if(!big_endian())
	  {
	    swap_buffer((char *)minext, 3, sizeof(float));
	    swap_buffer((char *)maxext, 3, sizeof(float));
	    swap_buffer((char *)&nverts, 1, sizeof(int));
	    swap_buffer((char *)&ncells, 1, sizeof(int));
	  }
	//#endif  
	
	size[0] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) +
		nverts * sizeof(unsigned char);
	size[1] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) +
		nverts * sizeof(unsigned short);
	size[2] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) +
		nverts * sizeof(float);
	
	found = 0;
	for (i = 0; i < 3; i++)
		if (size[i] == (unsigned int)filestat.st_size)
		{
			if (found == 0)
			{
				datatype = i;
				found = 1;
			}
		}
			if (found == 0)
			{
				printf("Corrupted file or unsupported dataset type\n");
				exit(5);
			}
			
			
			fread_return = fread(dim, sizeof(unsigned int), 3, fp);
	fread_return = fread(orig, sizeof(float), 3, fp);
	fread_return = fread(span, sizeof(float), 3, fp);
	//#ifdef _LITTLE_ENDIAN
	if(!big_endian())
	  {
	    swap_buffer((char *)dim, 3, sizeof(unsigned int));
	    swap_buffer((char *)orig, 3, sizeof(float));
	    swap_buffer((char *)span, 3, sizeof(float));
	  }
	//#endif 
	/*
	 span_t[0] = span[0];
	 span_t[1] = span[1];
	 span_t[2] = span[2];
	 orig_t[0] = orig[0];
	 orig_t[1] = orig[1];
	 orig_t[2] = orig[2];
	 */
	XDIM = dim[0];
	YDIM = dim[1];
	ZDIM = dim[2];
	dataset = (float *)malloc(sizeof(float)*XDIM*YDIM*ZDIM);
	
	maxraw = -99999999.f;
	minraw = 99999999.f;
	
	if (datatype == 0) {
		printf("data type: unsigned char \n");
		for (i=0; i<ZDIM; i++)
			for (j=0; j<YDIM; j++)
				for (k=0; k<XDIM; k++) {
					fread_return = fread(&c_unchar, sizeof(unsigned char), 1, fp);
					dataset[IndexVect(k,j,i)]=(float)c_unchar;
					
					if (c_unchar > maxraw)
						maxraw = c_unchar;
					if (c_unchar < minraw)
						minraw = c_unchar;
				}
	}
		else if (datatype == 1) {
			printf("data type: unsigned short \n");
			for (i=0; i<ZDIM; i++)
				for (j=0; j<YDIM; j++)
					for (k=0; k<XDIM; k++) {
						fread_return = fread(&c_unshort, sizeof(unsigned short), 1, fp);
						//#ifdef _LITTLE_ENDIAN
						if(!big_endian())
						  swap_buffer((char *)&c_unshort, 1, sizeof(unsigned short));
						//#endif 
						dataset[IndexVect(k,j,i)]=(float)c_unshort;
						
						if (c_unshort > maxraw)
							maxraw = c_unshort;
						if (c_unshort < minraw)
							minraw = c_unshort;
					}
		}
			else if (datatype == 2) {
				printf("data type: float \n");
				for (i=0; i<ZDIM; i++) 
					for (j=0; j<YDIM; j++)
						for (k=0; k<XDIM; k++) {
							fread_return = fread(&c_float, sizeof(float), 1, fp);
							//#ifdef _LITTLE_ENDIAN
							if(!big_endian())
							  swap_buffer((char *)&c_float, 1, sizeof(float));
							//#endif 
							dataset[IndexVect(k,j,i)]=c_float;
							
							if (c_float > maxraw)
								maxraw = c_float;
							if (c_float < minraw)
								minraw = c_float;
						}
			}
				
				else {
					printf("error\n");
					fclose(fp);
					exit(1);
				}
				
				fclose(fp);
				
				for (i=0; i<ZDIM; i++) 
					for (j=0; j<YDIM; j++)
						for (k=0; k<XDIM; k++)
							dataset[IndexVect(k,j,i)] = 255*(dataset[IndexVect(k,j,i)] - 
															 minraw)/(maxraw-minraw); 
				
				printf("minimum = %f,   maximum = %f \n",minraw,maxraw);
				
				
				*xd = XDIM;
				*yd = YDIM;
				*zd = ZDIM;
				*data = dataset;
				
				loadedVolumeInfo.read(input_name);
}




#if 0
void read_data(int *xd, int *yd, int *zd, 
			   float **data, const char *input_name)
{
	float c_float;
	u_char c_unchar;
	u_short c_unshort;
	int i,j,k;
	float *dataset;
	
	struct stat filestat;
	size_t size[3];
	int datatype;
	int found;
	FILE *fp;
	
	
	
	if ((fp=fopen(input_name, "r"))==NULL){
		printf("read error...\n");
		exit(0);
	}
	stat(input_name, &filestat);
	
	/* reading RAWIV header */
	fread(minext, sizeof(float), 3, fp);
	fread(maxext, sizeof(float), 3, fp);
	fread(&nverts, sizeof(int), 1, fp);
	fread(&ncells, sizeof(int), 1, fp);
	
	size[0] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(u_int) +
		nverts * sizeof(u_char);
	size[1] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(u_int) +
		nverts * sizeof(u_short);
	size[2] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(u_int) +
		nverts * sizeof(float);
	
	found = 0;
	for (i = 0; i < 3; i++)
		if (size[i] == filestat.st_size)
		{
			if (found == 0)
			{
				datatype = i;
				found = 1;
			}
		}
			if (found == 0)
			{
				printf("Corrupted file or unsupported dataset type\n");
				exit(5);
			}
			
			
			fread(dim, sizeof(u_int), 3, fp);
	fread(orig, sizeof(float), 3, fp);
	fread(span, sizeof(float), 3, fp);
	XDIM = dim[0];
	YDIM = dim[1];
	ZDIM = dim[2];
	
	
	dataset = (float *)malloc(sizeof(float)*XDIM*YDIM*ZDIM);
	
	
	/* reading the data */
	maxraw = -99999999;
	minraw = 99999999;
	
	if (datatype == 0) {
		printf("data type: unsigned char \n");
		for (i=0; i<ZDIM; i++)
			for (j=0; j<YDIM; j++)
				for (k=0; k<XDIM; k++) {
					fread(&c_unchar, sizeof(u_char), 1, fp);
					dataset[IndexVect(k,j,i)]=(float)c_unchar;
					
					if (c_unchar > maxraw)
						maxraw = c_unchar;
					if (c_unchar < minraw)
						minraw = c_unchar;
					
				}
	}
		
		else if (datatype == 1) {
			printf("data type: unsigned short \n");
			for (i=0; i<ZDIM; i++)
				for (j=0; j<YDIM; j++)
					for (k=0; k<XDIM; k++) {
						fread(&c_unshort, sizeof(u_short), 1, fp);
						dataset[IndexVect(k,j,i)]=(float)c_unshort;
						
						if (c_unshort > maxraw)
							maxraw = c_unshort;
						if (c_unshort < minraw)
							minraw = c_unshort;
						
					}
		}
			
			else if (datatype == 2) {
				printf("data type: float \n");
				for (i=0; i<ZDIM; i++) 
					for (j=0; j<YDIM; j++)
						for (k=0; k<XDIM; k++) {
							fread(&c_float, sizeof(float), 1, fp);
							dataset[IndexVect(k,j,i)]=c_float;
							
							if (c_float > maxraw)
								maxraw = c_float;
							if (c_float < minraw)
								minraw = c_float;
							
						}
			}
				
				else {
					printf("error\n");
					fclose(fp);
					exit(1);
				}
				
				fclose(fp);
				
				for (i=0; i<ZDIM; i++) 
					for (j=0; j<YDIM; j++)
						for (k=0; k<XDIM; k++)
							dataset[IndexVect(k,j,i)] = 255*(dataset[IndexVect(k,j,i)] - 
															 minraw)/(maxraw-minraw); 
				
				printf("minimum = %f,   maximum = %f \n",minraw,maxraw);
				
				*xd = XDIM;
				*yd = YDIM;
				*zd = ZDIM;
				*data = dataset;
				
}
#endif

void write_rawiv_float(float *result,FILE* fp)
{
	int i, j, k;
	float c_float;
	size_t fwrite_return;
	
	
	//#ifdef _LITTLE_ENDIAN
	if(!big_endian())
	  {
	    swap_buffer((char *)minext, 3, sizeof(float));
	    swap_buffer((char *)maxext, 3, sizeof(float));
	    swap_buffer((char *)&nverts, 1, sizeof(int));
	    swap_buffer((char *)&ncells, 1, sizeof(int));
	    swap_buffer((char *)dim, 3, sizeof(unsigned int));
	    swap_buffer((char *)orig, 3, sizeof(float));
	    swap_buffer((char *)span, 3, sizeof(float));
	  }
	//#endif 
	
	fwrite_return = fwrite(minext, sizeof(float), 3, fp);
	fwrite_return = fwrite(maxext, sizeof(float), 3, fp);
	fwrite_return = fwrite(&nverts, sizeof(int), 1, fp);
	fwrite_return = fwrite(&ncells, sizeof(int), 1, fp);
	fwrite_return = fwrite(dim, sizeof(unsigned int), 3, fp);
	fwrite_return = fwrite(orig, sizeof(float), 3, fp);
	fwrite_return = fwrite(span, sizeof(float), 3, fp);
	//#ifdef _LITTLE_ENDIAN
	if(!big_endian())
	  {
	    swap_buffer((char *)minext, 3, sizeof(float));
	    swap_buffer((char *)maxext, 3, sizeof(float));
	    swap_buffer((char *)&nverts, 1, sizeof(int));
	    swap_buffer((char *)&ncells, 1, sizeof(int));
	    swap_buffer((char *)dim, 3, sizeof(unsigned int));
	    swap_buffer((char *)orig, 3, sizeof(float));
	    swap_buffer((char *)span, 3, sizeof(float));
	  }
	//#endif 
	
	for (k=0; k<ZDIM; k++) 
		for (j=0; j<YDIM; j++)
			for (i=0; i<XDIM; i++) {
				
				c_float = result[IndexVect(i,j,k)];
				
				//#ifdef _LITTLE_ENDIAN
				if(!big_endian())
				  swap_buffer((char *)&c_float, 1, sizeof(float));
				//#endif 
				fwrite_return = fwrite(&c_float, sizeof(float), 1, fp);
				//#ifdef _LITTLE_ENDIAN
				if(!big_endian())
				  swap_buffer((char *)&c_float, 1, sizeof(float));
				//#endif 
			}
				
				fclose(fp);
}



#if 0
void write_rawv(int XDIM, int YDIM, int ZDIM, float *dataset, 
		unsigned char *result, FILE* fp, FILE* fp2)
{
	int i, j, k;
	unsigned char c;
//	float c_float;
	unsigned char c_unchar;
	
	unsigned int	MagicNumW=0xBAADBEEF;
	unsigned int	NumTimeStep, NumVariable;
	float		MinXYZT[4], MaxXYZT[4];
	unsigned char	VariableType[100];
	char		*VariableName[100];
	int m;
	
	
	
	NumTimeStep = 1;
	NumVariable = 4;
	MinXYZT[0]=0;
	MinXYZT[1]=0;
	MinXYZT[2]=0;
	MinXYZT[3]=0;
	MaxXYZT[0]=XDIM-1.f;
	MaxXYZT[1]=YDIM-1.f;
	MaxXYZT[2]=ZDIM-1.f;
	MaxXYZT[3]=1;
	VariableType[0] = 1;
	VariableName[0] = (char*)malloc(sizeof(char)*64);
	strcpy (VariableName[0], "red\n");
	VariableType[1] = 1;
	VariableName[1] = (char*)malloc(sizeof(char)*64);
	strcpy (VariableName[1], "green");
	VariableType[2] = 1;
	VariableName[2] = (char*)malloc(sizeof(char)*64);
	strcpy (VariableName[2], "blue");
	VariableType[3] = 1;
	VariableName[3] = (char*)malloc(sizeof(char)*64);
	strcpy (VariableName[3], "alpha");
	
	fwrite(&MagicNumW, sizeof(unsigned int), 1, fp2);
	fwrite(&XDIM, sizeof(unsigned int), 1, fp2);
	fwrite(&YDIM, sizeof(unsigned int), 1, fp2);
	fwrite(&ZDIM, sizeof(unsigned int), 1, fp2);
	fwrite(&NumTimeStep, sizeof(unsigned int), 1, fp2);
	fwrite(&NumVariable, sizeof(unsigned int), 1, fp2);
	fwrite(MinXYZT, sizeof(float), 4, fp2);
	fwrite(MaxXYZT, sizeof(float), 4, fp2);
	for (m=0; m<(int)NumVariable; m++) {
		fwrite(&VariableType[m], sizeof(unsigned char), 1, fp2);
		fwrite(&VariableName[m], sizeof(unsigned char), 64, fp2);
	}
	
	
	for (k=0; k<ZDIM; k++)
		for (j=0; j<YDIM; j++)
			for (i=0; i<XDIM; i++) {
				c = result[IndexVect(i,j,k)];
				if (c == 1) {
					c_unchar = 255/*dataset[IndexVect(i,j,k)]/255.0*/;
					fwrite(&c_unchar, sizeof(u_char), 1, fp2);
				}
				else if (c == 2) {
					c_unchar = 0;
					fwrite(&c_unchar, sizeof(u_char), 1, fp2);
				}
				else {
					c_unchar = 0;
					fwrite(&c_unchar, sizeof(u_char), 1, fp2);
				}
			}
				
				
				for (k=0; k<ZDIM; k++)
					for (j=0; j<YDIM; j++)
						for (i=0; i<XDIM; i++) {
							c = result[IndexVect(i,j,k)];
							if (c == 1) {
								c_unchar = 0;
								fwrite(&c_unchar, sizeof(u_char), 1, fp2);
							}
							else if (c == 2) {
								c_unchar = 255/*dataset[IndexVect(i,j,k)]/255.0*/;
								fwrite(&c_unchar, sizeof(u_char), 1, fp2);
							}
							else {
								c_unchar = 0;
								fwrite(&c_unchar, sizeof(u_char), 1, fp2);
							}
						}
							
							
							for (k=0; k<ZDIM; k++)
								for (j=0; j<YDIM; j++)
									for (i=0; i<XDIM; i++) {
										c = result[IndexVect(i,j,k)];
										if (c == 1) {
											c_unchar = 0;
											fwrite(&c_unchar, sizeof(u_char), 1, fp2);
										}
										else if (c == 2) {
											c_unchar = 0;
											fwrite(&c_unchar, sizeof(u_char), 1, fp2);
										}
										else {
											c_unchar = 0;
											fwrite(&c_unchar, sizeof(u_char), 1, fp2);
										}
									}
										
										for (k=0; k<ZDIM; k++)
											for (j=0; j<YDIM; j++)
												for (i=0; i<XDIM; i++) {
													c = result[IndexVect(i,j,k)];
													if (c == 1) {
														c_unchar = 255/*(dataset[IndexVect(i,j,k)]-125)/130.0*/;
														fwrite(&c_unchar, sizeof(u_char), 1, fp2);
													}
													else if (c == 2) {
														c_unchar = 255/*(dataset[IndexVect(i,j,k)]-125)/130.0*/;
														fwrite(&c_unchar, sizeof(u_char), 1, fp2);
													}
													else {
														c_unchar = 0;
														fwrite(&c_unchar, sizeof(u_char), 1, fp2);
													}
												}
													
													fclose(fp2);
	
}

#endif

};
예제 #9
0
void read_data(int *xd, int *yd, int *zd, float **data, 
			   /*float *span_t, float *orig_t,*/ const char *input_name)
{
	float c_float;
	unsigned char c_unchar;
	unsigned short c_unshort;
	int i,j,k;
	float *dataset;
	
	struct stat filestat;
	size_t size[3];
	int datatype = 0;
	int found;
	FILE *fp;
	
	size_t fread_return=0;
	
	
	
	if ((fp=fopen(input_name, "rb"))==NULL){
		printf("read error...\n");
		exit(0);
	}
	stat(input_name, &filestat);
	
	/* reading RAWIV header */
	fread_return = fread(minext, sizeof(float), 3, fp);
	fread_return = fread(maxext, sizeof(float), 3, fp);
	fread_return = fread(&nverts, sizeof(int), 1, fp);
	fread_return = fread(&ncells, sizeof(int), 1, fp);
	//#ifdef _LITTLE_ENDIAN
	if(!big_endian())
	  {
	    swap_buffer((char *)minext, 3, sizeof(float));
	    swap_buffer((char *)maxext, 3, sizeof(float));
	    swap_buffer((char *)&nverts, 1, sizeof(int));
	    swap_buffer((char *)&ncells, 1, sizeof(int));
	  }
	//#endif  
	
	size[0] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) +
		nverts * sizeof(unsigned char);
	size[1] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) +
		nverts * sizeof(unsigned short);
	size[2] = 12 * sizeof(float) + 2 * sizeof(int) + 3 * sizeof(unsigned int) +
		nverts * sizeof(float);
	
	found = 0;
	for (i = 0; i < 3; i++)
		if (size[i] == (unsigned int)filestat.st_size)
		{
			if (found == 0)
			{
				datatype = i;
				found = 1;
			}
		}
			if (found == 0)
			{
				printf("Corrupted file or unsupported dataset type\n");
				exit(5);
			}
			
			
			fread_return = fread(dim, sizeof(unsigned int), 3, fp);
	fread_return = fread(orig, sizeof(float), 3, fp);
	fread_return = fread(span, sizeof(float), 3, fp);
	//#ifdef _LITTLE_ENDIAN
	if(!big_endian())
	  {
	    swap_buffer((char *)dim, 3, sizeof(unsigned int));
	    swap_buffer((char *)orig, 3, sizeof(float));
	    swap_buffer((char *)span, 3, sizeof(float));
	  }
	//#endif 
	/*
	 span_t[0] = span[0];
	 span_t[1] = span[1];
	 span_t[2] = span[2];
	 orig_t[0] = orig[0];
	 orig_t[1] = orig[1];
	 orig_t[2] = orig[2];
	 */
	XDIM = dim[0];
	YDIM = dim[1];
	ZDIM = dim[2];
	dataset = (float *)malloc(sizeof(float)*XDIM*YDIM*ZDIM);
	
	maxraw = -99999999.f;
	minraw = 99999999.f;
	
	if (datatype == 0) {
		printf("data type: unsigned char \n");
		for (i=0; i<ZDIM; i++)
			for (j=0; j<YDIM; j++)
				for (k=0; k<XDIM; k++) {
					fread_return = fread(&c_unchar, sizeof(unsigned char), 1, fp);
					dataset[IndexVect(k,j,i)]=(float)c_unchar;
					
					if (c_unchar > maxraw)
						maxraw = c_unchar;
					if (c_unchar < minraw)
						minraw = c_unchar;
				}
	}
		else if (datatype == 1) {
			printf("data type: unsigned short \n");
			for (i=0; i<ZDIM; i++)
				for (j=0; j<YDIM; j++)
					for (k=0; k<XDIM; k++) {
						fread_return = fread(&c_unshort, sizeof(unsigned short), 1, fp);
						//#ifdef _LITTLE_ENDIAN
						if(!big_endian())
						  swap_buffer((char *)&c_unshort, 1, sizeof(unsigned short));
						//#endif 
						dataset[IndexVect(k,j,i)]=(float)c_unshort;
						
						if (c_unshort > maxraw)
							maxraw = c_unshort;
						if (c_unshort < minraw)
							minraw = c_unshort;
					}
		}
			else if (datatype == 2) {
				printf("data type: float \n");
				for (i=0; i<ZDIM; i++) 
					for (j=0; j<YDIM; j++)
						for (k=0; k<XDIM; k++) {
							fread_return = fread(&c_float, sizeof(float), 1, fp);
							//#ifdef _LITTLE_ENDIAN
							if(!big_endian())
							  swap_buffer((char *)&c_float, 1, sizeof(float));
							//#endif 
							dataset[IndexVect(k,j,i)]=c_float;
							
							if (c_float > maxraw)
								maxraw = c_float;
							if (c_float < minraw)
								minraw = c_float;
						}
			}
				
				else {
					printf("error\n");
					fclose(fp);
					exit(1);
				}
				
				fclose(fp);
				
				for (i=0; i<ZDIM; i++) 
					for (j=0; j<YDIM; j++)
						for (k=0; k<XDIM; k++)
							dataset[IndexVect(k,j,i)] = 255*(dataset[IndexVect(k,j,i)] - 
															 minraw)/(maxraw-minraw); 
				
				printf("minimum = %f,   maximum = %f \n",minraw,maxraw);
				
				
				*xd = XDIM;
				*yd = YDIM;
				*zd = ZDIM;
				*data = dataset;
				
				loadedVolumeInfo.read(input_name);
}