From 60295fbd04d46ae5741a6ef7e60f3f8de9ae196c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=BCrki?= Date: Thu, 23 Jul 2020 22:16:17 +0200 Subject: [PATCH] Add javadoc to all new or modified methods --- src/DetectionMethod.h | 4 +- src/SkeletonFinder.cpp | 84 ++++++++++++++++---------- src/SkeletonFinder.h | 2 - src/TrackingNetworkManager.cpp | 27 +++++++-- src/ofApp.cpp | 106 +++++++++++++++++++++++---------- src/ofApp.h | 1 - 6 files changed, 151 insertions(+), 73 deletions(-) diff --git a/src/DetectionMethod.h b/src/DetectionMethod.h index 152f8fa..c0cda8d 100644 --- a/src/DetectionMethod.h +++ b/src/DetectionMethod.h @@ -1 +1,3 @@ -#define BLOB \ No newline at end of file +// Comment or uncomment this line to change the detection method used + +#define BLOB diff --git a/src/SkeletonFinder.cpp b/src/SkeletonFinder.cpp index 54d0a71..806d255 100644 --- a/src/SkeletonFinder.cpp +++ b/src/SkeletonFinder.cpp @@ -1,14 +1,17 @@ // // SkeletonFinder.cpp // -// Created by Pierre B�rki on 19.05.20. +// Created by Pierre Bürki on 19.05.20. // Adapted from BlobFinder.cpp by maybites (14.02.14). // #include "SkeletonFinder.h" - -void SkeletonFinder::initGUI(ofxGui& gui) { +/** + * Creates and populates the GUI elements + */ +void SkeletonFinder::initGUI(ofxGui& gui) +{ panel = gui.addPanel(); panel->loadTheme("theme/theme_light.json"); @@ -36,16 +39,27 @@ void SkeletonFinder::initGUI(ofxGui& gui) { panel->setVisible(visible); } -void SkeletonFinder::setTransformMatrix(ofMatrix4x4* mat) { +/** + * Set the transformation matrix pointer + */ +void SkeletonFinder::setTransformMatrix(ofMatrix4x4* mat) +{ transformMatrix = mat; } -void SkeletonFinder::update(nuitrack::SkeletonData::Ptr data) { +/** + * Called each time a skeleton is detected on a frame + * Copy the data for later use + */ +void SkeletonFinder::update(nuitrack::SkeletonData::Ptr data) +{ skeletons.clear(); // TODO: filter using the capture bounds - for (nuitrack::Skeleton skel : data->getSkeletons()) { + for (nuitrack::Skeleton skel : data->getSkeletons()) + { vector joints; - for (nuitrack::Joint joint : skel.joints) { + for (nuitrack::Joint joint : skel.joints) + { glm::vec3 pos = ofxnui::Tracker::fromVector3(joint.real); // ofMatrix multiplication works in reverse @@ -55,24 +69,36 @@ void SkeletonFinder::update(nuitrack::SkeletonData::Ptr data) { } Skeleton skeleton(skel.id, joints); - if (!filtering.get() || isSkeletonInBounds(skeleton)) { + if (!filtering.get() || isSkeletonInBounds(skeleton)) + { skeletons.push_back(skeleton); } - } } -vector SkeletonFinder::getSkeletons() const { +/** + * Getter for the skeletons container + */ +vector SkeletonFinder::getSkeletons() const +{ return skeletons; } +/** + * Draw the sensor box + * Note that the sensor box plays a role only if "filtering" is activated + */ void SkeletonFinder::drawSensorBox() { sensorBox.draw(); } -// adapted from ofxNuitrack example -void SkeletonFinder::drawSkeletons() { +/** + * Draw all the skeletons in this->skeletons + * Adapted from ofxNuitrack example + */ +void SkeletonFinder::drawSkeletons() +{ static vector bones = { Bone(nuitrack::JOINT_WAIST, nuitrack::JOINT_TORSO, glm::vec3(0, 1, 0)), Bone(nuitrack::JOINT_TORSO, nuitrack::JOINT_NECK, glm::vec3(0, 1, 0)), @@ -98,8 +124,10 @@ void SkeletonFinder::drawSkeletons() { }; ofSetColor(0, 255, 0); - for (Skeleton skel : skeletons) { - for (Bone bone : bones) { + for (Skeleton skel : skeletons) + { + for (Bone bone : bones) + { auto j1 = skel.joints[bone.from]; auto j2 = skel.joints[bone.to]; @@ -112,23 +140,13 @@ void SkeletonFinder::drawSkeletons() { } } -string SkeletonFinder::getShortDesc() +/** + * Called each time the sensor box boundaries are changed + * + * Not modified from BlobFinder.cpp + */ +void SkeletonFinder::updateSensorBox(int& value) { - if (skeletons.size() == 0) { - return "No skeleton found"; - } else { - ostringstream s; - Skeleton skel = skeletons[0]; - auto pos = skel.joints[nuitrack::JOINT_HEAD].pos; - s << "Head position : (" << - pos.x << ", " << - pos.y << ", " << - pos.z << ")"; - return s.str(); - } -} - -void SkeletonFinder::updateSensorBox(int& value) { sensorBox.clear(); sensorBox.setMode(OF_PRIMITIVE_LINES); @@ -161,7 +179,11 @@ void SkeletonFinder::updateSensorBox(int& value) { //captureCam. } -bool SkeletonFinder::isSkeletonInBounds(const Skeleton& skel) { +/** + * Returns true if the skeleton's head is in the sensor box + */ +bool SkeletonFinder::isSkeletonInBounds(const Skeleton& skel) +{ glm::vec3 headPos = skel.joints[nuitrack::JOINT_HEAD].pos; return headPos.x < sensorBoxLeft.get() * SCALE && headPos.x > sensorBoxRight.get() * SCALE diff --git a/src/SkeletonFinder.h b/src/SkeletonFinder.h index f0d9591..6072d28 100644 --- a/src/SkeletonFinder.h +++ b/src/SkeletonFinder.h @@ -64,8 +64,6 @@ public: void drawSensorBox(); void drawSkeletons(); - string getShortDesc(); - vector getSkeletons() const; private: diff --git a/src/TrackingNetworkManager.cpp b/src/TrackingNetworkManager.cpp index d7efa4f..8e42e7c 100644 --- a/src/TrackingNetworkManager.cpp +++ b/src/TrackingNetworkManager.cpp @@ -4,7 +4,7 @@ // // Created by maybites on 14.02.14. // -// +// Modified by Pierre Bürki on 23.07.2020 #include "TrackingNetworkManager.h" @@ -116,9 +116,11 @@ void TrackingNetworkManager::sendTrackingData(const BodyFinder& bodyFinder) { } #else vector skeletons = bodyFinder.getSkeletons(); - if (skeletons.size() > 0) { + if (skeletons.size() > 0) + { // Only one skeleton is to be on the scene for the perspective to work - if (skeletons.size() > 1) { + if (skeletons.size() > 1) + { sendMultipleBodiesAlert(); return; } @@ -127,14 +129,23 @@ void TrackingNetworkManager::sendTrackingData(const BodyFinder& bodyFinder) { #endif } -void TrackingNetworkManager::sendMultipleBodiesAlert() { +/** + * Send a special message via OSC to signal multiple bodies + */ +void TrackingNetworkManager::sendMultipleBodiesAlert() +{ ofxOscMessage alertMsg; alertMsg.setAddress("/ks/server/track/multiple-bodies"); sendMessageToTrackingClients(alertMsg); } #ifdef BLOB -void TrackingNetworkManager::sendBlobData(const BlobTracker& blob) { +/** + * Send a given blob via OSC + * Slighty modified from the original so that it only sends the blob's head + */ +void TrackingNetworkManager::sendBlobData(const BlobTracker& blob) +{ ofxOscMessage blobMsg; blobMsg.setAddress("/ks/server/track/headblob"); @@ -147,7 +158,11 @@ void TrackingNetworkManager::sendBlobData(const BlobTracker& blob) { sendMessageToTrackingClients(blobMsg); } #else -void TrackingNetworkManager::sendSkeletonData(const Skeleton& skel) { +/** + * Send a given skeleton via OSC + */ +void TrackingNetworkManager::sendSkeletonData(const Skeleton& skel) +{ ofxOscMessage skeletonMsg; skeletonMsg.setAddress("/ks/server/track/skeleton"); diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 53c1558..fefd534 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -1,3 +1,11 @@ +// +// ofApp.cpp +// kinectTCPServer +// +// Created by maybites on 14.02.14. +// +// Edited by Pierre Bürki on 23.07.2020. + #include "ofApp.h" #define RECONNECT_TIME 400 @@ -7,7 +15,11 @@ #ifndef BLOB -ofMatrix4x4 ofApp::makeNuitrackToRealSenseTransform() { +/** + * Create the constant nuitrack -> realsense transformation matrix + */ +ofMatrix4x4 ofApp::makeNuitrackToRealSenseTransform() +{ // Thankfully this matrix is symmetric, so we need not worry about the row-major-ness // of the matrix object float mat[16] = { @@ -21,9 +33,13 @@ ofMatrix4x4 ofApp::makeNuitrackToRealSenseTransform() { const ofMatrix4x4 ofApp::nuitrackViewportToRealSenseViewportTransform = makeNuitrackToRealSenseTransform(); -void ofApp::initNuitrack() { +/** + * Set up Nuitrack's config and callbacks + */ +void ofApp::initNuitrack() +{ nuitracker = ofxnui::Tracker::create(); - nuitracker->init(""); + nuitracker->init(); // depth feed settings nuitracker->setConfigValue("Realsense2Module.Depth.FPS", "30"); @@ -51,21 +67,34 @@ void ofApp::initNuitrack() { nuitracker->setConfigValue("Segmentation.MAX_DISTANCE", "7000"); nuitracker->setConfigValue("Skeletonization.MaxDistance", "7000"); - nuitracker->setIssuesCallback([this](nuitrack::IssuesData::Ptr data) { - auto issue = data->getIssue(); - if (issue) { - ofLogNotice() << "Issue detected! " << issue->getName() << " [" << issue->getId() << "]"; + nuitracker->setIssuesCallback( + [this](nuitrack::IssuesData::Ptr data) + { + auto issue = data->getIssue(); + if (issue) + { + ofLogNotice() << "Issue detected! " << issue->getName() << " [" << issue->getId() << "]"; + } + } + ); + nuitracker->setRGBCallback( + [this](nuitrack::RGBFrame::Ptr data) + { + pointCloudManager.updateRGB(data); + } + ); + nuitracker->setDepthCallback( + [this](nuitrack::DepthFrame::Ptr data) + { + pointCloudManager.updateDepth(data); + } + ); + nuitracker->setSkeletonCallback( + [this](nuitrack::SkeletonData::Ptr data) + { + tracker.update(data); } - }); - nuitracker->setRGBCallback([this](nuitrack::RGBFrame::Ptr data) { - pointCloudManager.updateRGB(data); - }); - nuitracker->setDepthCallback([this](nuitrack::DepthFrame::Ptr data) { - pointCloudManager.updateDepth(data); - }); - nuitracker->setSkeletonCallback([this](nuitrack::SkeletonData::Ptr data) { - tracker.update(data); - }); + ); pointCloudManager.setDepthSensor(nuitracker->depthTracker); } @@ -105,15 +134,19 @@ void ofApp::setupTransformGui() { transformationGuiGroup.add(transformation.set("Transform", ofMatrix4x4())); guitransform->addGroup(transformationGuiGroup); - // The GUI apparently cannot display matrices - // Also this method apparently requires a reference for some reason + // This method apparently requires a reference for some reason bool visible = false; guitransform->setVisible(visible); reloadTransformMatrix(); } -void ofApp::reloadTransformMatrix() { +/** + * Load the transformation matrix from the xml file + * Also applies the nuitrack->realsense transformation if needed + */ +void ofApp::reloadTransformMatrix() +{ guitransform->loadFromFile("transformation.xml"); #ifdef BLOB @@ -124,7 +157,8 @@ void ofApp::reloadTransformMatrix() { #endif } -void ofApp::setup(){ +void ofApp::setup() +{ #ifdef BLOB if (ofIsGLProgrammableRenderer()) { @@ -136,12 +170,8 @@ void ofApp::setup(){ ofLog(OF_LOG_NOTICE) << "MainAPP: looking for RealSense Device..."; - // ofSetLogLevel(OF_LOG_VERBOSE); - realSense = RSDevice::createUniquePtr(); - realSense->checkConnectedDialog(); - realSense->setVideoSize(REALSENSE_VIDEO_WIDTH, REALSENSE_VIDEO_HEIGHT); ofLog(OF_LOG_NOTICE) << "... RealSense Device found."; @@ -161,7 +191,8 @@ void ofApp::setup(){ ofLog(OF_LOG_NOTICE) << "MainAPP: starting attached Device..."; #ifdef BLOB - if (realSense->capture()) { + if (realSense->capture()) + { createGUIDeviceParams(); createGUIPostProcessingParams(); } @@ -238,15 +269,18 @@ void ofApp::createGUIPostProcessingParams() { #endif //-------------------------------------------------------------- -void ofApp::update(){ +void ofApp::update() +{ ofBackground(100, 100, 100); #ifdef BLOB - if(realSense->update(ofxRealSenseTwo::PointCloud::VIDEO)) { - - if (maskUpdatesCounter < MASK_UPDATE_CYCLES) { - if (maskUpdatesCounter == 0) { + if(realSense->update(ofxRealSenseTwo::PointCloud::VIDEO)) + { + if (maskUpdatesCounter < MASK_UPDATE_CYCLES) + { + if (maskUpdatesCounter == 0) + { tracker.clearMask(); } tracker.captureMaskBegin(); @@ -254,7 +288,9 @@ void ofApp::update(){ tracker.captureMaskEnd(); maskUpdatesCounter++; - } else { + } + else + { // Cature captureCloud to FBO tracker.captureBegin(); drawCapturePointCloud(false); @@ -271,6 +307,9 @@ void ofApp::update(){ networkMng.update(tracker); } +/** + * Save current settings to the various xml files + */ void ofApp::saveSettings() { tracker.panel->saveToFile("tracking.xml"); @@ -284,6 +323,9 @@ void ofApp::saveSettings() #endif } +/** + * Load the settings from the various xml files + */ void ofApp::loadSettings() { tracker.panel->loadFromFile("tracking.xml"); diff --git a/src/ofApp.h b/src/ofApp.h index 69fc235..335a3a7 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -1,6 +1,5 @@ #pragma once - #include "ofMain.h" #include "ofxNetwork.h" #include "ofxGuiExtended.h" -- GitLab