p_blobfinder.cc
Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2004, 2005 Richard Vaughan
00004  *
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 /*
00023  * Desc: A plugin driver for Player that gives access to Stage devices.
00024  * Author: Richard Vaughan
00025  * Date: 10 December 2004
00026  * CVS: $Id$
00027  */
00028 
00029 // DOCUMENTATION
00030 
00036 // CODE
00037 
00038 #include "p_driver.h"
00039 using namespace Stg;
00040 
00041 InterfaceBlobfinder::InterfaceBlobfinder( player_devaddr_t addr,
00042                                 StgDriver* driver,
00043                                 ConfigFile* cf,
00044                                 int section )
00045   : InterfaceModel( addr, driver, cf, section, "blobfinder" )
00046 {
00047   // nothing to do for now
00048 }
00049 
00050 
00051 void InterfaceBlobfinder::Publish( void )
00052 {
00053   player_blobfinder_data_t bfd;
00054   bzero( &bfd, sizeof(bfd) );
00055 
00056   ModelBlobfinder* blobmod = (ModelBlobfinder*)this->mod;
00057   
00058   uint32_t bcount = 0;
00059   const ModelBlobfinder::Blob* blobs = blobmod->GetBlobs( &bcount );
00060   
00061   if ( bcount > 0 )
00062   {
00063           // and set the image width * height
00064           bfd.width = blobmod->scan_width;
00065           bfd.height = blobmod->scan_height;
00066           bfd.blobs_count = bcount;
00067 
00068           bfd.blobs = new player_blobfinder_blob_t[ bcount ];
00069 
00070           // now run through the blobs, packing them into the player buffer
00071           // counting the number of blobs in each channel and making entries
00072           // in the acts header
00073           unsigned int b;
00074           for( b=0; b<bcount; b++ )
00075                 {
00076                   // useful debug - leave in
00077                 /*
00078                 cout << "blob "
00079                 << " left: " <<  blobs[b].left
00080                 << " right: " <<  blobs[b].right
00081                 << " top: " <<  blobs[b].top
00082                 << " bottom: " <<  blobs[b].bottom
00083                 << " color: " << hex << blobs[b].color << dec
00084                 << endl;
00085                   */
00086 
00087                         int dx = blobs[b].right - blobs[b].left;
00088                         int dy = blobs[b].top - blobs[b].bottom;
00089 
00090                   bfd.blobs[b].x      = blobs[b].left + dx/2;
00091                   bfd.blobs[b].y      = blobs[b].bottom + dy/2;
00092 
00093                   bfd.blobs[b].left   = blobs[b].left;
00094                   bfd.blobs[b].right  = blobs[b].right;
00095                   bfd.blobs[b].top    = blobs[b].top;
00096                   bfd.blobs[b].bottom = blobs[b].bottom;
00097 
00098                   bfd.blobs[b].color = 
00099                          ((uint8_t)(blobs[b].color.r*255.0) << 16) +
00100                          ((uint8_t)(blobs[b].color.g*255.0) << 8) +
00101                          ((uint8_t)(blobs[b].color.b*255.0));
00102                          
00103                   bfd.blobs[b].area  = dx * dy;
00104 
00105                   bfd.blobs[b].range = blobs[b].range;
00106                 }
00107   }
00108 
00109   // should change player interface to support variable-lenght blob data
00110   // size_t size = sizeof(bfd) - sizeof(bfd.blobs) + bcount * sizeof(bfd.blobs[0]);
00111 
00112   this->driver->Publish( this->addr,
00113                                                                  PLAYER_MSGTYPE_DATA,
00114                                                                  PLAYER_BLOBFINDER_DATA_BLOBS,
00115                                                                  &bfd, sizeof(bfd), NULL);
00116   if ( bfd.blobs )
00117           delete [] bfd.blobs;
00118 }
00119 
00120 int InterfaceBlobfinder::ProcessMessage( QueuePointer& resp_queue,
00121                                                                                                           player_msghdr_t* hdr,
00122                                                                                                           void* data )
00123 {
00124   // todo: handle configuration requests
00125 
00126   //else
00127   {
00128     // Don't know how to handle this message.
00129     PRINT_WARN2( "blobfinder doesn't support msg with type/subtype %d/%d",
00130                  hdr->type, hdr->subtype);
00131     return(-1);
00132   }
00133 }
00134 


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57