Index: include/CBlobTracker.h =================================================================== --- include/CBlobTracker.h (revision 3) +++ include/CBlobTracker.h (working copy) @@ -146,7 +146,9 @@ std::vector > history; std::vector blobList; std::vector equivalences; + public: std::vector current; + private: std::vector listenerList; #ifdef WIN32 Index: include/CvCaptureFilter.h =================================================================== --- include/CvCaptureFilter.h (revision 3) +++ include/CvCaptureFilter.h (working copy) @@ -8,8 +8,13 @@ #include #include #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#elif defined(__APPLE__) + +#endif + // FIXME: we should put this in a namespace class TOUCHLIB_FILTER_EXPORT CvCaptureFilter : public Filter @@ -18,7 +23,7 @@ static CvCapture* capture; static void acquireImage(void *param); static IplImage* acquiredImage; - static HANDLE hThread; + //static HANDLE hThread; char source[255]; public: CvCaptureFilter(char*); Index: include/CaptureFilter.h =================================================================== --- include/CaptureFilter.h (revision 3) +++ include/CaptureFilter.h (working copy) @@ -8,8 +8,13 @@ #include #include #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#elif defined(__APPLE__) + +#endif + // FIXME: we should put this in a namespace class TOUCHLIB_FILTER_EXPORT CaptureFilter : public Filter @@ -18,7 +23,7 @@ static CvCapture* capture; static void acquireImage(void *param); static IplImage* acquiredImage; - static HANDLE hThread; + //static HANDLE hThread; char source[255]; public: CaptureFilter(char*); Index: include/mesh2d.h =================================================================== --- include/mesh2d.h (revision 3) +++ include/mesh2d.h (working copy) @@ -149,7 +149,7 @@ void getBarycentricCoords(vector2d pt, int tri_ind, float &bary_A, float &bary_B, float &bary_C) { vector2d pt_local; - pt_local = p - position; + pt_local = pt - position; pt_local.rotateBy(-rotation, vector2d(0,0)); pt_local /= scale; Index: include/CTouchScreen.h =================================================================== --- include/CTouchScreen.h (revision 3) +++ include/CTouchScreen.h (working copy) @@ -5,8 +5,14 @@ #include "CBlobTracker.h" #include "ITouchEvent.h" #include "Filter.h" -#include -#include + +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include + #include +#elif defined(__APPLE__) + #include +#endif + #include "ITouchListener.h" #include "mesh2d.h" @@ -96,7 +102,11 @@ ////////// +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) static void _processEntryPoint(void *obj); +#elif defined(__APPLE__) + static void* _processEntryPoint(void *obj); +#endif void cameraToScreenSpace(float &x, float &y); @@ -116,8 +126,13 @@ bool debugMode; bool volatile bTracking; +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) static HANDLE hThread; static HANDLE eventListMutex; +#elif defined(__APPLE__) + static pthread_t hThread; + static pthread_mutex_t eventListMutex; +#endif CBlobTracker tracker; Index: include/VideoWrapperFilter.h =================================================================== --- include/VideoWrapperFilter.h (revision 3) +++ include/VideoWrapperFilter.h (working copy) @@ -3,11 +3,13 @@ #include -#include -#include -#include -#include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include + #include + #include + #include + #include +#endif #include Index: include/vector2d.h =================================================================== --- include/vector2d.h (revision 3) +++ include/vector2d.h (working copy) @@ -222,7 +222,7 @@ static bool isOnSameSide(vector2d p1, vector2d p2, vector2d a, vector2d b) { - vector2df ba = b - a; + vector2d ba = b - a; float cp1 = ba.crossProduct(p1-a); float cp2 = ba.crossProduct(p2-a); Index: src/CvCaptureFilter.cpp =================================================================== --- src/CvCaptureFilter.cpp (revision 3) +++ src/CvCaptureFilter.cpp (working copy) @@ -1,6 +1,8 @@ #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#endif #include #include @@ -8,7 +10,7 @@ CvCapture * CvCaptureFilter::capture = 0; IplImage* CvCaptureFilter::acquiredImage = 0; -HANDLE CvCaptureFilter::hThread = 0; +//HANDLE CvCaptureFilter::hThread = 0; CvCaptureFilter::CvCaptureFilter(char* s) : Filter(s) { @@ -71,9 +73,12 @@ if(strcmp(value, "cam") == 0) { capture = cvCaptureFromCAM( CV_CAP_ANY ); - //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640); - //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480); +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH_HEIGHT, 640480); +#elif defined(__APPLE__) + cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640); + cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480); +#endif cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 30); Index: src/configapp.cpp =================================================================== --- src/configapp.cpp (revision 3) +++ src/configapp.cpp (working copy) @@ -1,20 +1,25 @@ -#pragma once -#define WIN32_LEAN_AND_MEAN -#define _WIN32_WINNT 0x0500 -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #pragma once + #define WIN32_LEAN_AND_MEAN + #define _WIN32_WINNT 0x0500 + #include + #include + + #include "glut.h" + + #pragma comment( lib, "glut32" ) + #pragma comment( lib, "user32" ) +#elif defined(__APPLE__) + #include +#endif + #include #include #include #include -#include - -#include "glut.h" -#pragma comment( lib, "glut32" ) -#pragma comment( lib, "user32" ) - #include "TouchScreenDevice.h" #include "TouchData.h" @@ -22,7 +27,9 @@ #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#endif void glutDrawBox(float x1, float y1, float x2, float y2, float r, float g, float b); void glutDrawPlus(float x1, float y1, float s, float r, float g, float b); @@ -121,6 +128,7 @@ if(curcalib == -1) { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) INPUT aInput; aInput.type = INPUT_MOUSE; @@ -132,6 +140,7 @@ aInput.mi.dy = ((1.0f - data.Y) * 65535.0f); int aResult = SendInput(1, &aInput, sizeof(INPUT) ); +#endif } } @@ -142,6 +151,7 @@ if(curcalib == -1) { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) INPUT aInput; aInput.type = INPUT_MOUSE; @@ -153,6 +163,7 @@ aInput.mi.dy = ((1.0f - data.Y) * 65535.0f); int aResult = SendInput(1, &aInput, sizeof(INPUT) ); +#endif } } @@ -172,6 +183,7 @@ if(curcalib == -1) { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) INPUT aInput; aInput.type = INPUT_MOUSE; @@ -180,6 +192,7 @@ aInput.mi.mouseData = 0; aInput.mi.time = 0; int aResult = SendInput(1, &aInput, sizeof(INPUT) ); +#endif } } @@ -352,13 +365,21 @@ glutMainLoop(); } +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) int _tmain(int argc, char * argv[]) +#elif defined(__APPLE__) +int main(int argc, char * argv[]) +#endif { screen = TouchScreenDevice::getTouchScreen(); if(!screen->loadConfig("config.xml")) { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) screen->pushFilter("dsvlcapture", "capture1"); +#elif defined(__APPLE__) + screen->pushFilter("cvcapture", "capture1"); +#endif screen->pushFilter("mono", "mono2"); screen->pushFilter("smooth", "smooth3"); screen->pushFilter("backgroundremove", "background4"); @@ -369,7 +390,7 @@ screen->setParameter("rectify6", "level", "25"); screen->setParameter("capture1", "source", "cam"); - //screen->setParameter("capture1", "source", "../tests/simple-2point.avi"); + //screen->setParameter("capture1", "source", "/Users/dan/Projects/touchlib/tests/simple-2point.avi"); //screen->setParameter("capture1", "source", "../tests/hard-5point.avi"); screen->setParameter("bc5", "brightness", "0.1"); @@ -381,10 +402,11 @@ screen->registerListener((ITouchListener *)&app); // Note: Begin processing should only be called after the screen is set up - screen->beginProcessing(); + //screen->beginProcessing(); do { + screen->process(); int keypressed = cvWaitKey(32) & 255; Index: src/CaptureFilter.cpp =================================================================== --- src/CaptureFilter.cpp (revision 3) +++ src/CaptureFilter.cpp (working copy) @@ -1,14 +1,17 @@ #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#endif + #include #include #include CvCapture * CaptureFilter::capture = 0; IplImage* CaptureFilter::acquiredImage = 0; -HANDLE CaptureFilter::hThread = 0; +//HANDLE CaptureFilter::hThread = 0; CaptureFilter::CaptureFilter(char* s) : Filter(s) { Index: src/VideoWrapperFilter.cpp =================================================================== --- src/VideoWrapperFilter.cpp (revision 3) +++ src/VideoWrapperFilter.cpp (working copy) @@ -4,7 +4,11 @@ VideoWrapperFilter::VideoWrapperFilter(char *s) : Filter(s) { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) strcpy(videostring, "vc: 0 320 30 I420 1"); +#elif defined(__APPLE__) + strcpy(videostring, "qt: 0 640 30 rgb 0"); +#endif g_hVideo = 0; destination = NULL; Index: src/FilterFactory.cpp =================================================================== --- src/FilterFactory.cpp (revision 3) +++ src/FilterFactory.cpp (working copy) @@ -2,8 +2,10 @@ #include "CvCaptureFilter.h" //#include "DsCaptureFilter.h" -#include "VideoWrapperFilter.h" -#include "DSVLCaptureFilter.h" +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include "VideoWrapperFilter.h" + #include "DSVLCaptureFilter.h" +#endif #include "BrightnessContrastFilter.h" #include "MonoFilter.h" @@ -25,10 +27,12 @@ if(strcmp(type, "cvcapture") == 0) { newFilter = (Filter *)new CvCaptureFilter((char*)label); +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) } else if(strcmp(type, "vwcapture") == 0) { newFilter = (Filter *)new VideoWrapperFilter((char*)label); } else if(strcmp(type, "dsvlcapture") == 0) { newFilter = (Filter *)new DSVLCaptureFilter((char*)label); +#endif } else if(strcmp(type, "mono") == 0) { newFilter = (Filter *)new MonoFilter((char*)label); } else if(strcmp(type, "rectify") == 0) { Index: src/MonoFilter.cpp =================================================================== --- src/MonoFilter.cpp (revision 3) +++ src/MonoFilter.cpp (working copy) @@ -31,11 +31,11 @@ // Note: the destination must have one channel. if(source->nChannels != 1 && destination->nChannels == 1) { - if(strcmpi(source->colorModel, "BGRA") == 0) + if(strcasecmp(source->colorModel, "BGRA") == 0) cvCvtColor(source, destination, CV_BGRA2GRAY); - else if(strcmpi(source->colorModel, "BGR") == 0) + else if(strcasecmp(source->colorModel, "BGR") == 0) cvCvtColor(source, destination, CV_BGR2GRAY); - else if(strcmpi(source->colorModel, "RGB") == 0) + else if(strcasecmp(source->colorModel, "RGB") == 0) cvCvtColor(source, destination, CV_RGB2GRAY); Index: src/test.cpp =================================================================== --- src/test.cpp (revision 3) +++ src/test.cpp (working copy) @@ -5,7 +5,9 @@ #include #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#endif #define RECTIFY_LEVEL 40 @@ -15,14 +17,15 @@ #include - -using namespace touchscreen; - - IplImage *src_image = 0, *dst_image = 0; +using namespace touchlib; +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) int _tmain(int argc, _TCHAR* argv[]) +#elif defined(__APPLE__) +int main(int argc, char* argv[]) +#endif { // NOTE: just uncomment this line in order to get the capture from the webcam //CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY ); Index: src/sampleapp.cpp =================================================================== --- src/sampleapp.cpp (revision 3) +++ src/sampleapp.cpp (working copy) @@ -2,9 +2,10 @@ #include #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#endif - #include "TouchScreenDevice.h" using namespace touchlib; @@ -101,8 +102,11 @@ IplImage *window_img; }; - +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) int _tmain(int argc, _TCHAR* argv[]) +#elif defined(__APPLE__) +int main(int argc, char* argv[]) +#endif { // FIXME: in the future we will call a static method on TouchScreenDevice // in order to get an ITouchScreen (singleton pattern) as opposed to directly @@ -115,7 +119,11 @@ char* configFileName = "config.xml"; if(!screen->loadConfig(configFileName)) { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) screen->pushFilter("capture", "capture1"); +#elif defined(__APPLE__) + screen->pushFilter("cvcapture", "capture1"); +#endif screen->pushFilter("mono", "mono2"); screen->pushFilter("smooth", "smooth3"); screen->pushFilter("backgroundremove", "background4"); @@ -125,8 +133,8 @@ screen->setParameter("rectify6", "level", "25"); - //screen->setParameter("capture1", "source", "cam"); - screen->setParameter("capture1", "source", "../tests/simple-2point.avi"); + screen->setParameter("capture1", "source", "cam"); + //screen->setParameter("capture1", "source", "../tests/simple-2point.avi"); //screen->setParameter("capture1", "source", "../tests/hard-5point.avi"); screen->setParameter("bc5", "brightness", "0.1"); @@ -138,11 +146,13 @@ screen->registerListener((ITouchListener *)&app); // Note: Begin processing should only be called after the screen is set up - screen->beginProcessing(); + //screen->beginProcessing(); bool ok=true; do { + screen->process(); + screen->getEvents(); app.draw(); //printf("*"); Index: src/touchtest.cpp =================================================================== --- src/touchtest.cpp (revision 3) +++ src/touchtest.cpp (working copy) @@ -2,9 +2,10 @@ #include #include -#include +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + #include +#endif - #include "TouchScreenDevice.h" using namespace touchlib; @@ -101,8 +102,11 @@ IplImage *window_img; }; - +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) int _tmain(int argc, _TCHAR* argv[]) +#else +int main(int argc, char* argv[]) +#endif { // FIXME: in the future we will call a static method on TouchScreenDevice // in order to get an ITouchScreen (singleton pattern) as opposed to directly Index: src/CTouchScreen.cpp =================================================================== --- src/CTouchScreen.cpp (revision 3) +++ src/CTouchScreen.cpp (working copy) @@ -1,13 +1,19 @@ #include "CTouchScreen.h" #include "FilterFactory.h" -#include "process.h" #include "tinyxml.h" +#include + using namespace touchlib; -HANDLE CTouchScreen::hThread = 0; -HANDLE CTouchScreen::eventListMutex = 0; +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) + HANDLE CTouchScreen::hThread = 0; + HANDLE CTouchScreen::eventListMutex = 0; +#elif defined(__APPLE__) + pthread_t CTouchScreen::hThread; + pthread_mutex_t CTouchScreen::eventListMutex; +#endif // FIXME: Maybe some of this calibration stuff should be moved to the config app // Let the config app collect the points and set them en-masse..? @@ -18,15 +24,19 @@ tracker.registerListener((ITouchListener *)this); +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) eventListMutex = CreateMutex(NULL, 0, NULL); +#elif defined(__APPLE__) + pthread_mutex_init(&eventListMutex, NULL); +#endif screenScale = 0.75; initScreenPoints(); initCameraPoints(); - debugMode = true; - bTracking = false; + debugMode = false; + bTracking = true; screenMesh.recalcBoundingBox(); @@ -60,8 +70,15 @@ { unsigned int i; +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) if(hThread) TerminateThread(hThread, 0); +#elif defined(__APPLE__) + if(hThread) + pthread_cancel(hThread); + + pthread_mutex_destroy(&eventListMutex); +#endif for(i=0; iprocess(); } - void CTouchScreen::beginProcessing() { +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) hThread = (HANDLE)_beginthread(_processEntryPoint, 0, this); +#elif defined(__APPLE__) + pthread_create(&hThread, NULL, _processEntryPoint, this); +#endif } void CTouchScreen::getEvents() { unsigned int i=0; + +#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) DWORD dw = WaitForSingleObject(eventListMutex, INFINITE); // dw == WAIT_OBJECT_0 @@ -537,31 +576,34 @@ // handle time-out error //throw TimeoutExcp(); return; + } +#elif defined(__APPLE__) + pthread_mutex_lock(&eventListMutex); +#endif - } else { - - for(i=0; i