Skip to content

Commit

Permalink
add Convex_hull_3
Browse files Browse the repository at this point in the history
  • Loading branch information
sloriot committed Dec 6, 2017
1 parent 27bbe60 commit dcf2717
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -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")
Expand Down
84 changes: 84 additions & 0 deletions 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 <SWIG_CGAL/Polyhedron_3/all_includes.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Convex_hull_3/dual/halfspace_intersection_3.h>
#include <SWIG_CGAL/Common/Wrapper_iterator_helper.h>
%}

%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<Point_3>::input Point_range;
typedef Wrapper_iterator_helper<Plane_3>::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<Plane_3::cpp_base> 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<Plane_3::cpp_base> 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
6 changes: 6 additions & 0 deletions 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} )
39 changes: 39 additions & 0 deletions 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<Point_3> pts=new LinkedList<Point_3>();

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<Plane_3> planes=new LinkedList<Plane_3>();
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");
}
}
35 changes: 35 additions & 0 deletions 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");

0 comments on commit dcf2717

Please sign in to comment.