OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Change picked points' color ---why can't work in the pick function?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Yexin
Newbie


Joined: 02 Sep 2015
Posts: 3

PostPosted: Wed Sep 02, 2015 10:27 am    Post subject:
Change picked points' color ---why can't work in the pick function?
Reply with quote

Hi,

Guys, I have a pick problem. What I want to do is loading 10 points with their loactions and colors. I want to use poly pick, and use another color to show the picked points.
The loading points process is as follows:

Code:

osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
osg::ref_ptr<osg::Vec4Array> clr = new osg::Vec4Array;
v->push_back(osg::Vec3(0.0, 0.0, 0.0));
... // 10 points in total
clr->push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0f));
...// set the color
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, v->size()));
// after set the color and normal, add the geometry to Geode node
geode->addDrawable(geom.get());



Then I want to use ploy pick, the problem is : when I put the following codes in the pick() function in Pickhandler class, I found out that the color of the picked premitiveset has been changed, however, nothing changed in the view window. The following codes are in pick function:

Code:

if (picker->containsIntersections())
{
osgUtil::PolytopeIntersector::Intersections intersections = picker->getIntersections();
osgUtil::PolytopeIntersector::Intersections::iterator iter;
for (iter = intersections.begin(); iter != intersections.end(); iter++)
{
osg::NodePath nodepath = (*iter).nodePath;
node = (nodepath.size() >= 1) ? nodepath[nodepath.size() - 1] : 0;
int pointIndex = (*iter).primitiveIndex;
osg::Geode * geode = dynamic_cast<osg::Geode*> (node);
osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode->getDrawable(0));
osg::Vec4Array * clrary = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());
clrary->operator [] (pointIndex) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
node->addUpdateCallback(new CessnaCallback()); // not helpful
viewer->updateTraversal(); //not helpful
//viewer->run();//not helpful
}
}



First, I thought may be the colors have not been changed, so I tested changing several points' color in the main function, like this:

Code:

osg::Geode * geode1 = dynamic_cast<osg::Geode*> (nodePt.get());
osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode1->getDrawable(0));
osg::Vec4Array * clrary = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());
clrary->operator [] (10) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
clrary->operator [] (6) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
clrary->operator [] (2) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);


It changed the colors! So it confuses me why it can't work in the pick function? Any body any idears?
Any ideas and suggestions would be appreciated!


Thank you!

Cheers,
Yexin
Back to top
View user's profile Send private message
Trajce Nikolov NICK
Guest





PostPosted: Wed Sep 09, 2015 12:35 pm    Post subject:
Change picked points' color ---why can't work in the pick function?
Reply with quote

Hi,

can you try geom->dirtyDisplayLists() after changing the color?


Nick


On Wed, Sep 2, 2015 at 12:27 PM, Yexin W < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi,

Guys, I have a pick problem. What I want to do is loading 10 points with their loactions and colors. I want to use poly pick, and use another color to show the picked points.
The loading points process is as follows:


Code:

osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
osg::ref_ptr<osg::Vec4Array> clr = new osg::Vec4Array;
v->push_back(osg::Vec3(0.0, 0.0, 0.0));
... // 10 points in total
clr->push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0f));
...// set the color
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, v->size()));
// after set the color and normal, add the geometry to Geode node
geode->addDrawable(geom.get());





Then I want to use ploy pick, the problem is : when I put the following codes in the pick() function in Pickhandler class, I found out that the color of the picked premitiveset has been changed, however, nothing changed in the view window. The following codes are in pick function:


Code:

if (picker->containsIntersections())
{
osgUtil::PolytopeIntersector::Intersections intersections = picker->getIntersections();
osgUtil::PolytopeIntersector::Intersections::iterator iter;
for (iter = intersections.begin(); iter != intersections.end(); iter++)
{
osg::NodePath nodepath = (*iter).nodePath;
node = (nodepath.size() >= 1) ? nodepath[nodepath.size() - 1] : 0;
int pointIndex = (*iter).primitiveIndex;
osg::Geode * geode = dynamic_cast<osg::Geode*> (node);
osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode->getDrawable(0));
osg::Vec4Array * clrary = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());
clrary->operator [] (pointIndex) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
node->addUpdateCallback(new CessnaCallback()); // not helpful
viewer->updateTraversal(); //not helpful
//viewer->run();//not helpful
}
}





First, I thought may be the colors have not been changed, so I tested changing several points' color in the main function, like this:


Code:

osg::Geode * geode1 = dynamic_cast<osg::Geode*> (nodePt.get());
osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode1->getDrawable(0));
osg::Vec4Array * clrary = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());
clrary->operator [] (10) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
clrary->operator [] (6) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
clrary->operator [] (2) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);




It changed the colors! So it confuses me why it can't work in the pick function? Any body any idears?
Any ideas and suggestions would be appreciated!


Thank you!

Cheers,
Yexin

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64994#64994





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
Yexin
Newbie


Joined: 02 Sep 2015
Posts: 3

PostPosted: Thu Sep 10, 2015 9:24 am    Post subject:
Re: Change picked points' color ---why can't work in the pick function?
Reply with quote

Thank you so much, dear Trajce! That's exactly what I want! Very Happy Very Happy Very Happy



Trajce Nikolov NICK wrote:
Hi,

can you try geom->dirtyDisplayLists() after changing the color?

Nick

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Attaching color buffer with GL_R32F i... deroliver General 0 Tue Apr 09, 2019 6:19 pm View latest post
No new posts Mouse Events are impossible to work with Steal General 0 Fri Mar 15, 2019 4:02 pm View latest post
No new posts Cannot pick HUD text bclay General 3 Thu Feb 28, 2019 3:34 pm View latest post
No new posts How to change camera's yaw and pitch,... Rodrigo General [3rdparty] 3 Thu Jan 31, 2019 12:43 am View latest post
No new posts What kind of mathemetical formula is ... mirro General 0 Mon Jan 21, 2019 1:40 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP