change TUIO protocol from v2.0 to v1.1 to support a wider range of sender applications

This commit is contained in:
Jonathan Bosson
2017-02-21 14:00:36 -07:00
parent 2d223dc250
commit c4bd08c19e
92 changed files with 5296 additions and 5454 deletions

View File

@@ -40,4 +40,4 @@ create_new_module(
${HEADER_FILES} ${SOURCE_FILES}
)
include_external_library(${touch_module} libTUIO2 ${CMAKE_CURRENT_SOURCE_DIR}/ext/libTUIO2)
include_external_library(${touch_module} libTUIO ${CMAKE_CURRENT_SOURCE_DIR}/ext/libTUIO)

View File

@@ -22,29 +22,33 @@
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
project(libTUIO2)
message(STATUS "Generating libTUIO2 project")
project(libTUIO)
message(STATUS "Generating libTUIO project")
add_library(libTUIO2
${PROJECT_SOURCE_DIR}/TUIO2/WebSockSender.cpp
${PROJECT_SOURCE_DIR}/TUIO2/UdpSender.cpp
${PROJECT_SOURCE_DIR}/TUIO2/UdpReceiver.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioToken.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioTime.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioSymbol.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioServer.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioPointer.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioPoint.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioObject.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioManager.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioDispatcher.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioComponent.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioClient.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TuioBounds.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TcpSender.cpp
${PROJECT_SOURCE_DIR}/TUIO2/TcpReceiver.cpp
${PROJECT_SOURCE_DIR}/TUIO2/OscReceiver.cpp
${PROJECT_SOURCE_DIR}/TUIO2/FlashSender.cpp
add_library(libTUIO
${PROJECT_SOURCE_DIR}/TUIO/WebSockSender.cpp
${PROJECT_SOURCE_DIR}/TUIO/UdpSender.cpp
${PROJECT_SOURCE_DIR}/TUIO/UdpReceiver.cpp
#${PROJECT_SOURCE_DIR}/TUIO2/TuioToken.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioTime.cpp
#${PROJECT_SOURCE_DIR}/TUIO2/TuioSymbol.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioServer.cpp
#${PROJECT_SOURCE_DIR}/TUIO2/TuioPointer.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioPoint.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioObject.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioManager.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioDispatcher.cpp
#${PROJECT_SOURCE_DIR}/TUIO2/TuioComponent.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioCursor.cpp #
${PROJECT_SOURCE_DIR}/TUIO/TuioContainer.cpp #
${PROJECT_SOURCE_DIR}/TUIO/TuioClient.cpp
#${PROJECT_SOURCE_DIR}/TUIO2/TuioBounds.cpp
${PROJECT_SOURCE_DIR}/TUIO/TuioBlob.cpp #
${PROJECT_SOURCE_DIR}/TUIO/TcpSender.cpp
${PROJECT_SOURCE_DIR}/TUIO/TcpReceiver.cpp
${PROJECT_SOURCE_DIR}/TUIO/OscReceiver.cpp
${PROJECT_SOURCE_DIR}/TUIO/OneEuroFilter.cpp #
${PROJECT_SOURCE_DIR}/TUIO/FlashSender.cpp
${PROJECT_SOURCE_DIR}/oscpack/ip/IpEndpointName.cpp
@@ -60,4 +64,4 @@ add_library(libTUIO2
${PROJECT_SOURCE_DIR}/oscpack/osc/OscPrintReceivedElements.cpp
${PROJECT_SOURCE_DIR}/oscpack/osc/OscOutboundPacketStream.cpp
)
target_include_directories(libTUIO2 PUBLIC ${PROJECT_SOURCE_DIR})
target_include_directories(libTUIO PUBLIC ${PROJECT_SOURCE_DIR})

View File

@@ -1,7 +1,7 @@
# Doxyfile 1.5.6
# Project related configuration options
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "TUIO2 C++ Developer API"
PROJECT_NAME = "TUIO C++ Developer API"
# Build related configuration options
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO

View File

@@ -614,7 +614,7 @@ errorReturn:
License along with this library.
*/
using namespace TUIO2;
using namespace TUIO;
FlashSender::FlashSender() {
local = true;
@@ -640,8 +640,8 @@ bool FlashSender::isConnected() {
}
bool FlashSender::sendOscPacket (osc::OutboundPacketStream *bundle) {
if (lcConnection==NULL)return false;
if (!TFLCSConnectionHasConnectedClient(lcConnection))return false;
if (lcConnection==NULL) return false;
if (!TFLCSConnectionHasConnectedClient(lcConnection)) return false;
if ( bundle->Size() > buffer_size ) return false;
if ( bundle->Size() == 0 ) return false;

View File

@@ -163,14 +163,14 @@ typedef DWORD u_int32_t;
#define DEFAULT_LC_CONN_NAME "_OscDataStream"
#define DEFAULT_LC_METH_NAME "receiveOscData"
namespace TUIO2 {
namespace TUIO {
/**
* The FlashSender implements the Flash LocalConnection transport method for OSC
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
* @version 1.1.6
*/
class LIBDECL FlashSender : public OscSender {
public:

View File

@@ -0,0 +1,66 @@
/* reacTIVision tangible interaction framework
Copyright (C) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
Based on an example by Nicolas Roussel <nicolas.roussel@inria.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "OneEuroFilter.h"
#define M_PI 3.14159265392
using namespace TUIO;
double LowPassFilter::filter(double value, double alpha) {
if (alpha<=0.0 || alpha>1.0)
throw std::range_error("alpha should be in (0.0., 1.0]");
double result;
if (initialized)
result = alpha*value + (1.0-alpha)*lastResult;
else {
result = value;
initialized = true;
}
lastRawValue = value;
lastResult = result;
return result;
}
// -----------------------------------------------------------------
double OneEuroFilter::alpha(double cutoff) {
double te = 1.0 / freq;
double tau = 1.0 / (2*M_PI*cutoff);
return 1.0 / (1.0 + tau/te);
}
double OneEuroFilter::filter(double value, TimeStamp timestamp) {
// update the sampling frequency based on timestamps
if (lasttime!=UndefinedTime && timestamp!=UndefinedTime)
freq = 1.0 / (timestamp-lasttime);
lasttime = timestamp;
// estimate the current variation per second
double dvalue = x->initialized ? (value - x->lastRawValue)*freq : value;
double edvalue;
try { edvalue = dx->filter(dvalue, alpha(dcutoff));
} catch (std::range_error e) { return value; }
// use it to update the cutoff frequency
double cutoff = mincutoff + beta*fabs(edvalue);
// filter the given value
return x->filter(value, alpha(cutoff));
}

View File

@@ -0,0 +1,90 @@
/* reacTIVision tangible interaction framework
Copyright (C) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
Based on an example by Nicolas Roussel <nicolas.roussel@inria.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ONEEUROFILTER
#define ONEEUROFILTER
#include <stdexcept>
#include <cmath>
typedef double TimeStamp; // in seconds
static const TimeStamp UndefinedTime = -1.0;
namespace TUIO {
class LowPassFilter {
public:
bool initialized;
double lastRawValue,lastResult;
LowPassFilter(double initval=0.0) {
lastRawValue = lastResult = initval;
initialized = false;
}
double filter(double value, double alpha);
};
// -----------------------------------------------------------------
class OneEuroFilter {
double freq;
double mincutoff;
double beta;
double dcutoff;
LowPassFilter *x;
LowPassFilter *dx;
TimeStamp lasttime;
double alpha(double cutoff);
public:
OneEuroFilter(double f, double mc=1.0, double b=0.0, double dc=1.0) {
if (f<=0) throw std::range_error("freq should be >0");
else freq = f;
if (mc<=0) throw std::range_error("mincutoff should be >0");
else mincutoff = mc;
if (b<=0) throw std::range_error("beta should be >0");
else beta = b;
if (dc<=0) throw std::range_error("dcutoff should be >0");
else dcutoff = dc;
x = new LowPassFilter(alpha(mincutoff));
dx = new LowPassFilter(alpha(dcutoff));
lasttime = UndefinedTime;
}
~OneEuroFilter(void) {
delete x;
delete dx;
}
double filter(double value, TimeStamp timestamp=UndefinedTime);
};
}
#endif

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,15 +18,15 @@
#include "OscReceiver.h"
using namespace TUIO2;
using namespace TUIO;
using namespace osc;
void OscReceiver::ProcessMessage( const ReceivedMessage& msg, const IpEndpointName& remoteEndpoint) {
for (std::list<TuioClient*>::iterator client=clientList.begin(); client!= clientList.end(); client++)
for (std::list<TuioClient*>::iterator client=clientList.begin(); client!= clientList.end(); client++)
(*client)->processOSC(msg);
}
void OscReceiver::ProcessBundle( const ReceivedBundle& b, const IpEndpointName& remoteEndpoint) {
try {
for( ReceivedBundle::const_iterator i = b.ElementsBegin(); i != b.ElementsEnd(); ++i ){
if( i->IsBundle() )

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,7 @@
#include "oscpack/ip/PacketListener.h"
#include "oscpack/ip/IpEndpointName.h"
namespace TUIO2 {
namespace TUIO {
class TuioClient; // Forward declaration
@@ -35,7 +35,7 @@ namespace TUIO2 {
* The OscReceiver is the base class for the various OSC transport methods such as UDP, TCP ...
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
* @version 1.1.6
*/
class LIBDECL OscReceiver: public PacketListener {

View File

@@ -1,5 +1,5 @@
/*
TUIO2 C++ Library
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
@@ -26,14 +26,14 @@
#include <iostream>
#include <cstring>
namespace TUIO2 {
namespace TUIO {
/**
* The OscSender class is the base class for the various OSC transport methods such as UDP, TCP ...
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
* @version 1.1.6
*/
class LIBDECL OscSender {
public:

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,7 @@
#include "TcpReceiver.h"
using namespace TUIO2;
using namespace TUIO;
using namespace osc;
// workaround for connect method name conflict
@@ -39,6 +39,7 @@ static void* ClientThreadFunc( void* obj )
TcpReceiver *sender = static_cast<TcpReceiver*>(obj);
char data_buffer[MAX_TCP_SIZE+4];
char data_size[4];
int32_t bundle_size;
#ifdef WIN32
SOCKET client = sender->tcp_client_list.back();
@@ -53,15 +54,15 @@ static void* ClientThreadFunc( void* obj )
if (bytes>=4) {
memcpy(&data_size[0],&data_buffer[0], 4);
#ifdef OSC_HOST_LITTLE_ENDIAN
int32_t temp = (int32_t)(*data_size);
data_size[0] = temp>>24;
data_size[1] = (temp>>16) & 255;
data_size[2] = (temp>>8) & 255;
data_size[3] = (temp) & 255;
bundle_size = 0xFF & data_size[3];
bundle_size |= (0xFF & data_size[2]) << 8;
bundle_size |= (0xFF & data_size[1]) << 16;
bundle_size |= (int32_t)(0xFF & data_size[0]) << 24;
#else
bundle_size = (int32_t)(*data_size);
#endif
int32_t size = (int32_t)(*data_size);
if (size+4==bytes) {
sender->ProcessPacket(&data_buffer[4],(int)size,IpEndpointName());
if (bundle_size+4==bytes) {
sender->ProcessPacket(&data_buffer[4],(int)bundle_size,IpEndpointName());
}
}
}
@@ -113,7 +114,7 @@ static DWORD WINAPI ServerThreadFunc( LPVOID obj )
return 0;
};
TcpReceiver::TcpReceiver(unsigned short port)
TcpReceiver::TcpReceiver(int port)
: tcp_socket (-1)
, locked (false)
{
@@ -161,7 +162,7 @@ TcpReceiver::TcpReceiver(unsigned short port)
std::cout << "TUIO/TCP socket created on port " << port << std::endl;
}
TcpReceiver::TcpReceiver(const char *host, unsigned short port)
TcpReceiver::TcpReceiver(const char *host, int port)
: tcp_socket (-1)
, locked (false)
{

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -35,13 +35,13 @@ typedef int socklen_t;
#include <unistd.h>
#endif
namespace TUIO2 {
namespace TUIO {
/**
* The TcpReceiver provides the OscReceiver functionality for the TCP transport method
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
* @version 1.1.6
*/
class LIBDECL TcpReceiver: public OscReceiver {
@@ -52,7 +52,7 @@ namespace TUIO2 {
*
* @param port the number of the TCP port to listen to, defaults to 3333
*/
TcpReceiver (unsigned short port=3333);
TcpReceiver (int port=3333);
/**
* This constructor creates a TcpReceiver connected to the provided host and TCP port
@@ -60,7 +60,7 @@ namespace TUIO2 {
* @param host the host name to connect
* @param port the number of the TCP port to listen to, defaults to 3333
*/
TcpReceiver (const char *host, unsigned short port);
TcpReceiver (const char *host, int port);
/**
* The destructor is doing nothing in particular.

View File

@@ -17,7 +17,7 @@
*/
#include "TcpSender.h"
using namespace TUIO2;
using namespace TUIO;
#ifndef WIN32
static void* ClientThreadFunc( void* obj )

View File

@@ -37,14 +37,14 @@ typedef int socklen_t;
#include <list>
#define MAX_TCP_SIZE 65536
namespace TUIO2 {
namespace TUIO {
/**
* The TcpSender implements the TCP transport method for OSC
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
*/
class LIBDECL TcpSender : public OscSender {
public:

View File

@@ -0,0 +1,253 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioBlob.h"
using namespace TUIO;
TuioBlob::TuioBlob (TuioTime ttime, long si, int bi, float xp, float yp, float a, float w, float h, float f):TuioContainer(ttime, si, xp, yp) {
blob_id = bi;
angle = a;
angle_sum = a;
width = w;
height = h;
area = f;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
angleFilter = NULL;
angleThreshold = 0.0f;
widthFilter = NULL;
heightFilter = NULL;
sizeThreshold = 0.0f;
}
TuioBlob::TuioBlob (long si, int bi, float xp, float yp, float a, float w, float h, float f):TuioContainer(si, xp, yp) {
blob_id = bi;
angle = a;
angle_sum = a;
width = w;
height = h;
area = f;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
angleFilter = NULL;
angleThreshold = 0.0f;
widthFilter = NULL;
heightFilter = NULL;
sizeThreshold = 0.0f;
}
TuioBlob::TuioBlob (TuioBlob *tblb):TuioContainer(tblb) {
blob_id = tblb->getBlobID();
angle = tblb->getAngle();
angle_sum = tblb->getAngleSum();
width = tblb->getWidth();
height = tblb->getHeight();
area = tblb->getArea();
rotation_speed = 0.0f;
rotation_accel = 0.0f;
angleFilter = NULL;
angleThreshold = 0.0f;
widthFilter = NULL;
heightFilter = NULL;
sizeThreshold = 0.0f;
}
int TuioBlob::getBlobID() const{
return blob_id;
}
void TuioBlob::setBlobID(long b_id) {
blob_id = b_id;
}
void TuioBlob::update (TuioTime ttime, float xp, float yp, float a, float w, float h, float f, float xs, float ys, float rs, float ma, float ra) {
TuioContainer::update(ttime,xp,yp,xs,ys,ma);
angle = a;
angle_sum = a;
width = w;
height = h;
area = f;
rotation_speed = rs;
rotation_accel = ra;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void TuioBlob::update (float xp, float yp, float a, float w, float h, float f, float xs, float ys, float rs, float ma, float ra) {
TuioContainer::update(xp,yp,xs,ys,ma);
angle = a;
angle_sum = a;
width = w;
height = h;
area = f;
rotation_speed = rs;
rotation_accel = ra;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void TuioBlob::update (TuioTime ttime, float xp, float yp, float a, float w, float h, float f) {
TuioPoint lastPoint = path.back();
TuioContainer::update(ttime,xp,yp);
TuioTime diffTime = currentTime - lastPoint.getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
float last_rotation_speed = rotation_speed;
float prev_angle = angle_sum;
float da = a-angle;
if (da > M_PI/2.0f) angle_sum += (da-2*M_PI);
else if (da < M_PI/-2.0f) angle_sum += (da+2*M_PI);
else angle_sum += da;
if (angleFilter) angle_sum = angleFilter->filter(angle_sum,dt);
if (fabs(angle_sum-prev_angle)<angleThreshold) angle_sum = prev_angle;
int m = floor(angle_sum/(2*M_PI));
angle = angle_sum-(m*(2*M_PI));
da = (angle-a)/(2*M_PI);
if (da > 0.75f) da-=1.0f;
else if (da < -0.75f) da+=1.0f;
if (widthFilter && heightFilter) {
w = widthFilter->filter(w,dt);
h = heightFilter->filter(h,dt);
}
float dw = fabs(width - w);
float dh = fabs(height - h);
if ((dw>sizeThreshold) || (dh>sizeThreshold)) {
width = w;
height = h;
}
area = f;
rotation_speed = (float)da/dt;
rotation_accel = (rotation_speed - last_rotation_speed)/dt;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void TuioBlob::stop (TuioTime ttime) {
update(ttime,xpos,ypos,angle,width,height,area);
}
void TuioBlob::update (TuioBlob *tblb) {
TuioContainer::update(tblb);
angle = tblb->getAngle();
angle = tblb->getAngleSum();
width = tblb->getWidth();
height = tblb->getHeight();
area = tblb->getArea();
rotation_speed = tblb->getRotationSpeed();
rotation_accel = tblb->getRotationAccel();
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
float TuioBlob::getWidth() const{
return width;
}
float TuioBlob::getHeight() const{
return height;
}
int TuioBlob::getScreenWidth(int w) const{
return (int)(w*width);
}
int TuioBlob::getScreenHeight(int h) const{
return (int)(h*height);
}
float TuioBlob::getArea() const{
return area;
}
float TuioBlob::getAngle() const{
return angle;
}
float TuioBlob::getAngleSum() const{
return angle_sum;
}
float TuioBlob::getAngleDegrees() const{
return (float)(angle/M_PI*180);
}
float TuioBlob::getRotationSpeed() const{
return rotation_speed;
}
float TuioBlob::getRotationAccel() const{
return rotation_accel;
}
bool TuioBlob::isMoving() const{
if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
else return false;
}
void TuioBlob::addAngleThreshold(float thresh) {
angleThreshold = thresh;
}
void TuioBlob::removeAngleThreshold() {
angleThreshold = 0.0f;
}
void TuioBlob::addAngleFilter(float mcut, float beta) {
if (angleFilter) delete angleFilter;
angleFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
}
void TuioBlob::removeAngleFilter() {
if (angleFilter) delete angleFilter;
angleFilter = NULL;
}
void TuioBlob::addSizeThreshold(float thresh) {
sizeThreshold = thresh;
}
void TuioBlob::removeSizeThreshold() {
sizeThreshold = 0.0f;
}
void TuioBlob::addSizeFilter(float mcut, float beta) {
if (widthFilter) delete widthFilter;
widthFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
if (heightFilter) delete heightFilter;
heightFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
}
void TuioBlob::removeSizeFilter() {
if (widthFilter) delete widthFilter;
widthFilter = NULL;
if (heightFilter) delete heightFilter;
heightFilter = NULL;
}

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,27 +16,34 @@
License along with this library.
*/
#ifndef INCLUDED_TUIOBOUNDS_H
#define INCLUDED_TUIOBOUNDS_H
#ifndef INCLUDED_TUIOBLOB_H
#define INCLUDED_TUIOBLOB_H
#include "TuioComponent.h"
#include "TuioContainer.h"
namespace TUIO2 {
namespace TUIO {
/**
* The TuioBounds class encapsulates /tuio2/bnd TUIO boundary ellipses.
* The TuioBlob class encapsulates /tuio/2Dblb TUIO objects.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioBounds: public TuioComponent {
* @version 1.1.6
*/
class LIBDECL TuioBlob: public TuioContainer {
protected:
/**
* The individual blob ID number that is assigned to each TuioBlob.
*/
int blob_id;
/**
* The rotation angle value.
*/
float angle;
/**
* The accumulated angle value.
*/
float angle_sum;
/**
* The width value.
*/
@@ -58,15 +65,21 @@ namespace TUIO2 {
*/
float rotation_accel;
public:
using TuioComponent::update;
float angleThreshold;
OneEuroFilter *angleFilter;
float sizeThreshold;
OneEuroFilter *widthFilter;
OneEuroFilter *heightFilter;
public:
using TuioContainer::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, X and Y coordinate, width, height and angle to the newly created TuioBounds.
* Session ID, X and Y coordinate, width, height and angle to the newly created TuioBlob.
*
* @param ttime the TuioTime to assign
* @param tobj the TuioObject to assign
* @param si the Session ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
@@ -74,39 +87,55 @@ namespace TUIO2 {
* @param h the height to assign
* @param f the area to assign
*/
TuioBounds (TuioTime ttime, TuioObject *tobj, float xp, float yp, float a, float w, float h, float f);
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, X and Y coordinate, width, height and angle to the newly created TuioBounds.
*
* @param tobj the TuioObject to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param w the width to assign
* @param h the height to assign
* @param f the area to assign
*/
TuioBounds (TuioObject *tobj, float xp, float yp, float a, float w, float h, float f);
TuioBlob (TuioTime ttime, long si, int bi, float xp, float yp, float a, float w, float h, float f);
/**
* This constructor takes the provided Session ID, X and Y coordinate
* width, height and angle, and assigs these values to the newly created TuioBlob.
*
* @param si the Session ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param w the width to assign
* @param h the height to assign
* @param f the area to assign
*/
TuioBlob (long si, int bi, float xp, float yp, float a, float w, float h, float f);
/**
* This constructor takes the atttibutes of the provided TuioBounds
* and assigs these values to the newly created TuioBounds.
* This constructor takes the atttibutes of the provided TuioBlob
* and assigs these values to the newly created TuioBlob.
*
* @param tbnd the TuioBounds to assign
* @param tblb the TuioBlob to assign
*/
TuioBounds (TuioBounds *tbnd);
TuioBlob (TuioBlob *tblb);
/**
* The destructor is doing nothing in particular.
*/
~TuioBounds() {};
virtual ~TuioBlob() {
if (widthFilter) delete widthFilter;
if (heightFilter) delete heightFilter;
if (angleFilter) delete angleFilter;
};
/**
* Returns the Blob ID of this TuioBlob.
* @return the Blob ID of this TuioBlob
*/
int getBlobID() const;
/**
* Sets the Blob ID of this TuioBlob.
* @param b_id the new Blob ID for this TuioBlob
*/
void setBlobID(long b_id);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate, angle, X and Y velocity, motion acceleration,
* rotation speed and rotation acceleration to the private TuioBounds attributes.
* rotation speed and rotation acceleration to the private TuioBlob attributes.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
@@ -125,7 +154,7 @@ namespace TUIO2 {
/**
* Assigns the provided X and Y coordinate, angle, X and Y velocity, motion acceleration
* rotation velocity and rotation acceleration to the private TuioComponent attributes.
* rotation velocity and rotation acceleration to the private TuioContainer attributes.
* The TuioTime time stamp remains unchanged.
*
* @param xp the X coordinate to assign
@@ -144,7 +173,7 @@ namespace TUIO2 {
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate and angle to the private TuioBounds attributes.
* X and Y coordinate and angle to the private TuioBlob attributes.
* The speed and accleration values are calculated accordingly.
*
* @param ttime the TuioTime to assign
@@ -159,48 +188,100 @@ namespace TUIO2 {
/**
* This method is used to calculate the speed and acceleration values of a
* TuioBounds with unchanged position and angle.
* TuioBlob with unchanged position and angle.
*/
void stop (TuioTime ttime);
/**
* Takes the atttibutes of the provided TuioBounds
* and assigs these values to this TuioBounds.
* The TuioTime time stamp of this TuioComponent remains unchanged.
* Takes the atttibutes of the provided TuioBlob
* and assigs these values to this TuioBlob.
* The TuioTime time stamp of this TuioContainer remains unchanged.
*
* @param tbnd the TuioComponent to assign
* @param tblb the TuioContainer to assign
*/
void update (TuioBounds *tbnd);
void update (TuioBlob *tblb);
/**
* Returns the width of this TuioBounds.
* @return the width of this TuioBounds
* Returns the width of this TuioBlob.
* @return the width of this TuioBlob
*/
float getWidth() const;
/**
* Returns the height of this TuioBounds.
* @return the height of this TuioBounds
* Returns the height of this TuioBlob.
* @return the height of this TuioBlob
*/
float getHeight() const;
/**
* Returns the width of this TuioBounds.
* @return the width of this TuioBounds
* Returns the width of this TuioBlob.
* @return the width of this TuioBlob
*/
int getScreenWidth(int w) const;
/**
* Returns the height of this TuioBounds.
* @return the height of this TuioBounds
* Returns the height of this TuioBlob.
* @return the height of this TuioBlob
*/
int getScreenHeight(int h) const;
/**
* Returns the area of this TuioBounds.
* @return the area of this TuioBounds
* Returns the area of this TuioBlob.
* @return the area of this TuioBlob
*/
float getArea() const;
/**
* Returns the rotation angle of this TuioBlob.
* @return the rotation angle of this TuioBlob
*/
float getAngle() const;
/**
* Returns the accumulated rotation angle of this TuioBlob.
* @return the accumulated rotation angle of this TuioBlob
*/
float getAngleSum() const;
/**
* Returns the rotation angle in degrees of this TuioBlob.
* @return the rotation angle in degrees of this TuioBlob
*/
float getAngleDegrees() const;
/**
* Returns the rotation speed of this TuioBlob.
* @return the rotation speed of this TuioBlob
*/
float getRotationSpeed() const;
/**
* Returns the rotation acceleration of this TuioBlob.
* @return the rotation acceleration of this TuioBlob
*/
float getRotationAccel() const;
/**
* Returns true of this TuioBlob is moving.
* @return true of this TuioBlob is moving
*/
bool isMoving() const;
void addAngleThreshold(float thresh);
void removeAngleThreshold();
void addAngleFilter(float mcut, float beta);
void removeAngleFilter();
void addSizeThreshold(float thresh);
void removeSizeThreshold();
void addSizeFilter(float mcut, float beta);
void removeSizeFilter();
};
}
#endif

View File

@@ -0,0 +1,849 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioClient.h"
#include "UdpReceiver.h"
using namespace TUIO;
using namespace osc;
TuioClient::TuioClient()
: currentFrame (-1)
, source_id (0)
, source_name (NULL)
, source_addr (NULL)
, local_receiver(true)
{
receiver = new UdpReceiver();
initialize();
}
TuioClient::TuioClient(int port)
: currentFrame (-1)
, source_id (0)
, source_name (NULL)
, source_addr (NULL)
, local_receiver(true)
{
receiver = new UdpReceiver(port);
initialize();
}
TuioClient::TuioClient(OscReceiver *osc)
: currentFrame (-1)
, source_id (0)
, source_name (NULL)
, source_addr (NULL)
, receiver (osc)
, local_receiver(false)
{
initialize();
}
void TuioClient::initialize() {
receiver->addTuioClient(this);
maxCursorID[source_id] = -1;
maxBlobID[source_id] = -1;
}
TuioClient::~TuioClient() {
if (local_receiver) delete receiver;
}
void TuioClient::processOSC( const ReceivedMessage& msg ) {
try {
ReceivedMessageArgumentStream args = msg.ArgumentStream();
//ReceivedMessage::const_iterator arg = msg.ArgumentsBegin();
if( strcmp( msg.AddressPattern(), "/tuio/2Dobj" ) == 0 ){
const char* cmd;
args >> cmd;
if (strcmp(cmd,"source")==0) {
const char* src;
args >> src;
source_name = strtok((char*)src, "@");
char *addr = strtok(NULL, "@");
if (addr!=NULL) source_addr = addr;
else source_addr = (char*)"localhost";
// check if we know that source
std::string source_str(src);
std::map<std::string,int>::iterator iter = sourceList.find(source_str);
// add a new source
if (iter==sourceList.end()) {
source_id = sourceList.size();
sourceList[source_str] = source_id;
} else {
// use the found source_id
source_id = sourceList[source_str];
}
} else if (strcmp(cmd,"set")==0) {
int32 s_id, c_id;
float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
args >> s_id >> c_id >> xpos >> ypos >> angle >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
lockObjectList();
std::list<TuioObject*>::iterator tobj;
for (tobj=objectList.begin(); tobj!= objectList.end(); tobj++)
if((*tobj)->getSessionID()==(long)s_id) break;
if (tobj == objectList.end()) {
TuioObject *addObject = new TuioObject((long)s_id,(int)c_id,xpos,ypos,angle);
frameObjects.push_back(addObject);
} else if ( ((*tobj)->getX()!=xpos) || ((*tobj)->getY()!=ypos) || ((*tobj)->getAngle()!=angle) || ((*tobj)->getXSpeed()!=xspeed) || ((*tobj)->getYSpeed()!=yspeed) || ((*tobj)->getRotationSpeed()!=rspeed) || ((*tobj)->getMotionAccel()!=maccel) || ((*tobj)->getRotationAccel()!=raccel) ) {
TuioObject *updateObject = new TuioObject((long)s_id,(*tobj)->getSymbolID(),xpos,ypos,angle);
updateObject->update(xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
frameObjects.push_back(updateObject);
}
unlockObjectList();
} else if (strcmp(cmd,"alive")==0) {
int32 s_id;
aliveObjectList.clear();
while(!args.Eos()) {
args >> s_id;
aliveObjectList.push_back((long)s_id);
}
} else if (strcmp(cmd,"fseq")==0) {
int32 fseq;
args >> fseq;
bool lateFrame = false;
if (fseq>0) {
if (fseq>currentFrame) currentTime = TuioTime::getSessionTime();
if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
else lateFrame = true;
} else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100) {
currentTime = TuioTime::getSessionTime();
}
if (!lateFrame) {
lockObjectList();
//find the removed objects first
for (std::list<TuioObject*>::iterator tobj=objectList.begin(); tobj != objectList.end(); tobj++) {
if ((*tobj)->getTuioSourceID()==source_id) {
std::list<long>::iterator iter = find(aliveObjectList.begin(), aliveObjectList.end(), (*tobj)->getSessionID());
if (iter == aliveObjectList.end()) {
(*tobj)->remove(currentTime);
frameObjects.push_back(*tobj);
}
}
}
unlockObjectList();
for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
TuioObject *tobj = (*iter);
TuioObject *frameObject = NULL;
switch (tobj->getTuioState()) {
case TUIO_REMOVED:
frameObject = tobj;
frameObject->remove(currentTime);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioObject(frameObject);
lockObjectList();
for (std::list<TuioObject*>::iterator delobj=objectList.begin(); delobj!=objectList.end(); delobj++) {
if((*delobj)->getSessionID()==frameObject->getSessionID()) {
objectList.erase(delobj);
break;
}
}
unlockObjectList();
break;
case TUIO_ADDED:
lockObjectList();
frameObject = new TuioObject(currentTime,tobj->getSessionID(),tobj->getSymbolID(),tobj->getX(),tobj->getY(),tobj->getAngle());
if (source_name) frameObject->setTuioSource(source_id,source_name,source_addr);
objectList.push_back(frameObject);
unlockObjectList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioObject(frameObject);
break;
default:
lockObjectList();
std::list<TuioObject*>::iterator iter;
for (iter=objectList.begin(); iter != objectList.end(); iter++) {
if (((*iter)->getTuioSourceID()==source_id) && ((*iter)->getSessionID()==tobj->getSessionID())) {
frameObject = (*iter);
break;
}
}
if (iter==objectList.end()) {
unlockObjectList();
break;
}
if ( (tobj->getX()!=frameObject->getX() && tobj->getXSpeed()==0) || (tobj->getY()!=frameObject->getY() && tobj->getYSpeed()==0) )
frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle());
else
frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle(),tobj->getXSpeed(),tobj->getYSpeed(),tobj->getRotationSpeed(),tobj->getMotionAccel(),tobj->getRotationAccel());
unlockObjectList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioObject(frameObject);
}
delete tobj;
}
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->refresh(currentTime);
} else {
for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
TuioObject *tobj = (*iter);
delete tobj;
}
}
frameObjects.clear();
}
} else if( strcmp( msg.AddressPattern(), "/tuio/2Dcur" ) == 0 ) {
const char* cmd;
args >> cmd;
if (strcmp(cmd,"source")==0) {
const char* src;
args >> src;
source_name = strtok((char*)src, "@");
char *addr = strtok(NULL, "@");
if (addr!=NULL) source_addr = addr;
else source_addr = (char*)"localhost";
// check if we know that source
std::string source_str(src);
std::map<std::string,int>::iterator iter = sourceList.find(source_str);
// add a new source
if (iter==sourceList.end()) {
source_id = sourceList.size();
sourceList[source_str] = source_id;
maxCursorID[source_id] = -1;
} else {
// use the found source_id
source_id = sourceList[source_str];
}
} else if (strcmp(cmd,"set")==0) {
int32 s_id;
float xpos, ypos, xspeed, yspeed, maccel;
args >> s_id >> xpos >> ypos >> xspeed >> yspeed >> maccel;
lockCursorList();
std::list<TuioCursor*>::iterator tcur;
for (tcur=cursorList.begin(); tcur!= cursorList.end(); tcur++)
if (((*tcur)->getSessionID()==(long)s_id) && ((*tcur)->getTuioSourceID()==source_id)) break;
if (tcur==cursorList.end()) {
TuioCursor *addCursor = new TuioCursor((long)s_id,-1,xpos,ypos);
frameCursors.push_back(addCursor);
} else if ( ((*tcur)->getX()!=xpos) || ((*tcur)->getY()!=ypos) || ((*tcur)->getXSpeed()!=xspeed) || ((*tcur)->getYSpeed()!=yspeed) || ((*tcur)->getMotionAccel()!=maccel) ) {
TuioCursor *updateCursor = new TuioCursor((long)s_id,(*tcur)->getCursorID(),xpos,ypos);
updateCursor->update(xpos,ypos,xspeed,yspeed,maccel);
frameCursors.push_back(updateCursor);
}
unlockCursorList();
} else if (strcmp(cmd,"alive")==0) {
int32 s_id;
aliveCursorList.clear();
while(!args.Eos()) {
args >> s_id;
aliveCursorList.push_back((long)s_id);
}
} else if( strcmp( cmd, "fseq" ) == 0 ) {
int32 fseq;
args >> fseq;
bool lateFrame = false;
if (fseq>0) {
if (fseq>currentFrame) currentTime = TuioTime::getSessionTime();
if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
else lateFrame = true;
} else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100) {
currentTime = TuioTime::getSessionTime();
}
if (!lateFrame) {
lockCursorList();
// find the removed cursors first
for (std::list<TuioCursor*>::iterator tcur=cursorList.begin(); tcur != cursorList.end(); tcur++) {
if ((*tcur)->getTuioSourceID()==source_id) {
std::list<long>::iterator iter = find(aliveCursorList.begin(), aliveCursorList.end(), (*tcur)->getSessionID());
if (iter == aliveCursorList.end()) {
(*tcur)->remove(currentTime);
frameCursors.push_back(*tcur);
}
}
}
unlockCursorList();
for (std::list<TuioCursor*>::iterator iter=frameCursors.begin(); iter != frameCursors.end(); iter++) {
TuioCursor *tcur = (*iter);
int c_id = 0;
int free_size = 0;
TuioCursor *frameCursor = NULL;
switch (tcur->getTuioState()) {
case TUIO_REMOVED:
frameCursor = tcur;
frameCursor->remove(currentTime);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioCursor(frameCursor);
lockCursorList();
for (std::list<TuioCursor*>::iterator delcur=cursorList.begin(); delcur!=cursorList.end(); delcur++) {
if(((*delcur)->getTuioSourceID()==source_id) && ((*delcur)->getSessionID()==frameCursor->getSessionID())) {
cursorList.erase(delcur);
break;
}
}
if (frameCursor->getCursorID()==maxCursorID[source_id]) {
maxCursorID[source_id] = -1;
delete frameCursor;
if (cursorList.size()>0) {
std::list<TuioCursor*>::iterator clist;
for (clist=cursorList.begin(); clist != cursorList.end(); clist++) {
if ((*clist)->getTuioSourceID()==source_id) {
c_id = (*clist)->getCursorID();
if (c_id>maxCursorID[source_id]) maxCursorID[source_id]=c_id;
}
}
freeCursorBuffer.clear();
for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) {
TuioCursor *freeCursor = (*flist);
if (freeCursor->getTuioSourceID()==source_id) {
if (freeCursor->getCursorID()>maxCursorID[source_id]) delete freeCursor;
else freeCursorBuffer.push_back(freeCursor);
} else freeCursorBuffer.push_back(freeCursor);
}
freeCursorList = freeCursorBuffer;
} else {
freeCursorBuffer.clear();
for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) {
TuioCursor *freeCursor = (*flist);
if (freeCursor->getTuioSourceID()==source_id) delete freeCursor;
else freeCursorBuffer.push_back(freeCursor);
}
freeCursorList = freeCursorBuffer;
}
} else if (frameCursor->getCursorID()<maxCursorID[source_id]) {
freeCursorList.push_back(frameCursor);
}
unlockCursorList();
break;
case TUIO_ADDED:
lockCursorList();
for(std::list<TuioCursor*>::iterator iter = cursorList.begin();iter!= cursorList.end(); iter++)
if ((*iter)->getTuioSourceID()==source_id) c_id++;
for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin();iter!= freeCursorList.end(); iter++)
if ((*iter)->getTuioSourceID()==source_id) free_size++;
if ((free_size<=maxCursorID[source_id]) && (free_size>0)) {
std::list<TuioCursor*>::iterator closestCursor = freeCursorList.begin();
for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin();iter!= freeCursorList.end(); iter++) {
if (((*iter)->getTuioSourceID()==source_id) && ((*iter)->getDistance(tcur)<(*closestCursor)->getDistance(tcur))) closestCursor = iter;
}
if (closestCursor!=freeCursorList.end()) {
TuioCursor *freeCursor = (*closestCursor);
c_id = freeCursor->getCursorID();
freeCursorList.erase(closestCursor);
delete freeCursor;
}
} else maxCursorID[source_id] = c_id;
frameCursor = new TuioCursor(currentTime,tcur->getSessionID(),c_id,tcur->getX(),tcur->getY());
if (source_name) frameCursor->setTuioSource(source_id,source_name,source_addr);
cursorList.push_back(frameCursor);
delete tcur;
unlockCursorList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioCursor(frameCursor);
break;
default:
lockCursorList();
std::list<TuioCursor*>::iterator iter;
for (iter=cursorList.begin(); iter != cursorList.end(); iter++) {
if (((*iter)->getTuioSourceID()==source_id) && ((*iter)->getSessionID()==tcur->getSessionID())) {
frameCursor = (*iter);
break;
}
}
if (iter==cursorList.end()) {
unlockCursorList();
break;
}
if ( (tcur->getX()!=frameCursor->getX() && tcur->getXSpeed()==0) || (tcur->getY()!=frameCursor->getY() && tcur->getYSpeed()==0) )
frameCursor->update(currentTime,tcur->getX(),tcur->getY());
else
frameCursor->update(currentTime,tcur->getX(),tcur->getY(),tcur->getXSpeed(),tcur->getYSpeed(),tcur->getMotionAccel());
delete tcur;
unlockCursorList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioCursor(frameCursor);
}
}
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->refresh(currentTime);
} else {
for (std::list<TuioCursor*>::iterator iter=frameCursors.begin(); iter != frameCursors.end(); iter++) {
TuioCursor *tcur = (*iter);
delete tcur;
}
}
frameCursors.clear();
}
} else if( strcmp( msg.AddressPattern(), "/tuio/2Dblb" ) == 0 ){
const char* cmd;
args >> cmd;
if (strcmp(cmd,"source")==0) {
const char* src;
args >> src;
source_name = strtok((char*)src, "@");
char *addr = strtok(NULL, "@");
if (addr!=NULL) source_addr = addr;
else source_addr = (char*)"localhost";
// check if we know that source
std::string source_str(src);
std::map<std::string,int>::iterator iter = sourceList.find(source_str);
// add a new source
if (iter==sourceList.end()) {
source_id = sourceList.size();
sourceList[source_str] = source_id;
maxBlobID[source_id] = -1;
} else {
// use the found source_id
source_id = sourceList[source_str];
}
} else if (strcmp(cmd,"set")==0) {
int32 s_id;
float xpos, ypos, angle, width, height, area, xspeed, yspeed, rspeed, maccel, raccel;
args >> s_id >> xpos >> ypos >> angle >> width >> height >> area >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
lockBlobList();
std::list<TuioBlob*>::iterator tblb;
for (tblb=blobList.begin(); tblb!= blobList.end(); tblb++)
if((*tblb)->getSessionID()==(long)s_id) break;
if (tblb==blobList.end()) {
TuioBlob *addBlob = new TuioBlob((long)s_id,-1,xpos,ypos,angle,width,height,area);
frameBlobs.push_back(addBlob);
} else if ( ((*tblb)->getX()!=xpos) || ((*tblb)->getY()!=ypos) || ((*tblb)->getAngle()!=angle) || ((*tblb)->getWidth()!=width) || ((*tblb)->getHeight()!=height) || ((*tblb)->getArea()!=area) || ((*tblb)->getXSpeed()!=xspeed) || ((*tblb)->getYSpeed()!=yspeed) || ((*tblb)->getMotionAccel()!=maccel) ) {
TuioBlob *updateBlob = new TuioBlob((long)s_id,(*tblb)->getBlobID(),xpos,ypos,angle,width,height,area);
updateBlob->update(xpos,ypos,angle,width,height,area,xspeed,yspeed,rspeed,maccel,raccel);
frameBlobs.push_back(updateBlob);
}
unlockBlobList();
} else if (strcmp(cmd,"alive")==0) {
int32 s_id;
aliveBlobList.clear();
while(!args.Eos()) {
args >> s_id;
aliveBlobList.push_back((long)s_id);
}
} else if( strcmp( cmd, "fseq" ) == 0 ) {
int32 fseq;
args >> fseq;
bool lateFrame = false;
if (fseq>0) {
if (fseq>currentFrame) currentTime = TuioTime::getSessionTime();
if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
else lateFrame = true;
} else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100) {
currentTime = TuioTime::getSessionTime();
}
if (!lateFrame) {
lockBlobList();
// find the removed blobs first
for (std::list<TuioBlob*>::iterator tblb=blobList.begin(); tblb != blobList.end(); tblb++) {
if ((*tblb)->getTuioSourceID()==source_id) {
std::list<long>::iterator iter = find(aliveBlobList.begin(), aliveBlobList.end(), (*tblb)->getSessionID());
if (iter == aliveBlobList.end()) {
(*tblb)->remove(currentTime);
frameBlobs.push_back(*tblb);
}
}
}
unlockBlobList();
for (std::list<TuioBlob*>::iterator iter=frameBlobs.begin(); iter != frameBlobs.end(); iter++) {
TuioBlob *tblb = (*iter);
int b_id = 0;
int free_size = 0;
TuioBlob *frameBlob = NULL;
switch (tblb->getTuioState()) {
case TUIO_REMOVED:
frameBlob = tblb;
frameBlob->remove(currentTime);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioBlob(frameBlob);
lockBlobList();
for (std::list<TuioBlob*>::iterator delblb=blobList.begin(); delblb!=blobList.end(); delblb++) {
if(((*delblb)->getTuioSourceID()==source_id) && ((*delblb)->getSessionID()==frameBlob->getSessionID())) {
blobList.erase(delblb);
break;
}
}
if (frameBlob->getBlobID()==maxBlobID[source_id]) {
maxBlobID[source_id] = -1;
delete frameBlob;
if (blobList.size()>0) {
std::list<TuioBlob*>::iterator clist;
for (clist=blobList.begin(); clist != blobList.end(); clist++) {
if ((*clist)->getTuioSourceID()==source_id) {
b_id = (*clist)->getBlobID();
if (b_id>maxBlobID[source_id]) maxBlobID[source_id]=b_id;
}
}
freeBlobBuffer.clear();
for (std::list<TuioBlob*>::iterator flist=freeBlobList.begin(); flist != freeBlobList.end(); flist++) {
TuioBlob *freeBlob = (*flist);
if (freeBlob->getTuioSourceID()==source_id) {
if (freeBlob->getBlobID()>maxBlobID[source_id]) delete freeBlob;
else freeBlobBuffer.push_back(freeBlob);
} else freeBlobBuffer.push_back(freeBlob);
}
freeBlobList = freeBlobBuffer;
} else {
freeBlobBuffer.clear();
for (std::list<TuioBlob*>::iterator flist=freeBlobList.begin(); flist != freeBlobList.end(); flist++) {
TuioBlob *freeBlob = (*flist);
if (freeBlob->getTuioSourceID()==source_id) delete freeBlob;
else freeBlobBuffer.push_back(freeBlob);
}
freeBlobList = freeBlobBuffer;
}
} else if (frameBlob->getBlobID()<maxBlobID[source_id]) {
freeBlobList.push_back(frameBlob);
}
unlockBlobList();
break;
case TUIO_ADDED:
lockBlobList();
for(std::list<TuioBlob*>::iterator iter = blobList.begin();iter!= blobList.end(); iter++)
if ((*iter)->getTuioSourceID()==source_id) b_id++;
for(std::list<TuioBlob*>::iterator iter = freeBlobList.begin();iter!= freeBlobList.end(); iter++)
if ((*iter)->getTuioSourceID()==source_id) free_size++;
if ((free_size<=maxBlobID[source_id]) && (free_size>0)) {
std::list<TuioBlob*>::iterator closestBlob = freeBlobList.begin();
for(std::list<TuioBlob*>::iterator iter = freeBlobList.begin();iter!= freeBlobList.end(); iter++) {
if (((*iter)->getTuioSourceID()==source_id) && ((*iter)->getDistance(tblb)<(*closestBlob)->getDistance(tblb))) closestBlob = iter;
}
if (closestBlob!=freeBlobList.end()) {
TuioBlob *freeBlob = (*closestBlob);
b_id = freeBlob->getBlobID();
freeBlobList.erase(closestBlob);
delete freeBlob;
}
} else maxBlobID[source_id] = b_id;
frameBlob = new TuioBlob(currentTime,tblb->getSessionID(),b_id,tblb->getX(),tblb->getY(),tblb->getAngle(),tblb->getWidth(),tblb->getHeight(),tblb->getArea());
if (source_name) frameBlob->setTuioSource(source_id,source_name,source_addr);
blobList.push_back(frameBlob);
delete tblb;
unlockBlobList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioBlob(frameBlob);
break;
default:
lockBlobList();
std::list<TuioBlob*>::iterator iter;
for (iter=blobList.begin(); iter != blobList.end(); iter++) {
if (((*iter)->getTuioSourceID()==source_id) && ((*iter)->getSessionID()==tblb->getSessionID())) {
frameBlob = (*iter);
break;
}
}
if (iter==blobList.end()) {
unlockBlobList();
break;
}
if ( (tblb->getX()!=frameBlob->getX() && tblb->getXSpeed()==0) || (tblb->getY()!=frameBlob->getY() && tblb->getYSpeed()==0) || (tblb->getAngle()!=frameBlob->getAngle() && tblb->getRotationSpeed()==0) )
frameBlob->update(currentTime,tblb->getX(),tblb->getY(),tblb->getAngle(),tblb->getWidth(),tblb->getHeight(),tblb->getArea());
else
frameBlob->update(currentTime,tblb->getX(),tblb->getY(),tblb->getAngle(),tblb->getWidth(),tblb->getHeight(),tblb->getArea(),tblb->getXSpeed(),tblb->getYSpeed(),tblb->getRotationSpeed(),tblb->getMotionAccel(),tblb->getRotationAccel());
delete tblb;
unlockBlobList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioBlob(frameBlob);
}
}
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->refresh(currentTime);
} else {
for (std::list<TuioBlob*>::iterator iter=frameBlobs.begin(); iter != frameBlobs.end(); iter++) {
TuioBlob *tblb = (*iter);
delete tblb;
}
}
frameBlobs.clear();
}
}
} catch( Exception& e ){
std::cerr << "error parsing TUIO message: "<< msg.AddressPattern() << " - " << e.what() << std::endl;
}
}
bool TuioClient::isConnected() {
return receiver->isConnected();
}
void TuioClient::connect(bool lock) {
TuioTime::initSession();
currentTime.reset();
receiver->connect(lock);
unlockCursorList();
unlockObjectList();
unlockBlobList();
}
void TuioClient::disconnect() {
receiver->disconnect();
aliveObjectList.clear();
aliveCursorList.clear();
aliveBlobList.clear();
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++)
delete (*iter);
objectList.clear();
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++)
delete (*iter);
cursorList.clear();
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++)
delete (*iter);
blobList.clear();
for (std::list<TuioCursor*>::iterator iter=freeCursorList.begin(); iter != freeCursorList.end(); iter++)
delete(*iter);
freeCursorList.clear();
for (std::list<TuioBlob*>::iterator iter=freeBlobList.begin(); iter != freeBlobList.end(); iter++)
delete(*iter);
freeBlobList.clear();
}
TuioObject* TuioClient::getTuioObject(int src_id, long s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
if (((*iter)->getTuioSourceID()==src_id) && ((*iter)->getSessionID()==s_id)) {
unlockObjectList();
return (*iter);
}
}
unlockObjectList();
return NULL;
}
TuioCursor* TuioClient::getTuioCursor(int src_id, long s_id) {
lockCursorList();
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
if (((*iter)->getTuioSourceID()==src_id) && ((*iter)->getSessionID()==s_id)) {
unlockCursorList();
return (*iter);
}
}
unlockCursorList();
return NULL;
}
TuioBlob* TuioClient::getTuioBlob(int src_id, long s_id) {
lockBlobList();
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++) {
if (((*iter)->getTuioSourceID()==src_id) && ((*iter)->getSessionID()==s_id)) {
unlockBlobList();
return (*iter);
}
}
unlockBlobList();
return NULL;
}
std::list<TuioObject*> TuioClient::getTuioObjects(int source_id) {
lockObjectList();
std::list<TuioObject*> listBuffer;
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
TuioObject *tobj = (*iter);
if (tobj->getTuioSourceID()==source_id) listBuffer.push_back(tobj);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioCursor*> TuioClient::getTuioCursors(int source_id) {
lockCursorList();
std::list<TuioCursor*> listBuffer;
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
TuioCursor *tcur = (*iter);
if (tcur->getTuioSourceID()==source_id) listBuffer.push_back(tcur);
}
unlockCursorList();
return listBuffer;
}
std::list<TuioBlob*> TuioClient::getTuioBlobs(int source_id) {
lockBlobList();
std::list<TuioBlob*> listBuffer;
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++) {
TuioBlob *tblb = (*iter);
if (tblb->getTuioSourceID()==source_id) listBuffer.push_back(tblb);
}
unlockBlobList();
return listBuffer;
}
std::list<TuioObject> TuioClient::copyTuioObjects(int source_id) {
lockObjectList();
std::list<TuioObject> listBuffer;
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
TuioObject *tobj = (*iter);
if (tobj->getTuioSourceID()==source_id) listBuffer.push_back(*tobj);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioCursor> TuioClient::copyTuioCursors(int source_id) {
lockCursorList();
std::list<TuioCursor> listBuffer;
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
TuioCursor *tcur = (*iter);
if (tcur->getTuioSourceID()==source_id) listBuffer.push_back(*tcur);
}
unlockCursorList();
return listBuffer;
}
std::list<TuioBlob> TuioClient::copyTuioBlobs(int source_id) {
lockBlobList();
std::list<TuioBlob> listBuffer;
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++) {
TuioBlob *tblb = (*iter);
if (tblb->getTuioSourceID()==source_id) listBuffer.push_back(*tblb);
}
unlockBlobList();
return listBuffer;
}

View File

@@ -0,0 +1,301 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOCLIENT_H
#define INCLUDED_TUIOCLIENT_H
#include "TuioDispatcher.h"
#include "OscReceiver.h"
#include "oscpack/osc/OscReceivedElements.h"
#include <iostream>
#include <list>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
namespace TUIO {
class OscReceiver; // Forward declaration
/**
* <p>The TuioClient class is the central TUIO protocol decoder component. It provides a simple callback infrastructure using the {@link TuioListener} interface.
* In order to receive and decode TUIO messages an instance of TuioClient needs to be created. The TuioClient instance then generates TUIO events
* which are broadcasted to all registered classes that implement the {@link TuioListener} interface.</p>
* <p><code>
* TuioClient *client = new TuioClient();<br/>
* client->addTuioListener(myTuioListener);<br/>
* client->connect();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioClient : public TuioDispatcher {
public:
/**
* This constructor creates a TuioClient that uses an internal UdpReceiver listening to the default UDP port 3333
*
*/
TuioClient();
/**
* This constructor creates a TuioClient that uses an internal UdpReceiver listening to the provided UDP port
*
* @param port the UDP port the internal UdpReceiver is listening to
*/
TuioClient(int port);
/**
* This constructor creates a TuioClient that uses the provided OscReceiver for the incoming OSC data
*
* @param oscreceiver the OscReceiver implementation for the chosen transport method (UDP, TCP ...)
*/
TuioClient(OscReceiver *oscreceiver);
/**
* The destructor is doing nothing in particular.
*/
~TuioClient();
/**
* The TuioClient connects and starts receiving TUIO messages from its associated OscReceiver
*
* @param lock running in the background if set to false (default)
*/
void connect(bool lock=false);
/**
* The TuioClient disconnects and stops receiving TUIO messages from its associated OscReceiver
*/
void disconnect();
/**
* Returns true if this TuioClient is currently connected.
* @return true if this TuioClient is currently connected
*/
bool isConnected();
/**
* Returns a List of all currently active TuioObjects
*
* @return a List of TuioObjects
*/
std::list<TuioObject*> getTuioObjects() {
return TuioDispatcher::getTuioObjects();
}
/**
* Returns a List of all currently active TuioObjects
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List of TuioObjects
*/
std::list<TuioObject*> getTuioObjects(int source_id);
/**
* Returns a List with a copy of all currently active TuioObjects
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List with a copy of TuioObjects
*/
std::list<TuioObject> copyTuioObjects(int source_id);
/**
* Returns a List with a copy of all currently active TuioObjects
*
* @return a List with a copy of TuioObjects
*/
std::list<TuioObject> copyTuioObjects() {
return TuioDispatcher::copyTuioObjects();
}
/**
* Returns the TuioObject corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioObject
*
* @param s_id the session ID of the corresponding TuioObject
* @return an active TuioObject corresponding to the provided Session ID or NULL
*/
TuioObject* getTuioObject(long s_id) {
return getTuioObject(0,s_id);
};
/**
* Returns the TuioObject corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioObject
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioObject
* @return an active TuioObject corresponding to the provided Session ID or NULL
*/
TuioObject* getTuioObject(int src_id, long s_id);
/**
* Returns a List of all currently active TuioCursors
*
* @return a List of TuioCursors
*/
std::list<TuioCursor*> getTuioCursors() {
return TuioDispatcher::getTuioCursors();
}
/**
* Returns a List of all currently active TuioCursors
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List of TuioCursors
*/
std::list<TuioCursor*> getTuioCursors(int source_id);
/**
* Returns a List with a copy of all currently active TuioCursors
*
* @return a List with a copy of TuioCursors
*/
std::list<TuioCursor> copyTuioCursors() {
return TuioDispatcher::copyTuioCursors();
}
/**
* Returns a List with a copy of all currently active TuioCursors
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List with a copy of TuioCursors
*/
std::list<TuioCursor> copyTuioCursors(int source_id);
/**
* Returns the TuioCursor corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioCursor
*
* @param s_id the session ID of the corresponding TuioCursor
* @return an active TuioCursor corresponding to the provided Session ID or NULL
*/
TuioCursor* getTuioCursor(long s_id) {
return getTuioCursor(0,s_id);
};
/**
* Returns the TuioCursor corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioCursor
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioCursor
* @return an active TuioCursor corresponding to the provided Session ID or NULL
*/
TuioCursor* getTuioCursor(int src_id, long s_id);
/**
* Returns a List of all currently active TuioBlobs
*
* @return a List of TuioBlobs
*/
std::list<TuioBlob*> getTuioBlobs() {
return TuioDispatcher::getTuioBlobs();
}
/**
* Returns a List of all currently active TuioBlobs
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List of TuioBlobs
*/
std::list<TuioBlob*> getTuioBlobs(int source_id);
/**
* Returns a List with a copy of all currently active TuioBlobs
*
* @return a List with a copy of TuioBlobs
*/
std::list<TuioBlob> copyTuioBlobs() {
return TuioDispatcher::copyTuioBlobs();
}
/**
* Returns a List with a copy of all currently active TuioBlobs
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List with a copy of TuioBlobs
*/
std::list<TuioBlob> copyTuioBlobs(int source_id);
/**
* Returns the TuioBlob corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioBlob
*
* @param s_id the session ID of the corresponding TuioBlob
* @return an active TuioBlob corresponding to the provided Session ID or NULL
*/
TuioBlob* getTuioBlob(long s_id) {
return getTuioBlob(0,s_id);
};
/**
* Returns the TuioBlob corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioBlob
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioBlob
* @return an active TuioBlob corresponding to the provided Session ID or NULL
*/
TuioBlob* getTuioBlob(int src_id, long s_id);
void processOSC( const osc::ReceivedMessage& message);
private:
void initialize();
std::list<TuioObject*> frameObjects;
std::list<long> aliveObjectList;
std::list<TuioCursor*> frameCursors;
std::list<long> aliveCursorList;
std::list<TuioBlob*> frameBlobs;
std::list<long> aliveBlobList;
osc::int32 currentFrame;
TuioTime currentTime;
std::list<TuioCursor*> freeCursorList, freeCursorBuffer;
std::map<int,int> maxCursorID;
std::list<TuioBlob*> freeBlobList, freeBlobBuffer;
std::map<int,int> maxBlobID;
std::map<std::string,int> sourceList;
int source_id;
char *source_name;
char *source_addr;
OscReceiver *receiver;
bool local_receiver;
};
};
#endif /* INCLUDED_TUIOCLIENT_H */

View File

@@ -0,0 +1,277 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioContainer.h"
using namespace TUIO;
TuioContainer::TuioContainer (TuioTime ttime, long si, float xp, float yp):TuioPoint(ttime, xp,yp)
,state(TUIO_ADDED)
,source_id(0)
,source_name("undefined")
,source_addr("localhost")
{
session_id = si;
x_speed = 0.0f;
y_speed = 0.0f;
motion_speed = 0.0f;
motion_accel = 0.0f;
x_accel = 0.0f;
y_accel = 0.0f;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
lastPoint = &path.back();
}
TuioContainer::TuioContainer (long si, float xp, float yp):TuioPoint(xp,yp)
,state(TUIO_ADDED)
,source_id(0)
,source_name("undefined")
,source_addr("localhost")
{
session_id = si;
x_speed = 0.0f;
y_speed = 0.0f;
motion_speed = 0.0f;
motion_accel = 0.0f;
x_accel = 0.0f;
y_accel = 0.0f;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
lastPoint = &path.back();
}
TuioContainer::TuioContainer (TuioContainer *tcon):TuioPoint(tcon)
,state(TUIO_ADDED)
,source_id(0)
,source_name("undefined")
,source_addr("localhost")
{
session_id = tcon->getSessionID();
x_speed = 0.0f;
y_speed = 0.0f;
motion_speed = 0.0f;
motion_accel = 0.0f;
x_accel = 0.0f;
y_accel = 0.0f;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
lastPoint = &path.back();
}
void TuioContainer::setTuioSource(int src_id, const char *src_name, const char *src_addr) {
source_id = src_id;
source_name = std::string(src_name);
source_addr = std::string(src_addr);
}
const char* TuioContainer::getTuioSourceName() const{
return source_name.c_str();
}
const char* TuioContainer::getTuioSourceAddress() const{
return source_addr.c_str();
}
int TuioContainer::getTuioSourceID() const{
return source_id;
}
void TuioContainer::update (TuioTime ttime, float xp, float yp) {
lastPoint = &path.back();
TuioPoint::update(ttime,xp, yp);
TuioTime diffTime = currentTime - lastPoint->getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
float dx = xpos - lastPoint->getX();
float dy = ypos - lastPoint->getY();
float dist = sqrt(dx*dx+dy*dy);
float last_motion_speed = motion_speed;
float last_x_speed = x_speed;
float last_y_speed = y_speed;
x_speed = dx/dt;
y_speed = dy/dt;
motion_speed = dist/dt;
motion_accel = (motion_speed - last_motion_speed)/dt;
x_accel = (x_speed - last_x_speed)/dt;
y_accel = (y_speed - last_y_speed)/dt;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else state = TUIO_STOPPED;
}
void TuioContainer::stop(TuioTime ttime) {
if ( state==TUIO_IDLE )update(ttime,xpos,ypos);
else state=TUIO_IDLE;
}
void TuioContainer::update (TuioTime ttime, float xp, float yp, float xs, float ys, float ma) {
TuioPoint::update(ttime,xp, yp);
x_speed = xs;
y_speed = ys;
motion_speed = (float)sqrt(x_speed*x_speed+y_speed*y_speed);
motion_accel = ma;
x_accel = ma;
y_accel = ma;
lastPoint = &path.back();
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else state = TUIO_STOPPED;
}
void TuioContainer::update (float xp, float yp, float xs, float ys, float ma) {
TuioPoint::update(xp,yp);
x_speed = xs;
y_speed = ys;
motion_speed = (float)sqrt(x_speed*x_speed+y_speed*y_speed);
motion_accel = ma;
x_accel = ma;
y_accel = ma;
lastPoint = &path.back();
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else state = TUIO_STOPPED;
}
void TuioContainer::update (TuioContainer *tcon) {
TuioPoint::update(tcon);
x_speed = tcon->getXSpeed();
y_speed = tcon->getYSpeed();
motion_speed = tcon->getMotionSpeed();
motion_accel = tcon->getMotionAccel();
x_accel = motion_accel;
y_accel = motion_accel;
lastPoint = &path.back();
TuioPoint p(tcon->getTuioTime(),xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else state = TUIO_STOPPED;
}
void TuioContainer::remove(TuioTime ttime) {
currentTime = ttime;
state = TUIO_REMOVED;
}
long TuioContainer::getSessionID() const{
return session_id;
}
void TuioContainer::setSessionID(long s_id) {
session_id = s_id;
}
float TuioContainer::getXSpeed() const{
return x_speed;
}
float TuioContainer::getYSpeed() const{
return y_speed;
}
TuioPoint TuioContainer::getPosition() const{
TuioPoint p(xpos,ypos);
return p;
}
std::list<TuioPoint> TuioContainer::getPath() const{
return path;
}
float TuioContainer::getMotionSpeed() const{
return motion_speed;
}
float TuioContainer::getMotionAccel() const{
return motion_accel;
}
int TuioContainer::getTuioState() const{
return state;
}
bool TuioContainer::isMoving() const{
if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING)) return true;
else return false;
}
TuioPoint TuioContainer::predictPosition() {
/*if (path.size()>1) {
std::list<TuioPoint>::iterator iter = path.end();
std::advance(iter, -2);
TuioTime diffTime = currentTime - (*iter).getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
float tx = x_speed * dt;
float ty = y_speed * dt;
float nx = xpos+tx-tx*x_accel*dt;
float ny = ypos+ty-ty*y_accel*dt;
//if (xposFilter && yposFilter) {
// nx = xposFilter->filter(nx,dt);
// ny = yposFilter->filter(ny,dt);
// //std::cout << dt << " " << xp << " " << xpos << " " << yp << " " << ypos << std::endl;
//}
//std::cout << nx << " " << ny << std::endl;
return TuioPoint(nx,ny);
} else return TuioPoint(xpos,ypos);*/
TuioTime diffTime = currentTime - lastPoint->getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
float tx = x_speed * dt;
float ty = y_speed * dt;
float nx = xpos+tx-tx*x_accel*dt;
float ny = ypos+ty-ty*y_accel*dt;
//if (xposFilter && yposFilter) {
// nx = xposFilter->filter(nx,dt);
// ny = yposFilter->filter(ny,dt);
// //std::cout << dt << " " << xp << " " << xpos << " " << yp << " " << ypos << std::endl;
//}
//std::cout << nx << " " << ny << std::endl;
return TuioPoint(nx,ny);
}

View File

@@ -0,0 +1,279 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOCONTAINER_H
#define INCLUDED_TUIOCONTAINER_H
#include "TuioPoint.h"
#include <list>
#include <string>
#define TUIO_IDLE 0
#define TUIO_ADDED 1
#define TUIO_ACCELERATING 2
#define TUIO_DECELERATING 3
#define TUIO_ROTATING 4
#define TUIO_STOPPED 5
#define TUIO_REMOVED 6
#define MAX_PATH_SIZE 128
namespace TUIO {
/**
* The abstract TuioContainer class defines common attributes that apply to both subclasses {@link TuioObject} and {@link TuioCursor}.
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioContainer: public TuioPoint {
private:
TuioPoint *lastPoint;
protected:
/**
* The unique session ID number that is assigned to each TUIO object or cursor.
*/
long session_id;
/**
* The X-axis velocity value.
*/
float x_speed;
/**
* The Y-axis velocity value.
*/
float y_speed;
/**
* The motion speed value.
*/
float motion_speed;
/**
* The motion acceleration value.
*/
float motion_accel;
float x_accel;
float y_accel;
/**
* A List of TuioPoints containing all the previous positions of the TUIO component.
*/
std::list<TuioPoint> path;
/**
* Reflects the current state of the TuioComponent
*/
int state;
/**
* The ID of the TUIO source
*/
int source_id;
/**
* The name of the TUIO source
*/
std::string source_name;
/**
* The address of the TUIO source
*/
std::string source_addr;
public:
using TuioPoint::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, X and Y coordinate to the newly created TuioContainer.
*
* @param ttime the TuioTime to assign
* @param si the Session ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
TuioContainer (TuioTime ttime, long si, float xp, float yp);
/**
* This constructor takes the provided Session ID, X and Y coordinate
* and assigs these values to the newly created TuioContainer.
*
* @param si the Session ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
TuioContainer (long si, float xp, float yp);
/**
* This constructor takes the atttibutes of the provided TuioContainer
* and assigs these values to the newly created TuioContainer.
*
* @param tcon the TuioContainer to assign
*/
TuioContainer (TuioContainer *tcon);
/**
* The destructor is doing nothing in particular.
*/
virtual ~TuioContainer(){};
/**
* Sets the ID, name and address of the TUIO source
*
* @param src_id the ID of the TUIO source
* @param src_name the name of the TUIO source
* @param src_addr the address of the TUIO source
*/
virtual void setTuioSource(int src_id, const char *src_name, const char *src_addr);
/**
* Returns the name of the TUIO source
*/
virtual const char* getTuioSourceName() const;
/**
* Returns the address of the TUIO source
*/
virtual const char* getTuioSourceAddress() const;
/**
* Returns the ID of the TUIO source
*/
virtual int getTuioSourceID() const;
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate to the private TuioContainer attributes.
* The speed and accleration values are calculated accordingly.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
virtual void update (TuioTime ttime, float xp, float yp);
/**
* This method is used to calculate the speed and acceleration values of
* TuioContainers with unchanged positions.
*/
virtual void stop(TuioTime ttime);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate, X and Y velocity and acceleration
* to the private TuioContainer attributes.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param ma the acceleration to assign
*/
virtual void update (TuioTime ttime, float xp, float yp, float xs, float ys, float ma);
/**
* Assigns the provided X and Y coordinate, X and Y velocity and acceleration
* to the private TuioContainer attributes. The TuioTime time stamp remains unchanged.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param ma the acceleration to assign
*/
virtual void update (float xp, float yp, float xs, float ys, float ma);
/**
* Takes the atttibutes of the provided TuioContainer
* and assigs these values to this TuioContainer.
* The TuioTime time stamp of this TuioContainer remains unchanged.
*
* @param tcon the TuioContainer to assign
*/
virtual void update (TuioContainer *tcon);
/**
* Assigns the REMOVE state to this TuioContainer and sets
* its TuioTime time stamp to the provided TuioTime argument.
*
* @param ttime the TuioTime to assign
*/
virtual void remove(TuioTime ttime);
/**
* Returns the Session ID of this TuioContainer.
* @return the Session ID of this TuioContainer
*/
virtual long getSessionID() const;
/**
* Sets the Session ID of this TuioContainer.
* @param s_id the new Session ID for this TuioContainer
*/
virtual void setSessionID(long s_id);
/**
* Returns the X velocity of this TuioContainer.
* @return the X velocity of this TuioContainer
*/
virtual float getXSpeed() const;
/**
* Returns the Y velocity of this TuioContainer.
* @return the Y velocity of this TuioContainer
*/
virtual float getYSpeed() const;
/**
* Returns the position of this TuioContainer.
* @return the position of this TuioContainer
*/
virtual TuioPoint getPosition() const;
/**
* Returns the path of this TuioContainer.
* @return the path of this TuioContainer
*/
virtual std::list<TuioPoint> getPath() const;
/**
* Returns the motion speed of this TuioContainer.
* @return the motion speed of this TuioContainer
*/
virtual float getMotionSpeed() const;
/**
* Returns the motion acceleration of this TuioContainer.
* @return the motion acceleration of this TuioContainer
*/
virtual float getMotionAccel() const;
/**
* Returns the TUIO state of this TuioContainer.
* @return the TUIO state of this TuioContainer
*/
virtual int getTuioState() const;
/**
* Returns true of this TuioContainer is moving.
* @return true of this TuioContainer is moving
*/
virtual bool isMoving() const;
virtual TuioPoint predictPosition();
};
}
#endif

View File

@@ -0,0 +1,38 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioCursor.h"
using namespace TUIO;
TuioCursor::TuioCursor (TuioTime ttime, long si, int ci, float xp, float yp):TuioContainer(ttime,si,xp,yp) {
cursor_id = ci;
}
TuioCursor::TuioCursor (long si, int ci, float xp, float yp):TuioContainer(si,xp,yp) {
cursor_id = ci;
}
TuioCursor::TuioCursor (TuioCursor *tcur):TuioContainer(tcur) {
cursor_id = tcur->getCursorID();
}
int TuioCursor::getCursorID() const{
return cursor_id;
};

View File

@@ -0,0 +1,86 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOCURSOR_H
#define INCLUDED_TUIOCURSOR_H
#include "TuioContainer.h"
namespace TUIO {
/**
* The TuioCursor class encapsulates /tuio/2Dcur TUIO cursors.
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioCursor: public TuioContainer {
protected:
/**
* The individual cursor ID number that is assigned to each TuioCursor.
*/
int cursor_id;
public:
using TuioContainer::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, Cursor ID, X and Y coordinate to the newly created TuioCursor.
*
* @param ttime the TuioTime to assign
* @param si the Session ID to assign
* @param ci the Cursor ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
TuioCursor (TuioTime ttime, long si, int ci, float xp, float yp);
/**
* This constructor takes the provided Session ID, Cursor ID, X and Y coordinate
* and assigs these values to the newly created TuioCursor.
*
* @param si the Session ID to assign
* @param ci the Cursor ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
TuioCursor (long si, int ci, float xp, float yp);
/**
* This constructor takes the atttibutes of the provided TuioCursor
* and assigs these values to the newly created TuioCursor.
*
* @param tcur the TuioCursor to assign
*/
TuioCursor (TuioCursor *tcur);
/**
* The destructor is doing nothing in particular.
*/
virtual ~TuioCursor(){};
/**
* Returns the Cursor ID of this TuioCursor.
* @return the Cursor ID of this TuioCursor
*/
int getCursorID() const;
};
}
#endif

View File

@@ -0,0 +1,211 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioDispatcher.h"
#include <iostream>
#include <list>
#include <algorithm>
#include <cstring>
using namespace TUIO;
TuioDispatcher::TuioDispatcher() {
#ifndef WIN32
pthread_mutex_init(&cursorMutex,NULL);
pthread_mutex_init(&objectMutex,NULL);
pthread_mutex_init(&blobMutex,NULL);
#else
cursorMutex = CreateMutex(NULL,FALSE,TEXT("cursorMutex"));
objectMutex = CreateMutex(NULL,FALSE,TEXT("objectMutex"));
blobMutex = CreateMutex(NULL,FALSE,TEXT("blobMutex"));
#endif
}
TuioDispatcher::~TuioDispatcher() {
#ifndef WIN32
pthread_mutex_destroy(&cursorMutex);
pthread_mutex_destroy(&objectMutex);
pthread_mutex_destroy(&blobMutex);
#else
CloseHandle(cursorMutex);
CloseHandle(objectMutex);
CloseHandle(blobMutex);
#endif
}
void TuioDispatcher::lockObjectList() {
#ifndef WIN32
pthread_mutex_lock(&objectMutex);
#else
WaitForSingleObject(objectMutex, INFINITE);
#endif
}
void TuioDispatcher::unlockObjectList() {
#ifndef WIN32
pthread_mutex_unlock(&objectMutex);
#else
ReleaseMutex(objectMutex);
#endif
}
void TuioDispatcher::lockCursorList() {
#ifndef WIN32
pthread_mutex_lock(&cursorMutex);
#else
WaitForSingleObject(cursorMutex, INFINITE);
#endif
}
void TuioDispatcher::unlockCursorList() {
#ifndef WIN32
pthread_mutex_unlock(&cursorMutex);
#else
ReleaseMutex(cursorMutex);
#endif
}
void TuioDispatcher::lockBlobList() {
#ifndef WIN32
pthread_mutex_lock(&blobMutex);
#else
WaitForSingleObject(blobMutex, INFINITE);
#endif
}
void TuioDispatcher::unlockBlobList() {
#ifndef WIN32
pthread_mutex_unlock(&blobMutex);
#else
ReleaseMutex(blobMutex);
#endif
}
void TuioDispatcher::addTuioListener(TuioListener *listener) {
listenerList.push_back(listener);
}
void TuioDispatcher::removeTuioListener(TuioListener *listener) {
std::list<TuioListener*>::iterator result = find(listenerList.begin(),listenerList.end(),listener);
if (result!=listenerList.end()) listenerList.remove(listener);
}
void TuioDispatcher::removeAllTuioListeners() {
listenerList.clear();
}
TuioObject* TuioDispatcher::getTuioObject(long s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
if((*iter)->getSessionID()==s_id) {
unlockObjectList();
return (*iter);
}
}
unlockObjectList();
return NULL;
}
TuioCursor* TuioDispatcher::getTuioCursor(long s_id) {
lockCursorList();
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
if((*iter)->getSessionID()==s_id) {
unlockCursorList();
return (*iter);
}
}
unlockCursorList();
return NULL;
}
TuioBlob* TuioDispatcher::getTuioBlob(long s_id) {
lockBlobList();
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++) {
if((*iter)->getSessionID()==s_id) {
unlockBlobList();
return (*iter);
}
}
unlockBlobList();
return NULL;
}
std::list<TuioObject*> TuioDispatcher::getTuioObjects() {
lockObjectList();
std::list<TuioObject*> listBuffer;
listBuffer.insert(listBuffer.end(), objectList.begin(), objectList.end());
//std::list<TuioObject*> listBuffer = objectList;
unlockObjectList();
return listBuffer;
}
std::list<TuioCursor*> TuioDispatcher::getTuioCursors() {
lockCursorList();
std::list<TuioCursor*> listBuffer;
listBuffer.insert(listBuffer.end(), cursorList.begin(), cursorList.end());
//std::list<TuioCursor*> listBuffer = cursorList;
unlockCursorList();
return listBuffer;
}
std::list<TuioBlob*> TuioDispatcher::getTuioBlobs() {
lockBlobList();
std::list<TuioBlob*> listBuffer;
listBuffer.insert(listBuffer.end(), blobList.begin(), blobList.end());
//std::list<TuioBlob*> listBuffer = blobList;
unlockBlobList();
return listBuffer;
}
std::list<TuioObject> TuioDispatcher::copyTuioObjects() {
lockObjectList();
std::list<TuioObject> listBuffer;
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
TuioObject *tobj = (*iter);
listBuffer.push_back(*tobj);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioCursor> TuioDispatcher::copyTuioCursors() {
lockCursorList();
std::list<TuioCursor> listBuffer;
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
TuioCursor *tcur = (*iter);
listBuffer.push_back(*tcur);
}
unlockCursorList();
return listBuffer;
}
std::list<TuioBlob> TuioDispatcher::copyTuioBlobs() {
lockBlobList();
std::list<TuioBlob> listBuffer;
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++) {
TuioBlob *tblb = (*iter);
listBuffer.push_back(*tblb);
}
unlockBlobList();
return listBuffer;
}

View File

@@ -0,0 +1,187 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIODISPATCHER_H
#define INCLUDED_TUIODISPATCHER_H
#include "TuioListener.h"
#ifndef WIN32
#include <pthread.h>
#else
#include <windows.h>
#endif
namespace TUIO {
/**
* <p>The TuioDispatcher generates TUIO events which are broadcasted to all
* registered classes that implement the {@link TuioListener} interface.</p>
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioDispatcher {
public:
/**
* This constructor creates a TuioDispatcher
*
*/
TuioDispatcher();
/**
* The destructor is doing nothing in particular.
*/
~TuioDispatcher();
/**
* Adds the provided TuioListener to the list of registered TUIO event listeners
*
* @param listener the TuioListener to add
*/
void addTuioListener(TuioListener *listener);
/**
* Removes the provided TuioListener from the list of registered TUIO event listeners
*
* @param listener the TuioListener to remove
*/
void removeTuioListener(TuioListener *listener);
/**
* Removes all TuioListener from the list of registered TUIO event listeners
*/
void removeAllTuioListeners();
/**
* Returns a List of all currently active TuioObjects
*
* @return a List of all currently active TuioObjects
*/
std::list<TuioObject*> getTuioObjects();
/**
* Returns a List with a copy of currently active TuioObjects
*
* @return a List with a copy of all currently active TuioObjects
*/
std::list<TuioObject> copyTuioObjects();
/**
* Returns a List of all currently active TuioCursors
*
* @return a List of all currently active TuioCursors
*/
std::list<TuioCursor*> getTuioCursors();
/**
* Returns a List with a copy of currently active TuioCursors
*
* @return a List with a copy of all currently active TuioCursors
*/
std::list<TuioCursor> copyTuioCursors();
/**
* Returns a List of all currently active TuioBlobs
*
* @return a List of all currently active TuioBlobs
*/
std::list<TuioBlob*> getTuioBlobs();
/**
* Returns a List with a copy of currently active TuioBlobs
*
* @return a List with a copy of all currently active TuioBlobs
*/
std::list<TuioBlob> copyTuioBlobs();
/**
* Returns the TuioObject corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioObject
*
* @return an active TuioObject corresponding to the provided Session ID or NULL
*/
TuioObject* getTuioObject(long s_id);
/**
* Returns the TuioCursor corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioCursor
*
* @return an active TuioCursor corresponding to the provided Session ID or NULL
*/
TuioCursor* getTuioCursor(long s_id);
/**
* Returns the TuioBlob corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioBlob
*
* @return an active TuioBlob corresponding to the provided Session ID or NULL
*/
TuioBlob* getTuioBlob(long s_id);
/**
* Locks the TuioObject list in order to avoid updates during access
*/
void lockObjectList();
/**
* Releases the lock of the TuioObject list
*/
void unlockObjectList();
/**
* Locks the TuioCursor list in order to avoid updates during access
*/
void lockCursorList();
/**
* Releases the lock of the TuioCursor list
*/
void unlockCursorList();
/**
* Locks the TuioBlob list in order to avoid updates during access
*/
void lockBlobList();
/**
* Releases the lock of the TuioBlob list
*/
void unlockBlobList();
protected:
std::list<TuioListener*> listenerList;
std::list<TuioObject*> objectList;
std::list<TuioCursor*> cursorList;
std::list<TuioBlob*> blobList;
#ifndef WIN32
pthread_mutex_t objectMutex;
pthread_mutex_t cursorMutex;
pthread_mutex_t blobMutex;
#else
HANDLE objectMutex;
HANDLE cursorMutex;
HANDLE blobMutex;
#endif
};
}
#endif /* INCLUDED_TUIODISPATCHER_H */

View File

@@ -0,0 +1,124 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOLISTENER_H
#define INCLUDED_TUIOLISTENER_H
#include "TuioObject.h"
#include "TuioCursor.h"
#include "TuioBlob.h"
namespace TUIO {
/**
* <p>The TuioListener interface provides a simple callback infrastructure which is used by the {@link TuioClient} class
* to dispatch TUIO events to all registered instances of classes that implement the TuioListener interface defined here.</p>
* <p>Any class that implements the TuioListener interface is required to implement all of the callback methods defined here.
* The {@link TuioClient} makes use of these interface methods in order to dispatch TUIO events to all registered TuioListener implementations.</p>
* <p><code>
* public class MyTuioListener implements TuioListener<br/>
* ...</code><p><code>
* MyTuioListener listener = new MyTuioListener();<br/>
* TuioClient client = new TuioClient();<br/>
* client.addTuioListener(listener);<br/>
* client.start();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioListener {
public:
/**
* The destructor is doing nothing in particular.
*/
virtual ~TuioListener(){};
/**
* This callback method is invoked by the TuioClient when a new TuioObject is added to the session.
*
* @param tobj the TuioObject reference associated to the addTuioObject event
*/
virtual void addTuioObject(TuioObject *tobj)=0;
/**
* This callback method is invoked by the TuioClient when an existing TuioObject is updated during the session.
*
* @param tobj the TuioObject reference associated to the updateTuioObject event
*/
virtual void updateTuioObject(TuioObject *tobj)=0;
/**
* This callback method is invoked by the TuioClient when an existing TuioObject is removed from the session.
*
* @param tobj the TuioObject reference associated to the removeTuioObject event
*/
virtual void removeTuioObject(TuioObject *tobj)=0;
/**
* This callback method is invoked by the TuioClient when a new TuioCursor is added to the session.
*
* @param tcur the TuioCursor reference associated to the addTuioCursor event
*/
virtual void addTuioCursor(TuioCursor *tcur)=0;
/**
* This callback method is invoked by the TuioClient when an existing TuioCursor is updated during the session.
*
* @param tcur the TuioCursor reference associated to the updateTuioCursor event
*/
virtual void updateTuioCursor(TuioCursor *tcur)=0;
/**
* This callback method is invoked by the TuioClient when an existing TuioCursor is removed from the session.
*
* @param tcur the TuioCursor reference associated to the removeTuioCursor event
*/
virtual void removeTuioCursor(TuioCursor *tcur)=0;
/**
* This callback method is invoked by the TuioClient when a new TuioBlob is added to the session.
*
* @param tcur the TuioBlob reference associated to the addTuioBlob event
*/
virtual void addTuioBlob(TuioBlob *tblb)=0;
/**
* This callback method is invoked by the TuioClient when an existing TuioBlob is updated during the session.
*
* @param tblb the TuioBlob reference associated to the updateTuioBlob event
*/
virtual void updateTuioBlob(TuioBlob *tblb)=0;
/**
* This callback method is invoked by the TuioClient when an existing TuioBlob is removed from the session.
*
* @param tblb the TuioBlob reference associated to the removeTuioBlob event
*/
virtual void removeTuioBlob(TuioBlob *tblb)=0;
/**
* This callback method is invoked by the TuioClient to mark the end of a received TUIO message bundle.
*
* @param ftime the TuioTime associated to the current TUIO message bundle
*/
virtual void refresh(TuioTime ftime)=0;
};
}
#endif /* INCLUDED_TUIOLISTENER_H */

View File

@@ -0,0 +1,615 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioManager.h"
using namespace TUIO;
TuioManager::TuioManager()
: currentFrameTime(TuioTime::getSystemTime())
, currentFrame(-1)
, maxCursorID(-1)
, maxBlobID(-1)
, sessionID(-1)
, updateObject(false)
, updateCursor(false)
, updateBlob(false)
, verbose(false)
, invert_x(false)
, invert_y(false)
, invert_a(false)
{
}
TuioManager::~TuioManager() {
}
TuioObject* TuioManager::addTuioObject(int f_id, float x, float y, float a) {
sessionID++;
TuioObject *tobj = new TuioObject(currentFrameTime, sessionID, f_id, x, y, a);
objectList.push_back(tobj);
updateObject = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioObject(tobj);
if (verbose)
std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
return tobj;
}
void TuioManager::addExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
tobj->setSessionID(sessionID++);
objectList.push_back(tobj);
updateObject = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioObject(tobj);
if (verbose)
std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
}
void TuioManager::updateTuioObject(TuioObject *tobj, float x, float y, float a) {
if (tobj==NULL) return;
if (tobj->getTuioTime()==currentFrameTime) return;
tobj->update(currentFrameTime,x,y,a);
updateObject = true;
if (tobj->isMoving()) {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioObject(tobj);
if (verbose)
std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
<< " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
}
}
void TuioManager::updateExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
updateObject = true;
if (tobj->isMoving()) {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioObject(tobj);
if (verbose)
std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
<< " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
}
}
void TuioManager::removeTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioObject(tobj);
if (verbose)
std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ")" << std::endl;
objectList.remove(tobj);
delete tobj;
updateObject = true;
}
void TuioManager::removeExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
objectList.remove(tobj);
updateObject = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioObject(tobj);
if (verbose)
std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ")" << std::endl;
}
TuioCursor* TuioManager::addTuioCursor(float x, float y) {
sessionID++;
int cursorID = (int)cursorList.size();
if ((int)(cursorList.size())<=maxCursorID) {
std::list<TuioCursor*>::iterator closestCursor = freeCursorList.begin();
for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin();iter!= freeCursorList.end(); iter++) {
if((*iter)->getDistance(x,y)<(*closestCursor)->getDistance(x,y)) closestCursor = iter;
}
TuioCursor *freeCursor = (*closestCursor);
cursorID = (*closestCursor)->getCursorID();
freeCursorList.erase(closestCursor);
delete freeCursor;
} else maxCursorID = cursorID;
TuioCursor *tcur = new TuioCursor(currentFrameTime, sessionID, cursorID, x, y);
cursorList.push_back(tcur);
updateCursor = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioCursor(tcur);
if (verbose)
std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl;
return tcur;
}
void TuioManager::addExternalTuioCursor(TuioCursor *tcur) {
if (tcur==NULL) return;
tcur->setSessionID(sessionID++);
cursorList.push_back(tcur);
updateCursor = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioCursor(tcur);
if (verbose)
std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl;
}
void TuioManager::updateTuioCursor(TuioCursor *tcur,float x, float y) {
if (tcur==NULL) return;
//if (tcur->getTuioTime()==currentFrameTime) return;
tcur->update(currentFrameTime,x,y);
updateCursor = true;
if (tcur->isMoving()) {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioCursor(tcur);
if (verbose)
std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()
<< " " << tcur->getXSpeed() << " " << tcur->getYSpeed() << " " << tcur->getMotionAccel() << " " << std::endl;
}
}
void TuioManager::updateExternalTuioCursor(TuioCursor *tcur) {
if (tcur==NULL) return;
updateCursor = true;
if (tcur->isMoving()) {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioCursor(tcur);
if (verbose)
std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()
<< " " << tcur->getXSpeed() << " " << tcur->getYSpeed() << " " << tcur->getMotionAccel() << " " << std::endl;
}
}
void TuioManager::removeTuioCursor(TuioCursor *tcur) {
if (tcur==NULL) return;
cursorList.remove(tcur);
tcur->remove(currentFrameTime);
updateCursor = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioCursor(tcur);
if (verbose)
std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ")" << std::endl;
if (tcur->getCursorID()==maxCursorID) {
maxCursorID = -1;
delete tcur;
if (cursorList.size()>0) {
std::list<TuioCursor*>::iterator clist;
for (clist=cursorList.begin(); clist != cursorList.end(); clist++) {
int cursorID = (*clist)->getCursorID();
if (cursorID>maxCursorID) maxCursorID=cursorID;
}
freeCursorBuffer.clear();
for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) {
TuioCursor *freeCursor = (*flist);
if (freeCursor->getCursorID()>maxCursorID) delete freeCursor;
else freeCursorBuffer.push_back(freeCursor);
}
freeCursorList = freeCursorBuffer;
} else {
for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) {
TuioCursor *freeCursor = (*flist);
delete freeCursor;
}
freeCursorList.clear();
}
} else if (tcur->getCursorID()<maxCursorID) {
freeCursorList.push_back(tcur);
}
}
void TuioManager::removeExternalTuioCursor(TuioCursor *tcur) {
if (tcur==NULL) return;
cursorList.remove(tcur);
updateCursor = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioCursor(tcur);
if (verbose)
std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ")" << std::endl;
}
TuioBlob* TuioManager::addTuioBlob(float x, float y, float a, float w, float h, float f) {
sessionID++;
int blobID = (int)blobList.size();
if ((int)(blobList.size())<=maxBlobID) {
std::list<TuioBlob*>::iterator closestBlob = freeBlobList.begin();
for(std::list<TuioBlob*>::iterator iter = freeBlobList.begin();iter!= freeBlobList.end(); iter++) {
if((*iter)->getDistance(x,y)<(*closestBlob)->getDistance(x,y)) closestBlob = iter;
}
TuioBlob *freeBlob = (*closestBlob);
blobID = (*closestBlob)->getBlobID();
freeBlobList.erase(closestBlob);
delete freeBlob;
} else maxBlobID = blobID;
TuioBlob *tblb = new TuioBlob(currentFrameTime, sessionID, blobID, x, y, a, w, h, f);
blobList.push_back(tblb);
updateBlob = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioBlob(tblb);
if (verbose)
std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea() << std::endl;
return tblb;
}
void TuioManager::addExternalTuioBlob(TuioBlob *tblb) {
if (tblb==NULL) return;
int blobID = (int)blobList.size();
if (blobID <= maxBlobID) {
std::list<TuioBlob*>::iterator closestBlob = freeBlobList.begin();
for(std::list<TuioBlob*>::iterator iter = freeBlobList.begin();iter!= freeBlobList.end(); iter++) {
if((*iter)->getDistance(tblb->getX(),tblb->getY())<(*closestBlob)->getDistance(tblb->getX(),tblb->getY())) closestBlob = iter;
}
TuioBlob *freeBlob = (*closestBlob);
blobID = (*closestBlob)->getBlobID();
freeBlobList.erase(closestBlob);
delete freeBlob;
} else maxBlobID = blobID;
tblb->setSessionID(sessionID++);
tblb->setBlobID(blobID);
blobList.push_back(tblb);
updateBlob = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->addTuioBlob(tblb);
if (verbose)
std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea() << std::endl;
}
void TuioManager::updateTuioBlob(TuioBlob *tblb,float x, float y, float a, float w, float h, float f) {
if (tblb==NULL) return;
if (tblb->getTuioTime()==currentFrameTime) return;
tblb->update(currentFrameTime,x,y,a,w,h,f);
updateBlob = true;
if (tblb->isMoving()) {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioBlob(tblb);
if (verbose)
std::cout << "set blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea()
<< " " << tblb->getXSpeed() << " " << tblb->getYSpeed() << " " << tblb->getRotationSpeed() << " " << tblb->getMotionAccel()<< " " << tblb->getRotationAccel() << " " << std::endl;
}
}
void TuioManager::updateExternalTuioBlob(TuioBlob *tblb) {
if (tblb==NULL) return;
updateBlob = true;
if (tblb->isMoving()) {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->updateTuioBlob(tblb);
if (verbose)
std::cout << "set blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea()
<< " " << tblb->getXSpeed() << " " << tblb->getYSpeed() << " " << tblb->getRotationSpeed() << " " << tblb->getMotionAccel()<< " " << tblb->getRotationAccel() << " " << std::endl;
}
}
void TuioManager::removeTuioBlob(TuioBlob *tblb) {
if (tblb==NULL) return;
blobList.remove(tblb);
tblb->remove(currentFrameTime);
updateBlob = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioBlob(tblb);
if (verbose)
std::cout << "del blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ")" << std::endl;
if (tblb->getBlobID()==maxBlobID) {
maxBlobID = -1;
delete tblb;
if (blobList.size()>0) {
std::list<TuioBlob*>::iterator clist;
for (clist=blobList.begin(); clist != blobList.end(); clist++) {
int blobID = (*clist)->getBlobID();
if (blobID>maxBlobID) maxBlobID=blobID;
}
freeBlobBuffer.clear();
for (std::list<TuioBlob*>::iterator flist=freeBlobList.begin(); flist != freeBlobList.end(); flist++) {
TuioBlob *freeBlob = (*flist);
if (freeBlob->getBlobID()>maxBlobID) delete freeBlob;
else freeBlobBuffer.push_back(freeBlob);
}
freeBlobList = freeBlobBuffer;
} else {
for (std::list<TuioBlob*>::iterator flist=freeBlobList.begin(); flist != freeBlobList.end(); flist++) {
TuioBlob *freeBlob = (*flist);
delete freeBlob;
}
freeBlobList.clear();
}
} else if (tblb->getBlobID()<maxBlobID) {
freeBlobList.push_back(tblb);
}
}
void TuioManager::removeExternalTuioBlob(TuioBlob *tblb) {
if (tblb==NULL) return;
blobList.remove(tblb);
updateBlob = true;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->removeTuioBlob(tblb);
if (verbose)
std::cout << "del blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ")" << std::endl;
}
long TuioManager::getSessionID() {
sessionID++;
return sessionID;
}
long TuioManager::getFrameID() {
return currentFrame;
}
TuioTime TuioManager::getFrameTime() {
return currentFrameTime;
}
void TuioManager::initFrame(TuioTime ttime) {
currentFrameTime = TuioTime(ttime);
currentFrame++;
}
void TuioManager::commitFrame() {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->refresh(currentFrameTime);
}
TuioObject* TuioManager::getClosestTuioObject(float xp, float yp) {
TuioObject *closestObject = NULL;
float closestDistance = 1.0f;
for (std::list<TuioObject*>::iterator iter=objectList.begin(); iter != objectList.end(); iter++) {
float distance = (*iter)->getDistance(xp,yp);
if(distance<closestDistance) {
closestObject = (*iter);
closestDistance = distance;
}
}
return closestObject;
}
TuioCursor* TuioManager::getClosestTuioCursor(float xp, float yp) {
TuioCursor *closestCursor = NULL;
float closestDistance = 1.0f;
for (std::list<TuioCursor*>::iterator iter=cursorList.begin(); iter != cursorList.end(); iter++) {
float distance = (*iter)->getDistance(xp,yp);
if(distance<closestDistance) {
closestCursor = (*iter);
closestDistance = distance;
}
}
return closestCursor;
}
TuioBlob* TuioManager::getClosestTuioBlob(float xp, float yp) {
TuioBlob *closestBlob = NULL;
float closestDistance = 1.0f;
for (std::list<TuioBlob*>::iterator iter=blobList.begin(); iter != blobList.end(); iter++) {
float distance = (*iter)->getDistance(xp,yp);
if(distance<closestDistance) {
closestBlob = (*iter);
closestDistance = distance;
}
}
return closestBlob;
}
std::list<TuioObject*> TuioManager::getUntouchedObjects() {
std::list<TuioObject*> untouched;
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
TuioObject *tobj = (*tuioObject);
if (tobj->getTuioTime()!=currentFrameTime) untouched.push_back(tobj);
}
return untouched;
}
void TuioManager::stopUntouchedMovingObjects() {
std::list<TuioObject*> untouched;
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
TuioObject *tobj = (*tuioObject);
if ((tobj->getTuioTime()!=currentFrameTime) && (tobj->isMoving())) {
tobj->stop(currentFrameTime);
updateObject = true;
if (verbose)
std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
<< " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
}
}
}
void TuioManager::removeUntouchedStoppedObjects() {
std::list<TuioObject*>::iterator tuioObject = objectList.begin();
while (tuioObject!=objectList.end()) {
TuioObject *tobj = (*tuioObject);
if ((tobj->getTuioTime()!=currentFrameTime) && (!tobj->isMoving())) {
removeTuioObject(tobj);
tuioObject = objectList.begin();
} else tuioObject++;
}
}
void TuioManager::resetTuioObjects() {
std::list<TuioObject*>::iterator tuioObject = objectList.begin();
while (tuioObject!=objectList.end()) {
removeTuioObject((*tuioObject));
tuioObject = objectList.begin();
}
}
std::list<TuioCursor*> TuioManager::getUntouchedCursors() {
std::list<TuioCursor*> untouched;
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
TuioCursor *tcur = (*tuioCursor);
if (tcur->getTuioTime()!=currentFrameTime) untouched.push_back(tcur);
}
return untouched;
}
void TuioManager::stopUntouchedMovingCursors() {
std::list<TuioCursor*> untouched;
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
TuioCursor *tcur = (*tuioCursor);
if ((tcur->getTuioTime()!=currentFrameTime) && (tcur->isMoving())) {
tcur->stop(currentFrameTime);
updateCursor = true;
if (verbose)
std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY()
<< " " << tcur->getXSpeed() << " " << tcur->getYSpeed()<< " " << tcur->getMotionAccel() << " " << std::endl;
}
}
}
void TuioManager::removeUntouchedStoppedCursors() {
if (cursorList.size()==0) return;
std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin();
while (tuioCursor!=cursorList.end()) {
TuioCursor *tcur = (*tuioCursor);
if ((tcur->getTuioTime()!=currentFrameTime) && (!tcur->isMoving())) {
removeTuioCursor(tcur);
tuioCursor = cursorList.begin();
} else tuioCursor++;
}
}
void TuioManager::resetTuioCursors() {
std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin();
while (tuioCursor!=cursorList.end()) {
removeTuioCursor((*tuioCursor));
tuioCursor = cursorList.begin();
}
}
std::list<TuioBlob*> TuioManager::getUntouchedBlobs() {
std::list<TuioBlob*> untouched;
for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
TuioBlob *tblb = (*tuioBlob);
if (tblb->getTuioTime()!=currentFrameTime) untouched.push_back(tblb);
}
return untouched;
}
void TuioManager::stopUntouchedMovingBlobs() {
std::list<TuioBlob*> untouched;
for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
TuioBlob *tblb = (*tuioBlob);
if ((tblb->getTuioTime()!=currentFrameTime) && (tblb->isMoving())) {
tblb->stop(currentFrameTime);
updateBlob = true;
if (verbose)
std::cout << "set blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea()
<< " " << tblb->getXSpeed() << " " << tblb->getYSpeed() << " " << tblb->getRotationSpeed() << " " << tblb->getMotionAccel()<< " " << tblb->getRotationAccel() << " " << std::endl;
}
}
}
void TuioManager::removeUntouchedStoppedBlobs() {
std::list<TuioBlob*>::iterator tuioBlob = blobList.begin();
while (tuioBlob!=blobList.end()) {
TuioBlob *tblb = (*tuioBlob);
if ((tblb->getTuioTime()!=currentFrameTime) && (!tblb->isMoving())) {
removeTuioBlob(tblb);
tuioBlob = blobList.begin();
} else tuioBlob++;
}
}
void TuioManager::resetTuioBlobs() {
std::list<TuioBlob*>::iterator tuioBlob = blobList.begin();
while (tuioBlob!=blobList.end()) {
removeTuioBlob((*tuioBlob));
tuioBlob = blobList.begin();
}
}

View File

@@ -0,0 +1,389 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOMANAGER_H
#define INCLUDED_TUIOMANAGER_H
#include "TuioDispatcher.h"
#include <iostream>
#include <list>
#include <algorithm>
#define OBJ_MESSAGE_SIZE 108 // setMessage + fseqMessage size
#define CUR_MESSAGE_SIZE 88
#define BLB_MESSAGE_SIZE 116
namespace TUIO {
/**
* <p>The TuioManager class is the central TUIO session management component.</p>
* <p>During runtime the each frame is marked with the initFrame and commitFrame methods,
* while the currently present TuioObjects are managed by the server with ADD, UPDATE and REMOVE methods in analogy to the TuioClient's TuioListener interface.</p>
* <p><code>
* TuioManager *manager = new TuioManager();<br/>
* ...<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* TuioObject *tobj = server->addTuioObject(xpos,ypos, angle);<br/>
* TuioCursor *tcur = server->addTuioObject(xpos,ypos);<br/>
* TuioBlob *tblb = server->addTuioBlob(xpos,ypos,width,height,angle);<br/>
* server->commitFrame();<br/>
* ...<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* server->updateTuioObject(tobj, xpos,ypos, angle);<br/>
* server->updateTuioCursor(tcur, xpos,ypos);<br/>
* server->updateTuioBlob(tblb, xpos,ypos,width,height,angle);<br/>
* server->commitFrame();<br/>
* ...<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* server->removeTuioObject(tobj);<br/>
* server->removeTuioCursor(tcur);<br/>
* server->removeTuioBlob(tblb);<br/>
* server->commitFrame();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioManager : public TuioDispatcher {
public:
/**
* The default constructor creates a TuioManager
*/
TuioManager();
/**
* The destructor is doing nothing in particular.
*/
~TuioManager();
/**
* Creates a new TuioObject based on the given arguments.
* The new TuioObject is added to the TuioServer's internal list of active TuioObjects
* and a reference is returned to the caller.
*
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @return reference to the created TuioObject
*/
TuioObject* addTuioObject(int sym, float xp, float yp, float a);
/**
* Updates the referenced TuioObject based on the given arguments.
*
* @param tobj the TuioObject to update
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
void updateTuioObject(TuioObject *tobj, float xp, float yp, float a);
/**
* Removes the referenced TuioObject from the TuioServer's internal list of TuioObjects
* and deletes the referenced TuioObject afterwards
*
* @param tobj the TuioObject to remove
*/
void removeTuioObject(TuioObject *tobj);
/**
* Adds an externally managed TuioObject to the TuioServer's internal list of active TuioObjects
*
* @param tobj the TuioObject to add
*/
void addExternalTuioObject(TuioObject *tobj);
/**
* Updates an externally managed TuioObject
*
* @param tobj the TuioObject to update
*/
void updateExternalTuioObject(TuioObject *tobj);
/**
* Removes an externally managed TuioObject from the TuioServer's internal list of TuioObjects
* The referenced TuioObject is not deleted
*
* @param tobj the TuioObject to remove
*/
void removeExternalTuioObject(TuioObject *tobj);
/**
* Creates a new TuioCursor based on the given arguments.
* The new TuioCursor is added to the TuioServer's internal list of active TuioCursors
* and a reference is returned to the caller.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @return reference to the created TuioCursor
*/
TuioCursor* addTuioCursor(float xp, float yp);
/**
* Updates the referenced TuioCursor based on the given arguments.
*
* @param tcur the TuioObject to update
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
void updateTuioCursor(TuioCursor *tcur, float xp, float yp);
/**
* Removes the referenced TuioCursor from the TuioServer's internal list of TuioCursors
* and deletes the referenced TuioCursor afterwards
*
* @param tcur the TuioCursor to remove
*/
void removeTuioCursor(TuioCursor *tcur);
/**
* Adds an externally managed TuioCursor
*
* @param tcur the TuioCursor to add
*/
void addExternalTuioCursor(TuioCursor *tcur);
/**
* Updates an externally managed TuioCursor
*
* @param tcur the TuioCursor to update
*/
void updateExternalTuioCursor(TuioCursor *tcur);
/**
* Removes an externally managed TuioCursor from the TuioServer's internal list of TuioCursor
* The referenced TuioCursor is not deleted
*
* @param tcur the TuioCursor to remove
*/
void removeExternalTuioCursor(TuioCursor *tcur);
/**
* Creates a new TuioBlob based on the given arguments.
* The new TuioBlob is added to the TuioServer's internal list of active TuioBlobs
* and a reference is returned to the caller.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param angle the angle to assign
* @param width the width to assign
* @param height the height to assign
* @param area the area to assign
* @return reference to the created TuioBlob
*/
TuioBlob* addTuioBlob(float xp, float yp, float angle, float width, float height, float area);
/**
* Updates the referenced TuioBlob based on the given arguments.
*
* @param tblb the TuioObject to update
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param angle the angle to assign
* @param width the width to assign
* @param height the height to assign
* @param area the area to assign
*/
void updateTuioBlob(TuioBlob *tblb, float xp, float yp, float angle, float width, float height, float area);
/**
* Removes the referenced TuioBlob from the TuioServer's internal list of TuioBlobs
* and deletes the referenced TuioBlob afterwards
*
* @param tblb the TuioBlob to remove
*/
void removeTuioBlob(TuioBlob *tblb);
/**
* Updates an externally managed TuioBlob
*
* @param tblb the TuioBlob to update
*/
void addExternalTuioBlob(TuioBlob *tblb);
/**
* Updates an externally managed TuioBlob
*
* @param tblb the TuioBlob to update
*/
void updateExternalTuioBlob(TuioBlob *tblb);
/**
* Removes an externally managed TuioBlob from the TuioServer's internal list of TuioBlob
* The referenced TuioBlob is not deleted
*
* @param tblb the TuioBlob to remove
*/
void removeExternalTuioBlob(TuioBlob *tblb);
/**
* Initializes a new frame with the given TuioTime
*
* @param ttime the frame time
*/
void initFrame(TuioTime ttime);
/**
* Commits the current frame.
* Generates and sends TUIO messages of all currently active and updated TuioObjects and TuioCursors.
*/
void commitFrame();
/**
* Returns the next available Session ID for external use.
* @return the next available Session ID for external use
*/
long getSessionID();
/**
* Returns the current frame ID for external use.
* @return the current frame ID for external use
*/
long getFrameID();
/**
* Returns the current frame ID for external use.
* @return the current frame ID for external use
*/
TuioTime getFrameTime();
/**
* Returns a List of all currently inactive TuioObjects
*
* @return a List of all currently inactive TuioObjects
*/
std::list<TuioObject*> getUntouchedObjects();
/**
* Returns a List of all currently inactive TuioCursors
*
* @return a List of all currently inactive TuioCursors
*/
std::list<TuioCursor*> getUntouchedCursors();
/**
* Returns a List of all currently inactive TuioBlobs
*
* @return a List of all currently inactive TuioBlobs
*/
std::list<TuioBlob*> getUntouchedBlobs();
/**
* Calculates speed and acceleration values for all currently inactive TuioObjects
*/
void stopUntouchedMovingObjects();
/**
* Calculates speed and acceleration values for all currently inactive TuioCursors
*/
void stopUntouchedMovingCursors();
/**
* Calculates speed and acceleration values for all currently inactive TuioBlobs
*/
void stopUntouchedMovingBlobs();
/**
* Removes all currently inactive TuioObjects from the TuioServer's internal list of TuioObjects
*/
void removeUntouchedStoppedObjects();
/**
* Removes all currently inactive TuioCursors from the TuioServer's internal list of TuioCursors
*/
void removeUntouchedStoppedCursors();
/**
* Removes all currently inactive TuioCursors from the TuioServer's internal list of TuioBlobs
*/
void removeUntouchedStoppedBlobs();
/**
* Returns the TuioObject closest to the provided coordinates
* or NULL if there isn't any active TuioObject
*
* @return the closest TuioObject to the provided coordinates or NULL
*/
TuioObject* getClosestTuioObject(float xp, float yp);
/**
* Returns the TuioCursor closest to the provided coordinates
* or NULL if there isn't any active TuioCursor
*
* @return the closest TuioCursor corresponding to the provided coordinates or NULL
*/
TuioCursor* getClosestTuioCursor(float xp, float yp);
/**
* Returns the TuioBlob closest to the provided coordinates
* or NULL if there isn't any active TuioBlob
*
* @return the closest TuioBlob corresponding to the provided coordinates or NULL
*/
TuioBlob* getClosestTuioBlob(float xp, float yp);
/**
* The TuioServer prints verbose TUIO event messages to the console if set to true.
* @param verbose print verbose messages if set to true
*/
void setVerbose(bool verbose) { this->verbose=verbose; }
bool isVerbose() { return verbose; }
void setInversion(bool ix, bool iy, bool ia) {
invert_x = ix;
invert_y = iy;
invert_a = ia;
};
void setInvertXpos(bool ix) { invert_x = ix; };
void setInvertYpos(bool iy) { invert_y = iy; };
void setInvertAngle(bool ia) { invert_a = ia; };
bool getInvertXpos() { return invert_x; };
bool getInvertYpos() { return invert_y; };
bool getInvertAngle() { return invert_a; };
void resetTuioObjects();
void resetTuioCursors();
void resetTuioBlobs();
protected:
std::list<TuioCursor*> freeCursorList;
std::list<TuioCursor*> freeCursorBuffer;
std::list<TuioBlob*> freeBlobList;
std::list<TuioBlob*> freeBlobBuffer;
TuioTime currentFrameTime;
long currentFrame;
int maxCursorID;
int maxBlobID;
long sessionID;
bool updateObject;
bool updateCursor;
bool updateBlob;
bool verbose;
bool invert_x;
bool invert_y;
bool invert_a;
};
}
#endif /* INCLUDED_TUIOMANAGER_H */

View File

@@ -0,0 +1,165 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioObject.h"
using namespace TUIO;
TuioObject::TuioObject (TuioTime ttime, long si, int sym, float xp, float yp, float a):TuioContainer(ttime, si, xp, yp) {
symbol_id = sym;
angle = a;
angle_sum = a;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
angleFilter = NULL;
angleThreshold = 0.0f;
}
TuioObject::TuioObject (long si, int sym, float xp, float yp, float a):TuioContainer(si, xp, yp) {
symbol_id = sym;
angle = a;
angle_sum = a;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
angleFilter = NULL;
angleThreshold = 0.0f;
}
TuioObject::TuioObject (TuioObject *tobj):TuioContainer(tobj) {
symbol_id = tobj->getSymbolID();
angle = tobj->getAngle();
angle_sum = tobj->getAngleSum();
rotation_speed = 0.0f;
rotation_accel = 0.0f;
angleFilter = NULL;
angleThreshold = 0.0f;
}
void TuioObject::update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
TuioContainer::update(ttime,xp,yp,xs,ys,ma);
angle = a;
angle_sum = a;
rotation_speed = rs;
rotation_accel = ra;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void TuioObject::update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
TuioContainer::update(xp,yp,xs,ys,ma);
angle = a;
angle_sum = a;
rotation_speed = rs;
rotation_accel = ra;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void TuioObject::update (TuioTime ttime, float xp, float yp, float a) {
TuioPoint lastPoint = path.back();
TuioContainer::update(ttime,xp,yp);
TuioTime diffTime = currentTime - lastPoint.getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
float last_rotation_speed = rotation_speed;
float prev_angle = angle_sum;
float da = a-angle;
if (da > M_PI/2.0f) angle_sum += (da-2*M_PI);
else if (da < M_PI/-2.0f) angle_sum += (da+2*M_PI);
else angle_sum += da;
if (angleFilter) angle_sum = angleFilter->filter(angle_sum,dt);
if (fabs(angle_sum-prev_angle)<angleThreshold) angle_sum = prev_angle;
int m = floor(angle_sum/(2*M_PI));
angle = angle_sum-(m*(2*M_PI));
da = (angle-a)/(2*M_PI);
if (da > 0.75f) da-=1.0f;
else if (da < -0.75f) da+=1.0f;
rotation_speed = (float)da/dt;
rotation_accel = (rotation_speed - last_rotation_speed)/dt;
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void TuioObject::stop (TuioTime ttime) {
update(ttime,xpos,ypos,angle);
}
void TuioObject::update (TuioObject *tobj) {
TuioContainer::update(tobj);
angle = tobj->getAngle();
angle_sum = tobj->getAngleSum();
rotation_speed = tobj->getRotationSpeed();
rotation_accel = tobj->getRotationAccel();
if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
int TuioObject::getSymbolID() const{
return symbol_id;
}
float TuioObject::getAngle() const{
return angle;
}
float TuioObject::getAngleSum() const{
return angle_sum;
}
float TuioObject::getAngleDegrees() const{
return (float)(angle/M_PI*180);
}
float TuioObject::getRotationSpeed() const{
return rotation_speed;
}
float TuioObject::getRotationAccel() const{
return rotation_accel;
}
bool TuioObject::isMoving() const{
if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
else return false;
}
void TuioObject::addAngleThreshold(float thresh) {
angleThreshold = thresh;
}
void TuioObject::removeAngleThreshold() {
angleThreshold = 0.0f;
}
void TuioObject::addAngleFilter(float mcut, float beta) {
if (angleFilter) delete angleFilter;
angleFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
}
void TuioObject::removeAngleFilter() {
if (angleFilter) delete angleFilter;
angleFilter = NULL;
}

View File

@@ -0,0 +1,213 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOOBJECT_H
#define INCLUDED_TUIOOBJECT_H
#include "TuioContainer.h"
namespace TUIO {
/**
* The TuioObject class encapsulates /tuio/2Dobj TUIO objects.
*
* @author Martin Kaltenbrunner
* @version 1.1.6
*/
class LIBDECL TuioObject: public TuioContainer {
protected:
/**
* The individual symbol ID number that is assigned to each TuioObject.
*/
int symbol_id;
/**
* The rotation angle value.
*/
float angle;
/**
* The accumulated angle value.
*/
float angle_sum;
/**
* The rotation speed value.
*/
float rotation_speed;
/**
* The rotation acceleration value.
*/
float rotation_accel;
float angleThreshold;
OneEuroFilter *angleFilter;
public:
using TuioContainer::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, Symbol ID, X and Y coordinate and angle to the newly created TuioObject.
*
* @param ttime the TuioTime to assign
* @param si the Session ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioObject (TuioTime ttime, long si, int sym, float xp, float yp, float a);
/**
* This constructor takes the provided Session ID, Symbol ID, X and Y coordinate
* and angle, and assigs these values to the newly created TuioObject.
*
* @param si the Session ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioObject (long si, int sym, float xp, float yp, float a);
/**
* This constructor takes the atttibutes of the provided TuioObject
* and assigs these values to the newly created TuioObject.
*
* @param tobj the TuioObject to assign
*/
TuioObject (TuioObject *tobj);
/**
* The destructor is doing nothing in particular.
*/
virtual ~TuioObject() {
if (angleFilter) delete angleFilter;
};
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate, angle, X and Y velocity, motion acceleration,
* rotation speed and rotation acceleration to the private TuioObject attributes.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle coordinate to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param rs the rotation velocity to assign
* @param ma the motion acceleration to assign
* @param ra the rotation acceleration to assign
*/
void update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra);
/**
* Assigns the provided X and Y coordinate, angle, X and Y velocity, motion acceleration
* rotation velocity and rotation acceleration to the private TuioContainer attributes.
* The TuioTime time stamp remains unchanged.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle coordinate to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param rs the rotation velocity to assign
* @param ma the motion acceleration to assign
* @param ra the rotation acceleration to assign
*/
void update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate and angle to the private TuioObject attributes.
* The speed and accleration values are calculated accordingly.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle coordinate to assign
*/
void update (TuioTime ttime, float xp, float yp, float a);
/**
* This method is used to calculate the speed and acceleration values of a
* TuioObject with unchanged position and angle.
*/
void stop (TuioTime ttime);
/**
* Takes the atttibutes of the provided TuioObject
* and assigs these values to this TuioObject.
* The TuioTime time stamp of this TuioContainer remains unchanged.
*
* @param tobj the TuioContainer to assign
*/
void update (TuioObject *tobj);
/**
* Returns the symbol ID of this TuioObject.
* @return the symbol ID of this TuioObject
*/
int getSymbolID() const;
/**
* Returns the rotation angle of this TuioObject.
* @return the rotation angle of this TuioObject
*/
float getAngle() const;
/**
* Returns the accumulated rotation angle of this TuioObject.
* @return the accumulated rotation angle of this TuioObject
*/
float getAngleSum() const;
/**
* Returns the rotation angle in degrees of this TuioObject.
* @return the rotation angle in degrees of this TuioObject
*/
float getAngleDegrees() const;
/**
* Returns the rotation speed of this TuioObject.
* @return the rotation speed of this TuioObject
*/
float getRotationSpeed() const;
/**
* Returns the rotation acceleration of this TuioObject.
* @return the rotation acceleration of this TuioObject
*/
float getRotationAccel() const;
/**
* Returns true of this TuioObject is moving.
* @return true of this TuioObject is moving
*/
bool isMoving() const;
void addAngleThreshold(float thresh);
void removeAngleThreshold();
void addAngleFilter(float mcut, float beta);
void removeAngleFilter();
};
}
#endif

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,13 +18,18 @@
#include "TuioPoint.h"
using namespace TUIO2;
using namespace TUIO;
TuioPoint::TuioPoint (float xp, float yp) {
xpos = xp;
ypos = yp;
currentTime = TuioTime::getSystemTime();
currentTime = TuioTime::getSessionTime();
startTime = currentTime;
xposFilter = NULL;
yposFilter = NULL;
posThreshold = 0.0f;
}
TuioPoint::TuioPoint (TuioTime ttime, float xp, float yp) {
@@ -32,13 +37,23 @@ TuioPoint::TuioPoint (TuioTime ttime, float xp, float yp) {
ypos = yp;
currentTime = ttime;
startTime = currentTime;
xposFilter = NULL;
yposFilter = NULL;
posThreshold = 0.0f;
}
TuioPoint::TuioPoint (TuioPoint *tpoint) {
xpos = tpoint->getX();
ypos = tpoint->getY();
currentTime = TuioTime::getSystemTime();
currentTime = TuioTime::getSessionTime();
startTime = currentTime;
xposFilter = NULL;
yposFilter = NULL;
posThreshold = 0.0f;
}
void TuioPoint::update (TuioPoint *tpoint) {
@@ -49,16 +64,30 @@ void TuioPoint::update (TuioPoint *tpoint) {
void TuioPoint::update (float xp, float yp) {
xpos = xp;
ypos = yp;
}
}
void TuioPoint::update (TuioTime ttime, float xp, float yp) {
xpos = xp;
ypos = yp;
if (xposFilter && yposFilter) {
TuioTime diffTime = ttime - startTime;
float dt = diffTime.getTotalMilliseconds()/1000.0f;
xp = xposFilter->filter(xp,dt);
yp = yposFilter->filter(yp,dt);
//std::cout << dt << " " << xp << " " << xpos << " " << yp << " " << ypos << std::endl;
}
float dx = fabs(xpos - xp);
float dy = fabs(ypos - yp);
if ((dx>posThreshold) || (dy>posThreshold)) {
xpos = xp;
ypos = yp;
}
currentTime = ttime;
}
float TuioPoint::getX() const{
float TuioPoint::getX() const{
return xpos;
}
@@ -87,10 +116,10 @@ float TuioPoint::getAngle(float xp, float yp) const{
float side = xpos-xp;
float height = ypos-yp;
float distance = getDistance(xp,yp);
float angle = (float)(asin(side/distance)+M_PI/2);
if (height<0) angle = 2.0f*(float)M_PI-angle;
return angle;
}
@@ -106,7 +135,7 @@ float TuioPoint::getAngleDegrees(TuioPoint *tpoint) const{
return ((getAngle(tpoint)/(float)M_PI)*180.0f);
}
int TuioPoint::getScreenX(int width) const{
int TuioPoint::getScreenX(int width) const{
return (int)floor(xpos*width+0.5f);
}
@@ -114,7 +143,7 @@ int TuioPoint::getScreenY(int height) const{
return (int)floor(ypos*height+0.5f);
}
TuioTime TuioPoint::getTuioTime() const{
TuioTime TuioPoint::getTuioTime() const{
return currentTime;
}
@@ -122,3 +151,26 @@ TuioTime TuioPoint::getStartTime() const{
return startTime;
}
void TuioPoint::addPositionThreshold(float thresh) {
posThreshold = thresh;
}
void TuioPoint::removePositionThreshold() {
posThreshold = 0.0f;
}
void TuioPoint::addPositionFilter(float mcut, float beta) {
if (xposFilter) delete xposFilter;
xposFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
if (yposFilter) delete yposFilter;
yposFilter = new OneEuroFilter(60.0f, mcut, beta, 1.0f);
}
void TuioPoint::removePositionFilter() {
if (xposFilter) delete xposFilter;
xposFilter = NULL;
if (yposFilter) delete yposFilter;
yposFilter = NULL;
}

View File

@@ -1,17 +1,17 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
@@ -20,22 +20,22 @@
#define INCLUDED_TUIOPOINT_H
#include "TuioTime.h"
#include "limits.h"
#include "OneEuroFilter.h"
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace TUIO2 {
namespace TUIO {
/**
* The TuioPoint class on the one hand is a simple tobj and utility class to handle TUIO positions in general,
* on the other hand the TuioPoint is the base class for the TuioPointer and TuioToken classes.
* The TuioPoint class on the one hand is a simple container and utility class to handle TUIO positions in general,
* on the other hand the TuioPoint is the base class for the TuioCursor and TuioObject classes.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
* @version 1.1.6
*/
class LIBDECL TuioPoint {
protected:
@@ -55,19 +55,20 @@ namespace TUIO2 {
* The creation time of this TuioPoint represented as TuioTime (time since session start)
*/
TuioTime startTime;
OneEuroFilter *xposFilter;
OneEuroFilter *yposFilter;
float posThreshold;
public:
/**
* This constructor takes two floating point coordinate arguments
* and sets the coordinate attributes to these values.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
TuioPoint (float xp, float yp);
/**
* This constructor takes a TuioTime object and two floating point coordinate arguments and sets
* The default constructor takes no arguments and sets
* its coordinate attributes to zero and its time stamp to the current session time.
*/
TuioPoint (float xp, float yp);
/**
* This constructor takes a TuioTime object and two floating point coordinate arguments and sets
* its coordinate attributes to these values and its time stamp to the provided TUIO time object.
*
* @param ttime the TuioTime to assign
@@ -75,37 +76,40 @@ namespace TUIO2 {
* @param yp the Y coordinate to assign
*/
TuioPoint (TuioTime ttime, float xp, float yp);
/**
* This constructor takes a TuioPoint argument and sets its coordinate attributes
* This constructor takes a TuioPoint argument and sets its coordinate attributes
* to the coordinates of the provided TuioPoint and its time stamp to the current session time.
*
* @param tpoint the TuioPoint to assign
*/
TuioPoint (TuioPoint *tpoint);
/**
* The destructor is doing nothing in particular.
* The destructor is doing nothing in particular.
*/
~TuioPoint(){};
virtual ~TuioPoint(){
if (xposFilter) delete xposFilter;
if (yposFilter) delete yposFilter;
};
/**
* Takes a TuioPoint argument and updates its coordinate attributes
* Takes a TuioPoint argument and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and leaves its time stamp unchanged.
*
* @param tpoint the TuioPoint to assign
*/
void update (TuioPoint *tpoint);
/**
* Takes two floating point coordinate arguments and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and leaves its time stamp unchanged.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
*/
void update (float xp, float yp);
*/
void update (float xp, float yp);
/**
* Takes a TuioTime object and two floating point coordinate arguments and updates its coordinate attributes
* to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object.
@@ -115,7 +119,8 @@ namespace TUIO2 {
* @param yp the Y coordinate to assign
*/
void update (TuioTime ttime, float xp, float yp);
/**
* Returns the X coordinate of this TuioPoint.
* @return the X coordinate of this TuioPoint
@@ -208,6 +213,14 @@ namespace TUIO2 {
* @return the start time of this TuioPoint as TuioTime
*/
TuioTime getStartTime() const;
void addPositionThreshold(float thresh);
void removePositionThreshold();
void addPositionFilter(float mcut, float beta);
void removePositionFilter();
};
}
#endif

View File

@@ -0,0 +1,634 @@
/*
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioServer.h"
#include "UdpSender.h"
using namespace TUIO;
using namespace osc;
TuioServer::TuioServer()
:full_update (false)
,periodic_update (false)
,objectProfileEnabled (true)
,cursorProfileEnabled (true)
,blobProfileEnabled (true)
,source_name (NULL)
{
OscSender *oscsend = new UdpSender();
initialize(oscsend);
}
TuioServer::TuioServer(const char *host, int port)
:full_update (false)
,periodic_update (false)
,objectProfileEnabled (true)
,cursorProfileEnabled (true)
,blobProfileEnabled (true)
,source_name (NULL)
{
OscSender *oscsend = new UdpSender(host,port);
initialize(oscsend);
}
TuioServer::TuioServer(OscSender *oscsend)
:full_update (false)
,periodic_update (false)
,objectProfileEnabled (true)
,cursorProfileEnabled (true)
,blobProfileEnabled (true)
,source_name (NULL)
{
initialize(oscsend);
}
void TuioServer::initialize(OscSender *oscsend) {
senderList.push_back(oscsend);
int size = oscsend->getBufferSize();
oscBuffer = new char[size];
oscPacket = new osc::OutboundPacketStream(oscBuffer,size);
fullBuffer = new char[size];
fullPacket = new osc::OutboundPacketStream(oscBuffer,size);
objectUpdateTime = TuioTime(currentFrameTime);
cursorUpdateTime = TuioTime(currentFrameTime);
blobUpdateTime = TuioTime(currentFrameTime);
if (cursorProfileEnabled) sendEmptyCursorBundle();
if (objectProfileEnabled) sendEmptyObjectBundle();
if (blobProfileEnabled) sendEmptyBlobBundle();
invert_x = false;
invert_y = false;
invert_a = false;
}
TuioServer::~TuioServer() {
initFrame(TuioTime::getSessionTime());
stopUntouchedMovingCursors();
stopUntouchedMovingObjects();
stopUntouchedMovingBlobs();
initFrame(TuioTime::getSessionTime());
removeUntouchedStoppedCursors();
removeUntouchedStoppedObjects();
removeUntouchedStoppedBlobs();
if (cursorProfileEnabled) sendEmptyCursorBundle();
if (objectProfileEnabled) sendEmptyObjectBundle();
if (blobProfileEnabled) sendEmptyBlobBundle();
delete []oscBuffer;
delete oscPacket;
delete []fullBuffer;
delete fullPacket;
if (source_name) delete[] source_name;
for (unsigned int i=0;i<senderList.size();i++)
delete senderList[i];
}
void TuioServer::addOscSender(OscSender *sender) {
// add source address if previously local
/*if ((source_name) && (primary_sender->isLocal()) && (senderList.size()==1)) {
setSourceName(source_name);
}*/
// resize packets to smallest transport method
unsigned int size = sender->getBufferSize();
if (size<oscPacket->Capacity()) {
osc::OutboundPacketStream *temp = oscPacket;
oscPacket = new osc::OutboundPacketStream(oscBuffer,size);
delete temp;
temp = fullPacket;
fullPacket = new osc::OutboundPacketStream(oscBuffer,size);
delete temp;
}
senderList.push_back(sender);
}
void TuioServer::deliverOscPacket(osc::OutboundPacketStream *packet) {
for (unsigned int i=0;i<senderList.size();i++)
senderList[i]->sendOscPacket(packet);
}
void TuioServer::setSourceName(const char *name, const char *ip) {
if (!source_name) source_name = new char[256];
sprintf(source_name,"%s@%s",name,ip);
}
void TuioServer::setSourceName(const char *src) {
if (!source_name) source_name = new char[256];
/*if (senderList[0]->isLocal()) {
sprintf(source_name,"%s",src);
} else {*/
char hostname[64];
char *source_addr = NULL;
struct hostent *hp = NULL;
struct in_addr *addr = NULL;
gethostname(hostname, 64);
hp = gethostbyname(hostname);
if (hp==NULL) {
sprintf(hostname, "%s.local", hostname);
hp = gethostbyname(hostname);
}
if (hp!=NULL) {
for (int i = 0; hp->h_addr_list[i] != 0; ++i) {
addr = (struct in_addr *)(hp->h_addr_list[i]);
//std::cout << inet_ntoa(*addr) << std::endl;
source_addr = inet_ntoa(*addr);
}
} else {
//generate a random internet address
srand ( (unsigned int)time(NULL) );
int32 r = rand();
addr = (struct in_addr*)&r;
source_addr = inet_ntoa(*addr);
}
sprintf(source_name,"%s@%s",src,source_addr);
//}
std::cout << "tuio/src " << source_name << std::endl;
}
void TuioServer::commitFrame() {
TuioManager::commitFrame();
if(updateObject) {
startObjectBundle();
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<OBJ_MESSAGE_SIZE) {
sendObjectBundle(currentFrame);
startObjectBundle();
}
TuioObject *tobj = (*tuioObject);
if ((full_update) || (tobj->getTuioTime()==currentFrameTime)) addObjectMessage(tobj);
}
objectUpdateTime = TuioTime(currentFrameTime);
sendObjectBundle(currentFrame);
} else if (objectProfileEnabled && periodic_update) {
TuioTime timeCheck = currentFrameTime - objectUpdateTime;
if(timeCheck.getSeconds()>=update_interval) {
objectUpdateTime = TuioTime(currentFrameTime);
startObjectBundle();
if (full_update) {
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<OBJ_MESSAGE_SIZE) {
sendObjectBundle(currentFrame);
startObjectBundle();
}
addObjectMessage(*tuioObject);
}
}
sendObjectBundle(currentFrame);
}
}
updateObject = false;
if(updateCursor) {
startCursorBundle();
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<CUR_MESSAGE_SIZE) {
sendCursorBundle(currentFrame);
startCursorBundle();
}
TuioCursor *tcur = (*tuioCursor);
if ((full_update) || (tcur->getTuioTime()==currentFrameTime)) addCursorMessage(tcur);
}
cursorUpdateTime = TuioTime(currentFrameTime);
sendCursorBundle(currentFrame);
} else if (cursorProfileEnabled && periodic_update) {
TuioTime timeCheck = currentFrameTime - cursorUpdateTime;
if(timeCheck.getSeconds()>=update_interval) {
cursorUpdateTime = TuioTime(currentFrameTime);
startCursorBundle();
if (full_update) {
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<CUR_MESSAGE_SIZE) {
sendCursorBundle(currentFrame);
startCursorBundle();
}
addCursorMessage(*tuioCursor);
}
}
sendCursorBundle(currentFrame);
}
}
updateCursor = false;
if(updateBlob) {
startBlobBundle();
for (std::list<TuioBlob*>::iterator tuioBlob =blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<BLB_MESSAGE_SIZE) {
sendBlobBundle(currentFrame);
startBlobBundle();
}
TuioBlob *tblb = (*tuioBlob);
if ((full_update) || (tblb->getTuioTime()==currentFrameTime)) addBlobMessage(tblb);
}
blobUpdateTime = TuioTime(currentFrameTime);
sendBlobBundle(currentFrame);
} else if (blobProfileEnabled && periodic_update) {
TuioTime timeCheck = currentFrameTime - blobUpdateTime;
if(timeCheck.getSeconds()>=update_interval) {
blobUpdateTime = TuioTime(currentFrameTime);
startBlobBundle();
if (full_update) {
for (std::list<TuioBlob*>::iterator tuioBlob =blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<BLB_MESSAGE_SIZE) {
sendBlobBundle(currentFrame);
startBlobBundle();
}
addBlobMessage(*tuioBlob);
}
}
sendBlobBundle(currentFrame);
}
}
updateBlob = false;
}
void TuioServer::sendEmptyCursorBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "alive" << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "fseq" << -1 << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::startCursorBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "alive";
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
if ((*tuioCursor)->getTuioState()!=TUIO_ADDED) (*oscPacket) << (int32)((*tuioCursor)->getSessionID());
}
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addCursorMessage(TuioCursor *tcur) {
if (tcur->getTuioState()==TUIO_ADDED) return;
float xpos = tcur->getX();
float xvel = tcur->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = tcur->getY();
float yvel = tcur->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
(*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "set";
(*oscPacket) << (int32)(tcur->getSessionID()) << xpos << ypos;
(*oscPacket) << xvel << yvel << tcur->getMotionAccel();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::sendCursorBundle(long fseq) {
(*oscPacket) << osc::BeginMessage( "/tuio/2Dcur") << "fseq" << (int32)fseq << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::sendEmptyObjectBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "alive" << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "fseq" << -1 << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::startObjectBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "alive";
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
(*oscPacket) << (int32)((*tuioObject)->getSessionID());
}
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addObjectMessage(TuioObject *tobj) {
float xpos = tobj->getX();
float xvel = tobj->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = tobj->getY();
float yvel = tobj->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
float angle = tobj->getAngle();
float rvel = tobj->getRotationSpeed();
if (invert_a) {
angle = 2.0f*(float)M_PI - angle;
rvel = -1 * rvel;
}
(*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "set";
(*oscPacket) << (int32)(tobj->getSessionID()) << tobj->getSymbolID() << xpos << ypos << angle;
(*oscPacket) << xvel << yvel << rvel << tobj->getMotionAccel() << tobj->getRotationAccel();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::sendObjectBundle(long fseq) {
(*oscPacket) << osc::BeginMessage( "/tuio/2Dobj") << "fseq" << (int32)fseq << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::sendEmptyBlobBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "alive" << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "fseq" << -1 << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::startBlobBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source_name) (*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "source" << source_name << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "alive";
for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
if ((*tuioBlob)->getTuioState()!=TUIO_ADDED) (*oscPacket) << (int32)((*tuioBlob)->getSessionID());
}
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addBlobMessage(TuioBlob *tblb) {
if (tblb->getTuioState()==TUIO_ADDED) return;
float xpos = tblb->getX();
float xvel = tblb->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = tblb->getY();
float yvel = tblb->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
float angle = tblb->getAngle();
float rvel = tblb->getRotationSpeed();
if (invert_a) {
angle = 2.0f*(float)M_PI - angle;
rvel = -1 * rvel;
}
(*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "set";
(*oscPacket) << (int32)(tblb->getSessionID()) << xpos << ypos << angle << tblb->getWidth() << tblb->getHeight() << tblb->getArea();
(*oscPacket) << xvel << yvel << rvel << tblb->getMotionAccel() << tblb->getRotationAccel();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::sendBlobBundle(long fseq) {
(*oscPacket) << osc::BeginMessage( "/tuio/2Dblb") << "fseq" << (int32)fseq << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::sendFullMessages() {
// prepare the cursor packet
fullPacket->Clear();
(*fullPacket) << osc::BeginBundleImmediate;
if (source_name) (*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "source" << source_name << osc::EndMessage;
// add the cursor alive message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "alive";
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++)
(*fullPacket) << (int32)((*tuioCursor)->getSessionID());
(*fullPacket) << osc::EndMessage;
// add all current cursor set messages
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) {
// start a new packet if we exceed the packet capacity
if ((fullPacket->Capacity()-fullPacket->Size())<CUR_MESSAGE_SIZE) {
// add the immediate fseq message and send the cursor packet
(*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "fseq" << -1 << osc::EndMessage;
(*fullPacket) << osc::EndBundle;
deliverOscPacket( fullPacket );
// prepare the new cursor packet
fullPacket->Clear();
(*fullPacket) << osc::BeginBundleImmediate;
if (source_name) (*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "source" << source_name << osc::EndMessage;
// add the cursor alive message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "alive";
for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++)
(*fullPacket) << (int32)((*tuioCursor)->getSessionID());
(*fullPacket) << osc::EndMessage;
}
float xpos = (*tuioCursor)->getX();
float xvel = (*tuioCursor)->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = (*tuioCursor)->getY();
float yvel = (*tuioCursor)->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
// add the actual cursor set message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "set";
(*fullPacket) << (int32)((*tuioCursor)->getSessionID()) << xpos << ypos;
(*fullPacket) << xvel << yvel <<(*tuioCursor)->getMotionAccel();
(*fullPacket) << osc::EndMessage;
}
// add the immediate fseq message and send the cursor packet
(*fullPacket) << osc::BeginMessage( "/tuio/2Dcur") << "fseq" << -1 << osc::EndMessage;
(*fullPacket) << osc::EndBundle;
deliverOscPacket( fullPacket );
// prepare the object packet
fullPacket->Clear();
(*fullPacket) << osc::BeginBundleImmediate;
if (source_name) (*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "source" << source_name << osc::EndMessage;
// add the object alive message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "alive";
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++)
(*fullPacket) << (int32)((*tuioObject)->getSessionID());
(*fullPacket) << osc::EndMessage;
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
// start a new packet if we exceed the packet capacity
if ((fullPacket->Capacity()-fullPacket->Size())<OBJ_MESSAGE_SIZE) {
// add the immediate fseq message and send the object packet
(*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "fseq" << -1 << osc::EndMessage;
(*fullPacket) << osc::EndBundle;
deliverOscPacket( fullPacket );
// prepare the new object packet
fullPacket->Clear();
(*fullPacket) << osc::BeginBundleImmediate;
if (source_name) (*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "source" << source_name << osc::EndMessage;
// add the object alive message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "alive";
for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++)
(*fullPacket) << (int32)((*tuioObject)->getSessionID());
(*fullPacket) << osc::EndMessage;
}
float xpos = (*tuioObject)->getX();
float xvel = (*tuioObject)->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = (*tuioObject)->getY();
float yvel = (*tuioObject)->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
float angle = (*tuioObject)->getAngle();
float rvel = (*tuioObject)->getRotationSpeed();
if (invert_a) {
angle = 2.0f*(float)M_PI - angle;
rvel = -1 * rvel;
}
// add the actual object set message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "set";
(*fullPacket) << (int32)((*tuioObject)->getSessionID()) << (*tuioObject)->getSymbolID() << xpos << ypos << angle;
(*fullPacket) << xvel << yvel << rvel << (*tuioObject)->getMotionAccel() << (*tuioObject)->getRotationAccel();
(*fullPacket) << osc::EndMessage;
}
// add the immediate fseq message and send the object packet
(*fullPacket) << osc::BeginMessage( "/tuio/2Dobj") << "fseq" << -1 << osc::EndMessage;
(*fullPacket) << osc::EndBundle;
deliverOscPacket( fullPacket );
// prepare the blob packet
fullPacket->Clear();
(*fullPacket) << osc::BeginBundleImmediate;
if (source_name) (*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "source" << source_name << osc::EndMessage;
// add the object alive message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "alive";
for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++)
(*fullPacket) << (int32)((*tuioBlob)->getSessionID());
(*fullPacket) << osc::EndMessage;
for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
// start a new packet if we exceed the packet capacity
if ((fullPacket->Capacity()-fullPacket->Size())<BLB_MESSAGE_SIZE) {
// add the immediate fseq message and send the object packet
(*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "fseq" << -1 << osc::EndMessage;
(*fullPacket) << osc::EndBundle;
deliverOscPacket( fullPacket );
// prepare the new blob packet
fullPacket->Clear();
(*fullPacket) << osc::BeginBundleImmediate;
if (source_name) (*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "source" << source_name << osc::EndMessage;
// add the blob alive message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "alive";
for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++)
(*fullPacket) << (int32)((*tuioBlob)->getSessionID());
(*fullPacket) << osc::EndMessage;
}
float xpos = (*tuioBlob)->getX();
float xvel = (*tuioBlob)->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = (*tuioBlob)->getY();
float yvel = (*tuioBlob)->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
float angle = (*tuioBlob)->getAngle();
float rvel = (*tuioBlob)->getRotationSpeed();
if (invert_a) {
angle = 2.0f*(float)M_PI - angle;
rvel = -1 * rvel;
}
// add the actual blob set message
(*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "set";
(*fullPacket) << (int32)((*tuioBlob)->getSessionID()) << xpos << ypos << angle << (*tuioBlob)->getWidth() << (*tuioBlob)->getHeight() << (*tuioBlob)->getArea();
(*fullPacket) << xvel << yvel << rvel << (*tuioBlob)->getMotionAccel() << (*tuioBlob)->getRotationAccel();
(*fullPacket) << osc::EndMessage;
}
// add the immediate fseq message and send the blob packet
(*fullPacket) << osc::BeginMessage( "/tuio/2Dblb") << "fseq" << -1 << osc::EndMessage;
(*fullPacket) << osc::EndBundle;
deliverOscPacket( fullPacket );
}

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,11 +16,14 @@
License along with this library.
*/
#ifndef INCLUDED_TUIOSERVER_H
#define INCLUDED_TUIOSERVER_H
#ifndef INCLUDED_TuioServer_H
#define INCLUDED_TuioServer_H
#include "TuioManager.h"
#include "UdpSender.h"
#include "TcpSender.h"
#include "WebSockSender.h"
#include "FlashSender.h"
#include <iostream>
#include <vector>
#include <stdio.h>
@@ -30,46 +33,40 @@
#include <unistd.h>
#endif
#define TOK_MESSAGE_SIZE 108
#define PTR_MESSAGE_SIZE 68
#define BND_MESSAGE_SIZE 116
#define SYM_MESSAGE_SIZE 116
#define ALV_MESSAGE_SIZE 20
namespace TUIO2 {
namespace TUIO {
/**
* <p>The TuioServer class is the central TUIO protocol encoder component.
* In order to encode and send TUIO messages an instance of TuioServer needs to be created. The TuioServer instance then generates TUIO messages
* which are deliverered by the provided OSCSender. The shown UDPSender send OSC to UDP port 3333 on localhost or to the configured host and port.</p>
* <p>During runtime the each frame is marked with the initFrame and commitFrame methods,
* while the currently present TuioTokens are managed by the server with ADD, UPDATE and REMOVE methods in analogy to the TuioClient's TuioListener interface.</p>
* while the currently present TuioObjects are managed by the server with ADD, UPDATE and REMOVE methods in analogy to the TuioClient's TuioListener interface.</p>
*<p>See the SimpleSimulator example project for further hints on how to use the TuioServer class and its various methods.
* <p><code>
* OscSender *sender = new UDPSender();</br>
* TuioServer *server = new TuioServer(sender);<br/>
* server->setSource(src); // passes a TuioSource* argument<br/>
* server->setSourceName("MyTuioSource"); // optional for TUIO 1.1<br/>
* ...<br/>
* server->initTuioFrame(TuioTime::getSessionTime());<br/>
* TuioToken *ttok = server->addTuioToken(xpos,ypos,angle);<br/>
* TuioPointer *tptr = server->addTuioPointer(xpos,ypos,width,pressure);<br/>
* TuioBounds *tbnd = server->addTuioBounds(xpos,ypos,angle,width,height,area);<br/>
* server->commitTuioFrame();<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* TuioObject *tobj = server->addTuioObject(xpos,ypos,angle);<br/>
* TuioCursor *tcur = server->addTuiCursor(xpos,ypos);<br/>
* TuioBlob *tblb = server->addTuioBlob(xpos,ypos,angle,width,height, area);<br/>
* server->commitFrame();<br/>
* ...<br/>
* server->initTuioFrame(TuioTime::getSessionTime());<br/>
* server->updateTuioToken(ttok,xpos,ypos,angle);<br/>
* server->updateTuioPointer(tptr,xpos,ypos,width,pressure);<br/>
* server->updateTuioBounds(tbnd,xpos,ypos,angle,width,height,area);<br/>
* server->commitTuioFrame();<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* server->updateTuioObject(tobj,xpos,ypos,angle);<br/>
* server->updateTuioCursor(tcur,xpos,ypos);<br/>
* server->updateTuioBlob(tblb,xpos,ypos,angle,width,height,area);<br/>
* server->commitFrame();<br/>
* ...<br/>
* server->initTuioFrame(TuioTime::getSessionTime());<br/>
* server->removeTuioToken(ttok);<br/>
* server->removeTuioPointer(tptr);<br/>
* server->removeTuioBounds(tbnd);<br/>
* server->commitTuioFrame();<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* server->removeTuioObject(tobj);<br/>
* server->removeTuioCursor(tcur);<br/>
* server->removeTuioBlob(tblb);<br/>
* server->commitFrame();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
* @version 1.1.6
*/
class LIBDECL TuioServer : public TuioManager {
@@ -86,7 +83,7 @@ namespace TUIO2 {
* @param host the host name for UDP deleivery
* @param port the UDP port number on the provided host
*/
TuioServer(const char *host, unsigned short port);
TuioServer(const char *host, int port);
/**
* This constructor creates a TuioServer that sends OSC data using the provided OscSender
@@ -101,12 +98,12 @@ namespace TUIO2 {
~TuioServer();
/**
* Generates and sends TUIO messages of all currently active TUIO Components
* Generates and sends TUIO messages of all currently active TuioObjects, TuioCursors and TuioBlobs
*/
void sendFullTuioBundle();
void sendFullMessages();
/**
* Enables the full update of all currently active and inactive TUIO Components
* Enables the full update of all currently active and inactive TuioObjects, TuioCursors and TuioBlobs
*
*/
void enableFullUpdate() {
@@ -114,22 +111,22 @@ namespace TUIO2 {
}
/**
* Disables the full update of all currently active and inactive TUIO Components
* Disables the full update of all currently active and inactive TuioObjects, TuioCursors and TuioBlobs
*/
void disableFullUpdate() {
full_update = false;
}
/**
* Returns true if the full update of all currently active TUIO Components is enabled.
* @return true if the full update of all currently active TUIO Components is enabled
* Returns true if the full update of all currently active TuioObjects, TuioCursors and TuioBlobs is enabled.
* @return true if the full update of all currently active TuioObjects, TuioCursors and TuioBlobs is enabled
*/
bool fullUpdateEnabled() {
return full_update;
}
/**
* Disables the periodic full update of all currently active TUIO Components
* Disables the periodic full update of all currently active TuioObjects TuioObjects, TuioCursors and TuioBlobs
*
* @param interval update interval in seconds, defaults to one second
*/
@@ -139,15 +136,15 @@ namespace TUIO2 {
}
/**
* Disables the periodic full update of all currently active and inactive TUIO Components
* Disables the periodic full update of all currently active and inactive TuioObjects, TuioCursors and TuioBlobs
*/
void disablePeriodicMessages() {
periodic_update = false;
}
/**
* Returns true if the periodic update of all currently active TUIO Components is enabled.
* @return true if the periodic update of all currently active TUIO Components is enabled
* Returns true if the periodic update of all currently active TuioObjects, TuioCursors and TuioBlobs is enabled.
* @return true if the periodic update of all currently active TuioObjects, TuioCursors and TuioBlobs is enabled
*/
bool periodicMessagesEnabled() {
return periodic_update;
@@ -163,48 +160,71 @@ namespace TUIO2 {
/**
* Commits the current frame.
* Generates and sends TUIO messages of all currently active and updated TUIO Components.
* Generates and sends TUIO messages of all currently active and updated TuioObjects, TuioCursors and TuioBlobs.
*/
void commitFrame();
/**
* Commits the current frame.
* Generates and sends TUIO messages of all currently active and updated TuioObjects, TuioCursors and TuioBlobs.
*/
void commitTuioFrame();
/**
* Creates the TuioSource that is transmitted within the /tuio2/frm source attributes.
* Defines the name of this TUIO source, which is transmitted within the /tuio/[profile] source message.
*
* @param name the source name to assign
* @param name the desired name of this TUIO source
*/
void setSourceName(const char *name);
/**
* Defines the name and IP address of this TUIO source, which is transmitted within the /tuio/[profile] source message.
*
* @param name the desired name of this TUIO source
* @param ip the local IP address
*/
void setSourceName(const char* name);
void setDimension(unsigned short w, unsigned short h);
void setSourceName(const char *name, const char *ip);
void addOscSender(OscSender *sender);
void enableObjectProfile(bool flag) { objectProfileEnabled = flag; };
void enableCursorProfile(bool flag) { cursorProfileEnabled = flag; };
void enableBlobProfile(bool flag) { blobProfileEnabled = flag; };
private:
void initialize();
OscSender *primary_sender;
bool local_sender;
void initialize(OscSender *oscsend);
std::vector<OscSender*> senderList;
void deliverOscPacket(osc::OutboundPacketStream *packet);
osc::OutboundPacketStream *oscPacket;
osc::OutboundPacketStream *oscPacket;
char *oscBuffer;
osc::OutboundPacketStream *fullPacket;
osc::OutboundPacketStream *fullPacket;
char *fullBuffer;
void checkBundleCapacity(int size);
void startTuioBundle(unsigned int fseq);
void addTokenMessage(TuioToken *ttok);
void addPointerMessage(TuioPointer *tptr);
void addBoundsMessage(TuioBounds *tbnd);
void addSymbolMessage(TuioSymbol *tsym);
void sendTuioBundle();
void sendEmptyTuioBundle();
void startObjectBundle();
void addObjectMessage(TuioObject *tobj);
void sendObjectBundle(long fseq);
void sendEmptyObjectBundle();
void startCursorBundle();
void addCursorMessage(TuioCursor *tcur);
void sendCursorBundle(long fseq);
void sendEmptyCursorBundle();
void startBlobBundle();
void addBlobMessage(TuioBlob *tblb);
void sendBlobBundle(long fseq);
void sendEmptyBlobBundle();
int update_interval;
bool full_update, periodic_update;
TuioTime updateTime;
TuioSource *source;
TuioTime objectUpdateTime, cursorUpdateTime, blobUpdateTime ;
bool objectProfileEnabled, cursorProfileEnabled, blobProfileEnabled;
char *source_name;
};
}
#endif /* INCLUDED_TUIOSERVER_H */
#endif /* INCLUDED_TuioServer_H */

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,7 @@
*/
#include "TuioTime.h"
using namespace TUIO2;
using namespace TUIO;
long TuioTime::start_seconds = 0;
long TuioTime::start_micro_seconds = 0;
@@ -26,15 +26,7 @@ TuioTime::TuioTime (long msec) {
seconds = msec/MSEC_SECOND;
micro_seconds = USEC_MILLISECOND*(msec%MSEC_SECOND);
}
TuioTime::TuioTime (osc::TimeTag timetag) {
osc::uint32 secs = timetag >> 32;
osc::uint32 frac = timetag & 0x00000000FFFFFFFF;
seconds = secs - JAN_1970;
micro_seconds = frac / NTP_UNITS;
}
TuioTime::TuioTime (long sec, long usec) {
seconds = sec;
micro_seconds = usec;
@@ -96,10 +88,6 @@ bool TuioTime::operator!=(TuioTime ttime) {
void TuioTime::reset() {
seconds = 0;
micro_seconds = 0;
TuioTime system_time = getSystemTime();
seconds = system_time.getSeconds();
micro_seconds = system_time.getMicroseconds();
}
long TuioTime::getSeconds() const{
@@ -114,26 +102,18 @@ long TuioTime::getTotalMilliseconds() const{
return seconds*MSEC_SECOND+micro_seconds/MSEC_SECOND;
}
unsigned int TuioTime::getFrameID() const{
return frame_id;
}
void TuioTime::setFrameID(unsigned int f_id) {
frame_id = f_id;
}
/*void TuioTime::initSession() {
TuioTime startTime = TuioTime::getSystemTime();
start_seconds = startTime.getSeconds();
start_micro_seconds = startTime.getMicroseconds();
void TuioTime::initSession() {
TuioTime startTime = TuioTime::getSystemTime();
start_seconds = startTime.getSeconds();
start_micro_seconds = startTime.getMicroseconds();
}
TuioTime TuioTime::getSessionTime() {
return (getSystemTime() - getStartTime());
}*/
return (getSystemTime() - getStartTime());
}
TuioTime TuioTime::getStartTime() {
return TuioTime(start_seconds,start_micro_seconds);
return TuioTime(start_seconds,start_micro_seconds);
}
TuioTime TuioTime::getSystemTime() {
@@ -147,14 +127,3 @@ TuioTime TuioTime::getSystemTime() {
#endif
return systemTime;
}
osc::TimeTag TuioTime::getSystemTimeTag() {
TuioTime systemTime = getSystemTime();
osc::uint32 secs = systemTime.getSeconds() + JAN_1970;
osc::uint32 frac = systemTime.getMicroseconds() * NTP_UNITS;
osc::uint64 timetag = (osc::uint64) secs << 32 | frac;
return osc::TimeTag(timetag);
}

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,6 @@
#define INCLUDED_TUIOTIME_H
#include "LibExport.h"
#include "oscpack/osc/OscTypes.h"
#ifndef WIN32
#include <pthread.h>
@@ -34,10 +33,7 @@
#define USEC_SECOND 1000000
#define USEC_MILLISECOND 1000
#define JAN_1970 0x83aa7e80 /* 2208988800 1970 - 1900 in seconds */
#define NTP_UNITS 4294.967295 /* NTP units per second */
namespace TUIO2 {
namespace TUIO {
/**
* The TuioTime class is a simple structure that is used to reprent the time that has elapsed since the session start.
@@ -47,7 +43,7 @@ namespace TUIO2 {
* The class also provides various addtional convience method, which allow some simple time arithmetics.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
* @version 1.1.6
*/
class LIBDECL TuioTime {
@@ -56,8 +52,6 @@ namespace TUIO2 {
long micro_seconds;
static long start_seconds;
static long start_micro_seconds;
unsigned int frame_id;
public:
@@ -65,7 +59,7 @@ namespace TUIO2 {
* The default constructor takes no arguments and sets
* the Seconds and Microseconds attributes of the newly created TuioTime both to zero.
*/
TuioTime ():seconds(0),micro_seconds(0),frame_id(0) {};
TuioTime ():seconds(0),micro_seconds(0) {};
/**
* The destructor is doing nothing in particular.
@@ -79,15 +73,6 @@ namespace TUIO2 {
* @param msec the total time in Millseconds
*/
TuioTime (long msec);
/**
* This constructor takes the provided time in OSC format
* and assigs this value to the newly created TuioTime.
*
* @param tag the time in OSC format
*/
TuioTime (osc::TimeTag timetag);
/**
* This constructor takes the provided time represented in Seconds and Microseconds
@@ -176,29 +161,17 @@ namespace TUIO2 {
* @return the total TuioTime in Milliseconds
*/
long getTotalMilliseconds() const;
/**
* Returns the assigned Frame ID.
* @return the assigned Frame ID
*/
unsigned int getFrameID() const;
/**
* assigns a Frame ID.
* @f_id the Frame ID to assign
*/
void setFrameID(unsigned int f_id);
/**
* This static method globally resets the TUIO session time.
*/
//static void initSession();
static void initSession();
/**
* Returns the present TuioTime representing the time since session start.
* @return the present TuioTime representing the time since session start
*/
//tatic TuioTime getSessionTime();
static TuioTime getSessionTime();
/**
* Returns the absolut TuioTime representing the session start.
@@ -211,12 +184,6 @@ namespace TUIO2 {
* @return the absolut TuioTime representing the current system time
*/
static TuioTime getSystemTime();
/**
* Returns the absolut TuioTime representing the current system time.
* @return the absolut TuioTime representing the current system time
*/
static osc::TimeTag getSystemTimeTag();
};
}
#endif /* INCLUDED_TUIOTIME_H */

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,7 @@
#include "UdpReceiver.h"
using namespace TUIO2;
using namespace TUIO;
using namespace osc;
#ifndef WIN32
@@ -31,7 +31,7 @@ static DWORD WINAPI ClientThreadFunc( LPVOID obj )
return 0;
};
UdpReceiver::UdpReceiver(unsigned short port):locked (false) {
UdpReceiver::UdpReceiver(int port):locked (false) {
try {
socket = new UdpListeningReceiveSocket(IpEndpointName( IpEndpointName::ANY_ADDRESS, port ), this );
} catch (std::exception &e) {

View File

@@ -1,6 +1,6 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
TUIO C++ Library
Copyright (c) 2005-2016 Martin Kaltenbrunner <martin@tuio.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -22,13 +22,13 @@
#include "OscReceiver.h"
#include "oscpack/ip/UdpSocket.h"
namespace TUIO2 {
namespace TUIO {
/**
* The UdpReceiver provides the OscReceiver functionality for the UDP transport method
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
* @version 1.1.6
*/
class LIBDECL UdpReceiver: public OscReceiver {
@@ -44,7 +44,7 @@ namespace TUIO2 {
*
* @param port the number of the UDP port to listen to, defaults to 3333
*/
UdpReceiver (unsigned short port=3333);
UdpReceiver (int port=3333);
/**
* The destructor is doing nothing in particular.

View File

@@ -18,7 +18,7 @@
#include "UdpSender.h"
using namespace TUIO2;
using namespace TUIO;
UdpSender::UdpSender() {
try {

View File

@@ -26,14 +26,14 @@
#define MAX_UDP_SIZE 4096
#define MIN_UDP_SIZE 576
namespace TUIO2 {
namespace TUIO {
/**
* The UdpSender implements the UDP transport method for OSC
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
* @version 1.1.6
*/
class LIBDECL UdpSender : public OscSender {
public:

View File

@@ -26,7 +26,7 @@
#endif
#endif
using namespace TUIO2;
using namespace TUIO;
WebSockSender::WebSockSender()
:TcpSender( 8080 )
@@ -114,6 +114,7 @@ void WebSockSender::newClient( int tcp_client ) {
"HTTP/1.1 101 Switching Protocols\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Sec-WebSocket-Accept: %s\r\n\r\n",
base64( digest, SHA1_HASH_SIZE ).c_str() );

View File

@@ -67,7 +67,7 @@ __inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
#include <string.h>
#include <vector>
namespace TUIO2 {
namespace TUIO {
/**
* The WebSockSender implements the WebSocket transport method for OSC

View File

@@ -34,7 +34,7 @@
requested that these non-binding requests be included whenever the
above license is reproduced.
*/
#include "oscpack/ip/NetworkingUtils.h"
#include "ip/NetworkingUtils.h"
#include <netdb.h>
#include <sys/socket.h>

View File

@@ -34,7 +34,7 @@
requested that these non-binding requests be included whenever the
above license is reproduced.
*/
#include "oscpack/ip/UdpSocket.h"
#include "ip/UdpSocket.h"
#include <pthread.h>
#include <unistd.h>
@@ -57,8 +57,8 @@
#include <stdexcept>
#include <vector>
#include "oscpack/ip/PacketListener.h"
#include "oscpack/ip/TimerListener.h"
#include "ip/PacketListener.h"
#include "ip/TimerListener.h"
#if defined(__APPLE__) && !defined(_SOCKLEN_T)

View File

@@ -1,94 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioBounds.h"
using namespace TUIO2;
TuioBounds::TuioBounds (TuioTime ttime, TuioObject *tobj, float xp, float yp, float a, float w, float h, float f):TuioComponent(ttime, tobj, xp, yp,a) {
width = w;
height = h;
area = f;
}
TuioBounds::TuioBounds (TuioObject *tobj, float xp, float yp, float a, float w, float h, float f):TuioComponent(tobj, xp, yp, a) {
width = w;
height = h;
area = f;
}
TuioBounds::TuioBounds (TuioBounds *tbnd):TuioComponent(tbnd) {
angle = tbnd->getAngle();
width = tbnd->getWidth();
height = tbnd->getHeight();
area = tbnd->getArea();
rotation_speed = 0.0f;
rotation_accel = 0.0f;
}
void TuioBounds::update (TuioTime ttime, float xp, float yp, float a, float w, float h, float f, float xs, float ys, float rs, float ma, float ra) {
TuioComponent::update(ttime,xp,yp,a,xs,ys,rs,ma,ra);
width = w;
height = h;
area = f;
}
void TuioBounds::update (float xp, float yp, float a, float w, float h, float f, float xs, float ys, float rs, float ma, float ra) {
TuioComponent::update(xp,yp,a,xs,ys,rs,ma,ra);
width = w;
height = h;
area = f;
}
void TuioBounds::update (TuioTime ttime, float xp, float yp, float a, float w, float h, float f) {
TuioComponent::update(ttime,xp,yp,a);
width = w;
height = h;
area = f;
}
void TuioBounds::stop (TuioTime ttime) {
update(ttime,xpos,ypos,angle,width,height,area);
}
void TuioBounds::update (TuioBounds *tbnd) {
TuioComponent::update(tbnd);
width = tbnd->getWidth();
height = tbnd->getHeight();
area = tbnd->getArea();
}
float TuioBounds::getWidth() const{
return width;
}
float TuioBounds::getHeight() const{
return height;
}
int TuioBounds::getScreenWidth(int w) const{
return (int)(w*width);
}
int TuioBounds::getScreenHeight(int h) const{
return (int)(h*height);
}
float TuioBounds::getArea() const{
return area;
}

View File

@@ -1,520 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioClient.h"
#include "UdpReceiver.h"
using namespace TUIO2;
using namespace osc;
TuioClient::TuioClient()
: lateFrame (false)
, source_count (0)
, receiver (NULL)
, local_receiver(true)
{
receiver = new UdpReceiver();
initialize();
}
TuioClient::TuioClient(unsigned short port)
: lateFrame (false)
, source_count (0)
, receiver (NULL)
, local_receiver(true)
{
receiver = new UdpReceiver(port);
initialize();
}
TuioClient::TuioClient(OscReceiver *osc)
: lateFrame (false)
, source_count (0)
, receiver (osc)
, local_receiver(false)
{
initialize();
}
void TuioClient::initialize() {
receiver->addTuioClient(this);
}
TuioClient::~TuioClient() {
if (local_receiver) delete receiver;
}
void TuioClient::processOSC( const ReceivedMessage& msg ) {
try {
ReceivedMessageArgumentStream args = msg.ArgumentStream();
//ReceivedMessage::const_iterator arg = msg.ArgumentsBegin();
if( strcmp( msg.AddressPattern(), "/tuio2/frm" ) == 0 ) {
//lockFrame();
int32 fseq_raw,dim_raw;
TimeTag timetag;
const char* src_string;
args >> fseq_raw >> timetag >> dim_raw >> src_string;
// check if we know that source
std::map<std::string,TuioSource*>::iterator iter = sourceList.find(src_string);
if (iter==sourceList.end()) { // add a new source
frameSource = new TuioSource(source_count, src_string, (unsigned int)dim_raw);
sourceList[src_string] = frameSource;
source_count++;
} else { // use the found source
frameSource = sourceList[src_string];
}
unsigned int currentFrameID = (unsigned int)fseq_raw;
frameTime = TuioTime(timetag);
frameTime.setFrameID(currentFrameID);
// frame sequence
lateFrame = false;
unsigned int lastFrameID = frameSource->getFrameTime().getFrameID();
unsigned int timeDiff = frameTime.getTotalMilliseconds() - frameSource->getFrameTime().getTotalMilliseconds();
frameSource->setFrameTime(frameTime);
// drop late frames (but accept the reserved ID 0 and consider a possible reset after 1sec
if ((currentFrameID<lastFrameID) && (currentFrameID!=0) && (timeDiff<1000)) lateFrame = true;
} else if( strcmp( msg.AddressPattern(), "/tuio2/tok" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw, tu_id_raw, c_id_raw;
unsigned short t_id, u_id;
unsigned int s_id,c_id;
float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
args >> s_id_raw >> tu_id_raw >> c_id_raw >> xpos >> ypos >> angle;
if (!args.Eos()) args >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
else xspeed = yspeed = rspeed = maccel = raccel = 0.0f;
s_id = (unsigned int)s_id_raw;
c_id = (unsigned int)c_id_raw;
t_id = tu_id_raw >> 16;
u_id = tu_id_raw & 0x0000FFFF;
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
//if (tobj == NULL) std::cout << "new cont " << s_id << " " << frameSource.getSourceID() << std::endl;
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
TuioToken *ttok = tobj->getTuioToken();
if (ttok == NULL) {
ttok = new TuioToken(frameTime,tobj,t_id,u_id,c_id,xpos,ypos,angle);
tobj->setTuioToken(ttok);
} else if ( (ttok->getX()!=xpos) || (ttok->getY()!=ypos) || (ttok->getAngle()!=angle) || (ttok->getXSpeed()!=xspeed) || (ttok->getYSpeed()!=yspeed) || (ttok->getRotationSpeed()!=rspeed) || (ttok->getMotionAccel()!=maccel) || (ttok->getRotationAccel()!=raccel) ) {
ttok->update(frameTime,xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
}
} else if( strcmp( msg.AddressPattern(), "/tuio2/ptr" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw, tu_id_raw, c_id_raw;
unsigned short t_id, u_id;
unsigned int s_id,c_id;
float xpos, ypos, angle, shear,radius, pressure, xspeed, yspeed, pspeed, maccel, paccel;
args >> s_id_raw >> tu_id_raw >> c_id_raw >> xpos >> ypos >> angle >> shear >> radius >> pressure;
if (!args.Eos()) args >> xspeed >> yspeed >> pspeed >> maccel >> paccel;
else xspeed = yspeed = pspeed = maccel = paccel = 0.0f;
s_id = (unsigned int)s_id_raw;
c_id = (unsigned int)c_id_raw;
t_id = tu_id_raw >> 16;
u_id = tu_id_raw & 0x0000FFFF;
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
//if (tobj == NULL) std::cout << "new cont " << s_id << " " << frameSource.getSourceID() << std::endl;
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
TuioPointer *tptr = tobj->getTuioPointer();
if (tptr == NULL) {
tptr = new TuioPointer(frameTime,tobj,t_id,u_id,c_id,xpos,ypos,angle,shear,radius,pressure);
tobj->setTuioPointer(tptr);
} else if ( (tptr->getX()!=xpos) || (tptr->getY()!=ypos) || (tptr->getAngle()!=angle) || (tptr->getShear()!=shear) || (tptr->getRadius()!=radius) || (tptr->getPressure()!=pressure) || (tptr->getXSpeed()!=xspeed) || (tptr->getYSpeed()!=yspeed) || (tptr->getPressureSpeed()!=pspeed) || (tptr->getMotionAccel()!=maccel) || (tptr->getPressureAccel()!=paccel) ) {
tptr->update(frameTime,xpos,ypos,angle,shear,radius,pressure,xspeed,yspeed,pspeed,maccel,paccel);
}
} else if( strcmp( msg.AddressPattern(), "/tuio2/bnd" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw;
unsigned int s_id;
float xpos, ypos, angle, width, height, area;
float xspeed, yspeed, rspeed, maccel, raccel;
args >> s_id_raw >> xpos >> ypos >> angle >> width >> height >> area;
if (!args.Eos()) args >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
else xspeed = yspeed = rspeed = maccel = raccel = 0.0f;
s_id = (unsigned int)s_id_raw;
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
TuioBounds *tbnd = tobj->getTuioBounds();
if (tbnd == NULL) {
tbnd = new TuioBounds(frameTime,tobj,xpos,ypos,angle,width,height,area);
tobj->setTuioBounds(tbnd);
} else if ( (tbnd->getX()!=xpos) || (tbnd->getY()!=ypos) || (tbnd->getAngle()!=angle) || (tbnd->getWidth()!=width) || (tbnd->getHeight()!=height) || (tbnd->getArea()!=area) || (tbnd->getXSpeed()!=xspeed) || (tbnd->getYSpeed()!=yspeed) || (tbnd->getRotationSpeed()!=rspeed) || (tbnd->getMotionAccel()!=maccel) || (tbnd->getRotationAccel()!=raccel)) {
tbnd->update(frameTime,xpos,ypos,angle,width,height,area,xspeed,yspeed,rspeed,maccel,raccel);
}
} else if( strcmp( msg.AddressPattern(), "/tuio2/sym" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw, tu_id_raw, c_id_raw;
unsigned int s_id, c_id;
unsigned short t_id, u_id;
const char* type;
const char* data;
args >> s_id_raw >> tu_id_raw >> c_id_raw >> type >> data;
s_id = (unsigned int)s_id_raw;
c_id = (unsigned int)c_id_raw;
t_id = tu_id_raw >> 16;
u_id = tu_id_raw & 0x0000FFFF;
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
TuioSymbol *tsym = tobj->getTuioSymbol();
if (tsym == NULL) {
tsym = new TuioSymbol(frameTime,tobj,t_id,u_id,c_id,type,data);
tobj->setTuioSymbol(tsym);
} else {
tsym->update(frameTime);
}
} else if( strcmp( msg.AddressPattern(), "/tuio2/chg" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw;
args >> s_id_raw;
unsigned int s_id = (unsigned int)s_id_raw;
std::list<TuioPoint> pointList;
while(!args.Eos()) {
float xpos, ypos;
args >> xpos >> ypos;
pointList.push_back(TuioPoint(frameTime, xpos, ypos));
}
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
/*TuioGeometry *tgeo = tobj->getTuioGeometry();
if (tgeo == NULL) {
tgeo = new TuioGeometry(frameTime, tobj);
tobj->setTuioGeometry(tgeo);
} tgeo->setConvexHull(pointList);*/
} else if( strcmp( msg.AddressPattern(), "/tuio2/ocg" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw;
args >> s_id_raw;
unsigned int s_id = (unsigned int)s_id_raw;
std::list<TuioPoint> pointList;
while(!args.Eos()) {
float xpos, ypos;
args >> xpos >> ypos;
pointList.push_back(TuioPoint(frameTime, xpos, ypos));
}
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
/*TuioGeometry *tgeo = tobj->getTuioGeometry();
if (tgeo == NULL) {
tgeo = new TuioGeometry(frameTime, tobj);
tobj->setTuioGeometry(tgeo);
} tgeo->setOuterContour(pointList);*/
} else if( strcmp( msg.AddressPattern(), "/tuio2/icg" ) == 0 ) {
if (lateFrame) return;
int32 s_id_raw;
args >> s_id_raw;
unsigned int s_id = (unsigned int)s_id_raw;
std::list<TuioPoint> pointList;
while(!args.Eos()) {
float xpos,ypos;
args >> xpos >> ypos;
pointList.push_back(TuioPoint(frameTime, xpos, ypos));
}
TuioObject *tobj = getFrameObject(frameSource->getSourceID(),s_id);
if (tobj == NULL) tobj = new TuioObject(frameTime,frameSource,s_id);
addFrameObject(tobj);
/*TuioGeometry *tgeo = tobj->getTuioGeometry();
if (tgeo == NULL) {
tgeo = new TuioGeometry(frameTime, tobj);
tobj->setTuioGeometry(tgeo);
} tgeo->setOuterContour(pointList);*/
} else if( strcmp( msg.AddressPattern(), "/tuio2/alv" ) == 0 ) {
if (lateFrame) return;
int32 s_id;
aliveObjectList.clear();
while(!args.Eos()) {
args >> s_id;
aliveObjectList.push_back((unsigned int)s_id);
}
lockObjectList();
//find the removed tobjs first
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
if ((*tobj)->getTuioSource()->getSourceID()!=frameSource->getSourceID()) continue;
std::list<unsigned int>::iterator iter = find(aliveObjectList.begin(), aliveObjectList.end(), (*tobj)->getSessionID());
if (iter == aliveObjectList.end()) {
(*tobj)->remove(frameTime);
addFrameObject(*tobj);
}
}
unlockObjectList();
for (std::list<TuioObject*>::iterator iter=frameObjectList.begin(); iter!=frameObjectList.end(); iter++) {
TuioObject *tobj = (*iter);
switch (tobj->getTuioState()) {
case TUIO_REMOVED:
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener!=listenerList.end(); listener++)
(*listener)->tuioRemove(tobj);
lockObjectList();
for (std::list<TuioObject*>::iterator delcon=tobjList.begin(); delcon!=tobjList.end(); delcon++) {
if (((*delcon)->getSessionID()==tobj->getSessionID()) && ((*delcon)->getTuioSource()->getSourceID()==frameSource->getSourceID())) {
delete *delcon;
tobjList.erase(delcon);
break;
}
}
unlockObjectList();
break;
case TUIO_ADDED:
lockObjectList();
tobjList.push_back(tobj);
unlockObjectList();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioAdd(tobj);
break;
default:
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioUpdate(tobj);
}
}
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioRefresh(frameTime);
frameObjectList.clear();
//unlockFrame();
}
} catch( Exception& e ){
std::cerr << "error parsing TUIO2 message: "<< msg.AddressPattern() << " - " << e.what() << std::endl;
//unlockFrame();
}
}
bool TuioClient::isConnected() {
return receiver->isConnected();
}
void TuioClient::connect(bool lock) {
receiver->connect(lock);
unlockObjectList();
}
void TuioClient::disconnect() {
receiver->disconnect();
aliveObjectList.clear();
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++)
delete (*iter);
tobjList.clear();
}
TuioObject* TuioClient::getTuioObject(unsigned int src_id, unsigned int s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
if (((*iter)->getSessionID()==s_id) && ((*iter)->getTuioSource()->getSourceID()==src_id)) {
unlockObjectList();
return (*iter);
}
}
unlockObjectList();
return NULL;
}
TuioToken* TuioClient::getTuioToken(unsigned int src_id, unsigned int s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
if (((*iter)->getSessionID()==s_id) && ((*iter)->getTuioSource()->getSourceID()==src_id)) {
unlockObjectList();
return (*iter)->getTuioToken();
}
}
unlockObjectList();
return NULL;
}
TuioPointer* TuioClient::getTuioPointer(unsigned int src_id, unsigned int s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
if (((*iter)->getSessionID()==s_id) && ((*iter)->getTuioSource()->getSourceID()==src_id)) {
unlockObjectList();
return (*iter)->getTuioPointer();
}
}
unlockObjectList();
return NULL;
}
TuioBounds* TuioClient::getTuioBounds(unsigned int src_id, unsigned int s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
if (((*iter)->getSessionID()==s_id) && ((*iter)->getTuioSource()->getSourceID()==src_id)) {
unlockObjectList();
return (*iter)->getTuioBounds();
}
}
unlockObjectList();
return NULL;
}
TuioSymbol* TuioClient::getTuioSymbol(unsigned int src_id, unsigned int s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
if (((*iter)->getSessionID()==s_id) && ((*iter)->getTuioSource()->getSourceID()==src_id)) {
unlockObjectList();
return (*iter)->getTuioSymbol();
}
}
unlockObjectList();
return NULL;
}
std::list<TuioObject*> TuioClient::getTuioObjectList(unsigned int src_id) {
lockObjectList();
std::list<TuioObject*> listBuffer;
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj != tobjList.end(); tobj++) {
if ((*tobj)->getTuioSource()->getSourceID()==src_id) listBuffer.push_back(*tobj);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioToken*> TuioClient::getTuioTokenList(unsigned int src_id) {
lockObjectList();
std::list<TuioToken*> listBuffer;
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj != tobjList.end(); tobj++) {
if ((*tobj)->getTuioSource()->getSourceID()==src_id) {
TuioToken *ttok = (*tobj)->getTuioToken();
if (ttok!=NULL) listBuffer.push_back(ttok);
}
}
unlockObjectList();
return listBuffer;
}
std::list<TuioPointer*> TuioClient::getTuioPointerList(unsigned int src_id) {
lockObjectList();
std::list<TuioPointer*> listBuffer;
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj != tobjList.end(); tobj++) {
if ((*tobj)->getTuioSource()->getSourceID()==src_id) {
TuioPointer *tptr = (*tobj)->getTuioPointer();
if (tptr!=NULL) listBuffer.push_back(tptr);
}
}
unlockObjectList();
return listBuffer;
}
std::list<TuioBounds*> TuioClient::getTuioBoundsList(unsigned int src_id) {
lockObjectList();
std::list<TuioBounds*> listBuffer;
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj != tobjList.end(); tobj++) {
if ((*tobj)->getTuioSource()->getSourceID()==src_id) {
TuioBounds *tbnd = (*tobj)->getTuioBounds();
if (tbnd!=NULL) listBuffer.push_back(tbnd);
}
}
unlockObjectList();
return listBuffer;
}
std::list<TuioSymbol*> TuioClient::getTuioSymbolList(unsigned int src_id) {
lockObjectList();
std::list<TuioSymbol*> listBuffer;
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj != tobjList.end(); tobj++) {
if ((*tobj)->getTuioSource()->getSourceID()==src_id) {
TuioSymbol *tsym = (*tobj)->getTuioSymbol();
if (tsym!=NULL) listBuffer.push_back(tsym);
}
}
unlockObjectList();
return listBuffer;
}
void TuioClient::addFrameObject(TuioObject *tobj) {
for (std::list<TuioObject*>::iterator iter=frameObjectList.begin(); iter != frameObjectList.end(); iter++) {
if ((*iter)->getSessionID()==tobj->getSessionID()) return;
}
frameObjectList.push_back(tobj);
}
TuioObject* TuioClient::getFrameObject(unsigned int src_id, unsigned int s_id) {
for (std::list<TuioObject*>::iterator tobj=frameObjectList.begin(); tobj != frameObjectList.end(); tobj++) {
if ((*tobj)->getSessionID()==s_id) return *tobj;
}
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj != tobjList.end(); tobj++) {
if (((*tobj)->getSessionID()==s_id) && ((*tobj)->getTuioSource()->getSourceID()==src_id)) return *tobj;
}
return NULL;
}
void TuioClient::lockFrame() {
#ifndef WIN32
pthread_mutex_lock(&frameMutex);
#else
WaitForSingleObject(frameMutex, INFINITE);
#endif
}
void TuioClient::unlockFrame() {
#ifndef WIN32
pthread_mutex_unlock(&frameMutex);
#else
ReleaseMutex(frameMutex);
#endif
}

View File

@@ -1,241 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOCLIENT_H
#define INCLUDED_TUIOCLIENT_H
#include "TuioDispatcher.h"
#include "OscReceiver.h"
#include "oscpack/osc/OscReceivedElements.h"
#include <iostream>
#include <list>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
namespace TUIO2 {
class OscReceiver; // Forward declaration
/**
* <p>The TuioClient class is the central TUIO protocol decoder component. It provides a simple callback infrastructure using the {@link TuioListener} interface.
* In order to receive and decode TUIO messages an instance of TuioClient needs to be created. The TuioClient instance then generates TUIO events
* which are broadcasted to all registered classes that implement the {@link TuioListener} interface.</p>
* <p><code>
* TuioClient *client = new TuioClient();<br/>
* client->addTuioListener(myTuioListener);<br/>
* client->connect();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioClient : public TuioDispatcher {
public:
/**
* This constructor creates a TuioClient that uses an internal UdpReceiver listening to the default UDP port 3333
*
*/
TuioClient();
/**
* This constructor creates a TuioClient that uses an internal UdpReceiver listening to the provided UDP port
*
* @param port the UDP port the internal UdpReceiver is listening to
*/
TuioClient(unsigned short port);
/**
* This constructor creates a TuioClient that uses the provided OscReceiver for the incoming OSC data
*
* @param oscreceiver the OscReceiver implementation for the chosen transport method (UDP, TCP ...)
*/
TuioClient(OscReceiver *oscreceiver);
/**
* The destructor is doing nothing in particular.
*/
~TuioClient();
/**
* The TuioClient connects and starts receiving TUIO messages from its associated OscReceiver
*
* @param lock running in the background if set to false (default)
*/
void connect(bool lock=false);
/**
* The TuioClient disconnects and stops receiving TUIO messages from its associated OscReceiver
*/
void disconnect();
/**
* Returns true if this TuioClient is currently connected.
* @return true if this TuioClient is currently connected
*/
bool isConnected();
/**
* Returns the TuioObject corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioObject
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioObject
* @return an active TuioObject corresponding to the provided Session ID or NULL
*/
using TuioDispatcher::getTuioObject;
TuioObject* getTuioObject(unsigned int src_id, unsigned int s_id);
/**
* Returns a list of all currently active TuioObject
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a list of TuioObject
*/
using TuioDispatcher::getTuioObjectList;
std::list<TuioObject*> getTuioObjectList(unsigned int src_id);
/**
* Returns the TuioToken corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioToken
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioToken
* @return an active TuioToken corresponding to the provided Session ID or NULL
*/
using TuioDispatcher::getTuioToken;
TuioToken* getTuioToken(unsigned int src_id, unsigned int s_id);
/**
* Returns a list of all currently active TuioTokens
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a list of TuioTokens
*/
using TuioDispatcher::getTuioTokenList;
std::list<TuioToken*> getTuioTokenList(unsigned int src_id);
/**
* Returns the TuioPointer corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioPointer
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioPointer
* @return an active TuioPointer corresponding to the provided Session ID or NULL
*/
using TuioDispatcher::getTuioPointer;
TuioPointer* getTuioPointer(unsigned int src_id, unsigned int s_id);
/**
* Returns a List of all currently active TuioPointers
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List of TuioPointers
*/
using TuioDispatcher::getTuioPointerList;
std::list<TuioPointer*> getTuioPointerList(unsigned int src_id);
/**
* Returns the TuioBounds corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioBounds
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioBounds
* @return an active TuioBounds corresponding to the provided Session ID or NULL
*/
using TuioDispatcher::getTuioBounds;
TuioBounds* getTuioBounds(unsigned int src_id, unsigned int s_id);
/**
* Returns a List of all currently active TuioBounds
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List of TuioBounds
*/
using TuioDispatcher::getTuioBoundsList;
std::list<TuioBounds*> getTuioBoundsList(unsigned int src_id);
/**
* Returns the TuioSymbol corresponding to the provided Session ID
* which is associated to the given Source ID
* or NULL if the Session ID does not refer to an active TuioSymbol
*
* @param src_id the source ID of the corresponding TUIO source
* @param s_id the session ID of the corresponding TuioSymbol
* @return an active TuioSymbol corresponding to the provided Session ID or NULL
*/
using TuioDispatcher::getTuioSymbol;
TuioSymbol* getTuioSymbol(unsigned int src_id, unsigned int s_id);
/**
* Returns a List of all currently active TuioSymbol
* which are associated to the given Source ID
*
* @param src_id the source ID of the corresponding TUIO source
* @return a List of TuioSymbol
*/
using TuioDispatcher::getTuioSymbolList;
std::list<TuioSymbol*> getTuioSymbolList(unsigned int src_id);
/**
* Parses the incoming OSC message
*
* @param message the incoming OSC message
*/
void processOSC( const osc::ReceivedMessage& message);
private:
void initialize();
void addFrameObject(TuioObject *con);
TuioObject* getFrameObject(unsigned int src_id,unsigned int s_id);
std::list<unsigned int> aliveObjectList;
std::list<TuioObject*> frameObjectList;
TuioTime frameTime;
bool lateFrame;
unsigned int source_count;
std::map<std::string,TuioSource*> sourceList;
TuioSource *frameSource;
OscReceiver *receiver;
bool local_receiver;
#ifndef WIN32
pthread_mutex_t frameMutex;
#else
HANDLE frameMutex;
#endif
void lockFrame();
void unlockFrame();
};
};
#endif /* INCLUDED_TUIOCLIENT_H */

View File

@@ -1,245 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioComponent.h"
#include "TuioObject.h"
using namespace TUIO2;
TuioComponent::TuioComponent (TuioTime ttime, TuioObject *tobj, float xp, float yp, float a):TuioPoint(ttime, xp,yp)
,state(TUIO_ADDED)
{
container = tobj;
angle = a;
x_speed = 0.0f;
y_speed = 0.0f;
motion_speed = 0.0f;
motion_accel = 0.0f;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
}
TuioComponent::TuioComponent (TuioObject *tobj, float xp, float yp, float a):TuioPoint(xp,yp)
,state(TUIO_ADDED)
{
container = tobj;
angle = a;
x_speed = 0.0f;
y_speed = 0.0f;
motion_speed = 0.0f;
motion_accel = 0.0f;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
}
TuioComponent::TuioComponent (TuioComponent *tcomp):TuioPoint(tcomp)
,state(TUIO_ADDED)
{
container = tcomp->getContainingTuioObject();
angle = tcomp->getAngle();
x_speed = 0.0f;
y_speed = 0.0f;
motion_speed = 0.0f;
motion_accel = 0.0f;
rotation_speed = 0.0f;
rotation_accel = 0.0f;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
}
TuioObject* TuioComponent::getContainingTuioObject() {
return container;
}
void TuioComponent::setContainingTuioObject(TuioObject *tobj) {
container = tobj;
}
void TuioComponent::update (TuioTime ttime, float xp, float yp, float a) {
TuioPoint lastPoint = path.back();
TuioPoint::update(ttime,xp, yp);
TuioTime diffTime = currentTime - lastPoint.getTuioTime();
float dt = diffTime.getTotalMilliseconds()/1000.0f;
float dx = xpos - lastPoint.getX();
float dy = ypos - lastPoint.getY();
float dist = sqrt(dx*dx+dy*dy);
float last_motion_speed = motion_speed;
x_speed = dx/dt;
y_speed = dy/dt;
motion_speed = dist/dt;
motion_accel = (motion_speed - last_motion_speed)/dt;
float last_angle = angle;
float last_rotation_speed = rotation_speed;
angle = a;
double da = (angle-last_angle)/(2*M_PI);
if (da > 0.75f) da-=1.0f;
else if (da < -0.75f) da+=1.0f;
rotation_speed = (float)da/dt;
rotation_accel = (rotation_speed - last_rotation_speed)/dt;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
else state = TUIO_STOPPED;
container->update(ttime);
}
void TuioComponent::stop(TuioTime ttime) {
update(ttime,xpos,ypos);
container->update(ttime);
}
void TuioComponent::update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
TuioPoint::update(ttime,xp, yp);
angle = a;
x_speed = xs;
y_speed = ys;
motion_speed = (float)sqrt(x_speed*x_speed+y_speed*y_speed);
rotation_speed = rs;
motion_accel = ma;
rotation_accel = ra;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
else state = TUIO_STOPPED;
container->update(ttime);
}
void TuioComponent::update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
TuioPoint::update(xp,yp);
angle = a;
x_speed = xs;
y_speed = ys;
motion_speed = (float)sqrt(x_speed*x_speed+y_speed*y_speed);
rotation_speed = rs;
motion_accel = ma;
rotation_accel = ra;
TuioPoint p(currentTime,xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
else state = TUIO_STOPPED;
container->update(currentTime);
}
void TuioComponent::update (TuioComponent *tcomp) {
TuioPoint::update(tcomp);
angle = tcomp->getAngle();
x_speed = tcomp->getXSpeed();
y_speed = tcomp->getYSpeed();
motion_speed = tcomp->getMotionSpeed();
rotation_speed = tcomp->getRotationSpeed();
motion_accel = tcomp->getMotionAccel();
rotation_accel = tcomp->getRotationAccel();
TuioPoint p(tcomp->getTuioTime(),xpos,ypos);
path.push_back(p);
if (path.size()>MAX_PATH_SIZE) path.pop_front();
if (motion_accel>0) state = TUIO_ACCELERATING;
else if (motion_accel<0) state = TUIO_DECELERATING;
else if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
else state = TUIO_STOPPED;
container->update(tcomp->getTuioTime());
}
void TuioComponent::remove(TuioTime ttime) {
currentTime = ttime;
state = TUIO_REMOVED;
container->update(ttime);
}
unsigned int TuioComponent::getSessionID() const{
return container->getSessionID();
}
float TuioComponent::getAngle() const{
return angle;
}
float TuioComponent::getAngleDegrees() const{
return (float)(angle/M_PI*180);
}
float TuioComponent::getXSpeed() const{
return x_speed;
}
float TuioComponent::getYSpeed() const{
return y_speed;
}
TuioPoint TuioComponent::getPosition() const{
TuioPoint p(xpos,ypos);
return p;
}
std::list<TuioPoint> TuioComponent::getPath() const{
return path;
}
float TuioComponent::getMotionSpeed() const{
return motion_speed;
}
float TuioComponent::getMotionAccel() const{
return motion_accel;
}
float TuioComponent::getRotationSpeed() const{
return rotation_speed;
}
float TuioComponent::getRotationAccel() const{
return rotation_accel;
}
int TuioComponent::getTuioState() const{
return state;
}
bool TuioComponent::isMoving() const{
if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
else return false;
}

View File

@@ -1,287 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOCOMPONENT_H
#define INCLUDED_TUIOCOMPONENT_H
#include "TuioPoint.h"
#include <list>
#include <string>
#define TUIO_IDLE 0
#define TUIO_ADDED 1
#define TUIO_ACCELERATING 2
#define TUIO_DECELERATING 3
#define TUIO_ROTATING 4
#define TUIO_STOPPED 5
#define TUIO_REMOVED 6
#define MAX_PATH_SIZE 128
namespace TUIO2 {
/**
* The abstract TuioComponent class defines common attributes that apply to all subclasses {@link TuioToken}, {@link TuioPointer} and {@link TuioBounds}.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class TuioObject;
class LIBDECL TuioComponent: public TuioPoint {
protected:
/**
* The TuioObject that contains this TUIO component.
*/
TuioObject *container;
/**
* The rotation angle value.
*/
float angle;
/**
* The X-axis velocity value.
*/
float x_speed;
/**
* The Y-axis velocity value.
*/
float y_speed;
/**
* The motion speed value.
*/
float motion_speed;
/**
* The motion acceleration value.
*/
float motion_accel;
/**
* The rotation speed value.
*/
float rotation_speed;
/**
* The rotation acceleration value.
*/
float rotation_accel;
/**
* A List of TuioPoints containing all the previous positions of the TUIO component.
*/
std::list<TuioPoint> path;
/**
* Reflects the current state of the TuioComponent
*/
int state;
public:
using TuioPoint::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, X and Y coordinate to the newly created TuioComponent.
*
* @param ttime the TuioTime to assign
* @param tobj the TuioObject to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioComponent (TuioTime ttime, TuioObject *tobj, float xp, float yp, float a);
/**
* This constructor takes the provided Session ID, X and Y coordinate
* and assigs these values to the newly created TuioComponent.
*
* @param tobj the TuioObject to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioComponent (TuioObject *tobj, float xp, float yp,float a);
/**
* This constructor takes the atttibutes of the provided TuioComponent
* and assigs these values to the newly created TuioComponent.
*
* @param tcon the TuioComponent to assign
*/
TuioComponent (TuioComponent *tcon);
/**
* The destructor is doing nothing in particular.
*/
virtual ~TuioComponent(){};
/**
* Returns the TuioObject containing this TuioComponent.
* @return the TuioObject containing this TuioComponent
*/
virtual TuioObject* getContainingTuioObject();
/**
* Returns the TuioObject containing this TuioComponent.
* @param the TuioObject containing this TuioComponent
*/
virtual void setContainingTuioObject(TuioObject *tobj);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate to the private TuioComponent attributes.
* The speed and accleration values are calculated accordingly.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
virtual void update (TuioTime ttime, float xp, float yp, float a);
/**
* This method is used to calculate the speed and acceleration values of
* TuioComponents with unchanged positions.
*/
virtual void stop(TuioTime ttime);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate, X and Y velocity and acceleration
* to the private TuioComponent attributes.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param rs the rotation velocity to assign
* @param ma the motion acceleration to assign
* @param ra the rotation acceleration to assign
*/
virtual void update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra);
/**
* Assigns the provided X and Y coordinate, X and Y velocity and acceleration
* to the private TuioComponent attributes. The TuioTime time stamp remains unchanged.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param rs the rotation velocity to assign
* @param ma the motion acceleration to assign
* @param ra the rotation acceleration to assign
*/
virtual void update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra);
/**
* Takes the atttibutes of the provided TuioComponent
* and assigs these values to this TuioComponent.
* The TuioTime time stamp of this TuioComponent remains unchanged.
*
* @param tcon the TuioComponent to assign
*/
virtual void update(TuioComponent *tcon);
/**
* Assigns the REMOVE state to this TuioComponent and sets
* its TuioTime time stamp to the provided TuioTime argument.
*
* @param ttime the TuioTime to assign
*/
virtual void remove(TuioTime ttime);
/**
* Returns the Session ID of this TuioComponent.
* @return the Session ID of this TuioComponent
*/
virtual unsigned int getSessionID() const;
/**
* Returns the X velocity of this TuioComponent.
* @return the X velocity of this TuioComponent
*/
virtual float getXSpeed() const;
/**
* Returns the Y velocity of this TuioComponent.
* @return the Y velocity of this TuioComponent
*/
virtual float getYSpeed() const;
/**
* Returns the position of this TuioComponent.
* @return the position of this TuioComponent
*/
virtual TuioPoint getPosition() const;
/**
* Returns the path of this TuioComponent.
* @return the path of this TuioComponent
*/
virtual std::list<TuioPoint> getPath() const;
/**
* Returns the motion speed of this TuioComponent.
* @return the motion speed of this TuioComponent
*/
virtual float getMotionSpeed() const;
/**
* Returns the motion acceleration of this TuioComponent.
* @return the motion acceleration of this TuioComponent
*/
virtual float getMotionAccel() const;
/**
* Returns the rotation angle of this TuioComponent.
* @return the rotation angle of this TuioComponent
*/
float getAngle() const;
/**
* Returns the rotation angle in degrees of this TuioComponent.
* @return the rotation angle in degrees of this TuioComponent
*/
float getAngleDegrees() const;
/**
* Returns the rotation speed of this TuioComponent.
* @return the rotation speed of this TuioComponent
*/
float getRotationSpeed() const;
/**
* Returns the rotation acceleration of this TuioComponent.
* @return the rotation acceleration of this TuioComponent
*/
float getRotationAccel() const;
/**
* Returns the TUIO state of this TuioComponent.
* @return the TUIO state of this TuioComponent
*/
virtual int getTuioState() const;
/**
* Returns true of this TuioComponent is moving.
* @return true of this TuioComponent is moving
*/
virtual bool isMoving() const;
};
}
#endif // INCLUDED_TUIOCOMPONENT_H

View File

@@ -1,165 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioDispatcher.h"
#include <iostream>
#include <list>
#include <algorithm>
#include <cstring>
using namespace TUIO2;
TuioDispatcher::TuioDispatcher() {
#ifndef WIN32
pthread_mutex_init(&tobjMutex,NULL);
#else
tobjMutex = CreateMutex(NULL,FALSE,"tobjMutex");
#endif
}
TuioDispatcher::~TuioDispatcher() {
#ifndef WIN32
pthread_mutex_destroy(&tobjMutex);
#else
CloseHandle(tobjMutex);
#endif
}
void TuioDispatcher::lockObjectList() {
#ifndef WIN32
pthread_mutex_lock(&tobjMutex);
#else
WaitForSingleObject(tobjMutex, INFINITE);
#endif
}
void TuioDispatcher::unlockObjectList() {
#ifndef WIN32
pthread_mutex_unlock(&tobjMutex);
#else
ReleaseMutex(tobjMutex);
#endif
}
void TuioDispatcher::addTuioListener(TuioListener *listener) {
listenerList.push_back(listener);
}
void TuioDispatcher::removeTuioListener(TuioListener *listener) {
std::list<TuioListener*>::iterator result = find(listenerList.begin(),listenerList.end(),listener);
if (result!=listenerList.end()) listenerList.remove(listener);
}
void TuioDispatcher::removeAllTuioListeners() {
listenerList.clear();
}
TuioObject* TuioDispatcher::getTuioObject(unsigned int s_id) {
lockObjectList();
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
if((*tobj)->getSessionID()==s_id) {
unlockObjectList();
return (*tobj);
}
}
unlockObjectList();
return NULL;
}
TuioToken* TuioDispatcher::getTuioToken(unsigned int s_id) {
TuioObject *tobj = getTuioObject(s_id);
if (tobj==NULL) return NULL;
return tobj->getTuioToken();
}
TuioPointer* TuioDispatcher::getTuioPointer(unsigned int s_id) {
TuioObject *tobj = getTuioObject(s_id);
if (tobj==NULL) return NULL;
return tobj->getTuioPointer();
}
TuioBounds* TuioDispatcher::getTuioBounds(unsigned int s_id) {
TuioObject *tobj = getTuioObject(s_id);
if (tobj==NULL) return NULL;
return tobj->getTuioBounds();
}
TuioSymbol* TuioDispatcher::getTuioSymbol(unsigned int s_id) {
TuioObject *tobj = getTuioObject(s_id);
if (tobj==NULL) return NULL;
return tobj->getTuioSymbol();
}
std::list<TuioObject*> TuioDispatcher::getTuioObjectList() {
std::list<TuioObject*> listBuffer;
lockObjectList();
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
listBuffer.push_back(*tobj);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioToken*> TuioDispatcher::getTuioTokenList() {
std::list<TuioToken*> listBuffer;
lockObjectList();
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
TuioToken *ttok = (*tobj)->getTuioToken();
if (ttok!=NULL) listBuffer.push_back(ttok);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioPointer*> TuioDispatcher::getTuioPointerList() {
std::list<TuioPointer*> listBuffer;
lockObjectList();
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
TuioPointer *tptr = (*tobj)->getTuioPointer();
if (tptr!=NULL) listBuffer.push_back(tptr);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioBounds*> TuioDispatcher::getTuioBoundsList() {
std::list<TuioBounds*> listBuffer;
lockObjectList();
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
TuioBounds *tbnd = (*tobj)->getTuioBounds();
if (tbnd!=NULL) listBuffer.push_back(tbnd);
}
unlockObjectList();
return listBuffer;
}
std::list<TuioSymbol*> TuioDispatcher::getTuioSymbolList() {
std::list<TuioSymbol*> listBuffer;
lockObjectList();
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
TuioSymbol *tsym = (*tobj)->getTuioSymbol();
if (tsym!=NULL) listBuffer.push_back(tsym);
}
unlockObjectList();
return listBuffer;
}

View File

@@ -1,169 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIODISPATCHER_H
#define INCLUDED_TUIODISPATCHER_H
#include "TuioListener.h"
#ifndef WIN32
#include <pthread.h>
#else
#include <windows.h>
#endif
namespace TUIO2 {
/**
* <p>The TuioDispatcher generates TUIO events which are broadcasted to all
* registered classes that implement the {@link TuioListener} interface.</p>
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioDispatcher {
public:
/**
* This constructor creates a TuioDispatcher
*
*/
TuioDispatcher();
/**
* The destructor is doing nothing in particular.
*/
~TuioDispatcher();
/**
* Adds the provided TuioListener to the list of registered TUIO event listeners
*
* @param listener the TuioListener to add
*/
void addTuioListener(TuioListener *listener);
/**
* Removes the provided TuioListener from the list of registered TUIO event listeners
*
* @param listener the TuioListener to remove
*/
void removeTuioListener(TuioListener *listener);
/**
* Removes all TuioListener from the list of registered TUIO event listeners
*/
void removeAllTuioListeners();
/**
* Returns a List of all currently active TuioObject
*
* @return a List of all currently active TuioObject
*/
std::list<TuioObject*> getTuioObjectList();
/**
* Returns a List of all currently active TuioTokens
*
* @return a List of all currently active TuioTokens
*/
std::list<TuioToken*> getTuioTokenList();
/**
* Returns a List of all currently active TuioPointers
*
* @return a List of all currently active TuioPointers
*/
std::list<TuioPointer*> getTuioPointerList();
/**
* Returns a List of all currently active TuioBounds
*
* @return a List of all currently active TuioBounds
*/
std::list<TuioBounds*> getTuioBoundsList();
/**
* Returns a List of all currently active TuioSymbols
*
* @return a List of all currently active TuioSymbols
*/
std::list<TuioSymbol*> getTuioSymbolList();
/**
* Returns the TuioObject corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioObject
*
* @return an active TuioObject corresponding to the provided Session ID or NULL
*/
TuioObject* getTuioObject(unsigned int s_id);
/**
* Returns the TuioToken corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioToken
*
* @return an active TuioToken corresponding to the provided Session ID or NULL
*/
TuioToken* getTuioToken(unsigned int s_id);
/**
* Returns the TuioPointer corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioPointer
*
* @return an active TuioPointer corresponding to the provided Session ID or NULL
*/
TuioPointer* getTuioPointer(unsigned int s_id);
/**
* Returns the TuioBounds corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioBounds
*
* @return an active TuioBounds corresponding to the provided Session ID or NULL
*/
TuioBounds* getTuioBounds(unsigned int s_id);
/**
* Returns the TuioSymbol corresponding to the provided Session ID
* or NULL if the Session ID does not refer to an active TuioSymbol
*
* @return an active TuioSymbol corresponding to the provided Session ID or NULL
*/
TuioSymbol* getTuioSymbol(unsigned int s_id);
/**
* Locks the TuioObject list in order to avoid updates during access
*/
void lockObjectList();
/**
* Releases the lock of the TuioObject list
*/
void unlockObjectList();
protected:
std::list<TuioListener*> listenerList;
std::list<TuioObject*> tobjList;
#ifndef WIN32
pthread_mutex_t tobjMutex;
#else
HANDLE tobjMutex;
#endif
};
}
#endif /* INCLUDED_TUIODISPATCHER_H */

View File

@@ -1,80 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOLISTENER_H
#define INCLUDED_TUIOLISTENER_H
#include "TuioObject.h"
namespace TUIO2 {
/**
* <p>The TuioListener interface provides a simple callback infrastructure which is used by the {@link TuioClient} class
* to dispatch TUIO events to all registered instances of classes that implement the TuioListener interface defined here.</p>
* <p>Any class that implements the TuioListener interface is required to implement all of the callback methods defined here.
* The {@link TuioClient} makes use of these interface methods in order to dispatch TUIO events to all registered TuioListener implementations.</p>
* <p><code>
* public class MyTuioListener implements TuioListener<br/>
* ...</code><p><code>
* MyTuioListener listener = new MyTuioListener();<br/>
* TuioClient client = new TuioClient();<br/>
* client.addTuioListener(listener);<br/>
* client.start();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioListener {
public:
/**
* The destructor is doing nothing in particular.
*/
virtual ~TuioListener(){};
/**
* This callback method is invoked by the TuioClient when a new TUIO Component is added to the session.
*
* @param tobj the TuioObject reference that encapsulates all related TUIO Components
*/
virtual void tuioAdd(TuioObject *tobj)=0;
/**
* This callback method is invoked by the TuioClient when an existing TUIO Component is updated during the session.
*
* @param tobj the TuioObject reference that encapsulates all related TUIO Components
*/
virtual void tuioUpdate(TuioObject *tobj)=0;
/**
* This callback method is invoked by the TuioClient when a TUIO Component is removed from the session.
*
* @param tobj the TuioObject reference that encapsulates all related TUIO Components
*/
virtual void tuioRemove(TuioObject *tobj)=0;
/**
* This callback method is invoked by the TuioClient to mark the end of a received TUIO message bundle.
*
* @param ftime the TuioTime associated to the current TUIO message bundle
*/
virtual void tuioRefresh(TuioTime ftime)=0;
};
}
#endif /* INCLUDED_TUIOLISTENER_H */

View File

@@ -1,575 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioManager.h"
using namespace TUIO2;
TuioManager::TuioManager()
: currentFrameTime(TuioTime::getSystemTime())
, currentFrame(-1)
, pointerCount(0)
, maxPointerID(-1)
, sessionID(-1)
, tobjUpdate(false)
, verbose(false)
, invert_x(false)
, invert_y(false)
, invert_a(false)
{
}
TuioManager::~TuioManager() {
}
TuioObject* TuioManager::createTuioObject() {
sessionID++;
TuioObject *tobj = new TuioObject(sessionID);
tobjList.push_back(tobj);
return tobj;
}
void TuioManager::addExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
tobjList.push_back(tobj);
TuioPointer *tptr = tobj->getTuioPointer();
if (tptr!=NULL) pointerCount++;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioAdd(tobj);
if (verbose) std::cout << "add " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
}
void TuioManager::updateExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioUpdate(tobj);
if (verbose) std::cout << "set " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
}
void TuioManager::removeExternalTuioObject(TuioObject *tobj) {
if (tobj==NULL) return;
tobjList.remove(tobj);
TuioPointer *tptr = tobj->getTuioPointer();
if (tptr!=NULL) pointerCount--;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioRemove(tobj);
if (verbose) std::cout << "del " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
}
void TuioManager::removeTuioObject(unsigned int s_id) {
TuioObject *tobj = NULL;
for(std::list<TuioObject*>::iterator iter = tobjList.begin();iter!= tobjList.end(); iter++) {
if((*iter)->getSessionID()==s_id) {
tobj = *iter;
break;
}
}
if (tobj==NULL) return;
else removeTuioObject(tobj);
}
void TuioManager::removeTuioObject(TuioObject *tobj) {
if (tobj== NULL) return;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioRemove(tobj);
if (tobj->containsTuioToken()) {
if (verbose) std::cout << "del tok " << tobj->getSessionID() << std::endl;
tobj->deleteTuioToken();
}
if (tobj->containsTuioPointer()) {
if (verbose) std::cout << "del ptr " << tobj->getSessionID() << std::endl;
tobj->deleteTuioPointer();
}
if (tobj->containsTuioBounds()) {
if (verbose) std::cout << "del bnd " << tobj->getSessionID() << std::endl;
tobj->deleteTuioBounds();
}
if (tobj->containsTuioSymbol()) {
if (verbose) std::cout << "del sym " << tobj->getSessionID() << std::endl;
tobj->deleteTuioSymbol();
}
tobjList.remove(tobj);
tobjUpdate = true;
delete tobj;
}
TuioObject* TuioManager::createTuioToken(unsigned int sym, float x, float y, float a) {
return addTuioToken(NULL, sym, 0, 0, x, y, a);
}
TuioObject* TuioManager::createTuioToken(unsigned int sym, unsigned short t_id, unsigned short u_id, float x, float y, float a) {
return addTuioToken(NULL, sym, t_id, u_id, x, y, a);
}
TuioObject* TuioManager::addTuioToken(TuioObject *tobj, unsigned int sym, float x, float y, float a) {
return addTuioToken(tobj, sym, 0, 0, x, y, a);
}
TuioObject* TuioManager::addTuioToken(TuioObject *tobj, unsigned short t_id, unsigned short u_id, unsigned int sym, float x, float y, float a) {
TuioToken *ttok = new TuioToken(currentFrameTime, tobj, t_id, u_id, sym, x, y, a);
return addTuioToken(ttok);
}
TuioObject* TuioManager::addTuioToken(TuioToken *ttok) {
if (ttok==NULL) return NULL;
TuioObject *tobj = ttok->getContainingTuioObject();
if (tobj==NULL) tobj = createTuioObject();
tobj->setTuioToken(ttok);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) {
(*listener)->tuioAdd(tobj);
}
if (verbose) std::cout << "add tok " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
return tobj;
}
void TuioManager::updateTuioToken(TuioToken *ttok, float x, float y, float a) {
if (ttok==NULL) return;
if (ttok->getTuioTime()==currentFrameTime) return;
ttok->update(currentFrameTime,x,y,a);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioUpdate(ttok->getContainingTuioObject());
if (verbose)std::cout << "set tok " << ttok->getSessionID() << std::endl;
tobjUpdate = true;
}
void TuioManager::removeTuioToken(TuioToken *ttok) {
if (ttok==NULL) return;
TuioObject *tobj = ttok->getContainingTuioObject();
if (tobj==NULL) {
delete ttok;
return;
} else removeTuioObject(tobj);
}
TuioObject* TuioManager::createTuioPointer(float x, float y, float a, float s, float r, float p) {
return addTuioPointer(NULL, 0, 0, x, y, a, s, r, p);
}
TuioObject* TuioManager::createTuioPointer(unsigned short t_id, unsigned short u_id, float x, float y, float a, float s, float r, float p) {
return addTuioPointer(NULL, t_id, u_id, x, y, a, s, r, p);
}
TuioObject* TuioManager::addTuioPointer(TuioObject *tobj, float x, float y, float a, float s, float r, float p) {
return addTuioPointer(tobj, 0, 0, x, y, a, s, r, p);
}
TuioObject* TuioManager::addTuioPointer(TuioObject *tobj, unsigned short t_id, unsigned short u_id, float x, float y, float a, float s, float r, float p) {
int pointerID = pointerCount;
if ((pointerCount<=maxPointerID) && (freePointerList.size()>0)) {
std::list<TuioPointer*>::iterator closestPointer = freePointerList.begin();
for(std::list<TuioPointer*>::iterator iter = freePointerList.begin();iter!= freePointerList.end(); iter++) {
if((*iter)->getDistance(x,y)<(*closestPointer)->getDistance(x,y)) closestPointer = iter;
}
TuioPointer *freePointer = (*closestPointer);
pointerID = (*closestPointer)->getPointerID();
freePointerList.erase(closestPointer);
delete freePointer;
} else maxPointerID = pointerID;
TuioPointer *tptr = new TuioPointer(currentFrameTime, tobj, t_id, u_id, pointerID, x, y, a, s, r, p);
return addTuioPointer(tptr);
}
TuioObject* TuioManager::createTuioPointer(unsigned int p_id, float x, float y, float a, float s, float r, float p) {
return addTuioPointer(NULL, p_id, 0, 0, x, y, a, s, r, p);
}
TuioObject* TuioManager::createTuioPointer(unsigned int p_id, unsigned short t_id, unsigned short u_id, float x, float y, float a, float s, float r, float p) {
return addTuioPointer(NULL, p_id, t_id, u_id, x, y, a, s, r, p);
}
TuioObject* TuioManager::addTuioPointer(TuioObject *tobj, unsigned int p_id, float x, float y, float a, float s, float r, float p) {
return addTuioPointer(tobj, p_id, 0, 0, x, y, a, s, r, p);
}
TuioObject* TuioManager::addTuioPointer(TuioObject *tobj, unsigned int p_id, unsigned short t_id, unsigned short u_id, float x, float y, float a, float s, float r, float p) {
TuioPointer *tptr = new TuioPointer(currentFrameTime, tobj, t_id, u_id, p_id, x, y, a, s, r, p);
return addTuioPointer(tptr);
}
TuioObject* TuioManager::addTuioPointer(TuioPointer *tptr) {
if (tptr==NULL) return NULL;
TuioObject *tobj = tptr->getContainingTuioObject();
if (tobj==NULL) tobj = createTuioObject();
tobj->setTuioPointer(tptr);
pointerCount++;
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) {
(*listener)->tuioAdd(tobj);
}
if (verbose) std::cout << "add ptr " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
return tobj;
}
void TuioManager::updateTuioPointer(TuioPointer *tptr, float x, float y, float a, float s, float r, float p) {
if (tptr==NULL) return;
if (tptr->getTuioTime()==currentFrameTime) return;
TuioObject *tobj = tptr->getContainingTuioObject();
if (tobj==NULL) return;
tptr->update(currentFrameTime,x,y,a,s,r,p);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioUpdate(tobj);
if (verbose)std::cout << "set ptr " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
}
void TuioManager::removeTuioPointer(TuioPointer *tptr) {
if (tptr==NULL) return;
pointerCount--;
TuioObject *tobj = tptr->getContainingTuioObject();
if (tptr->getPointerID()==maxPointerID) {
maxPointerID = -1;
if (pointerCount>0) {
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
if ((*iter)->containsTuioPointer()) {
int pointerID = (*iter)->getTuioPointer()->getPointerID();
if (pointerID>maxPointerID) maxPointerID=pointerID;
}
}
freePointerBuffer.clear();
for (std::list<TuioPointer*>::iterator flist=freePointerList.begin(); flist != freePointerList.end(); flist++) {
TuioPointer *freePointer = (*flist);
if (freePointer->getPointerID()<=maxPointerID) freePointerBuffer.push_back(new TuioPointer(freePointer));
}
freePointerList = freePointerBuffer;
} else {
for (std::list<TuioPointer*>::iterator flist=freePointerList.begin(); flist != freePointerList.end(); flist++) {
TuioPointer *freePointer = (*flist);
delete freePointer;
}
freePointerList.clear();
}
} else if (tptr->getPointerID()<maxPointerID) {
freePointerList.push_back(new TuioPointer(tptr));
}
if (tobj==NULL) {
delete tptr;
return;
} else removeTuioObject(tobj);
}
TuioObject* TuioManager::createTuioBounds(float x, float y, float a, float w, float h, float f) {
return addTuioBounds(NULL, x, y, a ,w ,h ,f);
}
TuioObject* TuioManager::addTuioBounds(TuioObject *tobj, float x, float y, float a, float w, float h, float f) {
TuioBounds *tbnd = new TuioBounds(currentFrameTime, tobj, x, y, a, w, h, f);
return addTuioBounds(tbnd);
}
TuioObject* TuioManager::addTuioBounds(TuioBounds *tbnd) {
if (tbnd==NULL) return NULL;
TuioObject *tobj = tbnd->getContainingTuioObject();
if (tobj==NULL) tobj = createTuioObject();
tobj->setTuioBounds(tbnd);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) {
(*listener)->tuioAdd(tobj);
}
if (verbose) std::cout << "add bnd " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
return tobj;
}
void TuioManager::updateTuioBounds(TuioBounds *tbnd, float x, float y, float a, float w, float h, float f) {
if (tbnd==NULL) return;
if (tbnd->getTuioTime()==currentFrameTime) return;
tbnd->update(currentFrameTime,x,y,a,w,h,f);
TuioObject *tobj = tbnd->getContainingTuioObject();
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioUpdate(tobj);
if (verbose)std::cout << "set bnd " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
}
void TuioManager::removeTuioBounds(TuioBounds *tbnd) {
if (tbnd==NULL) return;
TuioObject *tobj = tbnd->getContainingTuioObject();
if (tobj==NULL) {
delete tbnd;
return;
} else removeTuioObject(tobj);
}
TuioObject* TuioManager::createTuioSymbol(unsigned short t_id, unsigned short u_id, unsigned int sym, const char *type, const char *data) {
return addTuioSymbol(NULL, t_id, u_id, sym, type, data);
}
TuioObject* TuioManager::addTuioSymbol(TuioObject *tobj, unsigned short t_id, unsigned short u_id, unsigned int sym, const char *type, const char *data) {
TuioSymbol *tsym = new TuioSymbol(currentFrameTime, tobj, t_id, u_id, sym, type, data);
return addTuioSymbol(tsym);
}
TuioObject* TuioManager::addTuioSymbol(TuioSymbol *tsym) {
if (tsym==NULL) return NULL;
TuioObject *tobj = tsym->getContainingTuioObject();
if (tobj==NULL) tobj = createTuioObject();
tobj->setTuioSymbol(tsym);
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) {
if (tobjUpdate)(*listener)->tuioUpdate(tobj);
else(*listener)->tuioAdd(tobj);
}
if (verbose) std::cout << "add sym " << tobj->getSessionID() << std::endl;
tobjUpdate = true;
return tobj;
}
void TuioManager::removeTuioSymbol(TuioSymbol *tsym) {
if (tsym==NULL) return;
TuioObject *tobj = tsym->getContainingTuioObject();
if (tobj==NULL) {
delete tsym;
return;
} else removeTuioObject(tobj);
}
int TuioManager::getSessionID() {
sessionID++;
if (sessionID==UINT_MAX) sessionID = 0;
return sessionID;
}
int TuioManager::getFrameID() {
return currentFrame;
}
TuioTime TuioManager::getFrameTime() {
return currentFrameTime;
}
void TuioManager::initTuioFrame(TuioTime ttime) {
frameTimeTag = TuioTime::getSystemTimeTag();
currentFrameTime = TuioTime(ttime);
currentFrame++;
if (currentFrame==UINT_MAX) currentFrame = 1;
}
void TuioManager::commitTuioFrame() {
for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
(*listener)->tuioRefresh(currentFrameTime);
if (verbose) std::cout << "refresh " << currentFrame << " " << currentFrameTime.getTotalMilliseconds() << std::endl;
}
TuioToken* TuioManager::getClosestTuioToken(float xp, float yp) {
TuioToken *closestToken = NULL;
float closestDistance = 1.0f;
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
TuioToken *ttok = (*iter)->getTuioToken();
if (ttok==NULL) continue;
float distance = ttok->getDistance(xp,yp);
if(distance<closestDistance) {
closestToken = ttok;
closestDistance = distance;
}
}
return closestToken;
}
TuioPointer* TuioManager::getClosestTuioPointer(float xp, float yp) {
TuioPointer *closestPointer = NULL;
float closestDistance = 1.0f;
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter != tobjList.end(); iter++) {
TuioPointer *tptr = (*iter)->getTuioPointer();
if (tptr==NULL) continue;
float distance = tptr->getDistance(xp,yp);
if(distance<closestDistance) {
closestPointer = tptr;
closestDistance = distance;
}
}
return closestPointer;
}
TuioBounds* TuioManager::getClosestTuioBounds(float xp, float yp) {
TuioBounds *closestBounds = NULL;
float closestDistance = 1.0f;
for (std::list<TuioObject*>::iterator iter=tobjList.begin(); iter!=tobjList.end(); iter++) {
TuioBounds *tbnd = (*iter)->getTuioBounds();
if (tbnd==NULL) continue;
float distance = tbnd->getDistance(xp,yp);
if(distance<closestDistance) {
closestBounds = tbnd;
closestDistance = distance;
}
}
return closestBounds;
}
std::list<TuioObject*> TuioManager::getUntouchedObjects() {
std::list<TuioObject*> untouched;
for (std::list<TuioObject*>::iterator tobj=tobjList.begin(); tobj!=tobjList.end(); tobj++) {
bool touched = false;
if ((*tobj)->containsTuioToken()) {
if ((*tobj)->getTuioToken()->getTuioTime()==currentFrameTime) touched=true;
}
if ((*tobj)->containsTuioPointer()) {
if ((*tobj)->getTuioPointer()->getTuioTime()==currentFrameTime) touched=true;
}
if ((*tobj)->containsTuioBounds()) {
if ((*tobj)->getTuioToken()->getTuioTime()==currentFrameTime) touched=true;
}
if ((*tobj)->containsTuioSymbol()) {
if ((*tobj)->getTuioSymbol()->getTuioTime()==currentFrameTime) touched=true;
}
if (!touched) untouched.push_back(*tobj);
}
return untouched;
}
void TuioManager::stopUntouchedMovingObjects() {
for (std::list<TuioObject*>::iterator tobj = tobjList.begin(); tobj!=tobjList.end(); tobj++) {
if ((*tobj)->containsTuioToken()) {
TuioToken *ttok = (*tobj)->getTuioToken();
if ((ttok->getTuioTime()!=currentFrameTime) && (ttok->isMoving())) {
ttok->stop(currentFrameTime);
if (verbose) std::cout << "set tok " << ttok->getSessionID() << std::endl;
tobjUpdate = true;
}
}
if ((*tobj)->containsTuioPointer()) {
TuioPointer *tptr = (*tobj)->getTuioPointer();
if ((tptr->getTuioTime()!=currentFrameTime) && (tptr->isMoving())) {
tptr->stop(currentFrameTime);
if (verbose) std::cout << "set ptr " << tptr->getSessionID() << std::endl;
tobjUpdate = true;
}
}
if ((*tobj)->containsTuioBounds()) {
TuioBounds *tbnd = (*tobj)->getTuioBounds();
if ((tbnd->getTuioTime()!=currentFrameTime) && (tbnd->isMoving())) {
tbnd->stop(currentFrameTime);
if (verbose) std::cout << "set bnd " << tbnd->getSessionID() << std::endl;
tobjUpdate = true;
}
}
}
}
void TuioManager::removeUntouchedStoppedObjects() {
std::list<TuioObject*>::iterator iter = tobjList.begin();
while (iter!=tobjList.end()) {
TuioObject *tobj = (*iter);
if ((tobj->getTuioTime()!=currentFrameTime) && (!tobj->isMoving())) {
removeTuioObject(tobj);
iter = tobjList.begin();
} else iter++;
}
}
void TuioManager::resetTuioObjectList() {
pointerCount=0;
std::list<TuioObject*>::iterator tobj = tobjList.begin();
while (tobj!=tobjList.end()) {
removeTuioObject((*tobj));
tobj = tobjList.begin();
}
}

View File

@@ -1,601 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOMANAGER_H
#define INCLUDED_TUIOMANAGER_H
#include "TuioDispatcher.h"
#include <iostream>
#include <list>
#include <algorithm>
namespace TUIO2 {
/**
* <p>The TuioManager class is the central TUIO session management component.</p>
* <p>During runtime the each frame is marked with the initFrame and commitFrame methods,
* while the currently present TuioTokens are managed by the server with ADD, UPDATE and REMOVE methods in analogy to the TuioClient's TuioListener interface.</p>
* <p><code>
* TuioManager *manager = new TuioManager();<br/>
* ...<br/>
* server->initTuioFrame(TuioTime::getSessionTime());<br/>
* TuioToken *ttok = server->addTuioToken(xpos,ypos, angle);<br/>
* TuioPointer *tptr = server->addTuioToken(xpos,ypos);<br/>
* TuioBounds *tbnd = server->addTuioBounds(xpos,ypos,width,height,angle);<br/>
* server->commitFrame();<br/>
* ...<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* server->updateTuioToken(ttok, xpos,ypos, angle);<br/>
* server->updateTuioPointer(tptr, xpos,ypos);<br/>
* server->updateTuioBounds(tbnd, xpos,ypos,width,height,angle);<br/>
* server->commitFrame();<br/>
* ...<br/>
* server->initFrame(TuioTime::getSessionTime());<br/>
* server->removeTuioToken(ttok);<br/>
* server->removeTuioPointer(tptr);<br/>
* server->removeTuioBounds(tbnd);<br/>
* server->commitFrame();<br/>
* </code></p>
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioManager : public TuioDispatcher {
public:
/**
* The default constructor creates a TuioManager
*/
TuioManager();
/**
* The destructor is doing nothing in particular.
*/
~TuioManager();
/**
* Adds an externally managed TuioObject to the TuioServer's internal list of active TuioObjects
*
* @param tobj the TuioObject to add
*/
void addExternalTuioObject(TuioObject *tobj);
/**
* Updates an externally managed TuioObject
*
* @param tobj the TuioObject to update
*/
void updateExternalTuioObject(TuioObject *tobj);
/**
* Removes an externally managed TuioObject from the TuioServer's internal list of TuioObjects
* The referenced TuioObject is not deleted
*
* @param tobj the TuioObject to remove
*/
void removeExternalTuioObject(TuioObject *tobj);
/**
* Creates an internally managed TuioObject with a new Session ID
* and adds it to the TuioServer's internal list of TuioObjects
*
* @return the newly created but empty TuioObject
*/
TuioObject* createTuioObject();
/**
* Removes an internally managed TuioObject from the TuioServer's internal list of TuioObjects
* The provided TuioObject (and all its encapsulated TUIO Components) are deleted
*
* @param s_id the Session ID of the internal TuioObject to remove
*/
void removeTuioObject(unsigned int s_id);
/**
* Removes an internally managed TuioObject from the TuioServer's internal list of TuioObjects
* The provided TuioObject (and all its encapsulated TUIO Components) are deleted
*
* @param tobj the internal TuioObject to remove
*/
void removeTuioObject(TuioObject *tobj);
/**
* Creates a new TuioToken based on the given arguments.
* A new TuioObject containing that TuioToken is added
* to the TuioServer's internal list of TuioObjects
* and the TuioToken reference is returned to the caller.
*
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @return reference to the created TuioToken
*/
TuioObject* createTuioToken(unsigned int sym, float xp, float yp, float a);
/**
* Creates a new TuioToken based on the given arguments.
* A new TuioObject containing that TuioToken is added
* to the TuioServer's internal list of TuioObjects
* and the TuioToken reference is returned to the caller.
*
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @return a reference to the TuioObject of the TuioToken
*/
TuioObject* createTuioToken(unsigned int sym, unsigned short t_id, unsigned short u_id, float xp, float yp, float a);
/**
* Creates a new TuioToken based on the given arguments.
* and adds it to an existing TuioObject with the Session ID
* from the TuioServer's internal list of TuioObjects
* and the TuioToken reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @return a reference to the TuioObject of the TuioToken
*/
TuioObject* addTuioToken(TuioObject *tobj, unsigned short t_id, unsigned short u_id, unsigned int sym, float xp, float yp, float a);
/**
* Creates a new TuioToken based on the given arguments.
* and adds it to an existing TuioObject with the Session ID
* from the TuioServer's internal list of TuioObjects
* and the TuioToken reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @return a reference to the TuioObject of the TuioToken
*/
TuioObject* addTuioToken(TuioObject *tobj, unsigned int sym, float xp, float yp, float a);
/**
* Adds the provided TuioToken to an existing TuioObject
* from the TuioServer's internal list of TuioObjects
* or creates the according TuioObject if not found.
*
* @param ttok the existing TuioToken to add
* @return a reference to the TuioObject of the TuioToken
*/
TuioObject* addTuioToken(TuioToken *ttok);
/**
* Updates the referenced TuioToken based on the given arguments.
*
* @param ttok the TuioToken to update
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
void updateTuioToken(TuioToken *ttok, float xp, float yp, float a);
/**
* Removes the provided TuioToken from an existing TuioObject
* and also deletes the TuioObject with all other components
*
* @param ttok the TuioToken to remove
*/
void removeTuioToken(TuioToken *ttok);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* createTuioPointer(float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* and adds it to an existing TuioObject with the Session ID
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference of the TuioObject is returned to the caller.
*
* @param tobj the existing TuioObject
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* addTuioPointer(TuioObject *tobj, float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* createTuioPointer(unsigned short t_id, unsigned short u_id, float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* addTuioPointer(TuioObject *tobj, unsigned short t_id, unsigned short u_id, float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param p_id the Pointer ID to assign
* @param xp the X coordinate to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return reference to the created TuioPointer
*/
TuioObject* createTuioPointer(unsigned int p_id, float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param p_id the Pointer ID to assign
* @param xp the X coordinate to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return reference to the created TuioPointer
*/
TuioObject* addTuioPointer(TuioObject *tobj, unsigned int p_id, float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param p_id the Pointer ID to assign
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param xp the X coordinate to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* createTuioPointer(unsigned int p_id, unsigned short t_id, unsigned short u_id, float xp, float yp, float a, float s, float r, float p);
/**
* Creates a new TuioPointer based on the given arguments.
* The new TuioPointer is added to the TuioServer's internal list of active TuioPointers
* and a reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param p_id the Pointer ID to assign
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param xp the X coordinate to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* addTuioPointer(TuioObject *tobj, unsigned int p_id, unsigned short t_id, unsigned short u_id, float xp, float yp, float a, float s, float r, float p);
/**
* Adds the provided TuioPointer to an existing TuioObject
* from the TuioServer's internal list of TuioObjects
* or creates the according TuioObject if not found.
*
* @param tptr the existing TuioPointer to add
* @return a reference to the TuioObject of the TuioPointer
*/
TuioObject* addTuioPointer(TuioPointer *tptr);
/**
* Updates the referenced TuioPointer based on the given arguments.
*
* @param tptr the TuioPointer to update
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the rotation angle to assign
* @param s the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
*/
void updateTuioPointer(TuioPointer *tptr, float xp, float yp, float a, float s, float r, float p);
/**
* Removes the provided TuioPointer from an existing TuioObject
* and also deletes the TuioObject with all other components
*
* @param tptr the TuioPointer to remove
*/
void removeTuioPointer(TuioPointer *tptr);
/**
* Creates a new TuioBounds based on the given arguments.
* The new TuioBounds is added to the TuioServer's internal list of active TuioBounds
* and a reference is returned to the caller.
*
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param angle the angle to assign
* @param width the width to assign
* @param height the height to assign
* @param area the area to assign
* @return a reference to the TuioObject of the TuioBounds
*/
TuioObject* createTuioBounds(float xp, float yp, float angle, float width, float height, float area);
/**
* Creates a new TuioBounds based on the given arguments.
* The new TuioBounds is added to the TuioServer's internal list of active TuioBounds
* and a reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param angle the angle to assign
* @param width the width to assign
* @param height the height to assign
* @param area the area to assign
* @return a reference to the TuioObject of the TuioBounds
*/
TuioObject* addTuioBounds(TuioObject *tobj, float xp, float yp, float angle, float width, float height, float area);
/**
* Adds the provided TuioBounds to an existing TuioObject
* from the TuioServer's internal list of TuioObjects
* or creates the according TuioObject if not found.
*
* @param tbnd the TuioBounds to add
* @return a reference to the TuioObject of the TuioBounds
*/
TuioObject* addTuioBounds(TuioBounds *tbnd);
/**
* Updates the referenced TuioBounds based on the given arguments.
*
* @param tbnd the TuioToken to update
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param angle the angle to assign
* @param width the width to assign
* @param height the height to assign
* @param area the area to assign
*/
void updateTuioBounds(TuioBounds *tbnd, float xp, float yp, float angle, float width, float height, float area);
/**
* Removes the referenced TuioBounds from the TuioServer's internal list of TuioObjects
* and also deletes its TuioObject (and all its encapsulated TUIO Components)
*
* @param tbnd the TuioBounds to remove
*/
void removeTuioBounds(TuioBounds *tbnd);
/**
* Creates a new TuioSymbol based on the given arguments.
* The new TuioSymbol is added to the TuioServer's internal list of TuioObjects
* and a reference is returned to the caller.
*
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param sym the Symbol ID to assign
* @param type the type descriptor to assign
* @param data the synbol data to assign
* @return a reference to the TuioObject of the TuioSymbol
*/
TuioObject* createTuioSymbol(unsigned short t_id, unsigned short u_id, unsigned int sym, const char *type, const char *data);
/**
* Creates a new TuioSymbol based on the given arguments.
* The new TuioSymbol is added to the TuioServer's internal list of TuioObjects
* and a reference is returned to the caller.
*
* @param tobj the existing TuioObject
* @param t_id the Type ID to assign
* @param u_id the User ID to assign
* @param sym the Symbol ID to assign
* @param type the type descriptor to assign
* @param data the synbol data to assign
* @return a reference to the TuioObject of the TuioSymbol
*/
TuioObject* addTuioSymbol(TuioObject *tobj, unsigned short t_id, unsigned short u_id, unsigned int sym, const char *type, const char *data);
/**
* Adds the provided TuioSymbol to an existing TuioObject
* from the TuioServer's internal list of TuioObjects
* or creates the according TuioObject if not found.
*
* @param tsym the TuioSymbol to add
* @return a reference to the TuioObject of the TuioSymbol
*/
TuioObject* addTuioSymbol(TuioSymbol *tsym);
/**
* Removes the referenced TuioSymbol from the TuioServer's internal list of TuioObjects
* and also deletes its TuioObject (and all its encapsulated TUIO Components)
*
* @param tsym the TuioSymbol to remove
*/
void removeTuioSymbol(TuioSymbol *tsym);
/**
* Initializes a new frame with the given TuioTime
*
* @param ttime the frame time
*/
void initTuioFrame(TuioTime ttime);
/**
* Commits the current frame.
* Generates and sends TUIO messages of all currently active and updated TuioTokens and TuioPointers.
*/
void commitTuioFrame();
/**
* Returns the next available Session ID for external use.
* @return the next available Session ID for external use
*/
int getSessionID();
/**
* Returns the current frame ID for external use.
* @return the current frame ID for external use
*/
int getFrameID();
/**
* Returns the current frame time for external use.
* @return the current frame time for external use
*/
TuioTime getFrameTime();
/**
* Returns a List of all currently inactive TuioObjects
*
* @return a List of all currently inactive TuioObjects
*/
std::list<TuioObject*> getUntouchedObjects();
/**
* Calculates speed and acceleration values for all currently inactive TuioObjects
*/
void stopUntouchedMovingObjects();
/**
* Removes all currently inactive TuioObjects from the TuioServer's internal list
*/
void removeUntouchedStoppedObjects();
/**
* Returns the TuioToken closest to the provided coordinates
* or NULL if there isn't any active TuioToken
*
* @return the closest TuioToken to the provided coordinates or NULL
*/
TuioToken* getClosestTuioToken(float xp, float yp);
/**
* Returns the TuioPointer closest to the provided coordinates
* or NULL if there isn't any active TuioPointer
*
* @return the closest TuioPointer corresponding to the provided coordinates or NULL
*/
TuioPointer* getClosestTuioPointer(float xp, float yp);
/**
* Returns the TuioBounds closest to the provided coordinates
* or NULL if there isn't any active TuioBounds
*
* @return the closest TuioBounds corresponding to the provided coordinates or NULL
*/
TuioBounds* getClosestTuioBounds(float xp, float yp);
/**
* The TuioServer prints verbose TUIO event messages to the console if set to true.
* @param verbose print verbose messages if set to true
*/
void setVerbose(bool verbose) { this->verbose=verbose; }
void setInversion(bool ix, bool iy, bool ia) {
invert_x = ix;
invert_y = iy;
invert_a = ia;
};
void setInvertXpos(bool ix) { invert_x = ix; };
void setInvertYpos(bool iy) { invert_y = iy; };
void setInvertAngle(bool ia) { invert_a = ia; };
bool getInvertXpos() { return invert_x; };
bool getInvertYpos() { return invert_y; };
bool getInvertAngle() { return invert_a; };
void resetTuioObjectList();
protected:
std::list<TuioPointer*> freePointerList;
std::list<TuioPointer*> freePointerBuffer;
TuioTime currentFrameTime;
osc::TimeTag frameTimeTag;
unsigned int currentFrame;
unsigned int pointerCount, maxPointerID;
unsigned int sessionID;
bool tobjUpdate;
bool verbose;
bool invert_x;
bool invert_y;
bool invert_a;
};
}
#endif /* INCLUDED_TUIOMANAGER_H */

View File

@@ -1,311 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioObject.h"
using namespace TUIO2;
TuioObject::TuioObject (unsigned int s_id) {
currentTime = TuioTime::getSystemTime();
session_id = s_id;
startTime = currentTime;
token = NULL;
pointer = NULL;
bounds = NULL;
symbol = NULL;
state = TUIO_ADDED;
}
TuioObject::TuioObject (TuioTime ttime, unsigned int s_id) {
currentTime = ttime;
session_id = s_id;
startTime = currentTime;
token = NULL;
pointer = NULL;
bounds = NULL;
symbol = NULL;
state = TUIO_ADDED;
}
TuioObject::TuioObject (TuioTime ttime, TuioSource *src, unsigned int s_id) {
currentTime = ttime;
session_id = s_id;
startTime = currentTime;
setTuioSource(src);
token = NULL;
pointer = NULL;
bounds = NULL;
symbol = NULL;
state = TUIO_ADDED;
}
TuioObject::~TuioObject() {
deleteAllTuioComponents();
}
unsigned int TuioObject::getSessionID() {
return session_id;
}
void TuioObject::setTuioSource(TuioSource *src) {
source.setSourceString(src->getSourceID(),src->getSourceString());
}
TuioSource* TuioObject::getTuioSource() {
return &source;
}
void TuioObject::setTuioToken (TuioToken *ttok) {
token = ttok;
token->setContainingTuioObject(this);
currentTime = TuioTime::getSystemTime();
state = TUIO_ADDED;
}
void TuioObject::setTuioPointer (TuioPointer *tptr) {
pointer = tptr;
pointer->setContainingTuioObject(this);
currentTime = TuioTime::getSystemTime();
state = TUIO_ADDED;
}
void TuioObject::setTuioBounds (TuioBounds *tbnd) {
bounds = tbnd;
bounds->setContainingTuioObject(this);
currentTime = TuioTime::getSystemTime();
state = TUIO_ADDED;
}
void TuioObject::setTuioSymbol (TuioSymbol *tsym) {
symbol = tsym;
symbol->setContainingTuioObject(this);
currentTime = TuioTime::getSystemTime();
state = TUIO_ADDED;
}
void TuioObject::removeAllTuioComponents(TuioTime ttime) {
removeTuioToken(ttime);
removeTuioPointer(ttime);
removeTuioBounds(ttime);
removeTuioSymbol(ttime);
}
void TuioObject::removeTuioToken (TuioTime ttime) {
if (token != NULL) token->remove(ttime);
currentTime = ttime;
}
void TuioObject::removeTuioPointer (TuioTime ttime) {
if (pointer != NULL) pointer->remove(ttime);
currentTime = ttime;
}
void TuioObject::removeTuioBounds (TuioTime ttime) {
if (bounds != NULL) bounds->remove(ttime);
currentTime = ttime;
}
void TuioObject::removeTuioSymbol (TuioTime ttime) {
if (symbol != NULL) symbol->remove(ttime);
currentTime = ttime;
}
void TuioObject::deleteAllTuioComponents() {
deleteTuioToken();
deleteTuioPointer();
deleteTuioBounds();
deleteTuioSymbol();
}
void TuioObject::deleteTuioToken () {
if (token != NULL) {
delete token;
token = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::deleteTuioPointer () {
if (pointer != NULL) {
delete pointer;
pointer = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::deleteTuioBounds () {
if (bounds != NULL) {
delete bounds;
bounds = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::deleteTuioSymbol () {
if (symbol != NULL) {
delete symbol;
symbol = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::clearAllTuioComponents() {
clearTuioToken();
clearTuioPointer();
clearTuioBounds();
clearTuioSymbol();
}
void TuioObject::clearTuioToken () {
if (token != NULL) {
token = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::clearTuioPointer () {
if (pointer != NULL) {
pointer = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::clearTuioBounds () {
if (bounds != NULL) {
bounds = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
void TuioObject::clearTuioSymbol () {
if (symbol != NULL) {
symbol = NULL;
//currentTime = TuioTime::getSessionTime();
}
}
bool TuioObject::containsAnyTuioComponent () {
if (token != NULL) return true;
else if (pointer != NULL) return true;
else if (bounds != NULL) return true;
else if (symbol != NULL) return true;
else return false;
}
bool TuioObject::containsTuioToken () {
if (token != NULL) return true;
else return false;
}
bool TuioObject::containsTuioPointer () {
if (pointer != NULL) return true;
else return false;
}
bool TuioObject::containsTuioBounds () {
if (bounds != NULL) return true;
else return false;
}
bool TuioObject::containsTuioSymbol () {
if (symbol != NULL) return true;
else return false;
}
bool TuioObject::containsNewTuioToken () {
if (token == NULL) return false;
else if (token->getTuioState()==TUIO_ADDED) return true;
else return false;
}
bool TuioObject::containsNewTuioPointer () {
if (pointer == NULL) return false;
else if (pointer->getTuioState()==TUIO_ADDED) return true;
else return false;
}
bool TuioObject::containsNewTuioBounds () {
if (bounds == NULL) return false;
else if (bounds->getTuioState()==TUIO_ADDED) return true;
else return false;
}
bool TuioObject::containsNewTuioSymbol () {
if (symbol == NULL) return false;
else if (symbol->getTuioState()==TUIO_ADDED) return true;
else return false;
}
TuioToken* TuioObject::getTuioToken () {
return token;
}
TuioPointer* TuioObject::getTuioPointer () {
return pointer;
}
TuioBounds* TuioObject::getTuioBounds () {
return bounds;
}
TuioSymbol* TuioObject::getTuioSymbol () {
return symbol;
}
void TuioObject::stop(TuioTime ttime){
if (token!=NULL) token->stop(ttime);
if (pointer!=NULL) pointer->stop(ttime);
if (bounds!=NULL) bounds->stop(ttime);
currentTime = ttime;
}
void TuioObject::remove(TuioTime ttime){
if (token!=NULL) token->remove(ttime);
if (pointer!=NULL) pointer->remove(ttime);
if (bounds!=NULL) bounds->remove(ttime);
currentTime = ttime;
state = TUIO_REMOVED;
}
void TuioObject::update(TuioTime ttime){
currentTime = ttime;
state = TUIO_IDLE;
}
bool TuioObject::isMoving(){
if ((token!=NULL) && token->isMoving()) return true;
if ((pointer!=NULL) && pointer->isMoving()) return true;
if ((bounds!=NULL) && bounds->isMoving()) return true;
return false;
}
TuioTime TuioObject::getTuioTime() const{
return currentTime;
}
TuioTime TuioObject::getStartTime() const{
return startTime;
}
unsigned char TuioObject::getTuioState() const{
return state;
}

View File

@@ -1,347 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOOBJECT_H
#define INCLUDED_TUIOOBJECT_H
#include "TuioTime.h"
#include "TuioToken.h"
#include "TuioPointer.h"
#include "TuioBounds.h"
#include "TuioSymbol.h"
#include "TuioSource.h"
namespace TUIO2 {
/**
* The TuioObject class encapsulates all Tuio objects that share the same Session ID.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioObject {
protected:
/**
* The shared session ID
*/
unsigned int session_id;
/**
* The associated TuioSource
*/
TuioSource source;
/**
* the associated TuioToken
*/
TuioToken *token;
/**
* the associated TuioPointer
*/
TuioPointer *pointer;
/**
* the associated TuioBounds
*/
TuioBounds *bounds;
/**
* the associated TuioSymbol
*/
TuioSymbol *symbol;
/**
* The time stamp of the last update represented as TuioTime (time since session start)
*/
TuioTime currentTime;
/**
* The creation time of this TuioObject represented as TuioTime (time since session start)
*/
TuioTime startTime;
/**
* Reflects the current state of the TuioObject
*/
unsigned char state;
public:
/**
* The default constructor only takes the Session ID
* @param s_id the Session ID to assign
*/
TuioObject (unsigned int s_id);
/**
* Copy constructor takes a reference of a TuioObject
* @param t the reference TuioObject to assign
*/
//TuioObject(const TuioObject &t);
/**
* This constructor takes a TuioTime and the Session ID
* @param ttime the TuioTime to assign
* @param s_id the Session ID to assign
*/
TuioObject (TuioTime ttime, unsigned int s_id);
/**
* This constructor takes a TuioTime and the Session ID
* @param ttime the TuioTime to assign
* @param src the TuioSource to assign
* @param s_id the Session ID to assign
*/
TuioObject (TuioTime ttime, TuioSource *src, unsigned int s_id);
/**
* The default destructor also delets all assigned TUIO components
*/
~TuioObject ();
/**
* Returns the associated Session ID
* @return the associated Session ID
*/
unsigned int getSessionID();
/**
* Sets the assotiated TUIO source
*
* @param src the TuioSource to assign
*/
void setTuioSource(TuioSource *src);
/**
* Returns the associated TUIO source
*/
TuioSource* getTuioSource();
/**
* This method assigns a TuioToken to this TuioObject
* @param ttok the TuioToken to assign
*/
void setTuioToken(TuioToken *ttok);
/**
* This method assigns a TuioPointer to this TuioObject
* @param tptr the TuioPointer to assign
*/
void setTuioPointer(TuioPointer *tptr);
/**
* This method assigns a TuioBounds to this TuioObject
* @param tbnd the TuioBounds to assign
*/
void setTuioBounds(TuioBounds *tbnd);
/**
* This method assigns a TuioSymbol to this TuioObject
* @param tsym the TuioSymbol to assign
*/
void setTuioSymbol(TuioSymbol *tsym);
/**
* This method sets all TuioComponents in this TuioObject to TUIO_REMOVED state
*/
void removeAllTuioComponents(TuioTime ttime);
/**
* This method sets the TuioToken in this TuioObject to TUIO_REMOVED state
*/
void removeTuioToken(TuioTime ttime);
/**
* This method sets the TuioPointer in this TuioObject to TUIO_REMOVED state
*/
void removeTuioPointer(TuioTime ttime);
/**
* This method sets the TuioBounds in this TuioObject to TUIO_REMOVED state
*/
void removeTuioBounds(TuioTime ttime);
/**
* This method sets the TuioSymbol in this TuioObject to TUIO_REMOVED state
*/
void removeTuioSymbol(TuioTime ttime);
/**
* This method deletes all TuioComponents in this TuioObject
*/
void deleteAllTuioComponents();
/**
* This method deletes the TuioToken in this TuioObject
*/
void deleteTuioToken();
/**
* This method deletes the TuioPointer in this TuioObject
*/
void deleteTuioPointer();
/**
* This method deletes the TuioBounds in this TuioObject
*/
void deleteTuioBounds();
/**
* This method deletes the TuioSymbol in this TuioObject
*/
void deleteTuioSymbol();
/**
* This method clears all TuioComponents in this TuioObject
*/
void clearAllTuioComponents();
/**
* This method clears the TuioToken in this TuioObject
*/
void clearTuioToken();
/**
* This method clears the TuioPointer in this TuioObject
*/
void clearTuioPointer();
/**
* This method clears the TuioBounds in this TuioObject
*/
void clearTuioBounds();
/**
* This method clears the TuioSymbol in this TuioObject
*/
void clearTuioSymbol();
/**
* This method tests for any TuioComponent in this TuioObject
* @return true if any TuioComponent has been assigned
*/
bool containsAnyTuioComponent();
/**
* This method tests for a TuioToken in this TuioObject
* @return true if a TuioToken has been assigned
*/
bool containsTuioToken();
/**
* This method tests for a TuioPointer in this TuioObject
* @return true if a TuioPointer has been assigned
*/
bool containsTuioPointer();
/**
* This method tests for a TuioBounds in this TuioObject
* @return true if a TuioBounds has been assigned
*/
bool containsTuioBounds();
/**
* This method tests for a TuioSymbol in this TuioObject
* @return true if a TuioSymbol has been assigned
*/
bool containsTuioSymbol();
/**
* This method tests if a new TuioToken has been added to this TuioObject
* @return true if a TuioToken has been added
*/
bool containsNewTuioToken();
/**
* This method tests if a new TuioPointer has been added this TuioObject
* @return true if a TuioPointer has been added
*/
bool containsNewTuioPointer();
/**
* This method tests if a new TuioBounds has been added to this TuioObject
* @return true if a TuioBounds has been added
*/
bool containsNewTuioBounds();
/**
* This method tests if a new TuioSymbol has beed added to this TuioObject
* @return true if a TuioSymbol has been added
*/
bool containsNewTuioSymbol();
/**
* This method returns the TuioToken associated to this TuioObject
* @return the associated TuioToken
*/
TuioToken* getTuioToken();
/**
* This method returns the TuioPointer associated to this TuioObject
* @return the associated TuioPointer
*/
TuioPointer* getTuioPointer();
/**
* This method returns the TuioBounds associated to this TuioObject
* @return the associated TuioBounds
*/
TuioBounds* getTuioBounds();
/**
* This method returns the TuioSymbol associated to this TuioObject
* @return the associated TuioSymbol
*/
TuioSymbol* getTuioSymbol();
/**
* This method stops all encapsulated TuioComponents
*/
void stop(TuioTime ttime);
/**
* This method removes all encapsulated TuioComponents
*/
void remove(TuioTime ttime);
/**
* This method returns true if any encapsulated TuioComponent is moving
*/
bool isMoving();
/**
* This method refreshes the currentTime after an update
*/
void update(TuioTime ttime);
/**
* Returns current time stamp of this TuioPoint as TuioTime
*
* @return the time stamp of this TuioPoint as TuioTime
*/
TuioTime getTuioTime() const;
/**
* Returns the start time of this TuioPoint as TuioTime.
*
* @return the start time of this TuioPoint as TuioTime
*/
TuioTime getStartTime() const;
/**
* Returns the TUIO state of this TuioObject.
* @return the TUIO state of this TuioObject
*/
unsigned char getTuioState() const;
};
}
#endif // INCLUDED_TUIOOBJECT_H

View File

@@ -1,132 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioPointer.h"
using namespace TUIO2;
TuioPointer::TuioPointer (TuioTime ttime, TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int pi, float xp, float yp, float a, float sa, float r, float p):TuioComponent(ttime,tobj,xp,yp,a) {
type_id = ti;
user_id = ui;
pointer_id = pi;
shear = sa;
radius = r;
pressure = p;
}
TuioPointer::TuioPointer (TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int pi, float xp, float yp, float a, float sa, float r, float p):TuioComponent(tobj,xp,yp,a) {
type_id = ti;
user_id = ui;
shear = sa;
pointer_id = pi;
radius = r;
pressure = p;
}
TuioPointer::TuioPointer (TuioObject *tobj, unsigned int pi, float xp, float yp, float a, float sa, float r, float p):TuioComponent(tobj,xp,yp,a) {
type_id = 0;
user_id = 0;
pointer_id = pi;
shear = sa;
radius = r;
pressure = p;
}
TuioPointer::TuioPointer (TuioPointer *tptr):TuioComponent(tptr) {
pointer_id = tptr->getPointerID();
type_id = tptr->getTypeID();
user_id = tptr->getUserID();
shear = tptr->getShear();
radius = tptr->getRadius();
pressure = tptr->getPressure();
}
void TuioPointer::update (TuioTime ttime, float xp, float yp, float a, float sa, float r, float p, float xs, float ys, float ps, float ma, float pa) {
TuioComponent::update(ttime,xp,yp,a,xs,ys,0,ma,0);
shear = sa;
radius = r;
pressure = p;
pressure_speed = ps;
pressure_accel = pa;
}
void TuioPointer::update (float xp, float yp, float a, float sa, float r, float p, float xs, float ys, float ps, float ma, float pa) {
TuioComponent::update(xp,yp,a,xs,ys,0,ma,0);
shear = sa;
radius = r;
pressure = p;
pressure_speed = ps;
pressure_accel = pa;
}
void TuioPointer::update (TuioTime ttime, float xp, float yp, float a, float sa, float r, float p) {
TuioComponent::update(ttime,xp,yp,a);
shear = sa;
radius = r;
pressure = p;
}
void TuioPointer::update (TuioPointer *tptr) {
TuioComponent::update(tptr);
shear = tptr->getShear();
radius = tptr->getRadius();
pressure = tptr->getPressure();
}
unsigned int TuioPointer::getPointerID() const{
return pointer_id;
};
unsigned short TuioPointer::getTypeID() const{
return type_id;
};
unsigned short TuioPointer::getUserID() const{
return user_id;
};
unsigned int TuioPointer::getTypeUserID() const {
int tu_id = user_id << 16 | type_id;
return tu_id;
}
void TuioPointer::setTypeUserID(unsigned int tu_id) {
user_id = tu_id >> 16;
type_id = tu_id & 0x0000FFFF;
}
float TuioPointer::getShear() const{
return shear;
};
float TuioPointer::getRadius() const{
return radius;
};
float TuioPointer::getPressure() const{
return pressure;
};
float TuioPointer::getPressureSpeed() const{
return pressure_speed;
}
float TuioPointer::getPressureAccel() const{
return pressure_accel;
}

View File

@@ -1,263 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOPOINTER_H
#define INCLUDED_TUIOPOINTER_H
#include "TuioComponent.h"
namespace TUIO2 {
/**
* The TuioPointer class encapsulates /tuio2/ptr TUIO pointers.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioPointer: public TuioComponent {
protected:
/**
* The individual pointer ID number that is assigned to each TuioPointer.
*/
unsigned int pointer_id;
/**
* The pointer type ID that is assigned to each TuioPointer.
*/
unsigned short type_id;
/**
* The user ID that is assigned to each TuioPointer.
*/
unsigned short user_id;
/**
* The shear angle that is assigned to each TuioPointer.
*/
float shear;
/**
* The action radius that is assigned to each TuioPointer.
*/
float radius;
/**
* The pressure that is assigned to each TuioPointer.
*/
float pressure;
/**
* The pressure speed value.
*/
float pressure_speed;
/**
* The pressure acceleration value.
*/
float pressure_accel;
public:
using TuioComponent::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, Pointer ID, X and Y coordinate to the newly created TuioPointer.
*
* @param ttime the TuioTime to assign
* @param tobj the TuioObject to assign
* @param ti the Type ID to assign
* @param ui the User ID to assign
* @param pi the Pointer ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param sa the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
*/
TuioPointer (TuioTime ttime, TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int pi, float xp, float yp, float a, float sa, float r, float p);
/**
* This constructor takes the provided Session ID, Pointer ID, X and Y coordinate
* and assigs these values to the newly created TuioPointer.
*
* @param tobj the TuioObject to assign
* @param ti the Type ID to assign
* @param ui the User ID to assign
* @param pi the Pointer ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param sa the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
*/
TuioPointer (TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int pi, float xp, float yp, float a, float sa, float r, float p);
/**
* This constructor takes the provided Session ID, Pointer ID, X and Y coordinate
* and assigs these values to the newly created TuioPointer.
*
* @param tobj the TuioObject to assign
* @param pi the Pointer ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param sa the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
*/
TuioPointer (TuioObject *tobj, unsigned int pi, float xp, float yp, float a, float sa, float r, float p);
/**
* This constructor takes the atttibutes of the provided TuioPointer
* and assigs these values to the newly created TuioPointer.
*
* @param tptr the TuioPointer to assign
*/
TuioPointer (TuioPointer *tptr);
/**
* The destructor is doing nothing in particular.
*/
~TuioPointer(){};
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate, width, pressure, X and Y velocity, motion acceleration,
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param sa the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param ps the pressure velocity to assign
* @param ma the motion acceleration to assign
* @param pa the pressure acceleration to assign
*/
void update (TuioTime ttime, float xp, float yp, float a, float sa, float r, float p, float xs, float ys, float ps, float ma, float pa);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate, width, pressure, X and Y velocity, motion acceleration,
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param sa the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
* @param xs the X velocity to assign
* @param ys the Y velocity to assign
* @param ps the pressure velocity to assign
* @param ma the motion acceleration to assign
* @param pa the pressure acceleration to assign
*/
void update (float xp, float yp, float a, float sa, float r, float p, float xs, float ys, float ps, float ma, float pa);
/**
* Takes a TuioTime argument and assigns it along with the provided
* X and Y coordinate and angle to the private TuioToken attributes.
* The speed and accleration values are calculated accordingly.
*
* @param ttime the TuioTime to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
* @param sa the shear angle to assign
* @param r the radius to assign
* @param p the pressure to assign
*/
void update (TuioTime ttime, float xp, float yp, float a, float sa, float r, float p);
/**
* Takes the atttibutes of the provided TuioPointer
* and assigs these values to this TuioPointer.
* The TuioTime time stamp of this TuioComponent remains unchanged.
*
* @param ttok the TuioComponent to assign
*/
void update (TuioPointer *tptr);
/**
* Returns the Pointer ID of this TuioPointer.
* @return the Pointer ID of this TuioPointer
*/
unsigned int getPointerID() const;
/**
* Returns the Type ID of this TuioPointer.
* @return the Type ID of this TuioPointer
*/
unsigned short getTypeID() const;
/**
* Returns the User ID of this TuioPointer.
* @return the User ID of this TuioPointer
*/
unsigned short getUserID() const;
/**
* Returns the encoded Type & User ID of this TuioPointer.
* @return the encoded Type & User ID of this TuioPointer
*/
unsigned int getTypeUserID() const;
/**
* Decodes and assigns the Type & User ID to this TuioPointer.
* @param tu_id the encoded Type & User ID of this TuioPointer
*/
void setTypeUserID(unsigned int tu_id);
/**
* Returns the shear angle of this TuioPointer.
* @return the shear angle of this TuioPointer
*/
float getShear() const;
/**
* Returns the action radius of this TuioPointer.
* @return the action radius of this TuioPointer
*/
float getRadius() const;
/**
* Returns the Pressure of this TuioPointer.
* @return the Pressure of this TuioPointer
*/
float getPressure() const;
/**
* Returns the pressure speed of this TuioPointer.
* @return the pressure speed of this TuioPointer
*/
float getPressureSpeed() const;
/**
* Returns the pressure acceleration of this TuioPointer.
* @return the pressure acceleration of this TuioPointer
*/
float getPressureAccel() const;
};
}
#endif

View File

@@ -1,329 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioServer.h"
#include "UdpSender.h"
using namespace TUIO2;
using namespace osc;
TuioServer::TuioServer()
:local_sender (true)
,full_update (false)
,periodic_update (false)
,source (NULL)
{
primary_sender = new UdpSender();
initialize();
}
TuioServer::TuioServer(const char *host, unsigned short port)
:local_sender (true)
,full_update (false)
,periodic_update (false)
,source (NULL)
{
primary_sender = new UdpSender(host,port);
initialize();
}
TuioServer::TuioServer(OscSender *oscsend)
:primary_sender (oscsend)
,local_sender (false)
,full_update (false)
,periodic_update (false)
,source (NULL)
{
initialize();
}
void TuioServer::initialize() {
senderList.push_back(primary_sender);
int size = primary_sender->getBufferSize();
oscBuffer = new char[size];
oscPacket = new osc::OutboundPacketStream(oscBuffer,size);
fullBuffer = new char[size];
fullPacket = new osc::OutboundPacketStream(oscBuffer,size);
updateTime = TuioTime(currentFrameTime);
//sendEmptyTuioBundle();
invert_x = false;
invert_y = false;
invert_a = false;
}
TuioServer::~TuioServer() {
initTuioFrame(TuioTime::getSystemTime());
stopUntouchedMovingObjects();
initTuioFrame(TuioTime::getSystemTime());
removeUntouchedStoppedObjects();
sendEmptyTuioBundle();
delete []oscBuffer;
delete oscPacket;
delete []fullBuffer;
delete fullPacket;
if (local_sender) delete primary_sender;
}
void TuioServer::addOscSender(OscSender *sender) {
// add source address if previously local
/*if ((source_name) && (primary_sender->isLocal()) && (senderList.size()==1)) {
setSourceName(source_name);
}*/
// resize packets to smallest transport method
unsigned int size = sender->getBufferSize();
if (size<oscPacket->Capacity()) {
osc::OutboundPacketStream *temp = oscPacket;
oscPacket = new osc::OutboundPacketStream(oscBuffer,size);
delete temp;
temp = fullPacket;
fullPacket = new osc::OutboundPacketStream(oscBuffer,size);
delete temp;
}
senderList.push_back(sender);
}
void TuioServer::deliverOscPacket(osc::OutboundPacketStream *packet) {
for (unsigned int i=0;i<senderList.size();i++)
senderList[i]->sendOscPacket(packet);
}
void TuioServer::setSourceName(const char* name) {
if (source==NULL) source = new TuioSource(name);
//else source->setSourceName(name);
}
void TuioServer::setDimension(unsigned short w, unsigned short h) {
if (source!=NULL) source->setDimension(w,h);
// decoder test
/*int dim = source->getDimension();
short width = dim >> 16;
short height = dim & 0x0000FFFF;
printf("dim: %i %i\n",width,height);*/
}
void TuioServer::commitTuioFrame() {
TuioManager::commitTuioFrame();
if(tobjUpdate) {
startTuioBundle(currentFrame);
for (std::list<TuioObject*>::iterator tobj = tobjList.begin(); tobj!=tobjList.end(); tobj++) {
if ((*tobj)->containsTuioToken()) {
TuioToken *ttok = (*tobj)->getTuioToken();
if ((full_update) || (ttok->getTuioTime()==currentFrameTime)) addTokenMessage(ttok);
}
if ((*tobj)->containsTuioPointer()) {
TuioPointer *tptr = (*tobj)->getTuioPointer();
if ((full_update) || (tptr->getTuioTime()==currentFrameTime)) addPointerMessage(tptr);
}
if ((*tobj)->containsTuioBounds()) {
TuioBounds *tbnd = (*tobj)->getTuioBounds();
if ((full_update) || (tbnd->getTuioTime()==currentFrameTime)) addBoundsMessage(tbnd);
}
if ((*tobj)->containsTuioSymbol()) {
TuioSymbol *tsym = (*tobj)->getTuioSymbol();
if ((full_update) || (tsym->getTuioTime()==currentFrameTime)) addSymbolMessage(tsym);
}
}
updateTime = TuioTime(currentFrameTime);
sendTuioBundle();
} else if (periodic_update) {
TuioTime timeCheck = currentFrameTime - updateTime;
if(timeCheck.getSeconds()>=update_interval) {
updateTime = TuioTime(currentFrameTime);
startTuioBundle(currentFrame);
if (full_update) {
for (std::list<TuioObject*>::iterator tobj = tobjList.begin(); tobj!=tobjList.end(); tobj++) {
// start a new packet if we exceed the packet capacity
if ((oscPacket->Capacity()-oscPacket->Size())<TOK_MESSAGE_SIZE) {
sendTuioBundle();
startTuioBundle(currentFrame);
}
addTokenMessage((*tobj)->getTuioToken());
}
}
sendTuioBundle();
}
}
tobjUpdate = false;
}
void TuioServer::sendEmptyTuioBundle() {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
(*oscPacket) << osc::BeginMessage( "/tuio2/frm") << 0 << TuioTime::getSystemTimeTag() << (int32)source->getDimension() << source->getSourceName() << osc::EndMessage;
(*oscPacket) << osc::BeginMessage( "/tuio2/alv") << osc::EndMessage;
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}
void TuioServer::sendFullTuioBundle() {
}
void TuioServer::checkBundleCapacity(int msg_size) {
int size = msg_size + ALV_MESSAGE_SIZE + 4*tobjList.size();
if ((oscPacket->Capacity()-oscPacket->Size())<size) {
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket ); // send the intermediate bundle without final ALV message!
startTuioBundle(currentFrame);
}
}
void TuioServer::startTuioBundle(unsigned int fseq) {
oscPacket->Clear();
(*oscPacket) << osc::BeginBundleImmediate;
if (source) (*oscPacket) << osc::BeginMessage( "/tuio2/frm") << (int32)currentFrame << frameTimeTag << (int32)source->getDimension() << source->getSourceName();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addTokenMessage(TuioToken *ttok) {
// start a new packet if we exceed the packet capacity
checkBundleCapacity(TOK_MESSAGE_SIZE);
float xpos = ttok->getX();
float xvel = ttok->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = ttok->getY();
float yvel = ttok->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
float angle = ttok->getAngle();
float rvel = ttok->getRotationSpeed();
if (invert_a) {
angle = 2.0f*(float)M_PI - angle;
rvel = -1 * rvel;
}
(*oscPacket) << osc::BeginMessage( "/tuio2/tok");
(*oscPacket) << (int32)ttok->getSessionID() << (int32)ttok->getTypeUserID() << (int32)ttok->getSymbolID() << xpos << ypos << angle;
(*oscPacket) << xvel << yvel << rvel << ttok->getMotionAccel() << ttok->getRotationAccel();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addPointerMessage(TuioPointer *tptr) {
// start a new packet if we exceed the packet capacity
checkBundleCapacity(PTR_MESSAGE_SIZE);
float xpos = tptr->getX();
float xvel = tptr->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = tptr->getY();
float yvel = tptr->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
(*oscPacket) << osc::BeginMessage( "/tuio2/ptr");
(*oscPacket) << (int32)tptr->getSessionID() << (int32)tptr->getTypeUserID() << (int32)tptr->getPointerID();
(*oscPacket) << xpos << ypos << tptr->getAngle() << tptr->getShear() << tptr->getRadius() << tptr->getPressure();
(*oscPacket) << xvel << yvel << tptr->getPressureSpeed() << tptr->getMotionAccel() << tptr->getPressureAccel();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addBoundsMessage(TuioBounds *tbnd) {
// start a new packet if we exceed the packet capacity
checkBundleCapacity(BND_MESSAGE_SIZE);
float xpos = tbnd->getX();
float xvel = tbnd->getXSpeed();
if (invert_x) {
xpos = 1 - xpos;
xvel = -1 * xvel;
}
float ypos = tbnd->getY();
float yvel = tbnd->getYSpeed();
if (invert_y) {
ypos = 1 - ypos;
yvel = -1 * yvel;
}
float angle = tbnd->getAngle();
float rvel = tbnd->getRotationSpeed();
if (invert_a) {
angle = 2.0f*(float)M_PI - angle;
rvel = -1 * rvel;
}
(*oscPacket) << osc::BeginMessage( "/tuio2/bnd");
(*oscPacket) << (int32)tbnd->getSessionID() << xpos << ypos << angle << tbnd->getWidth() << tbnd->getHeight() << tbnd->getArea();
(*oscPacket) << xvel << yvel << rvel << tbnd->getMotionAccel() << tbnd->getRotationAccel();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::addSymbolMessage(TuioSymbol *tsym) {
// start a new packet if we exceed the packet capacity
checkBundleCapacity(SYM_MESSAGE_SIZE);
(*oscPacket) << osc::BeginMessage( "/tuio2/sym");
(*oscPacket) << (int32)tsym->getSessionID() << (int32)tsym->getTypeUserID() << (int32)tsym->getSymbolID();
(*oscPacket) << tsym->getSymbolType() << tsym->getSymbolData();
(*oscPacket) << osc::EndMessage;
}
void TuioServer::sendTuioBundle() {
//int before = oscPacket->Capacity()-oscPacket->Size();
(*oscPacket) << osc::BeginMessage( "/tuio2/alv");
for(std::list<TuioObject*>::iterator tobj = tobjList.begin();tobj!= tobjList.end(); tobj++)
(*oscPacket) << (int32)(*tobj)->getSessionID();
(*oscPacket) << osc::EndMessage;
//int after = oscPacket->Capacity()-oscPacket->Size();
//printf("ALV_MESSAGE_SIZE: %i\n",before-after);
(*oscPacket) << osc::EndBundle;
deliverOscPacket( oscPacket );
}

View File

@@ -1,244 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOSOURCE_H
#define INCLUDED_TUIOSOURCE_H
#include <sstream>
#include <string.h>
#include <stdlib.h>
#include <iostream>
namespace TUIO2 {
/**
* The TuioSource class encapsulates the meta data for the TUIO source attributes provided in /tuio2/frm.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioSource {
protected:
/**
* The ID of the TUIO source
*/
unsigned int source_id;
/**
* The name of the TUIO source
*/
std::string source_name;
/**
* The instance of the TUIO source
*/
unsigned int source_instance;
/**
* The address of the TUIO source
*/
std::string source_address;
/**
* The encoded sensor dimension
*/
unsigned int dimension;
/**
* The TuioTime of the last frame
*/
TuioTime frameTime;
public:
/**
* Sets the ID, name and address of the TUIO source
*/
TuioSource() {
source_id = 0;
source_name = "default";
source_instance = 0;
source_address = "localhost";
dimension = 0;
};
/**
* Sets the ID, name and address of the TUIO source
*
* @param src_name the name of the TUIO source
*/
TuioSource(std::string src_name) {
source_id = 0;
source_name = src_name;
source_instance = 0;
source_address = "localhost";
dimension = 0;
};
/**
* Sets the ID, name and address of the TUIO source
*
* @param src_name the name of the TUIO source
*/
TuioSource(unsigned int sid, std::string src_string, unsigned int dim) {
source_id = sid;
setSourceString(src_string);
setDimension(dim);
};
/**
* Sets the ID, name and address of the TUIO source
*
* @param src_name the name of the TUIO source
* @param src_inst the instance of the TUIO source
* @param src_addr the address of the TUIO source
*/
TuioSource(std::string src_name, unsigned int src_inst, std::string src_addr) {
source_id = 0;
source_name = src_name;
source_instance = src_inst;
source_address = src_addr;
};
/**
* Sets the ID, name and address of the TUIO source
*
* @param src_id the ID of the TUIO source
* @param src_name the name of the TUIO source
* @param src_inst the instance of the TUIO source
* @param src_addr the address of the TUIO source
*/
TuioSource(unsigned int src_id, std::string src_name, unsigned int src_inst, std::string src_addr) {
source_id = src_id;
source_name = src_name;
source_instance = src_inst;
source_address = src_addr;
};
~TuioSource() {};
void setSourceString(std::string src_string) {
if (src_string.length()==0) return;
char *data = strdup(src_string.c_str());
char *name_inst = strtok(data, "@");
char *addr = strtok(NULL, "@");
if (addr!=NULL) source_address = std::string(addr);
else source_address = (char*)"0x7F000001";
char *name = strtok(name_inst, ":");
source_name = std::string(name);
char *inst = strtok(NULL, ":");
if (inst!=NULL) source_instance = atoi(inst);
else source_instance = 0;
}
void setSourceString(unsigned int src_id, std::string src_string) {
source_id = src_id;
setSourceString(src_string);
}
std::string getSourceString() {
std::stringstream src_stream;
src_stream << source_name << ":" << source_instance << "@" << source_address;
return src_stream.str();
}
/**
* Returns the ID of the TUIO source
*/
unsigned int getSourceID() { return source_id; }
/**
* Returns the name of the TUIO source
*/
const char* getSourceName() { return source_name.c_str(); }
/**
* Returns the instance of the TUIO source
*/
unsigned int getSourceInstance() { return source_instance; }
/**
* Returns the address of the TUIO source
*/
const char* getSourceAddress() { return source_address.c_str(); }
/**
* Encodes the sensor dimension
* @param w the sensor width
* @param h the sensor height
*/
void setDimension(unsigned short w, unsigned short h) {
dimension = w << 16 | h;
}
/**
* Sets the encoded sensor dimension
* @param d the sensor dimension
*/
void setDimension(unsigned int d) {
dimension = d;
}
/**
* Returns the encoded sensor dimension
* @return the encoded sensor dimension
*/
unsigned int getDimension() {
return dimension;
}
/**
* Returns the decoded sensor width
* @return the decoded sensor width
*/
unsigned short getWidth() {
unsigned short width = dimension >> 16;
return width;
}
/**
* Returns the decoded sensor height
* @return the decoded sensor height
*/
unsigned short getHeight() {
unsigned short height = dimension & 0x0000FFFF;
return height;
}
/**
* Sets the last frame time
* @param ttime the TuioTime of the last frame
*/
void setFrameTime(TuioTime ttime) {
frameTime = ttime;
}
/**
* Returns the last frame time
* @return the TuioTime of the last frame
*/
TuioTime getFrameTime() {
return frameTime;
}
};
}
#endif // INCLUDED_TUIOSOURCE_H

View File

@@ -1,91 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioSymbol.h"
using namespace TUIO2;
TuioSymbol::TuioSymbol (TuioTime ttime, TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, const char *type, const char *data):TuioComponent(ttime,tobj,0,0,0) {
currentTime = ttime;
startTime = currentTime;
type_id = ti;
user_id = ui;
symbol_id = sym;
symbol_type = std::string(type);
symbol_data = std::string(data);
state = TUIO_ADDED;
}
TuioSymbol::TuioSymbol (TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, const char *type, const char *data):TuioComponent(tobj,0,0,0) {
currentTime = TuioTime::getSystemTime();
startTime = currentTime;
type_id = ti;
user_id = ui;
symbol_id = sym;
symbol_type = std::string(type);
symbol_data = std::string(data);
state = TUIO_ADDED;
}
TuioSymbol::TuioSymbol (TuioSymbol *tsym):TuioComponent(tsym->getTuioTime(),tsym->getContainingTuioObject(),0,0,0) {
currentTime = TuioTime::getSystemTime();
startTime = currentTime;
session_id = tsym->getSessionID();
type_id = tsym->getTypeID();
user_id = tsym->getUserID();
symbol_id = tsym->getSymbolID();
symbol_type = tsym->getSymbolType();
symbol_data = tsym->getSymbolData();
state = TUIO_ADDED;
}
unsigned int TuioSymbol::getSymbolID() const {
return symbol_id;
}
unsigned short TuioSymbol::getTypeID() const {
return type_id;
}
unsigned short TuioSymbol::getUserID() const {
return user_id;
}
unsigned int TuioSymbol::getTypeUserID() const {
int tu_id = user_id << 16 | type_id;
return tu_id;
}
void TuioSymbol::setTypeUserID(unsigned int tu_id) {
user_id = tu_id >> 16;
type_id = tu_id & 0x0000FFFF;
}
const char* TuioSymbol::getSymbolType() const {
return symbol_type.c_str();
}
const char* TuioSymbol::getSymbolData() const {
return symbol_data.c_str();
}
void TuioSymbol::update(TuioTime ttime) {
TuioComponent::update(ttime,0,0);
}

View File

@@ -1,160 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOSYMBOL_H
#define INCLUDED_TUIOSYMBOL_H
//#pragma clang diagnostic ignored "-Woverloaded-virtual"
#include "TuioTime.h"
#include "TuioComponent.h"
#include <string>
namespace TUIO2 {
/**
* The TuioSymbol class encapsulates /tuio2/sym TUIO symbol.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioSymbol : public TuioComponent {
protected:
/**
* The unique Session ID that is assigned to each TUIO tobj.
*/
unsigned int session_id;
/**
* The individual symbol ID number that is assigned to each TuioToken.
*/
unsigned int symbol_id;
/**
* The symbol type ID that is assigned to each TuioToken.
*/
unsigned short type_id;
/**
* The user ID that is assigned to each TuioToken.
*/
unsigned short user_id;
/**
* The symbol type descriptor
*/
std::string symbol_type;
/**
* The actual symbol data
*/
std::string symbol_data;
/**
* The time stamp of the last update represented as TuioTime (time since session start)
*/
TuioTime currentTime;
/**
* The creation time of this TuioPoint represented as TuioTime (time since session start)
*/
TuioTime startTime;
/**
* Reflects the current state of the TuioSymbol
*/
unsigned char state;
public:
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, Type ID, User ID and Symbol ID as well as the Symbol type and data.
*
* @param ttime the TuioTime to assign
* @param tobj the TuioObject to assign
* @param ti the Type ID to assign
* @param ui the User ID to assign
* @param sym the Symbol ID to assign
* @param type the symbol type descriptor
* @param data the symbol data to assign
*/
TuioSymbol (TuioTime ttime, TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, const char *type, const char *data);
/**
* This constructor assigns the provided Session ID, Type ID, User ID and Symbol ID
* as well as the Symbol type and data.
*
* @param tobj the TuioObject to assign
* @param ti the Type ID to assign
* @param ui the User ID to assign
* @param sym the Symbol ID to assign
* @param type the symbol type descriptor
* @param data the symbol data to assign
*/
TuioSymbol (TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, const char *type, const char *data);
/**
* This constructor takes a TuioSymbol argument and sets its attributes
* to the ones of the provided TuioSymbol.
*
* @param tsym the TuioSymbol to assign
*/
TuioSymbol (TuioSymbol *tsym);
/**
* Returns the Symbol ID of this TuioSymbol.
* @return the Symbol ID of this TuioSymbol
*/
unsigned int getSymbolID() const;
/**
* Returns the Type ID of this TuioSymbol.
* @return the Type ID of this TuioSymbol
*/
unsigned short getTypeID() const;
/**
* Returns the User ID of this TuioSymbol.
* @return the User ID of this TuioSymbol
*/
unsigned short getUserID() const;
/**
* Returns the encoded Type & User ID of this TuioSymbol.
* @return the encoded Type & User ID of this TuioSymbol
*/
unsigned int getTypeUserID() const;
/**
* Decodes and assigns the Type & User ID to this TuioSymbol.
* @param tu_id the encoded Type & User ID of this TuioSymbol
*/
void setTypeUserID(unsigned int tu_id);
/**
* Returns the Type string of this TuioSymbol.
* @return the Type string of this TuioSymbol
*/
const char* getSymbolType() const;
/**
* Returns the actual data of this TuioSymbol.
* @return the actual data of this TuioSymbol
*/
const char* getSymbolData() const;
void update(TuioTime ttime);
/*void update(TuioTime ttime, float xp, float yp);
void update (TuioTime ttime, float xp, float yp, float xs, float ys, float ma);
void update (TuioSymbol *tsym);*/
};
}
#endif

View File

@@ -1,69 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#include "TuioToken.h"
using namespace TUIO2;
TuioToken::TuioToken (TuioTime ttime, TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, float xp, float yp, float a):TuioComponent(ttime, tobj, xp, yp,a) {
type_id = ti;
user_id = ui;
symbol_id = sym;
}
TuioToken::TuioToken (TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, float xp, float yp, float a):TuioComponent(tobj, xp, yp, a) {
type_id = ti;
user_id = ui;
symbol_id = sym;
}
TuioToken::TuioToken (TuioObject *tobj, unsigned int sym, float xp, float yp, float a):TuioComponent(tobj, xp, yp, a) {
type_id = 0;
user_id = 0;
symbol_id = sym;
}
TuioToken::TuioToken (TuioToken *ttok):TuioComponent(ttok) {
symbol_id = ttok->getSymbolID();
}
void TuioToken::stop (TuioTime ttime) {
update(ttime,xpos,ypos,angle);
}
unsigned int TuioToken::getSymbolID() const{
return symbol_id;
}
unsigned short TuioToken::getTypeID() const{
return type_id;
};
unsigned short TuioToken::getUserID() const{
return user_id;
};
unsigned int TuioToken::getTypeUserID() const {
int tu_id = user_id << 16 | type_id;
return tu_id;
}
void TuioToken::setTypeUserID(unsigned int tu_id) {
user_id = tu_id >> 16;
type_id = tu_id & 0x0000FFFF;
}

View File

@@ -1,151 +0,0 @@
/*
TUIO2 C++ Library
Copyright (c) 2009-2014 Martin Kaltenbrunner <martin@tuio.org>
This library 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.0 of the License, or (at your option) any later version.
This library 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 this library.
*/
#ifndef INCLUDED_TUIOTOKEN_H
#define INCLUDED_TUIOTOKEN_H
#include "TuioComponent.h"
namespace TUIO2 {
/**
* The TuioToken class encapsulates /tuio2/tok TUIO tokens.
*
* @author Martin Kaltenbrunner
* @version 2.0.a0
*/
class LIBDECL TuioToken: public TuioComponent {
protected:
/**
* The individual symbol ID number that is assigned to each TuioToken.
*/
unsigned int symbol_id;
/**
* The symbol type ID that is assigned to each TuioToken.
*/
unsigned short type_id;
/**
* The user ID that is assigned to each TuioToken.
*/
unsigned short user_id;
public:
using TuioComponent::update;
/**
* This constructor takes a TuioTime argument and assigns it along with the provided
* Session ID, Symbol ID, X and Y coordinate and angle to the newly created TuioToken.
*
* @param ttime the TuioTime to assign
* @param tobj the TuioObject to assign
* @param ti the Type ID to assign
* @param ui the User ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioToken (TuioTime ttime, TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, float xp, float yp, float a);
/**
* This constructor takes the provided Session ID, Symbol ID, X and Y coordinate
* and angle, and assigs these values to the newly created TuioToken.
*
* @param tobj the TuioObject to assign
* @param ti the Type ID to assign
* @param ui the User ID to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioToken (TuioObject *tobj, unsigned short ti, unsigned short ui, unsigned int sym, float xp, float yp, float a);
/**
* This constructor takes the provided Session ID, Symbol ID, X and Y coordinate
* and angle, and assigs these values to the newly created TuioToken.
*
* @param tobj the TuioObject to assign
* @param sym the Symbol ID to assign
* @param xp the X coordinate to assign
* @param yp the Y coordinate to assign
* @param a the angle to assign
*/
TuioToken (TuioObject *tobj, unsigned int sym, float xp, float yp, float a);
/**
* This constructor takes the atttibutes of the provided TuioToken
* and assigs these values to the newly created TuioToken.
*
* @param ttok the TuioToken to assign
*/
TuioToken (TuioToken *ttok);
/**
* The destructor is doing nothing in particular.
*/
~TuioToken() {};
/**
* This method is used to calculate the speed and acceleration values of a
* TuioToken with unchanged position and angle.
*/
void stop (TuioTime ttime);
/**
* Takes the atttibutes of the provided TuioToken
* and assigs these values to this TuioToken.
* The TuioTime time stamp of this TuioToken remains unchanged.
*
* @param ttok the TuioToken to assign
*/
void update (TuioToken *ttok);
/**
* Returns the symbol ID of this TuioToken.
* @return the symbol ID of this TuioToken
*/
unsigned int getSymbolID() const;
/**
* Returns the Type ID of this TuioToken.
* @return the Type ID of this TuioToken
*/
unsigned short getTypeID() const;
/**
* Returns the User ID of this TuioToken.
* @return the User ID of this TuioToken
*/
unsigned short getUserID() const;
/**
* Returns the encoded Type & User ID of this TuioToken.
* @return the encoded Type & User ID of this TuioToken
*/
unsigned int getTypeUserID() const;
/**
* Decodes and assigns the Type & User ID to this TuioToken.
* @param tu_id the encoded Type & User ID of this TuioToken
*/
void setTypeUserID(unsigned int tu_id);
};
}
#endif

View File

@@ -25,15 +25,16 @@
#ifndef __OPENSPACE_MODULE_TOUCH___TOUCHEAR___H__
#define __OPENSPACE_MODULE_TOUCH___TOUCHEAR___H__
#include <modules/touch/ext/libTUIO2/TUIO2/TuioListener.h>
#include <modules/touch/ext/libTUIO2/TUIO2/TuioClient.h>
#include <modules/touch/ext/libTUIO2/TUIO2/UdpReceiver.h>
#include <modules/touch/ext/libTUIO2/TUIO2/TcpReceiver.h>
#include <modules/touch/ext/libTUIO/TUIO/TuioListener.h>
#include <modules/touch/ext/libTUIO/TUIO/TuioClient.h>
#include <modules/touch/ext/libTUIO/TUIO/UdpReceiver.h>
#include <modules/touch/ext/libTUIO/TUIO/TcpReceiver.h>
#include "glm/glm.hpp"
#include <math.h>
#include <vector>
#include <mutex>
using namespace TUIO2;
using namespace TUIO;
class TuioEar : public TuioListener {
@@ -45,12 +46,21 @@ class TuioEar : public TuioListener {
delete _oscReceiver;
}
void tuioAdd(TuioObject *tobj);
void tuioUpdate(TuioObject *tobj);
void tuioRemove(TuioObject *tobj);
void tuioRefresh(TuioTime frameTime);
void addTuioObject(TuioObject *tobj);
void updateTuioObject(TuioObject *tobj);
void removeTuioObject(TuioObject *tobj);
std::vector<TuioObject*> getInput();
void addTuioCursor(TuioCursor *tcur);
void updateTuioCursor(TuioCursor *tcur);
void removeTuioCursor(TuioCursor *tcur);
void addTuioBlob(TuioBlob *tblb);
void updateTuioBlob(TuioBlob *tblb);
void removeTuioBlob(TuioBlob *tblb);
void refresh(TuioTime frameTime);
std::vector<TuioCursor*> getInput();
void clearInput();
void unlock() { _mx.unlock(); };
@@ -58,7 +68,7 @@ class TuioEar : public TuioListener {
TuioClient *_tuioClient;
OscReceiver *_oscReceiver;
std::vector<TuioObject*> _list;
std::vector<TuioCursor*> _list;
std::mutex _mx;
};

View File

@@ -39,55 +39,70 @@ namespace {
const std::string _loggerCat = "TuioEar";
}
void TuioEar::tuioAdd(TuioObject *tobj) {
if (tobj->containsNewTuioPointer()) {
_mx.lock();
_list.push_back(tobj);
void TuioEar::addTuioObject(TuioObject *tobj) {
//std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/" << tobj->getTuioSourceID() << ") " << tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
}
//LINFO("add ptr " << tobj->getTuioPointer()->getSessionID() << ", size: " << _list.size() << "\n");
}
if (tobj->containsNewTuioToken()) LINFO("add tok " << tobj->getTuioToken()->getSessionID() << "\n");
if(tobj->containsNewTuioBounds()) LINFO("add bnd " << tobj->getTuioBounds()->getSessionID() << "\n");
if(tobj->containsNewTuioSymbol()) LINFO("add sym " << tobj->getTuioSymbol()->getSessionID() << "\n");
//std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/"<< tobj->getTuioSourceID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
void TuioEar::updateTuioObject(TuioObject *tobj) {
//std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/" << tobj->getTuioSourceID() << ") " << tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
//<< " " << tobj->getMotionSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
}
void TuioEar::removeTuioObject(TuioObject *tobj) {
//std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/" << tobj->getTuioSourceID() << ")" << std::endl;
}
void TuioEar::addTuioCursor(TuioCursor *tcur) {
_mx.lock();
_list.push_back(new TuioCursor(tcur));
_mx.unlock();
//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";
}
void TuioEar::tuioUpdate(TuioObject *tobj) {
if (tobj->containsTuioPointer()) {
_mx.lock();
_list.push_back(tobj);
//LINFO("set ptr " << tobj->getTuioPointer()->getSessionID() << ", size: " << _list.size() << "\n");
}
if (tobj->containsTuioToken()) LINFO("set tok " << tobj->getTuioToken()->getSessionID() << "\n");
if (tobj->containsTuioBounds()) LINFO("set bnd " << tobj->getTuioBounds()->getSessionID() << "\n");
if (tobj->containsTuioSymbol()) LINFO("set sym " << tobj->getTuioSymbol()->getSessionID() << "\n");
//std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/"<< tobj->getTuioSourceID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << " " << tobj->getMotionSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
void TuioEar::updateTuioCursor(TuioCursor *tcur) {
_mx.lock();
_list.push_back(new TuioCursor(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";
}
void TuioEar::tuioRemove(TuioObject *tobj) {
if (tobj->containsTuioPointer()) {
LINFO("del ptr " << tobj->getTuioPointer()->getSessionID() << ", size: " << _list.size() << "\n");
}
if (tobj->containsTuioToken()) LINFO("del tok " << tobj->getTuioToken()->getSessionID() << "\n");
if (tobj->containsTuioBounds()) LINFO("del bnd " << tobj->getTuioBounds()->getSessionID() << "\n");
if (tobj->containsTuioSymbol()) LINFO("del sym " << tobj->getTuioSymbol()->getSessionID() << "\n");
//std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/"<< tobj->getTuioSourceID() << ")" << std::endl;
void TuioEar::removeTuioCursor(TuioCursor *tcur) {
//std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << "/" << tcur->getTuioSourceID() << ")" << std::endl;
}
void TuioEar::tuioRefresh(TuioTime frameTime) {
//LINFO("refresh " << frameTime.getFrameID() << " "<< frameTime.getTotalMilliseconds() << "\n");
void TuioEar::addTuioBlob(TuioBlob *tblb) {
std::cout << "add blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << "/" << tblb->getTuioSourceID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea() << std::endl;
}
std::vector<TuioObject*> TuioEar::getInput() {
void TuioEar::updateTuioBlob(TuioBlob *tblb) {
std::cout << "set blb " << tblb->getBlobID() << " (" << tblb->getSessionID() << "/" << tblb->getTuioSourceID() << ") " << tblb->getX() << " " << tblb->getY() << " " << tblb->getAngle() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getArea()
<< " " << tblb->getMotionSpeed() << " " << tblb->getRotationSpeed() << " " << tblb->getMotionAccel() << " " << tblb->getRotationAccel() << std::endl;
}
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();
return _list;
}
void TuioEar::clearInput() {
_mx.lock();
for (auto &&j : _list) {
delete j;
}
_list.clear();
_mx.unlock();
}

View File

@@ -67,21 +67,25 @@ TouchModule::TouchModule()
OsEng.registerModuleCallback( // maybe call ear->clearInput() here rather than postdraw
OpenSpaceEngine::CallbackOption::PreSync,
[&]() {
std::vector<TuioObject*> list = ear->getInput();
std::vector<TuioObject*> group;
std::vector<TuioCursor*> list = ear->getInput();
std::vector<TuioCursor*> group;
glm::vec2 centroid;
ear->unlock();
std::string s = "";
//print list for debugging
std::string s = "";
const std::string _loggerCat = "TouchModule";
std::ostringstream os;
for (auto &&j : list) {
os << " (" << j->getTuioPointer()->getX() << "," << j->getTuioPointer()->getY() << ") ";
os << " (" << j->getX() << "," << j->getY() << ") ";
}
if (list.size() > 0)
LINFO("List size: " << list.size() << 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;
@@ -104,7 +108,7 @@ TouchModule::TouchModule()
}
}
}*/
//if (centroid.x + centroid.y != 0.0f)
//LINFO("List size: " << list.size() << ", Centroid: (" << centroid.x << ", " << centroid.y << ")\n");
@@ -117,7 +121,7 @@ TouchModule::TouchModule()
[&]() {
WindowWrapper& wrapper = OsEng.windowWrapper();
if (OsEng.isMaster() && wrapper.isRegularRendering()) {
ear->clearInput();
}
}
);