Re: [osg-users] Dinamic Line Drawing
Hi Patrick, Similar to the change that Judson suggested for 'Add_new_point', the osg::Matrix and osg::Vec3f you pass into the constructor should be 'const osg::Matrix&' (same for vector), otherwise you are making a copy of the object every time. The empty destructor is okay, as everything is contained in smart pointers and will be properly cleaned up. (Except for the original usage of 'Add_new_point'.) Unless you need them for later modification, you don't have to have member variables for the matrices, the osg::Geode, and the color/normal arrays. Cheers, /ulrich On 10/05/13 23:57, Judson Weissert wrote: > Hi Patrick, > > On 5/9/2013 9:16 PM, Patrick Keenan wrote: >>... >> Code: >> >> osg::Vec3Array* line_pts = new osg::Vec3Array; >> line_pts->push_back(osg::Vec3(100, 0, 0)); >> line_pts->push_back(osg::Vec3(0, 100, 500)); >> line_pts->push_back(osg::Vec3(100, 100, 100)); >> >> >> lines_test = new >> M_OSG_line_strip(osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, >> 0.0f, 1.0f), >> osg::Matrix::translate(0.0f, 0.0f, 0.0f), >> >> osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, >> 0.0f, 1.0f), >> line_pts, >> osg::Vec4(0.0f,1.0f,1.0f,1.0f) >> ); > > Memory leak if lines_test assignment line throws an exception (lines_pts will > leak). An > osg::ref_ptr would solve this. > >>... >> Code: >> >> void M_frame::OnTestBtnClick(wxCommandEvent& WXUNUSED(event)) >> { >> osg::Vec3f* new_pt = new osg::Vec3f(4000.0f, 2000.0f, 0.0f); // works >> lines_test->Add_new_point(new_pt); >> } >> > Another memory leak for all points created since nobody is calling delete. I > suggest > passing osg::Vec3 parameters by value or const reference. > > Regards, > > Judson ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Patrick, On 5/9/2013 9:16 PM, Patrick Keenan wrote: Hi, This post was really helpful for me but I still couldn't add points on the fly either. A few edits made it happen so I'm attaching my M_OSG_line_strip class. To use the class I have the following in my CreateScene() Code: osg::Vec3Array* line_pts = new osg::Vec3Array; line_pts->push_back(osg::Vec3(100, 0, 0)); line_pts->push_back(osg::Vec3(0, 100, 500)); line_pts->push_back(osg::Vec3(100, 100, 100)); lines_test = new M_OSG_line_strip(osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, 0.0f, 1.0f), osg::Matrix::translate(0.0f, 0.0f, 0.0f), osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, 0.0f, 1.0f), line_pts, osg::Vec4(0.0f,1.0f,1.0f,1.0f) ); Memory leak if lines_test assignment line throws an exception (lines_pts will leak). An osg::ref_ptr would solve this. tmp_root->addChild(lines_test->Get()); and to dynamically add a new line I have Code: void M_frame::OnTestBtnClick(wxCommandEvent& WXUNUSED(event)) { osg::Vec3f* new_pt = new osg::Vec3f(4000.0f, 2000.0f, 0.0f); // works lines_test->Add_new_point(new_pt); } Another memory leak for all points created since nobody is calling delete. I suggest passing osg::Vec3 parameters by value or const reference. Regards, Judson ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi, This post was really helpful for me but I still couldn't add points on the fly either. A few edits made it happen so I'm attaching my M_OSG_line_strip class. To use the class I have the following in my CreateScene() Code: osg::Vec3Array* line_pts = new osg::Vec3Array; line_pts->push_back(osg::Vec3(100, 0, 0)); line_pts->push_back(osg::Vec3(0, 100, 500)); line_pts->push_back(osg::Vec3(100, 100, 100)); lines_test = new M_OSG_line_strip(osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, 0.0f, 1.0f), osg::Matrix::translate(0.0f, 0.0f, 0.0f), osg::Matrix::rotate(osg::inDegrees(0.0f), 0.0f, 0.0f, 1.0f), line_pts, osg::Vec4(0.0f,1.0f,1.0f,1.0f) ); tmp_root->addChild(lines_test->Get()); and to dynamically add a new line I have Code: void M_frame::OnTestBtnClick(wxCommandEvent& WXUNUSED(event)) { osg::Vec3f* new_pt = new osg::Vec3f(4000.0f, 2000.0f, 0.0f); // works lines_test->Add_new_point(new_pt); } Seems to work great. Critique of the use of osg::ref_ptr is welcomed. Thanks, Patrick -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=53984#53984 Attachments: http://forum.openscenegraph.org//files/m_osg_line_strip_887.h http://forum.openscenegraph.org//files/m_osg_line_strip_762.cpp ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Allen, On 21/5/09 5:47 PM, Allen Saucier wrote: Has anyone figured out how to draw only the "last" segment that was added? I've still not figured that out and I've got over 15,000 small line segments in my vertex array ... And from what I can tell: ... just causes the "ALL" the vertices to be redrawn. Is there a more efficient way? I'd like to draw only the last "line," which would be the line segment between the last vertex and the new last vertex just added. OpenGL/OpenSceneGraph always redraws the entire geometry each frame. There is no such thing as 'existing' (already drawn) geometry. Does anyone know if there is a way to do that? Thx! :) There isn't. (Well, if your camera doesn't move and the rest of the scene is completely static, you could store the frame and depth buffer of the last frame, load that every time and only draw what has changed. But in your case that's probably not worth the trouble.) Instead, try to make it as simple as possible for OSG to discard geometry. For example you could batch line segments together (say everything in a 100m radius) so that OSG can cull that Drawable if it's outside the view frustum. Cheers, /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Has anyone figured out how to draw only the "last" segment that was added? I've still not figured that out and I've got over 15,000 small line segments in my vertex array osg::ref_ptr m_ov3aLineVerticesData; And from what I can tell: m_ov3aLineVerticesData->push_back(osg::Vec3(x2,y2,z2)); // curr position m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->dirtyBound();// forces needed boundary recalc just causes the "ALL" the vertices to be redrawn. Is there a more efficient way? I'd like to draw only the last "line," which would be the line segment between the last vertex and the new last vertex just added. Does anyone know if there is a way to do that? Thx! :) Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=12688#12688 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
On 14/5/09 1:10 PM, Sergey Bocharov wrote: I find the problem. I use QT and QOSGGraphics.cpp for rendering OpenGL into QT Widget. So , when I try to make dYnamic line , it works bad (in usual viewer works fine). Example in attach. Please help to fix it , or advise another method to render osg to QT Widget. I don't have Qt (on OS X) so I can't test your code but I find it unlikely that the render backend (it's just an OpenGL context after all) would have an effect on the OSG core rendering. It's been a while since I've done Qt but how are you triggering the draws? There's some code to connect a timer to an update function but I can't actually find that function. Cheers, /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Sergey, On 13/5/09 7:53 PM, Sergey Bocharov wrote: I spend my time and here is му test case for Dinamic Line Drawing As I see , we dont need no setUseDisplayList(false), no dirtyBound() It works fine. Now i will search why it dont works in my application. Test case in attach. run it and just press any key. The test case you sent works for me. And you do use setUseDisplayList(false) in the TglLine::TglLine() constructor. However, in the TglLine::TglLine(float ...) constructor you have identical code that *doesn't* setUseDisplayList(false). Maybe you're using the other constructor? I'd always refactor code like that to use a common init function: TglLine::TglLine() { init(); } TglLine::TglLine(float x, float y, float z, const osg::Vec4& colour) { init(); addNode(x,y,z,colour); } Cheers, /uli PS: s/Dinamic/Dynamic/g ;-) ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi, ALL I spend my time and here is му test case for Dinamic Line Drawing As I see , we dont need no setUseDisplayList(false), no dirtyBound() It works fine. Now i will search why it dont works in my application. Test case in attach. run it and just press any key. ... Thank you! Cheers, Sergey -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=12025#12025 osgDinamicLine.cpp Description: Binary data ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Sergey, the code that I posted does work. Have you tried using my code? [Question] Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=12001#12001 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Sergey, what you are trying to do is certainly possible, but it is hard to follow and correct code snippets. I suggest you make a very simple example that people can compile. Then post the zipped code to the forum/mailing list and let someone fix it. jp Sergey Bocharov wrote: All my experiments false. I cant make a simple thing - draw dinamic line in my application with color vertex. May be i'm stuped, but i'm confused about gurus of this forum who cant help to do this simple thing. :-( -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=11962#11962 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
All my experiments false. I cant make a simple thing - draw dinamic line in my application with color vertex. May be i'm stuped, but i'm confused about gurus of this forum who cant help to do this simple thing. :-( -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=11962#11962 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Here's my working code, Sergey: // CLASS // class COsgPaxNodeSceneElementInfo { public: // TRAIL components // osg::ref_ptr m_podreTrailDrawElements; osg::ref_ptr m_ov3aLineVerticesData; osg::ref_ptr m_ogeomTrailGeometry; osg::ref_ptrm_ogeoTrailGeode; osg::Vec3d m_ov3dPrevPos; void COsgPaxNodeSceneElementInfo::m_vConstructATrail(double x, double y, double z); void COsgPaxNodeSceneElementInfo::m_vUpdateTrail( double x2, double y2, double z2); }; // class // CALLED BEFORE I ATTEMPT TO UPDATE A TRAIL // void COsgPaxNodeSceneElementInfo::m_vConstructATrail(double x, double y, double z) { // initialize previous to current point/position sent in m_ov3dPrevPos.set(x,y,z); // curr pos osg::Vec3d ov3d(x,y,z); // ALLOCATE ONCE AND ONLY ONCE m_podreTrailDrawElements= new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); m_ov3aLineVerticesData = new osg::Vec3Array(); m_ogeomTrailGeometry= new osg::Geometry(); m_ogeoTrailGeode= new osg::Geode; m_ov3aLineVerticesData->push_back(m_ov3dPrevPos); // prev position m_ov3aLineVerticesData->push_back(ov3d); // curr position m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get()); m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get()); // attempt to draw lines faster by disabling display lists & // then with each new vertex added, call dirtyBound() on the geometry. m_ogeomTrailGeometry->setUseDisplayList(false); m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get()); // ADD ONLY ONCE to the Node Scene root->addChild(m_ogeoTrailGeode.get()); } // m_vConstructATrail // CALLED PERIODICALLY // void COsgPaxNodeSceneElementInfo::m_vUpdateTrail( double x2, double y2, double z2) { m_ov3aLineVerticesData->push_back(osg::Vec3(x2,y2,z2)); // curr position m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->dirtyBound();// forces needed boundary recalc } // m_vUpdateTrail After much experimentation, I got this to work, though, it is still not quite right. I have no color and did not know how to set that up. But from your code, I now know how to do that. :) Still, osg, redraws ALL of the line segments instead of the very last one added. I would prefer it to only draw the last one added. That would be 1000 times faster. 8) I found that I had to have m_ogeomTrailGeometry->setUseDisplayList(false); set to false and I had to call m_ogeomTrailGeometry->dirtyBound(); in order to get my code to work at all. Hope this helps :? Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10527#10527 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Paul Martz wrote : >When you first set up your line strip, you only put one vertex in it, so I >wouldn't expect anything to be drawn until you add an additional vertex. >You have set your color binding to be BIND_PER_VERTEX and you have >one color >in the color array. Initially (when you only have one vertex) this is OK. >But as soon as you add more vertices, you do not also add more colors, >so >this could potentially cause a crash if OSG or OpenGL tries to index off >the >end of you color array. When I add new vertex , I add a new color for this vertex: colors->push_back(osg::Vec4(color.red(),color.green(),color.blue(), color.alphaF())); Look this code : // ADD NODE void TglLine::addNode(float X,float Y,float Z, QColor color){ vertexData->push_back(osg::Vec3(X,Y,Z)); colors->push_back(osg::Vec4(color.red(),color.green(),color.blue(), color.alphaF())); drawArrayLines->setFirst(0); int i =vertexData->size(); drawArrayLines->setCount(i); linesGeom->dirtyBound(); } //HERE my call -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10376#10376 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
When you first set up your line strip, you only put one vertex in it, so I wouldn't expect anything to be drawn until you add an additional vertex. You have set your color binding to be BIND_PER_VERTEX and you have one color in the color array. Initially (when you only have one vertex) this is OK. But as soon as you add more vertices, you do not also add more colors, so this could potentially cause a crash if OSG or OpenGL tries to index off the end of you color array. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Sergey Sent: Saturday, April 18, 2009 8:47 AM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Dinamic Line Drawing may be it depends on driver , but setUseDisplayList(false); works very strange!!! if I set it to false I get one direct line without color information and all new vertices is drawn in (0,0,0). Here my code and 2 screens differs only in one : in second screen line linesGeom->setUseDisplayList(false); is commented Any Idea? CODE - class TglLine { public: int ID; TglLine(float X,float Y,float Z, QColor color); ~TglLine(void); osg::Geode* Geode; void addNode(float X,float Y,float Z, QColor color); private: osg::ref_ptr drawArrayLines ; osg::ref_ptr vertexData ; osg::ref_ptr colors ; osg::ref_ptr linesGeom ; }; //CONSTRUCTOR TglLine::TglLine(float X,float Y,float Z, QColor color) { //ALLOCATE MEMORY drawArrayLines = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); vertexData = new osg::Vec3Array; linesGeom = new osg::Geometry(); Geode =new osg::Geode; colors = new osg::Vec4Array; vertexData->push_back(osg::Vec3(X,Y,Z)); drawArrayLines->setFirst(0); drawArrayLines->setCount(vertexData->size()); linesGeom->addPrimitiveSet(drawArrayLines.get()); linesGeom->setVertexArray(vertexData.get()); linesGeom->setColorArray(colors); linesGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); // linesGeom->setUseDisplayList(false); Geode->addDrawable(linesGeom.get()); } // ADD NODE void TglLine::addNode(float X,float Y,float Z, QColor color){ vertexData->push_back(osg::Vec3(X,Y,Z)); colors->push_back(osg::Vec4(color.red(),color.green(),color.blue(), color.alphaF())); drawArrayLines->setFirst(0); int i =vertexData->size(); drawArrayLines->setCount(i); linesGeom->dirtyBound(); } //HERE my call TglLine *test_line=new TglLine::TglLine(0,0,0,QColor(255,255,255,255)); root->addChild(test_line->Geode); QColor col= QColor(255,0,255,100); test_line->addNode(0,0,5000, col); test_line->addNode(1, 1, 1, col); test_line->addNode(-1, -1, -1, col); test_line->addNode(-1, 300, -1, col); -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10366#10366 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
may be it depends on driver , but setUseDisplayList(false); works very strange!!! if I set it to false I get one direct line without color information and all new vertices is drawn in (0,0,0). Here my code and 2 screens differs only in one : in second screen line linesGeom->setUseDisplayList(false); is commented Any Idea? CODE - class TglLine { public: int ID; TglLine(float X,float Y,float Z, QColor color); ~TglLine(void); osg::Geode* Geode; void addNode(float X,float Y,float Z, QColor color); private: osg::ref_ptr drawArrayLines ; osg::ref_ptr vertexData ; osg::ref_ptr colors ; osg::ref_ptr linesGeom ; }; //CONSTRUCTOR TglLine::TglLine(float X,float Y,float Z, QColor color) { //ALLOCATE MEMORY drawArrayLines = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); vertexData = new osg::Vec3Array; linesGeom = new osg::Geometry(); Geode =new osg::Geode; colors = new osg::Vec4Array; vertexData->push_back(osg::Vec3(X,Y,Z)); drawArrayLines->setFirst(0); drawArrayLines->setCount(vertexData->size()); linesGeom->addPrimitiveSet(drawArrayLines.get()); linesGeom->setVertexArray(vertexData.get()); linesGeom->setColorArray(colors); linesGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); // linesGeom->setUseDisplayList(false); Geode->addDrawable(linesGeom.get()); } // ADD NODE void TglLine::addNode(float X,float Y,float Z, QColor color){ vertexData->push_back(osg::Vec3(X,Y,Z)); colors->push_back(osg::Vec4(color.red(),color.green(),color.blue(), color.alphaF())); drawArrayLines->setFirst(0); int i =vertexData->size(); drawArrayLines->setCount(i); linesGeom->dirtyBound(); } //HERE my call TglLine *test_line=new TglLine::TglLine(0,0,0,QColor(255,255,255,255)); root->addChild(test_line->Geode); QColor col= QColor(255,0,255,100); test_line->addNode(0,0,5000, col); test_line->addNode(1, 1, 1, col); test_line->addNode(-1, -1, -1, col); test_line->addNode(-1, 300, -1, col); -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10366#10366 <>___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
I'm guessing that I have about 10,000 vertices or a little more. I stopped the app after 4500 had been displayed and the line was 1/2 drawn. Thx for the note, too, on dirtyBound(). I didn't really know what it did or what it meant so I threw in a comment for myself as a reminder that it did what I needed. Do I need the call to dirtyDisplayList() too, you think? Brian R Hill wrote: > Allen, > > Your code has the following line: > > m_ogeomTrailGeometry->dirtyBound(); // forces redraw > > dirtyBound does not force a redraw. It simply recalculates the bounding > volume for the geometry. The problem you were having before was that the > geometry was being clipped because the bounding volume was incorrect. > > Your performance issues can be due to a number of things. > > How many verts do you have? > > Brian > Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10338#10338 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Allen, Your code has the following line: m_ogeomTrailGeometry->dirtyBound(); // forces redraw dirtyBound does not force a redraw. It simply recalculates the bounding volume for the geometry. The problem you were having before was that the geometry was being clipped because the bounding volume was incorrect. Your performance issues can be due to a number of things. How many verts do you have? Brian This is a PRIVATE message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery. NOTE: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose. • -osg-users-boun...@lists.openscenegraph.org wrote: - To: osg-users@lists.openscenegraph.org From: "Allen Saucier" Sent by: osg-users-boun...@lists.openscenegraph.org Date: 04/16/2009 05:05PM Subject: Re: [osg-users] Dinamic Line Drawing Thx everyone!! for the help. :D :D You've given me a lot to think about. I really appreciate your time. J-S, here's my code that now works but still "drags" a little after a few thousand iterations. I found that setVertexArray is (I believe, but could be totally wrong) actually "copying" the array I send it. After a few thousand times of being called, it really slows down my entire interface. In fact, my interface Almost crawls to a halt calling setVertexArray() each time through the frame loop after about 4000 calls to it. And I'm drawing a LOT of small line segments each millisecond to make up the long "looking" line. I'm not using vertex buffer objects... yet. if I need to switch to them, I will. Though that will be in the land of experimentation for me too. ha, ha,... :-) I found that dirtyDisplayList() w.o dirtyBound() did nothing. I found that dirtyBound() worked all by itself to get the line to draw during each iteration of my osg::viewer::frame loop. I'm using osg::PrimitiveSet::LINE_STRIP as my primitive type and I do not need to push_back 2 vertices per line segment - I think. [Embarassed] At least, my line is being drawn... :) Honestly, I think it's the way I'm drawing the line. I don't believe there is a bug in OSG. I'm just to new @ this stuff.. ha, ha... here's my code: snippets of it: the 2 main methods w/in my class are 1) setup my line and 2) then to add to that line one new vertex at a time. This code actually works but it does 'slow' down after a few thousand iterations and then speeds up.. and slows down and speeds up... class COsgPaxNodeSceneElementInfo { osg::ref_ptr m_podreTrailDrawElements; osg::ref_ptr m_ov3aLineVerticesData; osg::ref_ptr m_ogeomTrailGeometry; osg::ref_ptr m_ogeoTrailGeode; osg::Vec3d m_ov3dPrevPos; ///< previous trail head bool m_bHasTrail; void m_vConstructATrail(math::Vector3D &p_v3dVec); void m_vUpdateTrail(model::PlatformStateVector &p_psvState); }; void COsgPaxNodeSceneElementInfo::m_vConstructATrail(math::Vector3D &p_v3dVec) { // initialize previous to current point/position sent in m_ov3dPrevPos.set(p_v3dVec.getX(), p_v3dVec.getY(), p_v3dVec.getZ()); // curr pos osg::Vec3d ov3d(p_v3dVec.getX(), p_v3dVec.getY(), p_v3dVec.getZ());); // ALLOCATE ONCE AND ONLY ONCE m_podreTrailDrawElements= new osg::DrawArrays (osg::PrimitiveSet::LINE_STRIP); m_ov3aLineVerticesData = new osg::Vec3Array(); m_ogeomTrailGeometry= new osg::Geometry(); m_ogeoTrailGeode= new osg::Geode; m_ov3aLineVerticesData->push_back(m_ov3dPrevPos); // prev pos m_ov3aLineVerticesData->push_back(ov3d); // curr pos m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get()); m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get()); // attempt to draw lines faster by disabling display lists & // then with each new vertex added, call dirtyBound() on the geometry. m_ogeomTrailGeometry->setUseDisplayList(false); m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get()); // ADD ONLY ONCE to the Node Scene m_no3vViewer->m_iAddElementToScene(m_ogeoTrailGeode.get()); // equivalent to root->addChild(m_ogeoTrailGeode.get()); but "root" of the osg node scene is actually located w/in another class object, not this one. // keep track of fact that this node scene elem has a trail m_bHasTrail = true; } // m_vConstructATrail void COsgPaxNodeSceneElementInfo::m_vUpdateTrail( model::PlatformStateVector &p_psvState) { if (!m_bHasTrail) return; static bool b_trailIsShowing=true; // trails on be default static double x,y,z; x=p_psvState.getPos
Re: [osg-users] Dinamic Line Drawing
Thx everyone!! for the help. :D :D You've given me a lot to think about. I really appreciate your time. J-S, here's my code that now works but still "drags" a little after a few thousand iterations. I found that setVertexArray is (I believe, but could be totally wrong) actually "copying" the array I send it. After a few thousand times of being called, it really slows down my entire interface. In fact, my interface Almost crawls to a halt calling setVertexArray() each time through the frame loop after about 4000 calls to it. And I'm drawing a LOT of small line segments each millisecond to make up the long "looking" line. I'm not using vertex buffer objects... yet. if I need to switch to them, I will. Though that will be in the land of experimentation for me too. ha, ha,... :-) I found that dirtyDisplayList() w.o dirtyBound() did nothing. I found that dirtyBound() worked all by itself to get the line to draw during each iteration of my osg::viewer::frame loop. I'm using osg::PrimitiveSet::LINE_STRIP as my primitive type and I do not need to push_back 2 vertices per line segment - I think. [Embarassed] At least, my line is being drawn... :) Honestly, I think it's the way I'm drawing the line. I don't believe there is a bug in OSG. I'm just to new @ this stuff.. ha, ha... here's my code: snippets of it: the 2 main methods w/in my class are 1) setup my line and 2) then to add to that line one new vertex at a time. This code actually works but it does 'slow' down after a few thousand iterations and then speeds up.. and slows down and speeds up... class COsgPaxNodeSceneElementInfo { osg::ref_ptr m_podreTrailDrawElements; osg::ref_ptr m_ov3aLineVerticesData; osg::ref_ptr m_ogeomTrailGeometry; osg::ref_ptr m_ogeoTrailGeode; osg::Vec3d m_ov3dPrevPos; ///< previous trail head bool m_bHasTrail; void m_vConstructATrail(math::Vector3D &p_v3dVec); void m_vUpdateTrail(model::PlatformStateVector &p_psvState); }; void COsgPaxNodeSceneElementInfo::m_vConstructATrail(math::Vector3D &p_v3dVec) { // initialize previous to current point/position sent in m_ov3dPrevPos.set(p_v3dVec.getX(), p_v3dVec.getY(), p_v3dVec.getZ()); // curr pos osg::Vec3d ov3d(p_v3dVec.getX(), p_v3dVec.getY(), p_v3dVec.getZ()); // ALLOCATE ONCE AND ONLY ONCE m_podreTrailDrawElements= new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); m_ov3aLineVerticesData = new osg::Vec3Array(); m_ogeomTrailGeometry= new osg::Geometry(); m_ogeoTrailGeode= new osg::Geode; m_ov3aLineVerticesData->push_back(m_ov3dPrevPos); // prev pos m_ov3aLineVerticesData->push_back(ov3d); // curr pos m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get()); m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get()); // attempt to draw lines faster by disabling display lists & // then with each new vertex added, call dirtyBound() on the geometry. m_ogeomTrailGeometry->setUseDisplayList(false); m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get()); // ADD ONLY ONCE to the Node Scene m_no3vViewer->m_iAddElementToScene(m_ogeoTrailGeode.get()); // equivalent to root->addChild(m_ogeoTrailGeode.get()); but "root" of the osg node scene is actually located w/in another class object, not this one. // keep track of fact that this node scene elem has a trail m_bHasTrail = true; } // m_vConstructATrail void COsgPaxNodeSceneElementInfo::m_vUpdateTrail( model::PlatformStateVector &p_psvState) { if (!m_bHasTrail) return; static bool b_trailIsShowing=true; // trails on be default static double x,y,z; x=p_psvState.getPosition().getX(); y=p_psvState.getPosition().getY(); z=p_psvState.getPosition().getZ(); // for now, just keep current PTL around; // unused @ moment, however m_dPtl=p_psvState.getOrientation().getW(); m_ov3aLineVerticesData->push_back(osg::Vec3(x,y,z)); // prev pos m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->dirtyBound(); // forces redraw } // m_vUpdateTrail Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10322#10322 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hello Allen, I've tried leaving setDisplayList (true) and calling the method dirtyDisplayList() and not calling setVertexArray(vad). That doesn't work either. Nothing has worked so far except to call setVertexArray(vad); Check the code to osg::Geometry::setVertexArray to see if it's doing things you're not: void Geometry::setVertexArray(Array* array) { _vertexData.array = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); } The important parts in your case are dirtyDisplayList() and dirtyBound()... If the old array pointer is the same as the new one, then _vertexData.array = array will just reassign the same value. computeFastPathsUsed() doesn't change anything, it just sets a flag to say whether you're on the OpenGL fast paths or not. And you're probably not using vertex buffer objects (setUseDisplayList(false) + setUseVertexBufferObject(false) (the default) = plain old vertex buffers) so the last line is not executed for you. The gist of it is: 1. In all cases, you need to add a vertex array, a normal array, a color array and one or more primitiveset(s). (note that the normal and color arrays can just contain one element with binding BIND_OVERALL) 2. For static geometry, you leave setUseDisplayList() set to true (the default) and you're done. OSG will build the display list once, and always draw using that display list afterwards. 3. For dynamic geometry, you'll setUseDisplayList(false) and modify the vertices in the vertex array (either keep a ref_ptr to it or get the pointer each time from the osg::Geometry object). Note that if the geometry is updated only seldom (once per second, or once per 30 seconds, for example) you could leave setUseDisplayList(true) (the default) and call dirtyDisplayList() when you change the vertices in the vertex array. But nowadays, there's little advantage to using display lists even for static or "almost static" geometry - they're even being deprecated in OpenGL 3.0. So to sum up, you need to set the vertex array in your initial setup, and then either dirtyDisplayList() in your update (draw line) code or setUseDisplayList(false) in your initial setup. If it still doesn't work for you, send us some repro code. Check out the osggeometry example to see if you're doing things like that example, and if not, modify it to match your code, see if you can reproduce your results, and send it to us. In my mind, the method, dirtyDisplayList() should 1) dirty my display list 2) rebuild it and therefore during the next draw sequence of the viewer, the line should be drawn. But that simply is not the case. Yes it is. That's it exactly. If that doesn't work for you, send us some repro code. My best guess is: Some flag w/in the Geometry/Drawable is not being set to "dirty" and some flag is not being set to "redaw" once the Geometry/Drawable is dirty. That's the nearest I can tell. That code path is being used every day by a very large number of programmers in a very large number of software programs (it's a very common thing to do), so I'm pretty sure if it were broken we'd know. :-) Nevertheless, with a small example that shows what you're doing, we might be able to see more clearly if there's a bug or if there's something missing in your usage. Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
What type of primitive (mode) is in your DrawArrays? If it's GL_LINES then obviously you'll need to add 2 vertices to draw an additional line segment. Other than that I don't know what the problem is. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Allen Saucier Sent: Thursday, April 16, 2009 10:27 AM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Dinamic Line Drawing Well, it didntt work for me. :-( I'm actaully calling osg::viewer::frame() a few 100x / ms, I turned off DisplayLists for the geometry, did not call setVertexArray(vad), did not call dirtyDisplayList() and the line is not being drawn at all now. I've tried leaving setDisplayList (true) and calling the method dirtyDisplayList() and not calling setVertexArray(vad). That doesn't work either. Nothing has worked so far except to call setVertexArray(vad); In my mind, the method, dirtyDisplayList() should 1) dirty my display list 2) rebuild it and therefore during the next draw sequence of the viewer, the line should be drawn. But that simply is not the case. My best guess is: Some flag w/in the Geometry/Drawable is not being set to "dirty" and some flag is not being set to "redaw" once the Geometry/Drawable is dirty. That's the nearest I can tell. Do you have any more suggestions? [Question] Thx code to "draw line" after initial setup -- osg::Vec3Array *vad = dynamic_cast (m_ogeomTrailGeometry->getVertexArray()); vad->push_back(osg::Vec3(x,y,z)); osg::DrawArrays *drArrys = dynamic_cast (m_ogeomTrailGeometry->getPrimitiveSet(0)); drArrys->setFirst(0); drArrys->setCount(vad->size()); m_ogeomTrailGeometry->dirtyDisplayList(); // doesn't work // m_ogeomTrailGeometry->setVertexArray(vad); // works when uncommented Paul Martz wrote: > If you use osgViewer::Viewer::run(), then you're rendering constantly > and don't need to do anything else to tell it to redraw. > > If you're using osgViewer::Viewer::frame(), then you need to call that > function. > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > -Original Message- > From: > [mailto:] On Behalf Of Allen > Saucier > Sent: Thursday, April 16, 2009 8:03 AM > To: > Subject: Re: Dinamic Line Drawing > > Wow, that easy? ha, ha... > > Paul, how does the "system" know when to redraw after I've added to > the vertices? Don't I have to tell it to redraw after I've added a > vertex and up'ed the vertex counter? > > -vertex counter == osg::DrawArrays *vad; -new vertices added to *vad > w/ > push_back() cmd > > > Paul Martz wrote: > > > setUseDisplayLists( false ). > > > > Paul Martz > > Skew Matrix Software LLC > > http://www.skew-matrix.com > > +1 303 859 9466 > > > > -Original Message- > > From: > > [mailto:] On Behalf Of Allen > > Saucier > > Sent: Wednesday, April 15, 2009 3:44 PM > > To: > > Subject: Re: Dinamic Line Drawing > > > > Thanks Paul! I didn't understand that in the previous postings. > > Would you mind telling me how to "disable" the display listings for > > this > > > geometry? > > > > > > > ** PAUL wrote *** > > Your geometry is probably using display lists (on by default). > > setVertexArray will dirty and rebuild them. A more efficient > > solution would be to disable display lists. If you do that, you > > should be able to change individual elements of your array and not > > have to set the entire > > > array. > > > > > Paul Martz > > Skew Matrix Software LLC > > http://www.skew-matrix.com > > +1 303 859 9466 > > > > > > > > Allen > > > > -- > > Read this topic online here: > > http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 > > > > > > > > > > > > ___ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > > org > > > > ___ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > > org > > > > -- > > Post generated by Mail2Forum > > > >
Re: [osg-users] Dinamic Line Drawing
Your bounding volume may not be correct. Try calling dirtyBound(). Brian This is a PRIVATE message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery. NOTE: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose. • -osg-users-boun...@lists.openscenegraph.org wrote: - To: osg-users@lists.openscenegraph.org From: "Allen Saucier" Sent by: osg-users-boun...@lists.openscenegraph.org Date: 04/16/2009 12:26PM Subject: Re: [osg-users] Dinamic Line Drawing Well, it didntt work for me. :-( I'm actaully calling osg::viewer::frame() a few 100x / ms, I turned off DisplayLists for the geometry, did not call setVertexArray(vad), did not call dirtyDisplayList() and the line is not being drawn at all now. I've tried leaving setDisplayList (true) and calling the method dirtyDisplayList() and not calling setVertexArray(vad). That doesn't work either. Nothing has worked so far except to call setVertexArray(vad); In my mind, the method, dirtyDisplayList() should 1) dirty my display list 2) rebuild it and therefore during the next draw sequence of the viewer, the line should be drawn. But that simply is not the case. My best guess is: Some flag w/in the Geometry/Drawable is not being set to "dirty" and some flag is not being set to "redaw" once the Geometry/Drawable is dirty. That's the nearest I can tell. Do you have any more suggestions? [Question] Thx code to "draw line" after initial setup -- osg::Vec3Array *vad = dynamic_cast (m_ogeomTrailGeometry->getVertexArray()); vad->push_back(osg::Vec3(x,y,z)); osg::DrawArrays *drArrys = dynamic_cast (m_ogeomTrailGeometry->getPrimitiveSet(0));:: drArrys->setFirst(0); drArrys->setCount(vad->size()); m_ogeomTrailGeometry->dirtyDisplayList(); // doesn't work> // m_ogeomTrailGeometry->setVertexArray(vad); // works when uncommented Paul Martz wrote: > If you use osgViewer::Viewer::run(), then you're rendering constantly and > don't need to do anything else to tell it to redraw. > > If you're using osgViewer::Viewer::frame(), then you need to call that > function. > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > -Original Message- > From: > [mailto:] On Behalf Of Allen > Saucier > Sent: Thursday, April 16, 2009 8:03 AM > To: > Subject: Re: Dinamic Line Drawing > > Wow, that easy? ha, ha... > > Paul, how does the "system" know when to redraw after I've added to the > vertices? Don't I have to tell it to redraw after I've added a vertex and > up'ed the vertex counter? > > -vertex counter == osg::DrawArrays *vad; -new vertices added to *vad w/ > push_back() cmd > > > Paul Martz wrote: > > > setUseDisplayLists( false ). > > > > Paul Martz > > Skew Matrix Software LLC > > http://www.skew-matrix.com > > +1 303 859 9466 > > > > -Original Message- > > From: > > [mailto:] On Behalf Of Allen > > Saucier > > Sent: Wednesday, April 15, 2009 3:44 PM > > To: > > Subject: Re: Dinamic Line Drawing > > > > Thanks Paul! I didn't understand that in the previous postings. > > Would you mind telling me how to "disable" the display listings for this > > > geometry? > > > > > > > ** PAUL wrote *** > > Your geometry is probably using display lists (on by default). > > setVertexArray will dirty and rebuild them. A more efficient solution > > would be to disable display lists. If you do that, you should be able > > to change individual elements of your array and not have to set the entire > > > array. > > > > > Paul Martz > > Skew Matrix Software LLC > > http://www.skew-matrix.com > > +1 303 859 9466 > > > > > > > > Allen > > > > -- > > Read this topic online here: > > http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 > > > > > > > > > > > > ___ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > > org > > > > ___ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > > org > > > > -- >
Re: [osg-users] Dinamic Line Drawing
Well, it didntt work for me. :-( I'm actaully calling osg::viewer::frame() a few 100x / ms, I turned off DisplayLists for the geometry, did not call setVertexArray(vad), did not call dirtyDisplayList() and the line is not being drawn at all now. I've tried leaving setDisplayList (true) and calling the method dirtyDisplayList() and not calling setVertexArray(vad). That doesn't work either. Nothing has worked so far except to call setVertexArray(vad); In my mind, the method, dirtyDisplayList() should 1) dirty my display list 2) rebuild it and therefore during the next draw sequence of the viewer, the line should be drawn. But that simply is not the case. My best guess is: Some flag w/in the Geometry/Drawable is not being set to "dirty" and some flag is not being set to "redaw" once the Geometry/Drawable is dirty. That's the nearest I can tell. Do you have any more suggestions? [Question] Thx code to "draw line" after initial setup -- osg::Vec3Array *vad = dynamic_cast (m_ogeomTrailGeometry->getVertexArray()); vad->push_back(osg::Vec3(x,y,z)); osg::DrawArrays *drArrys = dynamic_cast (m_ogeomTrailGeometry->getPrimitiveSet(0)); drArrys->setFirst(0); drArrys->setCount(vad->size()); m_ogeomTrailGeometry->dirtyDisplayList(); // doesn't work // m_ogeomTrailGeometry->setVertexArray(vad); // works when uncommented Paul Martz wrote: > If you use osgViewer::Viewer::run(), then you're rendering constantly and > don't need to do anything else to tell it to redraw. > > If you're using osgViewer::Viewer::frame(), then you need to call that > function. > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > -Original Message- > From: > [mailto:] On Behalf Of Allen > Saucier > Sent: Thursday, April 16, 2009 8:03 AM > To: > Subject: Re: Dinamic Line Drawing > > Wow, that easy? ha, ha... > > Paul, how does the "system" know when to redraw after I've added to the > vertices? Don't I have to tell it to redraw after I've added a vertex and > up'ed the vertex counter? > > -vertex counter == osg::DrawArrays *vad; -new vertices added to *vad w/ > push_back() cmd > > > Paul Martz wrote: > > > setUseDisplayLists( false ). > > > > Paul Martz > > Skew Matrix Software LLC > > http://www.skew-matrix.com > > +1 303 859 9466 > > > > -Original Message- > > From: > > [mailto:] On Behalf Of Allen > > Saucier > > Sent: Wednesday, April 15, 2009 3:44 PM > > To: > > Subject: Re: Dinamic Line Drawing > > > > Thanks Paul! I didn't understand that in the previous postings. > > Would you mind telling me how to "disable" the display listings for this > > > geometry? > > > > > > > ** PAUL wrote *** > > Your geometry is probably using display lists (on by default). > > setVertexArray will dirty and rebuild them. A more efficient solution > > would be to disable display lists. If you do that, you should be able > > to change individual elements of your array and not have to set the entire > > > array. > > > > > Paul Martz > > Skew Matrix Software LLC > > http://www.skew-matrix.com > > +1 303 859 9466 > > > > > > > > Allen > > > > -- > > Read this topic online here: > > http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 > > > > > > > > > > > > ___ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > > org > > > > ___ > > osg-users mailing list > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > > org > > > > -- > > Post generated by Mail2Forum > > > > > > > Allen > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=10304#10304 > > > > > > ___ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > ___ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > -- > Post generated by Mail2Forum Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10315#10315 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
WOW! so simple. Excellent! Thxs Paul!:D Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10313#10313 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
If you use osgViewer::Viewer::run(), then you're rendering constantly and don't need to do anything else to tell it to redraw. If you're using osgViewer::Viewer::frame(), then you need to call that function. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Allen Saucier Sent: Thursday, April 16, 2009 8:03 AM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Dinamic Line Drawing Wow, that easy? ha, ha... Paul, how does the "system" know when to redraw after I've added to the vertices? Don't I have to tell it to redraw after I've added a vertex and up'ed the vertex counter? -vertex counter == osg::DrawArrays *vad; -new vertices added to *vad w/ push_back() cmd Paul Martz wrote: > setUseDisplayLists( false ). > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > -Original Message- > From: > [mailto:] On Behalf Of Allen > Saucier > Sent: Wednesday, April 15, 2009 3:44 PM > To: > Subject: Re: Dinamic Line Drawing > > Thanks Paul! I didn't understand that in the previous postings. > Would you mind telling me how to "disable" the display listings for this geometry? > > > ** PAUL wrote *** > Your geometry is probably using display lists (on by default). > setVertexArray will dirty and rebuild them. A more efficient solution > would be to disable display lists. If you do that, you should be able > to change individual elements of your array and not have to set the entire array. > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > > > Allen > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 > > > > > > ___ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > org > > ___ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph. > org > > -- > Post generated by Mail2Forum Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10304#10304 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Wow, that easy? ha, ha... Paul, how does the "system" know when to redraw after I've added to the vertices? Don't I have to tell it to redraw after I've added a vertex and up'ed the vertex counter? -vertex counter == osg::DrawArrays *vad; -new vertices added to *vad w/ push_back() cmd Paul Martz wrote: > setUseDisplayLists( false ). > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > -Original Message- > From: > [mailto:] On Behalf Of Allen > Saucier > Sent: Wednesday, April 15, 2009 3:44 PM > To: > Subject: Re: Dinamic Line Drawing > > Thanks Paul! I didn't understand that in the previous postings. Would you > mind telling me how to "disable" the display listings for this geometry? > > > ** PAUL wrote *** > Your geometry is probably using display lists (on by default). > setVertexArray will dirty and rebuild them. A more efficient solution would > be to disable display lists. If you do that, you should be able to change > individual elements of your array and not have to set the entire array. > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > +1 303 859 9466 > > > > Allen > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 > > > > > > ___ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > ___ > osg-users mailing list > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > -- > Post generated by Mail2Forum Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10304#10304 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
setUseDisplayLists( false ). Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Allen Saucier Sent: Wednesday, April 15, 2009 3:44 PM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Dinamic Line Drawing Thanks Paul! I didn't understand that in the previous postings. Would you mind telling me how to "disable" the display listings for this geometry? ** PAUL wrote *** Your geometry is probably using display lists (on by default). setVertexArray will dirty and rebuild them. A more efficient solution would be to disable display lists. If you do that, you should be able to change individual elements of your array and not have to set the entire array. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Thanks Paul! I didn't understand that in the previous postings. Would you mind telling me how to "disable" the display listings for this geometry? ** PAUL wrote *** Your geometry is probably using display lists (on by default). setVertexArray will dirty and rebuild them. A more efficient solution would be to disable display lists. If you do that, you should be able to change individual elements of your array and not have to set the entire array. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10279#10279 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Your geometry is probably using display lists (on by default). setVertexArray will dirty and rebuild them. A more efficient solution would be to disable display lists. If you do that, you should be able to change individual elements of your array and not have to set the entire array. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Allen Saucier Sent: Wednesday, April 15, 2009 3:26 PM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Dinamic Line Drawing boooch (and anyone who might have suggestions...), I really appreciate the code you posted but I can't get it to work as you did. The ONLY way I was able to get the "lines" drawn was to RE-set the vertexArray of my geometry. Like so: m_ogeomTrailGeometry->setVertexArray(vad); However, this is an extremely expensive operation. Do you have any suggestions that I might try to lower my re-draw expense? Here's my code snippet: class class1 { public: osg::ref_ptr m_podreTrailDrawElements; osg::ref_ptr m_ov3aLineVerticesData; osg::ref_ptr m_ogeomTrailGeometry; osg::ref_ptr m_ogeoTrailGeode; osg::Vec3d m_ov3dPrevPos; } class1::method_1(double xInitial, double yInitial, double zInitial) { // initialize previous to current point/position sent in m_ov3dPrevPos.set(xInitial, yInitial, zInitial); // curr pos osg::Vec3d ov3d(xInitial, yInitial, zInitial); m_podreTrailDrawElements= new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); m_ov3aLineVerticesData = new osg::Vec3Array(); m_ogeomTrailGeometry= new osg::Geometry(); m_ogeoTrailGeode= new osg::Geode; m_ov3aLineVerticesData->push_back(m_ov3dPrevPos); // prev pos m_ov3aLineVerticesData->push_back(ov3d); // curr pos m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get()); m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get());// add line segs to geometry m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get()); // ADD ONLY ONCE to the Node Scene m_no3vViewer->m_iAddElementToScene(m_ogeoTrailGeode.get()); } // method_1() class1::method_updateLine(double x, double y, double z) { osg::Vec3Array *vad = dynamic_cast(m_ogeomTrailGeometry->getVertexArray()); vad->push_back(osg::Vec3(x,y,z)); osg::DrawArrays *drArrys = dynamic_cast(m_ogeomTrailGeometry->getPrimitiveSet(0)); drArrys->setFirst(0); drArrys->setCount(vad->size()); //drArrys->dirty(); //std::cout<<" vad->size()=="<< vad->size() << std::endl; m_ogeomTrailGeometry->setVertexArray(vad); } Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10277#10277 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
boooch (and anyone who might have suggestions...), I really appreciate the code you posted but I can't get it to work as you did. The ONLY way I was able to get the "lines" drawn was to RE-set the vertexArray of my geometry. Like so: m_ogeomTrailGeometry->setVertexArray(vad); However, this is an extremely expensive operation. Do you have any suggestions that I might try to lower my re-draw expense? Here's my code snippet: class class1 { public: osg::ref_ptr m_podreTrailDrawElements; osg::ref_ptr m_ov3aLineVerticesData; osg::ref_ptr m_ogeomTrailGeometry; osg::ref_ptr m_ogeoTrailGeode; osg::Vec3d m_ov3dPrevPos; } class1::method_1(double xInitial, double yInitial, double zInitial) { // initialize previous to current point/position sent in m_ov3dPrevPos.set(xInitial, yInitial, zInitial); // curr pos osg::Vec3d ov3d(xInitial, yInitial, zInitial); m_podreTrailDrawElements= new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); m_ov3aLineVerticesData = new osg::Vec3Array(); m_ogeomTrailGeometry= new osg::Geometry(); m_ogeoTrailGeode= new osg::Geode; m_ov3aLineVerticesData->push_back(m_ov3dPrevPos); // prev pos m_ov3aLineVerticesData->push_back(ov3d); // curr pos m_podreTrailDrawElements->setFirst(0); m_podreTrailDrawElements->setCount(m_ov3aLineVerticesData->size()); m_ogeomTrailGeometry->addPrimitiveSet(m_podreTrailDrawElements.get()); m_ogeomTrailGeometry->setVertexArray(m_ov3aLineVerticesData.get());// add line segs to geometry m_ogeoTrailGeode->addDrawable(m_ogeomTrailGeometry.get()); // ADD ONLY ONCE to the Node Scene m_no3vViewer->m_iAddElementToScene(m_ogeoTrailGeode.get()); } // method_1() class1::method_updateLine(double x, double y, double z) { osg::Vec3Array *vad = dynamic_cast(m_ogeomTrailGeometry->getVertexArray()); vad->push_back(osg::Vec3(x,y,z)); osg::DrawArrays *drArrys = dynamic_cast(m_ogeomTrailGeometry->getPrimitiveSet(0)); drArrys->setFirst(0); drArrys->setCount(vad->size()); //drArrys->dirty(); //std::cout<<" vad->size()=="<< vad->size() << std::endl; m_ogeomTrailGeometry->setVertexArray(vad); } Allen -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10277#10277 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
thank you for advise . As Resume here my working code: Code: osg::Geometry* linesGeom = new osg::Geometry();// is my geometry osg::DrawArrays* drawArrayLines = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); linesGeom->addPrimitiveSet(drawArrayLines); osg::Vec3Array* vertexData = new osg::Vec3Array; linesGeom->setVertexArray(vertexData); osg::ref_ptr tmp_geode (new osg::Geode);// Greate test Geode tmp_geode->addDrawable(linesGeom); nazemTargetPathGroup->addChild(tmp_geode);// add geode to my osg::Group // ADD SOME VERTEX vertexData->push_back(osg::Vec3(0,0,0)); vertexData->push_back(osg::Vec3(0,0,5000)); vertexData->push_back(osg::Vec3(1, 1, 1)); vertexData->push_back(osg::Vec3(-1, -1, -1)); vertexData->push_back(osg::Vec3(-1, 300, -1)); drawArrayLines->setFirst(0); drawArrayLines->setCount(vertexData->size()); // NOW ADD NEW VERTEX: vertexData->push_back(osg::Vec3(100, 300, -1)); drawArrayLines->setFirst(0); drawArrayLines->setCount(vertexData->size()); -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10019#10019 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Rahul Jain wrote: > Hi Sergey, > > You must be creating a osg::Geometry, Right ? If yes then you can use > function osg::Vec3Array* vertexData = geom->getVertexArray(). Ones you > have vertexData you can add your new vertex as > vertexData->push_back(newVertex); > > cheers > RJ > > OK. But > > > Code: > osg::Vec3Array* vertexData = linesGeom->getVertexArray(); > > > > generates error: invalid conversion from `osg::Array*' to 'osg::Vec3Array*' > > -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10017#10017 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Sergey, You must be creating a osg::Geometry, Right ? If yes then you can use function osg::Vec3Array* vertexData = geom->getVertexArray(). Ones you have vertexData you can add your new vertex as vertexData->push_back(newVertex); cheers RJ Sergey wrote: [quote="Rahul Jain"]Hi Sergey, You need to add your new vertices to the geometry vertex data and update the first and size of your primitive set which is drawing the line. thanx Rahul! One thing I cant find : how to fill drawArrayLines with new vertices -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=9982#9982 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
[quote="Rahul Jain"]Hi Sergey, You need to add your new vertices to the geometry vertex data and update the first and size of your primitive set which is drawing the line. thanx Rahul! One thing I cant find : how to fill drawArrayLines with new vertices -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=9982#9982 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
You probably don't need to call setFirst(0) every time, but it won't hurt either. Also, when dynamically changing geometry this way you need to manage display lists (either disable them or dirty them when changed) and you need to manage the bounding volume (either dirty them on change or override the computeBound() method). Brian > Date: Thu, 9 Apr 2009 18:13:07 +0530 > From: rah...@vizexperts.com > To: osg-users@lists.openscenegraph.org > Subject: Re: [osg-users] Dinamic Line Drawing > > Hi Sergey, > > You need to add your new vertices to the geometry vertex data and > update the first and size of your primitive set which is drawing the line. > > For example > > > osg::Geometry* geom // is your geometry > osg::DrawArrays* drawArrayLines = new > osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); // Is your line strip > Primitive set > > geom ->addPrimitiveSet(_drawArrayLines); // Add primitive set > > Whenever you have new vertex add the new vertex to the vertex array of > your geometry and call > > drawArrayLines->setFirst(0); > drawArrayLines->setCount( Num of vertex in your vertex array); > > > I Hope this will help you > > cheers > RJ > > > Sergey wrote: > > Hi, ALL > > How can I draw line , and append to this line new vertices (nodes) time > > after time? For example I need to draw a trajectory of moving object. > > In examples I have seen only static lines with determined count of vertices. > > > > Thank you. > > > > -- > > Read this topic online here: > > http://forum.openscenegraph.org/viewtopic.php?p=9969#9969 > > > > > > > > > > > > ___ > > osg-users mailing list > > osg-users@lists.openscenegraph.org > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _ Quick access to your favorite MSN content and Windows Live with Internet Explorer 8. http://ie8.msn.com/microsoft/internet-explorer-8/en-us/ie8.aspx?ocid=B037MSN55C0701A___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Dinamic Line Drawing
Hi Sergey, You need to add your new vertices to the geometry vertex data and update the first and size of your primitive set which is drawing the line. For example osg::Geometry* geom // is your geometry osg::DrawArrays* drawArrayLines = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP); // Is your line strip Primitive set geom ->addPrimitiveSet(_drawArrayLines); // Add primitive set Whenever you have new vertex add the new vertex to the vertex array of your geometry and call drawArrayLines->setFirst(0); drawArrayLines->setCount( Num of vertex in your vertex array); I Hope this will help you cheers RJ Sergey wrote: Hi, ALL How can I draw line , and append to this line new vertices (nodes) time after time? For example I need to draw a trajectory of moving object. In examples I have seen only static lines with determined count of vertices. Thank you. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=9969#9969 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org