GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/viewer/node.h Lines: 11 34 32.4 %
Date: 2020-05-14 11:23:33 Branches: 1 4 25.0 %

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 <iostream>
13
#include <gepetto/viewer/fwd.h>
14
#include <gepetto/viewer/node-visitor.h>
15
#include <gepetto/viewer/node-property.h>
16
#include <gepetto/viewer/config-osg.h>
17
18
namespace gepetto {
19
namespace viewer {
20
21
    enum {
22
      IntersectionBit = 0x1,
23
      NodeBit         = 0x2
24
    };
25
26
    /// Abstract base class of 3D objects in a scene.
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
35
        /** PositionAttitudeTransform related to the global configuration */
36
        osg::MatrixTransformRefPtr transform_ptr_;
37
        RangedStoredPropertyTpl<osgVector3, float> scale_;
38
        osg::Matrixf Ms_;
39
        StoredPropertyTpl<Configuration> M_;
40
41
        /** Associated switch node */
42
        /** TODO: The use of multiswitch may be better */
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
55
        /** Initialization function */
56
        void init ();
57
58
        void updateTransform ();
59
60
        ::osg::Group* setupHighlightState (unsigned int state);
61
62
    protected:
63
        /** protected because it's used in LeafNodeCapsule */
64
        ::osg::GeodeRefPtr landmark_geode_ptr_;
65
66
        /** Geode pointer for landmarks */
67
	::osg::GeodeRefPtr geode_ptr_;
68
        /** Alpha value */
69
        float alpha_;
70
71
        /**
72
         \brief Default constructor
73
         */
74
        Node (const std::string& name);
75
76
        /** Copy constructor */
77
        Node (const Node& other);
78
79
        /**
80
         \brief Return the root node to include it in the scene
81
         */
82
3
        ::osg::GroupRefPtr asQueue () const
83
        {
84
3
            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:
97
        static const float TransparencyRenderingBinThreshold;
98
99
        /**
100
         \brief returns rotation and position of the node
101
         in word frame
102
         */
103
        const Configuration& getGlobalTransform() const;
104
105
        /**
106
         \brief getID is a public method for getting the id_name of the Object
107
         */
108
        std::string getID () const
109
        {
110
            return id_name_;
111
        }
112
113
3
        bool isDirty () const
114
        {
115
3
          return dirty_;
116
        }
117
118
4
        void setDirty (bool dirty=true)
119
        {
120
4
          dirty_ = dirty;
121
4
        }
122
123
        /** Apply a new global configuration
124
         */
125
4
        inline void applyConfiguration (const osgVector3 & position, const osgQuat & quat)
126
        {
127
4
          applyConfiguration (Configuration(position, quat));
128
4
        }
129
130
        /** Apply a new global configuration
131
         */
132
4
        void applyConfiguration (const Configuration & cfg) { M_.set(cfg); }
133
134
	/** Set Static transformation
135
         */
136
        void setStaticTransform (const osgVector3 & position, const osgQuat & quat);
137
138
	/** Get Static rotation
139
        */
140
        osgQuat getStaticRotation() const;
141
142
	/** Get Static position
143
        */
144
        osgVector3 getStaticPosition() const;
145
146
        /**
147
         \brief Virtual method for setting the visibility mode of the object : visible or not visible
148
         \param visibilitymode state
149
         */
150
        virtual void setVisibilityMode (const VisibilityMode& visibility_state);
151
152
        virtual const VisibilityMode& getVisibilityMode () const
153
        { return visibilityMode_; }
154
155
        /**
156
         \brief Virtual method for setting the lighting mode of the object : influence by light or not
157
         \param lightingmode state
158
         */
159
        virtual void setLightingMode (const LightingMode& lighting_state);
160
161
        virtual LightingMode getLightingMode () const;
162
163
        /**
164
         \brief Virtual method for setting the wireframe mode of the object : visible or not
165
         \param wireframemode state
166
         */
167
        virtual void setWireFrameMode (const WireFrameMode& wireframe_state);
168
169
        virtual const WireFrameMode& getWireFrameMode () const
170
        {
171
          return selected_wireframe_;
172
        }
173
174
        /** Set scale value of the OSG object */
175
        void setScale (float scale) { setScale(osgVector3(scale,scale,scale)); }
176
177
        /** Set scales value of the OSG object */
178
        void setScale (const osgVector3 & scale) { scale_.set(scale); }
179
180
	/** Get scale
181
        */
182
        osgVector3 getScale() const { return scale_.value; }
183
184
        /** Set the color of the object */
185
        virtual void setColor (const osgVector4& color) = 0;
186
187
	virtual osg::ref_ptr<osg::Node> getOsgNode() const;
188
189
        /**
190
         \brief Return the root node to include it in the scene
191
         */
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
238
        SCENE_VIEWER_ACCEPT_VISITOR;
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 */