Example #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;
}
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;

}
Example #4
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;
}
Example #5
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;
}
Example #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;
}
Example #7
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;
}
Example #8
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;
}
Example #9
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;
}
Example #10
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;
}
Example #11
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;
}
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;
}
Example #13
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;
}
Example #14
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;

}
Example #15
0
int main(int argc, char **argv)
{
  if(argc != 6)
    {
      cerr << "Usage: " << argv[0] << " <input Original volume file>  <input seed file ><input real axis> <Rotate Num> <output seed file>" << endl;
      return 1;
    }

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

      VolMagick::Volume inputVol;

      VolMagick::readVolumeFile(inputVol, argv[1]);

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


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

	  float a, b, c;
	  float v[3], center[3];

	  //The first line is the axis
	  faxis>>v[0]>>v[1]>>v[2];

	 faxis.seekg (0, ios::beg);

	  for(int i=0; i<3; i++)
	  	center[i]=0.0;
	  int axisNum=0;
	  while(faxis>> a>> b>>c){
	  	center[0] += a;
		center[1] += b;
		center[2] += b;
	  	axisNum++;
	  }
	  faxis.close();
	
	  for(int i=0; i<3; i++)
	  {
	  	center[i]/=(float)axisNum;
		v[i]-= center[i];
	  }


		
	  string s1, s2;


	  normalize(v);

	  float Matrix[3][3];


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


	 int ni, nj, nk;
    
	  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 = inputVol.XMin() + seeda * inputVol.XSpan();
		y0 = inputVol.YMin() + seedb * inputVol.YSpan();
	    z0 = inputVol.ZMin() + seedc * inputVol.ZSpan();

		float inputseed[3];
		inputseed[0] = x0-center[0];
		inputseed[1] = y0-center[1];
		inputseed[2] = z0-center[2];

		 for(int num=0; num<Num; num ++)
		 {	
		    float alpha = 2.0*Pi*num/Num;
			defineRotationMatrix(Matrix, alpha, v);
			float u[3];
			MatrixMultipleVector(Matrix, inputseed, u);

			ni = (int)((u[0]+center[0]-inputVol.XMin())/inputVol.XSpan()+0.5);
			nj = (int)((u[1]+center[1]-inputVol.YMin())/inputVol.YSpan()+0.5);
            nk = (int)((u[2]+center[2]-inputVol.ZMin())/inputVol.ZSpan()+0.5);
			cout<<ni <<" " <<nj<<" "<<nk <<endl;
			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;
}
Example #16
0
/*using namespace std;

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

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

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

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

private:
  mutable VolMagick::uint64 _numSteps;
};

typedef boost::tuple<double, double, double> Color;
*/
int main(int argc, char **argv)
{
  if(argc < 3)
    {
      std:: cerr << 
	"Usage: " << argv[0] << "[vol 1] [vol 2] [out vol] [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;
}
Example #17
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;
}
Example #18
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;
}
Example #19
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;
}
Example #20
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;
}