Re: [osg-users] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-30 Thread Hartwig Wiesmann
Hi Robert,

I want to come back to my original remark that culling does not work correctly 
with AutoTransforms and ROTATE_TO_SCREEN.

I have modified the example osgautotransform.cpp by adding a new class that 
contains an AutoTransform and a drawable. An object of this class is added to 
the scene (createScene has been extended; basically the shown code replaces the 
original createScene method):


Code:

class AutoScaledBox : public osg::Node
{
public:

AutoScaledBox(void) : m_AutoTransformPtr(nullptr)
{
this->initialize();
}

AutoScaledBox(AutoScaledBox const& autoScaledRectangle, osg::CopyOp 
const& copyOperator=osg::CopyOp::SHALLOW_COPY) : 
osg::Node(autoScaledRectangle,copyOperator), 
m_AutoTransformPtr(autoScaledRectangle.m_AutoTransformPtr)
{
}

META_Node("",AutoScaledBox)

virtual osg::BoundingSphere computeBound(void) const override
{
if (m_AutoTransformPtr)
return m_AutoTransformPtr->computeBound();
else
return osg::BoundingSphere();
}

virtual void traverse(osg::NodeVisitor& nodeVisitor) override
{
if (m_AutoTransformPtr)
m_AutoTransformPtr->accept(nodeVisitor);
}

void setPosition(osg::Vec3 const& position)
{
if (m_AutoTransformPtr)
m_AutoTransformPtr->setPosition(position);
}

protected:
void initialize(void)
{
osg::ShapeDrawable* shapeDrawablePtr(new osg::ShapeDrawable());

shapeDrawablePtr->setShape(new osg::Box(osg::Vec3(),4.0f));

m_AutoTransformPtr = new osg::AutoTransform();
m_AutoTransformPtr->addChild(shapeDrawablePtr);

m_AutoTransformPtr->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
m_AutoTransformPtr->setAutoScaleToScreen(true);
}

private:
osg::ref_ptr m_AutoTransformPtr;
};

osg::Node* createAutoScaledBox(osg::Vec3 const& position)
{
AutoScaledBox* autoScaledRectanglePtr(new AutoScaledBox());


autoScaledRectanglePtr->setPosition(position);
return autoScaledRectanglePtr;
}

osg::Node* createScene()
{
osg::Group* root = new osg::Group;

//int numReps = ;
int numReps = 10;

root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_CAMERA,osgText::Text::XY_PLANE,
 "ROTATE_TO_CAMERA"));

root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_SCREEN,osgText::Text::XY_PLANE,
 "ROTATE_TO_SCREEN"));

root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps,osg::AutoTransform::NO_ROTATION,osgText::Text::XZ_PLANE,
 "NO_ROTATION"));

root->addChild(createAutoScale(osg::Vec3(500.0,500.0,500.0), 25.0, 
"AutoScale with no min, max limits"));
root->addChild(createAutoScale(osg::Vec3(500.0,500.0,300.0), 25.0, 
"AutoScale with minScale = 1, maxScale = 2.0 ", 1, 2.0));
root->addChild(createAutoScale(osg::Vec3(500.0,500.0,700.0), 25.0, 
"AutoScale with minScale = 0.0, maxScale = 5.0 ", 0.0, 5.0));


root->addChild(createAutoScaledBox(osg::Vec3(100.0f,100.0f,100.0f)));

return root;
}




If nothing else is modified you will see an additional small box at 100; 100; 
100.

Now, I additionally set the small feature culling pixel size to a relatively 
large value during the initialisation of the view:

Code:
view->getCamera()->setSmallFeatureCullingPixelSize(200.0f);



Afterwards, all the axis labels disappear (as expected) but the small box is 
still visible! But from my understanding this small box should also be culled.
Zooming in and out let the labels appear and disappear but the box remains 
visible all the time.

Cheers,
Hartwig

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





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


Re: [osg-users] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-30 Thread Robert Osfield
Hi Hartwig,

On 29 March 2018 at 22:51, Hartwig Wiesmann  wrote:
> what I would like to produce is an object that is always oriented towards the 
> user (screen) and has the same size independent of the zoom level. Though the 
> zoom level is limited in a certain range by an additional LOD.
> Therefore, I think that AutoTranslate is the only viable option, or?

You can also implement your own subclasses from
osg::Node/osg::Transform or even osg::AutoTransform.

You can also implement billboard with vertex shaders.

So there are plenty of viable options.

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


Re: [osg-users] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-29 Thread Hartwig Wiesmann
Hi Robert,

what I would like to produce is an object that is always oriented towards the 
user (screen) and has the same size independent of the zoom level. Though the 
zoom level is limited in a certain range by an additional LOD.
Therefore, I think that AutoTranslate is the only viable option, or?

Thank you!

Cheers,
Hartwig

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





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


Re: [osg-users] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-29 Thread Robert Osfield
HI Hatwig,

The code is correct, you can't cull something that you don't have a
valid bounding volume for.  Distabling culling for a particular node
only affect that node and all it's parents, it does affect culling of
the children which can still have their own culling be effective.

If you don't like the default behaviour of AutoTransform w.r.t
bounding volume calculation you can always write your own or subclass
from AutoTransform to specialise it to be compatible with a fixed
bounding volume,

Robert.



On 27 March 2018 at 17:44, Hartwig Wiesmann  wrote:
> Hi Robert,
>
> I was not talking about the cullingActive flag but the method 
> isCullingActive! isCullingActive checks besides the cullingActive flag if the 
> boundary sphere is valid. As long as the boundary sphere is invalid 
> isCullingActive() returns false. This is the problem I reported.
>
>
> Code:
> inline bool isCullingActive() const { return 
> _numChildrenWithCullingDisabled==0 && _cullingActive && getBound().valid(); }
>
>
>
>
> Cheers,
> Hartwig
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=73183#73183
>
>
>
>
>
> ___
> 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] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-28 Thread Robert Osfield
Hi Hartwig,

On 27 March 2018 at 17:44, Hartwig Wiesmann  wrote:
> I was not talking about the cullingActive flag but the method 
> isCullingActive! isCullingActive checks besides the cullingActive flag if the 
> boundary sphere is valid. As long as the boundary sphere is invalid 
> isCullingActive() returns false. This is the problem I reported.

This is by design, you can't cull something that doesn't have a valid
bounding volume as culling tests are based on the bounding volume.

For AutoTransform the bounding volume change per frame, especially so
if it's being scaled to screen space as it's size can grow and shrink,
so in this case leaving it undefined is the one safe thing to do.

As for children of an AutoTransform not being culled, this is
incorrect, the children's culling will be done in their own right,
what happens to the parents will no affect this.

As a general note, AutoTransform is not something I would recommend
using for large numbers of objects in your scene as it not only
presents issues with cullng itself but also forces the cull traversal
to transform the view frustum into the children coordinate frame, this
involves pushing/popping view frustum state on and off a stack as
well.

I don't know the specifics of your scene graph or the particular
performance issues you are trying to address, but it may well be that
pushing the task of rotating/scaling to a vertex or geometry shader
might be the best way to refactor your scene graph for best
performance.

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


Re: [osg-users] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-27 Thread Hartwig Wiesmann
Hi Robert,

I was not talking about the cullingActive flag but the method isCullingActive! 
isCullingActive checks besides the cullingActive flag if the boundary sphere is 
valid. As long as the boundary sphere is invalid isCullingActive() returns 
false. This is the problem I reported.


Code:
inline bool isCullingActive() const { return _numChildrenWithCullingDisabled==0 
&& _cullingActive && getBound().valid(); }




Cheers,
Hartwig

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





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


Re: [osg-users] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-27 Thread Robert Osfield
Hi Hartwig,

CullingActive flag is only effective for the Node that you set it for
and all it's parents, it doesn't disable culling for the children of
the node with CullingActive set.

Robert.

On 26 March 2018 at 22:28, Hartwig Wiesmann  wrote:
> Hi,
>
> I found a very old article covering this issue: 
> https://www.mail-archive.com/osg-users@lists.openscenegraph.org/msg15948.html.
>  In the meantime it seems to be that proposal (2) has been implemented and 
> the AutoTransform's computeBound() method returns an invalid bounding sphere 
> during the first cull traversal. Nevertheless, when checking in the example 
> osgautotransform.cpp the bounding spheres (of the text messages) remain 
> invalid. To check this I have added an update callback to the AutoTransforms 
> that only checks the validity of the bounding sphere.
>
> Now, if the bounding sphere remains invalid culling of the AutoTransform's 
> children will not be correctly performed because the AutoTransform's 
> isCullingActive method will always return false (bounding sphere is invalid).
>
> To solve this issue I was thinking to add a ComputeBoundingSphere callback or 
> an update callback to the AutoTransform. But this is not a good solution 
> because in this case I have to calculate always a new bounding sphere as I do 
> not have access to the node's "_boundingSphereComputed" flag.
>
> Another solution is to patch the node's getBound() method that will set the 
> flag "_boundingSphereComputed" only to true if a valid "_boundingSphere" 
> exists. This sounds reasonable in any case:
>
> Code:
> inline const BoundingSphere& getBound() const
> {
> if(!_boundingSphereComputed)
> {
> _boundingSphere = _initialBound;
> if (_computeBoundCallback.valid())
> 
> _boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
> else
> _boundingSphere.expandBy(computeBound());
>
> _boundingSphereComputed = _boundingSphere.valid();
> }
> return _boundingSphere;
> }
>
>
>
> But I do not know if this breaks anything.
>
> Is there any other method to get a valid bounding sphere for the 
> AutoTransform without sacrificing performance?
>
> Thank you!
>
> Cheers,
> Hartwig
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=73174#73174
>
>
>
>
>
> ___
> 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] AutoTransform, ROTATE_TO_SCREEN and small feature culling

2018-03-26 Thread Hartwig Wiesmann
Hi,

I found a very old article covering this issue: 
https://www.mail-archive.com/osg-users@lists.openscenegraph.org/msg15948.html. 
In the meantime it seems to be that proposal (2) has been implemented and the 
AutoTransform's computeBound() method returns an invalid bounding sphere during 
the first cull traversal. Nevertheless, when checking in the example 
osgautotransform.cpp the bounding spheres (of the text messages) remain 
invalid. To check this I have added an update callback to the AutoTransforms 
that only checks the validity of the bounding sphere.

Now, if the bounding sphere remains invalid culling of the AutoTransform's 
children will not be correctly performed because the AutoTransform's 
isCullingActive method will always return false (bounding sphere is invalid).

To solve this issue I was thinking to add a ComputeBoundingSphere callback or 
an update callback to the AutoTransform. But this is not a good solution 
because in this case I have to calculate always a new bounding sphere as I do 
not have access to the node's "_boundingSphereComputed" flag.

Another solution is to patch the node's getBound() method that will set the 
flag "_boundingSphereComputed" only to true if a valid "_boundingSphere" 
exists. This sounds reasonable in any case:

Code:
inline const BoundingSphere& getBound() const
{
if(!_boundingSphereComputed)
{
_boundingSphere = _initialBound;
if (_computeBoundCallback.valid())

_boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingSphere.expandBy(computeBound());

_boundingSphereComputed = _boundingSphere.valid();
}
return _boundingSphere;
}



But I do not know if this breaks anything.

Is there any other method to get a valid bounding sphere for the AutoTransform 
without sacrificing performance?

Thank you!

Cheers,
Hartwig

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





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