Why is it so complicated to call a procedure and receive a return value on the client?
I am attaching my attempt (CMakeLists.txt, vtkSquareFun.cxx, vtkSquareFun.h and TestPlugin.xml, each less than 20 lines of code), which basically calculates the square of an argument in vtkSquareFun::eval(double x). When I load this plugin in Paraview and open the Python Shell, I can evaluate vtkSquareFun::eval() using a detour by first setting the argument and then getting the result, which is linked to the argument property in TestPlugin.xml: fun=servermanager.CreateProxy("test","SquareFun") fun.GetProperty("Arg").SetElement(0,999) fun.UpdateVTKObjects() fun.UpdatePropertyInformation() fun.GetProperty("Result").GetElement(0) ... showing the correct result 998001. Why can't I simply run the following? fun=servermanager.CreateProxy("test","SquareFun") result=fun.InvokeCommand("eval",[999.0]) Does Paraview really not provide any means of calling a function with arguments and return value within a single client-server communication? All these individual message transfers are a bottleneck in our application. Does the Paraview architecture exclude more universal remote procedure calls, or do you think that one could just augment the available procedures with another procedure that can deliver a set of custom return values? Thanks Mario 2016-12-07 7:34 GMT+01:00 Mario Schreiber <schreibermari...@gmail.com>: > Hello, > I have a use case, where a vtkObject on the server implements a method like > > std::string doSomething(std::string arg); > > Now, with a proxy prx on the client for that class, I would like to call > the remote procedure similar to > > result=prx.InvokeCommand("doSomething",[arg]) > > Is something like this possible? > I found a very complicated workaround by first defining the arguments as > properties, defining the result as information_only property linked to on > of the args, then calling "UpdateVTKObjects" to push the arguments and > finally "UpdateInformationProperties" to pull the result. Is there an > easier solution, possible with a short example? > > Thank you > Mario >
FIND_PACKAGE(ParaView REQUIRED) INCLUDE(${PARAVIEW_USE_FILE}) ADD_PARAVIEW_PLUGIN(TestPlugin "1.0" SERVER_MANAGER_XML TestPlugin.xml SERVER_MANAGER_SOURCES vtkSquareFun.cxx )
<ServerManagerConfiguration> <ProxyGroup name="test"> <Proxy name="SquareFun" class="vtkSquareFun" label="SquareFun"> <DoubleVectorProperty name="Result" command="SetResult" number_of_elements="1" information_only="1" default_values="-1.0"> </DoubleVectorProperty> <DoubleVectorProperty name="Arg" command="SetArg" number_of_elements="1" information_property="Result" default_values="-1.0"> </DoubleVectorProperty> </Proxy> </ProxyGroup> </ServerManagerConfiguration>
#include "vtkSquareFun.h" #include "vtkObjectFactory.h" vtkStandardNewMacro(vtkSquareFun); void vtkSquareFun::SetArg(double x){ Arg=x; Result=eval(Arg); this->Modified(); } double vtkSquareFun::eval(double x){ return x*x; } double vtkSquareFun::SetResult(){ this->Modified(); return Result; }
#ifndef __vtkSquareFun_h #define __vtkSquareFun_h #include "vtkObject.h" class vtkSquareFun: public vtkObject{ double Arg; double Result; public: static vtkSquareFun *New(); double eval(double x); vtkTypeMacro(vtkSquareFun,vtkObject); //vtkSetMacro(Arg,double); void SetArg(double x); vtkGetMacro(Arg,double); vtkSetMacro(Result,double); vtkGetMacro(Result,double); double SetResult(); }; #endif
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView Search the list archives at: http://markmail.org/search/?q=ParaView Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/paraview