Kinect Scol plugin
DataSkeleton.cpp
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
32 #include "core/DataSkeleton.h"
33 #include "generator/User.h"
34 #include "generator/Depth.h"
35 #include "objects/KinectDevice.h"
36 #include "objects/KinectUser.h"
37 
38 DataSkeleton::DataSkeleton(KinectUser* existingUser)
39 {
40  p_User = existingUser;
41 }
42 
43 DataSkeleton::DataSkeleton()
44 {
45  p_User = 0;
46 }
47 
48 DataSkeleton::~DataSkeleton()
49 {
50  p_User = 0;
51 }
52 
53 bool DataSkeleton::GetBoneCurrentPosition(nite::JointType jointType, nite::Point3f &position, float minConfidence)
54 {
55  if (p_User && p_User->GetParentDevice()->GetUserGenerator() != 0 && p_User->GetParentDevice()->GetUserGenerator()->IsValid())
56  {
57  nite::UserTracker* pUserTracker = p_User->GetParentDevice()->GetUserGenerator()->GetUserTraker();
58  nite::UserTrackerFrameRef* pTrakerFrame = p_User->GetParentDevice()->GetUserGenerator()->GetTrakerFrame();
59  const nite::UserData* userData = pTrakerFrame->getUserById((nite::UserId)p_User->GetId());
60  if (userData && userData->isVisible())
61  {
62  const nite::Skeleton skl = userData->getSkeleton();
63  if (skl.getState() == nite::SKELETON_TRACKED)
64  {
65  const nite::SkeletonJoint joint = skl.getJoint(jointType);
66  if (joint.getPositionConfidence() < minConfidence)
67  return false;
68 
69  position = joint.getPosition();
70  return true;
71  }
72  }
73  }
74  return false;
75 }
76 
77 bool DataSkeleton::GetBoneImgCoordinates(nite::JointType jointType, nite::Point3f &v, float minConfidence)
78 {
79  if (p_User && p_User->GetParentDevice()->GetUserGenerator() != 0 && p_User->GetParentDevice()->GetUserGenerator()->IsValid())
80  {
81  nite::UserTracker* pUserTracker = p_User->GetParentDevice()->GetUserGenerator()->GetUserTraker();
82  nite::UserTrackerFrameRef* pTrakerFrame = p_User->GetParentDevice()->GetUserGenerator()->GetTrakerFrame();
83  const nite::UserData* userData = pTrakerFrame->getUserById(p_User->GetId());
84  if (userData && userData->isVisible())
85  {
86  const nite::Skeleton skl = userData->getSkeleton();
87  if (skl.getState() == nite::SKELETON_TRACKED)
88  {
89  const nite::SkeletonJoint joint = skl.getJoint(jointType);
90  if (joint.getPositionConfidence() < minConfidence)
91  return false;
92 
93  float x, y;
94  if (pUserTracker->convertJointCoordinatesToDepth(joint.getPosition().x, joint.getPosition().y, joint.getPosition().z, &x, &y) != nite::STATUS_OK)
95  return false;
96 
97  v.x = x;
98  v.y = y;
99  v.z = joint.getPosition().z;
100 
101  return true;
102  }
103  }
104  }
105  return false;
106 }
107 
108 bool DataSkeleton::GetBoneCurrentOrientation(nite::JointType jointType, Quaternion* mQuat, float minConfidence)
109 {
110  if (p_User && p_User->GetParentDevice()->GetUserGenerator() != 0 && p_User->GetParentDevice()->GetUserGenerator()->IsValid())
111  {
112  nite::UserTracker* pUserTracker = p_User->GetParentDevice()->GetUserGenerator()->GetUserTraker();
113  nite::UserTrackerFrameRef* pTrakerFrame = p_User->GetParentDevice()->GetUserGenerator()->GetTrakerFrame();
114  const nite::UserData* userData = pTrakerFrame->getUserById(p_User->GetId());
115  if (userData && userData->isVisible())
116  {
117  const nite::Skeleton skl = userData->getSkeleton();
118  if (skl.getState() == nite::SKELETON_TRACKED)
119  {
120  const nite::SkeletonJoint joint = skl.getJoint(jointType);
121  if (joint.getOrientationConfidence() < minConfidence)
122  return false;
123 
124  const nite::Quaternion jquat = joint.getOrientation();
125  mQuat->x = -jquat.x;
126  mQuat->y = jquat.y;
127  mQuat->z = -jquat.z;
128  mQuat->w = jquat.w;
129 
130  return true;
131  }
132  }
133  }
134  return false;
135 }
Kinect user handling. .
Definition: KinectUser.h:38