Ejemplo n.º 1
0
polyhedron cgal_to_polyhedron( const Nef_polyhedron &NP ){
    Polyhedron P;
    polyhedron ret;
    
    if( NP.is_simple() ){
        NP.convert_to_polyhedron(P);
        std::vector<double> coords;
        std::vector<int> tris;
        int next_id = 0;
        std::map< Polyhedron::Vertex*, int > vid;
        for( Polyhedron::Vertex_iterator iter=P.vertices_begin(); iter!=P.vertices_end(); iter++ ){
            coords.push_back( CGAL::to_double( (*iter).point().x() ) );
            coords.push_back( CGAL::to_double( (*iter).point().y() ) );
            coords.push_back( CGAL::to_double( (*iter).point().z() ) );
            vid[ &(*iter) ] = next_id++;
        }
        
        for( Polyhedron::Facet_iterator iter=P.facets_begin(); iter!=P.facets_end(); iter++ ){
            Polyhedron::Halfedge_around_facet_circulator j = iter->facet_begin();
            tris.push_back( CGAL::circulator_size(j) );
            do {
                tris.push_back( std::distance(P.vertices_begin(), j->vertex()) );
            } while ( ++j != iter->facet_begin());
        }
        
        ret.initialize_load_from_mesh( coords, tris );
    } else {
        std::cout << "resulting polyhedron is not simple!" << std::endl;
    }
    return ret;
}
Ejemplo n.º 2
0
int	main(int argc, char *argv[]) {
	int	c;
	while (EOF != (c = getopt(argc, argv, "dPXACSp:")))
		switch (c) {
		case 'd':
			if (debuglevel == LOG_DEBUG) {
				debuglevel++;
			} else {
				debuglevel = LOG_DEBUG;
			}
			break;
		case 'P':
			support_enable = false;
			break;
		case 'X':
			axes_enable = false;
			break;
		case 'A':
			axessupport_enable = false;
			break;
		case 'C':
			characteristics_enable = false;
			break;
		case 'S':
			solution_enable = false;
			break;
		case 'p':
			prefix = std::string(optarg);
			break;
		}

	Nef_nary_union	unioner;

	// solution
	try {
		if (solution_enable) {
			unioner.add_polyhedron(build_solution(thickness));
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add solution: %s",
			x.what());
	}

	// characteristics
	try {
		if (characteristics_enable) {
			unioner.add_polyhedron(build_characteristics());
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add charactistics: %s",
			x.what());
	}

	// add the cut support
	try {
		if (support_enable) {
			unioner.add_polyhedron(
				build_cutsupport(2 * thickness));
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add cut supports: %s",
			x.what());
	}

	// add the axes support
	try {
		if (axessupport_enable) {
			unioner.add_polyhedron(
				build_axessupport(thickness));
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add axes supports: %s",
			x.what());
	}

	// axes
	try {
		if (axes_enable) {
			unioner.add_polyhedron(build_axes());
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add axes: %s", x.what());
	}

	// extract
	debug(LOG_DEBUG, DEBUG_LOG, 0, "extracting image");
	Nef_polyhedron	image = unioner.get_union();

	// output
	debug(LOG_DEBUG, DEBUG_LOG, 0, "convert for output");
	Polyhedron	P;
	image.convert_to_polyhedron(P);
	std::cout << P;

	// output halves
	if (prefix.size() > 0) {
		PartWriter	pw(prefix);
		pw(PartWriter::BACK_PART, image, offset);
		pw(PartWriter::FRONT_PART, image, offset);
		pw(PartWriter::LEFT_PART, image, offset);
		pw(PartWriter::RIGHT_PART, image, offset);
		pw(PartWriter::TOP_PART, image, offset);
		pw(PartWriter::BOTTOM_PART, image, offset);
	} else {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "part output suppressed");
	}

	debug(LOG_DEBUG, DEBUG_LOG, 0, "output complete");
	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
/** 
 * \brief main function for example6
 */
int	main(int argc, char *argv[]) {

	int	c;
	while (EOF != (c = getopt(argc, argv, "dSACIXNPFxp:")))
		switch (c) {
		case 'd':
			if (debuglevel == LOG_DEBUG) {
				debuglevel++;
			} else {
				debuglevel = LOG_DEBUG;
			}
			break;
		case 'S':
			show_solution = !show_solution;
			break;
		case 'A':
			show_alternatives = !show_alternatives;
			break;
		case 'C':
			show_characteristics = !show_characteristics;
			break;
		case 'I':
			show_initial = !show_initial;
			break;
		case 'X':
			show_axes = !show_axes;
			break;
		case 'N':
			show_negative = !show_negative;
			break;
		case 'F':
			show_fcurve = !show_fcurve;
			break;
		case 'P':
			show_support = !show_support;
			break;
		case 'p':
			prefix = std::string(optarg);
			break;
		case 'x':
			yzslicing = false;
			break;
		}

	debug(LOG_DEBUG, DEBUG_LOG, 0, "nonuniqueness of solution of a "
		"partial differential equation");

	// start building up the union of things to be restricted to a box
	Nef_nary_union	unioner;

	// create a the solution surface
	try {
		if (show_solution) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "adding solution surface");
			unioner.add_polyhedron(build_solution(sheetthickness));
			debug(LOG_DEBUG, DEBUG_LOG, 0, "solution surface added");
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add solution: %s",
			x.what());
	}

	// create an alternative solution surface
	try {
		if (show_alternatives) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "adding alternatives");
			unioner.add_polyhedron(build_alternative(sheetthickness));
			debug(LOG_DEBUG, DEBUG_LOG, 0, "alternatives added");
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add alternatives: %s",
			x.what());
	}

	// add additional characteristics
	try {
		if (show_characteristics) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "adding characteristics");
			unioner.add_polyhedron(build_characteristics());
			debug(LOG_DEBUG, DEBUG_LOG, 0, "characteristics added");
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add characteristics: %s",
			x.what());
	}

	// add negative characteristics
	try {
		if (show_negative) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "adding neg characteristics");
			unioner.add_polyhedron(build_xcharacteristics());
			debug(LOG_DEBUG, DEBUG_LOG, 0, "neg characteristics added");
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add negative characteristics: %s",
			x.what());
	}

	// add the FCurve
	try {
		if (show_fcurve) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "adding fcurve");
			unioner.add_polyhedron(build_fcurve());
			debug(LOG_DEBUG, DEBUG_LOG, 0, "fcurve added");
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add fcurve: %s",
			x.what());
	}

	// add the support sheet
	try {
		if (show_support) {
			debug(LOG_DEBUG, DEBUG_LOG, 0, "adding support");
			unioner.add_polyhedron(build_support(sheetthickness));
			debug(LOG_DEBUG, DEBUG_LOG, 0, "support added");
		}
	} catch (std::exception& x) {
		debug(LOG_ERR, DEBUG_LOG, 0, "failed to add support: %s",
			x.what());
	}

	// add the initial curve
	if (show_initial) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "adding initial curve");
		unioner.add_polyhedron(build_initialcurve());
		debug(LOG_DEBUG, DEBUG_LOG, 0, "initial curve added");
	}

	// extract union
	debug(LOG_DEBUG, DEBUG_LOG, 0, "extract the image component union");
	Nef_polyhedron	image = unioner.get_union();
	debug(LOG_DEBUG, DEBUG_LOG, 0, "base image constructed");

	// restrict everything to a box
	debug(LOG_DEBUG, DEBUG_LOG, 0, "restrict to a box");
	Build_Box	box(point(-0.1, -2, -2), point(4, 2, 2));
        Polyhedron      boxp;
        boxp.delegate(box);
	image = image * boxp;
	debug(LOG_DEBUG, DEBUG_LOG, 0, "restriction complete");

	// add axes
	if (show_axes) {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "adding axes");
		image = image + build_axes();
		debug(LOG_DEBUG, DEBUG_LOG, 0, "axes added");
	}

	// output 
	Polyhedron	P;
	debug(LOG_DEBUG, DEBUG_LOG, 0, "convert to polyhedron for output");
	image.convert_to_polyhedron(P);
	std::cout << P;

	// write parts
	if (prefix.size() > 0) {
		PartWriter	pw(prefix);
		pw(PartWriter::LEFT_PART, image);
		pw(PartWriter::RIGHT_PART, image);
		pw(PartWriter::FRONT_PART, image);
		pw(PartWriter::BACK_PART, image);
	} else {
		debug(LOG_DEBUG, DEBUG_LOG, 0, "part output suppressed");
	}

	// that's it
	debug(LOG_DEBUG, DEBUG_LOG, 0, "output complete");
	return EXIT_SUCCESS;
}