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 {
22  VisibilityBit = 1 << 0,
23  IntersectionBit = 1 << 1,
24  NodeBit = 1 << 2
25  };
26 
28  class Node : public Properties
29  {
30  private:
31  friend struct NodeTest;
32 
33  std::string id_name_; // automoatic id generated by the program
34  bool dirty_;
35 
37  osg::MatrixTransformRefPtr transform_ptr_;
39  osg::Matrixf Ms_;
41 
44  osg::GroupRefPtr switch_node_ptr_;
45  WireFrameMode selected_wireframe_;
46  std::vector< ::osg::GroupRefPtr > wireframe_modes_;
47 
48  osg::GroupRefPtr hl_switch_node_ptr_;
49  std::size_t selected_highlight_;
50  bool highlight_enabled_;
51  std::vector< ::osg::GroupRefPtr > highlight_nodes_;
52 
53  VisibilityMode visibilityMode_;
54  LightingMode lightingMode_;
55 
57  void init ();
58 
59  void updateTransform ();
60 
61  ::osg::Group* setupHighlightState (unsigned int state);
62 
63  protected:
65  ::osg::GeodeRefPtr landmark_geode_ptr_;
66 
68  ::osg::GeodeRefPtr geode_ptr_;
70  float alpha_;
71 
75  Node (const std::string& name);
76 
78  Node (const Node& other);
79 
83  ::osg::GroupRefPtr asQueue () const
84  {
85  return transform_ptr_;
86  }
87 
88  void setID (const std::string& id_name)
89  {
90  id_name_ = id_name;
91  switch_node_ptr_->setName (id_name_);
92  }
93 
94  void setTransparentRenderingBin (bool transparent = true,
95  osg::StateSet* ss = NULL);
96 
97  public:
99 
104  const Configuration& getGlobalTransform() const;
105 
109  std::string getID () const
110  {
111  return id_name_;
112  }
113 
114  bool isDirty () const
115  {
116  return dirty_;
117  }
118 
119  void setDirty (bool dirty=true)
120  {
121  dirty_ = dirty;
122  }
123 
126  bool isSelectable () const
127  {
128  return transform_ptr_->getNodeMask() & IntersectionBit;
129  }
130 
133  void setSelectable (bool selectable=true);
134 
137  inline void applyConfiguration (const osgVector3 & position, const osgQuat & quat)
138  {
139  applyConfiguration (Configuration(position, quat));
140  }
141 
144  void applyConfiguration (const Configuration & cfg) { M_.set(cfg); }
145 
148  void setStaticTransform (const osgVector3 & position, const osgQuat & quat);
149 
152  osgQuat getStaticRotation() const;
153 
157 
162  virtual void setVisibilityMode (const VisibilityMode& visibility_state);
163 
164  virtual const VisibilityMode& getVisibilityMode () const
165  { return visibilityMode_; }
166 
171  virtual void setLightingMode (const LightingMode& lighting_state);
172 
173  virtual LightingMode getLightingMode () const;
174 
179  virtual void setWireFrameMode (const WireFrameMode& wireframe_state);
180 
181  virtual const WireFrameMode& getWireFrameMode () const
182  {
183  return selected_wireframe_;
184  }
185 
187  void setScale (float scale) { setScale(osgVector3(scale,scale,scale)); }
188 
190  void setScale (const osgVector3 & scale) { scale_.set(scale); }
191 
194  osgVector3 getScale() const { return scale_.value; }
195 
197  virtual void setColor (const osgVector4& color) = 0;
198 
199  virtual osg::ref_ptr<osg::Node> getOsgNode() const;
200 
204  virtual ::osg::GroupRefPtr asGroup () const
205  {
206  return switch_node_ptr_;
207  }
208 
209  virtual void addLandmark(const float &size);
210 
211  bool hasLandmark () const;
212 
213  ::osg::StateSetRefPtr getOrCreateRootStateSet ()
214  {
215  return switch_node_ptr_->getOrCreateStateSet ();
216  }
217 
218  void deleteLandmark();
219 
220  bool getHighlightEnabled () const
221  {
222  return highlight_enabled_;
223  }
224 
225  void setHighlightEnabled (bool enabled)
226  {
227  setHighlightState (0);
228  highlight_enabled_ = enabled;
229  }
230 
231  void setHighlightState (unsigned int state);
232 
233  const std::size_t& getHighlightState () const
234  {
235  return selected_highlight_;
236  }
237 
238  /*Tools::ConfigurationPtr_t getConfiguration () const
239  {
240  Tools::ConfigurationPtr_t configuration = Tools::Configuration::create(toDefVector3(auto_transform_ptr_->getPosition()),toEigenQuat(auto_transform_ptr_->getRotation()));
241  return configuration;
242  }*/
243 
244  virtual void setAlpha (const float& alpha);
245  virtual float getAlpha() const;
246 
247  void setTransparency (const float& transparency);
248  float getTransparency() const;
249 
251  virtual void traverse (NodeVisitor& visitor);
252 
253  /* Destructor */
254  virtual ~Node ();
255 
256  }; /* class Node */
257 
258 } /* namespace viewer */
259 } /* namespace gepetto */
260 
261 #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:88
Definition: node-property.h:492
void setHighlightEnabled(bool enabled)
Definition: node.h:225
std::string getID() const
getID is a public method for getting the id_name of the Object
Definition: node.h:109
::osg::GeodeRefPtr geode_ptr_
Definition: node.h:68
::osg::Vec4f osgVector4
Definition: config-osg.h:110
virtual const VisibilityMode & getVisibilityMode() const
Definition: node.h:164
VisibilityMode
Definition: config-osg.h:117
void setScale(float scale)
Definition: node.h:187
SCENE_VIEWER_ACCEPT_VISITOR
Definition: node.h:250
Definition: node.h:24
Definition: node-visitor.h:35
void applyConfiguration(const Configuration &cfg)
Definition: node.h:144
bool isDirty() const
Definition: node.h:114
void applyConfiguration(const osgVector3 &position, const osgQuat &quat)
Definition: node.h:137
Definition: action-search-bar.hh:27
friend struct NodeTest
Definition: node.h:31
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:204
virtual void traverse(NodeVisitor &visitor)
void setSelectable(bool selectable=true)
float getTransparency() const
Definition: node-property.h:381
virtual void addLandmark(const float &size)
::osg::StateSetRefPtr getOrCreateRootStateSet()
Definition: node.h:213
::osg::GroupRefPtr asQueue() const
Return the root node to include it in the scene.
Definition: node.h:83
virtual const WireFrameMode & getWireFrameMode() const
Definition: node.h:181
bool getHighlightEnabled() const
Definition: node.h:220
osgVector3 getScale() const
Definition: node.h:194
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:233
void setStaticTransform(const osgVector3 &position, const osgQuat &quat)
void setHighlightState(unsigned int state)
void setScale(const osgVector3 &scale)
Definition: node.h:190
static const float TransparencyRenderingBinThreshold
Definition: node.h:98
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:119
bool isSelectable() const
Definition: node.h:126
::osg::GeodeRefPtr landmark_geode_ptr_
Definition: node.h:65
WireFrameMode
Definition: config-osg.h:130
void setTransparency(const float &transparency)
Definition: node.h:22
Abstract base class of 3D objects in a scene.
Definition: node.h:28
float alpha_
Definition: node.h:70