Commit 6350c95d authored by Alexander Dielen's avatar Alexander Dielen

quick pybind11 test using openmesh vectors

parent a0d5d21e
[submodule "pybind11"]
path = pybind11
url = https://github.com/pybind/pybind11.git
#include "Bindings.hh"
#include "Vector.hh"
#include "Mesh.hh"
#include "PropertyManager.hh"
#include "InputOutput.hh"
#include "Decimater.hh"
#include <memory>
#include <boost/python/numpy.hpp>
namespace py = boost::python;
namespace np = boost::python::numpy;
namespace OpenMesh {
namespace Python {
/**
* Expose mesh items to %Python.
*/
void expose_items() {
class_<ArrayItems::Vertex>("Vertex");
class_<ArrayItems::Halfedge>("Halfedge");
class_<ArrayItems::Edge>("Edge");
class_<ArrayItems::Face>("Face");
}
/**
* Expose item and property handles to %Python.
*/
void expose_handles() {
class_<BaseHandle>("BaseHandle", init<optional<int> >())
.def("idx", &BaseHandle::idx)
.def("is_valid", &BaseHandle::is_valid)
.def("reset", &BaseHandle::reset)
.def("invalidate", &BaseHandle::invalidate)
.def(self == self)
.def(self != self)
.def(self < self)
;
class_<VertexHandle, bases<BaseHandle> >("VertexHandle", init<optional<int> >());
class_<HalfedgeHandle, bases<BaseHandle> >("HalfedgeHandle", init<optional<int> >());
class_<EdgeHandle, bases<BaseHandle> >("EdgeHandle", init<optional<int> >());
class_<FaceHandle, bases<BaseHandle> >("FaceHandle", init<optional<int> >());
class_<BasePropHandleT<object>, bases<BaseHandle> >("BasePropHandle", init<optional<int> >());
class_<VPropHandleT<object>, bases<BasePropHandleT<object> > >("VPropHandle", init<optional<int> >())
.def(init<const BasePropHandleT<object>&>());
class_<HPropHandleT<object>, bases<BasePropHandleT<object> > >("HPropHandle", init<optional<int> >())
.def(init<const BasePropHandleT<object>&>());
class_<EPropHandleT<object>, bases<BasePropHandleT<object> > >("EPropHandle", init<optional<int> >())
.def(init<const BasePropHandleT<object>&>());
class_<FPropHandleT<object>, bases<BasePropHandleT<object> > >("FPropHandle", init<optional<int> >())
.def(init<const BasePropHandleT<object>&>());
class_<MPropHandleT<object>, bases<BasePropHandleT<object> > >("MPropHandle", init<optional<int> >())
.def(init<const BasePropHandleT<object>&>());
}
/**
* Expose the StatusBits enum and StatusInfo class to %Python.
*/
void expose_status_bits_and_info() {
using OpenMesh::Attributes::StatusBits;
using OpenMesh::Attributes::StatusInfo;
enum_<StatusBits>("StatusBits")
.value("DELETED", OpenMesh::Attributes::DELETED)
.value("LOCKED", OpenMesh::Attributes::LOCKED)
.value("SELECTED", OpenMesh::Attributes::SELECTED)
.value("HIDDEN", OpenMesh::Attributes::HIDDEN)
.value("FEATURE", OpenMesh::Attributes::FEATURE)
.value("TAGGED", OpenMesh::Attributes::TAGGED)
.value("TAGGED2", OpenMesh::Attributes::TAGGED2)
.value("FIXEDNONMANIFOLD", OpenMesh::Attributes::FIXEDNONMANIFOLD)
.value("UNUSED", OpenMesh::Attributes::UNUSED)
;
class_<StatusInfo>("StatusInfo")
.def("deleted", &StatusInfo::deleted)
.def("set_deleted", &StatusInfo::set_deleted)
.def("locked", &StatusInfo::locked)
.def("set_locked", &StatusInfo::set_locked)
.def("selected", &StatusInfo::selected)
.def("set_selected", &StatusInfo::set_selected)
.def("hidden", &StatusInfo::hidden)
.def("set_hidden", &StatusInfo::set_hidden)
.def("feature", &StatusInfo::feature)
.def("set_feature", &StatusInfo::set_feature)
.def("tagged", &StatusInfo::tagged)
.def("set_tagged", &StatusInfo::set_tagged)
.def("tagged2", &StatusInfo::tagged2)
.def("set_tagged2", &StatusInfo::set_tagged2)
.def("fixed_nonmanifold", &StatusInfo::fixed_nonmanifold)
.def("set_fixed_nonmanifold", &StatusInfo::set_fixed_nonmanifold)
.def("bits", &StatusInfo::bits)
.def("set_bits", &StatusInfo::set_bits)
.def("is_bit_set", &StatusInfo::is_bit_set)
.def("set_bit", &StatusInfo::set_bit)
.def("unset_bit", &StatusInfo::unset_bit)
.def("change_bit", &StatusInfo::change_bit)
;
}
BOOST_PYTHON_MODULE(openmesh) {
Py_Initialize();
np::initialize();
expose_items();
expose_handles();
expose_status_bits_and_info();
expose_vec<float, 2>("Vec2f");
expose_vec<float, 3>("Vec3f");
expose_vec<float, 4>("Vec4f");
expose_vec<double, 2>("Vec2d");
expose_vec<double, 3>("Vec3d");
expose_vec<double, 4>("Vec4d");
expose_mesh<PolyMesh>("PolyMesh");
expose_mesh<TriMesh>("TriMesh");
expose_iterator<OpenMesh::PolyConnectivity::VertexIter, &OpenMesh::ArrayKernel::n_vertices>("VertexIter");
expose_iterator<OpenMesh::PolyConnectivity::HalfedgeIter, &OpenMesh::ArrayKernel::n_halfedges>("HalfedgeIter");
expose_iterator<OpenMesh::PolyConnectivity::EdgeIter, &OpenMesh::ArrayKernel::n_edges>("EdgeIter");
expose_iterator<OpenMesh::PolyConnectivity::FaceIter, &OpenMesh::ArrayKernel::n_faces>("FaceIter");
expose_circulator<OpenMesh::PolyConnectivity::VertexVertexIter, VertexHandle>("VertexVertexIter");
expose_circulator<OpenMesh::PolyConnectivity::VertexIHalfedgeIter, VertexHandle>("VertexIHalfedgeIter");
expose_circulator<OpenMesh::PolyConnectivity::VertexOHalfedgeIter, VertexHandle>("VertexOHalfedgeIter");
expose_circulator<OpenMesh::PolyConnectivity::VertexEdgeIter, VertexHandle>("VertexEdgeIter");
expose_circulator<OpenMesh::PolyConnectivity::VertexFaceIter, VertexHandle>("VertexFaceIter");
expose_circulator<OpenMesh::PolyConnectivity::FaceVertexIter, FaceHandle>("FaceVertexIter");
expose_circulator<OpenMesh::PolyConnectivity::FaceHalfedgeIter, FaceHandle>("FaceHalfedgeIter");
expose_circulator<OpenMesh::PolyConnectivity::FaceEdgeIter, FaceHandle>("FaceEdgeIter");
expose_circulator<OpenMesh::PolyConnectivity::FaceFaceIter, FaceHandle>("FaceFaceIter");
expose_circulator<OpenMesh::PolyConnectivity::HalfedgeLoopIter, HalfedgeHandle>("HalfedgeLoopIter");
typedef IteratorWrapperT<PolyConnectivity::VertexIter, &ArrayKernel::n_vertices> VertexIterWrapper;
typedef IteratorWrapperT<PolyConnectivity::HalfedgeIter, &ArrayKernel::n_halfedges> HalfedgeIterWrapper;
typedef IteratorWrapperT<PolyConnectivity::EdgeIter, &ArrayKernel::n_edges> EdgeIterWrapper;
typedef IteratorWrapperT<PolyConnectivity::FaceIter, &ArrayKernel::n_faces> FaceIterWrapper;
expose_property_manager<VPropHandleT<object>, VertexHandle, VertexIterWrapper>("VPropertyManager");
expose_property_manager<HPropHandleT<object>, HalfedgeHandle, HalfedgeIterWrapper>("HPropertyManager");
expose_property_manager<EPropHandleT<object>, EdgeHandle, EdgeIterWrapper>("EPropertyManager");
expose_property_manager<FPropHandleT<object>, FaceHandle, FaceIterWrapper>("FPropertyManager");
expose_io();
expose_decimater<PolyMesh>("PolyMesh");
expose_decimater<TriMesh>("TriMesh");
}
} // namespace Python
} // namespace OpenMesh
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
IF(NOT DEFINED OPENMESH_BUILD_PYTHON_UNIT_TESTS)
SET(OPENMESH_BUILD_PYTHON_UNIT_TESTS FALSE CACHE BOOL "Enable or disable building the Python unit tests.")
ENDIF()
project(openmesh)
IF(NOT DEFINED OPENMESH_PYTHON_VERSION)
SET(OPENMESH_PYTHON_VERSION "2.7" CACHE STRING "Choose the Python version that is used to build the Python Bindings.")
ENDIF()
find_package(OpenMesh)
include_directories(${OPENMESH_INCLUDE_DIRS})
add_subdirectory(pybind11)
pybind11_add_module(openmesh src/Bindings.cc)
SET(ERROR_MESSAGE_RUNNING "Checking the Boost Python configuration failed! An \
error occurred while running a small Boost Python test project. Make sure that \
your Python and Boost Python libraries match.")
SET(ERROR_MESSAGE_INTERPRETER "Checking the Boost Python configuration failed! \
Python Interpreter not found.")
SET(ERROR_MESSAGE_BUILDING "Checking the Boost Python configuration failed! \
Building a small Boost Python test project failed. Make sure that your Python \
and Boost Python libraries match.")
# Create log file
SET(PYTHONLOG "${CMAKE_CURRENT_BINARY_DIR}/PythonLog.txt")
FILE(WRITE ${PYTHONLOG} "")
# Look for OpenMesh
MESSAGE(STATUS "Looking for OpenMesh")
FIND_PACKAGE(OpenMesh QUIET)
IF(OPENMESH_FOUND)
MESSAGE(STATUS "Looking for OpenMesh -- found")
# Look for the python libs
MESSAGE(STATUS "Looking for PythonLibs")
FIND_PACKAGE(PythonLibs ${OPENMESH_PYTHON_VERSION} QUIET)
IF(PYTHONLIBS_FOUND)
MESSAGE(STATUS "Looking for PythonLibs -- found")
# Determine the name of the python component
STRING(REGEX MATCH "^[0-9]+\\.[0-9]+" PYTHON_VERSION_MAJOR_MINOR ${PYTHONLIBS_VERSION_STRING})
STRING(REGEX REPLACE "\\." "" PYTHON_VERSION_MAJOR_MINOR ${PYTHON_VERSION_MAJOR_MINOR})
STRING(REGEX MATCH "^[0-9]" PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR_MINOR})
MESSAGE(STATUS "Looking for Boost Python")
SET(BOOST_PYTHON_COMPONENT_NAMES "python-py${PYTHON_VERSION_MAJOR_MINOR}" "python${PYTHON_VERSION_MAJOR}" "python")
FOREACH(NAME ${BOOST_PYTHON_COMPONENT_NAMES})
IF(NOT Boost_FOUND)
FILE(APPEND ${PYTHONLOG} "Looking for component ${NAME}\n")
FIND_PACKAGE(Boost QUIET COMPONENTS ${NAME})
ENDIF()
ENDFOREACH()
FILE(APPEND ${PYTHONLOG} "\n")
IF(Boost_FOUND)
MESSAGE(STATUS "Looking for Boost Python -- found")
MESSAGE(STATUS "Checking the Boost Python configuration")
SET(CMAKE_TRY_COMPILE_CONFIGURATION "Release")
TRY_COMPILE(
COMPILE_WORKS
${CMAKE_CURRENT_BINARY_DIR}/Example/
${CMAKE_CURRENT_SOURCE_DIR}/Example/
Example
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${PYTHON_INCLUDE_DIRS};${Boost_INCLUDE_DIRS}"
"-DLINK_DIRECTORIES:STRING=${Boost_LIBRARY_DIRS}"
"-DLINK_LIBRARIES:STRING=${PYTHON_LIBRARIES};${Boost_LIBRARIES}"
OUTPUT_VARIABLE OUTPUT_TRY_COMPILE
)
FILE(APPEND ${PYTHONLOG} "INCLUDE_DIRECTORIES: ${PYTHON_INCLUDE_DIRS};${Boost_INCLUDE_DIRS}\n")
FILE(APPEND ${PYTHONLOG} "LINK_DIRECTORIES: ${Boost_LIBRARY_DIRS}\n")
FILE(APPEND ${PYTHONLOG} "LINK_LIBRARIES: ${PYTHON_LIBRARIES};${Boost_LIBRARIES}\n\n")
FILE(APPEND ${PYTHONLOG} "${OUTPUT_TRY_COMPILE}")
IF(COMPILE_WORKS)
# Look for the python interpreter to check if the example works
# strip version string of any characters (e.g. rc1 # '+') than 0-9 and .
STRING(REGEX REPLACE "(rc[0-9]+)|[^ 0-9 | \\.]" "" PYTHONLIBS_VERSION_STRING_STRIPPED ${PYTHONLIBS_VERSION_STRING})
FIND_PACKAGE(PythonInterp ${PYTHONLIBS_VERSION_STRING_STRIPPED} QUIET)
IF(PYTHONINTERP_FOUND)
IF(MSVC)
# TODO check if path is correct
SET(PYTHON_WORKING_DIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_TRY_COMPILE_CONFIGURATION}")
ELSE()
SET(PYTHON_WORKING_DIR "${CMAKE_CURRENT_BINARY_DIR}/Example")
ENDIF()
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} -c "from example import *; greet(); planet = World()"
WORKING_DIRECTORY ${PYTHON_WORKING_DIR}
RESULT_VARIABLE PYTHON_WORKS
OUTPUT_QUIET
ERROR_QUIET
)
IF(PYTHON_WORKS EQUAL 0)
### EVERYTHING WORKS ###
MESSAGE(STATUS "Checking the Boost Python configuration -- done")
IF(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND ${Boost_VERSION} VERSION_LESS 105600)
MESSAGE("There are known issues with Clang and Boost Python 1.55 and below.")
MESSAGE("Please consider updating Boost Python.")
ENDIF()
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Build)
FILE(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
FILE(GLOB SOURCES *.cc *hh)
INCLUDE_DIRECTORIES(${OPENMESH_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ../)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ADD_LIBRARY(openmesh SHARED ${SOURCES})
INSTALL(TARGETS openmesh DESTINATION ${ACG_PROJECT_LIBDIR}/python ) # TODO
TARGET_LINK_LIBRARIES(
openmesh
${OPENMESH_LIBRARIES}
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
)
SET_TARGET_PROPERTIES(
openmesh
PROPERTIES
PREFIX ""
DEBUG_POSTFIX ""
RELEASE_POSTFIX ""
)
IF(APPLE)
SET_TARGET_PROPERTIES(openmesh PROPERTIES SUFFIX ".so")
IF (NOT (CMAKE_MAJOR_VERSION LESS 3))
SET_TARGET_PROPERTIES(openmesh PROPERTIES MACOSX_RPATH TRUE)
ENDIF()
ENDIF()
IF(WIN32)
SET_TARGET_PROPERTIES(openmesh PROPERTIES SUFFIX ".pyd")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
SET(OUTPUTS openmesh.exp openmesh.lib openmesh.pyd)
FOREACH(FILE ${OUTPUTS})
ADD_CUSTOM_COMMAND(
TARGET openmesh POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${FILE}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
ENDFOREACH()
ENDIF()
IF(OPENMESH_BUILD_PYTHON_UNIT_TESTS)
SET(UNITTEST_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests/)
# Copy unit tests
FILE(GLOB UNITTESTS Unittests/*.py)
FOREACH(TEST ${UNITTESTS})
FILE(COPY ${TEST} DESTINATION ${UNITTEST_OUTPUT_DIRECTORY})
ENDFOREACH()
# Copy test files
FILE(GLOB TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/Unittests/TestFiles/*(.off|.obj|.mtl|.stl|.ply|.om))
FOREACH(FILE ${TESTFILES})
FILE(COPY ${FILE} DESTINATION ${UNITTEST_OUTPUT_DIRECTORY})
ENDFOREACH()
# Copy library
IF(WIN32)
FOREACH(FILE ${OUTPUTS})
ADD_CUSTOM_COMMAND(
TARGET openmesh POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${FILE}
${UNITTEST_OUTPUT_DIRECTORY}
)
ENDFOREACH()
ELSE()
ADD_CUSTOM_COMMAND(
TARGET openmesh POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/Build/openmesh.so
${UNITTEST_OUTPUT_DIRECTORY}
)
ENDIF()
ADD_TEST(
NAME Python_tests
WORKING_DIRECTORY ${UNITTEST_OUTPUT_DIRECTORY}
COMMAND ${PYTHON_EXECUTABLE} -m unittest discover --verbose
)
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR ${ERROR_MESSAGE_RUNNING})
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR ${ERROR_MESSAGE_INTERPRETER})
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR ${ERROR_MESSAGE_BUILDING})
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "Boost Python not found!")
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "PythonLibs not found!")
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "OpenMesh not found!")
ENDIF()
target_link_libraries(openmesh PRIVATE ${OPENMESH_LIBRARIES})
Subproject commit add56ccdcac23a6c522a2c1174a866e293c61dab
#include "Bindings.hh"
#include "Vector.hh"
#include <pybind11/pybind11.h>
namespace py = pybind11;
PYBIND11_MODULE(openmesh, m) {
expose_vec<double, 3>(m, "Vec3d");
}
// #include "Bindings.hh"
// #include "Vector.hh"
// #include "Mesh.hh"
// #include "PropertyManager.hh"
// #include "InputOutput.hh"
// #include "Decimater.hh"
//
// #include <memory>
//
// #include <boost/python/numpy.hpp>
//
// namespace py = boost::python;
// namespace np = boost::python::numpy;
//
// namespace OpenMesh {
// namespace Python {
//
// /**
// * Expose mesh items to %Python.
// */
// void expose_items() {
// class_<ArrayItems::Vertex>("Vertex");
// class_<ArrayItems::Halfedge>("Halfedge");
// class_<ArrayItems::Edge>("Edge");
// class_<ArrayItems::Face>("Face");
// }
//
// /**
// * Expose item and property handles to %Python.
// */
// void expose_handles() {
// class_<BaseHandle>("BaseHandle", init<optional<int> >())
// .def("idx", &BaseHandle::idx)
// .def("is_valid", &BaseHandle::is_valid)
// .def("reset", &BaseHandle::reset)
// .def("invalidate", &BaseHandle::invalidate)
// .def(self == self)
// .def(self != self)
// .def(self < self)
// ;
//
// class_<VertexHandle, bases<BaseHandle> >("VertexHandle", init<optional<int> >());
// class_<HalfedgeHandle, bases<BaseHandle> >("HalfedgeHandle", init<optional<int> >());
// class_<EdgeHandle, bases<BaseHandle> >("EdgeHandle", init<optional<int> >());
// class_<FaceHandle, bases<BaseHandle> >("FaceHandle", init<optional<int> >());
//
// class_<BasePropHandleT<object>, bases<BaseHandle> >("BasePropHandle", init<optional<int> >());
//
// class_<VPropHandleT<object>, bases<BasePropHandleT<object> > >("VPropHandle", init<optional<int> >())
// .def(init<const BasePropHandleT<object>&>());
// class_<HPropHandleT<object>, bases<BasePropHandleT<object> > >("HPropHandle", init<optional<int> >())
// .def(init<const BasePropHandleT<object>&>());
// class_<EPropHandleT<object>, bases<BasePropHandleT<object> > >("EPropHandle", init<optional<int> >())
// .def(init<const BasePropHandleT<object>&>());
// class_<FPropHandleT<object>, bases<BasePropHandleT<object> > >("FPropHandle", init<optional<int> >())
// .def(init<const BasePropHandleT<object>&>());
// class_<MPropHandleT<object>, bases<BasePropHandleT<object> > >("MPropHandle", init<optional<int> >())
// .def(init<const BasePropHandleT<object>&>());
// }
//
//
// /**
// * Expose the StatusBits enum and StatusInfo class to %Python.
// */
// void expose_status_bits_and_info() {
// using OpenMesh::Attributes::StatusBits;
// using OpenMesh::Attributes::StatusInfo;
//
// enum_<StatusBits>("StatusBits")
// .value("DELETED", OpenMesh::Attributes::DELETED)
// .value("LOCKED", OpenMesh::Attributes::LOCKED)
// .value("SELECTED", OpenMesh::Attributes::SELECTED)
// .value("HIDDEN", OpenMesh::Attributes::HIDDEN)
// .value("FEATURE", OpenMesh::Attributes::FEATURE)
// .value("TAGGED", OpenMesh::Attributes::TAGGED)
// .value("TAGGED2", OpenMesh::Attributes::TAGGED2)
// .value("FIXEDNONMANIFOLD", OpenMesh::Attributes::FIXEDNONMANIFOLD)
// .value("UNUSED", OpenMesh::Attributes::UNUSED)
// ;
//
// class_<StatusInfo>("StatusInfo")
// .def("deleted", &StatusInfo::deleted)
// .def("set_deleted", &StatusInfo::set_deleted)
// .def("locked", &StatusInfo::locked)
// .def("set_locked", &StatusInfo::set_locked)
// .def("selected", &StatusInfo::selected)
// .def("set_selected", &StatusInfo::set_selected)
// .def("hidden", &StatusInfo::hidden)
// .def("set_hidden", &StatusInfo::set_hidden)
// .def("feature", &StatusInfo::feature)
// .def("set_feature", &StatusInfo::set_feature)
// .def("tagged", &StatusInfo::tagged)
// .def("set_tagged", &StatusInfo::set_tagged)
// .def("tagged2", &StatusInfo::tagged2)
// .def("set_tagged2", &StatusInfo::set_tagged2)
// .def("fixed_nonmanifold", &StatusInfo::fixed_nonmanifold)
// .def("set_fixed_nonmanifold", &StatusInfo::set_fixed_nonmanifold)
// .def("bits", &StatusInfo::bits)
// .def("set_bits", &StatusInfo::set_bits)
// .def("is_bit_set", &StatusInfo::is_bit_set)
// .def("set_bit", &StatusInfo::set_bit)
// .def("unset_bit", &StatusInfo::unset_bit)
// .def("change_bit", &StatusInfo::change_bit)
// ;
// }
//
// BOOST_PYTHON_MODULE(openmesh) {
// Py_Initialize();
// np::initialize();
//
// expose_items();
// expose_handles();
// expose_status_bits_and_info();
//
// expose_vec<float, 2>("Vec2f");
// expose_vec<float, 3>("Vec3f");
// expose_vec<float, 4>("Vec4f");
// expose_vec<double, 2>("Vec2d");
// expose_vec<double, 3>("Vec3d");
// expose_vec<double, 4>("Vec4d");
//
// expose_mesh<PolyMesh>("PolyMesh");
// expose_mesh<TriMesh>("TriMesh");
//
// expose_iterator<OpenMesh::PolyConnectivity::VertexIter, &OpenMesh::ArrayKernel::n_vertices>("VertexIter");
// expose_iterator<OpenMesh::PolyConnectivity::HalfedgeIter, &OpenMesh::ArrayKernel::n_halfedges>("HalfedgeIter");
// expose_iterator<OpenMesh::PolyConnectivity::EdgeIter, &OpenMesh::ArrayKernel::n_edges>("EdgeIter");
// expose_iterator<OpenMesh::PolyConnectivity::FaceIter, &OpenMesh::ArrayKernel::n_faces>("FaceIter");
//
// expose_circulator<OpenMesh::PolyConnectivity::VertexVertexIter, VertexHandle>("VertexVertexIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexIHalfedgeIter, VertexHandle>("VertexIHalfedgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexOHalfedgeIter, VertexHandle>("VertexOHalfedgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexEdgeIter, VertexHandle>("VertexEdgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexFaceIter, VertexHandle>("VertexFaceIter");
//
// expose_circulator<OpenMesh::PolyConnectivity::FaceVertexIter, FaceHandle>("FaceVertexIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceHalfedgeIter, FaceHandle>("FaceHalfedgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceEdgeIter, FaceHandle>("FaceEdgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceFaceIter, FaceHandle>("FaceFaceIter");
//
// expose_circulator<OpenMesh::PolyConnectivity::HalfedgeLoopIter, HalfedgeHandle>("HalfedgeLoopIter");
//
// typedef IteratorWrapperT<PolyConnectivity::VertexIter, &ArrayKernel::n_vertices> VertexIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::HalfedgeIter, &ArrayKernel::n_halfedges> HalfedgeIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::EdgeIter, &ArrayKernel::n_edges> EdgeIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::FaceIter, &ArrayKernel::n_faces> FaceIterWrapper;
//
// expose_property_manager<VPropHandleT<object>, VertexHandle, VertexIterWrapper>("VPropertyManager");
// expose_property_manager<HPropHandleT<object>, HalfedgeHandle, HalfedgeIterWrapper>("HPropertyManager");
// expose_property_manager<EPropHandleT<object>, EdgeHandle, EdgeIterWrapper>("EPropertyManager");
// expose_property_manager<FPropHandleT<object>, FaceHandle, FaceIterWrapper>("FPropertyManager");
//
// expose_io();
//
// expose_decimater<PolyMesh>("PolyMesh");
// expose_decimater<TriMesh>("TriMesh");
// }
//
// } // namespace Python
// } // namespace OpenMesh
......@@ -3,31 +3,10 @@
#ifndef OPENMESH_PYTHON_BINDINGS_HH
#define OPENMESH_PYTHON_BINDINGS_HH
#include <boost/python.hpp>
#include <boost/python/return_internal_reference.hpp>
#include <boost/python/reference_existing_object.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
using namespace boost::python;
namespace OpenMesh {
/**
* This namespace contains classes and functions that are used to expose
* %OpenMesh to %Python.
*/
namespace Python {
/**
* Return value policy for functions that return references to objects that are
* managed by %OpenMesh.
*/
#define OPENMESH_PYTHON_DEFAULT_POLICY return_value_policy<copy_const_reference>()
struct MeshTraits : public OpenMesh::DefaultTraits {
/** Use double precision points */
typedef OpenMesh::Vec3d Point;
......@@ -42,7 +21,4 @@ struct MeshTraits : public OpenMesh::DefaultTraits {
typedef OpenMesh::TriMesh_ArrayKernelT<MeshTraits> TriMesh;
typedef OpenMesh::PolyMesh_ArrayKernelT<MeshTraits> PolyMesh;
} // namespace OpenMesh
} // namespace Python
#endif
#ifndef OPENMESH_PYTHON_VECTOR_HH
#define OPENMESH_PYTHON_VECTOR_HH
#include "Bindings.hh"
#include <pybind11/pybind11.h>
namespace py = pybind11;
namespace OpenMesh {
namespace Python {
template <class Vector, class Scalar>
void set_item(Vector& _vec, int _index, Scalar _value) {
......@@ -16,8 +15,9 @@ void set_item(Vector& _vec, int _index, Scalar _value) {
_vec[_index] = _value;
}
else {
PyErr_SetString(PyExc_IndexError, "Index out of range.");
throw_error_already_set();
// TODO
// PyErr_SetString(PyExc_IndexError, "Index out of range.");
// throw_error_already_set();
}
}
......@@ -31,8 +31,9 @@ Scalar get_item(Vector& _vec, int _index) {