본문으로 바로가기

CGAL을 이용한 메시 boolean 연산..

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/Seam_mesh.h>
#include <CGAL/Surface_mesh_parameterization/IO/File_off.h>
#include <CGAL/Surface_mesh_parameterization/parameterize.h>
#include <CGAL/Surface_mesh_parameterization/Two_vertices_parameterizer_3.h>
#include <CGAL/Surface_mesh_parameterization/LSCM_parameterizer_3.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Polygon_mesh_processing/remesh.h>

#include <CGAL/boost/graph/selection.h>
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

typedef CGAL::Simple_cartesian<double>      Kernel;
typedef Kernel::Point_2                     Point_2;
typedef Kernel::Point_3                     Point_3;
typedef CGAL::Surface_mesh<Kernel::Point_3> SurfaceMesh;

int main(int argc, char* argv[])
{
	if(argc != 5) {
		std::cout << "Usage: <off_file> <off_file> <operation> <out_off_file>";
		return EXIT_FAILURE;
	}

	const std::string filename1 = argv[1];
	const std::string filename2 = argv[2];
	const std::string operation = argv[3];
	const std::string out_filename = argv[4];

	SurfaceMesh surface_mesh_1;
	SurfaceMesh surface_mesh_2;

	std::ifstream in_mesh1(filename1);
	if(!in_mesh1){
		std::cerr << "problem loading the input data" << std::endl;
		return EXIT_FAILURE;
	} else {
		in_mesh1 >> surface_mesh_1;
	}
	
	std::ifstream in_mesh2(filename2);
	if(!in_mesh2){
		std::cerr << "problem loading the input data" << std::endl;
		return EXIT_FAILURE;
	} else {
		in_mesh2 >> surface_mesh_2;
	}

	bool res = false;
	auto surf_1 = surface_mesh_1;
	auto surf_2 = surface_mesh_2;
	namespace PMP = CGAL::Polygon_mesh_processing;
	SurfaceMesh output_surface_mesh;

	if(operation == "union") {
		res = PMP::corefine_and_compute_union(surf_1, surf_2, output_surface_mesh);

	} else if(operation == "intersection") {
		res = PMP::corefine_and_compute_intersection(surf_1, surf_2, output_surface_mesh);

	} else if(operation == "difference") {
		res = PMP::corefine_and_compute_difference(surf_1, surf_2, output_surface_mesh);

	} else if(operation == "difference2") {
		res = PMP::corefine_and_compute_difference(surf_2, surf_1, output_surface_mesh);

	} else if(operation == "corefinement") {
		 PMP::corefine(surf_1, surf_2); // both surfaces are corefined
		 output_surface_mesh = std::move(surf_1);

	} else {
		output_surface_mesh.clear();
	}

	CGAL::IO::write_polygon_mesh(out_filename, output_surface_mesh, CGAL::parameters::stream_precision(17));

	return EXIT_SUCCESS;
}

 

아래는 가시화해본 화면..

'블로그 (Blog) > 개발로그 (Devlogs)' 카테고리의 다른 글

tcping  (0) 2024.06.21
subprocess for C++  (0) 2024.06.20
개발 진행중인 화면..  (0) 2024.06.11
Qt용 스프레드쉬트 예제 코드  (0) 2024.05.23
Mesh Deformation  (0) 2024.05.20