Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGAL Nef_polyhedron_3 Union issue #2861

Closed
JamesYangLim opened this issue Feb 21, 2018 · 4 comments
Closed

CGAL Nef_polyhedron_3 Union issue #2861

JamesYangLim opened this issue Feb 21, 2018 · 4 comments

Comments

@JamesYangLim
Copy link

Issue Details

Hi, I am trying to union 53 blocks from OFF files. However, the result is not closed and seems incorrect. Has anyone seen this kind of behaviour from Nef_polyhedron_3 union? Is this a bug?

These blocks are just random generated.

Data Files

Zip containing the cube OFF input files and OFF output file, 14kB

Output Visualisation

The 53 Blocks look like this:

53blocks00

After the union operation:

unioned53blocks01

Top view:

topview00

Source Code

#include "pch.h"
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/boost/graph/convert_nef_polyhedron_to_polygon_mesh.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>

#include <iostream>
#include <fstream>
#include <vector>

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron_3;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;
typedef CGAL::Surface_mesh<Point_3> Mesh;

TEST(NefTest, unionTest)
{
	std::vector<Polyhedron_3> ps;

	for (int i = 0; i < 53; ++i)
	{
		Polyhedron_3 tempP;
		std::stringstream ss;
		ss << "C:\\Temp\\NefBoolean\\Mesh_" << i << ".off";
		std::ifstream input(ss.str().c_str());
		input >> tempP;
		input.close();
		ps.push_back(tempP);
	}

	std::vector<Nef_polyhedron_3> ns;
	for (auto p : ps)
	{
		ns.emplace_back(Nef_polyhedron_3(p));
	}

	Nef_polyhedron_3 unionedN(ns[0]);
	for (int i = 1; i < ns.size(); ++i)
	{
		unionedN += ns[i];
	}
	
	Mesh m;
	CGAL::convert_nef_polyhedron_to_polygon_mesh(unionedN, m);

	std::ofstream out;
	out.open("c:\\Temp\\OutputMesh.off");
	out << m;
	out.close();
}

Environment

  • Operating system (Windows 64 bits):
  • Release mode
  • CGAL version: 4.11
  • Boost version: 1_66_0
@sloriot
Copy link
Member

sloriot commented Feb 21, 2018

The operation with Nef is not an issue, the error you have comes from the conversion from Nef to a polygon mesh. In your output you have some non-manifold edges (edges incident to more that 2 faces) and this kind of data is not representable with a polygon mesh.

@sloriot sloriot closed this as completed Feb 21, 2018
@JamesYangLim
Copy link
Author

@sloriot Thanks Sebastian, this is very helpful. May I suggest that it throws an exception just like Polyhedron_3 says that the surface is not simple.

@sloriot
Copy link
Member

sloriot commented Feb 22, 2018

You can use the function nef.is_simple() for that purpose.

@ankofl
Copy link

ankofl commented Oct 15, 2024

The operation with Nef is not an issue, the error you have comes from the conversion from Nef to a polygon mesh. In your output you have some non-manifold edges (edges incident to more that 2 faces) and this kind of data is not representable with a polygon mesh.

@sloriot In other words, if two grids have touching edges, they cannot be combined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants