34 #define skl_states (static_cast<nite::SkeletonState*>(m_skeletons_ptr))    35 #define user_tracker (static_cast<nite::UserTracker*>(m_userTracker_ptr))    37 #define FILL_JOINT_DATA(_J1, _J2)                                  \    38     obs->_J1.x = user.getSkeleton().getJoint(_J2).getPosition().x; \    39     obs->_J1.y = user.getSkeleton().getJoint(_J2).getPosition().y; \    40     obs->_J1.z = user.getSkeleton().getJoint(_J2).getPosition().z; \    41     obs->_J1.conf = user.getSkeleton().getJoint(_J2).getPositionConfidence();    45 #pragma comment(lib, "NiTE2.lib")    49     "head",        
"neck",       
"torso",    
"left_shoulder", 
"left_elbow",
    50     "left_hand",   
"left_hip",   
"left_knee", 
"left_foot",   
"right_shoulder",
    51     "right_elbow", 
"right_hand", 
"right_hip", 
"right_knee", 
"right_foot"};
    61 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2    72         "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or 'BUILD_NITE2'=OFF, "    73         "so this class cannot be used.");
    82 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2    83     nite::NiTE::shutdown();  
   108             scene->insert(std::make_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
   111             m_win->setCameraElevationDeg(-90);
   112             m_win->setCameraAzimuthDeg(90);
   113             m_win->setCameraZoom(4);
   114             m_win->setCameraPointingToPoint(0, 0, 0);
   118             body->setName(
"body");
   122                 sph->setColor(0, 1, 0);
   123                 sph->setName(jointName);
   129             lines->setName(
"lines");
   130             lines->setColor(0, 0, 1);
   134             m_win->unlockAccess3DScene();
   141                 m_win->addTextMessage(0.35, 0.9, 
"Please, adopt this position");
   145                 if (!scene->getByName(
"dummy"))
   147                     const double SCALE = 0.8;
   148                     const double BODY_RADIUS = 0.22 * SCALE;
   149                     const double BODY_LENGTH = 0.8 * SCALE;
   150                     const double ARM_RADIUS = 0.05 * SCALE;
   151                     const double ARM_LENGTH = 0.4 * SCALE;
   152                     const double LEG_RADIUS = 0.1 * SCALE;
   153                     const double LEG_LENGTH = 0.8 * SCALE;
   154                     const double HEAD_RADIUS = 0.15 * SCALE;
   155                     const double ALPHA_CH = 0.8;
   158                         std::make_shared<CSetOfObjects>();
   159                     dummy->setName(
"dummy");
   164                             std::make_shared<CSphere>(HEAD_RADIUS);
   165                         part->setColor(1, 1, 1, ALPHA_CH);
   167                             0, 0, 0.5 * BODY_LENGTH + HEAD_RADIUS, 0, 0, 0));
   173                             BODY_RADIUS, BODY_RADIUS, BODY_LENGTH);
   174                         part->setColor(1, 1, 1, ALPHA_CH);
   182                             ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
   183                         part->setColor(1, 1, 1, ALPHA_CH);
   185                             -BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS, 0,
   192                             ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
   193                         part->setColor(1, 1, 1, ALPHA_CH);
   195                             -BODY_RADIUS - ARM_LENGTH + ARM_RADIUS, 0,
   196                             0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
   202                             ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
   203                         part->setColor(1, 1, 1, ALPHA_CH);
   205                             BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS, 0,
   212                             ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
   213                         part->setColor(1, 1, 1, ALPHA_CH);
   215                             BODY_RADIUS + ARM_LENGTH - ARM_RADIUS, 0,
   216                             0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
   222                             LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
   223                         part->setColor(1, 1, 1, ALPHA_CH);
   225                             -BODY_RADIUS + LEG_RADIUS, 0,
   226                             -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
   232                             LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
   233                         part->setColor(1, 1, 1, ALPHA_CH);
   235                             BODY_RADIUS - LEG_RADIUS, 0,
   236                             -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
   239                     scene->insert(dummy);
   245                             scene->getByName(
"dummy"));
   246                     dummy->setVisibility(
true);
   252                         scene->getByName(
"body"));
   270                     s->setColor(1, 0, 0);
   271                     s->setRadius(i == 0 ? 0.07 : 0.03);
   274             m_win->unlockAccess3DScene();
   275             m_win->forceRepaint();
   297             scene->insert(std::make_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
   300             m_win->setCameraElevationDeg(-90);
   301             m_win->setCameraAzimuthDeg(90);
   302             m_win->setCameraZoom(4);
   303             m_win->setCameraPointingToPoint(0, 0, 0);
   307             body->setName(
"body");
   311                 sph->setColor(0, 1, 0);
   312                 sph->setName(jointName);
   318             lines->setName(
"lines");
   319             lines->setColor(0, 0, 1);
   323             m_win->unlockAccess3DScene();
   331             m_win->clearTextMessages();
   333                 scene->getByName(
"dummy"));
   334             if (dummy) dummy->setVisibility(
false);
   340                         scene->getByName(
"body"));
   360                             j = obs->left_shoulder;
   379                             j = obs->right_shoulder;
   382                             j = obs->right_elbow;
   401                         j.
x * 1e-3, j.
y * 1e-3, j.
z * 1e-3, 0, 0, 0));
   403                         std::min(1.0, 2 * (1 - j.
conf)),
   404                         std::min(1.0, 2 * j.
conf), 0);
   405                     s->setRadius(i == 0 ? 0.07 : 0.03);
   410                     body->getByName(
"lines"));
   424                         s0->getPoseX(), s0->getPoseY(), s0->getPoseZ(),
   425                         s1->getPoseX(), s1->getPoseY(), s1->getPoseZ());
   428             m_win->unlockAccess3DScene();
   429             m_win->forceRepaint();
   439 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2   442         std::this_thread::sleep_for(200ms);
   448     nite::UserTrackerFrameRef userTrackerFrame;
   449     nite::Status niteRc = 
user_tracker->readFrame(&userTrackerFrame);
   451     if (niteRc != nite::STATUS_OK)
   453         printf(
"    [Skeleton tracker] Get next frame failed\n");
   458     const nite::Array<nite::UserData>& users = userTrackerFrame.getUsers();
   462         const nite::UserData& user = users[i];
   465         skl_states[user.getId()] = user.getSkeleton().getState();
   470             cout << 
"   [Skeleton tracker] New user found" << endl;
   472         else if (user.getSkeleton().getState() == nite::SKELETON_TRACKED)
   474             cout << 
"   [Skeleton tracker] User " << user.getId() << 
" tracked"   477                 std::make_shared<CObservationSkeleton>();
   480             const uint64_t nowUI = userTrackerFrame.getTimestamp();
   492             const auto AtDO = std::chrono::microseconds(AtUI);
   534             cout << 
"   [Skeleton tracker] Looking for user..." << endl;
   542         cout << 
"   [Skeleton tracker] No user found after 2000 attempts ..."   544         nite::NiTE::shutdown();  
   548         "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or "   549         "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
   558 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2   564     if (niteRc != nite::STATUS_OK)
   566         printf(
"Couldn't create user tracker\n");
   571         printf(
"Sucessfully created user tracker \n");
   573             "Start moving around to get detected...\n(PSI pose may be required "   574             "for skeleton calibration, depending on the configuration)\n");
   597         "MRPT has been compiled with 'BUILD_OPENNI2'=OFF OR "   598         "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
   607     const std::string& iniSection)
   610         configSource.
read_float(iniSection, 
"pose_x", 0, 
false),
   611         configSource.
read_float(iniSection, 
"pose_y", 0, 
false),
   612         configSource.
read_float(iniSection, 
"pose_z", 0, 
false),
   621     cout << 
"---------------------------" << endl;
   622     cout << 
"Skeleton Tracker parameters: " << endl;
   623     cout << 
"---------------------------" << endl;
   626     cout << 
"---------------------------" << endl << endl;
 
std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments. 
 
void appendObservation(const mrpt::serialization::CSerializable::Ptr &obj)
Like appendObservations() but for just one observation. 
 
void initialize() override
Connects to the PrimeSense camera and prepares it to get skeleton data. 
 
app initialize(argc, argv)
 
void * m_skeletons_ptr
Opaque pointers to specific NITE data. 
 
A set of object, which are referenced to the coordinates framework established in this object...
 
#define THROW_EXCEPTION(msg)
 
mrpt::system::TTimeStamp m_timeStartTT
 
std::string m_sensorLabel
See CGenericSensor. 
 
unsigned int m_toutCounter
Timeout counter (for internal use only) 
 
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime. 
 
Contains classes for various device interfaces. 
 
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
 
static CDisplayWindow3D::Ptr Create(const std::string &windowCaption, unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300)
Class factory returning a smart pointer. 
 
int m_nUsers
Number of detected users. 
 
mrpt::poses::CPose3D m_sensorPose
Sensor pose. 
 
void processPreview(const mrpt::obs::CObservationSkeleton::Ptr &obs)
Displays real-time info for the captured skeleton. 
 
#define ASSERT_(f)
Defines an assertion mechanism. 
 
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
 
~CSkeletonTracker() override
Destructor. 
 
This class allows loading and storing values and vectors of different types from a configuration text...
 
A class for grabbing mrpt::obs::CObservationSkeleton from a PrimeSense camera. 
 
constexpr double DEG2RAD(const double x)
Degrees to radians. 
 
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection) override
See the class documentation at the top for expected parameters. 
 
This namespace contains representation of robot actions and observations. 
 
double conf
Confidence value [0...1]. 
 
std::vector< std::pair< JOINT, JOINT > > m_linesToPlot
Lines between joints. 
 
void processPreviewNone()
 
CSkeletonTracker()
Constructor. 
 
A class used to store a 3D point. 
 
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files: 
 
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
 
bool m_showPreview
Preview window management. 
 
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
 
A solid or wire-frame sphere. 
 
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
 
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates). 
 
The namespace for 3D scene representation and rendering. 
 
A generic joint for the skeleton observation. 
 
A set of independent lines (or segments), one line with its own start and end positions (X...
 
uint32_t m_timeStartUI
Timestamp management. 
 
mrpt::gui::CDisplayWindow3D::Ptr m_win
 
void doProcess() override
This method will be invoked at a minimum rate of "process_rate" (Hz) 
 
#define FILL_JOINT_DATA(_J1, _J2)
 
std::vector< double > m_joint_theta
Joint angles when no skeleton has been detected.