MEPP2 Project
DataVisitor.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <osg/Geode>
14 #include <osg/NodeVisitor>
15 
16 #include <iostream>
17 
20 
21 namespace FEVV {
22 
23 class BaseViewerOSG;
24 
25 class DataVisitor : public osg::NodeVisitor
26 {
27 public:
29  typedef std::vector< Data > Output;
30 
31 public:
33  : NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), current_level(0),
34  exportVector(new Output()), viewer(_viewer)
35  {
36  // add for time mode - for geodes with setNodeMask(0x0) - MT 14/02/18
37 
38  // doc :
39  // http://podsvirov.github.io/osg/reference/openscenegraph/a00553.html#a99be1e526672165ae46af189ed7f472c
40  //
41  // void osg::NodeVisitor::setNodeMaskOverride ( Node::NodeMask mask )
42  // - Set the NodeMaskOverride mask.
43  // - Used in validNodeMask() to determine whether to operate on a node or
44  // its subgraph, by OR'ing NodeVisitor::_nodeMaskOverride with the Node's
45  // own Node::_nodeMask.
46  // Typically used to force on nodes which may have been switched off by
47  // their own Node::_nodeMask.
48  //
49  // void osg::NodeVisitor::setTraversalMask ( Node::NodeMask mask )
50  // - Set the TraversalMask of this NodeVisitor.
51  // - The TraversalMask is used by the NodeVisitor::validNodeMask() method
52  // to determine whether to operate on a node and its subgraph.
53  // validNodeMask() is called automatically in the Node::accept() method
54  // before any call to NodeVisitor::apply(), apply() is only ever called
55  // if validNodeMask returns true. Note, if NodeVisitor::_traversalMask
56  // is 0 then all operations will be switched off for all nodes. Whereas
57  // setting both _traversalMask and _nodeMaskOverride to 0xffffffff will
58  // allow a visitor to work on all nodes regardless of their own
59  // Node::_nodeMask state.
60 
61  setNodeMaskOverride(0xffffffff); // simply works with that one
62  // setTraversalMask(0xffffffff);
63  }
64 
65  virtual ~DataVisitor()
66  {
67  exportVector->clear();
68  delete exportVector;
69  }
70 
71  virtual void apply(osg::Node &_node)
72  {
73  // std::string name = "";
74  // for( unsigned ii = current_level; ii > 0; --ii )
75  // {
76  // name += '\t';
77  // }
78  // name += _node.className();
79  // name += ": ";
80  // name += _node.getName();
81  // exportVector.push_back( StringNodePair(name, &_node) );
82 
84  if((_node.getName().size() > 0) &&
85  ((_node.getName() == "Gizmo") || (_node.getName() == "UnitGrid") ||
86  (_node.getName() == "Hud") ||
87  (_node.getName().compare(0, 7, "Dragger") == 0)))
88  {
89  return;
90  }
91 
93  result.node = &_node;
94  result.name = _node.getName();
95  result.type = Helpers::DataType::GROUP;
96  result.position = current_level;
97  result.viewer = viewer;
98  exportVector->push_back(result);
99 
100  // std::cout << name << std::endl;
101  ++current_level;
102  traverse(_node);
103  --current_level;
104  }
105 
106  virtual void apply(osg::Geode &_geode)
107  {
108  // std::string name = "";
109  // for( unsigned ii = current_level; ii > 0; --ii )
110  // {
111  // name += '\t';
112  // }
113  // name += _geode.className();
114  // name += ": ";
115  // name += _geode.getName();
116  // exportVector.push_back( StringNodePair(name, &_geode) );
117 
119  result.node = &_geode;
120  result.name = _geode.getName();
121  result.type = Helpers::DataType::MODEL;
122  result.position = current_level;
123  result.viewer = viewer;
124  exportVector->push_back(result);
125 
126  // std::cout << name << std::endl;
127  }
128 
130 
131  void reset() { exportVector->clear(); }
132 
133 private:
134  unsigned int current_level;
137 };
138 
139 } // namespace FEVV
FEVV::DataVisitor
Definition: DataVisitor.h:26
FEVV::DataVisitor::exportResults
Output * exportResults()
Definition: DataVisitor.h:129
FEVV::DataVisitor::viewer
BaseViewerOSG * viewer
Definition: DataVisitor.h:136
BaseViewerOSG.h
FEVV::DataVisitor::Output
std::vector< Data > Output
Definition: DataVisitor.h:29
FEVV::Helpers::Model
Definition: DataStructures.h:29
FEVV::Helpers::Model::position
unsigned int position
Definition: DataStructures.h:33
FEVV::DataVisitor::~DataVisitor
virtual ~DataVisitor()
Definition: DataVisitor.h:65
FEVV::BaseViewerOSG
Definition: BaseViewerOSG.h:47
DataStructures.h
FEVV::DataVisitor::Data
Helpers::Model< osg::Node > Data
Definition: DataVisitor.h:28
FEVV::DataVisitor::DataVisitor
DataVisitor(FEVV::BaseViewerOSG *_viewer)
Definition: DataVisitor.h:32
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Helpers::Model::type
DataType type
Definition: DataStructures.h:32
FEVV::Helpers::Model::name
std::string name
Definition: DataStructures.h:31
FEVV::DataVisitor::apply
virtual void apply(osg::Geode &_geode)
Definition: DataVisitor.h:106
FEVV::DataVisitor::current_level
unsigned int current_level
Definition: DataVisitor.h:134
FEVV::DataVisitor::apply
virtual void apply(osg::Node &_node)
Definition: DataVisitor.h:71
FEVV::Helpers::Model::node
NodeType * node
Definition: DataStructures.h:30
FEVV::DataVisitor::exportVector
Output * exportVector
Definition: DataVisitor.h:135
FEVV::DataVisitor::reset
void reset()
Definition: DataVisitor.h:131
FEVV::Helpers::Model::viewer
BaseViewerOSG * viewer
Definition: DataStructures.h:34