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 Sebastian Messerschmidt


There you go:

The example without vertex sharing.





Am 9/28/2016 um 4:57 PM schrieb 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
Movie is working ;)  But if it is giving you an assertion in debug and 
works in release mode it simply means you're using undefined behavior. 
You should never rely on something like this.


So, do you think it would be possible to implement the same behaviour 
with textures?
Not directly. If you really need to tag individual triangles it isn't 
doable with a simple texture. In this case my next approach actually 
would include using vertex colors and some shader to draw flat colored 
triangles based on the provoking vertex.
The problem that makes this non-trivial is simply due to the vertex 
sharing. If you duplicate the vertices (or at least some of them) it 
is solveable without fancy tricks in 5 minutes, but depending on the 
number of triangles in your road this might not be an option.

So how many triangles will be in your road?

Cheers
Sebastian


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 



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



#include 
#include 
#include 
#include 

#include 
#include 

#include 
#include 
#include 
#include 

#include 
#include 

//#include 

#include 
const unsigned int DIMENSION = 64;

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

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());
doUserOperationsColor(result);
}
}
}

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(osg::Vec4d(1, 1, 1, 1), tc);
tex->getImage(0)->dirty();
tex->dirtyTextureObject();
}

}


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]] = osg::Vec4(1, 0, 0, 1);
color[result.indexList[1]] = osg::Vec4(1, 0, 0, 1);
color[result.indexList[2]] = osg::Vec4(1, 0, 0, 1);
geom->dirtyDisplayList();
color.dirty();




}
protected:
osg::ref_ptr _selector;
unsigned int currentPrimitiveSetIndex;
osg::ref_ptr _root;

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

2016-09-28 Thread Sebastian Messerschmidt



Am 9/28/2016 um 4:57 PM schrieb 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
Movie is working ;)  But if it is giving you an assertion in debug and 
works in release mode it simply means you're using undefined behavior. 
You should never rely on something like this.


So, do you think it would be possible to implement the same behaviour with 
textures?
Not directly. If you really need to tag individual triangles it isn't 
doable with a simple texture. In this case my next approach actually 
would include using vertex colors and some shader to draw flat colored 
triangles based on the provoking vertex.
The problem that makes this non-trivial is simply due to the vertex 
sharing. If you duplicate the vertices (or at least some of them) it is 
solveable without fancy tricks in 5 minutes, but depending on the number 
of triangles in your road this might not be an option.

So how many triangles will be in your road?

Cheers
Sebastian


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


___
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 Sebastian Messerschmidt


Just pointing out, that you might have been lucky:
Your example is crashing on my machine, due to the empty primitive-sets 
;) There isn't even picking involved.



Hi Gianni.

Hi Sebastian,
in attachment you can find a movie of what I implemented with primitive sets. 
That's exactly what I need.
The "road" is initially gray. Then the user choose a color (pushing in my 
example 1,2,3 or 4 key) and picking the road surface triangles are coloured with the 
current color.

Since you said what I implemented with primitive sets is not the right way to do, then 
I'm trying to change my mind using the approach you suggested (i.e. textures) to reach 
exactly the same behaviour. In this case I could use a "monochromatic" image 
(to mimic the behaviour of my example) or a nice texture loaded from file. A nice texture 
anyway is not a must.
I just think that it is rather complicated* and not a very scalable 
solution in my eyes . Of course you can go your way. But it seemed, 
that you somehow had to rely on very specific order of primitive sets 
etc. That is why I presented some ideas how to tackle it differently 
and maybe less convoluted.  I simply wouldn't have preferred this 
solution.



In attachment you can find also the example code I run to record the movie.

Thanks, so basically that is what you meant when you said "monochromatic".


Cheers
Sebastian


*complicated because you're happily jumping between the primitive-sets 
on something that looks like a bold assumption to me. Maybe I'm 
overlooking something.

Hope this helps,
Gianni

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





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




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


___
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 Sebastian Messerschmidt


Hi Gianni.

Hi Sebastian,
in attachment you can find a movie of what I implemented with primitive sets. 
That's exactly what I need.
The "road" is initially gray. Then the user choose a color (pushing in my 
example 1,2,3 or 4 key) and picking the road surface triangles are coloured with the 
current color.

Since you said what I implemented with primitive sets is not the right way to do, then 
I'm trying to change my mind using the approach you suggested (i.e. textures) to reach 
exactly the same behaviour. In this case I could use a "monochromatic" image 
(to mimic the behaviour of my example) or a nice texture loaded from file. A nice texture 
anyway is not a must.
I just think that it is rather complicated* and not a very scalable 
solution in my eyes . Of course you can go your way. But it seemed, that 
you somehow had to rely on very specific order of primitive sets etc. 
That is why I presented some ideas how to tackle it differently and 
maybe less convoluted.  I simply wouldn't have preferred this solution.




In attachment you can find also the example code I run to record the movie.

Thanks, so basically that is what you meant when you said "monochromatic".


Cheers
Sebastian


*complicated because you're happily jumping between the primitive-sets 
on something that looks like a bold assumption to me. Maybe I'm 
overlooking something.


Hope this helps,
Gianni

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





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


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


Re: [osg-users] 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] 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 Sebastian Messerschmidt

Hi Gianni,

attached you find a quick example using a simple texture to let the user 
"draw" different colors at different positions.
Basically it modifies the image data and samples it back when drawing. 
I've created a mesh, but basically this would work with a simple quad 
too. Is this maybe closer to what you want?


Cheers
Sebastian


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



#include 
#include 
#include 
#include 

#include 
#include 

#include 
#include 
#include 
#include 

#include 
#include 

//#include 

#include 
const unsigned int DIMENSION = 64;

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler(osg::ref_ptr group, osg::Image* image)
: _selector(0), currentPrimitiveSetIndex(0), _root(group), 
_image(image)
{}

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);
}
}
}

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(osg::Vec4d(1, 1, 1, 1), tc);
tex->getImage(0)->dirty();
tex->dirtyTextureObject();
}

}
protected:
osg::ref_ptr _selector;
unsigned int currentPrimitiveSetIndex;
osg::ref_ptr _root;
osg::ref_ptr _image;
};

osg::Vec3Array* buildVertices(unsigned int num_rows) 
{
//create a grid 
osg::Vec3Array* v = new osg::Vec3Array(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::Vec3(i, j, 0);
}
}
return v;
}
osg::Vec2Array* buildTexCoords(unsigned int num_rows)
{
//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;
}

osg::DrawElementsUInt* buildElements(unsigned int num_rows)
{
osg::DrawElementsUInt* element = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES);

for (unsigned int i = 0; i < num_rows - 1; ++i)
{
for (unsigned int j = 0; j < num_rows - 1; j++)
{
unsigned int offset = i * num_rows + j;
(*element).push_back(offset + 0);
(*element).push_back(offset + 1);
(*element).push_back(offset + num_rows);
(*element).push_back(offset + 1);
(*element).push_back(offset + num_rows + 1);
(*element).push_back(offset + 

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 Sebastian Messerschmidt

Hi Gianni,

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.
Basically this is something I wouldn't approach by using 
color-materials. I'd use multiple textures per geometry-element and sort 
of blend them based on a per-face value. Do you need to place the curbs 
etc. also dynamically?
If you only need to add puddles etc. you might be better of using 
decals, or even drawing on top of the original road-geometry.
The problem with the multiple primitive sets is, that you will have to 
recompile the data every time some triangle is changed.
If your geometry doesn't have to look nice, you indeed can simply use 
flat shading and set the vertex colors, but one problem with this is 
that with shared vertices you will affect neighboring triangles as well. 
Are there any restrictions to how the road is represented?


Another approach might be to use a geometry shader and determine the 
color of your triangle there (I believe this would work for shared 
indices as well). The determination of the color could be based on the 
vertices texture coordinate which point into an image which holds the 
"color" information. This way you wouldn't need to modify the geometry 
at all, but upload a modified texture if needed. I can try to make a 
minimal example, if you give me some time (I can do this after work).


Cheers
Sebastian


Cheers
Sebastian

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


___
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 Trajce Nikolov NICK
Gianni,

you should call geometry->dirtyDisplayList(); at the end of your move
function ... Not sure about the rest of the logic of your code now though
  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 :-) )

void move(osg::Geometry* geometry, unsigned int sourcePrimitiveSetIndex,
unsigned int elementIndex, unsigned int destinationPrimitiveIndex)
{
osg::DrawElementsUInt* sourcePrimitiveSet =
dynamic_cast(geometry->getPrimitiveSet(sourcePrimitiveSetIndex));
osg::DrawElementsUInt* destinationPrimitiveSet =
dynamic_cast(geometry->getPrimitiveSet(destinationPrimitiveIndex));
destinationPrimitiveSet->push_back(sourcePrimitiveSet->at(elementIndex *
3));
destinationPrimitiveSet->push_back(sourcePrimitiveSet->at(elementIndex * 3
+ 1));
destinationPrimitiveSet->push_back(sourcePrimitiveSet->at(elementIndex * 3
+ 2));
sourcePrimitiveSet->erase(sourcePrimitiveSet->begin() + elementIndex * 3);
sourcePrimitiveSet->erase(sourcePrimitiveSet->begin() + elementIndex * 3);
sourcePrimitiveSet->erase(sourcePrimitiveSet->begin() + elementIndex * 3);

sourcePrimitiveSet->dirty();
destinationPrimitiveSet->dirty();
geometry->dirtyDisplayList();
}



On Mon, Sep 26, 2016 at 4:03 PM, Sebastian Messerschmidt <
sebastian.messerschm...@gmx.de> wrote:

> Hi Gianni,
>
> A very simplistic solution using a outline triangle:
>
>
> 
> #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(osg::ref_ptr group)
> : _selector(0), currentPrimitiveSetIndex(0), _root(group)
> {}
>
> 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);
> }
> }
> }
>
> return false;
> }
>
> virtual void doUserOperations(osgUtil::Line
> SegmentIntersector::Intersection& result)
> {
> osg::Geometry* geom = dynamic_cast(r
> esult.drawable.get());
>
> //first solution: add some outline
> if (_root->getNumChildren())
> {
> _root->removeChildren(0, _root->getNumChildren());
> }
> else if (result.indexList.size() > 2)
> {
> osg::DrawElementsUInt* elements = new
> osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES);
> osg::Vec3Array* vertices = new osg::Vec3Array;
> osg::Vec4Array* colors = new osg::Vec4Array;
> colors->push_back(osg::Vec4(1, 0, 0, 1));
> const osg::Vec3Array& org_vertices = dynamic_cast osg::Vec3Array&>(*geom->getVertexArray());
>
> vertices->push_back(org_vertices[result.indexList[0]]);
> vertices->push_back(org_vertices[result.indexList[1]]);
> vertices->push_back(org_vertices[result.indexList[2]]);
> (*elements).push_back(0);
> (*elements).push_back(1);
> (*elements).push_back(2);
>
> osg::Geode* geode = new osg::Geode;
> osg::Geometry* geometry = new osg::Geometry;
> geode->addDrawable(geometry);
> geometry->setVertexArray(vertices);
> geometry->setColorArray(colors, osg::Array::BIND_OVERALL);
> geometry->addPrimitiveSet(elements);
> geometry->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(
> osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE));
> geometry->getOrCreateStateSet()->setAttribute(new osg::LineWidth(3.0));
> _root->addChild(geode);
> }
>
>
> }
>
> protected:
> osg::ref_ptr _selector;
> unsigned int currentPrimitiveSetIndex;
> osg::ref_ptr _root;
> };
>
> osg::Vec3Array* 

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

2016-09-26 Thread Sebastian Messerschmidt

Hi Gianni,

A very simplistic solution using a outline triangle:



#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(osg::ref_ptr group)
: _selector(0), currentPrimitiveSetIndex(0), _root(group)
{}

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);
}
}
}

return false;
}

virtual void 
doUserOperations(osgUtil::LineSegmentIntersector::Intersection& result)

{
osg::Geometry* geom = 
dynamic_cast(result.drawable.get());


//first solution: add some outline
if (_root->getNumChildren())
{
_root->removeChildren(0, _root->getNumChildren());
}
else if (result.indexList.size() > 2)
{
osg::DrawElementsUInt* elements = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES);

osg::Vec3Array* vertices = new osg::Vec3Array;
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1, 0, 0, 1));
const osg::Vec3Array& org_vertices = dynamic_castosg::Vec3Array&>(*geom->getVertexArray());


vertices->push_back(org_vertices[result.indexList[0]]);
vertices->push_back(org_vertices[result.indexList[1]]);
vertices->push_back(org_vertices[result.indexList[2]]);
(*elements).push_back(0);
(*elements).push_back(1);
(*elements).push_back(2);

osg::Geode* geode = new osg::Geode;
osg::Geometry* geometry = new osg::Geometry;
geode->addDrawable(geometry);
geometry->setVertexArray(vertices);
geometry->setColorArray(colors, osg::Array::BIND_OVERALL);
geometry->addPrimitiveSet(elements);
geometry->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(
osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE));

geometry->getOrCreateStateSet()->setAttribute(new osg::LineWidth(3.0));
_root->addChild(geode);
}


}

protected:
osg::ref_ptr _selector;
unsigned int currentPrimitiveSetIndex;
osg::ref_ptr _root;
};

osg::Vec3Array* buildVertices() {
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(0, 0, 0));
vertices->push_back(osg::Vec3(10, 0, 0));
vertices->push_back(osg::Vec3(10, 10, 0));
vertices->push_back(osg::Vec3(0, 10, 0));
vertices->push_back(osg::Vec3(20, 0, 0));
vertices->push_back(osg::Vec3(20, 10, 0));
vertices->push_back(osg::Vec3(20, 20, 0));
vertices->push_back(osg::Vec3(10, 20, 0));
vertices->push_back(osg::Vec3(0, 20, 0));
return vertices;
}

osg::DrawElementsUInt* buildElements()
{
osg::DrawElementsUInt* element = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES);

element->push_back(0);
element->push_back(1);
element->push_back(2);
element->push_back(0);
element->push_back(2);
element->push_back(3);
//
element->push_back(1);
element->push_back(4);
element->push_back(5);
element->push_back(1);
element->push_back(5);
element->push_back(2);
//
element->push_back(2);
element->push_back(5);
element->push_back(6);
element->push_back(2);
element->push_back(6);
element->push_back(7);
//
element->push_back(3);
element->push_back(2);
element->push_back(7);
element->push_back(3);
element->push_back(7);
element->push_back(8);

return element;
}



osg::Vec4Array* buildColors() 

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

2016-09-26 Thread Sebastian Messerschmidt

Hi Gianni,

One question,
why should I use a "vertex" shader/attribute when I need to colour a triangle 
uniformly?

Long story short: There is no such thing as per-primitive colors.

Long story long:
In order to color your primitives you need to assign a color to each 
vertex. That is how modern GPU-pipelines work. Another way to tackle 
your problem is to simply assign a different color-array holding 
per-vertex colors that is updated with your selections.

I'll try to create a small example for you to make things less foggy.

Cheers
Sebastian


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


___
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] different materials for a geometry and highlight

2016-09-26 Thread Trajce Nikolov NICK
Hi Gianni,

I have stopped looking at the issue since Sebastian's suggestion is really
better (more modern approach and really easier to implement and maintain
once you get a handle of it). If you still want to continue your way I will
have a look later today if I can spot anything .. Will ping you

On Mon, Sep 26, 2016 at 11:33 AM, Gianni Ambrosio 
wrote:

> 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
>



-- 
trajce nikolov nick
___
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 Sebastian Messerschmidt



Am 9/22/2016 um 12:23 PM schrieb 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.
Maybe your questions was a bit to vague and you took a shot in the dark 
with your primitive set attempt.

You were asking for material not for color, so I assumed something else.


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.
The minimalistic way would be to simply add uniform face colors (vertex 
color) for each face in your geometry and change the appropriate face in 
the buffer. So you have a buffer with n-entries where n is the number of 
faces your primitive set creates.
As you are using indexed vertices you simply need to find out which face 
is affected by the picked indices and modify those color entries.
I'd like to help you here with some example, but I'm chasing a project 
deadline right now. The only advice I can give is to start with a 
minimal example, modifying the colors without picking to understand what 
is going on and then to integrate picking and interaction.



Cheers
Sebastian


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


___
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 Sebastian Messerschmidt

Hi Gianni,




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

So basically you are raping the primitive sets to color the primitive?
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.


just my 2 cents
Cheers
Sebastian


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





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


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


Re: [osg-users] 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 Trajce Nikolov NICK
Hi Gianni,

I am having the same results as in the video and I thought that is what is
expected - I thought your main problem was updating the selection area with
colors. Let me see if I can spot something else in your code ... I am doing
this in breaks :-)

On Wed, Sep 21, 2016 at 8:48 AM, Gianni Ambrosio 
wrote:

> Sorry the avi extension is not allowed. Here is the movie.
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68678#68678
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
trajce nikolov nick
___
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 Trajce Nikolov NICK
Hi Gianni,

I give it a shot. Your code actually works. Only one little line to add
in doUserOperations - you should dirty the vertex buffer object

selVertices->dirty();
selVertices->getBufferObject()->dirty();  <--- this is the thing
 _selector->dirtyBound();

Cheers!
Nick


On Tue, Sep 20, 2016 at 4:18 PM, Gianni Ambrosio 
wrote:

>
> 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
>



-- 
trajce nikolov nick
___
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 Trajce Nikolov NICK
Hi Gianni,

if you make Qt free example I can have a look

On Tue, Sep 20, 2016 at 12:33 PM, Gianni Ambrosio 
wrote:

> 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
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
trajce nikolov nick
___
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] 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 Sebastian Messerschmidt

Hi Gianni,

I browsed the LineSegmentIntersector code and it seems, the intersector 
is using a triangleFunctor to traverse your primitive sets as triangles 
anyways. So the Ifnromation
So basically you cannot find out which primitive set was affected 
without reverse-engineering which primitive sets the triangle originated 
from.


One easy way would be to use multiple drawables (I think you could still 
share the vertex data) or to specialize the intersector to traverse per 
primitive set.


Cheers

Sebastian


Am 9/19/2016 um 10:50 AM schrieb Sebastian Messerschmidt:

Hi Gianni,

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?
I might be wrong, but I think the intersector.primitiveIndex might 
yield the number you are looking for

Also be sure to handle all intersections returned.

Cheers
Sebastian


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 



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


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


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

2016-09-19 Thread Sebastian Messerschmidt

Hi Gianni,

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?
I might be wrong, but I think the intersector.primitiveIndex might yield 
the number you are looking for

Also be sure to handle all intersections returned.

Cheers
Sebastian


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


___
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