Re: [osg-users] scene snapshot

2017-08-30 Thread Gianni Ambrosio
Hi Nick,
I'm not sure my scenario is like mine but hope this code snippet may help:


Code:

void setViewTowardsXMinus()
{
   
nodeTrackerManipulator->setTransformation(computeEye(osg::Vec3d(nodeTrackerManipulator->getDistance(),
 0.0, 0.0)), osg::Vec3d(0.0, 0.0, 0.0), 
nodeTrackerManipulator->getHomeUpPosition());
}

void setViewTowardsXPlus()
{
   
nodeTrackerManipulator->setTransformation(computeEye(osg::Vec3d(-nodeTrackerManipulator->getDistance(),
 0.0, 0.0)), osg::Vec3d(0.0, 0.0, 0.0), 
nodeTrackerManipulator->getHomeUpPosition());
}

void setViewTowardsYMinus()
{
   nodeTrackerManipulator->setTransformation(computeEye(osg::Vec3d(0.0, 
nodeTrackerManipulator->getDistance(), 0.0)), osg::Vec3d(0.0, 0.0, 0.0), 
nodeTrackerManipulator->getHomeUpPosition());
}

void setViewTowardsYPlus()
{
   nodeTrackerManipulator->setTransformation(computeEye(osg::Vec3d(0.0, 
-nodeTrackerManipulator->getDistance(), 0.0)), osg::Vec3d(0.0, 0.0, 0.0), 
nodeTrackerManipulator->getHomeUpPosition());
}

void setViewTowardsZMinus()
{
   nodeTrackerManipulator->setTransformation(computeEye(osg::Vec3d(0.0, 0.0, 
nodeTrackerManipulator->getDistance())), osg::Vec3d(0.0, 0.0, 0.0), 
nodeTrackerManipulator->getHomeUpPosition());
}

void setViewTowardsZPlus()
{
   nodeTrackerManipulator->setTransformation(computeEye(osg::Vec3(0.0f, 0.0f, 
-nodeTrackerManipulator->getDistance())), osg::Vec3d(0.0, 0.0, 0.0), 
nodeTrackerManipulator->getHomeUpPosition());
}

osg::Vec3d computeEye(const osg::Vec3d& iEye)
{
   osg::Vec3d eye = iEye;
   ...
   double psi, theta, phi;
   graphicObject->getInitialRotation(psi, theta, phi);
   osg::Quat initAttitude = viosg::quatFromBody313(psi, theta, phi);
   eye = initAttitude * graphicObject->getTransformNode()->getAttitude() * eye;
   return eye;
}




Cheers,
Gianni

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





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


Re: [osg-users] How can I increase the performance? Two different scenarios

2017-08-28 Thread Gianni Ambrosio
OK, let's start from one issue (maybe I can get some answers).

I have a wavefront/obj file that loaded in my application is pretty slow.
Frame rate ~ 7
geometry # 13
Vertices # 4914461
Primitives # 9648023

The obj file is loaded by the osg_obj plugin.

What can I do to improve the performance?
First of all I thought of splitting the geometry in chunks. Is there anything 
useful in OSG libraries? Is there a known algorithm just for splitting the mesh?

I gave a look at MeshLab and CGAL library but I didn't find anything doing just 
that. MeshLab is really fast manipulating that huge mesh! in CGAL there is a 
mesh segmentation but it's much more then splitting and it is a quite slow 
process.

Cheers,
Gianni

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





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


Re: [osg-users] How to change "field of view"(FOV), distance.

2017-08-21 Thread Gianni Ambrosio
Hi Arfaa,
here is my implementation:

Code:
bool ViewerWidget::setMainCameraFieldOfView(double iFov)
{
   osg::Camera* camera = mainView()->getCamera();
   double fovy, aspectRatio, zNear, zFar;
   bool result = camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, 
zNear, zFar);
   if (true == result) {
  camera->setProjectionMatrixAsPerspective(iFov, aspectRatio, zNear, zFar);
   }
   return result;
}



ViewerWidget inherits from osgViewer::CompositeViewer. Anyway what I notice on 
your code is that you use a CameraViewer while I set the FOV to a osg::Camera. 
You could try the code on a osg::Camera and if it works then I guess there is 
something to investigate on the CameraViewer side.

HTH, Gianni

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





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


Re: [osg-users] ViewerBase::frame() method slow after changing the color of a geometry

2017-08-18 Thread Gianni Ambrosio
Hi,
just an update that can be useful for others.

As suggested I split the original huge geometry in chunks (1-3 vertices 
each works fine) and it works fine now.

Thanks again,
Gianni

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





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


Re: [osg-users] ViewerBase::frame() method slow after changing the color of a geometry

2017-07-21 Thread Gianni Ambrosio
Thank you very much Robert,
I will do as you suggested.

Gianni

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





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


Re: [osg-users] ViewerBase::frame() method slow after changing the color of a geometry

2017-07-21 Thread Gianni Ambrosio
Thanks Lionel and Robert for the quick reply.

I tried what Lionel suggested but in fact the geometry generation is much more 
slow now.
Anyway, since I suspected that "dirtyDisplayList()" is the cause of the delay, 
I tried to remove that line but without it I cannot see the new color.
Now, is "dirtyDisplayList()" really required for what I need or is there a 
different call should I use just to see the triangle with the updated color?

Thanks,
Gianni

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





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


[osg-users] ViewerBase::frame() method slow after changing the color of a geometry

2017-07-21 Thread Gianni Ambrosio
Hi All,
I build a huge geometry (27 milion vertices, 9 milion triangles) as follows:

osg::Geometry* geometry = new osg::Geometry;
geometry->setDataVariance(osg::Object::DYNAMIC);
geometry->setVertexArray(buildVertices(count));
geometry->setColorArray(buildColors(count), 
osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(buildElements(count));

On mouse event, after getting an intersection with the graphics, I do:

osg::Geometry* geom = 
dynamic_cast(intersection.drawable.get());
osg::Vec4Array& color = 
dynamic_cast(*geom->getColorArray());
color[intersection.indexList[0]] = selectedColor;
color[intersection.indexList[1]] = selectedColor;
color[intersection.indexList[2]] = selectedColor;
geom->dirtyDisplayList();
color.dirty();

The problem is that after these lines there is a delay of at least one second 
before seeing the triangle with the updated color on my 3D viewer.
Debugging OSG code I found that "ViewerBase::frame()" is called twice before 
seeing the new color. Moreover the first time "frame()" is called 
"renderingTraversals()" takes a lot.

I will debug the OSG code deeper but is there a way to prevent the delay I see 
in my application?
You can find the full example in attachment.

Thanks for your help,
Gianni

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



// materials.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 

#include 

#include 
#include 
#include 
#include 

#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

#include 

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler()
: selectedColor(0.5f, 0.5f, 0.5f, 1.0f)
{}

virtual bool handle(const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa)
{
if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE &&
ea.getModKeyMask() & 
osgGA::GUIEventAdapter::MODKEY_CTRL)
{
osgViewer::View* viewer = 
dynamic_cast();
if (viewer)
{
std::chrono::steady_clock::time_point start1 = 
std::chrono::steady_clock::now();
osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());

//intersector->setPrecisionHint(osgUtil::Intersector::USE_FLOAT_CALCULATIONS);
osgUtil::IntersectionVisitor iv(intersector.get());
osg::Camera* camera = viewer->getCamera();
std::chrono::steady_clock::time_point end1 = 
std::chrono::steady_clock::now();
std::cout << "Intersector creation took " << 
std::chrono::duration_cast(end1 - start1).count() << 
" us.\n";
std::chrono::steady_clock::time_point  start2 = 
std::chrono::steady_clock::now();
camera->accept(iv);
std::chrono::steady_clock::time_point  end2 = 
std::chrono::steady_clock::now();
std::cout << "Camera accept took " << 
std::chrono::duration_cast(end2 - start2).count() << 
" us.\n";
std::chrono::steady_clock::time_point start3 = 
std::chrono::steady_clock::now();
if (intersector->containsIntersections())
{

osgUtil::LineSegmentIntersector::Intersections& intersections = 
intersector->getIntersections();

osgUtil::LineSegmentIntersector::Intersection result = *(intersections.begin());
doUserOperationsColor(result);
}
std::chrono::steady_clock::time_point  end3 = 
std::chrono::steady_clock::now();
std::cout << "Apply color to geometry took " << 
std::chrono::duration_cast(end3 - start3).count() << 
" us.\n";
 }
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_0) {
selectedColor.set(0.5f, 0.5f, 0.5f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
selectedColor.set(1.0f, 0.0f, 0.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
selectedColor.set(0.0f, 1.0f, 0.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
selectedColor.set(0.0f, 0.0f, 1.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
selectedColor.set(1.0f, 0.0f, 1.0f, 1.0f);
}
return false;
}


Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Debugging the OSG code it seems most of time spent before seeing the picked 
triangle with adifferent color is inside "ViewerBase::renderingTraversals()", 
and exactly in the following line:

if (_endDynamicDrawBlock.valid())
{
_endDynamicDrawBlock->block(); // <-- HERE!
}

Any idea?

Regards,
Gianni

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





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


Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Just an update.
OSG KdTree works great!

Computational time for "camera->accept(intersectionVisitor)":
before it was about 10M microseconds
with KdTree it is about 25 microseconds!

This is the code I modified in my example:

Code:

osg::Node* createScene() {
osg::Geode* geode = new osg::Geode;
   osg::KdTree* kdtree = new osg::KdTree;
   osg::Geometry* geometry = buildGeometry();
   osg::KdTree::BuildOptions buildOptions;
   kdtree->build(buildOptions, geometry);
   geometry->setShape(kdtree);
geode->addDrawable(geometry);
return geode;
}




Gianni

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





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


Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Thanks Jordi for the fast reply.
I will try with Kdtrees. In fact USE_FLOAT_CALCULATIONS does not help much.

I have one more issue.
As you can see in my previously attached example, after mouse picking, I 
basically set:

geometry->dirtyDisplayList();
geometry->getColorArray()->dirty();

Those methods are pretty fast but in fact I have a delay of about one second on 
my PC (some seconds on other PCs) before seeing the picked triangle with a 
different color. Is there an obvious reason for that delay?


Regards,
Gianni

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





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


[osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Hi All,
I built a test geometry with about 9M triangles and 27M vertices. The intent of 
my spike solution (attached) is to select a triangle with mouse to change its 
color. I realized that the bottleneck of that code is the line where the camera 
accepts the "osgUtil::IntersectionVisitor" (line 51: camera->accept(iv)). That 
call takes most of the computation time.
Debugging the OSG code I fall into:

void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, 
osg::Drawable* drawable, const osg::Vec3d& s, const osg::Vec3d& e)

In that code there are different methods to be used: KdTree, 
USE_DOUBLE_CALCULATIONS or USE_FLOAT_CALCULATIONS.
On the basis of your experience, is one of the previous method ideal to solve 
my performance issue or something else must be done?

Best regards,
Gianni

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



// materials.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 

#include 

#include 
#include 
#include 
#include 

#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

#include 

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler()
: selectedColor(0.5f, 0.5f, 0.5f, 1.0f)
{}

virtual bool handle(const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa)
{
if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE &&
ea.getModKeyMask() & 
osgGA::GUIEventAdapter::MODKEY_CTRL)
{
osgViewer::View* viewer = 
dynamic_cast();
if (viewer)
{
std::chrono::steady_clock::time_point start1 = 
std::chrono::steady_clock::now();
osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
osgUtil::IntersectionVisitor 
iv(intersector.get());
osg::Camera* camera = viewer->getCamera();
std::chrono::steady_clock::time_point end1 = 
std::chrono::steady_clock::now();
std::cout << "Intersector creation took " << 
std::chrono::duration_cast(end1 - start1).count() << 
" us.\n";
std::chrono::steady_clock::time_point  start2 = 
std::chrono::steady_clock::now();
camera->accept(iv);
std::chrono::steady_clock::time_point  end2 = 
std::chrono::steady_clock::now();
std::cout << "Camera accept took " << 
std::chrono::duration_cast(end2 - start2).count() << 
" us.\n";
std::chrono::steady_clock::time_point start3 = 
std::chrono::steady_clock::now();
if (intersector->containsIntersections())
{

osgUtil::LineSegmentIntersector::Intersections& intersections = 
intersector->getIntersections();

osgUtil::LineSegmentIntersector::Intersection result = *(intersections.begin());
doUserOperationsColor(result);
}
std::chrono::steady_clock::time_point  end3 = 
std::chrono::steady_clock::now();
std::cout << "Apply color to geometry took " << 
std::chrono::duration_cast(end3 - start3).count() << 
" us.\n";
 }
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_0) {
selectedColor.set(0.5f, 0.5f, 0.5f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
selectedColor.set(1.0f, 0.0f, 0.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
selectedColor.set(0.0f, 1.0f, 0.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
selectedColor.set(0.0f, 0.0f, 1.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
selectedColor.set(1.0f, 0.0f, 1.0f, 1.0f);
}
return false;
}

virtual void 
doUserOperationsColor(osgUtil::LineSegmentIntersector::Intersection& result)
{
osg::Geometry* geom = 
dynamic_cast(result.drawable.get());
osg::Vec4Array& color = 
dynamic_cast(*geom->getColorArray());
color[result.indexList[0]] = selectedColor;
color[result.indexList[1]] = selectedColor;
color[result.indexList[2]] = selectedColor;
geom->dirtyDisplayList();
color.dirty();
}

protected:
osg::Vec4 selectedColor;
};

osg::Vec3Array* 

Re: [osg-users] wireframe darker wrt the surface color

2017-07-18 Thread Gianni Ambrosio
Hi Sebastian,
sorry I missed your reply.


SMesserschmidt wrote:
> 
> Most probably your problem is lighting. Your surface is shaded correctly 
> while your wireframe stays constant. At a certain angle the lit result is 
> simply the same color as your constant wireframe.
> 

I think you are right. That's what happening. Now I don't remember exactly what 
I tried few months ago but if it is simply to reach, what should I do to make 
the wireframe color just a little bit darker with respect to the surface color 
at every view angle?

SMesserschmidt wrote:
> 
> Can you present the relevant code, where you set up the wireframe?
> 

Please see attached cpp file.

Regards,
Gianni

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



#include 
#include 
#include 
#include 
#include 

#include "Wireframable.h"

//-
Wireframable::Wireframable()
{
   decorator = new osg::Group;
   decorator->setName("wireframe");
   decorator->setNodeMask(0x0); //disable wireframe by default

   setPolygonMode();
   setMaterial(osg::Vec4(0.5, 0.5f, 0.5f, 1.0f));
}

//-
Wireframable::Wireframable(const Wireframable& iOther)
: viframework::viobjects::SmartPointer(iOther)
{
}

//-
void Wireframable::enableWireframe(bool iEnable)
{
   decorator->setNodeMask(static_cast(iEnable));
}

//-
void Wireframable::enableLighting(bool enable)
{
   decorator->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OVERRIDE | enable ? osg::StateAttribute::ON : 
osg::StateAttribute::OFF);
}

//-
bool Wireframable::isWireframeEnabled() const
{
   return static_cast(decorator->getNodeMask());
}

//-
void Wireframable::setMaterial(const osg::Vec4& color)
{
#if 0
   //osg::Material* material = new osg::Material;
   //decorator->getOrCreateStateSet()->setAttributeAndModes(material, 
osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
   //enableLighting(false);
   //osg::Material* material = new osg::Material;
   //decorator->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);
   decorator->getOrCreateStateSet()->setAttributeAndModes(new 
osg::Depth(osg::Depth::ALWAYS, 0.0, 1.0, false), osg::StateAttribute::ON);
   //decorator->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, 
osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);
   //decorator->getOrCreateStateSet()->setAttributeAndModes(material, 
osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
#else
   // version which sets the color of the wireframe.
   osg::Material* material = new osg::Material;
   material->setColorMode(osg::Material::OFF); // switch glColor usage off
   // turn all lighting off
   material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0f, 
0.0f, 1.0f));
   material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0f, 
0.0f, 1.0f));
   material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0f, 
0.0f, 1.0f));
   // except emission... in which we set the color we desire
   material->setEmission(osg::Material::FRONT_AND_BACK, color);
   decorator->getOrCreateStateSet()->setAttributeAndModes(material, 
osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
   enableLighting(true);
#endif
}

//-
void Wireframable::setNode(osg::ref_ptr iNode)
{
   bool nodeAlreadySet = false;
   if (iNode->getParents().size()>0) {
  // call from GraphicObject copy constructor: decorator is already a child 
of node's parent
  osg::Group* parent = iNode->getParent(0);
  for (unsigned int i = 0; igetNumChildren(); ++i) {
 if ("wireframe" == parent->getChild(i)->getName()) {
decorator = static_cast(parent->getChild(i));
decorator->addChild(iNode); // we need to repeate this because 
DEEP_COPY_ALL does not keep the relation
nodeAlreadySet = true;
break;
 }
  }
   }
   if (false == nodeAlreadySet) {
  decorator->addChild(iNode);
  iNode->getParent(0)->addChild(decorator);
   }
}

//-
void Wireframable::setPolygonMode()
{
   osg::PolygonMode* polymode = new osg::PolygonMode;
   polymode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
   decorator->getOrCreateStateSet()->setAttributeAndModes(polymode, 
osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
}
___

Re: [osg-users] wireframe darker wrt the surface color

2017-04-04 Thread Gianni Ambrosio
Thanks Nick,
I have to think it over since I've implemented a shader some months ago but  
I'm not really familiar with. The point would be how to get the real geometry 
color? BTW, I can try.

Anyway, isn't there a simpler way to get the desired result? Robert, any idea?

Regards,
Gianni

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





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


Re: [osg-users] wireframe darker wrt the surface color

2017-03-29 Thread Gianni Ambrosio
Hi Nick

Trajce Nikolov NICK wrote:
> Hi Gianni,
> 
> you can do something like
> getOrCreateStateSet()->setAttributeAndModes(new 
> osg::Depth(osg::Depth::ALWAYS, 0.0, 1.0, false), osg::StateAttribute::ON);
> 

I tried the line you suggested with lights on or off but I have in every case a 
gray wireframe. While I would like to have a darker/lighter yellow wireframe on 
a yellow surface, and a darker/lighter green wireframe on a green surface.

Gianni

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





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


Re: [osg-users] wireframe darker wrt the surface color

2017-03-27 Thread Gianni Ambrosio
So, I need the wireframe to be always visible (darker or ligher) independently 
of the object rotation.

Is there a way to implement it?

Regards,
Gianni

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





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


Re: [osg-users] wireframe darker wrt the surface color

2017-03-27 Thread Gianni Ambrosio
The point is that if I simply use:


Code:
   osg::Material* material = new osg::Material;
   stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::OFF);
   stateset->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::ON);




then, I get the wireframe of the same color of the surface but when I rotate 
the 3D object the wireframe disappears at a certain position.

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



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


[osg-users] wireframe darker wrt the surface color

2017-03-21 Thread Gianni Ambrosio
Hi All,
I implemented the wireframe feature as follows:


Code:
void addWireframe(osg::Group* root, osg::Node* scene)
{
   osg::ref_ptr decorator = new osg::Group;
   decorator->setNodeMask(0x1);

   osg::StateSet* stateset = decorator->getOrCreateStateSet();

   osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
   polyoffset->setFactor(2.0f);
   polyoffset->setUnits(2.0f);
   stateset->setAttributeAndModes(polyoffset, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::ON);

   osg::PolygonMode* polymode = new osg::PolygonMode;
   polymode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
   stateset->setAttributeAndModes(polymode, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::ON);

   osg::Material* material = new osg::Material;
   material->setColorMode(osg::Material::OFF); // switch glColor usage off
   // turn all lighting off
   material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.5, 0.5f, 
0.5f, 1.0f));
   material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.5, 0.5f, 
0.5f, 1.0f));
   material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0f, 
0.0f, 1.0f));
   // except emission... in which we set the color we desire
   material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.7, 0.7f, 
0.7f, 1.0f));
   stateset->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::ON);
   stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::ON);

   decorator->addChild(scene);
   root->addChild(decorator);
}



Now instead of having the wireframe of a fixed color, I would like to show it 
in a slightly darker color wrt the color of the related geometry. Is it 
possible? How?

Thanks in advance,
Gianni

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





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


Re: [osg-users] different result rotating Vec3d for Quat or Matrixd

2017-01-24 Thread Gianni Ambrosio

Trajce Nikolov NICK wrote:
> 
> if you swap the order of the matrix and the vector will you get the same 
> result?
> 

Yes, same result but ...
1) that's pretty counterintuitive: why should I have to change the order to get 
the same result? And unfortunately I guess that's not documented.
2) if I really need to multiply the matrix on the left side then there isn't a 
similar way to get the same transformation with a quaternion since "Vec3d * 
Quat" gives a compile time error.

Regards,
Gianni

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





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


[osg-users] different result rotating Vec3d for Quat or Matrixd

2017-01-24 Thread Gianni Ambrosio
Hi,
may be this is a newbie question but I would like to understand the reason of 
this behaviour.

I have to calculate the coordinate of a 3D point wrt a different coordinate 
reference. The new coordinate reference is simply rotated wrt the first one. I 
tried two different implementations with different results.

osg::Vec3d eyeOffset(0.0, 0.0, 300.0);
osg::Quat rotation(osg::DegreesToRadians(0.0), osg::Z_AXIS, 
osg::DegreesToRadians(0.0),  osg::Y_AXIS, osg::DegreesToRadians(45.0), 
osg::X_AXIS);
osg::Vec3d localEyeOffset = rotation * eyeOffset;
osg::Matrixd rotationMatrix(rotation);
osg::Vec3d localEyeOffset2 = rotationMatrix * eyeOffset;

I expected to have the same result for localEyeOffset and localEyeOffset2, 
while this is what I get:
localEyeOffset is (0.0, -212.132, 212.132)
localEyeOffset2 is (0.0, 212.132, 212.132)

Can you explain me why?

Regards,
Gianni

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





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


Re: [osg-users] OSG 3.4 + FFmpeg

2016-11-16 Thread Gianni Ambrosio
Hi Sam,
if you don't have a pre-built libraries than you can choose the FFmpeg version 
you like since you have to build them on your own.
With OSG 3.4 now I build ffmpeg 3.0.2.

Cheers,
Gianni

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





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


Re: [osg-users] help for warping

2016-11-16 Thread Gianni Ambrosio
Warping done with MVP matrix, thanks anyway.

Gianni

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





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


Re: [osg-users] blending with shader

2016-11-11 Thread Gianni Ambrosio
Hi David,
thanks it works!

Here are my vertex and fragment shaders:

Code:

varying vec2 texCoord;

void main(void)
{
   gl_Position = ftransform();
   texCoord = gl_MultiTexCoord0.xy;
}




Code:

uniform float width;
uniform float height;
uniform float gamma;
uniform sampler2D sceneTexture;
uniform sampler2D blendTexture;
uniform sampler2D blackTexture;

varying vec2 texCoord;

void main(void) {
   vec4 sceneColor = texture2D(sceneTexture, texCoord);
   vec2 fragCoord = vec2(gl_FragCoord.x/width, gl_FragCoord.y/height);
   vec4 blendColor = texture2D(blendTexture, fragCoord);
   vec4 blackColor = texture2D(blackTexture, fragCoord);
   vec4 gammaVector = vec4(gamma, gamma, gamma, 1.0);
   gl_FragColor = pow(pow(sceneColor*blendColor, gammaVector) * (1.0 - 
pow(blackColor, gammaVector)) + pow(blackColor, gammaVector), 1.0/gammaVector);
};




I had to use fragCoord for blending images because those images must not be 
distorted.
Is that code correct? I mean, it works but maybe there is a cleaner way to 
implement that. In particulare, is there a way to avoid passing "width' and 
"height" variables to the shader?

Regards,
Gianni[/img]

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





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


Re: [osg-users] blending with shader

2016-11-10 Thread Gianni Ambrosio
Hi David,
you should find the complete code (including the shader) in the 
"osgdistortion.cpp" file I attached in a previous message. I modified the 
original OSG example to include the blending shader I used. If you download it 
and the "blending.png" image (attached to the same message) and modify the path 
properly inside the cpp file, you can have a full example.

Thanks for your support,
Gianni

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





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


Re: [osg-users] blending with shader

2016-11-10 Thread Gianni Ambrosio
Hi All,
I can apply blending to a texture rendered with a RTT camera from a shader but 
now I have a different problem.

Before blending I have to apply a distortion to the scene because of a 
projection on a curved screen. Blending image is already distorted so I have to 
apply blending on an already distorted texture of the scene.
I'm trying to implement distortion/warping moving texcoords of a Geometry node 
(i.e. geometry->setTexCoordArray(0, tcoords);). That geometry is a grid where 
the texture, that comes from RTT camera, is applied.

Here is the code to attach the blending shader to the Geometry/Geode:


Code:

void addShader(osg::Geode* node, double width, double height)
{
   osg::StateSet * stateset = node->getOrCreateStateSet();

   osg::Program * program = new osg::Program;
   stateset->setAttribute(program);
   addFragmentShader(program, blendingShaderFilePath);

   stateset->addUniform(new osg::Uniform("width", (float)width));
   stateset->addUniform(new osg::Uniform("height", (float)height));
   stateset->addUniform(new osg::Uniform("gamma", gamma));
   stateset->addUniform(new osg::Uniform("eye", osg::Vec3(0.0f, 0.0f, 0.0f)));

   osg::ref_ptr< osg::Image> blendingImage = 
osgDB::readImageFile(blendingImagePath);
   osg::Texture2D* blendingTexture = new osg::Texture2D(blendingImage.get());
   blendingTexture->setFilter(osg::Texture2D::MIN_FILTER, 
osg::Texture2D::LINEAR);
   blendingTexture->setFilter(osg::Texture2D::MAG_FILTER, 
osg::Texture2D::LINEAR);

   stateset->setTextureAttribute(1, blendingTexture);
   stateset->addUniform(new osg::Uniform("blendTexture", 1));
}




The problem is that I can just see the blended image, while distortion is lost.

How could I make distortion/warping live together with blending?

Regards,
Gianni

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





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


Re: [osg-users] help for warping

2016-11-07 Thread Gianni Ambrosio
If I have to clarify something please ask.

Gianni

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





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


[osg-users] help for warping

2016-11-03 Thread Gianni Ambrosio
Hi All,
I'm struggling with a warping implementation to show a 3D scene to a curved 
screen.

I gave a look at osgdistortion example and implemented a RTT camera just like 
in that example.
So now I have a render to texture camera that generates a texture of the 3D 
scene. Then a HUD camera with a geode as child where its geometry is attached 
to the texture.

I have a csv file that describes the screen shape as mesh of points. The file 
contains the following data: x,y,z,u,v.
Each line represents the x,y,z patial coordinates of a screen point.

For a different project that uses Unity and C#, a colleague implemented the 
warping basically in this way:


Code:

Vector2[] uvs = new Vector2[mesh.vertices.Count()];
for (int i = 0; i < mesh.vertices.Count(); i++) {
Vector3 pos = camera.WorldToViewportPoint(mesh3d.vertices[i]);
uvs[i] = new Vector2(pos.x, pos.y);
}
mesh.uv = uvs;



I didn't find a WorldToViewportPoint method in OSG but I find some references 
on the web to implement it.

On the other hand it seems the osgdistortion example is implemented differently.

One more thing I have to say is that projectors and curved screen are fixed 
while the observer is sitting on a moving platform. So I have to correct the 
camera frustum first.

Anyway, could you please suggest and explain me how to implement the warping 
considering that it would be also nice to use a shader to improve performance 
(if possible)?

Cheers,
Gianni

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





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


Re: [osg-users] passing uniforms to compute shader

2016-10-28 Thread Gianni Ambrosio
Well, you could provide the code you use so that someone can find the error.

Cheers,
Gianni

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





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


Re: [osg-users] Qt version for OSG3.4.0

2016-10-17 Thread Gianni Ambrosio
I'm currently working with Qt 5.6.0 but Qt 5.5.1 worked fine as well.

Cheers,
Gianni

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





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


Re: [osg-users] blending with shader

2016-10-12 Thread Gianni Ambrosio
Thanks for the explanations.

d_a_heitbrink wrote:
> 
> As per the inout, this states the parameter into the function is both an 
> input and an output. I set the version for my shader to something like 4.5 in 
> compatibility mode. The function was called last in my shader.
> 

I was just asking how do you get the value of color parameter passed to the 
function not the meaning of "inout" (I already read that from documentation ;))

Regards,
Gianni

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





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


Re: [osg-users] blending with shader

2016-10-10 Thread Gianni Ambrosio
Hi David,
I'm not able to use the BlendFunct you posted but it seems I can get something 
nice with the following (fragment) shader:

char myBlendingProgram[] =
"uniform float width;\n"
"uniform float height;\n"
"uniform sampler2D sceneTexture;\n"
"uniform sampler2D blendTexture;\n"
"void main(void) {\n"
"   vec2 texCoord = vec2(gl_FragCoord.x/width, gl_FragCoord.y/height);\n"
"   vec4 sceneColor = texture2D(sceneTexture, texCoord);\n"
"   vec4 blendingColor = texture2D(blendTexture, texCoord);\n"
"   gl_FragColor = sceneColor * blendingColor;\n"
"}\n";

Anyway I have some questions.

In your BlendFunct I don't know how you get the "inout vec4 color" parameter. I 
guess it's something like "sceneColor" in my shader. But I would like to know 
the proper way you suggest to get it.

Then,
just like the osgdistortion example, I have the following OSG node structure:


Code:
root (osg::Group)
+--- renderToTextureCamera (osg::Camera)
|  +--- (Scene)
+--- hudCamera(osg::Camera)
   +--- geode (osg::Geode)
  +--- geometry (osg::Geometry)



To the renderToTextureCamera I call:
camera->attach(osg::Camera::COLOR_BUFFER, texture);

While I attach the texture to the geometry with the code:
osg::StateSet* stateset = geometry->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute:: ON);
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);

And I attach the shader to the Geode node.

Is it correct to attach the shader to the geode?

Anyway, here is the code I use to attach the shader and related uniforms to the 
geode stateset:


Code:
void OsgPlugin::addShader(osg::Geode* node)
{
osg::StateSet * stateset = node->getOrCreateStateSet();

osg::Program * program = new osg::Program;
stateset->setAttribute(program);
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, 
myBlendingProgram));

stateset->addUniform(new osg::Uniform("width", (float)1280.0));
stateset->addUniform(new osg::Uniform("height", (float)720.0));

osg::ref_ptr< osg::Image> blendingImage = 
osgDB::readImageFile("C:/Users/User/Desktop/temp/blending.png");
osg::Texture2D* texture = new osg::Texture2D(blendingImage.get());
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);

stateset->setTextureAttribute(1, texture);
stateset->addUniform(new osg::Uniform("blendTexture", 1));
}




One note: I have to use 1 as first parameter of setTextureAttribute to make my 
example working (with 0 it didn't work).
On the other hand I was surprised to have a valid sceneTexture in my shader 
without setting it on the stateset of the geode nor adding a uniform for it! 
Can you exaplain me why? I can suppose the TextureAttribute can be inherited 
from the stateset of the related geometry but I can't understand why the 
uniform is not needed.

Moreover, the "sceneTexture" variable I get in the shader is not distorted. In 
fact I used the same code of osgdistortion exampe for the moment where a sort 
of distortion is implemented on the geometry.
If I remove the shader I can correctly see the distortion. Can you explain me 
why please?

I have one more question (problem to solve) but I think that's enough for the 
moment.

Best regards,
Gianni

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





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


Re: [osg-users] multiple input with osgwidgets

2016-10-05 Thread Gianni Ambrosio

Meldryt wrote:
> 
> The reason why i use MouseHandler is because it will send events to the 
> WindowManager which knows all about its windows and widgets.
> 

I may be wrong since I don't know your code in detail but I think about class 
"responsiblities". From my point of view it's not bad to implement a 
MouseEventHandler which updates (in some way) the window manager. Maybe a 
WindowManagerUpdater that will be a collaborator of the MouseEventHandler so 
that your cose will be more testable. You will not have to send events to the 
window manager but just call the proper methods from the WindowManagerUpdater.

Cheers,
Gianni

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





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


Re: [osg-users] blending with shader

2016-10-05 Thread Gianni Ambrosio
Hi,
do ypu think the osgdistortion example is a good starting point to create the 
proper osg structure to render the scent into a texture?

Cheers,
Gianni

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





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


Re: [osg-users] multiple input with osgwidgets

2016-10-04 Thread Gianni Ambrosio
Honestly I usually derive from osgGA::GUIEventHandler to handle mouse events.

Cheers,
Gianni

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





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


[osg-users] blending with shader

2016-09-30 Thread Gianni Ambrosio
Hi All,
I have a projector attached to a PC where a 3rd party application runs. The 3rd 
party application uses OSG 3.0.1 and allows to add custom code re-implementing 
some virtual methods of their base Plugin class.

I need to apply a blending operation to the visualized scene so that the 
projector displays the blended image on the (curved) screen (please see 
attached image). I guess the source image (=image of the scene just like an osg 
viewer does) must be warped also but that's story I will investigate on later.

Even if I have just a rough idea of shaders, as far as I have understood that's 
the way to implement the required blending.

I found several examples in which a shader manipulates the 3D scene but in my 
case I think I have to modify the resulting image of the scene.
Now, it is not clear to me how pass the required informations to the shader 
code and if I can handle the whole rendered image of the scene from the shader 
and how.

Regards,
Gianni

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



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


Re: [osg-users] multiple input with osgwidgets

2016-09-30 Thread Gianni Ambrosio
Hi Meldryt,
I worked with osgWidget in the past. I move a widget with left_mouse+mouse_move 
and resize it with central_mouse_button+mouse_move.
I also tried to show a contextual menu clicking with right mouse button on it.
Now I'm on OSG 3.4.0 but moved recentrly from OSG 3.0.1.

Could you please just write "one" of the cases not working in your 
implemetation?

Cheers,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-30 Thread Gianni Ambrosio
Hi Sebastian,
thanks for the example.

The roads I use may have from 600K to a maximum of 9 milion elements 
(=triangles). Maybe a mean of 2 milions.

Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-28 Thread Gianni Ambrosio
Hi Sebastian,
I would like to adopt you solution if possible but I was not able to implement 
with textures the same behaviour of the example I did with primitive sets.

I know that on windows the example crashes in debug mode because of an 
assertion inside Microsoft implementaition of std::vector. It's a matter of  
_ITERATOR_DEBUG_LEVEL. In release mode it works fine. Just to explain the 
reason. Anyway the movie should not crash :D

So, do you think it would be possible to implement the same behaviour with 
textures?

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-28 Thread Gianni Ambrosio
Hi Sebastian,
after looking at your example I understood a shader is not needed, right?
The solution you suggest is to apply a texture instead of changing color. In my 
case the image of the texture would be a monochromatic image.
If all that is correct, then I have few questions.
I modified my previous example to insert your solution there.

1) Since most part of the road surface may be not associated to a "material", 
then I thought of adding a BIND_OVERALL default grey color. Does it make sense?
2) On the basis of point 1) is it possible to add a texture only to triangles 
affected by a "material". In your example you added a texture to the overall 
geometry. Isn't that a problem if the road has a bunch of vertices? I mean, 
that bunch of vertices would be duplicated to create texture coords.
3) In the attached example Ididn't understand how to set the image just to the 
picked triangle so that it will be shown of the "current" color. (In my example 
pushing 1,2,3 and 4 keys changes the current color).
4) I have to read some documentation about textures since I didn't understand 
how texture coords should be defined and the effect of:

texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST);
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST);

5) I tried to create different texture coords (see #ifdef in the attached code) 
but "result.getTextureLookUp(tc);" in "doUserOperations" method does not seem 
to work. Anyway even with your implementation of "buildTexCoords" the selection 
is pretty odd.

Regards,
Gianni

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



#include "stdafx.h"

#include 

#include 
#include 
#include 
#include 

#include 

#include 
#include 

const unsigned int DIMENSION = 4;

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
   SelectModelHandler()
  : selectedColor(0.5f, 0.5f, 0.5f, 1.0f)
   {}

   virtual bool handle( const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa )
   {
  if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
  ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON &&
  ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_CTRL)
  {
 osgViewer::View* viewer = dynamic_cast();
 if (viewer) {
osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
osgUtil::IntersectionVisitor iv(intersector.get());
osg::Camera* camera = viewer->getCamera();
camera->accept( iv );

if (intersector->containsIntersections()) {
   osgUtil::LineSegmentIntersector::Intersection result = 
*(intersector->getIntersections().begin());
   doUserOperations( result );
}
 }
  }
  if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
 selectedColor.set(1.0f, 0.0f, 0.0f, 1.0f);
  }
  if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
 selectedColor.set(0.0f, 1.0f, 0.0f, 1.0f);
  }
  if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
 selectedColor.set(0.0f, 0.0f, 1.0f, 1.0f);
  }
  if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
 selectedColor.set(1.0f, 0.0f, 1.0f, 1.0f);
  }
  return false;
   }

   virtual void doUserOperations( 
osgUtil::LineSegmentIntersector::Intersection& result )
   {
  osg::Geometry* geom = dynamic_cast(result.drawable.get());
  osg::Vec3 tc;
  //the result seems slightly off 
  osg::Texture* tex = result.getTextureLookUp(tc);
  if (tex && tex->getImage(0)) {
 tex->getImage(0)->setColor(selectedColor, tc);
 tex->getImage(0)->dirty();
 tex->dirtyTextureObject();
  }
   }

protected:
   osg::Vec4 selectedColor;
};

osg::Image* makeDataImage(unsigned int rows)
{
   osg::Image* image = new osg::Image;
   image->allocateImage(rows, rows, 1, GL_RGB, GL_UNSIGNED_BYTE);
   for (unsigned int i = 0; i < rows; ++i) {
  for (unsigned int j = 0; j < rows; ++j) {
 osg::Vec2 uv(i / static_cast(rows - 1), j / 
static_cast(rows - 1));
 image->setColor(osg::Vec4(1, 0, 0, 1), uv);
  }
   }
   return image;
}

osg::Vec2Array* buildTexCoords(unsigned int num_rows)
{
#if 1
//create a grid 
osg::Vec2Array* v = new osg::Vec2Array(num_rows* num_rows);
for (unsigned int i = 0; i < num_rows; ++i)
{
for (unsigned int j = 0; j < num_rows; ++j)
{
(*v)[i * num_rows + j] = osg::Vec2(i / 
static_cast(num_rows -1), j / static_cast(num_rows -1));
}
}
return v;
#else
osg::Vec2Array* textureCoords = new osg::Vec2Array;
   textureCoords->push_back(osg::Vec2(0,0));
   textureCoords->push_back(osg::Vec2(1,0));
   textureCoords->push_back(osg::Vec2(0,1));
   

Re: [osg-users] OSG and Qt

2016-09-27 Thread Gianni Ambrosio
Hi Inna,
in osgGA library you can find several classes that derive from EventHandler. If 
you use Qt and osgQt library you can choose to handle events with osg or Qt. If 
you have something particular you are looking for please ask.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-27 Thread Gianni Ambrosio

SMesserschmidt wrote:
> Do you need to place the curbs 
> etc. also dynamically?
> 

The road geometry is fixed, I mean, the user can only assign/change a material 
to each triangle without adding or removing triangles from the road surface.

SMesserschmidt wrote:
> 
> Are there any restrictions to how the road is represented?
> 

I thought a color can be handled easily by the core road structure but in case 
dose it make sense to generate a monochromatic texture?

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-27 Thread Gianni Ambrosio

SMesserschmidt wrote:
> I can try to make a 
> minimal example, if you give me some time (I can do this after work).
> 

Sebastian,
yes thanks, when you have time is fine. In the meanwhile I try to understand 
the solutions you suggested.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-27 Thread Gianni Ambrosio

Trajce Nikolov NICK wrote:
> 
> you should call geometry->dirtyDisplayList(); at the end of your move function

Nick, I confirm my first example now works adding that line. At least I 
undestood what was missing.
Waiting for an opinion about the overall scenario, thanks again!

Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-27 Thread Gianni Ambrosio

Trajce Nikolov NICK wrote:
> Maybe better idea then these email iterations is to write us what is your 
> goal with this code since I see no smart logic in there (sorry :-) )
> 

OK, I try to explain in detail.

The object I visualize on 3D is a road. A road can have different "materials": 
asphalt, curbs, oil, puddles, obsacles ... The road surface including materials 
is defined in a core road structure. I drow the 3D road base on the data stored 
in the core road structure. There each road element (=triangle) is associated 
to a "material" object. For that reason I thought to use different colors, one 
for each material. So, asphalt = dark grey, curbs = red/white, oil = dark 
green, puddle = brown ...
The user, after loading a road, can change the "material" definition. So 
picking on the road surface he can add a puddle in the middle of the road. So 
the picked triangles must be shown in brown then.
In addition I have to update the core road structure accordingly.

This is the scenario. Hope this is clearer now.

Thanks Nick and Sebastian for the time spent, really!
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-26 Thread Gianni Ambrosio
One question,
why should I use a "vertex" shader/attribute when I need to colour a triangle 
uniformly?

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-26 Thread Gianni Ambrosio
Well, Nick,
I have to say I didn't understand what Sebastian suggested since I'm not 
familiar with shaders. As far as I understood a shader can not be debugged and 
I don't know if they are testable. Moreover the code is in a place different 
from the usual code, so something that has effect in the application but in 
some way disjoined. I'm not sure I would like such a solution.

Please consider also one more thing I didn't mention so clearly. After changing 
the color of triangles of my surfare, then at a certain point I have to update 
also an underlying code structure according to the new colors. Is there a way 
using a shader also to handle this part of the implementation?

Regards,
Gianni

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





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


Re: [osg-users] OSG and Qt

2016-09-26 Thread Gianni Ambrosio
Hi Inna,
I use OSG in Qt applications for years and I've never had specific problems 
with event handling.
Currently I'm on Qt 5.6 and OSG 3.4.0.

Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-26 Thread Gianni Ambrosio
Dear Nick,
I'm not sure to use the solution suggested by Sebastian (I've never worked with 
shaders so it is quite difficult to understand). So I would like to know if you 
foud a reason of the problem in my example?

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-22 Thread Gianni Ambrosio

SMesserschmidt wrote:
> So basically you are raping the primitive sets to color the primitive?

Yes, that's why at the beginning I asked help to suggest me the best way to 
implement this. Nobody replied so I found this way.

SMesserschmidt wrote:
> 
> That is certainly a complicated way in case you simply have a bunch of 
> triangles which you want to re-color during selection. I'd advice to use an 
> additional vertex-attribute (per vertex) holding your "color-index" and 
> evaluate it in the vertex-shader and modify this based on the intersected 
> indices. 
> 

In fact it is a little tricky even if I'm not sure I would have a bunch of 
nodes to change. But who knows ...
Anyway thans for the hint. I'm trying to understand what does that means 
exactly but if in the menwhile you can explain me a little bit in detail it 
would be nice.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-22 Thread Gianni Ambrosio
Hi Nick,
the triangle shown in white has just being added to highlight the selection. We 
can discard it for a while. For that reason I completly removed the selection 
highlight in my example. Please see attached code.
If you run the example and select a triangle pushing CTRL+LEFTMOUSE you will 
see a couple of messages on the console, something like:

"moving from primitive 1 to 0
... BUT why triangle does not change color?"

That's the point!

In my example I have 4 primitive sets:
index 0 = red
index 1 = green
index 2 = blue
index 3 = pink

Picking a green triangle it is moved from the original primitive set (1 i.e. 
green) to the primitive set with index = 0 (i.e. red). But why the triangle 
moved from green to red is still green? I would expect it to be red.

Regards,
Gianni

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



#include "stdafx.h"

#include 
#include 
#include 
#include 

#include 
#include 

#include 

#include 

#include 

#include 

const osg::Vec4 selectedColor(1.0f, 1.0f, 1.0f, 0.5f);
const osg::Vec4 color1(1.0f, 0.0f, 0.0f, 1.0f);
const osg::Vec4 color2(0.0f, 1.0f, 0.0f, 1.0f);
const osg::Vec4 color3(0.0f, 0.0f, 1.0f, 1.0f);
const osg::Vec4 color4(1.0f, 0.0f, 1.0f, 1.0f);

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler() : _selector(0), currentPrimitiveSetIndex(0) {}

virtual bool handle( const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa )
{
   if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
   {
  _selector->setVertexArray( new osg::Vec3Array(3) );
   }
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON &&
ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_CTRL)
{
   osgViewer::View* viewer = dynamic_cast();
   if ( viewer )
   {
   osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
   osgUtil::IntersectionVisitor iv(intersector.get());
   osg::Camera* camera = viewer->getCamera();
   camera->accept( iv );

   if ( intersector->containsIntersections() )
   {
   osgUtil::LineSegmentIntersector::Intersection result = 
*(intersector->getIntersections().begin());
   doUserOperations( result );
   }
   }
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
   currentPrimitiveSetIndex = 0;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
   currentPrimitiveSetIndex = 1;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
   currentPrimitiveSetIndex = 2;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
   currentPrimitiveSetIndex = 3;
}
return false;
}

virtual void doUserOperations( 
osgUtil::LineSegmentIntersector::Intersection& result )
{
osg::Geometry* geom = dynamic_cast( 
result.drawable.get() );
//if ( !geom || !_selector || geom==_selector ) return;

osg::Geode* geode = 
dynamic_cast(result.nodePath[result.nodePath.size()-1]);
unsigned int primitiveIndex = 
getPrimitiveIndex(dynamic_cast(geode->getDrawable(0)), 
result.primitiveIndex);
unsigned int indexInsidePrimitive = 
getIndexInsidePrimitive(dynamic_cast(geode->getDrawable(0)), 
result.primitiveIndex);
if (primitiveIndex != currentPrimitiveSetIndex) {
   std::cout << "moving from primitive " << primitiveIndex << " to " << 
currentPrimitiveSetIndex << std::endl;
   move(dynamic_cast(geode->getDrawable(0)), 
primitiveIndex, indexInsidePrimitive, currentPrimitiveSetIndex);
   std::cout << "... BUT why triangle does not change color?" << 
std::endl;
} else {
   std::cout << "nothing to move" << std::endl;
}
}

unsigned int getPrimitiveIndex(osg::Geometry* geometry, unsigned int 
globalIndex)
{
   unsigned int numPrimitives = geometry->getNumPrimitiveSets();
   unsigned int currentPrimitive = numPrimitives;
   unsigned int globalCount = 0;
   for (int i=0; igetPrimitiveSet(i);
  unsigned int count = primitiveSet->getNumPrimitives();
  if (globalCount <= globalIndex && globalIndex < globalCount+count) {
 currentPrimitive = i;
 break;
  } else {
 globalCount += count;
  }
   }
   return currentPrimitive;
}

unsigned int 

Re: [osg-users] different materials for a geometry and highlight

2016-09-21 Thread Gianni Ambrosio
Hi Nick,
the problem I have is that I change the content of primitive sets but the color 
does not change in the 3D view.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-21 Thread Gianni Ambrosio
Hi Nick,
thanks for the support but even with that line I can't see the result I 
expected. Basically, when the application starts, if I select a green triangle 
then it should be shown in red, while now it ramains green. (please see 
attached movie). In fact the triangle after picking is moved from primitive set 
1 to primitive set 0. Triangles belonging to primitive set 0 are accociated 
with red color in the color array. It's fine to see the white selector triangle 
"over" the selected triangle but is shoud become red.


Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-20 Thread Gianni Ambrosio

Trajce Nikolov NICK wrote:
> Hi Gianni,
> 
> if you make Qt free example I can have a look
> 

Sorry, this example "was" with Qt, now it is Qt-free. Just remove the includes 
on top: they are not used in this code.

Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-20 Thread Gianni Ambrosio
Hi All,
I'm attaching the updated code where you can see the problem: even if I call 
dirty() for primitive sets and dirtyBounds() on the related geometry, the 
graphics is not updated.

Cheers,
Gianni

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



#include "stdafx.h"

#include 
#include 
#include 

#include 
#include 
#include 
#include 

#include 
#include 

#include 

#include 

#include 

#include 

const osg::Vec4 selectedColor(1.0f, 1.0f, 1.0f, 0.5f);
const osg::Vec4 color1(1.0f, 0.0f, 0.0f, 1.0f);
const osg::Vec4 color2(0.0f, 1.0f, 0.0f, 1.0f);
const osg::Vec4 color3(0.0f, 0.0f, 1.0f, 1.0f);
const osg::Vec4 color4(1.0f, 0.0f, 1.0f, 1.0f);

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler() : _selector(0), currentPrimitiveIndex(0) {}

osg::Geode* createFaceSelector()
{
osg::ref_ptr colors = new osg::Vec4Array(1);
(*colors)[0] = selectedColor;

_selector = new osg::Geometry;
_selector->setDataVariance( osg::Object::DYNAMIC );
_selector->setUseDisplayList( false );
_selector->setUseVertexBufferObjects( true );
_selector->setVertexArray( new osg::Vec3Array(3) );
_selector->setColorArray( colors.get() );
_selector->setColorBinding( osg::Geometry::BIND_OVERALL );
_selector->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLES, 0, 3) );

osg::ref_ptr geode = new osg::Geode;
geode->addDrawable( _selector.get() );
geode->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );
geode->getOrCreateStateSet()->setMode( GL_BLEND, 
osg::StateAttribute::ON );
geode->getOrCreateStateSet()->setRenderingHint( 
osg::StateSet::TRANSPARENT_BIN );
geode->getOrCreateStateSet()->setAttributeAndModes(new 
osg::PolygonOffset(-1.0f, -1.0f));
return geode.release();
}

virtual bool handle( const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa )
{
   if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
   {
  _selector->setVertexArray( new osg::Vec3Array(3) );
   }
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON &&
ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_CTRL)
{
   osgViewer::View* viewer = dynamic_cast();
   if ( viewer )
   {
   osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
   osgUtil::IntersectionVisitor iv(intersector.get());
   osg::Camera* camera = viewer->getCamera();
   camera->accept( iv );

   if ( intersector->containsIntersections() )
   {
   osgUtil::LineSegmentIntersector::Intersection result = 
*(intersector->getIntersections().begin());
   doUserOperations( result );
   }
   }
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
   currentPrimitiveIndex = 0;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
   currentPrimitiveIndex = 1;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
   currentPrimitiveIndex = 2;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
   currentPrimitiveIndex = 3;
}
return false;
}

virtual void doUserOperations( 
osgUtil::LineSegmentIntersector::Intersection& result )
{
osg::Geometry* geom = dynamic_cast( 
result.drawable.get() );
if ( !geom || !_selector || geom==_selector ) return;

osg::Vec3Array* vertices = dynamic_cast( 
geom->getVertexArray() );
osg::Vec3Array* selVertices = dynamic_cast( 
_selector->getVertexArray() );
if ( !vertices || !selVertices ) return;

osg::Geode* geode = 
dynamic_cast(result.nodePath[result.nodePath.size()-1]);
unsigned int primitiveIndex = 
getPrimitiveIndex(dynamic_cast(geode->getDrawable(0)), 
result.primitiveIndex);
unsigned int indexInsidePrimitive = 
getIndexInsidePrimitive(dynamic_cast(geode->getDrawable(0)), 
result.primitiveIndex);
std::cout << "primitiveIndex = " << result.primitiveIndex << std::endl;
std::cout << primitiveIndex << " - " << indexInsidePrimitive << 
std::endl;
move(dynamic_cast(geode->getDrawable(0)), 
primitiveIndex, indexInsidePrimitive, currentPrimitiveIndex);

osg::Matrix matrix = osg::computeLocalToWorld( result.nodePath );
const std::vector& selIndices = result.indexList;
for ( 

Re: [osg-users] Feedback/guidance sought on move of osgQt out into it's own project/repository

2016-09-20 Thread Gianni Ambrosio
Hi Mathieu,

Mathieu wrote:
> Qt4 is now on extended support (commercial) since december 2015. Which means 
> that any project seriously using Qt should have migrated long ago (wink to my 
> colleagues) !
> 

I would not say "long ago" in general. We moved recently to Qt5. There are 
several aspects to take in account: win10 support (from qt5.5 on if I remember 
correctly), supported compilers, ... and so on. Moreover there is also an LGPL 
license.
I would suggest to support Qt5 from a certain OSG version, but create a branch 
of the latest osgQt that supports Qt4.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-19 Thread Gianni Ambrosio

Trajce Nikolov NICK wrote:
> Maybe you dirty your color array too?
> 

Thanks Nikolov, in my code the color array don't change. Anyway I tried as you 
suggested and I can confirm that's not the point.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-19 Thread Gianni Ambrosio
OK,
I found a way to move a triangle from a primitive set to another.
Debugging the code primitive sets are updated correctly but the color remains 
the same.

I call 

sourcePrimitiveSet->dirty();
destinationPrimitiveSet->dirty();
geometry->dirtyBound();

What's wrong with it? Isn't enough?

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-19 Thread Gianni Ambrosio
Hi Sebastian,

SMesserschmidt wrote:
> I might be wrong, but I think the intersector.primitiveIndex might yield 
> the number you are looking for
> 

thanks for the reply but unfortunately it seems to return a number from 0 to 7 
that is the number of triangles in my example geometry. While the number of 
primitive sets is 4 in my example. But in fact I can use it at first to find 
the primitive set (knowing the size of each primitive set and its index). Then 
I have to verify if the "primitiveIndex" attribute of the same triangle changes 
moving that triangle from one primitive set to another.

Regards,
Gianni

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





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


Re: [osg-users] different materials for a geometry and highlight

2016-09-19 Thread Gianni Ambrosio
Hi All,
I've attached an example. Hope this helps to have a reply from somebody 
(Robert?).

Part of that example is from the OSG 3 Cookbook.
Suppose I have geometry build of triangles. I would like to understand which is 
the better way to change the color of a selected triangle. And if there is a 
preferred way to organize the object geometry to facilitate the color change 
feature.

The user chooses the current color punshing 1,2,3 or 4 key. Then pushing 
CTRL+LEFTMOUSE on the 3D geometry a triangle is selected. I need to apply the 
current selected color to the corresponding selected triangle.

Should I use the osgUtil::LineSegmentIntersector::Intersection::indexList value 
to find the corresponding primitive set the selected triangle belongs to? That 
seems too much of a hack from my point of view.
Isn't that possible in OSG using primitive sets then I have to split the object 
geometry into different pieces? (i.e. one Geode for each color so that I can 
then use the osgUtil::LineSegmentIntersector::Intersection::nodePath instead?)

Thanks for the help.
Gianni

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



#include "stdafx.h"

#include 
#include 
#include 

#include 
#include 
#include 
#include 

#include 
#include 

#include 

#include 

#include 

#include 

const osg::Vec4 selectedColor(1.0f, 1.0f, 1.0f, 0.5f);
const osg::Vec4 color1(1.0f, 0.0f, 0.0f, 1.0f);
const osg::Vec4 color2(0.0f, 1.0f, 0.0f, 1.0f);
const osg::Vec4 color3(0.0f, 0.0f, 1.0f, 1.0f);
const osg::Vec4 color4(1.0f, 0.0f, 1.0f, 1.0f);

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler() : _selector(0), currentColor(color1) {}

osg::Geode* createFaceSelector()
{
osg::ref_ptr colors = new osg::Vec4Array(1);
(*colors)[0] = selectedColor;

_selector = new osg::Geometry;
_selector->setDataVariance( osg::Object::DYNAMIC );
_selector->setUseDisplayList( false );
_selector->setUseVertexBufferObjects( true );
_selector->setVertexArray( new osg::Vec3Array(3) );
_selector->setColorArray( colors.get() );
_selector->setColorBinding( osg::Geometry::BIND_OVERALL );
_selector->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLES, 0, 3) );

osg::ref_ptr geode = new osg::Geode;
geode->addDrawable( _selector.get() );
geode->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );
geode->getOrCreateStateSet()->setMode( GL_BLEND, 
osg::StateAttribute::ON );
geode->getOrCreateStateSet()->setRenderingHint( 
osg::StateSet::TRANSPARENT_BIN );
geode->getOrCreateStateSet()->setAttributeAndModes(new 
osg::PolygonOffset(-1.0f, -1.0f));
return geode.release();
}

virtual bool handle( const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa )
{
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE &&
ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON &&
ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_CTRL)
{
   osgViewer::View* viewer = dynamic_cast();
   if ( viewer )
   {
   osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
   osgUtil::IntersectionVisitor iv(intersector.get());
   osg::Camera* camera = viewer->getCamera();
   camera->accept( iv );

   if ( intersector->containsIntersections() )
   {
   osgUtil::LineSegmentIntersector::Intersection result = 
*(intersector->getIntersections().begin());
   doUserOperations( result );
   }
   }
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
   currentColor = color1;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
   currentColor = color2;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
   currentColor = color3;
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
   currentColor = color4;
}
return false;
}

virtual void doUserOperations( 
osgUtil::LineSegmentIntersector::Intersection& result )
{
osg::Geometry* geom = dynamic_cast( 
result.drawable.get() );
if ( !geom || !_selector || geom==_selector ) return;

osg::Vec3Array* vertices = dynamic_cast( 
geom->getVertexArray() );
osg::Vec3Array* selVertices = dynamic_cast( 
_selector->getVertexArray() );
if ( !vertices || !selVertices ) return;

osg::Matrix matrix = osg::computeLocalToWorld( result.nodePath );
const std::vector& selIndices = result.indexList;
for ( unsigned int i=0; i<3 && 

Re: [osg-users] different materials for a geometry and highlight

2016-09-16 Thread Gianni Ambrosio

Code:
osg::Geometry* buildGeometry() {
   osg::Geometry* geometry = new osg::Geometry;
   geometry->setVertexArray(buildVertices());
   geometry->setColorArray(buildColors(), 
osg::Array::BIND_PER_PRIMITIVE_SET);

   std::vector elements = buildElements();
   for (std::vector::iterator i = elements.begin(); 
i != elements.end(); ++i) {
 geometry->addPrimitiveSet(*i);
   }

   return geometry;
}



When I pick a triangle, is there a way from the information stored into a 
osgUtil::LineSegmentIntersector::Intersection to get the related primitive set?

Regards,
Gianni

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





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


Re: [osg-users] odd scene resize

2016-09-07 Thread Gianni Ambrosio
Hi Sebastian,
the FIXED option is right the opposite of what I'm looking for.

I mean, if there are HORIZONTAL and VERTICAL options, there should be one 
option that is HORIZONTAL+VERTICAL and one option that is 
NO-HORIZONTAL+NO-VERTICAL. So one case seems missing.

I try to explain in detail.

ProjectionResizePolicy = VERTICAL:
If I resize the window horizontally, then the scene is resized without 
distortions.
While ... resizing the window vertically, the scene is not resized at all!

ProjectionResizePolicy = HORIZONTAL:
The opposite of HORIZONTAL case.


ProjectionResizePolicy = FIXED:
Scene completly distorted.

Now, first of all FIXED is not a combination of both HORIZONTAL and VERTICAL 
from my point of view.
Second, what I'm looking for is exactly a combination of HORIZONTAL and 
VERTICAL. Where resizing the window horizontally or vertically, the scene is 
resized in both cases to fit the viewer rectangle without distortions.

Cheers,
Gianni

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





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


Re: [osg-users] odd scene resize

2016-09-07 Thread Gianni Ambrosio
So, isn't possible to have both HORIZONTAL and VERTICAL?

Gianni

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





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


[osg-users] odd scene resize

2016-09-07 Thread Gianni Ambrosio
Dear Robert,
why resizing a (non-Qt) window horizontally then the scene is resized 
accordingly while resizing the window vertically is has no effect on the scene 
size?

Please see attached images.

Regards,
Gianni

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



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


Re: [osg-users] Feedback/guidance sought on move of osgQt out into it's own project/repository

2016-09-06 Thread Gianni Ambrosio
Hi All,
I use osgQt. Currently I'm on Qt 5.5 with OSG 3.4 but if I remember correctly 
older OSG versions are not compatible with Qt5 and vice versa. So probably 
there should be two different forks: osgQt4 from the OSG version compatible 
with Qt4, and osgQt5 from an OSG version compatible with Qt5. From which 
version make a fork for osgQt5 depends on the modifications on osgQt of the 
latest OSG stable version wrt trunk code.

Regards,
Gianni

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





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


[osg-users] different materials for a geometry and highlight

2016-09-06 Thread Gianni Ambrosio
Dear All,
I currently draw graphics with:

osg::Geometry* geometry = getGeometry();
geometry->setVertexArray(vertices);
geometry->addPrimitiveSet(elements);

where:
osg::Vec3Array* vertices = new osg::Vec3Array;
osg::DrawElementsUInt* elements = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES);

I build vertices and elements based on an underlying model. I draw the geometry 
in a neutral gray color.

Now I need to apply some material information, got from the underlying model, 
on the osg::Geometry, so that it is not uniformly gray.
I have a list of possible materials each of them should be visualized with a 
different color.
Moreover the user could interact with the 3D surface selecting the 3D 
primitives and changing the material (so the color) to them. That chang will be 
stored then on the underlying model.
It would be fine also to highlight the selected trinagles of the geometry 
(transparent-white for example) to chenge the material.

Looking around I thought to solve the problem with different primitive sets, 
one for each material.
About highlighting the selection I found a topic where Robert suggested to use 
a dedicated osg::Geometry:
http://forum.openscenegraph.org/viewtopic.php?t=13347=previous

Any other (better) idea?

Best regards,
Gianni

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





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


Re: [osg-users] GUIEventHandler::handle return value never used?

2016-08-29 Thread Gianni Ambrosio
Hi Robert,
just out of curiosity, where, in the OSG code, the return value of handle() 
method is used and in which sense?

Regards,
Gianni

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





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


Re: [osg-users] GUIEventHandler::handle return value never used?

2016-08-29 Thread Gianni Ambrosio
Hi Robert,
the sense from what I can read from the handle code is: the return value states 
if the GUIEventHandler has handled the event. So, the event "manager" (the code 
in CompositeViewer) should not call other handlers for the current event if the 
event has been already handled by another event handler.

Regards,
Gianni

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





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


[osg-users] GUIEventHandler::handle return value never used?

2016-08-25 Thread Gianni Ambrosio
Hi All,
is there anybody that can explain me please why (at least in OSG 3.4.0) in 
CompositeViewer.cpp, inside eventTraversal() method, the return value of 
GUIEventHandle::handle(...) is not used?
Here is a code snippet:


Code:

for(ViewEventsMap::iterator veitr = viewEventsMap.begin();
veitr != viewEventsMap.end();
++veitr)
{
View* view = veitr->first;
_eventVisitor->setActionAdapter(view);

for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
itr != veitr->second.end();
++itr)
{
osgGA::Event* event = itr->get();
for(View::EventHandlers::iterator hitr = 
view->getEventHandlers().begin();
hitr != view->getEventHandlers().end();
++hitr)
{
(*hitr)->handle( event, view, _eventVisitor.get());
}
}
}




Please look at the line:
(*hitr)->handle( event, view, _eventVisitor.get());

While GUIEventHandler::handle method returns bool as you can see in the 
following code:


Code:

bool GUIEventHandler::handle(osgGA::Event* event, osg::Object* object, 
osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast(nv);
osgGA::GUIEventAdapter* ea = event->asGUIEventAdapter();
if (ea && ev && ev->getActionAdapter())
{
#if 1
bool handled = handle(*ea, *(ev->getActionAdapter()), object, nv);
if (handled) ea->setHandled(true);
return handled;
#else




Regards,
Gianni

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





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


Re: [osg-users] Strange problem with QT, OSG and osgdb_dae.so

2016-08-22 Thread Gianni Ambrosio
Hi All,
I can load COLLADA models with osg dae plugin in a Qt application correctly.

Cheers,
Gianni

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





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


Re: [osg-users] Problems with osgFX::Outline node

2016-08-18 Thread Gianni Ambrosio
Hi,
OSG version is 3.4.0

Cheers,
Gianni

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





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


[osg-users] Problems with osgFX::Outline node

2016-08-17 Thread Gianni Ambrosio
Hi All,
I found at least two problems related to osgFX::Outline.

First of all, turning off lightning on a child node then the outline seems 
inheriting that option.

Here is basically the code:


Code:

void ControlPoints::insertMarker(size_t iIndex, const 
viframework::vimath::Point& iPoint)
{
   osg::ref_ptr transform = new osg::AutoTransform();

   transform->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
   transform->setAutoScaleToScreen(true);
   transform->setMinimumScale(0.0);
   transform->setMaximumScale(FLT_MAX);

   transform->setPosition(osg::Vec3(iPoint.x(), iPoint.y(), iPoint.z()));
   transform->addChild(buildFlagWithOutlineEffect(30.0));
   root->addChild(transform);

   viroad::viosg::SceneManager::instance().setDirty();
}

osg::Node* ControlPoints::buildFlagWithOutlineEffect(float height)
{
   osgFX::Outline* outline = new osgFX::Outline;
   outline->setWidth(5);
   outline->setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
   Flag* flag = new Flag(height);
   //flag->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
   outline->addChild(flag);
   return outline;
}




In attachment you can see the different behaviour.
I would like to disable lightning on the flag but have a red outline.

About the second problem I will open a different topic.

Cheers,
Gianni

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



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


[osg-users] online documentation does not work

2016-08-10 Thread Gianni Ambrosio
Hi,
http://www.openscenegraph.org/index.php/documentation/guides/reference-guides

Click on any link relatet to specific library documentation (osg, osgViewer 
...) but the page is not shown. Yesterday and today the same problem.

Cheers,
Gianni

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





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


Re: [osg-users] OSG 3.4.0/QT 5.5 Warning "QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined"

2016-04-18 Thread Gianni Ambrosio
Hi Loopy,
I moved to OSG 3.4.0 and Qt5.6.0 recently but I didn't get such a warning. It 
seems a particular case of your implementation. Did you try the osgviewerQt 
example?

Regards,
Gianni

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





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


Re: [osg-users] set proper size to window manager at startup

2016-04-18 Thread Gianni Ambrosio
I can understand you don't have time and you are not the author of osgWidgets. 
Anyway the case can be reproduced with osgviewerQt example. Putting one 
breakpoint on GLWidget::event(QEvent*) and another breakpoint on 
ViewerWidget::paintevent() method (the one that calls frame()) you can easily 
see that QEvent::Resize, QEvent::Show, QEvent::WindowActivate events fall into 
GLWidget::event() "before" the first frame() is called. So, from my point of 
view, this is not strictly a problem of osgWidgets: resize, show and activate 
evets are cleared from the event queue in every case and I dont' think this is 
correct.

Regards,
Gianni

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





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


Re: [osg-users] set proper size to window manager at startup

2016-04-18 Thread Gianni Ambrosio
OK, thanks Robert for the informations.
So, just tio summarize the case for Cedric.
When a Qt Application starts, most of Qt events (like resize, show, activate, 
...) are sent to GLWidget before the OSG code handles them. GLWidget handles 
those events and queue them into OSG Eventqueue to be processed on the next 
frame() call. The problem in that the first call of ViewerBase::frame(double) 
calls setStartTick(osg::Timer::instance()->getStartTick()) (in realize() 
method) which clears the queued events. So this causes all events already 
queues not correctly handled.

I found that setStartTick() call is used somewhere in OSG code. I can suggest 
to call eventQueue.clear() before setStartTick() separatedly when needed 
instead of calling it directly inside setStartTick() but I'm not aware of the 
overall OSG code and possible consequences.

Hope this helps.
Gianni

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





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


Re: [osg-users] set proper size to window manager at startup

2016-04-18 Thread Gianni Ambrosio
I verified the clear() call has been added to EventQueue::setStartTick() method 
in OSG 3.1.1. Who did that can explain me please why it was required? Is there 
a way to move a clear() call outside the method to prevent the regression from 
OSG 3.1.1 onwards?

Cheers,
Gianni

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





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


Re: [osg-users] set proper size to window manager at startup

2016-04-15 Thread Gianni Ambrosio
I recently moved from OSG 3.0.1 to 3.4.0 and I'm getting this unexpected 
behaviour only with OSG 3.4.0. In fact comparing the code of 3.0.1 and 3.4.0 I 
realized the clear() call in EventQueue::setStartTick() is only present in 
3.4.0 code. I don't know the reason of that but from my point of view in 3.4.0 
setStartTick() does more that it says: setStartTick just have to set the tick 
non more than that. Moreover that modification (clear()) has broken the scenaio 
I described.

Gianni

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





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


Re: [osg-users] set proper size to window manager at startup

2016-04-15 Thread Gianni Ambrosio
The problem seems to be here:

osg130-osgGAd.dll!osgGA::EventQueue::clear()  Line 37   C++
osg130-osgGAd.dll!osgGA::EventQueue::setStartTick(__int64 tick)  Line 212 + 
0x25 bytes  C++
osg130-osgViewerd.dll!osgViewer::CompositeViewer::setStartTick(__int64 tick)  
Line 355 + 0x1d bytes C++
osg130-osgViewerd.dll!osgViewer::CompositeViewer::realize()  Line 646 + 0x31 
bytes  C++
osg130-osgViewerd.dll!osgViewer::ViewerBase::frame(double simulationTime)  Line 
678 + 0xf bytes C++
osgWidgetsTest.exe!ViewerWidget::paintEvent(QPaintEvent * event)  Line 154 + 
0x46 bytes C++

The first time a paint event is called, the eventqueue is cleaned up (see 
EventQueue::clear()) and the RESIZE event with correct width and height 
unavoidably lost!

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





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


Re: [osg-users] set proper size to window manager at startup

2016-04-15 Thread Gianni Ambrosio
I verified that when the application starts the code falls into the following 
method (osgQt\GraphicsWindowQt.cpp),

void GLWidget::resizeEvent( QResizeEvent* event )

where it seems a resize event is insert into the event queue with proper width 
and height:

_gw->getEventQueue()->windowResize( x(), y(), scaled_width, scaled_height );

but a RESIZE event is not passed to the ResizeHandler. Can anybody see a good 
reason or a bug there?

Regards,
Gianni

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





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


[osg-users] set proper size to window manager at startup

2016-04-15 Thread Gianni Ambrosio
Hi All,
I have a Qt application ad I have to initialize a WindowManager with some 
default width and height like follows:

osg::ref_ptr wm = new osgWidget::WindowManager(view, 
1280.0f, 1024.0f, MASK_2D, osgWidget::WindowManager::WM_USE_RENDERBINS);

When the Qt application starts up then the QWidget containing the OSG view is 
resized properly by the Qt framework but even if I use:

view->addEventHandler(new osgWidget::ResizeHandler(wm, camera));

an osgGA::GUIEventAdapter::RESIZE event is not raised at that point. That 
means, every OSG windows added to the WindowManager are not resized correctly. 
Only when the user interactiverly resizes the window of Qt application, then a 
osgGA::GUIEventAdapter::RESIZE is rised and, falling into 
ResizeHandler::handle() methodm the Window Manager is updated with proper width 
and height.

Now, which is the correct way you see to solve this issue?

Regards,
Gianni

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





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


Re: [osg-users] xrandr version

2015-11-12 Thread Gianni Ambrosio
Hi Robert,
I think is would not easy to find an official documentation of xrandr but I 
foun the option available in v1.1 here:
http://www.x.org/archive/X11R7.5/doc/man/man1/xrandr.1.html#sect5

Moreover I cloned the git repository and verified all XRandR API used in 
"GraphicsWindowX11.cpp" (which AFAIK is the only file that uses XRandR) are 
available with the same signature.

Gianni

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





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


Re: [osg-users] xrandr version

2015-11-12 Thread Gianni Ambrosio

robertosfield wrote:
> 
> Which git repository xrandr?
> 

http://cgit.freedesktop.org/xorg/lib/libXrandr
addressed from here: http://www.x.org/wiki

robertosfield wrote:
> 
> The OSG?
> 

I'm on OSG 3.0.1 but the code related to xrandr, in "GraphicsWindowX11.cpp" 
file, on the OSG trunk is exactly the same.

robertosfield wrote:
> 
> What signatures are you referring to?
> 

The signature of every xrendr API used in "GraphicsWindowX11.cpp" file did not 
change from xrandr 1.1.1 to 1.2 (but I also check the trunk version). There is 
just one difference:

Xrandr.h (v1.2)
XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy, Window window);

Xrandr.h (v1.1.1)
XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy, Drawable draw);

BTW in Xrandr.c (v1.1.1) the signature is:
XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy, Window window)

Maybe Window and Drawable are both integers or so.

Hope this is clearer now.

Gianni

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





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


Re: [osg-users] xrandr version

2015-11-11 Thread Gianni Ambrosio
Hi Robert,
I removed the xrandr version check just for a try.

Some old RedHat and CentOS distributions (at least 5.9) uses an xrandr version 
1.1.1.

I also verified that width, height and refreshRate are correct even with xrandr 
1.1.1.

Regards,
Gianni

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





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


[osg-users] xrandr version

2015-11-11 Thread Gianni Ambrosio
Hi,
I'm trying to get the screen refresh rate from 
GraphicsWindowX11::getScreenSettings(...). Looking at the code I realized the 
point is the xrandr version. In fact supportsRandr() methods require xrandr 
version at least 1.2. But since I found the line:

OSG_NOTICE << "You must build osgViewer with Xrandr 1.2 or higher for 
setScreenSettings support!" << std::endl;

I suspect my xrandr 1.1.1 whould be enough to just read the sceen refresh rate 
(and it works fine indeed if remove the xrandr version check!).
Moreover the supportsRandr() check is used just in two methods that simply read 
the screen settings while in setScreenSettings(...)  it is not used at all.

Now, in the actual code (I verified the OSG trunk), the xrand version check is 
really required?

Regards,
Gianni

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





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


Re: [osg-users] update slave camera with frame scheme ON_DEMAND

2015-08-05 Thread Gianni Ambrosio
Hi All,
it seems I found the problem but not a solution jet.

In my CrossAxes object (that is an osg::Camera) I do:

setUpdateCallback(new AxesCameraUpdateCallback);

and in AxesCameraUpdateCallback::operator() implementation I have:

   transform-setAttitude(view-getCamera()-getViewMatrix().getRotate());

where transform is child of the CrossAxes camera node and parent of the real 
axes graphics (please see previous message for details).
In AxesCameraUpdateCallback I get the rotation from the camera of the view to 
show the global axes correctly oriented wrt the current camera orientation.
Unfortunately, in this case, it seems that the first time frame() is called I 
get an old value from

view-getCamera()-getViewMatrix().getRotate()

It seems that the camera view matrix is updated after my 
AxesCameraUpdateCalback is called. That's wht a second call to frame() fixes 
axes orientation. 

Since to set the desired point of view I call

NodeTrackerManipulator::setTransformation(const osg::Vec3d iEye, const 
osg::Vec3d iCenter, const osg::Vec3d iUp)

Which is the proper modification to do on my code to have a correct behaviour? 
Is there a way to get the correct view matrix in 
AxesCameraUpdateCallback::operator() implementation?

Best regards,
Gianni

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





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


Re: [osg-users] Find out if a node is dirty

2015-08-05 Thread Gianni Ambrosio
Hi Robert,
it there a reason why _boundingSphereComputed is not accessible through a 
public getter?

Regards,
Gianni

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





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


Re: [osg-users] Find out if a node is dirty

2015-08-05 Thread Gianni Ambrosio
Hi Robert,


robertosfield wrote:
 
 What do you need it for?
 

I'm now working to switch my applocation from a continuous frame to an 
ON_DEMAND frame to reduce CPU consumption. Unfotunately even with vsync enabled 
my application takes one cpu core even if nothing changes in the scene. So, for 
the time being I implemented a dirty falg in my scene manager so that the 
viewer can check it and call frame() as needed. Then, looking at that 
_boundingSphereComputed flag I was thinking if it may be useful instead of 
implementing my own dirty flag. I found some setters (i.e. in 
PositionAttitudeTransform) calls dirtyBounds()  which is propagated to parents.
For sure in my specific case (i.e. one viewer and one scene) a dirty flag 
like that would be enough but may be in a more general case (i.e. scene shared 
to more than one Viewer) there must be something stored in each viewer also. I 
thought of a time stamp for example: time of modification to be compared to the 
time stamp of the frame() computed from each viewer. But I don't know if that 
would make sense.

Regards,
Gianni

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





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


Re: [osg-users] update slave camera with frame scheme ON_DEMAND

2015-08-05 Thread Gianni Ambrosio
Thank you Robert for the explanation.

Please don't blame me if I have a couple of questions.

First of all, debugging the updateTraversal() implementation it seems the 
AxesCameraUpdateCallback is called twice: one in

scene-updateSceneGraph(*_updateVisitor);

and the second time in

camera-accept(*_updateVisitor);

I guess this is an expected behavior.

Second, you say The master Camera's value can depend upon values in the scene 
graph. But isn't the scene updated in updateSceneGraph call? While the slave 
cameras are updated in a couple of following for loops? I mean, couldn't the 
main camera view matrix be updated, I agree after the updateSceneGraph() call, 
but before the slave cameras? Or at least move the slave cameras with 
_useMastersSceneData=false after the main camera? Something like:

Code:

if (view-getCameraManipulator())
{
view-setFusionDistance( 
view-getCameraManipulator()-getFusionDistanceMode(),

view-getCameraManipulator()-getFusionDistanceValue() );

view-getCamera()-setViewMatrix( 
view-getCameraManipulator()-getInverseMatrix());
}

 // Do UpdateTraversal for slaves with their own subgraph
 for(unsigned int i=0; iview-getNumSlaves(); ++i)
 {
   osg::View::Slave slave = view-getSlave(i);
   osg::Camera* camera = slave._camera.get();
   if(camera  !slave._useMastersSceneData)
   {
  camera-accept(*_updateVisitor);
   }
 }

view-updateSlaves();




Regards,
Gianni

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





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


Re: [osg-users] update slave camera with frame scheme ON_DEMAND

2015-08-05 Thread Gianni Ambrosio
Hi Robert, I didn't understand your answer.

I use OSG 3.0.1 but I tried with 3.4.0.-rc8 and the behavior is the same. 
Moreover updateTraversal() of CompositeViewer is basically the same for these 
versions.
Anyway we are probably talking of a slightly different scenario: I have a slave 
camera which update callback needs an up to date viewer master camera's view 
matrix. In this case, as you told me, since the master camera matrix is updated 
(with the inverse matrix of the manipulator) after the slave camera update 
callback, then the value is that of the previous frame. I can understand and 
the reason is in CompositeViewer::updateTraversal() because the for loop // Do 
UpdateTraversal for slaves with their own subgraph is done before 
view-getCameraManipulator()-updateCamera(*(view-getCamera()));.
So, to make scenarios like mine working, my suggestion is to move:


Code:

// Do UpdateTraversal for slaves with their own subgraph
for(unsigned int i=0; iview-getNumSlaves(); ++i)
{
osg::View::Slave slave = view-getSlave(i);
osg::Camera* camera = slave._camera.get();
if(camera  !slave._useMastersSceneData)
{
camera-accept(*_updateVisitor);
}
}




after


Code:

if (view-getCameraManipulator())
{
view-setFusionDistance( 
view-getCameraManipulator()-getFusionDistanceMode(),

view-getCameraManipulator()-getFusionDistanceValue() );

view-getCameraManipulator()-updateCamera(*(view-getCamera()));

}




I tried this solution and it works fine.
With this modification the scene remains updated before the main camera, so 
nothing you already told me should be broken.
Moreover the for loop to move down is related to slave cameras with thier own 
subgraph.

Regards,
Gianni[/code]

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





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


Re: [osg-users] update slave camera with frame scheme ON_DEMAND

2015-08-05 Thread Gianni Ambrosio
OK Robert,
no problem, I thought there could be a way to improve the existing OSG code so 
that other users would not struggle like me because slave cameras are updated 
before the master camera. From my point of view the default behavior should 
comply with the common concept that the master gives the rules, then slaves 
depend on the master. So slave cameras may depend on the master camera and not 
vice versa. On this bases the master camera should be updated first, then the 
slaves.
I also had in mind another scenario (think of a rearview mirror of a car) in 
which, in addition to my scenario, the slave camera shares the scene with the 
master camera. I would say the slave camera depends on the master camera and I 
expect the master is updated first so that the slave can use correct master 
camera values.

Anyway, thank you for your time and answers.

Gianni

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





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


Re: [osg-users] some questions about Frame Scheme ON_DEMAND

2015-07-22 Thread Gianni Ambrosio
Hi All,
is there a way to get the osgViewer::View related to a manipulator? I can see a 
us.requestRedraw() but I need to force a requestRedraw() inside a manipulator 
when I'm not in an event handling.

Regards,
Gianni

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





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


Re: [osg-users] some questions about Frame Scheme ON_DEMAND

2015-07-20 Thread Gianni Ambrosio

wernerM wrote:
 Hi Gianni,
 I solved it for me by deriving the viewer class and setting a 
 local variable needsUpdate with any mod of the sceene.
 This works pretty good.
 


OK, so there isn't any way in OSG. I think it would be a nice improvement for 
the OSG code to add the scene modification flag to be handled by 
checkNeedToDoFrame().

I can understand your modification and I thought to implement a class for that 
so it can be injected where needed, it can be more testable and the viewer 
would have less resposibilities.

Regards,
Gianni

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





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


Re: [osg-users] some questions about Frame Scheme ON_DEMAND

2015-07-20 Thread Gianni Ambrosio
Hi All,
can anybody tell me please if there is a way to know if the OSG scene has been 
modified (i.e. node added or removed) so that I can check if 
osgViewer::ViewerBase::frame() must be called in a setRunFrameScheme(ON_DEMAND) 
case?

Regards
Gianni

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





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


Re: [osg-users] some questions about Frame Scheme ON_DEMAND

2015-07-18 Thread Gianni Ambrosio
Which is the relation between view and manipulator? I mean, is a manipulator 
instance supposed to be related to just one view?

Regards,
Gianni

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





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


Re: [osg-users] some questions about Frame Scheme ON_DEMAND

2015-07-17 Thread Gianni Ambrosio

gwaldron wrote:
 
 osgViewer::View inherits from GUIActionAdapter, so you can call 
 requestRedraw() on that directly.
 

I'm inside a NodeTrackerManipulator not in the viewer.

Regards,
Gianni

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





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


[osg-users] some questions about Frame Scheme ON_DEMAND

2015-07-17 Thread Gianni Ambrosio
Hi All,
I was using the default CONTINUOUS Frame Scheme but I got CPU consumption even 
if the application was idle.
I'm developing a Qt application (but my question is not strictly related to 
that).
So, I moved to ON_DEMAND frame scheme.

I use a Qt timer connected to the QWidget::update() slot so that the paint 
event is triggered.

Here in my viewer widget constructor:

connect(timer, SIGNAL(timeout()), this, SLOT(update()));

Then the QPaintEvent handled as follows:

void ViewerWidget::paintEvent(QPaintEvent* iEvent)
{
   if (osgViewer::ViewerBase::CONTINUOUS == getRunFrameScheme() || true == 
checkNeedToDoFrame()) {
  frame();
   }
}

I added a custom NodeTrackerManipulator, derived from the OSG one, to the 
viewer. Mouse interactions work fine because of us.requestRedraw() calls 
implemented on the OSG side of the manipulator.

But I have some cases not working.

1) I implemented some methods to fit the whole 3D scene, to set views along 
X/Y/Z axes, or to switch from perspective to orthographic views. In those cases 
I don't have a GUIActionAdapter to call a requestRedraw() on to. So is there a 
way from the manipulator to get the view?

2) If a node (with geometry) is added to the scene (as child of an existing 
node) the view is not updated. I expected that case was automatically handled. 
How could I solve this issue?

Regards,
Gianni

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





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


[osg-users] resize an osgWidget::Window

2015-06-25 Thread Gianni Ambrosio
Hi All,
is there a way to change width and height (non proportional) of a 
osgWidget::Window?
I tried with resize (w, h) but it does not work, even if I call 
window-update() after resize.

I found the implementation of callbackWindowScale where addScale is used. But 
in that case just one value (height) is passed to the method, so for my 
understanding that's most likely a proportional resizing (scaling, indeed).

Regards,
Gianni

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





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


[osg-users] DEEP_COPY_ALL with node graph

2015-06-25 Thread Gianni Ambrosio
Hi All,
I would like to know if this is an expected behaviour.

I have node A with nodes B and C as children. B is in addition child of C.
I make a copy of A with DEEP_COPY_ALL option but C-copy is not parent of B-copy.

Regards,
Gianni

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





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


Re: [osg-users] GUIEventAdapter getButton() on DRAG

2015-06-18 Thread Gianni Ambrosio
OK, it seems in some cases there is a need to have two states of button pressed 
so there is a getButton() that behaves correctly on PRESSED/RELEASED event 
while on DRAG event the pressed button is returned by getButtonMask() instead.

Gianni

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





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


[osg-users] GUIEventAdapter getButton() on DRAG

2015-06-18 Thread Gianni Ambrosio
Hi All,
is there a reason why osgGA::GUIEventAdapter::getButton() always returns 0 on 
osgGA::GUIEventAdapter::DRAG type event?

Regards,
Gianni

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





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


Re: [osg-users] how to insert a QWidgetImage in a osgWidget::Window?

2015-06-10 Thread Gianni Ambrosio
Hi Julien,
no I would like to show a Qt Widget in an osgWidget::Window.

I found an example that shows a Qt Widget in a HUD (with camera and so on)  but 
in that case I have two problems:
1) global coordinates sent to the Qt widget by 
osgViewer::InteractiveImageHandler are wrong (I debugged the code and coords 
are sent to the Qt widget wrt the 3D viewer widget, so not global like in Qt 
framework are usually handled, at least in my scenario).
2) I would like to drag and resize the widget and osgwidget::Window and that 
can be easily done with: window-attachMoveCallback() and attachScaleCallback().

Regards,
Gianni

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





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


  1   2   3   4   >