Dynamically change colors?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dynamically change colors?

Brennan Peter Sellner
Hi,

Is it possible to dynamically change the color and/or alpha of objects in
the scene from within a plugin?  For kicks, I exposed
KinBody::Link::_listGeomProperties and tried changing the diffuseColor and
ambientColor, but that had no effect, as I expected.

Thanks,

-Brennan



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamically change colors?

Rosen Diankov-2
No it isn't. But there's two other options you can do:

- Have multiple XML files of the same object but with different
colors. Then when you want to change a color, just call KinBody::Init
on a new XML file. You might want to store the transformation and
joint angles beforehand.
- Use the plotting functions to mark stuff.

Rosen,

2008/7/13 Brennan Peter Sellner <[hidden email]>:

> Hi,
>
> Is it possible to dynamically change the color and/or alpha of objects in
> the scene from within a plugin?  For kicks, I exposed
> KinBody::Link::_listGeomProperties and tried changing the diffuseColor and
> ambientColor, but that had no effect, as I expected.
>
> Thanks,
>
> -Brennan
>
>
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> _______________________________________________
> Openrave-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openrave-users
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamically change colors?

Brennan Peter Sellner
Hi,

I'm attempting to swap in a new XML file for a KinBody, as you suggested,
but Coin is segfaulting when I do.  Is there a mutex I should be acquiring
first?

My (trimmed) code:

   KinBody* b = g_pEnviron->GetKinBody(w.wstr);

   string xmlFile = b->GetXMLFilename();
   <manipulate the filename to build a new one and store in xmlFile>

   // Store transformation and joint angles
   Transform t = b->GetTransform();
   float* jointValues = NULL;
   int dof = b->GetDOF();
   if(dof > 0) {
     jointValues = new float[b->GetDOF()];
   }

   // Load new XML file
   b->Init(xmlFile.c_str(), NULL);

   if(dof != b->GetDOF()) {
     RAVEPRINT(L"FATAL ERROR: Cannot replace a body with %d DOF with a differing number of DOF (%d).\n", dof, b->GetDOF());
     assert(dof == b->GetDOF());
   }

   // Restore transformation and joint angles
   b->SetTransform(t);
   if(jointValues != NULL) {
     b->SetJointValues(NULL, NULL, jointValues);
   }

When I do this, the viewer crashes at some point after my function
returns, with the following backtrace:

#0  0xb7c31dca in SoSFRotation::setValue () from /usr/lib/libCoin.so.40
#1  0xb7c31f41 in SoSFRotation::setValue () from /usr/lib/libCoin.so.40
#2  0x080ef7e7 in KinBodyItem::UpdateFromModel (this=0x9f75b18, vtrans=@0xa03f7c4) at Item.cpp:353
#3  0x080e5709 in QtCoinViewer::UpdateFromModel (this=0x82677e0) at qtcoinviewer.cpp:1665
#4  0x080e3c7b in QtCoinViewer::AdvanceFrame (this=0x82677e0, bForward=true) at qtcoinviewer.cpp:1571
#5  0xb7dbca36 in SoSensor::trigger () from /usr/lib/libCoin.so.40
#6  0xb7dbf504 in SoTimerSensor::trigger () from /usr/lib/libCoin.so.40
#7  0xb7dbd2e0 in SoSensorManager::processTimerQueue () from /usr/lib/libCoin.so.40
#8  0x080f3063 in SoQtP::slot_timedOutSensor (this=0x82aa368) at SoQt.cpp:431
#9  0x080f2cfd in SoQtP::qt_metacall (this=0x82aa368, _c=InvokeMetaMethod, _id=0, _a=0x0) at moc_SoQtP.icc:68
#10 0xb69a52bd in QMetaObject::activate () from /usr/lib/libQtCore.so.4
#11 0xb69a56f6 in QMetaObject::activate () from /usr/lib/libQtCore.so.4
#12 0xb69c10df in QTimer::timeout () from /usr/lib/libQtCore.so.4
#13 0xb69ad734 in QTimer::timerEvent () from /usr/lib/libQtCore.so.4
#14 0xb69a47e6 in QObject::event () from /usr/lib/libQtCore.so.4
#15 0xb73c37c5 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4
#16 0xb73c4700 in QApplication::notify () from /usr/lib/libQtGui.so.4
#17 0xb69b82f0 in QEventDispatcherUNIX::activateTimers () from /usr/lib/libQtCore.so.4
#18 0xb69b892b in QEventDispatcherUNIX::processEvents () from /usr/lib/libQtCore.so.4
#19 0xb74268a6 in non-virtual thunk to QDesktopWidget::~QDesktopWidget() () from /usr/lib/libQtGui.so.4
#20 0xb699768a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4
#21 0xb699789d in QEventLoop::exec () from /usr/lib/libQtCore.so.4
#22 0xb6999fe7 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4
#23 0xb73c3565 in QApplication::exec () from /usr/lib/libQtGui.so.4
#24 0x080e3357 in QtCoinViewer::main (this=0x82677e0) at qtcoinviewer.cpp:1375
#25 0x08062e68 in MainOpenRAVEThread (p=0x0) at main.cpp:352
#26 0xb7832341 in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#27 0xb6aec4ee in clone () from /lib/tls/i686/cmov/libc.so.6

I'm running OpenRAVE r248 on Ubuntu 6.06, with libcoin 2.4.4 and Qt 4.1.2.

Thanks,

-Brennan


On Sun, 13 Jul 2008, Rosen Diankov wrote:

> No it isn't. But there's two other options you can do:
>
> - Have multiple XML files of the same object but with different
> colors. Then when you want to change a color, just call KinBody::Init
> on a new XML file. You might want to store the transformation and
> joint angles beforehand.
> - Use the plotting functions to mark stuff.
>
> Rosen,
>
> 2008/7/13 Brennan Peter Sellner <[hidden email]>:
>> Hi,
>>
>> Is it possible to dynamically change the color and/or alpha of objects in
>> the scene from within a plugin?  For kicks, I exposed
>> KinBody::Link::_listGeomProperties and tried changing the diffuseColor and
>> ambientColor, but that had no effect, as I expected.
>>
>> Thanks,
>>
>> -Brennan
>>
>>
>> -------------------------------------------------------------------------
>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
>> Studies have shown that voting for your favorite open source project,
>> along with a healthy diet, reduces your potential for chronic lameness
>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>> _______________________________________________
>> Openrave-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/openrave-users
>>
>
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamically change colors?

Rosen Diankov-2
Problem has been fixed in rev 250. Make sure to call b->Destroy()
before you call b->Init() or you'll just get the geometry appended to
the current link.

Rosen,

2008/7/14 Brennan Peter Sellner <[hidden email]>:

> Hi,
>
> I'm attempting to swap in a new XML file for a KinBody, as you suggested,
> but Coin is segfaulting when I do.  Is there a mutex I should be acquiring
> first?
>
> My (trimmed) code:
>
>   KinBody* b = g_pEnviron->GetKinBody(w.wstr);
>
>   string xmlFile = b->GetXMLFilename();
>   <manipulate the filename to build a new one and store in xmlFile>
>
>   // Store transformation and joint angles
>   Transform t = b->GetTransform();
>   float* jointValues = NULL;
>   int dof = b->GetDOF();
>   if(dof > 0) {
>     jointValues = new float[b->GetDOF()];
>   }
>
>   // Load new XML file
>   b->Init(xmlFile.c_str(), NULL);
>
>   if(dof != b->GetDOF()) {
>     RAVEPRINT(L"FATAL ERROR: Cannot replace a body with %d DOF with a differing number of DOF (%d).\n", dof, b->GetDOF());
>     assert(dof == b->GetDOF());
>   }
>
>   // Restore transformation and joint angles
>   b->SetTransform(t);
>   if(jointValues != NULL) {
>     b->SetJointValues(NULL, NULL, jointValues);
>   }
>
> When I do this, the viewer crashes at some point after my function
> returns, with the following backtrace:
>
> #0  0xb7c31dca in SoSFRotation::setValue () from /usr/lib/libCoin.so.40
> #1  0xb7c31f41 in SoSFRotation::setValue () from /usr/lib/libCoin.so.40
> #2  0x080ef7e7 in KinBodyItem::UpdateFromModel (this=0x9f75b18, vtrans=@0xa03f7c4) at Item.cpp:353
> #3  0x080e5709 in QtCoinViewer::UpdateFromModel (this=0x82677e0) at qtcoinviewer.cpp:1665
> #4  0x080e3c7b in QtCoinViewer::AdvanceFrame (this=0x82677e0, bForward=true) at qtcoinviewer.cpp:1571
> #5  0xb7dbca36 in SoSensor::trigger () from /usr/lib/libCoin.so.40
> #6  0xb7dbf504 in SoTimerSensor::trigger () from /usr/lib/libCoin.so.40
> #7  0xb7dbd2e0 in SoSensorManager::processTimerQueue () from /usr/lib/libCoin.so.40
> #8  0x080f3063 in SoQtP::slot_timedOutSensor (this=0x82aa368) at SoQt.cpp:431
> #9  0x080f2cfd in SoQtP::qt_metacall (this=0x82aa368, _c=InvokeMetaMethod, _id=0, _a=0x0) at moc_SoQtP.icc:68
> #10 0xb69a52bd in QMetaObject::activate () from /usr/lib/libQtCore.so.4
> #11 0xb69a56f6 in QMetaObject::activate () from /usr/lib/libQtCore.so.4
> #12 0xb69c10df in QTimer::timeout () from /usr/lib/libQtCore.so.4
> #13 0xb69ad734 in QTimer::timerEvent () from /usr/lib/libQtCore.so.4
> #14 0xb69a47e6 in QObject::event () from /usr/lib/libQtCore.so.4
> #15 0xb73c37c5 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4
> #16 0xb73c4700 in QApplication::notify () from /usr/lib/libQtGui.so.4
> #17 0xb69b82f0 in QEventDispatcherUNIX::activateTimers () from /usr/lib/libQtCore.so.4
> #18 0xb69b892b in QEventDispatcherUNIX::processEvents () from /usr/lib/libQtCore.so.4
> #19 0xb74268a6 in non-virtual thunk to QDesktopWidget::~QDesktopWidget() () from /usr/lib/libQtGui.so.4
> #20 0xb699768a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4
> #21 0xb699789d in QEventLoop::exec () from /usr/lib/libQtCore.so.4
> #22 0xb6999fe7 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4
> #23 0xb73c3565 in QApplication::exec () from /usr/lib/libQtGui.so.4
> #24 0x080e3357 in QtCoinViewer::main (this=0x82677e0) at qtcoinviewer.cpp:1375
> #25 0x08062e68 in MainOpenRAVEThread (p=0x0) at main.cpp:352
> #26 0xb7832341 in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
> #27 0xb6aec4ee in clone () from /lib/tls/i686/cmov/libc.so.6
>
> I'm running OpenRAVE r248 on Ubuntu 6.06, with libcoin 2.4.4 and Qt 4.1.2.
>
> Thanks,
>
> -Brennan
>
>
> On Sun, 13 Jul 2008, Rosen Diankov wrote:
>
>> No it isn't. But there's two other options you can do:
>>
>> - Have multiple XML files of the same object but with different
>> colors. Then when you want to change a color, just call KinBody::Init
>> on a new XML file. You might want to store the transformation and
>> joint angles beforehand.
>> - Use the plotting functions to mark stuff.
>>
>> Rosen,
>>
>> 2008/7/13 Brennan Peter Sellner <[hidden email]>:
>>> Hi,
>>>
>>> Is it possible to dynamically change the color and/or alpha of objects in
>>> the scene from within a plugin?  For kicks, I exposed
>>> KinBody::Link::_listGeomProperties and tried changing the diffuseColor and
>>> ambientColor, but that had no effect, as I expected.
>>>
>>> Thanks,
>>>
>>> -Brennan
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
>>> Studies have shown that voting for your favorite open source project,
>>> along with a healthy diet, reduces your potential for chronic lameness
>>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>>> _______________________________________________
>>> Openrave-users mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/openrave-users
>>>
>>
>>
>
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> _______________________________________________
> Openrave-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openrave-users
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dynamically change colors?

Brennan Peter Sellner
Thanks; that works nicely.

A note to anyone else trying this in the future: if you want to preserve
the node name (e.g. either you changed it, or the two XML files have
different name attributes), be sure to wcsdup(b->GetName()), then
b->SetName() after the Init(), as the name is deallocated in the process
of the destroy/init.

Thanks!

-Brennan

On Mon, 14 Jul 2008, Rosen Diankov wrote:

> Problem has been fixed in rev 250. Make sure to call b->Destroy()
> before you call b->Init() or you'll just get the geometry appended to
> the current link.
>
> Rosen,
>
> 2008/7/14 Brennan Peter Sellner <[hidden email]>:
>> Hi,
>>
>> I'm attempting to swap in a new XML file for a KinBody, as you suggested,
>> but Coin is segfaulting when I do.  Is there a mutex I should be acquiring
>> first?
>>
>> My (trimmed) code:
>>
>>   KinBody* b = g_pEnviron->GetKinBody(w.wstr);
>>
>>   string xmlFile = b->GetXMLFilename();
>>   <manipulate the filename to build a new one and store in xmlFile>
>>
>>   // Store transformation and joint angles
>>   Transform t = b->GetTransform();
>>   float* jointValues = NULL;
>>   int dof = b->GetDOF();
>>   if(dof > 0) {
>>     jointValues = new float[b->GetDOF()];
>>   }
>>
>>   // Load new XML file
>>   b->Init(xmlFile.c_str(), NULL);
>>
>>   if(dof != b->GetDOF()) {
>>     RAVEPRINT(L"FATAL ERROR: Cannot replace a body with %d DOF with a differing number of DOF (%d).\n", dof, b->GetDOF());
>>     assert(dof == b->GetDOF());
>>   }
>>
>>   // Restore transformation and joint angles
>>   b->SetTransform(t);
>>   if(jointValues != NULL) {
>>     b->SetJointValues(NULL, NULL, jointValues);
>>   }
>>
>> When I do this, the viewer crashes at some point after my function
>> returns, with the following backtrace:
>>
>> #0  0xb7c31dca in SoSFRotation::setValue () from /usr/lib/libCoin.so.40
>> #1  0xb7c31f41 in SoSFRotation::setValue () from /usr/lib/libCoin.so.40
>> #2  0x080ef7e7 in KinBodyItem::UpdateFromModel (this=0x9f75b18, vtrans=@0xa03f7c4) at Item.cpp:353
>> #3  0x080e5709 in QtCoinViewer::UpdateFromModel (this=0x82677e0) at qtcoinviewer.cpp:1665
>> #4  0x080e3c7b in QtCoinViewer::AdvanceFrame (this=0x82677e0, bForward=true) at qtcoinviewer.cpp:1571
>> #5  0xb7dbca36 in SoSensor::trigger () from /usr/lib/libCoin.so.40
>> #6  0xb7dbf504 in SoTimerSensor::trigger () from /usr/lib/libCoin.so.40
>> #7  0xb7dbd2e0 in SoSensorManager::processTimerQueue () from /usr/lib/libCoin.so.40
>> #8  0x080f3063 in SoQtP::slot_timedOutSensor (this=0x82aa368) at SoQt.cpp:431
>> #9  0x080f2cfd in SoQtP::qt_metacall (this=0x82aa368, _c=InvokeMetaMethod, _id=0, _a=0x0) at moc_SoQtP.icc:68
>> #10 0xb69a52bd in QMetaObject::activate () from /usr/lib/libQtCore.so.4
>> #11 0xb69a56f6 in QMetaObject::activate () from /usr/lib/libQtCore.so.4
>> #12 0xb69c10df in QTimer::timeout () from /usr/lib/libQtCore.so.4
>> #13 0xb69ad734 in QTimer::timerEvent () from /usr/lib/libQtCore.so.4
>> #14 0xb69a47e6 in QObject::event () from /usr/lib/libQtCore.so.4
>> #15 0xb73c37c5 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4
>> #16 0xb73c4700 in QApplication::notify () from /usr/lib/libQtGui.so.4
>> #17 0xb69b82f0 in QEventDispatcherUNIX::activateTimers () from /usr/lib/libQtCore.so.4
>> #18 0xb69b892b in QEventDispatcherUNIX::processEvents () from /usr/lib/libQtCore.so.4
>> #19 0xb74268a6 in non-virtual thunk to QDesktopWidget::~QDesktopWidget() () from /usr/lib/libQtGui.so.4
>> #20 0xb699768a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4
>> #21 0xb699789d in QEventLoop::exec () from /usr/lib/libQtCore.so.4
>> #22 0xb6999fe7 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4
>> #23 0xb73c3565 in QApplication::exec () from /usr/lib/libQtGui.so.4
>> #24 0x080e3357 in QtCoinViewer::main (this=0x82677e0) at qtcoinviewer.cpp:1375
>> #25 0x08062e68 in MainOpenRAVEThread (p=0x0) at main.cpp:352
>> #26 0xb7832341 in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
>> #27 0xb6aec4ee in clone () from /lib/tls/i686/cmov/libc.so.6
>>
>> I'm running OpenRAVE r248 on Ubuntu 6.06, with libcoin 2.4.4 and Qt 4.1.2.
>>
>> Thanks,
>>
>> -Brennan
>>
>>
>> On Sun, 13 Jul 2008, Rosen Diankov wrote:
>>
>>> No it isn't. But there's two other options you can do:
>>>
>>> - Have multiple XML files of the same object but with different
>>> colors. Then when you want to change a color, just call KinBody::Init
>>> on a new XML file. You might want to store the transformation and
>>> joint angles beforehand.
>>> - Use the plotting functions to mark stuff.
>>>
>>> Rosen,
>>>
>>> 2008/7/13 Brennan Peter Sellner <[hidden email]>:
>>>> Hi,
>>>>
>>>> Is it possible to dynamically change the color and/or alpha of objects in
>>>> the scene from within a plugin?  For kicks, I exposed
>>>> KinBody::Link::_listGeomProperties and tried changing the diffuseColor and
>>>> ambientColor, but that had no effect, as I expected.
>>>>
>>>> Thanks,
>>>>
>>>> -Brennan
>>>>
>>>>
>>>> -------------------------------------------------------------------------
>>>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
>>>> Studies have shown that voting for your favorite open source project,
>>>> along with a healthy diet, reduces your potential for chronic lameness
>>>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>>>> _______________________________________________
>>>> Openrave-users mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/openrave-users
>>>>
>>>
>>>
>>
>> -------------------------------------------------------------------------
>> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
>> Studies have shown that voting for your favorite open source project,
>> along with a healthy diet, reduces your potential for chronic lameness
>> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
>> _______________________________________________
>> Openrave-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/openrave-users
>>
>
>


Loading...