1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGGestureData.h"
40 #include "OSGGestureDataFields.h"
41 #include "OSGFieldContainer.h"
43 #include "OSGSField.ins"
47 GestureData::GestureBlob::GestureBlob( UInt32 uiEvent
,
49 const std::string
&szGesture
,
55 _iGestureId(iGestureId
),
56 _vPosition (rX
, rY
, 0.f
),
58 _uiCoordSys(uiCoordSys
),
60 _szGesture (szGesture
)
64 //GestureData::GestureBlob::~GestureBlob(void)
68 bool GestureData::GestureBlob::operator ==(const GestureBlob
&rhs
) const
70 // gesture id and uievent uniquely identifies the gesture
71 return (_uiEvent
== rhs
._uiEvent
&& _iGestureId
== rhs
._iGestureId
);
74 bool GestureData::GestureBlob::operator !=(const GestureBlob
&rhs
) const
76 return !(*this == rhs
);
79 bool GestureData::GestureBlob::operator < (const GestureBlob
&rhs
) const
81 return ((_iGestureId
< rhs
._iGestureId
) ||
82 (_iGestureId
== rhs
._iGestureId
&& _uiEvent
< rhs
._uiEvent
));
87 GestureData::GestureData(void) :
96 GestureData::GestureData(const GestureData
&source
) :
97 _vBlobs (source
._vBlobs
),
98 _vActiveBlobs(source
._vActiveBlobs
),
104 GestureData::~GestureData(void)
108 /*------------------------------ access -----------------------------------*/
110 const GestureData
&GestureData::operator = (const GestureData
&rhs
)
112 _vBlobs
= rhs
._vBlobs
;
114 _pWindow
= rhs
._pWindow
;
115 _pCSMWindow
= rhs
._pCSMWindow
;
120 bool GestureData::operator ==(const GestureData
&rhs
) const
122 //return (_vBlobs == rhs._vBlobs &&
123 // _pWindow == rhs._pWindow );
124 // _pCSMWindow == rhs._pCSMWindow );
126 return (_vBlobs
== rhs
._vBlobs
);
129 void GestureData::addGesture( UInt32 uiId
,
130 const std::string
&szGesture
,
135 GestureBlob
tmpBlob(GestureData::AddGesture
,
142 GestureBlobStoreIt tbIt
= std::lower_bound(_vBlobs
.begin(),
145 if(tbIt
== _vBlobs
.end())
147 _vBlobs
.push_back(tmpBlob
);
149 else if(tmpBlob
!= *tbIt
)
151 _vBlobs
.insert(tbIt
, tmpBlob
);
155 fprintf(stderr
, "addC: blob %d mode %d already present\n",
157 GestureData::AddGesture
);
161 void GestureData::updateGesture( UInt32 uiId
,
162 const std::string
&szGesture
,
167 ActiveBlobsStoreIt aIt
= std::lower_bound(_vActiveBlobs
.begin(),
168 _vActiveBlobs
.end (),
171 UInt32 uiEvent
= GestureData::UpdateGesture
;
173 if(aIt
== _vActiveBlobs
.end())
175 uiEvent
= GestureData::AddGesture
;
177 _vActiveBlobs
.push_back(uiId
);
183 uiEvent
= GestureData::AddGesture
;
185 _vActiveBlobs
.insert(aIt
, uiId
);
189 GestureBlob
tmpBlob(uiEvent
, uiId
, szGesture
, rX
, rY
, uiCoordSys
);
191 // fprintf(stderr, "update coursor %d / %f %f\n",
194 GestureBlobStoreIt tbIt
= std::lower_bound(_vBlobs
.begin(),
198 if(tbIt
== _vBlobs
.end())
200 _vBlobs
.push_back(tmpBlob
);
202 else if(tmpBlob
!= *tbIt
)
204 _vBlobs
.insert(tbIt
, tmpBlob
);
212 void GestureData::removeGesture(UInt32 uiId
)
214 GestureBlob
tmpBlob(GestureData::RemoveGesture
, uiId
, "", 0.f
, 0.f
);
216 GestureBlobStoreIt tbIt
= std::lower_bound(_vBlobs
.begin(),
220 if(tbIt
== _vBlobs
.end())
222 _vBlobs
.push_back(tmpBlob
);
224 else if(tmpBlob
!= *tbIt
)
226 _vBlobs
.insert(tbIt
, tmpBlob
);
230 fprintf(stderr
, "remC: blob %d mode %d already present\n",
232 GestureData::RemoveGesture
);
235 ActiveBlobsStoreIt aIt
= std::lower_bound(_vActiveBlobs
.begin(),
236 _vActiveBlobs
.end (),
239 if(aIt
!= _vActiveBlobs
.end())
243 _vActiveBlobs
.erase(aIt
);
249 void GestureData::prepSubmission(void)
253 void GestureData::clear(void)
255 // fprintf(stderr, "clear\n");
260 void GestureData::dump(void) const
262 fprintf(stderr
, "Blobs (%" PRISize
") :\n", _vBlobs
.size());
263 for(UInt32 i
= 0; i
< _vBlobs
.size(); ++i
)
265 fprintf(stderr
, " [%d] : %d %d %d | %f %f\n",
268 _vBlobs
[i
]._iGestureId
,
269 _vBlobs
[i
]._uiCoordSys
,
270 _vBlobs
[i
]._vPosition
[0],
271 _vBlobs
[i
]._vPosition
[1]);
274 fprintf(stderr
, "Active Blobs (%" PRISize
") :\n", _vActiveBlobs
.size());
276 for(UInt32 i
= 0; i
< _vActiveBlobs
.size(); ++i
)
278 fprintf(stderr
, "[%d] : %d\n",
284 DataType FieldTraits
<GestureData
>::_type("GestureData", "BaseType" );
286 OSG_FIELDTRAITS_GETTYPE ( GestureData
)
287 OSG_FIELD_DLLEXPORT_DEF1(SField
, GestureData
)