node.h
Go to the documentation of this file.
1 //
2 // node.h
3 // gepetto-viewer
4 //
5 // Created by Justin Carpentier, Mathieu Geisert in November 2014.
6 // Copyright (c) 2014 LAAS-CNRS. All rights reserved.
7 //
8 
9 #ifndef GEPETTO_VIEWER_NODE_HH
10 #define GEPETTO_VIEWER_NODE_HH
11 
12 #include <iostream>
13 #include <gepetto/viewer/fwd.h>
17 
18 namespace gepetto {
19 namespace viewer {
20 
21  enum {
23  NodeBit = 0x2
24  };
25 
27  class Node : public Properties
28  {
29  private:
30  friend struct NodeTest;
31 
32  std::string id_name_; // automoatic id generated by the program
33  bool dirty_;
34 
36  osg::MatrixTransformRefPtr transform_ptr_;
38  osg::Matrixf Ms_;
40 
43  osg::GroupRefPtr switch_node_ptr_;
44  WireFrameMode selected_wireframe_;
45  std::vector< ::osg::GroupRefPtr > wireframe_modes_;
46 
47  osg::GroupRefPtr hl_switch_node_ptr_;
48  std::size_t selected_highlight_;
49  bool highlight_enabled_;
50  std::vector< ::osg::GroupRefPtr > highlight_nodes_;
51 
52  VisibilityMode visibilityMode_;
53  LightingMode lightingMode_;
54 
56  void init ();
57 
58  void updateTransform ();
59 
60  ::osg::Group* setupHighlightState (unsigned int state);
61 
62  protected:
64  ::osg::GeodeRefPtr landmark_geode_ptr_;
65 
67  ::osg::GeodeRefPtr geode_ptr_;
69  float alpha_;
70 
74  Node (const std::string& name);
75 
77  Node (const Node& other);
78 
82  ::osg::GroupRefPtr asQueue () const
83  {
84  return transform_ptr_;
85  }
86 
87  void setID (const std::string& id_name)
88  {
89  id_name_ = id_name;
90  switch_node_ptr_->setName (id_name_);
91  }
92 
93  void setTransparentRenderingBin (bool transparent = true,
94  osg::StateSet* ss = NULL);
95 
96  public:
98 
103  const Configuration& getGlobalTransform() const;
104 
108  std::string getID () const
109  {
110  return id_name_;
111  }
112 
113  bool isDirty () const
114  {
115  return dirty_;
116  }
117 
118  void setDirty (bool dirty=true)
119  {
120  dirty_ = dirty;
121  }
122 
125  inline void applyConfiguration (const osgVector3 & position, const osgQuat & quat)
126  {
127  applyConfiguration (Configuration(position, quat));
128  }
129 
132  void applyConfiguration (const Configuration & cfg) { M_.set(cfg); }
133 
136  void setStaticTransform (const osgVector3 & position, const osgQuat & quat);
137 
140  osgQuat getStaticRotation() const;
141 
145 
150  virtual void setVisibilityMode (const VisibilityMode& visibility_state);
151 
152  virtual const VisibilityMode& getVisibilityMode () const
153  { return visibilityMode_; }
154 
159  virtual void setLightingMode (const LightingMode& lighting_state);
160 
161  virtual LightingMode getLightingMode () const;
162 
167  virtual void setWireFrameMode (const WireFrameMode& wireframe_state);
168 
169  virtual const WireFrameMode& getWireFrameMode () const
170  {
171  return selected_wireframe_;
172  }
173 
175  void setScale (float scale) { setScale(osgVector3(scale,scale,scale)); }
176 
178  void setScale (const osgVector3 & scale) { scale_.set(scale); }
179 
182  osgVector3 getScale() const { return scale_.value; }
183 
185  virtual void setColor (const osgVector4& color) = 0;
186 
187  virtual osg::ref_ptr<osg::Node> getOsgNode() const;
188 
192  virtual ::osg::GroupRefPtr asGroup () const
193  {
194  return switch_node_ptr_;
195  }
196 
197  virtual void addLandmark(const float &size);
198 
199  bool hasLandmark () const;
200 
201  ::osg::StateSetRefPtr getOrCreateRootStateSet ()
202  {
203  return switch_node_ptr_->getOrCreateStateSet ();
204  }
205 
206  void deleteLandmark();
207 
208  bool getHighlightEnabled () const
209  {
210  return highlight_enabled_;
211  }
212 
213  void setHighlightEnabled (bool enabled)
214  {
215  setHighlightState (0);
216  highlight_enabled_ = enabled;
217  }
218 
219  void setHighlightState (unsigned int state);
220 
221  const std::size_t& getHighlightState () const
222  {
223  return selected_highlight_;
224  }
225 
226  /*Tools::ConfigurationPtr_t getConfiguration () const
227  {
228  Tools::ConfigurationPtr_t configuration = Tools::Configuration::create(toDefVector3(auto_transform_ptr_->getPosition()),toEigenQuat(auto_transform_ptr_->getRotation()));
229  return configuration;
230  }*/
231 
232  virtual void setAlpha (const float& alpha);
233  virtual float getAlpha() const;
234 
235  void setTransparency (const float& transparency);
236  float getTransparency() const;
237 
239  virtual void traverse (NodeVisitor& visitor);
240 
241  /* Destructor */
242  virtual ~Node ();
243 
244  }; /* class Node */
245 
246 } /* namespace viewer */
247 } /* namespace gepetto */
248 
249 #endif /* dGEPETTO_VIEWER_NODE_HH */
gepetto::viewer::Node::setAlpha
virtual void setAlpha(const float &alpha)
gepetto::viewer::Node::~Node
virtual ~Node()
gepetto::viewer::Property::set
bool set(void)
gepetto::viewer::Node::setWireFrameMode
virtual void setWireFrameMode(const WireFrameMode &wireframe_state)
Virtual method for setting the wireframe mode of the object : visible or not.
osgQuat
::osg::Quat osgQuat
Definition: config-osg.h:112
gepetto::viewer::NodeVisitor
Definition: node-visitor.h:35
gepetto::viewer::Node::setColor
virtual void setColor(const osgVector4 &color)=0
gepetto
Definition: action-search-bar.hh:27
gepetto::viewer::Node::getID
std::string getID() const
getID is a public method for getting the id_name of the Object
Definition: node.h:108
gepetto::viewer::Node::traverse
virtual void traverse(NodeVisitor &visitor)
osgVector3
::osg::Vec3f osgVector3
Definition: config-osg.h:109
gepetto::viewer::Node::deleteLandmark
void deleteLandmark()
gepetto::viewer::Node::NodeTest
friend struct NodeTest
Definition: node.h:30
gepetto::viewer::Node::applyConfiguration
void applyConfiguration(const Configuration &cfg)
Definition: node.h:132
gepetto::viewer::Node::geode_ptr_
::osg::GeodeRefPtr geode_ptr_
Definition: node.h:67
gepetto::viewer::Node::getLightingMode
virtual LightingMode getLightingMode() const
fwd.h
gepetto::viewer::Node::setTransparentRenderingBin
void setTransparentRenderingBin(bool transparent=true, osg::StateSet *ss=NULL)
gepetto::viewer::Node::getHighlightState
const std::size_t & getHighlightState() const
Definition: node.h:221
gepetto::viewer::NodeBit
@ NodeBit
Definition: node.h:23
gepetto::viewer::Node::getHighlightEnabled
bool getHighlightEnabled() const
Definition: node.h:208
gepetto::viewer::Node::alpha_
float alpha_
Definition: node.h:69
gepetto::viewer::Node::getOsgNode
virtual osg::ref_ptr< osg::Node > getOsgNode() const
gepetto::viewer::IntersectionBit
@ IntersectionBit
Definition: node.h:22
node-property.h
gepetto::viewer::Node::applyConfiguration
void applyConfiguration(const osgVector3 &position, const osgQuat &quat)
Definition: node.h:125
gepetto::gui::Configuration
viewer::Configuration Configuration
Definition: configuration.hh:30
gepetto::viewer::Node::getGlobalTransform
const Configuration & getGlobalTransform() const
returns rotation and position of the node in word frame
gepetto::viewer::Node::asQueue
::osg::GroupRefPtr asQueue() const
Return the root node to include it in the scene.
Definition: node.h:82
gepetto::viewer::StoredPropertyTpl::value
T value
Definition: node-property.h:405
gepetto::viewer::Node::TransparencyRenderingBinThreshold
static const float TransparencyRenderingBinThreshold
Definition: node.h:97
gepetto::viewer::Node::setLightingMode
virtual void setLightingMode(const LightingMode &lighting_state)
Virtual method for setting the lighting mode of the object : influence by light or not.
gepetto::viewer::Node::landmark_geode_ptr_
::osg::GeodeRefPtr landmark_geode_ptr_
Definition: node.h:64
gepetto::viewer::Node::setVisibilityMode
virtual void setVisibilityMode(const VisibilityMode &visibility_state)
Virtual method for setting the visibility mode of the object : visible or not visible.
gepetto::viewer::Properties
Definition: node-property.h:492
gepetto::viewer::Node::setStaticTransform
void setStaticTransform(const osgVector3 &position, const osgQuat &quat)
gepetto::viewer::Node::setScale
void setScale(float scale)
Definition: node.h:175
gepetto::viewer::Node::addLandmark
virtual void addLandmark(const float &size)
gepetto::viewer::Node::setTransparency
void setTransparency(const float &transparency)
config-osg.h
gepetto::viewer::Node::setScale
void setScale(const osgVector3 &scale)
Definition: node.h:178
gepetto::viewer::Node
Abstract base class of 3D objects in a scene.
Definition: node.h:27
gepetto::viewer::Node::SCENE_VIEWER_ACCEPT_VISITOR
SCENE_VIEWER_ACCEPT_VISITOR
Definition: node.h:238
gepetto::viewer::Node::hasLandmark
bool hasLandmark() const
gepetto::viewer::Node::getStaticRotation
osgQuat getStaticRotation() const
gepetto::viewer::Node::setHighlightEnabled
void setHighlightEnabled(bool enabled)
Definition: node.h:213
gepetto::viewer::VisibilityMode
VisibilityMode
Definition: config-osg.h:117
gepetto::viewer::Node::setID
void setID(const std::string &id_name)
Definition: node.h:87
gepetto::viewer::Node::asGroup
virtual ::osg::GroupRefPtr asGroup() const
Return the root node to include it in the scene.
Definition: node.h:192
gepetto::viewer::Node::getVisibilityMode
virtual const VisibilityMode & getVisibilityMode() const
Definition: node.h:152
gepetto::viewer::Node::getOrCreateRootStateSet
::osg::StateSetRefPtr getOrCreateRootStateSet()
Definition: node.h:201
gepetto::viewer::Node::getTransparency
float getTransparency() const
gepetto::viewer::Node::getWireFrameMode
virtual const WireFrameMode & getWireFrameMode() const
Definition: node.h:169
gepetto::viewer::Node::isDirty
bool isDirty() const
Definition: node.h:113
gepetto::viewer::Node::setDirty
void setDirty(bool dirty=true)
Called when a property is modified.
Definition: node.h:118
gepetto::viewer::Node::getAlpha
virtual float getAlpha() const
gepetto::viewer::Node::setHighlightState
void setHighlightState(unsigned int state)
gepetto::viewer::LightingMode
LightingMode
Definition: config-osg.h:124
osgVector4
::osg::Vec4f osgVector4
Definition: config-osg.h:110
gepetto::viewer::WireFrameMode
WireFrameMode
Definition: config-osg.h:130
gepetto::viewer::StoredPropertyTpl
Definition: node-property.h:381
gepetto::viewer::RangedStoredPropertyTpl< osgVector3, float >
gepetto::viewer::Node::Node
Node(const std::string &name)
Default constructor.
gepetto::viewer::Node::getScale
osgVector3 getScale() const
Definition: node.h:182
node-visitor.h
gepetto::viewer::Configuration
Definition: config-osg.h:144
gepetto::viewer::Node::getStaticPosition
osgVector3 getStaticPosition() const