MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / UpdateFrame

Method UpdateFrame

Samples/NiUserSelection/ClosestUserSelector.cpp:73–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73void ClosestUserSelector::UpdateFrame()
74{
75 // clear the user list so we can fill it out.
76 ClearUserList();
77
78 // find out who are the closest ones.
79 for(UserStateHash::Iterator iter = m_hUsersState.Begin(); iter!=m_hUsersState.End(); ++iter)
80 {
81 UserSelectionState* val = iter->Value();
82 XnUserID newUser = iter->Key();
83 XnPoint3D newCom;
84 if(m_pUserGenerator->GetCoM(newUser,newCom)!=XN_STATUS_OK)
85 continue; // irrelevant user.
86 if(newCom.Z<=0)
87 {
88 continue; // this is not someone we can use.
89 }
90 if(val->m_eState == XN_SELECTION_FAILED)
91 {
92 // we failed last time so we might want to give a penalty
93 UserStatusWithCom* valWithCom=(UserStatusWithCom*)val;
94 XnFloat distSqr=0.0f;
95 XnFloat diff;
96 diff = newCom.X - valWithCom->m_COM.X;
97 distSqr += diff * diff;
98 diff = newCom.Y - valWithCom->m_COM.Y;
99 distSqr += diff * diff;
100 diff = newCom.Z - valWithCom->m_COM.Z;
101 distSqr += diff * diff;
102 if(distSqr<MIN_SQR_DIST_TO_RETRY)
103 {
104 newCom.Z+=DIST_MOD_FOR_FAILURE; // we haven't moved too much since we failed, lets give a penalty
105 }
106
107 }
108 if(val->m_eState == XN_SELECTION_SELECTED || val->m_eState == XN_SELECTION_TRACKING)
109 {
110 newCom.Z-=100.0f; // hysteresis to make the current user closer to avoid back and forth.
111 if(newCom.Z<=0)
112 {
113 newCom.Z=1.0f; // minimum dist!
114 }
115 }
116 InsertNewUser(newUser,newCom.Z); // add it to the list in an ordered manner
117 }
118
119
120 // go over the list and start or stop tracking.
121 for(UserStateHash::Iterator iter = m_hUsersState.Begin(); iter!=m_hUsersState.End(); ++iter)
122 {
123 UserSelectionState* pState = iter->Value();
124 XnUInt32 curUser = iter->Key();
125 if(TestIfShouldTrack(curUser))
126 {
127 // this means the user is in the list of those which need to track
128 if(pState->m_eState == XN_SELECTION_SELECTED || pState->m_eState == XN_SELECTION_TRACKING)
129 {
130 continue; // we are already tracking so nothing to do...

Callers

nothing calls this directly

Calls 6

AbortTrackingMethod · 0.80
BeginMethod · 0.45
EndMethod · 0.45
ValueMethod · 0.45
GetCoMMethod · 0.45
StartTrackingMethod · 0.45

Tested by

no test coverage detected