mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-02 01:30:34 -06:00
save input safely between frames with cursor->getPath() and clear list (& refrence path) after process to not lose any information
This commit is contained in:
@@ -60,15 +60,17 @@ class TuioEar : public TuioListener {
|
||||
|
||||
void refresh(TuioTime frameTime);
|
||||
|
||||
std::vector<TuioCursor*> getInput();
|
||||
TuioTime getLastProcessedTime(int id);
|
||||
std::vector<TuioCursor> getInput();
|
||||
void clearInput();
|
||||
void unlock() { _mx.unlock(); };
|
||||
|
||||
private:
|
||||
TuioClient *_tuioClient;
|
||||
OscReceiver *_oscReceiver;
|
||||
|
||||
std::vector<TuioCursor*> _list;
|
||||
std::vector<TuioCursor> _list;
|
||||
std::vector<int> _removeList;
|
||||
std::vector<std::pair<int, TuioTime>> _processedPath;
|
||||
std::mutex _mx;
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TuioEar";
|
||||
@@ -53,26 +54,49 @@ void TuioEar::removeTuioObject(TuioObject *tobj) {
|
||||
}
|
||||
|
||||
void TuioEar::addTuioCursor(TuioCursor *tcur) {
|
||||
_mx.lock();
|
||||
_list.push_back(new TuioCursor(tcur));
|
||||
_mx.unlock();
|
||||
_mx.lock();
|
||||
|
||||
//LINFO("add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << "/" << tcur->getTuioSourceID() << ") " << tcur->getX() << " " << tcur->getY() << " " << tobj->getY() << ", size: " << _list.size() << "\n");
|
||||
//std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << "/" << tcur->getTuioSourceID() << ") " << tcur->getX() << " " << tcur->getY() << ", size: " << _list.size() << "\n";
|
||||
// find same id in _list if it exists in _removeList (new input with same ID as a previously stored)
|
||||
int i = tcur->getSessionID();
|
||||
auto foundID = std::find_if(
|
||||
_removeList.begin(),
|
||||
_removeList.end(),
|
||||
[&i](int id) { return id == i; });
|
||||
|
||||
// if found, remove id from _removeList and update, otherwise add new id to list
|
||||
if (foundID != _removeList.end()) {
|
||||
std::find_if(
|
||||
_list.begin(),
|
||||
_list.end(),
|
||||
[&i](const TuioCursor& cursor) {
|
||||
return cursor.getSessionID() == i;
|
||||
})->update(tcur);
|
||||
_removeList.erase(foundID);
|
||||
}
|
||||
else
|
||||
_list.push_back(TuioCursor(*tcur));
|
||||
|
||||
_mx.unlock();
|
||||
}
|
||||
|
||||
void TuioEar::updateTuioCursor(TuioCursor *tcur) {
|
||||
_mx.lock();
|
||||
_list.push_back(new TuioCursor(tcur));
|
||||
int i = tcur->getSessionID();
|
||||
std::find_if(
|
||||
_list.begin(),
|
||||
_list.end(),
|
||||
[&i](const TuioCursor& cursor) {
|
||||
return cursor.getSessionID() == i;
|
||||
})->update(tcur);
|
||||
_mx.unlock();
|
||||
|
||||
//LINFO("set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/" << tobj->getTuioSourceID() << ") " << tobj->getX() << " " << tobj->getY() << ", size: " << _list.size() << "\n");
|
||||
//std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << "/" << tcur->getTuioSourceID() << ") " << tcur->getX() << " " << tcur->getY()
|
||||
//<< " " << tcur->getMotionSpeed() << " " << tcur->getMotionAccel() << " " << ", size: " << _list.size() << "\n";
|
||||
}
|
||||
|
||||
// save id to be removed and remove it in clearInput
|
||||
void TuioEar::removeTuioCursor(TuioCursor *tcur) {
|
||||
//std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << "/" << tcur->getTuioSourceID() << ")" << std::endl;
|
||||
_mx.lock();
|
||||
_removeList.push_back(tcur->getSessionID());
|
||||
//LINFO("To be removed: " << _removeFromList.size() << "\n");
|
||||
_mx.unlock();
|
||||
}
|
||||
|
||||
void TuioEar::addTuioBlob(TuioBlob *tblb) {
|
||||
@@ -88,22 +112,44 @@ void TuioEar::removeTuioBlob(TuioBlob *tblb) {
|
||||
std::cout << "del blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << "/" << tblb->getTuioSourceID() << ")" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void TuioEar::refresh(TuioTime frameTime) {
|
||||
//LINFO("refresh " << frameTime.getTotalMilliseconds() << "\n"); // about every 15ms on TuioPad app
|
||||
}
|
||||
|
||||
std::vector<TuioCursor*> TuioEar::getInput() {
|
||||
_mx.lock();
|
||||
TuioTime TuioEar::getLastProcessedTime(int id) {
|
||||
return std::find_if(
|
||||
_processedPath.begin(),
|
||||
_processedPath.end(),
|
||||
[&id](std::pair<int, TuioTime> t) { return id = t.first; }
|
||||
)->second;
|
||||
}
|
||||
|
||||
std::vector<TuioCursor> TuioEar::getInput() {
|
||||
std::lock_guard<std::mutex> lock(_mx);
|
||||
_processedPath.clear();
|
||||
for (const TuioCursor& c : _list)
|
||||
_processedPath.push_back(std::make_pair(c.getSessionID(), c.getTuioTime()));
|
||||
return _list;
|
||||
}
|
||||
|
||||
void TuioEar::clearInput() {
|
||||
_mx.lock();
|
||||
for (auto &&j : _list) {
|
||||
delete j;
|
||||
}
|
||||
_list.clear();
|
||||
_list.erase(
|
||||
std::remove_if(
|
||||
_list.begin(),
|
||||
_list.end(),
|
||||
[this](const TuioCursor& cursor) {
|
||||
return std::find_if(
|
||||
_removeList.begin(),
|
||||
_removeList.end(),
|
||||
[&cursor](int id) {
|
||||
return cursor.getSessionID() == id;
|
||||
}
|
||||
) != _removeList.end();
|
||||
}),
|
||||
_list.end()
|
||||
);
|
||||
_removeList.clear();
|
||||
_mx.unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <thread> // std::this_thread::sleep_for
|
||||
#include <chrono> // std::chrono::seconds
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TouchModule";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -67,52 +73,39 @@ TouchModule::TouchModule()
|
||||
OsEng.registerModuleCallback( // maybe call ear->clearInput() here rather than postdraw
|
||||
OpenSpaceEngine::CallbackOption::PreSync,
|
||||
[&]() {
|
||||
std::vector<TuioCursor*> list = ear->getInput();
|
||||
std::vector<TuioCursor*> group;
|
||||
//std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::vector<TuioCursor> list = ear->getInput();
|
||||
ear->clearInput();
|
||||
glm::vec2 centroid;
|
||||
ear->unlock();
|
||||
|
||||
|
||||
//print list for debugging
|
||||
std::string s = "";
|
||||
const std::string _loggerCat = "TouchModule";
|
||||
std::ostringstream os;
|
||||
for (auto &&j : list) {
|
||||
os << " (" << j->getX() << "," << j->getY() << ") ";
|
||||
for (const TuioCursor &j : list) {
|
||||
|
||||
os << j.getCursorID() << ", path size: " << j.getPath().size() << ", (" << j.getX() << "," << j.getY() << ") ";
|
||||
}
|
||||
if (list.size() > 0)
|
||||
LINFO("List size: " << list.size() << os.str() << "\n");
|
||||
LINFO("List size: " << list.size() << ", Id: " << os.str() << "\n");
|
||||
os.clear();
|
||||
|
||||
|
||||
ear->clearInput();
|
||||
/*
|
||||
// step through the list (from the start) and find each unique id TuioObject
|
||||
for (auto &&i : list) {
|
||||
bool sameId = false;
|
||||
// calculate centroid if multipleID
|
||||
if (list.size() > 1) {
|
||||
centroid = glm::vec2(0.0f, 0.0f);
|
||||
if (i->containsTuioPointer()) { // sanity check
|
||||
int id = i->getSessionID();
|
||||
for (auto &&j : group) // change to lambda/find function
|
||||
if (j->getSessionID() == id)
|
||||
sameId = true; // step out of for
|
||||
if (sameId) { // calculate a centroid
|
||||
for (auto &&j : group) {
|
||||
centroid.x += j->getTuioPointer()->getX();
|
||||
centroid.y += j->getTuioPointer()->getY();
|
||||
}
|
||||
centroid.x /= group.size();
|
||||
centroid.y /= group.size();
|
||||
}
|
||||
else
|
||||
group.push_back(i);
|
||||
|
||||
|
||||
for (auto &&i : list) {
|
||||
centroid.x += i->getX();
|
||||
centroid.y += i->getY();
|
||||
}
|
||||
}*/
|
||||
centroid.x /= list.size();
|
||||
centroid.y /= list.size();
|
||||
|
||||
//LINFO("List size: " << list.size() << ", Centroid: (" << centroid.x << ", " << centroid.y << ")" << "\n");
|
||||
}
|
||||
*/
|
||||
|
||||
//if (centroid.x + centroid.y != 0.0f)
|
||||
//LINFO("List size: " << list.size() << ", Centroid: (" << centroid.x << ", " << centroid.y << ")\n");
|
||||
// group
|
||||
glm::mat4 t;
|
||||
//OsEng.interactionHandler().camera()->rotate();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ Interpolator<double>& InteractionMode::rotateToFocusNodeInterpolator() {
|
||||
|
||||
|
||||
// KeyframeInteractionMode
|
||||
KeyframeInteractionMode::KeyframeInteractionMode(){
|
||||
KeyframeInteractionMode::KeyframeInteractionMode() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user