Exemplo n.º 1
0
 geometry_ptr read() 
 {
     geometry_ptr geom;
     int type=read_integer();
     switch (type)
     {
     case wkbPoint:
         geom = read_point();
         break;
     case wkbLineString:
         geom = read_linestring();
         break;
     case wkbPolygon:
         geom = read_polygon();
         break;
     case wkbMultiPoint:
         geom = read_multipoint();
         break;
     case wkbMultiLineString:
         geom = read_multilinestring();
         break;
     case wkbMultiPolygon:
         geom=read_multipolygon();
         break;
     case wkbGeometryCollection:
         break;
     default:
         break;
     }
     return geom;
 }
Exemplo n.º 2
0
POLYGONVECTOR *read_polygonvector(char *filename,short print) {
	/*!
	 *
	 * \author Emanuele Cordano
	 * \author May 2008
	 *
	 *\param (char*) - name of filename
	 *\param (short) -
	 *
	 *\brief It creates and reads a polygonvector from the following options:
	 */
	POLYGONVECTOR *polygons;
	FILE *fd;
	long j,n_po;
	fd=t_fopen(filename,"r");

	n_po=(long)read_index(fd,no_PRINT);
	polygons=new_polygonvector(n_po);

	for (j=polygons->nl;j<=polygons->nh;j++) {
		polygons->element[j]=read_polygon(fd,print);
		if (polygons->element[j]->index!=j) printf ("Error in read_polygonvector (polygon %ld) inconstancy: %ld %ld \n",j,j,polygons->element[j]->index);
	}

	t_fclose(fd);
	if (print==1) printf("Function read_polygonvector (number of polygons %ld) was successfully executed!!",polygons->nh);

	return polygons;

}
Exemplo n.º 3
0
Arquivo: wkb.cpp Projeto: rjw57/mapnik
 void read_multipolygon(boost::ptr_vector<geometry_type> & paths)
 {
     int num_polys = read_integer();
     for (int i = 0; i < num_polys; ++i)
     {
         pos_ += 5;
         read_polygon(paths);
     }
 }
Exemplo n.º 4
0
static problem
read_problem(u32 id, string& fn)
{
  problem p = { id };

  u32 polygonsCount = 0;

  ifstream fin(fn, ifstream::binary);

  fin >> polygonsCount;
  for (size_t i = 0; i < polygonsCount; i++) {
    auto polygon = read_polygon(fin);
    p.outline.push_back(polygon);
  }

  p.skeleton = read_polygon(fin);

  return p;
}
Exemplo n.º 5
0
Arquivo: wkb.cpp Projeto: rjw57/mapnik
    void read(boost::ptr_vector<geometry_type> & paths)
    {
        int type = read_integer();

#ifdef MAPNIK_LOG
        MAPNIK_LOG_DEBUG(wkb_reader) << "wkb_reader: Read=" << wkb_geometry_type_string(type) << "," << type;
#endif
        switch (type)
        {
        case wkbPoint:
            read_point(paths);
            break;
        case wkbLineString:
            read_linestring(paths);
            break;
        case wkbPolygon:
            read_polygon(paths);
            break;
        case wkbMultiPoint:
            read_multipoint(paths);
            break;
        case wkbMultiLineString:
            read_multilinestring(paths);
            break;
        case wkbMultiPolygon:
            read_multipolygon(paths);
            break;
        case wkbGeometryCollection:
            read_collection(paths);
            break;
        case wkbPointZ:
            read_point_xyz(paths);
            break;
        case wkbLineStringZ:
            read_linestring_xyz(paths);
            break;
        case wkbPolygonZ:
            read_polygon_xyz(paths);
            break;
        case wkbMultiPointZ:
            read_multipoint_xyz(paths);
            break;
        case wkbMultiLineStringZ:
            read_multilinestring_xyz(paths);
            break;
        case wkbMultiPolygonZ:
            read_multipolygon_xyz(paths);
            break;
        case wkbGeometryCollectionZ:
            read_collection(paths);
            break;
        default:
            break;
        }
    }
Exemplo n.º 6
0
    void read(boost::ptr_vector<geometry_type> & paths)
    {
        int type = read_integer();

        switch (type)
        {
        case wkbPoint:
            read_point(paths);
            break;
        case wkbLineString:
            read_linestring(paths);
            break;
        case wkbPolygon:
            read_polygon(paths);
            break;
        case wkbMultiPoint:
            read_multipoint(paths);
            break;
        case wkbMultiLineString:
            read_multilinestring(paths);
            break;
        case wkbMultiPolygon:
            read_multipolygon(paths);
            break;
        case wkbGeometryCollection:
            read_collection(paths);
            break;
        case wkbPointZ:
            read_point_xyz(paths);
            break;
        case wkbLineStringZ:
            read_linestring_xyz(paths);
            break;
        case wkbPolygonZ:
            read_polygon_xyz(paths);
            break;
        case wkbMultiPointZ:
            read_multipoint_xyz(paths);
            break;
        case wkbMultiLineStringZ:
            read_multilinestring_xyz(paths);
            break;
        case wkbMultiPolygonZ:
            read_multipolygon_xyz(paths);
            break;
        case wkbGeometryCollectionZ:
            read_collection(paths);
            break;
        default:
            break;
        }
    }
Exemplo n.º 7
0
struct PolygonVec *read_polygons(FILE* fptr, size_t npoly)
{
    int status=1;
    char buff[_MANGLE_SMALL_BUFFSIZE];
    struct PolygonVec *self=NULL;
    size_t i=0;

    self = PolygonVec_new(npoly);
    if (!self) {
        status=0;
        wlog("could not allocate %lu polygons\n", npoly);
        goto _read_polygons_bail;
    }

    // in order to get here, we had to read the token already
    strcpy(buff, "polygon");

    for (i=0; i<npoly; i++) {
        // buff comes in with 'polygon'
        if (0 != strcmp(buff,"polygon")) {
            status=0;
            wlog("Expected first token in polygon %lu to read "
                 "'polygon', got '%s'\n", i, buff);
            goto _read_polygons_bail;
        }

        status = read_polygon(fptr, &self->data[i]);
        if (!status) {
            wlog("failed to read polygon %lu\n", i);
            break;
        }

        if (i != (npoly-1)) {
            if (1 != fscanf(fptr,"%s",buff)) {
                status=0;
                wlog("Error reading token for polygon %lu\n", i);
                goto _read_polygons_bail;
            }
        }
    }

_read_polygons_bail:

    if (!status) {
        free(self);
        self=NULL;
    }
    return self;
}
Exemplo n.º 8
0
/*
 * Should be passed FILE* right after reading the first
 * 'polygon' token, which should be stored in buff
 *
 * poly_vec should be allocated now
 */
static int
do_read_polygons(struct PyMangleMask* self)
{
    int status=1;

    npy_intp npoly=0, i=0;

    npoly=self->poly_vec->size;

    if (self->verbose)
        fprintf(stderr,"reading %ld polygons\n", npoly);
    for (i=0; i<npoly; i++) {
        // buff comes in with 'polygon'
        if (0 != strcmp(self->buff,"polygon")) {
            status=0;
            PyErr_Format(PyExc_IOError, 
                    "Expected first token in poly to read 'polygon', got '%s'", 
                    self->buff);
            goto _read_some_polygons_errout;
        }

        // just for error messages and verbosity
        self->current_poly_index = i;

        status = read_polygon(self, &self->poly_vec->data[i]);
        if (status != 1) {
            break;
        }

        if (i != (npoly-1)) {
            if (1 != fscanf(self->fptr,"%s",self->buff)) {
                status=0;
                PyErr_Format(PyExc_IOError, 
                        "Error reading token for polygon %ld", i);
                goto _read_some_polygons_errout;
            }
        }
    }

_read_some_polygons_errout:
    return status;
}
Exemplo n.º 9
0
Arquivo: wkb.cpp Projeto: bblu/mapnik
 mapnik::geometry::geometry<double> read()
 {
     mapnik::geometry::geometry<double> geom = mapnik::geometry::geometry_empty();
     int type = read_integer();
     switch (type)
     {
     case wkbPoint:
         geom = std::move(read_point());
         break;
     case wkbLineString:
         geom = std::move(read_linestring());
         break;
     case wkbPolygon:
         geom = std::move(read_polygon());
         break;
     case wkbMultiPoint:
         geom = std::move(read_multipoint());
         break;
     case wkbMultiLineString:
         geom = std::move(read_multilinestring());
         break;
     case wkbMultiPolygon:
         geom = std::move(read_multipolygon());
         break;
     case wkbGeometryCollection:
         geom = std::move(read_collection());
         break;
     case wkbPointZ:
     case wkbPointM:
         geom = std::move(read_point<true>());
         break;
     case wkbPointZM:
         geom = std::move(read_point<true,true>());
         break;
     case wkbLineStringZ:
     case wkbLineStringM:
         geom = std::move(read_linestring<true>());
         break;
     case wkbLineStringZM:
         geom = std::move(read_linestring<true,true>());
         break;
     case wkbPolygonZ:
     case wkbPolygonM:
         geom = std::move(read_polygon<true>());
         break;
     case wkbPolygonZM:
         geom = std::move(read_polygon<true,true>());
         break;
     case wkbMultiPointZ:
     case wkbMultiPointM:
         geom = std::move(read_multipoint<true>());
         break;
     case wkbMultiPointZM:
         geom = std::move(read_multipoint<true,true>());
         break;
     case wkbMultiLineStringZ:
     case wkbMultiLineStringM:
         geom = std::move(read_multilinestring<true>());
         break;
     case wkbMultiLineStringZM:
         geom = std::move(read_multilinestring<true,true>());
         break;
     case wkbMultiPolygonZ:
     case wkbMultiPolygonM:
         geom = std::move(read_multipolygon<true>());
         break;
     case wkbMultiPolygonZM:
         geom = std::move(read_multipolygon<true,true>());
         break;
     case wkbGeometryCollectionZ:
     case wkbGeometryCollectionM:
     case wkbGeometryCollectionZM:
         geom = std::move(read_collection());
         break;
     default:
         break;
     }
     return geom;
 }
Exemplo n.º 10
0
static int read_polygon( LWObjectImport *local, FILE *fp, LWPntID *pntID,
   int *isurf, int isDetail, Progress *progress )
{
   static int vert[ 200 ];
   static LWPntID vID[ 200 ];
   LWPolID polID;
   int vscolor, nvert, ndet, i;
   char tag[ 40 ], *err = NULL;


   /* read the vertex count */

   if ( !read_int( fp, &nvert ))
      if ( feof( fp )) return 0;  else goto Fail;

   err = "Bad vertex count.";
   if ( nvert <= 0 || nvert > 200 ) goto Fail;

   /* read the vertices--these index the point list */

   err = "Couldn't read polygon.";

   for ( i = 0; i < nvert; i++ )
      if ( !read_int( fp, &vert[ i ] )) goto Fail;

   /* read the VideoScape color code */

   if ( !read_int( fp, &vscolor )) goto Fail;
   ++isurf[ vscolor ];

   /* get the surface name for this color code */

   get_surf( vscolor, tag, NULL, 0 );

   /* create the polygon */

   for ( i = 0; i < nvert; i++ )
      vID[ i ] = pntID[ vert[ i ]];

   polID = local->polygon( local->data, LWPOLTYPE_FACE, 0, nvert, vID );
   local->polTag( local->data, polID, LWPTAG_SURF, tag );

   /* update the progress monitor */

   i = ftell( fp );
   if ( i >= progress->nextstep ) {
      if ( MON_STEP( local->monitor )) {
         local->result = LWOBJIM_ABORTED;
         return 0;
      }
      progress->nextstep += progress->stepsize;
   }

   /* if this polygon has no detail polygons, we're done */

   if ( vscolor >= 0 ) return 1;

   /* read the detail polygon count--details can't have details */

   if ( isDetail || !read_int( fp, &ndet )) goto Fail;

   /* read the detail polygons recursively */

   for ( i = 0; i < ndet; i++ )
      if ( !read_polygon( local, fp, pntID, isurf, 1, progress ))
         if ( local->result == LWOBJIM_ABORTED ) return 0;
         else goto Fail;

   return 1;

Fail:
   local->result = LWOBJIM_FAILED;
   if ( !err )
      err = "Unexpected end of file.";
   if ( local->failedLen > 0 )
      strncpy( local->failedBuf, err, local->failedLen );

   return 0;
}
Exemplo n.º 11
0
geoLoad( long version, GlobalFunc *global, LWObjectImport *local,
   void *serverData )
{
   static int isurf[ 261 ];
   LWFVector pos = { 0.0f };
   LWPntID *pntID = NULL;
   Progress progress;
   FILE *fp = NULL;
   struct stat s;
   char str[ 6 ], *err = NULL;
   int npts;
   int i, j;


   /* check the activation version */

   if ( version != LWOBJECTIMPORT_VERSION ) return AFUNC_BADVERSION;

   /* get the file size */

   if ( stat( local->filename, &s )) {
      local->result = LWOBJIM_BADFILE;
      return AFUNC_OK;
   }

   progress.total = s.st_size;
   progress.stepsize = progress.total / 20;
   progress.nextstep = progress.stepsize;

   /* attempt to open the file */

   fp = fopen( local->filename, "r" );
   if ( !fp ) {
      local->result = LWOBJIM_BADFILE;
      return AFUNC_OK;
   }

   /* see whether this is a VideoScape ASCII object file;
      if not, let someone else try to load it */

   fread( str, 1, 4, fp );
   if ( strncmp( str, "3DG1", 4 )) {
      fclose( fp );
      local->result = LWOBJIM_NOREC;
      return AFUNC_OK;
   }

   /* initialize the layer */

   local->layer( local->data, 1, NULL );
   local->pivot( local->data, pos );

   /* read the point count */

   local->result = LWOBJIM_FAILED;   /* assume this until we succeed */

   err = "Bad point count.";
   if ( !read_int( fp, &npts )) goto Finish;
   if ( npts <= 0 ) goto Finish;

   /* allocate space to store point IDs */

   err = "Couldn't allocate memory for points.";
   pntID = calloc( npts, sizeof( LWPntID ));
   if ( !pntID ) goto Finish;

   /* initialize the progress monitor */

   MON_INIT( local->monitor, 20 );

   /* read the point list */

   for ( i = 0; i < npts; i++ ) {
      for ( j = 0; j < 3; j++ )
         if ( !read_float( fp, &pos[ j ] )) {
            err = "Couldn't read point.";
            goto Finish;
         }

      if ( !( pntID[ i ] = local->point( local->data, pos ))) {
         err = "Couldn't create point.";
         goto Finish;
      }

      j = ftell( fp );
      if ( j >= progress.nextstep ) {
         if ( MON_STEP( local->monitor )) {
            local->result = LWOBJIM_ABORTED;
            err = NULL;
            goto Finish;
         }
         progress.nextstep += progress.stepsize;
      }
   }

   /* read the polygon list; read_polygon() will set its own failure
      status and message */

   err = NULL;
   local->result = LWOBJIM_OK;
   memset( isurf, 0, 261 * sizeof( int ));

   while ( read_polygon( local, fp, pntID, isurf, 0, &progress )) ;

   /* create the surface descriptions */

   if ( local->result == LWOBJIM_OK )
      create_surfs( local, isurf );

   /* we're done */

   MON_DONE( local->monitor );
   local->done( local->data );

Finish:
   if ( fp ) fclose( fp );
   if ( pntID ) free( pntID );
   if (( local->result != LWOBJIM_OK ) && err && ( local->failedLen > 0 ))
      strncpy( local->failedBuf, err, local->failedLen );

   return AFUNC_OK;
}
Exemplo n.º 12
0
static Errcode read_256_color_frame(Rfile *rf)
/* Read and parse all the opcodes in a RND file. */
{
int opcode;
Rcel *screen = rf->screen;

	/* clear color map to zeros */
	stuff_bytes(0,screen->cmap->ctab,
				screen->cmap->num_colors * sizeof(Rgb3));

#ifdef DEBUG
	#define PRT(s) printf(s)
#else
	#define PRT(s)
#endif /* DEBUG */


	for(;;)
	{
		opcode = fgetc(rf->file);

		switch(opcode)
		{
			case EOF:
				return(Success);
   			case RND_CLEAR:   /* Clear entire display */
				pj_set_rast(screen,0);
				continue;
   			case RND_CMAPB:  /* Begin Color map */
				read_color_map(rf);
				break;
   			case RND_POLY:   /* Polygon */
				read_polygon(rf);
				break;
   			case RND_CRANGE:  /* Continous-color range */
				PRT("RND_CRANGE");
				goto bad_opcode;
   			case RND_CPOLY:   /* Continous-color polygon */
				PRT("RND_CPOLY");
				goto bad_opcode;
			case RND_WSLINE:  /* Output Scan line to driver */
				read_scanline(rf);
				break;
			case RND_RSLINE:  /* Input Scan line from driver */
				PRT("RND_RSLINE");
				goto bad_opcode;
			case RND_RCMAP:   /* Input color map rgb from driver */
				PRT("RND_RCMAP");
				goto bad_opcode;
			case RND_ETAIL:   /* i/o details for hard copy drivers */
				PRT("RND_ETAIL");
				goto bad_opcode;
			case RND_CFGREC:  /* execution time configuration record */
				PRT("RND_CFGREC");
				goto bad_opcode;
			case RND_NEWCFG:  /* new configuration record */
				PRT("RND_NEWCFG");
				goto bad_opcode;
			case RND_CHGCFG:  /* change configuration record */
				PRT("RND_CHGCFG");
				goto bad_opcode;
			case RND_SHOWCFG: /* show configuration record */
				PRT("RND_SHOWCFG");
				goto bad_opcode;
			case RND_FNAME:
				PRT("RND_FNAME");
				goto bad_opcode;
			default:
			bad_opcode:
#ifdef DEBUG
				printf("#%2d @ %06x", opcode, ftell(rf->file));
#endif /* DEBUG */
				rf->lasterr = Err_format;
				goto error;
		}
		if(rf->lasterr < Success)
			goto error;
	}
error:
	return(rf->lasterr);

#undef PRT
}