Re: [osg-users] How to prevent OSG linking against Desktop OpenGL

2016-09-09 Thread Daniel Neos
Hi wernerM,

Unfortunalety something like TeamViewer is not an option for me.
I have to it the hard way(via windows rdp)...



wernerM wrote:
> Hi Daniel,
> We are also using OSG together with modeen shaders like geometry shaders. We 
> have to do a lot of online presentations and online support. This works 
> perfect with TeamViewer. May this be an option for you? 
> 
> On 9. September 2016 18:04:13 MESZ, Daniel Neos <> wrote:
> >  
> > > Hi,my Applcation mainly uses Qt(with QOpenGlWidget) and OpensceneGraph, 
> > > thus it relies heavily on OpenGL.Since the Remote Desktop Protocol(RDP) 
> > > poorly supports OpenGL, there is no trivial way to runmy application over 
> > > Windows Remote Desktop. Hence, I choose to use Softwarerendering as a 
> > > fallback.I can tell Qt which opengl version to use programmatically with 
> > > QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true);or 
> > > QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true);But osg 
> > > seems to strictly link against opengl.dll from the desktop version, no 
> > > matter if i am delay loading the osg*.dll i am using or not.When delay 
> > > loading the osg*.dll , the desktop version will be loaded when the 
> > > application makes it first contact with osg-related stuff, in my case it 
> > > is an objects which inherits from QOpenGLWidget integrating the 
> > > openscenegraph viewCode:<
> > > br
> > > />OSGWidget::OSGWidget(QWidget* parent, Qt::WindowFlags f): 
> > > QOpenGLWidget(parent, f), m_graphicsWindow(new 
> > > osgViewer::GraphicsWindowEmbedded(x(),y(),width(),
> > > height())), m_geometry(new osg::Geometry()), 
> > > m_isInitialized(false), m_compositeViewer(new 
> > > osgViewer::CompositeViewer), m_camera(new osg::Camera), 
> > > m_view(new OsgView), m_geometryNode(new osg::Geode), 
> > > m_pickEventHandler(new PickEventHandler(static_cast<OSGWidget&>(*this)))  
> > >   , m_camManipulator(new OsgCameraManipulator), m_depthData(nullptr)  
> > >   , m_markedPoint(QPoint(DepthDataSet::InvalidPixelCoordinateValue, 
> > > DepthDataSet::InvalidPixelCoordinateValue)), 
> > > m_isMarkedPointVisible(false), m_isRendering(false){}Everything works 
> > > fine using the desktop version of openg. But If I am trying to link agains
> > > t the
> > > opengl32sw.dll(from Qt), osg seems to ignore it and links the 
> > > desktopOpenGL.The leads to the problem that the application crashes in 
> > > the deep of osg.To be more specific, here is an excerpt of the callstack 
> > > from top to bottom.->OSGWidget::paintGL() 
> > > ->m_compositeViewer->renderingTraversals()  -> ViewerBase::makeCurrent()  
> > >  -> osg::GraphicsContext::makeCurrent() -> 
> > > osg::State::initializeExtensionProcs()Here I need to say that my first 
> > > step is trying to run the application withsoftware rendering only, before 
> > > switching to Remote Desktop.I suspect that the mixture of the 
> > > opengl32.dll versions leads to crash the application or maybeeven 
> > > somethings is wrong with the opengl32sw.dll from Qt. But everything 
> > > non-related to osg seemsto be displayed fine. I am using osg 3.4.0 and Qt 
> > > 5.7So how can I run osg Code based on Software rendering
> > > ?Thank you!Cheers,Daniel[/b][/code]--Read this topic 
> > > online here:http://forum.openscenegraph.org/viewtopic.php?p=68563#68563 
> > > (http://forum.openscenegraph.org/viewtopic.php?p=68563#68563)osg-users 
> > > mailing 
> > > ://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
> > > (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > 
> 
> 
>  --
> Post generated by Mail2Forum


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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] How to prevent OSG linking against Desktop OpenGL

2016-09-09 Thread Daniel Neos
Hi,

my Applcation mainly uses Qt(with QOpenGlWidget) and OpensceneGraph, thus it 
relies heavily on OpenGL.

Since the Remote Desktop Protocol(RDP) poorly supports OpenGL, there is no 
trivial way to run
my application over Windows Remote Desktop. Hence, I choose to use 
Softwarerendering as a fallback.

I can tell Qt which opengl version to use programmatically with 
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true);
or QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true);

But osg seems to strictly link against opengl.dll from the desktop version, no 
matter if i am delay loading the osg*.dll i am using or not.

When delay loading the osg*.dll , the desktop version will be loaded when the 
application makes it first contact with osg-related stuff, 
in my case it is an objects which inherits from QOpenGLWidget integrating the 
openscenegraph view


Code:

OSGWidget::OSGWidget(QWidget* parent, Qt::WindowFlags f)
: QOpenGLWidget(parent, f)
, m_graphicsWindow(new osgViewer::GraphicsWindowEmbedded(x(),
y(),
width(),
height()))
, m_geometry(new osg::Geometry())
, m_isInitialized(false)
, m_compositeViewer(new osgViewer::CompositeViewer)
, m_camera(new osg::Camera)
, m_view(new OsgView)
, m_geometryNode(new osg::Geode)
, m_pickEventHandler(new PickEventHandler(static_cast(*this)))
, m_camManipulator(new OsgCameraManipulator)
, m_depthData(nullptr)
, m_markedPoint(QPoint(DepthDataSet::InvalidPixelCoordinateValue, 
DepthDataSet::InvalidPixelCoordinateValue))
, m_isMarkedPointVisible(false)
, m_isRendering(false)
{
}





Everything works fine using the desktop version of openg. But If I am trying to 
link against the opengl32sw.dll(from Qt), 
osg seems to ignore it and links the desktopOpenGL.

The leads to the problem that the application crashes in the deep of osg.
To be more specific, here is an excerpt of the callstack from top to bottom.

->OSGWidget::paintGL()
 ->m_compositeViewer->renderingTraversals()
  -> ViewerBase::makeCurrent()
   -> osg::GraphicsContext::makeCurrent() 
-> osg::State::initializeExtensionProcs()


Here I need to say that my first step is trying to run the application with
software rendering only, before switching to Remote Desktop.


I suspect that the mixture of the opengl32.dll versions leads to crash the 
application or maybe
even somethings is wrong with the opengl32sw.dll from Qt. But everything 
non-related to osg seems
to be displayed fine. I am using osg 3.4.0 and Qt 5.7


So how can I run osg Code based on Software rendering?





Thank you!

Cheers,
Daniel[/b][/code]

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Get openGL version with the Help of osg

2016-08-04 Thread Daniel Neos
Hi,

In my application, at the very first beginning, I want to check which openGL 
version the user has before creating/doing anything openGL related. 

For example the user can have a very poor openGL version(or remote Desktop only 
supports openGL 1.1), then I want to check the openGL version first and shut 
down the application, if necessary.

How can I achieve the openGL version with openscenegraph the most easy way? I 
tried the osg::getGLVersion() but I certainly need a kind of context first.

How can I get such a context without creating windows to yield the supported 
openGL version?


Thank you!

Cheers,
Daniel

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Improvement of Arcball Camera Handling

2016-07-21 Thread Daniel Neos
Hi,

I want to improve my CameraHandling since it acts a little bit odd if I am too 
far in the center of the scene, which is the lookat-point of the camera.

The camera is rotates around a specific point(mid of the boundingsphere 
center), always looking at it.  

But if I am getting to close to the midpoint, sometimes I lose the focus point 
or the camera rotates very fast. My code is rather simple, maybe there is a 
caveat which I am not aware of.

Also the distance changes, if I am rotating around the same axis everytime, I 
get close or far away.


Code:

void OsgWidgetEventHandler::rotateOrbitCamera(double angle, const osg::Vec3d& 
axis, osgViewer::View* viewer)
{
const osg::Matrixd rotation = osg::Matrix::rotate(angle, axis);
osg::Matrixd preTrans = osg::Matrix::identity();
osg::Matrixd postTrans = osg::Matrix::identity();

const osg::Vec3 translation = 
viewer->getCamera()->getViewMatrix().getTrans();
m_rotationPoint = translation - m_boundingSphereCenter;

preTrans.setTrans(-m_rotationPoint);
postTrans.setTrans(m_rotationPoint);
osg::Matrixd viewMatrix = viewer->getCamera()->getViewMatrix();
viewMatrix = viewMatrix * (preTrans * rotation *  postTrans);
viewer->getCamera()->setViewMatrix(viewMatrix);

osg::Vec3d eye, center, up;
viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
if (m_focusPointFlag)
{
viewer->getCamera()->setViewMatrixAsLookAt(eye, m_boundingSphereCenter, 
up);
}
}




The m_focusPointFlag is only false when the camera was translated(not zoomed), 
so that the lookat point can be changed.

How can I achieve a smooth arcball camera behaviour?

Thank you!

Cheers,
Daniel

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Visibility of Vertices

2016-07-08 Thread Daniel Neos
Hi,

is there an easy way to determine whether a single vertex is visible or not, 
i.e. no other object is blocking the line of sight?

My problem is that my geometry does not consist of solid objects or planes, 
just a lot of single vertices.

I want to be enable to pick a point reliably by a mouseclick. My approach is to 
use the polytopeintersector, then mapping all points that have been caught by 
the intersector into screen-coordinates and comparing them with the 
screen-coordinates of my mouseclick.

This works very well until my camera is set such that multiple vertices seems 
to be "in line", so that a point in the background gets accidentally picked.
I could exclude those points if I am able to tell that those points are 
occluded by the points in the foreground. I could imagine that this is rather 
simple with solid objects, but how can I achieve this in my setup?

Any help would by appreciated.


Here is the code which handles the pointpicking so far:

Code:

osg::Vec2d worldToScreenNormalized(const osg::Vec3d& worldPosition, const 
osg::Camera* pCamera, const osgGA::GUIEventAdapter& ea)
{
osg::Vec2d screenPosition;

if (pCamera != nullptr)
{
osg::Matrixd MVPW = pCamera->getViewMatrix() * 
pCamera->getProjectionMatrix() * pCamera->getViewport()->computeWindowMatrix();
osg::Vec4d screenPosition4d = osg::Vec4d(worldPosition, 1.0) * MVPW;
screenPosition4d = screenPosition4d / screenPosition4d.w();
screenPosition4d.y() = pCamera->getViewport()->height() - 
screenPosition4d.y();
screenPosition.set(screenPosition4d.x(), screenPosition4d.y());
screenPosition.set(2.0f*(screenPosition.x() - ea.getXmin()) / 
(ea.getXmax()- ea.getXmin()) - 1.0f,
-(2.0f*(screenPosition.y() - ea.getYmin()) / (ea.getYmax() - 
ea.getYmin()) - 1.0f));
}

return screenPosition;
}

bool PickHandler::getPickedPoint(const osgGA::GUIEventAdapter& ea, float buffer,
osgViewer::View* viewer)
{
try
{
intersector = new osgUtil::PolytopeIntersector(
osgUtil::Intersector::PROJECTION,
ea.getXnormalized() - buffer, ea.getYnormalized() - buffer, 
ea.getXnormalized() + buffer, ea.getYnormalized() + buffer);
}
catch (const std::bad_alloc&)
{
return false;
}

const osg::Vec2d clickedNormalizedScreencoord(ea.getXnormalized(), 
ea.getYnormalized());
// DimZero = check only for points
intersector->setDimensionMask(osgUtil::PolytopeIntersector::DimZero);
// nearest intersection
intersector->setIntersectionLimit(osgUtil::Intersector::NO_LIMIT);
osgUtil::IntersectionVisitor iv(intersector);
viewer->getCamera()->accept(iv);

// check if intersector has got intersections and chooses the first one, 
else set NaN
if (intersector->containsIntersections())
{
osgUtil::PolytopeIntersector::Intersection intersection
= *(intersector->getIntersections().begin());

osg::Vec3f pickedPoint;

float distance = 1E10;
unsigned int numIntersection=0;
osg::Vec3f sum;
for (auto it = intersector->getIntersections().begin(); it != 
intersector->getIntersections().end(); it++)
{
unsigned int numIntersections = it->numIntersectionPoints;
numIntersection++;
for (size_t i = 0; i < numIntersections; ++i)
{
osg::Vec2d screen = 
worldToScreenNormalized(it->intersectionPoints[i], viewer->getCamera(),ea);
if ((screen - clickedNormalizedScreencoord).length2() < 
distance )
{
distance = (screen - 
clickedNormalizedScreencoord).length2();
pickedPoint = it->intersectionPoints[i];
}
}
}

if (pickedPoint.isNaN())
{
return false;
}
m_point.set(pickedPoint[0], pickedPoint[1], pickedPoint[2]);
}
else
{
float NaN = std::numeric_limits::quiet_NaN();
m_point.set(NaN, NaN, NaN);
}
return true;
}








Thank you!

Cheers,
Daniel[/code]

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Keep Geometry always visible withtout occlusions

2016-07-06 Thread Daniel Neos
Hi,

I have a scene consisting one geometry node. This node contains 2 geometries. 
One of them has a lot of vertices, color are bound per vertex.
The other one is a single vertex, but set with a point of the size of 15, 
basically it is just a 'fat' vertex. This servers as a marker.

This marker shall be always visibile, but unfortunalety the other geometry 
mostly occludes the marker. It seems like the marker is stuck in between.

I managed it to get it always visible with making the marker opaque and setting 
the other geometry as transparent.

But now since it is transparent, unwanted (but understandable) effects occurs 
(the background can shine through).


Is there a way to always keep a marker unoccluded with letting the actual 
geometry opaque.

Thank you!

Cheers,
Daniel

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Realtime Pointpicking

2016-06-24 Thread Daniel Neos
Hi,

I have a Pickhandler and a dynamically changing scene which consists only of a 
geometry node. To be more specific, the geometry node represents a point cloud 
consisting over ~10 vertices.

Using a line intersector makes it nearly impossible to get an intersection, but 
the Intersector I am using, the polytopeintersector, needs ~200ms to get an 
intersection, which is too long for my application. I need a 'smooth' 
visualization of ~20-25fps and this would be definitley a bottleneck.

Is there a more simple way to get intersections of a non-solid object fast?

Here is my PickHandler. Input arguments in my application are the normalized 
(x,y)coordinates from the GUIEventAdapter, buffer is the tolerance with 0.005 
and the viewer casted from the ActionAdapter.


Code:

bool PickHandler::getPickedPoint(double x, double y, float buffer,
osgViewer::View* viewer)
{
 osg::ref_ptr intersector(0);
try
{
intersector = new osgUtil::PolytopeIntersector(
osgUtil::Intersector::PROJECTION,
x - buffer, y - buffer, x + buffer, y + buffer);
}
catch (const std::bad_alloc&)
{
return false;
}

// DimZero = check only for points
intersector->setDimensionMask(osgUtil::PolytopeIntersector::DimZero);

intersector->setIntersectionLimit(osgUtil::Intersector::LIMIT_NEAREST);
osgUtil::IntersectionVisitor iv(intersector);
viewer->getCamera()->accept(iv);

if (intersector->containsIntersections())
{
osgUtil::PolytopeIntersector::Intersection intersection
= *(intersector->getIntersections().begin());

const osg::Vec3f& p = intersection.intersectionPoints[0];
m_point.set(p[0], p[1], p[2]);
return true;
}
return false;




Thank you!

Cheers,
Daniel[/code]

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Arcball Camera without unexpecting 'roll' of the camera

2016-05-17 Thread Daniel Neos
Unfortunalety there is no feature "throw" feature. My class inherits from 
osgGA::GUIEventHandler and there is no setAllowThrow implemented, as far as I 
know.

Here is (part of) my actual mouse dragging code:


Code:


bool CameraHandler::handle(const osgGA::GUIEventAdapter & ea, 
osgGA::GUIActionAdapter & us)
{
osgViewer::View* viewer = dynamic_cast<osgViewer::View*>();
osg::Matrixd viewMatrix = viewer->getCamera()->getViewMatrix();
osg::Vec3d translation = viewMatrix.getTrans();

osg::Matrixd rotationX = osg::Matrix::rotate(deltaX  * 0.5, 
osg::Y_AXIS);
osg::Matrixd rotationY = osg::Matrix::rotate(-deltaY * 0.5, 
osg::X_AXIS);
osg::Matrixd preTrans = osg::Matrix::identity();
osg::Matrixd postTrans = osg::Matrix::identity();

osg::Vec3d bsCenter = osg::Vec3d(137.69, 284.17, 3305.0); // 
scene is (almost) static
m_rotationPoint = osg::Vec3(0.0, 0.0 , 0.0); // good rotation 
point for 

m_rotationPoint = translation - bsCenter; // good rotation 
point for 

preTrans.setTrans(-m_rotationPoint);
postTrans.setTrans(m_rotationPoint);

viewMatrix = viewMatrix * (preTrans * rotationX * rotationY * 
postTrans);
viewer->getCamera()->setViewMatrix(viewMatrix);

// ensure fixed point to look at
osg::Vec3d eye, center, up;
viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
if (focusPointFlag)
{
viewer->getCamera()->setViewMatrixAsLookAt(eye, bsCenter , 
up);
}

return true;
}





And if I am zooming in, sometimes the effect gets worse and the camera is 
hardly to control. Maybe there is an error in my rotation setup?

Thank you!

Cheers
Daniel Neos


cbuchner1 wrote:
> Could it be that the "throw" feature of the camera manipulator is responsible 
> for the roll?
> 
> If so, try disabling it.
> 
> 
> Also, post source code if you want specific help with a specific issue in 
> your implementation.
> 
> 
> Christian
> 
> 
> 
> 



Code:




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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Arcball Camera without unexpecting 'roll' of the camera

2016-05-16 Thread Daniel Neos
Hi everyone,

I have implemented a Cameramanipulator by myself, because I need more 
individually control over the camera in the scene, like rotating around a 
specific axis.

I let osg compute the Boundingsphere of my scene and set the rotationpoint and 
the lookat-point or center-point at the center of the Boundingsphere.

My rotation works like this

1.) Translate the camera to the center of the Boundingsphere (Multiplicated 
from the right side of the viewmatrix of the camera fist)

2.) Rotate the viewmatrix by the OSG::x_axis and OSG::y_axis (depending on the 
mousemovement)

3.) Translate the camera back with the vector from step 1.

4.) Now with the last step I ensure, that the camera stays focused at the 
samepoint by getting the eye, center and up vector and reseting the center 
vector, while eye and up remains the same.

This usually works fine and it is easy to navigate through the scene with the 
mouse, but as I reach some regions the camera unexpectedly seem to rotate 
around its own z-axis which results in to a 'roll'.

How can I prevent this behaviour? Sample code with arcball camera would be 
appreciated too :)

Thank you!

Cheers,
Daniel

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How to properly update a Geometry

2016-04-29 Thread Daniel Neos

gwaldron wrote:
> If you're just updating an existing array, you don't need to call 
> setVertexArray (etc); but you need to mark it dirty by calling
> 
>   m_vertices->dirty();
> 
> 
> That applies also to your other buffer objects (color array, elements, etc.)
> 
> 
> 
> Glenn Waldron
> 
> 


Hi Glenn, 

thanks for your solution, I somehow came up with a solution which calls 
setVertexArray() anyway,
because I am not feeling confident when updating a geometry with dynamically 
changing 
size of vertices each frame.

In my numbercrunching class, I create a geometry which I pass to
the visiualization class.


Code:

osg::ref_ptr vertices(new osg::Vec3Array());
osg::ref_ptr colors(new osg::Vec4Array());

for (int i = 0; i < nPixel; i++)
{
  // Fill in vertices and colors...
  // 
  //
}

m_geometry->setVertexArray(vertices.get());
m_geometry->setColorArray(colors.get());
m_geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
if (firstTimecall)
{
m_geometry->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, vertices->size()));
this->attachGeometry(m_geometry);
}
else
{
this->updateGeometry(m_geometry, nPixel);
}




Then I update the geometry of my visualization class like this


Code:

void OSGWidget::updateGeometry(osg::ref_ptr geometry, const int 
nPixel)
{
m_geometry->setVertexArray(geometry->getVertexArray());
m_geometry->setColorArray(geometry->getColorArray());

osg::DrawArrays* drawArrays = 
static_cast<osg::DrawArrays*>(m_geometry->getPrimitiveSet(0));
drawArrays->setCount(nPixel);
drawArrays->dirty();

// ensures update of scene
this->update();
}




This seems to work, but eventually there is a more efficient and elegant 
solution to exchange/ update vertice and colors.
I hope my issue is clear and small piece of samplecode will be appreciated. 
Thanks!

Cheers,
Daniel Neos

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] How to properly update a Geometry

2016-04-29 Thread Daniel Neos
Greetings everyone,

I am trying to display a point cloud, consisting of vertices and color with 
OpenSceneGraph. A static point cloud to display is rather easy with this guide. 
But I am not capable of updating such a point cloud. My intention is to create 
a geometry and attach it to my viewer class once.
This is the mentioned method which is called once in the beginning.

The OSGWidget strongly depends on this OpenGLWidget based approach. 


Code:

void OSGWidget::attachGeometry(osg::ref_ptr geom)
{
osg::Geode* geode = new osg::Geode;

geom->setDataVariance(osg::Object::DYNAMIC);
geom->setUseDisplayList(false);
geom->setUseVertexBufferObjects(true);
bool addDrawSuccess = geode->addDrawable(geom.get()); // Adding Drawable Shape 
to the geometry node


if (!addDrawSuccess)
{
throw "Adding Drawable failed!";
}

osg::StateSet* stateSet = geode->getOrCreateStateSet();
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);


float aspectRatio = static_cast(this->width()) / 
static_cast(this->height());

// Setting up the camera
osg::Camera* camera = new osg::Camera;
camera->setViewport(0, 0, this->width(), this->height());
camera->setClearColor(osg::Vec4(0.f, 0.f, 0.f, 1.f)); // Kind of 
Backgroundcolor, clears the buffer and sets the default color (RGBA)
camera->setProjectionMatrixAsPerspective(30.f, aspectRatio, 1.f, 1000.f); // 
Create perspective projection
camera->setGraphicsContext(graphicsWindow_); // embed 

osgViewer::View* view = new osgViewer::View;
view->setCamera(camera); // Set the defined camera
view->setSceneData(geode); // Set the geometry
view->addEventHandler(new osgViewer::StatsHandler);


osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;
manipulator->setAllowThrow(false);

view->setCameraManipulator(manipulator);

///
// Set the viewer
//
viewer_->addView(view);
viewer_->setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
viewer_->realize();

this->setFocusPolicy(Qt::StrongFocus);
this->setMinimumSize(100, 100);

this->setMouseTracking(true);
}





This method gets set once and shall set up the camera, interactor settings and 
the overall scene which only consists of one geode containing the geometry 
which shall be updated continiously.
And after I have 'attached' the geometry, I am trying to update the geometry 
like this


Code:

void PointCloudViewOSG::processData(DepthDataSet depthData)
{
if (depthData.points()->empty())
{
return; // empty cloud, cannot do anything
}

const DepthDataSet::IndexPtr::element_type& index = *depthData.index();
const size_t nPixel = depthData.points().get()->points.size();

if (depthData.intensity().isValid() && !index.empty() )
{
for (int i = 0; i < nPixel; i++)
{
float x = depthData.points().get()->points[i].x;
float y = depthData.points().get()->points[i].y;
float z = depthData.points().get()->points[i].z;
m_vertices->push_back(osg::Vec3(x
, y
, z));

// 32 bit integer variable containing the rgb (8 bit per channel) value
uint32_t rgb_val_;
memcpy(_val_, &(depthData.points().get()->points[i].rgb), 
sizeof(uint32_t));

uint32_t red, green, blue;
blue = rgb_val_ & 0x00ff;

rgb_val_ = rgb_val_ >> 8;
green = rgb_val_ & 0x00ff;

rgb_val_ = rgb_val_ >> 8;
red = rgb_val_ & 0x00ff;

m_colors->push_back(
osg::Vec4f((float)red / 255.0f,
(float)green / 255.0f,
(float)blue / 255.0f,
1.0f)
);
}

m_geometry->setVertexArray(m_vertices.get());

m_geometry->setColorArray(m_colors.get());

m_geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);

m_geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 
0, m_vertices->size()));  
}
}




(Apperantly the code tag can somehow not handle the whitespaces but i will let 
it be since it is more readable than if everything is aligned)

So my guess is that the  addPrimitiveSet(...)  shall not be called everytime I 
update the geometry, since it will push_back 
the primitive set everytime the geometry gets updated?

Do I have to reattach my geometry after every update? Or do I have to rewrite 
my update method?
So it boils down to the question  What steps are necessary to update my 
underlying geometry with new vertices and colors

I have read the basic tutorials and looked for similar questions in this forum 
and the only thing that I could adapt is the use of VBO for performance gain

PointCloudlibrary (PCL) is unfortunately not an alternative since of some 
incompatibilities with my application.




Thank you!

Cheers,
Daniel

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





___
osg-users mailing list