GCC Code Coverage Report


Directory: ./
File: include/gepetto/viewer/node.h
Date: 2024-12-20 15:53:58
Exec Total Coverage
Lines: 7 29 24.1%
Branches: 1 6 16.7%

Line Branch Exec Source
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 <gepetto/viewer/config-osg.h>
13 #include <gepetto/viewer/fwd.h>
14 #include <gepetto/viewer/node-property.h>
15 #include <gepetto/viewer/node-visitor.h>
16
17 #include <iostream>
18
19 namespace gepetto {
20 namespace viewer {
21
22 enum { VisibilityBit = 1 << 0, IntersectionBit = 1 << 1, NodeBit = 1 << 2 };
23
24 /// Abstract base class of 3D objects in a scene.
25 class Node : public Properties {
26 private:
27 friend struct NodeTest;
28
29 std::string id_name_; // automoatic id generated by the program
30 bool dirty_;
31
32 /** PositionAttitudeTransform related to the global configuration */
33 osg::MatrixTransformRefPtr transform_ptr_;
34 RangedStoredPropertyTpl<osgVector3, float> scale_;
35 osg::Matrixf Ms_;
36 StoredPropertyTpl<Configuration> M_;
37
38 /** Associated switch node */
39 /** TODO: The use of multiswitch may be better */
40 osg::GroupRefPtr switch_node_ptr_;
41 WireFrameMode selected_wireframe_;
42 std::vector< ::osg::GroupRefPtr> wireframe_modes_;
43
44 osg::GroupRefPtr hl_switch_node_ptr_;
45 std::size_t selected_highlight_;
46 bool highlight_enabled_;
47 std::vector< ::osg::GroupRefPtr> highlight_nodes_;
48
49 VisibilityMode visibilityMode_;
50 LightingMode lightingMode_;
51
52 /** Initialization function */
53 void init();
54
55 void updateTransform();
56
57 ::osg::Group* setupHighlightState(unsigned int state);
58
59 protected:
60 /** protected because it's used in LeafNodeCapsule */
61 ::osg::GeodeRefPtr landmark_geode_ptr_;
62
63 /** Geode pointer for landmarks */
64 ::osg::GeodeRefPtr geode_ptr_;
65 /** Alpha value */
66 float alpha_;
67
68 /**
69 \brief Default constructor
70 */
71 Node(const std::string& name);
72
73 /** Copy constructor */
74 Node(const Node& other);
75
76 /**
77 \brief Return the root node to include it in the scene
78 */
79 3 ::osg::GroupRefPtr asQueue() const { return transform_ptr_; }
80
81 void setID(const std::string& id_name) {
82 id_name_ = id_name;
83 switch_node_ptr_->setName(id_name_);
84 }
85
86 void setTransparentRenderingBin(bool transparent = true,
87 osg::StateSet* ss = NULL);
88
89 public:
90 static const float TransparencyRenderingBinThreshold;
91
92 /**
93 \brief returns rotation and position of the node
94 in word frame
95 */
96 const Configuration& getGlobalTransform() const;
97
98 /**
99 \brief getID is a public method for getting the id_name of the Object
100 */
101 std::string getID() const { return id_name_; }
102
103 3 bool isDirty() const { return dirty_; }
104
105 4 void setDirty(bool dirty = true) { dirty_ = dirty; }
106
107 /** Whether this node (and its children) can be selected from mouse.
108 */
109 bool isSelectable() const {
110 return transform_ptr_->getNodeMask() & IntersectionBit;
111 }
112
113 /** Set whether this node (and its children) can be selected from mouse.
114 */
115 void setSelectable(bool selectable = true);
116
117 /** Apply a new global configuration
118 */
119 4 inline void applyConfiguration(const osgVector3& position,
120 const osgQuat& quat) {
121
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 applyConfiguration(Configuration(position, quat));
122 4 }
123
124 /** Apply a new global configuration
125 */
126 4 void applyConfiguration(const Configuration& cfg) { M_.set(cfg); }
127
128 /** Set Static transformation
129 */
130 void setStaticTransform(const osgVector3& position, const osgQuat& quat);
131
132 /** Get Static rotation
133 */
134 osgQuat getStaticRotation() const;
135
136 /** Get Static position
137 */
138 osgVector3 getStaticPosition() const;
139
140 /**
141 \brief Virtual method for setting the visibility mode of the object : visible
142 or not visible \param visibilitymode state
143 */
144 virtual void setVisibilityMode(const VisibilityMode& visibility_state);
145
146 virtual const VisibilityMode& getVisibilityMode() const {
147 return visibilityMode_;
148 }
149
150 /**
151 \brief Virtual method for setting the lighting mode of the object : influence
152 by light or not \param lightingmode state
153 */
154 virtual void setLightingMode(const LightingMode& lighting_state);
155
156 virtual LightingMode getLightingMode() const;
157
158 /**
159 \brief Virtual method for setting the wireframe mode of the object : visible
160 or not \param wireframemode state
161 */
162 virtual void setWireFrameMode(const WireFrameMode& wireframe_state);
163
164 virtual const WireFrameMode& getWireFrameMode() const {
165 return selected_wireframe_;
166 }
167
168 /** Set scale value of the OSG object */
169 void setScale(float scale) { setScale(osgVector3(scale, scale, scale)); }
170
171 /** Set scales value of the OSG object */
172 void setScale(const osgVector3& scale) { scale_.set(scale); }
173
174 /** Get scale
175 */
176 osgVector3 getScale() const { return scale_.value; }
177
178 /** Set the color of the object */
179 virtual void setColor(const osgVector4& color) = 0;
180
181 virtual osg::ref_ptr<osg::Node> getOsgNode() const;
182
183 /**
184 \brief Return the root node to include it in the scene
185 */
186 virtual ::osg::GroupRefPtr asGroup() const { return switch_node_ptr_; }
187
188 virtual void addLandmark(const float& size);
189
190 bool hasLandmark() const;
191
192 ::osg::StateSetRefPtr getOrCreateRootStateSet() {
193 return switch_node_ptr_->getOrCreateStateSet();
194 }
195
196 void deleteLandmark();
197
198 bool getHighlightEnabled() const { return highlight_enabled_; }
199
200 void setHighlightEnabled(bool enabled) {
201 setHighlightState(0);
202 highlight_enabled_ = enabled;
203 }
204
205 void setHighlightState(unsigned int state);
206
207 const std::size_t& getHighlightState() const { return selected_highlight_; }
208
209 /*Tools::ConfigurationPtr_t getConfiguration () const
210 {
211 Tools::ConfigurationPtr_t configuration =
212 Tools::Configuration::create(toDefVector3(auto_transform_ptr_->getPosition()),toEigenQuat(auto_transform_ptr_->getRotation()));
213 return configuration;
214 }*/
215
216 virtual void setAlpha(const float& alpha);
217 virtual float getAlpha() const;
218
219 void setTransparency(const float& transparency);
220 float getTransparency() const;
221
222 SCENE_VIEWER_ACCEPT_VISITOR;
223 virtual void traverse(NodeVisitor& visitor);
224
225 /* Destructor */
226 virtual ~Node();
227
228 }; /* class Node */
229
230 } /* namespace viewer */
231 } /* namespace gepetto */
232
233 #endif /* dGEPETTO_VIEWER_NODE_HH */
234