<div dir="ltr">Hi Todd,<div><br></div><div>The Python buffer interface is the opposite of marshalling.  Python objects that support the buffer interface are able to directly access each other's memory.  The contents of a vtkDataArray wrapped in Python can be directly accessed by numpy routines that operate on buffers, i.e. the underlying C/C++/FORTRAN code directly sees the array contents as a raw pointer plus the data type, dimensions, and strides.  So, no, it isn't used for strings arrays or object arrays.  And it isn't supported by tuples since tuples aren't meant as a bulk data container.</div><div><br></div><div>I already mentioned in my first post that if people want to be able to return large vtk::vectors, I can add a wrapped std::vector object and have the wrappers return that instead of a tuple (and of course the wrapped vtk::vector would support iteration and indexing in Python).  There already are vtkVector and vtkTuple types for small fixed-size arrays, and parts of VTK's API uses them.  These are wrapped directly in Python rather than converted to tuples.</div><div><br></div><div> - David</div><div><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 6, 2018 at 3:16 AM Todd Martin <<a href="mailto:nztoddler@yahoo.com" target="_blank">nztoddler@yahoo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px"><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:16px"><div><div>Hi David<br><div><br><div><div>I agree that moving large chunks of data in a buffer is more efficient than iteration, but is that how arrays are marshaled into tuples in VTK? It certainly isn't possible for string/object arrays, since the memory size varies for each item.<br><div><br><div><div><div>I can also see that indexing into a list is more efficient, when a few specific items are needed; however, I don't think a tuple is the right object type for this, if the count is large. If std::array and std::vector are already being used for string lists, I believe that vtkArray and vtkVector types should be introduced that, optionally, expose a method to return a vtkIterator.<br><br></div></div></div></div></div><br></div></div></div><div><br></div><div class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955ydp58792aa3signature"><div style="font-size:16px;font-family:Helvetica,Arial,sans-serif"><div>Todd Martin, PhD.<br></div><div><i>Freelance Engineer/Software Architect.</i></div><br></div></div></div>
        <div><br></div><div><br></div>
        
        </div><div id="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yahoo_quoted_7053372558" class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yahoo_quoted">
            <div style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;color:#26282a">
                
                <div>
                    On Thursday, September 6, 2018, 2:29:45 PM GMT+12, David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528"><div><div dir="ltr">Hi Todd,<div><br clear="none"></div><div>VTK already supports the Python buffer interface for moving large amounts of data between VTK and Python, people have been using it to shuffle arrays between VTK and numpy for many years.  It's much more efficient than any iterator-based scheme.</div><div><br clear="none"></div><div>The main goal of wrapping std::vector is convenience: people have already been using std::vector for things like string lists, so there was a present demand for this feature.  The reason that I stuck with std::vector rather than going for a generic iterator-based interface is that it made it easy for me to piggy-back on the wrappers' existing support for C arrays.  Very little extra weight was added to the wrappers.</div><div><br clear="none"></div><div> - David</div><div><br clear="none"></div><div class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528yqt4625803681" id="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528yqt52947"><div><div><div><br clear="none"><div class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528gmail_quote"><div dir="ltr">On Wed, Sep 5, 2018 at 7:20 PM Andras Lasso <<a rel="nofollow" shape="rect" href="mailto:lasso@queensu.ca" target="_blank">lasso@queensu.ca</a>> wrote:<br clear="none"></div><blockquote class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US">
<div class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528m_8210864112105584769WordSection1">
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">I find this feature very useful! In application code, we commonly need to deal with variable-length arrays. We have been using std::vector accessors in C++ and adding vtkStringArray based or GetNumberOf…/GetNth… methods or for Python, which
 has made the API complex and has been very inconvenient to use in Python.<u></u><u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">These arrays typically contain up to a few ten elements, therefore, for us, convenience is much more important than efficiency.<u></u><u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u><u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Most often we return strings and vtkObject* in std::vector, so it would be great if vtkObject pointers would be supported, too.<u></u><u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Andras<u></u><u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><b>From:</b> vtk-developers <<a rel="nofollow" shape="rect" href="mailto:vtk-developers-bounces@public.kitware.com" target="_blank">vtk-developers-bounces@public.kitware.com</a>>
<b>On Behalf Of </b>Todd via vtk-developers<br clear="none">
<b>Sent:</b> Wednesday, September 5, 2018 8:16 PM<br clear="none">
<b>To:</b> David Gobbi <<a rel="nofollow" shape="rect" href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br clear="none">
<b>Cc:</b> VTK Developers <<a rel="nofollow" shape="rect" href="mailto:vtk-developers@vtk.org" target="_blank">vtk-developers@vtk.org</a>><br clear="none">
<b>Subject:</b> Re: [vtk-developers] Added support for std::vector to the wrappers<u></u><u></u></p>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Hi David<u></u><u></u></p>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Since std::vector types are unlikely to be small, like coordinate and bound arrays, that sounds horribly inefficient; especially when large quantities of strings and objects are being marshalled.<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Why not just map the std::vector/std::array to a Python iterator object?<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Todd<u></u><u></u></p>
</div>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">On 6 Sep 2018 4:20 a.m., David Gobbi <<a rel="nofollow" shape="rect" href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Hi Folks,<u></u><u></u></p>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Yesterday I merged a patch that allows std::vector<T> to be used from the Python wrappers, where T can be 'std::string' or any numeric type from 'signed char' to 'float' (including typedefs to those types).<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">This means that if you add a C++ method to VTK that takes std::vector<std::string>, then in Python you can pass a list or any other Python sequence and the wrappers will convert it to a vector for you.<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Method examples that can accept any Python sequence:<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">    void SetStrings(std::vector<std::string> strings);<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">    void SetStrings(const std::vector<std::string>& strings);<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Method example that takes a Python mutable sequence (the C++ method can write back to the container, since this is pass-by-reference):<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">    void GetStrings(std::vector<std::string>& strings);<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Method examples that return a vector (which is converted to a Python tuple):<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">    const std::vector<std::string>& GetStrings();<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">    std::vector<std::string>& GetStrings();<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">    std::vector<std::string> GetStrings();<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Note that std::vector is not 'wrapped' per se.  Instead, what is going on here is that the wrappers are converting to/from Python container types. My primary goal was convenience rather than efficiency, we can always add a wrapped std::vector
 type at a later date without sacrificing the convenience of automatic conversion.<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Chances are good that I'll be able to add std::vectors of VTK objects (smart or dumb pointers) and vtkVariant before VTK 9, but only if someone adds methods to VTK that take parameters of those types (as far as I know, there aren't any
 yet).<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">See the following VTK gitlab issue for additional information:<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><a rel="nofollow" shape="rect" href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.kitware.com%2Fvtk%2Fvtk%2Fissues%2F17362&data=02%7C01%7Classo%40queensu.ca%7C0e1f3f218b5543a5524608d6138e03b5%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636717898021517951&sdata=9vohuaiduQLCm6pfGlMxQbXL4hYutf1fKB6SafvQE4c%3D&reserved=0" target="_blank">https://gitlab.kitware.com/vtk/vtk/issues/17362</a><u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">The following is a list of VTK methods that take std::vector that have been wrapped due to this change (it is a short list, since people have historically avoided using std::vector as part of the VTK public API due to the obvious reason
 that they didn't want to exclude their methods from wrapping):<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkActor::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkAMRInformation::GetNumBlocks<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkCompositePolyDataMapper2::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkMapper::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkMultiProcessStream::GetRawData<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkMultiProcessStream::SetRawData<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLGlyph3DHelper::GlyphRender<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLIndexBufferObject::AppendTriangleIndexBuffer<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLIndexBufferObject::AppendLineIndexBuffer<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLIndexBufferObject::AppendTriangleLineIndexBuffer<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLIndexBufferObject::AppendPointIndexBuffer<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLIndexBufferObject::AppendStripIndexBuffer<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLIndexBufferObject::AppendEdgeFlagIndexBuffer<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLMoleculeMapper::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLPointGaussianMapper::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLPolyDataMapper::HandleAppleBug<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLPolyDataMapper::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLVertexBufferObject::SetShift<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLVertexBufferObject::SetScale<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLVertexBufferObject::GetShift<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLVertexBufferObject::GetScale<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkOpenGLVertexBufferObject::GetPackedVBO<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkParallelAMRUtilities::DistributeProcessInformation<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkProp::ProcessSelectorPixelBuffers<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkResourceFileLocator::Locate<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkShadowMapPass::ShadowMapTransforms<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkShadowMapPass::GetShadowMapTextureUnits<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkSparseArray::GetUniqueCoordinates<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">vtkUnicodeString::utf16_str<u></u><u></u></p>
</div>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"> - David<u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="m_-6186566561629308760m_-1279958805555581280m_-3640395916822351955yiv4300103528MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>

</blockquote></div></div></div></div></div></div></div></div></div>
            </div>
        </div></div></div></blockquote></div></div></div>