diff --git a/CMakeLists.txt b/CMakeLists.txt index 06ef84660..f4ce5cd25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,7 @@ if ( CGAL_FOUND ) add_subdirectory(SWIG_CGAL/Mesh_2) add_subdirectory(SWIG_CGAL/Interpolation) add_subdirectory(SWIG_CGAL/Convex_hull_2) + add_subdirectory(SWIG_CGAL/Convex_hull_3) #filter Voronoi diagram bindings find_path(CGAL_VOR_BASIC_H "CGAL/Voronoi_diagram_2/basic.h" ${CGAL_INCLUDE_DIRS} NO_DEFAULT_PATH) if ("${CGAL_VOR_BASIC_H}" STREQUAL "CGAL_VOR_BASIC_H-NOTFOUND") diff --git a/SWIG_CGAL/Convex_hull_3/CGAL_Convex_hull_3.i b/SWIG_CGAL/Convex_hull_3/CGAL_Convex_hull_3.i new file mode 100644 index 000000000..ac1522b7b --- /dev/null +++ b/SWIG_CGAL/Convex_hull_3/CGAL_Convex_hull_3.i @@ -0,0 +1,84 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) 2017 GeometryFactory (FRANCE) +// Distributed under the Boost Software License, Version 1.0. (See accompany- +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// ------------------------------------------------------------------------------ + + +%module (package="CGAL") CGAL_Convex_hull_3 + +%include "SWIG_CGAL/common.i" +Decl_void_type() + +SWIG_CGAL_add_java_loadLibrary(CGAL_Convex_hull_3) +SWIG_CGAL_package_common() + +%import "SWIG_CGAL/Common/Macros.h" +%import "SWIG_CGAL/Kernel/CGAL_Kernel.i" +%include "SWIG_CGAL/Common/Iterator.h" +%include "SWIG_CGAL/Common/Wrapper_iterator_helper.h" + +%pragma(java) jniclassimports=%{ +import CGAL.Kernel.Point_3; +import CGAL.Kernel.Plane_3; +import CGAL.Polyhedron_3.Polyhedron_3; +import java.util.Iterator; +%} +%pragma(java) moduleimports=%{ +import CGAL.Kernel.Point_3; +import CGAL.Kernel.Plane_3; +import CGAL.Polyhedron_3.Polyhedron_3; +import java.util.Iterator; +%} + +//include files +%{ +#include +#include +#include +#include +%} + +%types(Plane_3*,Plane_3);//needed so that the identifier SWIGTYPE_p_Point_3 is generated + +SWIG_CGAL_set_wrapper_iterator_helper_input(Point_3) +SWIG_CGAL_set_wrapper_iterator_helper_input(Plane_3) + +//import definitions of Polyhedron objects +%import "SWIG_CGAL/Polyhedron_3/CGAL_Polyhedron_3.i" + +//import Polyhedron_3 wrapper types +SWIG_CGAL_import_Polyhedron_3_SWIG_wrapper + + +%inline %{ +typedef Wrapper_iterator_helper::input Point_range; +typedef Wrapper_iterator_helper::input Plane_range; + +void convex_hull_3(Point_range range, Polyhedron_3_SWIG_wrapper& P) +{ + CGAL::convex_hull_3(range.first, range.second, P.get_data()); +} + +void halfspace_intersection_3(Plane_range range, Polyhedron_3_SWIG_wrapper& P) +{ + std::vector planes(range.first, range.second); + CGAL::halfspace_intersection_3(planes.begin(), planes.end(), P.get_data()); +} + +void halfspace_intersection_3(Plane_range range, Polyhedron_3_SWIG_wrapper& P, Point_3& pt) +{ + std::vector planes(range.first, range.second); + CGAL::halfspace_intersection_3(planes.begin(), planes.end(), P.get_data(), pt.get_data()); +} + +bool is_strongly_convex_3(Polyhedron_3_SWIG_wrapper& P) +{ + return CGAL::is_strongly_convex_3(P.get_data()); +} + +%} + +#ifdef SWIG_CGAL_HAS_Convex_hull_3_USER_PACKAGE +%include "SWIG_CGAL/User_packages/Convex_hull_3/extensions.i" +#endif diff --git a/SWIG_CGAL/Convex_hull_3/CMakeLists.txt b/SWIG_CGAL/Convex_hull_3/CMakeLists.txt new file mode 100644 index 000000000..4bbd74589 --- /dev/null +++ b/SWIG_CGAL/Convex_hull_3/CMakeLists.txt @@ -0,0 +1,6 @@ +SET (LIBSTOLINKWITH CGAL_Kernel_cpp) + +# Modules +ADD_SWIG_CGAL_JAVA_MODULE ( Convex_hull_3 ${LIBSTOLINKWITH} ) +ADD_SWIG_CGAL_PYTHON_MODULE ( Convex_hull_3 ${LIBSTOLINKWITH} ) +ADD_SWIG_CGAL_RUBY_MODULE ( Convex_hull_3 ${LIBSTOLINKWITH} ) diff --git a/examples/java/test_convex_hull_3.java b/examples/java/test_convex_hull_3.java new file mode 100644 index 000000000..8f1ad8cb5 --- /dev/null +++ b/examples/java/test_convex_hull_3.java @@ -0,0 +1,39 @@ +import CGAL.Kernel.Point_3; +import CGAL.Kernel.Plane_3; +import CGAL.Convex_hull_3.CGAL_Convex_hull_3; +import CGAL.Polyhedron_3.Polyhedron_3; +import java.util.LinkedList; + + +public class test_convex_hull_3 { + public static void main(String arg[]){ + LinkedList pts=new LinkedList(); + + pts.add( new Point_3(0, 0, 0) ); + pts.add( new Point_3(0, 1, 0) ); + pts.add( new Point_3(1, 1, 0) ); + pts.add( new Point_3(1, 0, 0) ); + pts.add( new Point_3(0, 0, 1) ); + pts.add( new Point_3(0, 1, 1) ); + pts.add( new Point_3(1, 1, 1) ); + pts.add( new Point_3(1, 0, 1) ); + + Polyhedron_3 res = new Polyhedron_3(); + + CGAL_Convex_hull_3.convex_hull_3(pts.iterator(), res); + System.out.println("convex hull has " + res.size_of_vertices() + " vertices"); + System.out.println("is strongly convex: "+CGAL_Convex_hull_3.is_strongly_convex_3(res)); + + LinkedList planes=new LinkedList(); + planes.add( new Plane_3(-1, 0, 0, 0) ); + planes.add( new Plane_3(1, 0, 0, -1) ); + planes.add( new Plane_3(0, -1, 0, 0) ); + planes.add( new Plane_3(0, 1, 0, -1) ); + planes.add( new Plane_3(0, 0, -1, 0) ); + planes.add( new Plane_3(0, 0, 1, -1) ); + + res.clear(); + CGAL_Convex_hull_3.halfspace_intersection_3(planes.iterator(), res); + System.out.println("halfspace intersection has " + res.size_of_vertices() + " vertices"); + } +} diff --git a/examples/python/test_convex_hull_3.py b/examples/python/test_convex_hull_3.py new file mode 100644 index 000000000..2da4ec20d --- /dev/null +++ b/examples/python/test_convex_hull_3.py @@ -0,0 +1,35 @@ +from __future__ import print_function +from CGAL.CGAL_Kernel import Point_3 +from CGAL.CGAL_Kernel import Plane_3 +from CGAL import CGAL_Convex_hull_3 +from CGAL.CGAL_Polyhedron_3 import Polyhedron_3 + +pts=[] +pts.append( Point_3(0, 0, 0) ) +pts.append( Point_3(0, 1, 0) ) +pts.append( Point_3(1, 1, 0) ) +pts.append( Point_3(1, 0, 0) ) +pts.append( Point_3(0, 0, 1) ) +pts.append( Point_3(0, 1, 1) ) +pts.append( Point_3(1, 1, 1) ) +pts.append( Point_3(1, 0, 1) ) + +res = Polyhedron_3(); + +CGAL_Convex_hull_3.convex_hull_3(pts, res) + +print("convex hull has ", res.size_of_vertices(), " vertices"); +print("is strongly convex: ",CGAL_Convex_hull_3.is_strongly_convex_3(res)); + + +planes=[]; +planes.append(Plane_3(-1, 0, 0, 0) ) +planes.append(Plane_3(1, 0, 0, -1) ) +planes.append(Plane_3(0, -1, 0, 0) ) +planes.append(Plane_3(0, 1, 0, -1) ) +planes.append(Plane_3(0, 0, -1, 0) ) +planes.append(Plane_3(0, 0, 1, -1) ) + +res.clear(); +CGAL_Convex_hull_3.halfspace_intersection_3(planes, res); +print("halfspace intersection has ", res.size_of_vertices(), " vertices");