예제 #1
0
int main(int argc,char *argv[])
{
  VolMagick::Volume v;
  VolMagick::readVolumeFile(v,argv[1]);

  UniformGrid ugrid(1,1,1);
  ugrid.importVolume(v);
  Point min,max;
  min.x=v.XMin();
  min.y=v.YMin();
  min.z=v.ZMin();
  max.x=v.XMax();
  max.y=v.YMax();
  max.z=v.ZMax();

//generateGridFile(min,max,v.XDim(),v.YDim(),v.ZDim());

  Mesh *mesh=new Mesh();

  float iso_val=atof(argv[2]);

  Mesher mesher;

  mesher.setGrid((Grid &)(ugrid));
  mesher.setMesh(mesh);

  mesher.generateMesh(iso_val);

 // mesh->correctNormals();
  mesher.saveMesh(string(argv[3]),&v);
  delete mesh;
  
  return 0;
}
void getMaterialIds(VolMagick::Volume &vol,vector<int> &matIds)
{
  int xdim=vol.XDim(),
      ydim=vol.YDim(),
      zdim=vol.ZDim();

  set<int> materials;

  for(int i=0;i<xdim;i++)
    for(int j=0;j<ydim;j++)
      for(int k=0;k<zdim;k++)
        materials.insert(vol(i,j,k));

  for(set<int>::iterator sIter=materials.begin();sIter!=materials.end();sIter++)
    if(*sIter!=0)
        matIds.push_back(*sIter);
  
}
void generatePartitionSurfaceByMC(VolMagick::Volume& vol, int &matId, MMHLS::Mesh *mesh)
{
	VolMagick::Volume tempv;
	tempv = vol;

	for(int i=0; i<vol.XDim(); i++)
	 for(int j=0; j<vol.YDim(); j++)
	   for(int k=0; k<vol.ZDim(); k++)
	    {
			if(vol(i,j,k) == matId)
				tempv(i,j,k, 1.0);
			else 
				tempv(i,j,k, 0.0);
		}
	FastContouring::ContourExtractor *contexa;
	contexa = new FastContouring::ContourExtractor;

	contexa->setVolume(tempv);
	FastContouring::TriSurf result = contexa->extractContour(0.5);
	for(int i =0; i<result.verts.size(); i+=3)
	{
		vector<float> vert;
		vert.push_back(result.verts[i]);
		vert.push_back(result.verts[i+1]);
		vert.push_back(result.verts[i+2]);
		mesh->vertexList.push_back(vert);
	}

	for(int i=0; i<result.tris.size(); i+=3)
	{
		vector <unsigned int > t;
		t.push_back(result.tris[i]);
		t.push_back(result.tris[i+1]);
		t.push_back(result.tris[i+2]);
		mesh->faceList.push_back(t);
	}
	delete contexa;

}
예제 #4
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;
}
예제 #5
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;
}
예제 #6
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;
}
예제 #7
0
int main(int argc, char **argv)
{
  if(argc < 4)
    {
      std:: cerr << 
	"Usage: " << argv[0] << 

"  inputmesh inputvol outputMesh [range]\n";
      return 1;
    }

  try
    {

	  geometry geom;
	  cvcraw_geometry::read(geom, string(argv[1]));

      VolMagick::Volume inputVol;


      VolMagick::readVolumeFile(inputVol,argv[2]); ///input volume
     
      double range = 0; bool gotRange = false;
      if( argc > 4 ) {
         range = atof( argv[4] );
         gotRange = true;
std::cout << "got range: " << range << std::endl;
      }
      
	  float x,y,z;

	  float value; 
	  
	  color_t color;

	  COLOUR c;

        if( !gotRange ) {
          // compute range, max absolute value
	  for(int i=0; i< geom.points.size(); i++)
	  {
	  		x = geom.points[i][0];
			y = geom.points[i][1];
			z = geom.points[i][2];


	  		value = inputVol.interpolate(x,y,z);
			if( range  < fabs( value ) ) range = fabs( value );
	   }
	}
	 
std::cout<<"range: "<< range << std::endl;
	  for(int i=0; i< geom.points.size(); i++)
	  {
	  		x = geom.points[i][0];
			y = geom.points[i][1];
			z = geom.points[i][2];


	  		value = inputVol.interpolate(x,y,z);
  	
	        c=GetColour(value, range);
			
	        color[0] = c.r;
			color[1] = c.g;
			color[2] = c.b;

			geom.colors.push_back(color);
	  }

	cvcraw_geometry::write(geom, string(argv[3]));

     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;
}
예제 #8
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;
}
예제 #9
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;
}
예제 #10
0
void GeometryInterface::setViewerState()
{
  using namespace std;
  using namespace boost;

  // static log4cplus::Logger logger = log4cplus::getFuncLogger();
  static log4cplus::Logger logger = FUNCTION_LOGGER;

  //so it responds to volumeInterfaceViewer.* property changes
  _geometryInterfaceViewer->setObjectName("geometryInterfaceViewer");

  CVC_NAMESPACE::PropertyMap properties;
  properties["geometryInterfaceViewer.rendering_mode"] = "colormapped";
  properties["geometryInterfaceViewer.shaded_rendering_enabled"] = "false";
  properties["geometryInterfaceViewer.draw_bounding_box"] = "true";
  properties["geometryInterfaceViewer.draw_subvolume_selector"] = "false";
  // arand, 6-14-2011: changed default below to 0.5
  properties["geometryInterfaceViewer.volume_rendering_quality"] = "0.5"; //[0.0,1.0]
  properties["geometryInterfaceViewer.volume_rendering_near_plane"] = "0.0";
  properties["geometryInterfaceViewer.projection_mode"] = "perspective";
  properties["geometryInterfaceViewer.draw_corner_axis"] = "true";
  properties["geometryInterfaceViewer.draw_geometry"] = "true";
  properties["geometryInterfaceViewer.draw_volumes"] = "true";
  properties["geometryInterfaceViewer.clip_geometry"] = "true";
  properties["geometryInterfaceViewer.volumes"] = "";
  properties["geometryInterfaceViewer.geometry_line_width"] = "1.2";
  properties["geometryInterfaceViewer.background_color"] = "#000000";

  //stereo related properties
  properties["geometryInterfaceViewer.io_distance"] = "0.062";
  properties["geometryInterfaceViewer.physical_distance_to_screen"] = "2.0";
  properties["geometryInterfaceViewer.physical_screen_width"] = "1.8";
  properties["geometryInterfaceViewer.focus_distance"] = "1000.0";

  //viewers_transfer_function should be a boost::shared_array<float>
  //on the data map.
  properties["geometryInterfaceViewer.transfer_function"] = "none";

  cvcapp.addProperties(properties);

  //set up the volume bounding box to encompass the geometry
  vector<cvcraw_geometry::cvcgeom_t> geoms =
    _geometryInterfaceViewer->getGeometriesFromDatamap();
  LOG4CPLUS_TRACE(logger, "geoms.size() == " << geoms.size());
  // cvcapp.log(3,str(format("%s :: geoms.size() == %s\n")
  //                  % BOOST_CURRENT_FUNCTION
  //                  % geoms.size()));

  if(geoms.empty())
    {
      //just use the default bounding box of a volume
      _geometryInterfaceViewer->colorMappedVolume(VolMagick::Volume());
      _geometryInterfaceViewer->rgbaVolumes(vector<VolMagick::Volume>());
    }
  else
    {
      VolMagick::BoundingBox bbox;
      cvcraw_geometry::cvcgeom_t initial_geom;
      
      //find a non empty geom to supply an initial bbox
      BOOST_FOREACH(cvcraw_geometry::cvcgeom_t geom, geoms)
        if(!geom.empty())
          {
            initial_geom = geom;
            break;
          }
      
      cvcraw_geometry::cvcgeom_t::point_t minpt;
      cvcraw_geometry::cvcgeom_t::point_t maxpt;
      if(initial_geom.empty())
        {
          //no non empty geometry so lets just use the default box
          _geometryInterfaceViewer->colorMappedVolume(VolMagick::Volume());
          _geometryInterfaceViewer->rgbaVolumes(vector<VolMagick::Volume>());
        }
      else
        {
          minpt = initial_geom.min_point();
          maxpt = initial_geom.max_point();
          // arand: slightly enlarging
          double eps0 = (maxpt[0]-minpt[0])/20.0;
          double eps1 = (maxpt[1]-minpt[1])/20.0;
          double eps2 = (maxpt[2]-minpt[2])/20.0;
          
          bbox = VolMagick::BoundingBox(minpt[0]-eps0,minpt[1]-eps1,minpt[2]-eps2,
                                        maxpt[0]+eps0,maxpt[1]+eps1,maxpt[2]+eps2);
        }
      
      //build a bounding box that encompasses all bounding boxes of the geometries
      BOOST_FOREACH(cvcraw_geometry::cvcgeom_t geom, geoms)
        {
          if(geom.empty()) continue;
          minpt = geom.min_point();
          maxpt = geom.max_point();
          VolMagick::BoundingBox geobox(minpt[0],minpt[1],minpt[2],
                                        maxpt[0],maxpt[1],maxpt[2]);
          
          cvcapp.log(5,str(boost::format("geobox: (%f,%f,%f) (%f,%f,%f)")
                           % geobox.minx % geobox.miny % geobox.minz
                           % geobox.maxx % geobox.maxy % geobox.maxz));
          cvcapp.log(5,str(boost::format("bbox: (%f,%f,%f) (%f,%f,%f)")
                           % bbox.minx % bbox.miny % bbox.minz
                           % bbox.maxx % bbox.maxy % bbox.maxz));
          
          bbox += geobox;
        }
      
      VolMagick::Volume newvol;
      newvol.boundingBox(bbox);
      _geometryInterfaceViewer->colorMappedVolume(newvol);
      _geometryInterfaceViewer->rgbaVolumes(vector<VolMagick::Volume>(4,newvol));
    }
}
예제 #11
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;
}
예제 #12
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;
}
예제 #13
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;
}
예제 #14
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;
}
예제 #15
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;
}
예제 #16
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;
}
예제 #17
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;
}
예제 #18
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;
}
예제 #19
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;
}
예제 #20
0
int main(int argc, char **argv)
{
  VolMagick::uint64 width, height, depth, i, j, k;
  Image cur;
  unsigned char *buf;

  if(argc < 3)
    {
      cout << "Usage: " << argv[0] << " <img0> <img1> ... <output volume>" << endl;
      return 0;
    }

  try
    {
#if 0
      // get width and height.  All images should have the same width and height
      // or this program will explode!!!!
      cur.read(argv[1]);
      width = cur.size().width();
      height = cur.size().height();

      cerr << "Image dimensions: " << width << ", " << height << endl;

      // get the depth
      depth = argc-2;
      cerr << "Volume dimensions: " << width << ", " << height << ", " << depth << endl;

      // allocate the slice buffer and open the volume file
      buf = (unsigned char *)malloc(width*height*sizeof(unsigned char));
      outvol = fopen(argv[argc-1],"wb");
      if(outvol == NULL)
	{
	  cerr << "Unable to open output file '" << argv[argc-1] << "'" << endl;
	  return 1;
	}

      // fill out the header and write it
      header.min[0] = 0.0; header.min[1] = 0.0; header.min[2] = 0.0;
      header.max[0] = float(width-1); header.max[1] = float(height-1); header.max[2] = float(depth-1);
      header.numVerts = width * height * depth;
      header.numCells = (width-1)*(height-1)*(depth-1);
      header.dim[0] = width; header.dim[1] = height; header.dim[2] = depth;
      header.origin[0] = header.origin[1] = header.origin[2] = 0.0;
      header.span[0] = 1.0; header.span[1] = 1.0; header.span[2] = 1.0;

      if(!big_endian())
	{
	  for(i=0; i<3; i++) SWAP_32(&(header.min[i]));
	  for(i=0; i<3; i++) SWAP_32(&(header.max[i]));
	  SWAP_32(&(header.numVerts));
	  SWAP_32(&(header.numCells));
	  for(i=0; i<3; i++) SWAP_32(&(header.dim[i]));
	  for(i=0; i<3; i++) SWAP_32(&(header.origin[i]));
	  for(i=0; i<3; i++) SWAP_32(&(header.span[i]));
	}

      fwrite(&header,sizeof(RawIVHeader),1,outvol);

      //now write out each image slice
      for(k=0; k<depth; k++)
	{
	  cur.read(Geometry(width,height),argv[k+1]);
	  cur.modifyImage();
	  cur.type(GrayscaleType);
	  /*
	   * We only need 1 value since after grayscale conversion R = G = B
	   */
	  cur.write(0,0,width,height,"R",CharPixel,buf);

	  /*
	    const PixelPacket *pixel_cache = cur.getConstPixels(0,0,width,height);
	    for(i=0; i<width; i++)
	    for(j=0; j<height; j++)
	    {
	    const PixelPacket *pixel = pixel_cache+j*width+i;
	    if(pixel  == NULL) cout << "i: " << i << ", j: " << j << endl;
	    ColorRGB c(*pixel);
	    buf[j*width+i] = (unsigned char)(c.green()*255.0);
	    }
	  */

	  fwrite(buf,sizeof(unsigned char),width*height,outvol);
	}

      free(buf);
      fclose(outvol);
#endif

      // get width and height.  All images should have the same width and height
      // or this program will explode!!!!
      cur.read(argv[1]);
      width = cur.size().width();
      height = cur.size().height();

      // get the depth
      depth = argc-2;
      cerr << "Volume dimensions: " << width << ", " << height << ", " << depth << endl;

      VolMagick::createVolumeFile(argv[argc-1],
				  VolMagick::BoundingBox(0.0,0.0,0.0,
							 double(width-1),double(height-1),double(depth-1)),
				  VolMagick::Dimension(width,height,depth));

      VolMagick::Volume buf;
      buf.dimension(VolMagick::Dimension(width,height,1));

      //now write out each image slice
      for(k=0; k<depth; k++)
	{
	  cur.read(Geometry(width,height),argv[k+1]);
	  cur.modifyImage();
	  cur.type(GrayscaleType);
	  /*
	   * We only need 1 value since after grayscale conversion R = G = B
	   */
	  cur.write(0,0,width,height,"R",CharPixel,*buf);

	  /*
	    const PixelPacket *pixel_cache = cur.getConstPixels(0,0,width,height);
	    for(i=0; i<width; i++)
	    for(j=0; j<height; j++)
	    {
	    const PixelPacket *pixel = pixel_cache+j*width+i;
	    if(pixel  == NULL) cout << "i: " << i << ", j: " << j << endl;
	    ColorRGB c(*pixel);
	    buf[j*width+i] = (unsigned char)(c.green()*255.0);
	    }
	  */

	  //fwrite(buf,sizeof(unsigned char),width*height,outvol);
	  VolMagick::writeVolumeFile(buf,argv[argc-1],0,0,
				     0,0,k);

	  if(depth>1)
	    fprintf(stderr,"%5.2f %%\r",(double(k)/double(depth-1))*100.0);
	}
      fprintf(stderr,"\nDone!\n");
    }
  catch(std::exception &error_)
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }

  return 0;
}
예제 #21
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);
        }      
      }
  }
예제 #22
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;
}
예제 #23
0
int main(int argc, char **argv)
{
  if(argc != 6)
    {
      cerr << "Usage: " << argv[0] << " <input Original volume file> <input cutvolume> <input seed file ><Rotate Num> <output seed file>" << endl;
      return 1;
    }

  try
    {
      VolMagickOpStatus status;
      VolMagick::setDefaultMessenger(&status);

      VolMagick::Volume inputVol;
	  VolMagick::VolumeFileInfo inputVol2info;

      VolMagick::readVolumeFile(inputVol, argv[1]);
	  inputVol2info.read(argv[2]);
	//  fstream fs;
//	  fs.open(argv[3]);

	  ifstream fs;
	  fs.open(argv[3], ios::in);
	  readUntilNewline(fs);
	  readUntilNewline(fs);
	  readUntilNewline(fs);

	  string s1, s2;

	  int seeda, seedb, seedc;
	  int Num = atoi(argv[4]);


	 float cx = (inputVol.XMin()+inputVol.XMax())*0.5;
	 float cy = (inputVol.YMin() + inputVol.YMax())*0.5;
	 
	 int ni, nj, nk;
	 float x, y;
    
         vector<vector<int> > seed(Num);
	  // vector <int>  seed[Num];
  
	 float x0, y0, z0;
	 
	while(fs>>s1>>seedb>>seedc>>s2){
  		seeda = atoi(s1.erase(0,7).c_str());
	//	cout<<seeda<< " "<< seedb<<" " <<seedc<<" " <<endl;
	    x0 = inputVol2info.XMin() + seeda * inputVol2info.XSpan();
		y0 = inputVol2info.YMin() + seedb * inputVol2info.YSpan();
	    z0 = inputVol2info.ZMin() + seedc * inputVol2info.ZSpan();


		 for(int num=0; num<Num; num ++)
		 {	
	 	 	float  nx = cos(2.0*Pi*(float)num/(float)Num)*(x0-cx) - sin(2.0*Pi*(float)num/(float)Num)*(y0-cy) + cx;
			float  ny = sin(2.0*Pi*(float)num/(float)Num)*(x0-cx) + cos(2.0*Pi*(float)num/(float)Num)*(y0-cy) + cy;
			ni = (int)((nx-inputVol.XMin())/inputVol.XSpan()+0.5);
			nj = (int)((ny-inputVol.YMin())/inputVol.YSpan()+0.5);
            nk = (int)((z0-inputVol.ZMin())/inputVol.ZSpan()+0.5);
			if(ni>=inputVol.XDim()||nj >= inputVol.YDim()|| nk >= inputVol.ZDim()|| ni<0 || nj <0 || nk <0) continue;
			else
			{
			   seed[num].push_back(ni);
			   seed[num].push_back(nj);
			   seed[num].push_back(nk);
			}
		 }
	  }
	  fs.close();

	  fstream fs1;
	  fs1.open(argv[5], ios::out);
	  fs1<<"<!DOCTYPE pointclassdoc>"<<endl;
	  fs1<<"<pointclassdoc>" <<endl;

	  string str[13]={"ffff00", "ff0000","00ff00","ff00ff","0000ff","ff5500","336699", "00ffff", "c0c0c0","800000", "800080", "808000", "008080"};
	  
	  if(Num>13) cout<<"You need add more colors." <<endl;
	  for(int num=0; num< Num; num++)
	  {
	  	 fs1<<" <pointclass timestep=\"0\" name=\"Class "<<num<<"\" color="<<"\"#"<<str[num]<<"\" variable=\"0\" >"<<endl;
		 for(int j = 0; j < seed[num].size()/3; j++)
		  fs1<<"  <point>" <<seed[num][3*j] <<" "<< seed[num][3*j+1] <<" "<<seed[num][3*j+2]<<"</point>"<<endl;
		 fs1<<" </pointclass>"<<endl;
	  }
	  fs1<<"</pointclassdoc>"<<endl;

	  fs1.close();

     cout<<"done !" <<endl;

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

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

}
예제 #25
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;
}
예제 #26
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;
}
예제 #27
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;
}
예제 #28
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;
}
예제 #29
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;
}
int main(int argc, char *argv[])
{
	if(argc<3)
	{
		cout<<argv[0]<<" <input volume> <output volume>"<<endl;
		return 1;
	}

	//Read the rawiv; count the number of unique values.
	VolMagick::Volume vol;
	VolMagick::readVolumeFile(vol,argv[1]);
	
	int x=vol.XDim(),y=vol.YDim(),z=vol.ZDim();
	
	VolMagick::Volume newvol(VolMagick::Dimension(x,y,z),VolMagick::Float,vol.boundingBox());

	vector<double> unique;
	double value;

	map<int, int> myMap;
	map<int,int>::iterator it;

  //  cout<<"vol[1]:" << vol(1,1,1) <<endl;
	// Go through the data set, checking every value. If the value is not in unique, add to unique.
	for(int i=0;i<x;i++)
		for(int j=0;j<y;j++)
			for(int k=0;k<z;k++)
			{
				value=vol(i,j,k);
				int l=0;
				for(;l<unique.size();l++)
					if(unique[l]==value) break;
				if(l==unique.size())
				{
					unique.push_back(value);
				//	myMap[value] = l;
				}
			}
	cout<<"Unique values found are: ";
	for(int i=0;i<unique.size();i++) 
	{
	cout<<unique[i]<<" ";
	myMap[unique[i]]=i;
	}
	cout<<endl;

//	cout<<"mymap size "<<myMap.size() <<endl;
//	for(it=myMap.begin(); it!=myMap.end(); ++it)
//	cout<<(*it).first<<" "<<(*it).second <<" "<<endl;
//	cout << endl;

	//Now go through the data again, and this time replace the values.
	for(int i=0;i<x;i++)
		for(int j=0;j<y;j++)
			for(int k=0;k<z;k++)
			{

			/*	value=vol(i,j,k);
				int l=0;
				for(;l<unique.size();l++)
					if(unique[l]==value) break;
				if(value!=0)
					newvol(i,j,k, (l+1));
				else
					newvol(i,j,k,0); */

				value = vol(i,j,k);
			//	if(value >= unique.size()) newvol(i,j,k, 0);
			//	else newvol(i,j,k, value+1);
				newvol(i,j,k, myMap[value]);
			}


	//Write the file out
	VolMagick::createVolumeFile(newvol,argv[2]);  
	cout<<"done !"<<endl;
}