Skip to content

Commit

Permalink
Merge pull request #5 from kwabenantim/vtk-renderer-fix
Browse files Browse the repository at this point in the history
fix PYBIND11_VTK_TYPECASTER macro and supply typecasters for vtkRende…
  • Loading branch information
kwabenantim committed May 30, 2023
2 parents bc4854a + a079798 commit 031c5cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions dynamic/wrappers/visualization/VtkScene2.cppwg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@
#include "SmartPointers.hpp"
#include "UblasIncludes.hpp"
#include "VtkScene.hpp"
#include <vtkOpenGLRenderer.h>
#include <vtkUnsignedCharArray.h>
#include <vtkSmartPointer.h>
#include "PythonObjectConverters.hpp"

#include "VtkScene2.cppwg.hpp"

namespace py = pybind11;
typedef VtkScene<2 > VtkScene2;
PYBIND11_DECLARE_HOLDER_TYPE(T, boost::shared_ptr<T>);
PYBIND11_DECLARE_HOLDER_TYPE(T, vtkSmartPointer<T>);
PYBIND11_VTK_TYPECASTER(vtkRenderer);
PYBIND11_VTK_TYPECASTER(vtkOpenGLRenderer);
PYBIND11_VTK_TYPECASTER(vtkUnsignedCharArray);


// Only needed if the type's `.get()` goes by another name
namespace PYBIND11_NAMESPACE { namespace detail {
template <typename T>
struct holder_helper<vtkSmartPointer<T>> { // <-- specialization
static const T *get(const vtkSmartPointer<T> &p) { return p.Get(); }
};
}}

class VtkScene2_Overloads : public VtkScene2{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/PythonObjectConverters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace pybind11 { namespace detail { \
protected: \
VTK_OBJ *value; \
public: \
static PYBIND11_DESCR name() { return type_descr(_(#VTK_OBJ)); } \
static constexpr auto name =_(#VTK_OBJ); \
operator VTK_OBJ *() { return value; } \
operator VTK_OBJ &() { return *value; } \
template <typename _T> using cast_op_type = \
Expand Down
2 changes: 1 addition & 1 deletion src/python/chaste/visualization/fortests.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def vtk_show(self, scene, width=400, height=300, output_format = "png", incremen
writer.SetWriteToMemory(1)
writer.SetInputConnection(windowToImageFilter.GetOutputPort())
writer.Write()
data = str(buffer(writer.GetResult()))
data = memoryview(writer.GetResult())

return Image(data)

Expand Down

0 comments on commit 031c5cf

Please sign in to comment.