ADTF Display Toolbox
Loading...
Searching...
No Matches
baseobjectscene.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <osg/PositionAttitudeTransform>
10
11#include "baseobject.h"
12
13namespace adtf
14{
15
16namespace disptb
17{
18
19namespace mixinlib
20{
21
22namespace endor
23{
24
40class cBaseObjectScene : public osg::PositionAttitudeTransform
41{
42protected:
43public:
48 cBaseObjectScene(const tChar* strName = ""): m_strName(strName)
49 {
50 }
51
56 {
57 }
58
63 virtual const tChar* GetName()
64 {
65 return m_strName.c_str();
66 }
67
73 virtual tResult AddObject(cBaseObject* pObj)
74 {
75 // check if an object with this id already exists
76 auto oObj = m_oObjects.find(pObj->GetId());
77 if (oObj != m_oObjects.end())
78 {
79 RETURN_ERROR(ERR_DEVICE_IN_USE);
80 }
81
82 // add it to the scene
83 addChild(pObj);
84 // and store it in our map
85 m_oObjects[pObj->GetId()] = pObj;
86
87 RETURN_NOERROR;
88 }
89
95 virtual tResult RemoveObject(tUInt32 nId)
96 {
97 // find the object
98 auto oObj = m_oObjects.find(nId);
99 if (oObj != m_oObjects.end())
100 {
101 // remove the osg node (expensive operation)
102 removeChild(oObj->second.get());
103 // remove it from our map
104 m_oObjects.erase(oObj);
105 }
106 else
107 {
108 RETURN_ERROR(ERR_NOT_FOUND);
109 }
110
111 RETURN_NOERROR;
112 }
113
120 virtual tResult GetObject(tUInt32 nId, cBaseObject** ppObj)
121 {
122 // find it in the map O(log N)
123 auto oObj = m_oObjects.find(nId);
124 if (oObj != m_oObjects.end())
125 {
126 *ppObj = oObj->second.get();
127 }
128 else
129 {
130 RETURN_ERROR(ERR_NOT_FOUND);
131 }
132
133 RETURN_NOERROR;
134 }
135
140 virtual tResult RemoveInvalid()
141 {
142 tUInt nChildren = getNumChildren();
143 for (tUInt nChild = 0; nChild < nChildren; ++nChild)
144 {
145 // no dynamic cast is necessary we know that we only added cIdSwitch children
146 cBaseObject* pObj = static_cast<cBaseObject*>(getChild(nChild));
147 if (pObj->IsUpdated())
148 {
149 // if it has been updated during this cycle we reset it.
150 pObj->Reset();
151 }
152 else
153 {
154 // if it has not been updated we remove it from the graph and the map
155 m_oObjects.erase(m_oObjects.find(pObj->GetId()));
156 removeChild(nChild); // expensive since osg uses a std::vector
157 // this should also have free'd the object
158 --nChildren;
159 --nChild;
160 }
161 }
162
163 RETURN_NOERROR;
164 }
165
174 virtual tResult SetPosition(tFloat64 fPosX, tFloat64 fPosY, tFloat64 fPosZ)
175 {
176 setPosition(osg::Vec3(fPosX, fPosY, fPosZ));
177 RETURN_NOERROR;
178 }
179
188 virtual tResult SetRotation(tFloat64 fRotX, tFloat64 fRotY, tFloat64 fRotZ)
189 {
190 setAttitude(osg::Quat(fRotX, osg::Vec3(1, 0, 0), fRotY, osg::Vec3(0, 1, 0), fRotZ, osg::Vec3(0, 0, 1)));
191 RETURN_NOERROR;
192 }
193
194protected:
195 std::string m_strName;
196 std::map<tUInt32, osg::ref_ptr<cBaseObject>> m_oObjects;
197};
198
199} // namespace endor
200
202using endor::cBaseObjectScene;
203
204} // namespace mixinlib
205
206} // namespace disptb
207
208} // namespace adtf
Copyright © Audi Electronics Venture GmbH.
cBaseObjectScene(const tChar *strName="")
Default constructor.
Base class for objects that can be managed with cBaseObjectScene.
Definition baseobject.h:42
tBool IsUpdated()
Returns whether or not this object has been updated since the last Reset call.
Definition baseobject.h:219
tResult Reset()
Resets the updated property to false.
Definition baseobject.h:228
tUInt32 GetId()
Returns the id of the object.
Definition baseobject.h:199
virtual tResult SetRotation(tFloat64 fRotX, tFloat64 fRotY, tFloat64 fRotZ)
Sets the rotation (attitude) of the scene.
virtual tResult RemoveObject(tUInt32 nId)
Removes an object from the scene.
virtual tResult AddObject(cBaseObject *pObj)
Use this to add a new object to the scene.
virtual tResult RemoveInvalid()
Removes all objects that have not been updated since the last call.
virtual const tChar * GetName()
Returns the name of the scene.
virtual tResult SetPosition(tFloat64 fPosX, tFloat64 fPosY, tFloat64 fPosZ)
Sets the position of the scene.
cBaseObjectScene(const tChar *strName="")
Default constructor.
virtual tResult GetObject(tUInt32 nId, cBaseObject **ppObj)
Retrieves an object.
Namespace for functionality provided by the Mixin Library.
Definition baseobject.h:26
Namespace for functionality provided by the Display Toolbox.
Main namespace.