1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version.  The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #include <osgVolume/VolumeTechnique>
15 #include <osgVolume/VolumeTile>
16 
17 using namespace osgVolume;
18 
VolumeTechnique()19 VolumeTechnique::VolumeTechnique():
20     _volumeTile(0)
21 {
22     setThreadSafeRefUnref(true);
23 }
24 
VolumeTechnique(const VolumeTechnique & rhs,const osg::CopyOp & copyop)25 VolumeTechnique::VolumeTechnique(const VolumeTechnique& rhs,const osg::CopyOp& copyop):
26     osg::Object(rhs,copyop),
27     _volumeTile(0)
28 {
29 }
30 
~VolumeTechnique()31 VolumeTechnique::~VolumeTechnique()
32 {
33 }
34 
init()35 void VolumeTechnique::init()
36 {
37     OSG_NOTICE<<className()<<"::initialize(..) not implementated yet"<<std::endl;
38 }
39 
update(osgUtil::UpdateVisitor * uv)40 void VolumeTechnique::update(osgUtil::UpdateVisitor* uv)
41 {
42     OSG_NOTICE<<className()<<"::update(..) not implementated yet"<<std::endl;
43     if (_volumeTile) _volumeTile->osg::Group::traverse(*uv);
44 }
45 
cull(osgUtil::CullVisitor * cv)46 void VolumeTechnique::cull(osgUtil::CullVisitor* cv)
47 {
48     OSG_NOTICE<<className()<<"::cull(..) not implementated yet"<<std::endl;
49     if (_volumeTile) _volumeTile->osg::Group::traverse(*cv);
50 }
51 
cleanSceneGraph()52 void VolumeTechnique::cleanSceneGraph()
53 {
54     OSG_NOTICE<<className()<<"::cleanSceneGraph(..) not implementated yet"<<std::endl;
55 }
56 
traverse(osg::NodeVisitor & nv)57 void VolumeTechnique::traverse(osg::NodeVisitor& nv)
58 {
59     if (!_volumeTile) return;
60 
61     // if app traversal update the frame count.
62     if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
63     {
64         if (_volumeTile->getDirty()) _volumeTile->init();
65 
66         osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv);
67         if (uv)
68         {
69             update(uv);
70             return;
71         }
72 
73     }
74     else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
75     {
76         osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
77         if (cv)
78         {
79             cull(cv);
80             return;
81         }
82     }
83 
84     if (_volumeTile->getDirty()) _volumeTile->init();
85 
86     // otherwise fallback to the Group::traverse()
87     _volumeTile->osg::Group::traverse(nv);
88 }
89 
isMoving(osgUtil::CullVisitor * cv)90 bool VolumeTechnique::isMoving(osgUtil::CullVisitor* cv)
91 {
92     bool moving = false;
93 
94     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
95 
96     ModelViewMatrixMap::iterator itr = _modelViewMatrixMap.find(cv->getIdentifier());
97     if (itr!=_modelViewMatrixMap.end())
98     {
99         osg::Matrix newModelViewMatrix = *(cv->getModelViewMatrix());
100         osg::Matrix& previousModelViewMatrix = itr->second;
101         moving = (newModelViewMatrix != previousModelViewMatrix);
102 
103         previousModelViewMatrix = newModelViewMatrix;
104     }
105     else
106     {
107         _modelViewMatrixMap[cv->getIdentifier()] = *(cv->getModelViewMatrix());
108     }
109     return moving;
110 }
111