Update of /cvsroot/playerstage/code/player/utils/playerv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20455/utils/playerv

Modified Files:
        Makefile.am playerv.c playerv.h registry.c 
Added Files:
        dev_vectormap.c 
Log Message:
added vectormap interface
added postgis vectormap driver
Thanks to Ben Morelli for these changes


Index: registry.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/registry.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** registry.c  20 May 2007 00:30:15 -0000      1.28
--- registry.c  20 Aug 2007 19:42:49 -0000      1.29
***************
*** 164,167 ****
--- 164,177 ----
        break;
  
+     case PLAYER_VECTORMAP_CODE:
+       device->proxy = vectormap_create(mainwnd, opt, client,
+          device->addr.index,
+          device->drivername,
+          device->subscribe);
+       device->fndestroy = (fndestroy_t) vectormap_destroy;
+       device->fnupdate = (fnupdate_t) vectormap_update;
+       break;
+ 
+ 
  #if 0
      case PLAYER_LOCALIZE_CODE:

--- NEW FILE: dev_vectormap.c ---
/* 
 *  PlayerViewer
 *  Copyright (C) Andrew Howard 2002
 *
 *  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.
 *
 */
/***************************************************************************
 * Desc: Map interface
 * Author: Richard Vaughan, based on similar code by Andrew Howard
 * Date: 5 March 2005
 * CVS: $Id: dev_vectormap.c,v 1.1 2007/08/20 19:42:49 thjc Exp $
 ***************************************************************************/

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "playerv.h"

// Update the map configuration
void vectormap_update_config(vectormap_t *map);

// Draw the map 
void vectormap_draw(vectormap_t *map);

// Draw a single map feature
void vectormap_draw_feature(vectormap_t *map, GEOSGeom geom);


// Create a map device
vectormap_t *vectormap_create(mainwnd_t *mainwnd, opt_t *opt, playerc_client_t 
*client,
                      int index, const char *drivername, int subscribe)
{
  char label[64];
  char section[64];
  vectormap_t *map;
  
  map = malloc(sizeof(vectormap_t));
  map->proxy = playerc_vectormap_create(client, index);
  map->drivername = strdup(drivername);
  map->datatime = 0;

  snprintf(section, sizeof(section), "vectormap:%d", index);

  // Construct the menu
  snprintf(label, sizeof(label), "vectormap:%d (%s)", index, map->drivername);
  map->menu = rtk_menu_create_sub(mainwnd->device_menu, label);
  map->subscribe_item = rtk_menuitem_create(map->menu, "Subscribe", 1);
  // Set the initial menu state
  rtk_menuitem_check(map->subscribe_item, subscribe);

  // Construct figures
  map->fig = rtk_fig_create(mainwnd->canvas, NULL, 1);
  printf("Created figure: %p\n", map->fig);

  return map;
}


// Destroy a map device
void vectormap_destroy(vectormap_t *map)
{
  if (map->proxy->info.subscribed)
    playerc_vectormap_unsubscribe(map->proxy);

  playerc_vectormap_destroy(map->proxy);
  rtk_fig_destroy(map->fig);
  free(map->drivername);
  free(map);

  return;
}


// Update a map device
void vectormap_update(vectormap_t *map)
{
  unsigned ii;

  // Update the device subscription
  if (rtk_menuitem_ischecked(map->subscribe_item))
  {
    if (!map->proxy->info.subscribed)
    {
      if (playerc_vectormap_subscribe(map->proxy, PLAYER_OPEN_MODE) != 0)
        PRINT_ERR1("libplayerc error: %s", playerc_error_str());

      // get the map info
      playerc_vectormap_get_map_info( map->proxy );

      // download intial map
      for (ii = 0;  ii < map->proxy->layers_count; ++ii)
      {
        playerc_vectormap_get_layer_info( map->proxy, ii );
      }

      for (ii = 0;  ii < map->proxy->layers_count; ++ii)
      {
        playerc_vectormap_get_layer_data( map->proxy, ii );
      }
      vectormap_draw( map );
    }
  }
  else
  {
    if (map->proxy->info.subscribed)
      if (playerc_vectormap_unsubscribe(map->proxy) != 0)
        PRINT_ERR1("libplayerc error: %s", playerc_error_str());
  }
  rtk_menuitem_check(map->subscribe_item, map->proxy->info.subscribed);

  // Dont draw the map.
  if(map->proxy->info.subscribed)
    rtk_fig_show(map->fig, 1);
  else
    rtk_fig_show(map->fig, 0);
}

//extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf(const unsigned char *wkb, 
size_t size);

// Draw the map scan
void vectormap_draw(vectormap_t *map)
{
  unsigned ii, jj;
  GEOSGeom feature;
  printf("Calling draw on vectormap\n");

  rtk_fig_show(map->fig, 1);
  rtk_fig_clear(map->fig);

  puts( "map draw" );

  // draw map data
  uint32_t colour = 0xFF0000;
  for (ii = 0;  ii < map->proxy->layers_count; ++ii)
  {
    // get a different colour for each layer the quick way, will duplicate 
after 6 layers
    colour = colour >> 4 & colour << 24;
    rtk_fig_color_rgb32(map->fig, colour);

    // render the features
    for (jj = 0;  jj < map->proxy->layers[ii]->features_count; ++jj)
    {
      feature = playerc_vectormap_get_feature_data( map->proxy, ii, jj );
      if (feature)
        vectormap_draw_feature(map, feature);
    }
  }

  // draw map extent
  rtk_fig_color_rgb32( map->fig, 0xFF0000 );
  double xCenter = map->proxy->extent.x1 - (map->proxy->extent.x1 - 
map->proxy->extent.x0)/2;
  double yCenter = map->proxy->extent.y1 - (map->proxy->extent.y1 - 
map->proxy->extent.y0)/2;

  rtk_fig_rectangle(
                    map->fig,
                    xCenter,
                    yCenter,
                    0,
                    map->proxy->extent.x1 - map->proxy->extent.x0,
                    map->proxy->extent.y1 - map->proxy->extent.y0,
                    0
                   );

  return;
}


void vectormap_draw_feature(vectormap_t *map, GEOSGeom geom)
{
#ifdef HAVE_GEOS
  GEOSCoordSeq seq;
  unsigned numcoords;
  unsigned ii;
  double x,y,x2,y2;
  switch (GEOSGeomTypeId(geom)) 
  {
    case GEOS_POINT:
      seq = GEOSGeom_getCoordSeq(geom);
      GEOSCoordSeq_getX(seq, 00, &x);
      GEOSCoordSeq_getY(seq, 00, &y);
      rtk_fig_point( map->fig, x, y );
      break;
    case GEOS_LINESTRING:
    case GEOS_LINEARRING:
      printf("Got a line string\n");
      seq = GEOSGeom_getCoordSeq(geom);
      if(GEOSCoordSeq_getSize(seq, &numcoords))
      {
        GEOSCoordSeq_getX(seq, ii, &x2);
        GEOSCoordSeq_getY(seq, ii, &y2);
        printf("first point: %f %f\n", x2,y2);
        if (numcoords < 2)
        {
          rtk_fig_point( map->fig, x2, y2 );
        }
        else
        {
          for (ii = 1; ii < numcoords; ++ii)
          {
            x = x2;
            y = y2;
            GEOSCoordSeq_getX(seq, ii, &x2);
            GEOSCoordSeq_getY(seq, ii, &y2);
            printf("drawing line from %f,%f to %f,%f\n",x,y,x2,y2);
            rtk_fig_line( map->fig, x, y ,x2, y2);
          }
        }
      }
      break;

    case GEOS_POLYGON:
      vectormap_draw_feature(map,GEOSGetExteriorRing(geom));
      for (ii = 0; ii < GEOSGetNumInteriorRings(geom); ++ii)
      {
        vectormap_draw_feature(map,GEOSGetInteriorRingN(geom,ii));
      }
      break;

    case GEOS_MULTIPOINT:
    case GEOS_MULTILINESTRING:
    case GEOS_MULTIPOLYGON:
    case GEOS_GEOMETRYCOLLECTION:
      for (ii = 0; ii < GEOSGetNumGeometries(geom); ++ii)
      {
        vectormap_draw_feature(map,GEOSGetGeometryN(geom,ii));
      }
      break;

    default:
      PRINT_ERR1("unknown feature type: %d", GEOSGeomTypeId(geom));
  }
#else
  printf("lib GEOS was not available at build time so features will not be 
rendered\n");
#endif
}

Index: playerv.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/playerv.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** playerv.h   20 May 2007 00:30:15 -0000      1.49
--- playerv.h   20 Aug 2007 19:42:49 -0000      1.50
***************
*** 820,822 ****
--- 820,858 ----
  
  
+ /***************************************************************************
+  * Vector Map device
+  ***************************************************************************/
+ 
+ // Vector Map device info
+ typedef struct
+ {
+   // Driver name
+   char *drivername;
+ 
+   // Map device proxy
+   playerc_vectormap_t *proxy;
+ 
+   // Timestamp on most recent data
+   double datatime;
+ 
+   // Menu stuff
+   rtk_menu_t *menu;
+   rtk_menuitem_t *subscribe_item;
+   // Figures
+   rtk_fig_t *fig;
+ 
+ } vectormap_t;
+ 
+ 
+ // Create a map device
+ vectormap_t *vectormap_create(mainwnd_t *mainwnd, opt_t *opt, 
playerc_client_t *client,
+                     int index,  const char *drivername, int subscribe);
+ 
+ // Destroy a map device
+ void vectormap_destroy(vectormap_t *map);
+ 
+ // Update a map device
+ void vectormap_update(vectormap_t *map);
+ 
+ 
  #endif

Index: Makefile.am
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/Makefile.am,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** Makefile.am 20 May 2007 00:30:15 -0000      1.43
--- Makefile.am 20 Aug 2007 19:42:49 -0000      1.44
***************
*** 5,9 ****
  EXTRA_DIST = playerv-laser-blobfinder-ptz.jpg playerv-sonar.jpg
  
! AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/client_libs @GTK_CFLAGS@
  
  bin_PROGRAMS = $(PLAYERV)
--- 5,9 ----
  EXTRA_DIST = playerv-laser-blobfinder-ptz.jpg playerv-sonar.jpg
  
! AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/client_libs @GTK_CFLAGS@ 
  
  bin_PROGRAMS = $(PLAYERV)
***************
*** 16,20 ****
                    opt.c \
                    opt.h \
!                 dev_aio.c \
                    dev_blobfinder.c \
                    dev_bumper.c \
--- 16,20 ----
                    opt.c \
                    opt.h \
!                   dev_aio.c \
                    dev_blobfinder.c \
                    dev_bumper.c \
***************
*** 30,34 ****
                    dev_wifi.c \
                    dev_gripper.c \
!                   dev_ranger.c
  #dev_localize.c
  
--- 30,35 ----
                    dev_wifi.c \
                    dev_gripper.c \
!                   dev_ranger.c \
!                                                                       
dev_vectormap.c
  #dev_localize.c
  
***************
*** 36,38 ****
                         $(top_builddir)/libplayerxdr/libplayerxdr.la \
                         $(top_builddir)/libplayercore/libplayererror.la
! playerv_LDADD = $(top_builddir)/client_libs/libplayerc/libplayerc.la 
$(top_builddir)/libplayerxdr/libplayerxdr.la 
$(top_builddir)/libplayercore/libplayererror.la -lrtk -L$(top_builddir)/rtk2 
-lrtk @GTK_LIBS@
--- 37,43 ----
                         $(top_builddir)/libplayerxdr/libplayerxdr.la \
                         $(top_builddir)/libplayercore/libplayererror.la
! playerv_LDADD = $(top_builddir)/client_libs/libplayerc/libplayerc.la \
!       $(top_builddir)/libplayerxdr/libplayerxdr.la \
!       $(top_builddir)/libplayercore/libplayererror.la \
!       $(top_builddir)/libplayercore/libplayerutils.la \
!       -lrtk -L$(top_builddir)/rtk2 -lrtk @GTK_LIBS@ @GEOS_LIBS@

Index: playerv.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/playerv.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** playerv.c   20 May 2007 00:30:15 -0000      1.48
--- playerv.c   20 Aug 2007 19:42:49 -0000      1.49
***************
*** 257,261 ****
      // See if the device should be subscribed immediately.
      snprintf(section, sizeof(section), "%s:%d",
!              playerc_lookup_name(device->addr.interf), device->addr.index);
      device->subscribe = opt_get_int(opt, section, "", 0);
      device->subscribe = opt_get_int(opt, section, "subscribe", 
device->subscribe);
--- 257,261 ----
      // See if the device should be subscribed immediately.
      snprintf(section, sizeof(section), "%s:%d",
!              interf_to_str(device->addr.interf), device->addr.index);
      device->subscribe = opt_get_int(opt, section, "", 0);
      device->subscribe = opt_get_int(opt, section, "subscribe", 
device->subscribe);
***************
*** 263,267 ****
      {
        snprintf(section, sizeof(section), "%s",
!                playerc_lookup_name(device->addr.interf));
        device->subscribe = opt_get_int(opt, section, "", device->subscribe);
        device->subscribe = opt_get_int(opt, section, "subscribe", 
device->subscribe);
--- 263,267 ----
      {
        snprintf(section, sizeof(section), "%s",
!                interf_to_str(device->addr.interf));
        device->subscribe = opt_get_int(opt, section, "", device->subscribe);
        device->subscribe = opt_get_int(opt, section, "subscribe", 
device->subscribe);
***************
*** 295,299 ****
      device = devices + i;
      snprintf(section, sizeof(section), "%s:%d",
!              playerc_lookup_name(device->addr.interf), device->addr.index);
      printf("%-16s %-40s", section, device->drivername);
      if (device->proxy)
--- 295,299 ----
      device = devices + i;
      snprintf(section, sizeof(section), "%s:%d",
!              interf_to_str(device->addr.interf), device->addr.index);
      printf("%-16s %-40s", section, device->drivername);
      if (device->proxy)


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to