Beispiel #1
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;
}
Beispiel #2
0
int main(int argc, char **argv)
{
  if(argc != 3)
    {
      cerr << "Usage: " << argv[0] << " <input volume file> <output volume file>" << endl;
      return 1;
    }

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

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

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


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

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

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