Login
Username:

Password:


Lost Password?

Register now!
Main Menu
H3D.org Feeds
H3D.org Forum Index
   Programming Issues
     Routing from C++ to Python Fields
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
GBaitson
Posted on: 2010/1/26 18:46
Quite a regular
Joined: 2009/5/19
From: National Digital Research Centre
Posts: 25
Routing from C++ to Python Fields
Hi all,

Would someone be able to help with a small problem please. I am working on trying to route fields from C++ to Python. I can get it to work using X3D (as below)

<PythonScript DEF="PS" url="Python.py"> </PythonScript> 
<ROUTE fromNode="IMAGE_INFO" fromField="totalSize" toNode="PS" toField="matrix" />


But when trying to do this is C++ (as below), the build crashes and won't run

PythonScript *ps = new PythonScript;
ps->setURLBase("Python.py");
imageInfo->totalSize->route(ps->getField("matrix"));


It could have something got to do with the "getField" method of the PythonScript. We've noticed that the getField method returns a Field pointer, whereas Route requires an AutoPointer. Do we have to use a method that returns an auto pointer or do we have to cast the return type of another method as an auto pointer? If so, what method/function would return a PythonScript field that we can route to?

Also, is there a way to see if the PythonScript is actually being loaded and that the variables/fields are accessible within the C++ file>

Any comments would be greatly appreciated
karlu
Posted on: 2010/1/27 8:02
Guru
Joined: 2004/12/2
From: Sweden
Posts: 585
Re: Routing from C++ to Python Fields
Could it be that the Python script has never actually executed when you try to find its fields and therefore is not fully initialized? Try calling initialize and maybe also traverseSG.


----------------
KJ Lundin Palmerius
Norrköping Visualization and Interaction Studio
Linköping University, Sweden

Markus
Posted on: 2010/1/27 8:17
Webmaster
Joined: 2006/3/27
From: SenseGraphics
Posts: 1531
Re: Routing from C++ to Python Fields
Use:
ps->url->setValue( "Python.py" );

setURLBase will not do what you think it does.
GBaitson
Posted on: 2010/1/27 12:34
Quite a regular
Joined: 2009/5/19
From: National Digital Research Centre
Posts: 25
Re: Routing from C++ to Python Fields
Thanks for your replies,

Eventually got it working, it was a mixture of both of your comments. In using H3D2.1, the 'setValue' method was looking for a vector of MFStrings. Upon creating a vector of MFString it was complaining that it wouldn't allow the conversion from const std::vector<_Ty> to const std::vector<_Ty> &, which I couldn't figure out exactly how to fix this.

So, I came across the method 'setValueFromString' which allowed the string path of the python file to be specified. Once this is specified, we then initialize the PythonScript.

So below is the piece of code that works

PythonScript *ps = new PythonScript;
ps->url->setValueFromString("Python.py");
ps->initialize();

c++_field->route(ps->getField("python_field"));
Markus
Posted on: 2010/2/3 8:17
Webmaster
Joined: 2006/3/27
From: SenseGraphics
Posts: 1531
Re: Routing from C++ to Python Fields
Just to make a small correction, setValue does does not require a vector of MFStrings, but a vector of std:string.

So my code was incorrect, it should have been:
vector<string> my_urls;
my_urls.push_back( "Python.py" );
ps->url->setValue( my_urls );


Where did you read that it required a vector of MFStrings?
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 



(C) 2004 SenseGraphics AB    ---    Powered by XOOPS