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 */
const Configuration & getGlobalTransform() const
returns rotation and position of the node in word frame
T value
Definition: node-property.h:405
virtual void setLightingMode(const LightingMode &lighting_state)
Virtual method for setting the lighting mode of the object : influence by light or not...
viewer::Configuration Configuration
Definition: configuration.hh:30
virtual void setWireFrameMode(const WireFrameMode &wireframe_state)
Virtual method for setting the wireframe mode of the object : visible or not.
osgVector3 getStaticPosition() const
virtual void setAlpha(const float &alpha)
virtual LightingMode getLightingMode() const
Node(const std::string &name)
Default constructor.
::osg::Vec3f osgVector3
Definition: config-osg.h:109
::osg::Quat osgQuat
Definition: config-osg.h:112
void setID(const std::string &id_name)
Definition: node.h:87
Definition: node-property.h:492
void setHighlightEnabled(bool enabled)
Definition: node.h:213
std::string getID() const
getID is a public method for getting the id_name of the Object
Definition: node.h:108
::osg::GeodeRefPtr geode_ptr_
Definition: node.h:67
::osg::Vec4f osgVector4
Definition: config-osg.h:110
virtual const VisibilityMode & getVisibilityMode() const
Definition: node.h:152
VisibilityMode
Definition: config-osg.h:117
void setScale(float scale)
Definition: node.h:175
SCENE_VIEWER_ACCEPT_VISITOR
Definition: node.h:238
Definition: node.h:23
Definition: node-visitor.h:35
void applyConfiguration(const Configuration &cfg)
Definition: node.h:132
bool isDirty() const
Definition: node.h:113
void applyConfiguration(const osgVector3 &position, const osgQuat &quat)
Definition: node.h:125
Definition: action-search-bar.hh:27
friend struct NodeTest
Definition: node.h:30
virtual void setColor(const osgVector4 &color)=0
virtual ::osg::GroupRefPtr asGroup() const
Return the root node to include it in the scene.
Definition: node.h:192
virtual void traverse(NodeVisitor &visitor)
float getTransparency() const
Definition: node-property.h:381
virtual void addLandmark(const float &size)
::osg::StateSetRefPtr getOrCreateRootStateSet()
Definition: node.h:201
::osg::GroupRefPtr asQueue() const
Return the root node to include it in the scene.
Definition: node.h:82
virtual const WireFrameMode & getWireFrameMode() const
Definition: node.h:169
bool getHighlightEnabled() const
Definition: node.h:208
osgVector3 getScale() const
Definition: node.h:182
LightingMode
Definition: config-osg.h:124
Definition: config-osg.h:144
virtual float getAlpha() const
virtual void setVisibilityMode(const VisibilityMode &visibility_state)
Virtual method for setting the visibility mode of the object : visible or not visible.
bool hasLandmark() const
const std::size_t & getHighlightState() const
Definition: node.h:221
void setStaticTransform(const osgVector3 &position, const osgQuat &quat)
void setHighlightState(unsigned int state)
void setScale(const osgVector3 &scale)
Definition: node.h:178
static const float TransparencyRenderingBinThreshold
Definition: node.h:97
osgQuat getStaticRotation() const
void setTransparentRenderingBin(bool transparent=true, osg::StateSet *ss=NULL)
virtual osg::ref_ptr< osg::Node > getOsgNode() const
void setDirty(bool dirty=true)
Called when a property is modified.
Definition: node.h:118
::osg::GeodeRefPtr landmark_geode_ptr_
Definition: node.h:64
WireFrameMode
Definition: config-osg.h:130
void setTransparency(const float &transparency)
Abstract base class of 3D objects in a scene.
Definition: node.h:27
float alpha_
Definition: node.h:69