<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi David/VTK'ers, </div><div class=""><br class=""></div><div class="">Following on from my previous email i am now having diffcultly using a more complicated data structure in a derived class. In this case i am trying:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class="">#include "vtkImageData.h"</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class="">#include <boost/python.hpp></font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class="">class VTK_EXPORT vtkImageDataDict: public vtkImageData</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class="">{</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class="">public:</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> vtkTypeMacro(vtkImageDataDict, vtkImageData);</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> // New method</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> static vtkImageDataDict *New();</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font size="1" face="Courier" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> // Python dictionary</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> boost::python::dict m_dict;</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> // test function to set the dictionary</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> void test_set_dict();</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> // prints the dictionary</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> void printImageDict();</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> // Dictionary getter</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> boost::python::dict getDict(){return this->m_dict;}</font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Courier" size="1" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> // Dictionary setter</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class=""> void setDict(boost::python::object dd);</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier" size="1" class="">};</font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">When I wrap the above class the <span style="font-family: Courier; font-size: x-small;" class="">test_set_dict </span>and<span style="font-family: Courier; font-size: x-small;" class=""> </span><span style="font-family: Courier; font-size: x-small;" class="">printImageDict </span>work fine but the wrapper seems to ignore <span style="font-family: Courier; font-size: x-small;" class="">getDict()</span></div><div class="">and <span style="font-family: Courier; font-size: x-small;" class="">setDict(). </span>I assume this is because vtkWrapperPython does not know what to do with <span style="font-family: Courier; font-size: x-small;" class="">boost::python </span>objects. Maybe I am going about this the wrong way? I did try doing the wrapping through boost python rather than VTK but found I ran into compilation issues. </div><div class=""><br class=""></div><div class="">Any help would be very much appreciated. </div><div class=""><br class=""></div><div class="">Kit</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 29 Jul 2016, at 17:07, David Gobbi <<a href="mailto:david.gobbi@gmail.com" class="">david.gobbi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Kit,<div class=""><br class=""></div><div class="">It's most likely because the class is missing vtkTypeMacro:</div><div class=""><br class=""></div><div class="">vtkTypeMacro(vtkNewData, vtkImageData);</div><div class=""><br class=""></div><div class=""> - David</div><div class=""><br class=""></div><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Jul 29, 2016 at 9:02 AM, Kit Chambers <span dir="ltr" class=""><<a href="mailto:kit.chambers.kc@gmail.com" target="_blank" class="">kit.chambers.kc@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class="">Hi,<div class=""><br class=""></div><div class="">I am trying to wrap a custom class derived from vtkImageData in python. And it works except for when i try to access my custom methods. For example:</div><div class=""><br class=""></div><font face="Courier New" class=""><span class="">import vtkNewDataPython as idp<br class=""></span><span class=""><br class="">mydata = idp.vtkNewData()<br class=""><br class="">print "\nvtkImageData functionality"<br class="">mydata.SetDimensions(2,3,1)<br class="">dims = mydata.GetDimensions()<br class="">print "image dimensions =",dims<br class="">print "Number of points: ",mydata.GetNumberOfPoints()<br class="">print "Number of cells: ",mydata.GetNumberOfCells()<br class=""><br class="">print "\ncustom functionality" <br class="">mydata.set_myvalue()<br class="">print "Myvalue = ", mydata.get_myvalue()<br class=""></span></font><span class=""><br class=""></span><span class=""><br class=""></span><div class="">Produces:</div><div class=""><div class=""><font face="Courier New" class="">vtkImageData functionality</font></div><div class=""><font face="Courier New" class="">image dimensions = (2, 3, 1)</font></div><div class=""><font face="Courier New" class="">Number of points: 6</font></div><div class=""><font face="Courier New" class="">Number of cells: 2</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">custom functionality</font></div><div class=""><font face="Courier New" class="">Traceback (most recent call last):</font></div><div class=""><font face="Courier New" class=""> File "./pytest.py", line 14, in <module></font></div><div class=""><font face="Courier New" class=""> mydata.set_myvalue()</font></div><div class=""><font face="Courier New" class="">AttributeError: set_myvalue</font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Basically it is doing just fine up until I try to call a custom method</div><div class=""><br class=""></div><div class="">The class looks like this:</div><div class=""><br class=""></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">#include "vtkImageData.h"</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">class VTK_EXPORT vtkNewData: public vtkImageData</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">{</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">public:</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> static vtkNewData *New();</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> void set_myvalue(){</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""><span style="white-space:pre-wrap" class=""> </span> this->myvalue=3;</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> }</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> int get_myvalue(){</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""><span style="white-space:pre-wrap" class=""> </span> return this->myvalue;</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> }</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> int myvalue;</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">};</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">The CmakeLists.txt is adapted mostly from <a href="https://github.com/paulmelis/vtk-wrapping-example" target="_blank" class="">https://github.com/paulmelis/vtk-wrapping-example</a> and looks like this</div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">#######################################</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""># Pre-requisites</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""># C++11 flags</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""># VTK</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">find_package(VTK REQUIRED</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> vtkCommonCore</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> vtkCommonDataModel</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> vtkWrappingPythonCore </font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> )</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">include(${VTK_USE_FILE})</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""># Python and vtk wrapping</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">find_package(PythonLibs 2.7 EXACT REQUIRED)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">include(vtkWrapPython)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">include_directories("${PYTHON_INCLUDE_PATH}")</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">#######################################</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""># Building vtkNewData</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">add_library(vtkNewData SHARED vtkNewData.cxx)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">TARGET_LINK_LIBRARIES(vtkNewData ${VTK_LIBRARIES} )</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">if(APPLE) </font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> set_target_properties(vtkNewData PROPERTIES SUFFIX ".so")</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">endif()</font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">#######################################</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""># Wrapping vtkNewData</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">vtk_wrap_python3(vtkNewDataPython vtkNewDataPython_SRCS vtkNewData.cxx)</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">add_library(vtkNewDataPythonD ${vtkNewDataPython_SRCS} vtkNewData.cxx)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">target_link_libraries(vtkNewDataPythonD </font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> ${VTK_LIBRARIES}</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> vtkWrappingPythonCore </font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> ${VTK_PYTHON_LIBRARIES})</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><br class=""></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">add_library(vtkNewDataPython MODULE vtkNewDataPythonInit.cxx)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">set(VTK_MODULES_USED vtkCommonDataModel vtkCommonCore) </font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">set(VTK_PYTHOND_LIBS)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">foreach(TMP_LIB ${VTK_MODULES_USED})</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> set(VTK_PYTHOND_LIBS ${VTK_PYTHOND_LIBS} ${TMP_LIB}PythonD)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">endforeach() </font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">target_link_libraries(vtkNewDataPython vtkNewDataPythonD ${VTK_PYTHOND_LIBS})</font></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">set_target_properties(vtkNewDataPython PROPERTIES PREFIX "")</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">if(WIN32 AND NOT CYGWIN)</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class=""> set_target_properties(vtkNewDataPython PROPERTIES SUFFIX ".pyd")</font></div><div style="margin:0px;line-height:normal" class=""><font face="Courier New" class="">endif(WIN32 AND NOT CYGWIN)</font></div></div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">I suspect there is something very simple I am missing here but cannot for the life of me think what. Any help would be appreciated.</div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">Cheers</div><span class="gmail-HOEnZb"><font color="#888888" class=""><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">Kit</div></font></span></div></blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></body></html>