1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/****************************************************************************
* *
* OpenNI 1.x Alpha *
* Copyright (C) 2011 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* OpenNI is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* OpenNI is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
* *
****************************************************************************/
#ifndef XNV_USER_SELECTOR_H_
#define XNV_USER_SELECTOR_H_
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include <XnCppWrapper.h>
#include <XnHashT.h>
#include "UserSelectionStructures.h"
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
/// @brief Class to select which users to track
///
/// The goal of this class is to decide which users to track. This is an abstract class
/// used as an interface for all user selection implementations. The assumption is that the user
/// selector will receive a user generator node and will output which users are at which state as
/// well as deciding which users to track.
/// @ingroup UserSelectionClasses
class UserSelector
{
public:
/// @brief This method is aimed to be called by the TrackingInitializer to update the sub
/// state of a user when trying to track.
///
/// This is an update of the progress of starting to track the user, i.e. the user is in state
/// selected (and not yet tracking) and the sub state represents the progress.
/// @param nUserId The user whose progress is to be updated
/// @param newSubState The new sub state achieved in the progress of starting to track.
/// @return The success status
virtual XnStatus UpdateUserTrackingProgress(XnUserID nUserId, XnInt64 newSubState);
/// @brief This method is aimed to be called by the TrackingInitializer when the user
/// tracking initialization is complete.
///
/// This tells the user selector how a selection went (succeed or failed).
/// @param nUserId The user whose progress is to be updated
/// @param bTracked True if the user is now being tracked and false otherwise.
/// @param newSubState The new sub state achieved in the tracking (mainly has meaning on failure).
/// @return The success status
virtual XnStatus UpdateUserTracking(XnUserID nUserId, XnBool bTracked, XnInt64 newSubState);
/// @brief This method should be called every frame.
///
/// @note The default implementation is to do nothing as many implementations would be event driven.
virtual void UpdateFrame() {};
/// @brief Method to get the current state (and sub state) of a user.
///
/// @param nUserId The user whose state we want to know
/// @param newState The state to fill with new data
/// @return The success status
virtual XnStatus GetUserState(XnUserID nUserId, UserSelectionState& newState);
/// @brief Method to Fill in the string label for a user (state + sub state).
///
/// @param nUserId The user whose label we want
/// @param strLabel Where to put the label
/// @param maxStrLen The maximum allowed string length.
/// @return The success status
XnStatus GetUserLabel(XnUserID nUserId, char* strLabel, XnUInt32 maxStrLen);
/// @brief Returns true if the user selector is valid and false otherwise.
XnBool IsValid() { return m_bValid; };
/// @brief Destructor
virtual ~UserSelector();
protected:
/// @brief A utility function to get the number of currently selected users (both tracking and not yet tracking).
XnUInt32 GetNumberOfSelectedUsers();
/// @brief Translates a state to a string
///
/// @param pUserState The user state to translate
/// @param strLabel Where to put the label
/// @param maxStrLen The maximum allowed string length.
/// @return The success status
XnStatus TranslateStateToLabel(const UserSelectionState* pUserState, char* strLabel, XnUInt32 maxStrLen);
/// @brief constructor
///
/// @param pUserGenerator The user generator which holds all the users.
UserSelector(xn::UserGenerator* pUserGenerator);
/// @brief Adds a new user to the hash
///
/// Called internally from the NewUserCallback callback.
/// @param nUserId The user we are adding
/// @return The success status
virtual XnStatus AddNewUser(XnUserID nUserId);
/// @brief Remove a user from the hash
///
/// Called internally from the LostUserCallback callback.
/// @param nUserId The user we are removing
/// @return The success status
virtual XnStatus RemoveUser(XnUserID nUserId);
/// @brief translate a calibration error to a string
///
/// @param eError The calibration error
/// @return The string version of the error.
const XnChar* GetCalibrationErrorString(XnCalibrationStatus eError);
/// @brief Creates a new user selection state object of the appropriate type
///
/// @return A pointer to the new object (NULL if failed).
virtual UserSelectionState* CreateUserSelectionState();
/// @brief Updates the user selection state object of the appropriate type
///
/// @param nUserId the user whose state we want to update
/// @param eState The new state of the user
/// @param subState The new sub state of the user
/// @return The success code.
virtual XnStatus UpdateUserSelectionState(XnUserID nUserId, XnSelectionState eState , XnInt64 subState);
/// @brief Defines the UserHash hash which holds a state for each user
typedef XnHashT<XnUserID, UserSelectionState*> UserStateHash;
xn::UserGenerator *m_pUserGenerator; ///< @brief the user generator to get user information from
/// @brief A hash for user states.
///
/// This is a hash which holds for each user in the scene a state and substate.
/// @see @ref UserSelectionState
UserStateHash m_hUsersState;
XnBool m_bValid; ///< @brief Holds true if the user selector is valid and false otherwise
XnCallbackHandle m_hUserCallbacks; ///< @brief A handle to be able to unregister the user callbacks
private:
/// @brief New user callback.
///
/// Called when a new user is found.
/// @param generator The user generator which called the callback
/// @param nUserId The newly found user
/// @param pCookie A cookie which on registering is defined as the calling user selector object.
static void XN_CALLBACK_TYPE NewUserCallback(xn::UserGenerator& generator, XnUserID nUserId, void* pCookie);
/// @brief Lost user callback.
///
/// Called when a user is lost (i.e. no longer counted in the scene. Does not include exiting).
/// @param generator The user generator which called the callback
/// @param nUserId The lost user
/// @param pCookie A cookie which on registering is defined as the calling user selector object.
static void XN_CALLBACK_TYPE LostUserCallback(xn::UserGenerator& generator, XnUserID nUserId, void* pCookie);
};
#endif // XNV_USER_SELECTOR_H_
|