~noskcaj/ubuntu/saucy/openwalnut/liberation

« back to all changes in this revision

Viewing changes to .pc/boost153/src/modules/openIGTLink/WIGTLinkRemote.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-05-24 03:12:03 UTC
  • Revision ID: package-import@ubuntu.com-20130524031203-l5g1lzm1vd83fupi
Tags: 1.3.1+hg5849-1ubuntu1
Cherrypick boost1.53 pointer cast fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
10
// OpenWalnut is free software: you can redistribute it and/or modify
 
11
// it under the terms of the GNU Lesser General Public License as published by
 
12
// the Free Software Foundation, either version 3 of the License, or
 
13
// (at your option) any later version.
 
14
//
 
15
// OpenWalnut is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
// GNU Lesser General Public License for more details.
 
19
//
 
20
// You should have received a copy of the GNU Lesser General Public License
 
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#include <iostream>
 
26
#include <string>
 
27
#include <vector>
 
28
 
 
29
#include "WIGTLinkRemote.h"
 
30
 
 
31
#include "core/dataHandler/WDataSet.h"
 
32
#include "core/dataHandler/WValueSet.h"
 
33
#include "core/dataHandler/WGridRegular3D.h"
 
34
#include "core/dataHandler/WDataSetScalar.h"
 
35
#include "core/common/WIOTools.h"
 
36
#include "core/common/WLogger.h"
 
37
 
 
38
#include "igtlOSUtil.h"
 
39
#include "igtlImageMessage.h"
 
40
#include "igtlImageMetaMessage.h"
 
41
#include "igtlServerSocket.h"
 
42
#include "igtlTransformMessage.h"
 
43
 
 
44
WIGTLinkRemote::WIGTLinkRemote()
 
45
    : checkCRC( false ), port( 0 )
 
46
{
 
47
    receiversCondition.reset( new WCondition );
 
48
    statusCondition.reset( new WCondition );
 
49
}
 
50
 
 
51
WIGTLinkRemote::~WIGTLinkRemote()
 
52
{
 
53
    receiversMutex.lock();
 
54
    //receiveQueue.clear();
 
55
    receiversCondition->notify();
 
56
    receiversMutex.unlock();
 
57
    if( socket.IsNotNull() )
 
58
    {
 
59
        socket->CloseSocket();
 
60
    }
 
61
}
 
62
 
 
63
void WIGTLinkRemote::createSocketAndWaitForConnection( uint32_t port )
 
64
{
 
65
    this->port = port;
 
66
}
 
67
 
 
68
void WIGTLinkRemote::createSocketAndConnect( std::string hostname, uint32_t port )
 
69
{
 
70
    std::cout << "setting up connection to: \"" <<  hostname << ":" <<  port <<  "\"" << std::endl;
 
71
    this->port = 0;
 
72
    socket = igtl::ClientSocket::New();
 
73
    int r =  socket->ConnectToServer( hostname.c_str(), port );
 
74
    if( r != 0 )
 
75
    {
 
76
        throw WException( "Cannot connect to server" );
 
77
    }
 
78
    std::cout << "connection established" <<  std::endl;
 
79
    statusCondition->notify(); // link established
 
80
}
 
81
 
 
82
void WIGTLinkRemote::threadMain()
 
83
{
 
84
    readDataLoop();
 
85
}
 
86
 
 
87
void WIGTLinkRemote::listenLoop()
 
88
{
 
89
    igtl::ServerSocket::Pointer serverSocket;
 
90
    serverSocket = igtl::ServerSocket::New();
 
91
    serverSocket->CreateServer( port );
 
92
 
 
93
    // wait for connection
 
94
    while( !m_shutdownFlag() && socket.IsNull() )
 
95
    {
 
96
        socket = serverSocket->WaitForConnection( 2000 );
 
97
    }
 
98
    if( !m_shutdownFlag() && socket.IsNotNull() )
 
99
    {
 
100
        statusCondition->notify(); // passive connection established
 
101
    }
 
102
}
 
103
 
 
104
void WIGTLinkRemote::readDataLoop()
 
105
{
 
106
    igtl::MessageHeader::Pointer headerMsg;
 
107
    headerMsg = igtl::MessageHeader::New();
 
108
 
 
109
    headerMsg->InitPack();
 
110
 
 
111
    if( port > 0 )
 
112
    {
 
113
        listenLoop();
 
114
    }
 
115
 
 
116
    WAssert( socket.IsNotNull(), "Something failed when setting up the socket" );
 
117
 
 
118
    while( !m_shutdownFlag() )
 
119
    {
 
120
        try
 
121
        {
 
122
            std::cout << "Waiting for data." <<  std::endl;
 
123
            int r = socket->Receive( headerMsg->GetPackPointer(), headerMsg->GetPackSize() );
 
124
            if( r == 0 )
 
125
            {
 
126
                // socket failed!!!
 
127
                throw WException( "Socket Failed" );
 
128
            }
 
129
            std::cout << "got something." <<  std::endl;
 
130
 
 
131
            if( r !=  headerMsg->GetPackSize() )
 
132
            {
 
133
                throw WException( "Invalid data size" );
 
134
            }
 
135
 
 
136
            // deserialize the header
 
137
            headerMsg->Unpack( checkCRC ? 1:0 );
 
138
 
 
139
            // check data type
 
140
            if( strcmp( headerMsg->GetDeviceType(), "TRANSFORM" ) == 0 )
 
141
            {
 
142
                //debugLog() << "Received TRANSFORM";
 
143
                receiveTransform( headerMsg );
 
144
            }
 
145
            else if( strcmp( headerMsg->GetDeviceType(), "IMAGE" ) == 0 )
 
146
            {
 
147
                std::cout << "got an image!!!" << std::endl;
 
148
                WDataSetScalarSPtr ds = receiveImage( headerMsg );
 
149
                receiversMutex.lock();
 
150
                receiveQueue.push( ds );
 
151
                receiversCondition->notify();
 
152
                receiversMutex.unlock();
 
153
            }
 
154
            else if( strcmp( headerMsg->GetDeviceType(), "POSITION" ) ==  0 )
 
155
            {
 
156
                //readPosition( headerMsg );
 
157
                socket->Skip( headerMsg->GetBodySizeToRead(), 0 );
 
158
            }
 
159
            else if( strcmp( headerMsg->GetDeviceType(), "STATUS" ) == 0 )
 
160
            {
 
161
                //readStatus( headerMsg );
 
162
                socket->Skip( headerMsg->GetBodySizeToRead(), 0 );
 
163
            }
 
164
            else
 
165
            {
 
166
                //debugLog() << "Unknown header received";
 
167
                socket->Skip( headerMsg->GetBodySizeToRead(), 0 );
 
168
            }
 
169
        }
 
170
        catch( const std::exception &e )
 
171
        {
 
172
            if( socket.IsNotNull() )
 
173
            {
 
174
                socket->CloseSocket();
 
175
            }
 
176
            if( port == 0 )
 
177
            {
 
178
                // we are in client mode and the connection failed
 
179
                // notify the main program and quit this thread
 
180
                // we have to start a new connection if this happens
 
181
                throw e;
 
182
            }
 
183
            else
 
184
            {
 
185
                // just continue listening
 
186
                socket = igtl::ClientSocket::Pointer();
 
187
                listenLoop();
 
188
            }
 
189
        }
 
190
    }
 
191
}
 
192
 
 
193
void WIGTLinkRemote::receiveTransform( igtl::MessageHeader::Pointer headerMsg )
 
194
{
 
195
    // TODO(mario): OpenWalnut needs a nice interface for transforms to display tracking devices etc
 
196
 
 
197
    // message body handler for transform
 
198
    igtl::TransformMessage::Pointer transMsg;
 
199
    transMsg =  igtl::TransformMessage::New();
 
200
    transMsg->SetMessageHeader( headerMsg );
 
201
    transMsg->AllocatePack();
 
202
 
 
203
    socket->Receive( transMsg->GetPackBodyPointer(), transMsg->GetPackBodySize() );
 
204
 
 
205
    // deserialize the message body
 
206
    int c =  transMsg->Unpack( checkCRC ? 1:0 ); // 1 indicates to perform CRC
 
207
    if( c & igtl::MessageHeader::UNPACK_BODY )
 
208
    {
 
209
        // if CRC check is OK, read transform data
 
210
        igtl::Matrix4x4 matrix;
 
211
        transMsg->GetMatrix( matrix );
 
212
 
 
213
        // TODO(mario): add better debugging
 
214
        igtl::PrintMatrix( matrix );
 
215
    }
 
216
}
 
217
 
 
218
WDataSetScalarSPtr WIGTLinkRemote::receiveImage( igtl::MessageHeader::Pointer headerMsg )
 
219
{
 
220
    igtl::ImageMessage::Pointer imgMsg;
 
221
    imgMsg = igtl::ImageMessage::New();
 
222
    imgMsg->SetMessageHeader( headerMsg );
 
223
    imgMsg->AllocatePack();
 
224
 
 
225
    // receive data from socket
 
226
    socket->Receive( imgMsg->GetPackBodyPointer(), imgMsg->GetPackBodySize() );
 
227
 
 
228
    // deserialize the data
 
229
    int c =  imgMsg->Unpack( checkCRC ? 1:0 ); // 1 stands for do CRC
 
230
 
 
231
    if( c & igtl::MessageHeader::UNPACK_BODY )
 
232
    {
 
233
        int size[ 3 ];
 
234
        float spacing[ 3 ];
 
235
        int svsize[ 3 ];
 
236
        int svoffset[ 3 ];
 
237
        int scalarType;
 
238
        igtl::Matrix4x4 mat;
 
239
 
 
240
        scalarType = imgMsg->GetScalarType();
 
241
        imgMsg->GetDimensions( size );
 
242
        imgMsg->GetSpacing( spacing );
 
243
        imgMsg->GetSubVolume( svsize, svoffset );
 
244
        imgMsg->GetMatrix( mat );
 
245
 
 
246
        WMatrix<double> owmat( 4, 4 );
 
247
        for( int i = 0; i < 4; ++i )
 
248
        {
 
249
            for( int j = 0; j < 4; ++j )
 
250
            {
 
251
                owmat( i, j ) = mat[ i ][ j ];
 
252
            }
 
253
        }
 
254
        WGridRegular3D::SPtr grid( new WGridRegular3D( size[ 0 ], size[ 1 ], size[ 2 ], WGridTransformOrtho( owmat ) ) );
 
255
 
 
256
        boost::shared_ptr< WValueSetBase > valueSet = createValueSet( imgMsg );
 
257
 
 
258
        WDataSetScalarSPtr ds( new WDataSetScalar( valueSet, grid ) );
 
259
        // if( length( imgMsg->GetDeviceName() > 0 ) )
 
260
        // {
 
261
        //    ds->setFilename( imgMsg->GetDeviceName() );
 
262
        // }
 
263
 
 
264
        return ds;
 
265
    }
 
266
    else
 
267
    {
 
268
        std::cerr << "decoding image failed" << std::endl;
 
269
    }
 
270
    return WDataSetScalarSPtr ();
 
271
}
 
272
 
 
273
void WIGTLinkRemote::injectMessage()
 
274
{
 
275
}
 
276
 
 
277
void WIGTLinkRemote::sendTransform( const std::string& name, const WMatrix<double> & matrix )
 
278
{
 
279
    if( socket.IsNotNull() )
 
280
    {
 
281
        igtl::TransformMessage::Pointer transMsg;
 
282
        transMsg = igtl::TransformMessage::New();
 
283
        transMsg->SetDeviceName( name.c_str() );
 
284
        igtl::Matrix4x4 igtlMatrix;
 
285
        for( int i = 0; i < 4; ++i )
 
286
        {
 
287
            for( int j = 0; j < 4; ++j )
 
288
            {
 
289
                igtlMatrix[ i ][ j ] =  matrix( i, j );
 
290
            }
 
291
        }
 
292
        transMsg->SetMatrix( igtlMatrix );
 
293
 
 
294
        transMsg->Pack();
 
295
 
 
296
        socket->Send( transMsg->GetPackPointer(), transMsg->GetPackSize() );
 
297
    }
 
298
}
 
299
 
 
300
namespace
 
301
{
 
302
    int convertTypeOWtoIGTL( int type )
 
303
    {
 
304
        switch( type )
 
305
        {
 
306
            case igtl::ImageMessage::TYPE_INT8:
 
307
                    return W_DT_INT8;
 
308
            case igtl::ImageMessage::TYPE_UINT8:
 
309
                    return W_DT_UINT8;
 
310
            case igtl::ImageMessage::TYPE_INT16:
 
311
                    return W_DT_INT16;
 
312
            case igtl::ImageMessage::TYPE_UINT16:
 
313
                    return W_DT_UINT16;
 
314
            case igtl::ImageMessage::TYPE_INT32:
 
315
                    return W_DT_INT16;
 
316
            case igtl::ImageMessage::TYPE_UINT32:
 
317
                    return W_DT_UINT32;
 
318
            default:
 
319
                // TODO(mario): throw exception?
 
320
                return W_DT_UNKNOWN;
 
321
        }
 
322
    }
 
323
}
 
324
 
 
325
void WIGTLinkRemote::sendImageMetaData( const std::vector < WDataSetScalarSPtr >& dataSets )
 
326
{
 
327
    igtl::ImageMetaMessage::Pointer imgMetaMsg;
 
328
    imgMetaMsg =  igtl::ImageMetaMessage::New();
 
329
 
 
330
    imgMetaMsg->SetDeviceName( "OpenWalnut" );
 
331
 
 
332
    // create meta data for each data set
 
333
    for( size_t i = 0; i < dataSets.size(); ++i )
 
334
    {
 
335
        igtl::ImageMetaElement::Pointer imgMeta;
 
336
        imgMeta = igtl::ImageMetaElement::New();
 
337
        imgMeta->SetName( dataSets[ i ]->getFilename().c_str() );
 
338
        imgMeta->SetDeviceName( dataSets[ i ]->getFilename().c_str() );
 
339
        imgMeta->SetModality( "UNKNOWN_MODALITY" );
 
340
        imgMeta->SetPatientName( dataSets[ i ]->getFilename().c_str() );
 
341
        imgMeta->SetPatientID( "PATIENT_ID_0" );
 
342
 
 
343
        igtl::TimeStamp::Pointer ts0;
 
344
        ts0 = igtl::TimeStamp::New();
 
345
        ts0->SetTime( 123456.78 );
 
346
 
 
347
        imgMeta->SetTimeStamp( ts0 );
 
348
        boost::shared_ptr < WGridRegular3D > g3dr( boost::shared_dynamic_cast < WGridRegular3D > ( dataSets[ i ]->getGrid() ) );
 
349
        imgMeta->SetSize( g3dr->getNbCoordsX(), g3dr->getNbCoordsY(), g3dr->getNbCoordsZ() );
 
350
        imgMeta->SetScalarType( convertTypeOWtoIGTL( dataSets[ i ]->getValueSet()->getDataType() ) );
 
351
        imgMetaMsg->AddImageMetaElement( imgMeta );
 
352
    }
 
353
    imgMetaMsg->Pack();
 
354
 
 
355
    socket->Send( imgMetaMsg->GetPackPointer(), imgMetaMsg->GetPackSize() );
 
356
}
 
357
 
 
358
namespace Ugly
 
359
{
 
360
    template < int DT >
 
361
    size_t getRawSizeT( boost::shared_ptr < WValueSetBase >  valueSet )
 
362
    {
 
363
        typedef typename DataTypeRT<DT>::type type;
 
364
        boost::shared_ptr < WValueSet < type > > v = boost::shared_dynamic_cast < WValueSet < type > >( valueSet );
 
365
        WAssert( v, "Type cast failed" );
 
366
        return valueSet->rawSize() * sizeof( type );
 
367
    }
 
368
 
 
369
    template < int DT >
 
370
    const void* getRawPtrT( boost::shared_ptr < WValueSetBase > valueSet )
 
371
    {
 
372
        typedef typename DataTypeRT<DT>::type type;
 
373
        boost::shared_ptr < WValueSet < type > > v;
 
374
        v = boost::shared_dynamic_cast < WValueSet < type > >( valueSet );
 
375
        WAssert( v, "Type cast failed" );
 
376
        const void* ptr = v->rawData();
 
377
        WAssert( ptr != 0, "Trying to query raw data, got null pointer" );
 
378
        return ptr;
 
379
    }
 
380
 
 
381
    size_t getRawSize( boost::shared_ptr < WValueSetBase > valueSet )
 
382
    {
 
383
        int type = valueSet->getDataType();
 
384
#define CASE( A ) case A: return getRawSizeT < A > ( valueSet );
 
385
        switch( type )
 
386
        {
 
387
            CASE( W_DT_UNSIGNED_CHAR );
 
388
            CASE( W_DT_INT8 );
 
389
            CASE( W_DT_SIGNED_SHORT ); // INT16
 
390
            CASE( W_DT_SIGNED_INT ); // INT32
 
391
            CASE( W_DT_FLOAT );
 
392
            CASE( W_DT_DOUBLE );
 
393
            CASE( W_DT_UINT16 );
 
394
            CASE( W_DT_UINT32 );
 
395
            CASE( W_DT_INT64 );
 
396
            CASE( W_DT_UINT64 );
 
397
            CASE( W_DT_FLOAT128 );
 
398
            default:
 
399
                throw WException( "Not implemented for given data type" );
 
400
        }
 
401
#undef CASE
 
402
    }
 
403
 
 
404
    const void* getRawPtr( boost::shared_ptr < WValueSetBase > valueSet )
 
405
    {
 
406
        int type = valueSet->getDataType();
 
407
#define CASE( A ) case A: return getRawPtrT < A > ( valueSet );
 
408
        switch( type )
 
409
        {
 
410
            CASE( W_DT_UNSIGNED_CHAR );
 
411
            CASE( W_DT_INT8 );
 
412
            CASE( W_DT_SIGNED_SHORT ); // INT16
 
413
            CASE( W_DT_SIGNED_INT ); // INT32
 
414
            CASE( W_DT_FLOAT );
 
415
            CASE( W_DT_DOUBLE );
 
416
            CASE( W_DT_UINT16 );
 
417
            CASE( W_DT_UINT32 );
 
418
            CASE( W_DT_INT64 );
 
419
            CASE( W_DT_UINT64 );
 
420
            CASE( W_DT_FLOAT128 );
 
421
            default:
 
422
                throw WException( "Not implemented for given data type" );
 
423
        }
 
424
#undef CASE
 
425
    }
 
426
}
 
427
 
 
428
void WIGTLinkRemote::sendImageData( WDataSetScalarSPtr dataSetScalar )
 
429
{
 
430
    boost::shared_ptr< WValueSetBase > valueSet = dataSetScalar->getValueSet();
 
431
    //size_t rawSize = valueSet->rawSize();
 
432
 
 
433
    int scalarType = 0;
 
434
    switch( valueSet->getDataType() )
 
435
    {
 
436
        case W_DT_FLOAT:
 
437
            scalarType = igtl::ImageMessage::TYPE_FLOAT32;
 
438
            break;
 
439
        case W_DT_DOUBLE:
 
440
            scalarType = igtl::ImageMessage::TYPE_FLOAT64;
 
441
            break;
 
442
        case W_DT_UINT16:
 
443
            scalarType = igtl::ImageMessage::TYPE_UINT16;
 
444
            break;
 
445
        case W_DT_UINT32:
 
446
            scalarType = igtl::ImageMessage::TYPE_UINT32;
 
447
            break;
 
448
        case W_DT_UNSIGNED_CHAR:
 
449
            scalarType = igtl::ImageMessage::TYPE_UINT8;
 
450
            break;
 
451
        case W_DT_INT8:
 
452
            scalarType = igtl::ImageMessage::TYPE_INT8;
 
453
            break;
 
454
        case W_DT_INT64:
 
455
        case W_DT_FLOAT128:
 
456
            throw WException( "Unsupported scalar type: not supported by igtl?" );
 
457
            break;
 
458
        case W_DT_SIGNED_INT:
 
459
            scalarType = igtl::ImageMessage::TYPE_INT32;
 
460
            break;
 
461
        case W_DT_SIGNED_SHORT:
 
462
            scalarType = igtl::ImageMessage::TYPE_INT16;
 
463
            break;
 
464
        case W_DT_BINARY:
 
465
        case W_DT_UINT64:
 
466
            throw WException( "Unsupported scalar type" );
 
467
            break;
 
468
        case W_DT_RGB:
 
469
        case W_DT_RGBA32:
 
470
            throw WException( "RGB not supported" );
 
471
            break;
 
472
        case W_DT_COMPLEX:
 
473
        case W_DT_COMPLEX128:
 
474
        case W_DT_COMPLEX256:
 
475
            throw WException( "Complex types are not supported, yet" );
 
476
            break;
 
477
        case W_DT_NONE:
 
478
            throw WException( "W_DT_NONE should never occur as a type." );
 
479
            break;
 
480
        case W_DT_ALL:
 
481
            throw WException( "W_DT_ALL should never occur as a type." );
 
482
            break;
 
483
    }
 
484
 
 
485
    if( socket.IsNotNull() )
 
486
    {
 
487
        int size[ 3 ];
 
488
        boost::shared_ptr < WGridRegular3D > g3dr( boost::shared_dynamic_cast < WGridRegular3D > ( dataSetScalar->getGrid() ) );
 
489
        size[ 0 ] = g3dr->getNbCoordsX();
 
490
        size[ 1 ] = g3dr->getNbCoordsY();
 
491
        size[ 2 ] = g3dr->getNbCoordsZ();
 
492
 
 
493
        int svsize[ 3 ] = { size[ 0 ], size[ 1 ], size[ 2 ]};
 
494
        int svoffset[] = { 0, 0, 0 };
 
495
 
 
496
        igtl::ImageMessage::Pointer imgMsg =  igtl::ImageMessage::New();
 
497
        imgMsg->SetDimensions( size );
 
498
        imgMsg->SetSpacing( g3dr->getOffsetX(), g3dr->getOffsetY(), g3dr->getOffsetZ() );
 
499
        imgMsg->SetDeviceName( "OpenWalnut" );
 
500
        imgMsg->SetSubVolume( svsize, svoffset );
 
501
        imgMsg->SetScalarType( scalarType );
 
502
        imgMsg->AllocateScalars();
 
503
 
 
504
        size_t rawsize =  Ugly::getRawSize( valueSet );
 
505
        std::cout << "Transfering " << rawsize << " = " << imgMsg->GetImageSize() << " bytes of data." << std::endl;
 
506
        memcpy( imgMsg->GetScalarPointer(), Ugly::getRawPtr( valueSet ), rawsize );
 
507
 
 
508
        igtl::Matrix4x4 matrix;
 
509
        igtl::IdentityMatrix( matrix );
 
510
        imgMsg->SetMatrix( matrix ); // TODO(mario): get the matrix from the data set
 
511
        imgMsg->Pack();
 
512
 
 
513
        socket->Send( imgMsg->GetPackPointer(), imgMsg->GetPackSize() );
 
514
    }
 
515
}
 
516
 
 
517
boost::shared_ptr < WValueSetBase > WIGTLinkRemote::createValueSet( const igtl::ImageMessage::Pointer& imgMsg )
 
518
{
 
519
    boost::shared_ptr<WValueSetBase> valueSet;
 
520
    int size[ 3 ];
 
521
    imgMsg->GetDimensions( size );
 
522
    size_t sz =  size[ 0 ] * size[ 1 ] * size[ 2 ];
 
523
#define CASE( igtltype, ctype, owtype )\
 
524
    case igtltype: \
 
525
            {\
 
526
                boost::shared_ptr < std::vector < ctype > > values( new std::vector < ctype >( sz ) );\
 
527
                memcpy( ( void* )&( ( *values )[ 0 ] ), imgMsg->GetScalarPointer(), sizeof( ctype ) * sz );\
 
528
                valueSet.reset( new WValueSet < ctype >( 0, 1, values, owtype ) );\
 
529
            }\
 
530
            break
 
531
 
 
532
     switch( imgMsg->GetScalarType() )
 
533
    {
 
534
        CASE( igtl::ImageMessage::TYPE_INT8, int8_t, W_DT_INT8 );
 
535
        CASE( igtl::ImageMessage::TYPE_UINT8, uint8_t, W_DT_UINT8 );
 
536
        CASE( igtl::ImageMessage::TYPE_INT16, int16_t, W_DT_INT16 );
 
537
        CASE( igtl::ImageMessage::TYPE_UINT16, uint16_t, W_DT_UINT16 );
 
538
        CASE( igtl::ImageMessage::TYPE_INT32, int32_t, W_DT_SIGNED_INT );
 
539
        CASE( igtl::ImageMessage::TYPE_UINT32, uint32_t, W_DT_UINT32 );
 
540
         default:
 
541
            break;
 
542
            // TODO(mario): throw exception?
 
543
    }
 
544
#undef CASE
 
545
    return valueSet;
 
546
}