gepetto-viewer  4.12.1
An user-friendly Graphical Interface
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 */
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.
gepetto::viewer::VisibilityBit
@ VisibilityBit
Definition: node.h:22
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:109
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:31
gepetto::viewer::Node::applyConfiguration
void applyConfiguration(const Configuration &cfg)
Definition: node.h:144
gepetto::viewer::Node::geode_ptr_
::osg::GeodeRefPtr geode_ptr_
Definition: node.h:68
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:233
gepetto::viewer::NodeBit
@ NodeBit
Definition: node.h:24
gepetto::viewer::Node::getHighlightEnabled
bool getHighlightEnabled() const
Definition: node.h:220
gepetto::viewer::Node::alpha_
float alpha_
Definition: node.h:70
gepetto::viewer::Node::getOsgNode
virtual osg::ref_ptr< osg::Node > getOsgNode() const
gepetto::viewer::IntersectionBit
@ IntersectionBit
Definition: node.h:23
node-property.h
gepetto::viewer::Node::isSelectable
bool isSelectable() const
Definition: node.h:126
gepetto::viewer::Node::applyConfiguration
void applyConfiguration(const osgVector3 &position, const osgQuat &quat)
Definition: node.h:137
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:83
gepetto::viewer::StoredPropertyTpl::value
T value
Definition: node-property.h:405
gepetto::viewer::Node::TransparencyRenderingBinThreshold
static const float TransparencyRenderingBinThreshold
Definition: node.h:98
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:65
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:187
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:190
gepetto::viewer::Node
Abstract base class of 3D objects in a scene.
Definition: node.h:28
gepetto::viewer::Node::SCENE_VIEWER_ACCEPT_VISITOR
SCENE_VIEWER_ACCEPT_VISITOR
Definition: node.h:250
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:225
gepetto::viewer::VisibilityMode
VisibilityMode
Definition: config-osg.h:117
gepetto::viewer::Node::setID
void setID(const std::string &id_name)
Definition: node.h:88
gepetto::viewer::Node::asGroup
virtual ::osg::GroupRefPtr asGroup() const
Return the root node to include it in the scene.
Definition: node.h:204
gepetto::viewer::Node::getVisibilityMode
virtual const VisibilityMode & getVisibilityMode() const
Definition: node.h:164
gepetto::viewer::Node::getOrCreateRootStateSet
::osg::StateSetRefPtr getOrCreateRootStateSet()
Definition: node.h:213
gepetto::viewer::Node::getTransparency
float getTransparency() const
gepetto::viewer::Node::getWireFrameMode
virtual const WireFrameMode & getWireFrameMode() const
Definition: node.h:181
gepetto::viewer::Node::isDirty
bool isDirty() const
Definition: node.h:114
gepetto::viewer::Node::setDirty
void setDirty(bool dirty=true)
Called when a property is modified.
Definition: node.h:119
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::setSelectable
void setSelectable(bool selectable=true)
gepetto::viewer::Node::getScale
osgVector3 getScale() const
Definition: node.h:194
node-visitor.h
gepetto::viewer::Configuration
Definition: config-osg.h:144
gepetto::viewer::Node::getStaticPosition
osgVector3 getStaticPosition() const