[Paraview-developers] establish client connection to pvserver from C++

Peter Vogt vogtpeter5 at gmail.com
Thu Apr 21 11:47:16 EDT 2016


Thank you!
Your example runs fine. The controller's sources also helped me to sort out
what was missing in my example, and what you meant by adding the
representation to the corresponding property of the view. Basically I
missed two calls "vtkSMPropertyHelper(repr, "Input").Set(sphere, 0);" and
"vtkSMPropertyHelper(view, "Representations").Add(repr);" and a few
"UpdateVTKObjects()."
I include my working example below, and I think we can consider my question
solved :)

By the way, is it ok to ask this kind of questions on the developers list?
I tried some other paraview coding years ago and didn't get any reply on
the users mailing list.

Thanks
Peter

my working solution:

#include "vtkInitializationHelper.h"
#include "vtkProcessModule.h"
#include "vtkPVOptions.h"
#include "vtkSMProxyManager.h"
#include "vtkSMSession.h"
#include "vtkSMSessionClient.h"
#include "vtkSMSessionProxyManager.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMProperty.h"
#include "vtkSMRenderViewProxy.h"

#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

#include "vtkSMRepresentationProxy.h"
#include "vtkSMPropertyHelper.h"

int main(int argc, char* argv[])
{
  // Initialization
  vtkPVOptions* options = vtkPVOptions::New();
  vtkInitializationHelper::Initialize(argc, argv,
                                      vtkProcessModule::PROCESS_CLIENT,
                                      options);

  vtkSMSessionClient* session = vtkSMSessionClient::New();
  vtkProcessModule::GetProcessModule()->RegisterSession(session);
  session->Connect(options->GetServerURL());
  cout<<"Connected to: "<<options->GetServerURL()<<endl;

  vtkSMSessionProxyManager *pxm = session->GetSessionProxyManager();
  vtkSMProxy *sphere = pxm->NewProxy("sources", "SphereSource");
  sphere->UpdateVTKObjects();
  cout<<"SphereSource created."<<endl;
  vtkSMRenderViewProxy* view=(vtkSMRenderViewProxy*)pxm->NewProxy("views",
"RenderView");
  bool ok=view->MakeRenderWindowInteractor(false);
  cout<<"RenderView created. "<<ok<<endl;
  vtkSMRepresentationProxy*
repr=view->CreateDefaultRepresentation(sphere,0);
  cout<<"DefaultRepresentation created."<<endl;

  vtkSMPropertyHelper(repr, "Input").Set(sphere, 0);
  vtkSMPropertyHelper(view, "Representations").Add(repr);
  repr->UpdateVTKObjects();
  view->UpdateVTKObjects();

  view->GetInteractor()->Initialize();
  view->GetInteractor()->Start();

  //TODO: clean up stuff
}


On Thu, Apr 21, 2016 at 4:49 PM, Utkarsh Ayachit <
utkarsh.ayachit at kitware.com> wrote:

> Peter,
>
> Here's an example:
>
> https://gitlab.kitware.com/paraview/paraview/merge_requests/747/diffs
>
> Utkarsh
>
> On Thu, Apr 21, 2016 at 9:57 AM, Peter Vogt <vogtpeter5 at gmail.com> wrote:
> > Thank you, Utkarsh,
> > the time for writing our last posts has overlapped. I had fixed the
> missing
> > UpdateVTKObjects() call in between, and I think the only missing step is
> to
> > add the sphere's representation to the view proxy.
> > But how do I add it to the Representations "property"? Neither
> > vtkSMViewProxy nor vtkSMRenderViewProxy have a method like
> > GetRepresentations() or InsertRepresentation(). Getting this final step
> > right will certainly help me understand the programming principle.
> >
> > If the vtkSMParaViewPipleineControllerWithRendering is the recommended
> way
> > of remotely rendering objects, I'll definitely appreciate an example
> using
> > this class, if it doesn't cost you too much time.
> >
> > Thanks
> > Peter
> >
> >
> > On Thu, Apr 21, 2016 at 3:42 PM, Utkarsh Ayachit
> > <utkarsh.ayachit at kitware.com> wrote:
> >>
> >> Peter,
> >>
> >> After a proxy is created or after any of its properties are changed,
> >> one must call "vtkSMProxy::UpdateVTKObject()" to push the changes made
> >> locally to the server or the underlying VTK objects. Try putting a
> >> call to this method the NewProxy(...) calls. You're also missing
> >> adding the Sphere source's representation to the View proxy's
> >> "Representations" property. Other option is to use the
> >> vtkSMParaViewPipleineControllerWithRendering.
> >>
> >> Give me a few hours, and I can put together an example that uses the
> >> controller to create a view and show something in it to get you
> >> started.
> >>
> >> Utkarsh
> >>
> >>
> >>
> >> On Thu, Apr 21, 2016 at 8:49 AM, Peter Vogt <vogtpeter5 at gmail.com>
> wrote:
> >> > Hello again,
> >> > thanks to your help, I was able to establish a connection to a
> pvserver
> >> > and
> >> > create a SphereSource proxy. Now I cannot figure out how to view the
> >> > rendered scene on the client.
> >> >
> >> > My attempt, "TestConnection.cxx", is attached below. I have tried
> three
> >> > alternatives, which I have marked in the code:
> >> > Alternative 1 calls "view->StillRender()", which shows the greyish
> >> > background, maybe because the sphere is outside the viewport?
> >> > Alternative 2 calls "view->ResetCamera()" before the StillRender(),
> but
> >> > ResetCamera crashes with the following output:
> >> >>ERROR: In
> >> >>
> >> >>
> /opt/ParaView-v5.0.1-source/ParaViewCore/ServerImplementation/Core/vtkPVSessionCoreInterpreterHelper.cxx,
> >> >> line 63
> >> >>vtkPVSessionCoreInterpreterHelper (0x976950): No vtkSIProxy for id :
> 257
> >> >>
> >> >>ERROR: In
> >> >>
> >> >>
> /opt/ParaView-v5.0.1-source/ParaViewCore/ServerImplementation/Core/vtkPVSessionCore.cxx,
> >> >> line 390
> >> >>vtkPVSessionCore (0x8ca480): Wrapper function not found for class
> "(vtk
> >> >> object is NULL)".
> >> >>while processing
> >> >>Message 0 = Invoke
> >> >>  Argument 0 = stream_value {
> >> >>    Message 0 = Invoke
> >> >>      Argument 0 = id_value {1}
> >> >>      Argument 1 = string_value {GetVTKObject}
> >> >>      Argument 2 = uint32_value {257}
> >> >>    }
> >> >>  Argument 1 = string_value {ResetCamera}
> >> >>
> >> >>
> >> >>ERROR: In
> >> >>
> >> >>
> /opt/ParaView-v5.0.1-source/ParaViewCore/ServerImplementation/Core/vtkPVSessionCore.cxx,
> >> >> line 391
> >> >>vtkPVSessionCore (0x8ca480): Aborting execution for debugging
> purposes.
> >> >>
> >> >>############ ABORT #############
> >> >>Wrong tag but don't know how to handle it... 188971
> >> >>Aborted (core dumped)
> >> > Alternative 3 tries to show an interactive RenderWindow, but crashes,
> >> > because view->GetInteractor() returns NULL.
> >> >
> >> > Apparently I am missing some important step. Can somebody point out
> how
> >> > to
> >> > modify the example (below) in order to render the sphere source
> visible?
> >> >
> >> > Thank you
> >> > Peter
> >> >
> >> > TestConnection.cxx:
> >> >
> >> > #include "vtkInitializationHelper.h"
> >> > #include "vtkProcessModule.h"
> >> > #include "vtkPVOptions.h"
> >> > #include "vtkSMProxyManager.h"
> >> > #include "vtkSMSession.h"
> >> > #include "vtkSMSessionClient.h"
> >> > #include "vtkSMSessionProxyManager.h"
> >> > #include "vtkSMSourceProxy.h"
> >> > #include "vtkSMProperty.h"
> >> > #include "vtkSMRenderViewProxy.h"
> >> >
> >> > #include "vtkRenderWindow.h"
> >> > #include "vtkRenderWindowInteractor.h"
> >> >
> >> > int main(int argc, char* argv[])
> >> > {
> >> >   // Initialization
> >> >   vtkPVOptions* options = vtkPVOptions::New();
> >> >   vtkInitializationHelper::Initialize(argc, argv,
> >> >
>  vtkProcessModule::PROCESS_CLIENT,
> >> >                                       options);
> >> >
> >> >   vtkSMSessionClient* session = vtkSMSessionClient::New();
> >> >   vtkProcessModule::GetProcessModule()->RegisterSession(session);
> >> >   session->Connect(options->GetServerURL());
> >> >   cout<<"Connected to: "<<options->GetServerURL()<<endl;
> >> >
> >> >   vtkSMSessionProxyManager *pxm = session->GetSessionProxyManager();
> >> >   vtkSMProxy *sphere = pxm->NewProxy("sources", "SphereSource");
> >> >   cout<<"SphereSource created."<<endl;
> >> >   vtkSMRenderViewProxy*
> >> > view=(vtkSMRenderViewProxy*)pxm->NewProxy("views",
> >> > "RenderView");
> >> >   cout<<"RenderView created."<<endl;
> >> >   vtkSMRepresentationProxy*
> >> > repr=view->CreateDefaultRepresentation(sphere,0);
> >> >   cout<<"DefaultRepresentation created."<<endl;
> >> >
> >> > //Alternative 1:
> >> >   view->StillRender(); while(1); //no crash, but only background
> >> > visible.
> >> >
> >> > //Alternative 2:
> >> > /*
> >> >   view->ResetCamera(); //crash here
> >> >   view->StillRender(); while(1);
> >> > */
> >> >
> >> > //Alternative 3:
> >> > /*
> >> >   view->InteractiveRender();
> >> >   view->GetInteractor()->Initialize(); //crash here, because
> >> > view->GetInteractor()==NULL
> >> >   view->GetInteractor()->Start();
> >> > */
> >> >   //TODO: clean up stuff
> >> > }
> >> >
> >> > On Wed, Apr 20, 2016 at 5:26 PM, Utkarsh Ayachit
> >> > <utkarsh.ayachit at kitware.com> wrote:
> >> >>
> >> >> > Thank you, but we need a pure C++ solution. There is plenty of
> >> >> > information
> >> >> > how this is done with python scripting, but I can't find anything
> for
> >> >> > C++.
> >> >> > I really need nothing more than a minimal example.
> >> >>
> >> >> Peter, look at TestComparativeAnimationCueProxy.cxx[1] file in the
> >> >> ParaView source. It demonstrates how the initialization needs to
> >> >> happen. If you have further questions on how to use anything specific
> >> >> in this application, feel free to holler :).
> >> >>
> >> >> [1]
> >> >>
> >> >>
> https://gitlab.kitware.com/paraview/paraview/blob/master/ParaViewCore/ServerManager/Default/Testing/Cxx/TestComparativeAnimationCueProxy.cxx
> >> >>
> >> >> Utkarsh
> >> >
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview-developers/attachments/20160421/b1e19d28/attachment.html>


More information about the Paraview-developers mailing list