Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    //-------------------------------
    //  Parse Inputs
    //-------------------------------
    parse_input(argc, argv);

    //-------------------------------
    //  Load Data & Create Lattice
    //-------------------------------
    std::vector<Cleaver::ScalarField*> fields = loadNRRDFiles(inputs, verbose);
    if(fields.empty()){
        std::cerr << "Failed to load image data. Terminating." << std::endl;
        return 0;
    }
    else if(fields.size() == 1)
        fields.push_back(new Cleaver::InverseField(fields[0]));

    Cleaver::AbstractVolume *volume = new Cleaver::Volume(fields);


    if(absolute_resolution)
        ((Cleaver::Volume*)volume)->setSize(rx,ry,rz);
    if(scaled_resolution)
        ((Cleaver::Volume*)volume)->setSize(sx*volume->size().x,
                                            sy*volume->size().y,
                                            sz*volume->size().z);

    if(padding)
        volume = new Cleaver::PaddedVolume(volume);

    std::cout << "Creating Mesh with Volume Size " << volume->size().toString() << std::endl;

    //--------------------------------
    //  Create Mesher & TetMesh
    //--------------------------------
    Cleaver::TetMesh *mesh = Cleaver::createMeshFromVolume(volume, verbose);

    //------------------
    //  Compute Angles
    //------------------
    mesh->computeAngles();
    if(verbose){
        std::cout.precision(12);
        std::cout << "Worst Angles:" << std::endl;
        std::cout << "min: " << mesh->min_angle << std::endl;
        std::cout << "max: " << mesh->max_angle << std::endl;
    }

    //----------------------
    //  Write Info File
    //----------------------
    mesh->writeInfo(output, verbose);

    //----------------------
    // Write Tet Mesh Files
    //----------------------
    if(format == tetgen)
        mesh->writeNodeEle(output, verbose);
    else if(format == scirun)
        mesh->writePtsEle(output, verbose);
    else if(format == matlab)
        mesh->writeMatlab(output, verbose);

    //----------------------
    // Write Surface Files
    //----------------------
    mesh->constructFaces();
    mesh->writePly(output, verbose);
    //mesh->writeMultiplePly(inputs, output, verbose);


    //-----------
    // Cleanup
    //-----------
    if(verbose)
        std::cout << "Cleaning up." << std::endl;
    delete mesh;
    for(unsigned int f=0; f < fields.size(); f++)
        delete fields[f];
    delete volume;

    //-----------
    //  Done
    //-----------
    if(verbose)
        std::cout << "Done." << std::endl;

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{


	cerr<<"THIS IS VOLUMEMESH"<<endl;

	int dim_x=30;
	int dim_y=30;
	int dim_z=30;
	float v_x=1.0;
	float v_y=1.0;
	float v_z=1.0;

	bool verbose=true;
	string format="tetgen";
	string outputFileName="meshOutput";

	//vector<float> outsideVec(dim_x*dim_y*dim_x,0);
	vector<float> insideVec(dim_x*dim_y*dim_x,0.0);
	int idx=0;
	//filling volumetric mateiral definition - a sphere centered in the middle of the lattice
	for (int x = 0  ; x < dim_x ; ++x ){
	  for (int y = 0  ; y < dim_y ; ++y ){
	    for (int z = 0  ; z < dim_z ; ++z ){	      
	      if(x < 2 || y < 2 || z < 2 ||
		 x > (dim_x - 2) || y > (dim_y - 2) || z > (dim_z - 2))
		{
		  insideVec[idx]=1.0;
		  ++idx;
			      continue;
		}
	      
	      if ((x-dim_x/2)*(x-dim_x/2)+(y-dim_y/2)*(y-dim_y/2)+(z-dim_z/2)<0.4*dim_x){
		
		insideVec[idx]=1.0;
	      }else{
		insideVec[idx]=0.0;
		//insideVec[idx]=1;
		//outsideVec[idx]=0;
	      }

	      std::cout << insideVec[idx] << std::endl;
	      
	      ++idx;
	    }
	  }
	}

	Cleaver::FloatField insideField=Cleaver::FloatField(dim_x,dim_y,dim_z,&insideVec[0]);
	//Cleaver::FloatField outsideField=Cleaver::FloatField(dim_x,dim_y,dim_z,&outsideVec[0]);

	Cleaver::InverseField inverseField=Cleaver::InverseField(&insideField);

	std::vector<Cleaver::ScalarField*> fields;
	fields.push_back(&insideField);
	fields.push_back(&inverseField);

	Cleaver::Volume volume(fields);
	Cleaver::TetMesh *mesh = Cleaver::createMeshFromVolume(volume, verbose);

    //------------------
    //  Compute Angles
    //------------------    
    mesh->computeAngles();
    if(verbose){
        std::cout.precision(12);
        std::cout << "Worst Angles:" << std::endl;
        std::cout << "min: " << mesh->min_angle << std::endl;
        std::cout << "max: " << mesh->max_angle << std::endl;
    }


    //----------------------
    //  Write Info File
    //----------------------
    mesh->writeInfo(outputFileName, verbose);


    //----------------------
    // Write Tet Mesh Files
    //----------------------
    if(format == tetgen)
        mesh->writeNodeEle(outputFileName, verbose);
    else if(format == scirun)
        mesh->writePtsEle(outputFileName, verbose);
    else if(format == matlab)
        mesh->writeMatlab(outputFileName, verbose);

    //----------------------
    // Write Surface Files
    //----------------------
    mesh->constructFaces();
    mesh->writePly(outputFileName, verbose);



}