root / branches / test / CCV_Select_Camera / addons / ofxNCore / src / MultiCams / CamsUtils.cpp @ 68
View | Annotate | Download (5.1 KB)
| 1 | //! CamsUtils.cpp
|
|---|---|
| 2 | /*!
|
| 3 | * |
| 4 | * |
| 5 | * Created by Yishi Guo on 06/13/2011. |
| 6 | * Copyright 2011 NUI Group. All rights reserved. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | // ----------------------------------------------
|
| 11 | |
| 12 | #include "CamsUtils.h" |
| 13 | |
| 14 | // ----------------------------------------------
|
| 15 | |
| 16 | CamsUtils::CamsUtils() {
|
| 17 | displayCams = NULL;
|
| 18 | rawCams = NULL;
|
| 19 | camCount = 0;
|
| 20 | |
| 21 | camsUsed = NULL;
|
| 22 | } |
| 23 | |
| 24 | // ----------------------------------------------
|
| 25 | |
| 26 | CamsUtils::~CamsUtils() {
|
| 27 | if ( rawCams != NULL ) { |
| 28 | stop(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // ----------------------------------------------
|
| 33 | |
| 34 | void CamsUtils::setup( CLEyeCameraColorMode colorMode, CLEyeCameraResolution camRes, float frameRate ) { |
| 35 | this->camCount = getDevicesCount(); |
| 36 | if ( camCount <= 0 ) { |
| 37 | return;
|
| 38 | } |
| 39 | |
| 40 | this->colorMode = colorMode; |
| 41 | this->camRes = camRes; |
| 42 | this->frameRate = frameRate; |
| 43 | |
| 44 | rawCams = new PS3*[camCount]; |
| 45 | //! init the bool array.
|
| 46 | camsSelected = new bool[camCount];
|
| 47 | for ( int i = 0; i < camCount; ++i ) { |
| 48 | camsSelected[i] = false;
|
| 49 | } |
| 50 | |
| 51 | start(); |
| 52 | } |
| 53 | |
| 54 | // ----------------------------------------------
|
| 55 | |
| 56 | void CamsUtils::update() {
|
| 57 | for ( int i = 0; i < camCount; ++i ) { |
| 58 | //printf( "CamsUtils::update()\t i = %d\n", i );
|
| 59 | bool newF = rawCams[i]->IsFrameNew();
|
| 60 | //printf( "CamsUtils::update()\t new = %d\n", newF );
|
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // ----------------------------------------------
|
| 65 | void CamsUtils::start() {
|
| 66 | //! init each camera.
|
| 67 | for ( int i = 0; i < camCount; ++i ) { |
| 68 | GUID guid = getGUID( i ); |
| 69 | |
| 70 | rawCams[i] = new PS3(); |
| 71 | rawCams[i]->SetCamera( guid, colorMode, camRes, frameRate ); |
| 72 | if ( rawCams[i]->StartCamera() ) {
|
| 73 | //printf( "rawCams[%d]->StartCamera() return true\n", i );
|
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | // ----------------------------------------------
|
| 78 | |
| 79 | void CamsUtils::stop() {
|
| 80 | if ( rawCams != NULL ) { |
| 81 | for ( int i = 0; i < camCount; ++i ) { |
| 82 | rawCams[i]->StopCamera(); |
| 83 | delete rawCams[i]; |
| 84 | rawCams[i] = NULL;
|
| 85 | } |
| 86 | delete rawCams; |
| 87 | rawCams = NULL;
|
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // ----------------------------------------------
|
| 92 | |
| 93 | int CamsUtils::getCount() {
|
| 94 | return camCount;
|
| 95 | } |
| 96 | |
| 97 | // ----------------------------------------------
|
| 98 | |
| 99 | int CamsUtils::getXGrid() {
|
| 100 | return xGrid;
|
| 101 | } |
| 102 | |
| 103 | // ----------------------------------------------
|
| 104 | |
| 105 | int CamsUtils::getYGrid() {
|
| 106 | return yGrid;
|
| 107 | } |
| 108 | |
| 109 | // ----------------------------------------------
|
| 110 | |
| 111 | PS3* CamsUtils::getCam( int index ) {
|
| 112 | if ( displayCams != NULL && xGrid * yGrid > index) { |
| 113 | // TODO
|
| 114 | return displayCams[index];
|
| 115 | } |
| 116 | |
| 117 | return NULL; // error |
| 118 | } |
| 119 | |
| 120 | // ----------------------------------------------
|
| 121 | |
| 122 | PS3* CamsUtils::getCam( int x, int y ) { |
| 123 | int index = x + xGrid * y;
|
| 124 | |
| 125 | return getCam( index );
|
| 126 | } |
| 127 | |
| 128 | // ----------------------------------------------
|
| 129 | |
| 130 | PS3* CamsUtils::getRawCam( int index ) {
|
| 131 | if ( rawCams != NULL && camCount > index && index >= 0 ) { //! index can not less than 0 |
| 132 | //printf( "CamsUtils::getRawCam()\t return\n" );
|
| 133 | return rawCams[index];
|
| 134 | } |
| 135 | |
| 136 | return NULL; |
| 137 | } |
| 138 | |
| 139 | // ----------------------------------------------
|
| 140 | |
| 141 | PS3** CamsUtils::getCams() {
|
| 142 | return displayCams;
|
| 143 | } |
| 144 | |
| 145 | // ----------------------------------------------
|
| 146 | |
| 147 | PS3** CamsUtils::getRawCams() {
|
| 148 | return rawCams;
|
| 149 | } |
| 150 | |
| 151 | // ----------------------------------------------
|
| 152 | |
| 153 | bool CamsUtils::isSelected( int rawId ) { |
| 154 | return camsSelected[rawId];
|
| 155 | } |
| 156 | |
| 157 | // ----------------------------------------------
|
| 158 | |
| 159 | void CamsUtils::setSelected( int rawId ) { |
| 160 | camsSelected[rawId] = true;
|
| 161 | } |
| 162 | |
| 163 | // ----------------------------------------------
|
| 164 | |
| 165 | bool CamsUtils::isUsed( int displayId ) { |
| 166 | return camsUsed[displayId];
|
| 167 | } |
| 168 | |
| 169 | // ----------------------------------------------
|
| 170 | |
| 171 | void CamsUtils::setXY( int x, int y ) { |
| 172 | this->xGrid = x; |
| 173 | this->yGrid = y; |
| 174 | createDisplayCams( xGrid, yGrid ); |
| 175 | } |
| 176 | |
| 177 | // ----------------------------------------------
|
| 178 | |
| 179 | void CamsUtils::setCam( int index, PS3* cam ) { |
| 180 | if ( cam == NULL ) { |
| 181 | return;
|
| 182 | } |
| 183 | displayCams[index] = cam; |
| 184 | camsUsed[index] = true;
|
| 185 | } |
| 186 | |
| 187 | // ----------------------------------------------
|
| 188 | |
| 189 | void CamsUtils::setCam( int x, int y, PS3* cam ) { |
| 190 | if ( cam == NULL ) { |
| 191 | return;
|
| 192 | } |
| 193 | int index = x + xGrid * y;
|
| 194 | setCam( index, cam ); |
| 195 | } |
| 196 | |
| 197 | // ----------------------------------------------
|
| 198 | |
| 199 | void CamsUtils::resetAll() {
|
| 200 | //! Set X/Y as reset all
|
| 201 | setXY( xGrid, yGrid ); |
| 202 | |
| 203 | //! Clean up selected cams
|
| 204 | for ( int i = 0; i < xGrid * yGrid; ++i ) { |
| 205 | camsSelected[i] = false;
|
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // ----------------------------------------------
|
| 210 | |
| 211 | void CamsUtils::saveXML( string filename ) {
|
| 212 | // TODO
|
| 213 | } |
| 214 | |
| 215 | // ----------------------------------------------
|
| 216 | |
| 217 | int CamsUtils::getDevicesCount() {
|
| 218 | return CLEyeGetCameraCount();
|
| 219 | } |
| 220 | |
| 221 | // ----------------------------------------------
|
| 222 | |
| 223 | GUID CamsUtils::getGUID( int camId ) {
|
| 224 | return CLEyeGetCameraUUID( camId );
|
| 225 | } |
| 226 | |
| 227 | // ----------------------------------------------
|
| 228 | |
| 229 | void CamsUtils::createDisplayCams( int x, int y ) { |
| 230 | printf( "\nCamsUtils::createDisplayCams()\n" );
|
| 231 | int count = x * y;
|
| 232 | |
| 233 | if ( displayCams != NULL ) { |
| 234 | delete displayCams; |
| 235 | } |
| 236 | displayCams = new PS3*[count]; |
| 237 | for ( int i = 0; i < count; ++i ) { |
| 238 | displayCams[i] = NULL;
|
| 239 | } |
| 240 | |
| 241 | //! for camsUsed array
|
| 242 | if ( camsUsed != NULL ) { |
| 243 | delete camsUsed; |
| 244 | } |
| 245 | camsUsed = new bool[count];
|
| 246 | for ( int i = 0; i < count; ++i ) { |
| 247 | camsUsed[i] = false;
|
| 248 | printf( "\ncamsUsed[%d]=%d\n", i, camsUsed[i] );
|
| 249 | } |
| 250 | |
| 251 | printf( "\nCamsUtils::createDisplayCams()\tx=%d, y=%d\n", x, y );
|
| 252 | } |
| 253 | |
| 254 | // ---------------------------------------------- |
