Beispiel #1
0
int delete_control_point(int n)
{
    int i;
    char msg[80];

    if ((n < 0) | (n > group.points.count - 1)) {
	sprintf(msg, "%d is an invalid control point index value.", n);
	G_warning(msg);
	return 1;
    }
    for (i = n; i < group.points.count - 1; i++) {
	G_copy(&group.points.e1[i], &group.points.e1[i + 1],
	       sizeof(group.points.e1[0]));
	G_copy(&group.points.n1[i], &group.points.n1[i + 1],
	       sizeof(group.points.n1[0]));
	G_copy(&group.points.e2[i], &group.points.e2[i + 1],
	       sizeof(group.points.e2[0]));
	G_copy(&group.points.n2[i], &group.points.n2[i + 1],
	       sizeof(group.points.n2[0]));
	G_copy(&group.points.status[i], &group.points.status[i + 1],
	       sizeof(group.points.status[0]));
    }
    group.points.count -= 1;
    if (I_put_control_points(group.name, &group.points) < 0) {
	G_fatal_error("bad return on I_put_control_points");
	return 1;
    }
    return 0;
}
Beispiel #2
0
CPLErr GRASSRasterBand::ResetReading ( struct Cell_head *sNewWindow )
{

    /* Check if the window has changed */
    if ( sNewWindow->north  != sOpenWindow.north  || sNewWindow->south  != sOpenWindow.south ||
	 sNewWindow->east   != sOpenWindow.east   || sNewWindow->west   != sOpenWindow.west ||
	 sNewWindow->ew_res != sOpenWindow.ew_res || sNewWindow->ns_res != sOpenWindow.ns_res ||
	 sNewWindow->rows   != sOpenWindow.rows   || sNewWindow->cols   != sOpenWindow.cols )
    {
	if( hCell >= 0 ) {
            G_close_cell( hCell );
	    hCell = -1;
	}

	/* Set window */
	G_set_window( sNewWindow );

	/* Open raster */
	G__setenv( "GISDBASE", ((GRASSDataset *)poDS)->pszGisdbase );
	G__setenv( "LOCATION_NAME", ((GRASSDataset *)poDS)->pszLocation );
	G__setenv( "MAPSET", pszMapset); 
	G_reset_mapsets();
	G_add_mapset_to_search_path ( pszMapset );
	
	if ( (hCell = G_open_cell_old( pszCellName, pszMapset)) < 0 ) {
	    CPLError( CE_Warning, CPLE_AppDefined, "GRASS: Cannot open raster '%s'", pszCellName );
            this->valid = false;
	    return CE_Failure;
	}

	G_copy((void *) &sOpenWindow, (void *) sNewWindow, sizeof(struct Cell_head));
	
    }
    else
    {
        /* The windows are identical, check current window */
        struct Cell_head sCurrentWindow;

        G_get_window ( &sCurrentWindow );

        if ( sNewWindow->north  != sCurrentWindow.north  || sNewWindow->south  != sCurrentWindow.south ||
             sNewWindow->east   != sCurrentWindow.east   || sNewWindow->west   != sCurrentWindow.west ||
             sNewWindow->ew_res != sCurrentWindow.ew_res || sNewWindow->ns_res != sCurrentWindow.ns_res ||
             sNewWindow->rows   != sCurrentWindow.rows   || sNewWindow->cols   != sCurrentWindow.cols
             )
        {
            /* Reset window */
            G_set_window( sNewWindow );
        }
    }


    return CE_None;
}
Beispiel #3
0
Coreness::Coreness(const graph& G): g(G), cn(G,0), ce(G, 0)
{
    graph G_copy(G);
    list < node > lnode = G_copy.all_nodes();
    vector < int > nc, ec;
    for (int K = 1; !lnode.empty(); ++K) {
        nc.push_back(0);
        ec.push_back(0);
        while (!lnode.empty()) {
            list < node >::iterator it = lnode.begin();
            list < node >::iterator end = lnode.end();
            int clear = 1;
            while (it != end) {
                if (it->degree() > K) {
                    ++it;
                    continue;
                }
                cn[*it] = K - 1;
		nc[K-1]++;
		node::adj_edges_iterator eit, eend;
		eend = it->adj_edges_end();
		for (eit=it->adj_edges_begin(); eit!=eend; ++eit) {
		    ce[*eit] = K - 1;
		    ec[K-1]++;
		}
                G_copy.del_node(*it);
                it = lnode.erase(it);
                clear = 0;
            }
            if (clear) {
//	cout << "Core " << K-1 << " " << nc[K-1] << " " << ec[K-1] << endl;
                break;
            }
        }
    }
}
Beispiel #4
0
GRASSRasterBand::GRASSRasterBand( GRASSDataset *poDS, int nBand,
                                  const char * pszMapset,
                                  const char * pszCellName )

{
    struct Cell_head	sCellInfo;

    // Note: GISDBASE, LOCATION_NAME ans MAPSET was set in GRASSDataset::Open

    this->poDS = poDS;
    this->nBand = nBand;
    this->valid = false;

    this->pszCellName = G_store ( (char *) pszCellName );
    this->pszMapset = G_store ( (char *) pszMapset );

    G_get_cellhd( (char *) pszCellName, (char *) pszMapset, &sCellInfo );
    nGRSType = G_raster_map_type( (char *) pszCellName, (char *) pszMapset );

/* -------------------------------------------------------------------- */
/*      Get min/max values.                                             */
/* -------------------------------------------------------------------- */
    struct FPRange sRange;

    if( G_read_fp_range( (char *) pszCellName, (char *) pszMapset, 
                         &sRange ) == -1 )
    {
        bHaveMinMax = FALSE;
    }
    else
    {
        bHaveMinMax = TRUE;
        G_get_fp_range_min_max( &sRange, &dfCellMin, &dfCellMax );
    }

/* -------------------------------------------------------------------- */
/*      Setup band type, and preferred nodata value.                    */
/* -------------------------------------------------------------------- */
    // Negative values are also (?) stored as 4 bytes (format = 3) 
    //       => raster with format < 3 has only positive values

    // GRASS modules usually do not waste space and only the format necessary to keep 
    // full raster values range is used -> no checks if shorter type could be used
    
    if( nGRSType == CELL_TYPE ) {
	if ( sCellInfo.format == 0 ) {  // 1 byte / cell -> possible range 0,255
	    if ( bHaveMinMax && dfCellMin > 0 ) {
                this->eDataType = GDT_Byte;
		dfNoData = 0.0;
	    } else if ( bHaveMinMax && dfCellMax < 255 ) {
                this->eDataType = GDT_Byte;
		dfNoData = 255.0;
	    } else { // maximum is not known or full range is used
		this->eDataType = GDT_UInt16;
		dfNoData = 256.0;
	    }
	    nativeNulls = false;
	} else if ( sCellInfo.format == 1 ) {  // 2 bytes / cell -> possible range 0,65535
	    if ( bHaveMinMax && dfCellMin > 0 ) {
		this->eDataType = GDT_UInt16;
		dfNoData = 0.0;
	    } else if ( bHaveMinMax && dfCellMax < 65535 ) {
                this->eDataType = GDT_UInt16;
		dfNoData = 65535;
	    } else { // maximum is not known or full range is used
		CELL cval;
		this->eDataType = GDT_Int32; 
		G_set_c_null_value ( &cval, 1);
		dfNoData = (double) cval;
		nativeNulls = true;
	    }
	    nativeNulls = false;
	} else {  // 3-4 bytes 
	    CELL cval;
	    this->eDataType = GDT_Int32;
	    G_set_c_null_value ( &cval, 1);
	    dfNoData = (double) cval;
	    nativeNulls = true;
	}
    } 
    else if( nGRSType == FCELL_TYPE ) {
	FCELL fval;
        this->eDataType = GDT_Float32;
	G_set_f_null_value ( &fval, 1);
	dfNoData = (double) fval;
	nativeNulls = true;
    }
    else if( nGRSType == DCELL_TYPE )
    {
	DCELL dval;
        this->eDataType = GDT_Float64;
	G_set_d_null_value ( &dval, 1);
	dfNoData = (double) dval;
	nativeNulls = true;
    }

    nBlockXSize = poDS->nRasterXSize;;
    nBlockYSize = 1;

    G_set_window( &(((GRASSDataset *)poDS)->sCellInfo) );
    if ( (hCell = G_open_cell_old((char *) pszCellName, (char *) pszMapset)) < 0 ) {
	CPLError( CE_Warning, CPLE_AppDefined, "GRASS: Cannot open raster '%s'", pszCellName );
	return;
    }
    G_copy((void *) &sOpenWindow, (void *) &(((GRASSDataset *)poDS)->sCellInfo), sizeof(struct Cell_head));

/* -------------------------------------------------------------------- */
/*      Do we have a color table?                                       */
/* -------------------------------------------------------------------- */
    poCT = NULL;
    if( G_read_colors( (char *) pszCellName, (char *) pszMapset, &sGrassColors ) == 1 )
    {
	int maxcolor; 
	CELL min, max;

	G_get_color_range ( &min, &max, &sGrassColors);

        if ( bHaveMinMax ) {
	    if ( max < dfCellMax ) {
	       maxcolor = max;
            } else {
	       maxcolor = (int) ceil ( dfCellMax );
	    }
	    if ( maxcolor > GRASS_MAX_COLORS ) { 
		maxcolor = GRASS_MAX_COLORS;
                CPLDebug( "GRASS", "Too many values, color table cut to %d entries.", maxcolor );
	    }
	} else {
	    if ( max < GRASS_MAX_COLORS ) {
	       maxcolor = max;
            } else {
	       maxcolor = GRASS_MAX_COLORS;
               CPLDebug( "GRASS", "Too many values, color table set to %d entries.", maxcolor );
	    }
        }
	    
        poCT = new GDALColorTable();
        for( int iColor = 0; iColor <= maxcolor; iColor++ )
        {
            int	nRed, nGreen, nBlue;
            GDALColorEntry    sColor;

#if GRASS_VERSION_MAJOR  >= 7
            if( Rast_get_c_color( &iColor, &nRed, &nGreen, &nBlue, &sGrassColors ) )
#else
            if( G_get_color( iColor, &nRed, &nGreen, &nBlue, &sGrassColors ) )
#endif
            {
                sColor.c1 = nRed;
                sColor.c2 = nGreen;
                sColor.c3 = nBlue;
                sColor.c4 = 255;

                poCT->SetColorEntry( iColor, &sColor );
            }
            else
            {
                sColor.c1 = 0;
                sColor.c2 = 0;
                sColor.c3 = 0;
                sColor.c4 = 0;

                poCT->SetColorEntry( iColor, &sColor );
            }
        }
	    
	/* Create metadata enries for color table rules */
	char key[200], value[200];
	int rcount = G_colors_count ( &sGrassColors );

	sprintf ( value, "%d", rcount );
	this->SetMetadataItem( "COLOR_TABLE_RULES_COUNT", value );

	/* Add the rules in reverse order */
	for ( int i = rcount-1; i >= 0; i-- ) {
	    DCELL val1, val2;
	    unsigned char r1, g1, b1, r2, g2, b2;

	     G_get_f_color_rule ( &val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2, &sGrassColors, i );
		

	     sprintf ( key, "COLOR_TABLE_RULE_RGB_%d", rcount-i-1 );
	     sprintf ( value, "%e %e %d %d %d %d %d %d", val1, val2, r1, g1, b1, r2, g2, b2 );
	     this->SetMetadataItem( key, value );
	}
    } else {
	this->SetMetadataItem( "COLOR_TABLE_RULES_COUNT", "0" );
    }
    
    this->valid = true;
}
Beispiel #5
0
static int zoom1(int x, int y)
{				/* called by Input_pointer */
    int top, bottom, left, right;
    int n, row, col;
    int nrows, ncols;
    struct Cell_head cellhd;
    int mag;
    double magnification();
    double north, south, east, west;

    if (In_view(pick_view = VIEW_MAP1, x, y)) {
	main_view = VIEW_MAP1;
	zoom_view = VIEW_MAP1_ZOOM;
	target_flag = 0;
    }
    else if (In_view(pick_view = VIEW_MAP2, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP2;
	zoom_view = VIEW_MAP2_ZOOM;
	target_flag = 1;
    }
    else if (In_view(pick_view = VIEW_MAP1_ZOOM, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP1;
	zoom_view = VIEW_MAP1_ZOOM;
	target_flag = 0;
    }
    else if (In_view(pick_view = VIEW_MAP2_ZOOM, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP2;
	zoom_view = VIEW_MAP2_ZOOM;
	target_flag = 1;
    }
    else
	return 0;		/* ignore the mouse event */
    if (!pick_view->cell.configured)
	return 0;		/* just to be sure */
    /*
     * make sure point is within edges of image as well
     */
    if (x <= pick_view->cell.left)
	return 0;
    if (x >= pick_view->cell.right)
	return 0;
    if (y <= pick_view->cell.top)
	return 0;
    if (y >= pick_view->cell.bottom)
	return 0;


    /*
     * ok, erase menu messages
     */
    Menu_msg("");

    /* determine magnification of zoom */
    if (zoom_view->cell.configured) {
	if (zoom_view == pick_view)
	    mag = floor(magnification(zoom_view) + 1.0) + .1;
	else
	    mag = ceil(magnification(zoom_view)) + .1;
    }
    else {
	mag = floor(magnification(main_view) + 1.0) + .1;
    }
    if (!ask_magnification(&mag))
	return 1;
    /* 
     * Determine the the zoom window (ie, cellhd)
     */

    G_copy(&cellhd, &main_view->cell.head, sizeof(cellhd));
    cellhd.ns_res = main_view->cell.ns_res / mag;
    cellhd.ew_res = main_view->cell.ew_res / mag;
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;
    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;


    /* convert x,y to col,row */

    col = view_to_col(pick_view, x);
    east = col_to_easting(&pick_view->cell.head, col, 0.5);
    col = easting_to_col(&cellhd, east);

    row = view_to_row(pick_view, y);
    north = row_to_northing(&pick_view->cell.head, row, 0.5);
    row = northing_to_row(&cellhd, north);

    ncols = zoom_view->ncols;
    nrows = zoom_view->nrows;


    n = cellhd.cols - col;
    if (n > col)
	n = col;
    if (n + n + 1 >= ncols) {
	n = ncols / 2;
	if (n + n + 1 >= ncols)
	    n--;
    }
    left = col - n;
    right = col + n;

    n = cellhd.rows - row;
    if (n > row)
	n = row;
    if (n + n + 1 >= nrows) {
	n = nrows / 2;
	if (n + n + 1 >= nrows)
	    n--;
    }
    top = row - n;
    bottom = row + n;


    north = row_to_northing(&cellhd, top, 0.0);
    west = col_to_easting(&cellhd, left, 0.0);
    south = row_to_northing(&cellhd, bottom, 1.0);
    east = col_to_easting(&cellhd, right, 1.0);


    cellhd.north = north;
    cellhd.south = south;
    cellhd.east = east;
    cellhd.west = west;

    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;

    /*
     * Outline the zoom window on the main map
     * Turn previous one to grey.
     */
    if (zoom_view->cell.configured) {
	R_standard_color(GREY);
	Outline_cellhd(main_view, &zoom_view->cell.head);
    }
    R_standard_color(RED);
    Outline_cellhd(main_view, &cellhd);


    /*
     * zoom
     */
    if (target_flag)
	select_target_env();
    G_copy(&zoom_view->cell.head, &cellhd, sizeof(cellhd));
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
		   pick_view->cell.ns_res, pick_view->cell.ew_res);
    drawcell(zoom_view);
    select_current_env();
    display_points(1);

    return 1;			/* pop back */
}
Beispiel #6
0
static int drawvect(int zoomit,	/* -1 = refresh, 0 = new image, 1 = zoom, 2 = warp */
		    View * zoom_view, double E[], double N[], int trans_order)
{				/* order of transformation if warping vectors */
    int stat = 0;
    int i;
    char name[GNAME_MAX], mapset[GMAPSET_MAX];
    struct Cell_head cellhd;
    struct line_pnts *Points;
    char msg[100], win_name[100];
    int t, b, l, r;
    int blank = 0;
    View *active_view;
    int left, top, nrows, ncols;
    static int vectclr[VFILES];


    /* if refresh screen or overlay & no displayed vector maps return */
    if ((zoomit == DO_REFRESH || zoomit == DO_WARP) && !numfiles) {
	if (zoomit == DO_REFRESH)
	    display_points(1);
	return 0;
    }

    /* numfiles stays at 0 until the end of the first vector map init */

    if (numfiles >= VFILES) {
	G_warning
	    ("Can't display another map; reached maximum number of files");
	return 0;
    }

    select_target_env();

    if (zoomit == DO_REFRESH || zoomit == DO_NEW) {	/* New Map File or Refresh Screen */

	if (zoomit == DO_NEW) {	/* zoomit==0, Draw New Map File */
	    if (!choose_vectfile(name, mapset))
		return 0;

	    strcpy(vect_file[numfiles], name);
	    strcpy(vect_mapset[numfiles], mapset);

	    get_vector_color();	/* ask line_color to draw map */

	    if (!numfiles) {	/* first map: SET VECTOR WINDOW BY WIND */
		G_get_window(&cellhd);
		G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd));
	    }
	    else		/* not the first map */
		G_copy(&cellhd, &VIEW_MAP2->cell.head,
		       sizeof(VIEW_MAP2->cell.head));

	    numfiles++;

	}
	else {			/* zoomit=-1 Refresh Screen */
	    G_copy(&cellhd, &VIEW_MAP2->cell.head,
		   sizeof(VIEW_MAP2->cell.head));

	    if (!cellmap_present)
		Erase_view(VIEW_MAP2_ZOOM);

	    VIEW_MAP2_ZOOM->cell.configured = 0;
	    blank = BLACK;
	}

	strcpy(win_name, "vect_map");
	if (!view2on) {
	    t = VIEW_MAP2->top;
	    b = VIEW_MAP2->bottom;
	    l = VIEW_MAP2->left;
	    r = VIEW_MAP2->right;
	    D_new_window(win_name, t, b, l, r);
	    if (!cellmap_present)
		blank = BLACK;
	    else
		blank = 0;	/* don't erase viewport */
	    view2on = 1;
	}

	active_view = VIEW_MAP2;
    }
    else {			/* zoomit>0   Zoom or Warp */

	G_copy(&cellhd, &zoom_view->cell.head, sizeof(zoom_view->cell.head));

	if (!(zoom_view == VIEW_MAP1)) {	/* target side */
	    VIEW_MAP2_ZOOM->cell.configured = 0;
	    strcpy(win_name, "zoom_map");
	    if (!view2zoomon) {
		t = VIEW_MAP2_ZOOM->top;
		b = VIEW_MAP2_ZOOM->bottom;
		l = VIEW_MAP2_ZOOM->left;
		r = VIEW_MAP2_ZOOM->right;
		D_new_window(win_name, t, b, l, r);
		view2zoomon = 1;

	    }
	    active_view = VIEW_MAP2_ZOOM;
	    blank = BLACK;
	}
	else {
	    strcpy(win_name, "warp_map");	/* defined in drawcell routine */
	    active_view = VIEW_MAP1;
	    blank = 0;		/* don't erase viewport */
	}
    }

    nrows = active_view->nrows;
    ncols = active_view->ncols;
    left = active_view->left;
    top = active_view->top;

    D_set_cur_wind(win_name);
    R_standard_color(YELLOW);
    Outline_box(top, top + nrows - 1, left, left + ncols - 1);
    Points = Vect_new_line_struct();

    if (zoomit != DO_WARP) {
	Curses_clear_window(INFO_WINDOW);
	Curses_write_window(INFO_WINDOW, 1, 13, "COORDINATES");
	Curses_write_window(INFO_WINDOW, 3, 2, "MAIN WINDOW");

	sprintf(msg, "N = %10.2f   E = %10.2f", VIEW_MAP2->cell.head.north,
		VIEW_MAP2->cell.head.east);
	Curses_write_window(INFO_WINDOW, 5, 4, msg);
	sprintf(msg, "S = %10.2f   W = %10.2f", VIEW_MAP2->cell.head.south,
		VIEW_MAP2->cell.head.west);
	Curses_write_window(INFO_WINDOW, 6, 4, msg);

	Curses_write_window(INFO_WINDOW, 9, 2, "ZOOM WINDOW");
	sprintf(msg, "N = %10.2f   E = %10.2f",
		VIEW_MAP2_ZOOM->cell.head.north,
		VIEW_MAP2_ZOOM->cell.head.east);
	Curses_write_window(INFO_WINDOW, 11, 4, msg);
	sprintf(msg, "S = %10.2f   W = %10.2f",
		VIEW_MAP2_ZOOM->cell.head.south,
		VIEW_MAP2_ZOOM->cell.head.west);
	Curses_write_window(INFO_WINDOW, 12, 4, msg);
    }

    if (zoomit) {		/* ie ! DO_NEW */

	dsp_setup(blank, &cellhd);

	for (i = 0; i < numfiles; i++) {
	    sprintf(msg, "Displaying %s", vect_file[i]);
	    Menu_msg(msg);
	    R_standard_color(vectclr[i]);
	    if (zoomit != DO_WARP)
		stat = plot(vect_file[i], vect_mapset[i], Points);
	    else
		stat = plot_warp(vect_file[i], vect_mapset[i],
				 Points, E, N, trans_order);
	}
    }
    else {			/* ie DO_NEW */

	if (numfiles == 1) {	/* let first file set window */
	    G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd));

	    cellhd.rows = VIEW_MAP2->nrows;
	    cellhd.cols = VIEW_MAP2->ncols;
	    cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
	    cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
	    if (cellhd.ns_res > cellhd.ew_res)
		cellhd.ew_res = cellhd.ns_res;
	    else
		cellhd.ns_res = cellhd.ew_res;

	    VIEW_MAP2->cell.ns_res = cellhd.ns_res;
	    VIEW_MAP2->cell.ew_res = cellhd.ew_res;

	    G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd));

	    G_adjust_window_to_box(&cellhd, &VIEW_MAP2->cell.head,
				   VIEW_MAP2->nrows, VIEW_MAP2->ncols);

	    if (!cellmap_present) {
		Configure_view(VIEW_MAP2, vect_file[numfiles - 1],
			       vect_mapset[numfiles - 1], cellhd.ns_res,
			       cellhd.ew_res);
	    }

	    Curses_write_window(INFO_WINDOW, 15, 2,
				"WHERE CURSOR-> Mid Button");
	}

	dsp_setup(blank, &cellhd);

	R_standard_color(YELLOW);
	Outline_box(top, top + nrows - 1, left, left + ncols - 1);

	sprintf(msg, "Displaying %s", vect_file[numfiles - 1]);
	Menu_msg(msg);

	R_standard_color(line_color);
	vectclr[numfiles - 1] = line_color;

	get_clr_name(vect_color[numfiles - 1], line_color);

	stat =
	    plot(vect_file[numfiles - 1], vect_mapset[numfiles - 1], Points);

    }

    display_points(1);

    R_standard_color(WHITE);
    Outline_box(top, top + nrows - 1, left, left + ncols - 1);

    Menu_msg("");

    Vect_destroy_line_struct(Points);

    /*    VIEW_MAP2->cell.configured = 1; XXX */

    select_current_env();
    if (from_screen < 0) {
	from_flag = 1;
	from_screen = 0;
	if (from_keyboard < 0) {
	    from_keyboard = 0;
	    from_screen = 1;
	}
    }

    if (numfiles) {
	Curses_clear_window(MENU_WINDOW);
	Curses_write_window(MENU_WINDOW, 1, 5, "COLOR  MAP FILE");
	for (i = 0; i < numfiles; i++) {
	    sprintf(msg, "%7s  %s", vect_color[i], vect_file[i]);
	    Curses_write_window(MENU_WINDOW, i + 3, 3, msg);
	}
    }

    return 0;
}
Beispiel #7
0
static int zoom2(int x, int y)
{
    int top, bottom, left, right;
    int row, col;
    struct Cell_head cellhd;

    x2 = x;
    y2 = y;
    /* 
     * user has completed the zoom window.
     * must be in same view as first corner
     */
    if (x1 == x2 || y1 == y2)
	return 0;		/* ignore event */
    if (!In_view(pick_view, x2, y2))
	return 0;
    /*
     * ok, erase menu messages
     */
    Menu_msg("");

    /*
     * assign window coordinates to top,bottom,left,right
     */
    if (x1 < x2) {
	left = x1;
	right = x2;
    }
    else {
	left = x2;
	right = x1;
    }
    if (y1 < y2) {
	top = y1;
	bottom = y2;
    }
    else {
	top = y2;
	bottom = y1;
    }

    /* 
     * Determine the the zoom window (ie, cellhd)
     * must copy the current view cellhd first, to preserve header info
     * (such as projection, zone, and other items.)
     * compute zoom window northings,eastings, rows, cols, and resolution
     */

    G_copy(&cellhd, &pick_view->cell.head, sizeof(cellhd));

    /* convert top to northing at top edge of cell
     * left to easting at left edge
     */
    col = view_to_col(pick_view, left);
    row = view_to_row(pick_view, top);
    cellhd.north = row_to_northing(&pick_view->cell.head, row, 0.0);
    cellhd.west = col_to_easting(&pick_view->cell.head, col, 0.0);

    /* convert bottom to northing at bottom edge of cell
     * right to easting at right edge
     */
    col = view_to_col(pick_view, right);
    row = view_to_row(pick_view, bottom);
    cellhd.south = row_to_northing(&pick_view->cell.head, row, 1.0);
    cellhd.east = col_to_easting(&pick_view->cell.head, col, 1.0);


    cellhd.rows = bottom - top + 1;
    cellhd.cols = right - left + 1;
    cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
    cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;

    /*
     * Outline the zoom window on the main map
     * Turn previous one to grey.
     */
    if (zoom_view->cell.configured) {
	R_standard_color(GREY);
	Outline_cellhd(main_view, &zoom_view->cell.head);
    }
    R_standard_color(RED);
    Outline_cellhd(main_view, &cellhd);


    /*
     * zoom
     */
    if (target_flag)
	select_target_env();
    G_adjust_window_to_box(&cellhd, &zoom_view->cell.head, zoom_view->nrows,
			   zoom_view->ncols);
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
		   pick_view->cell.ns_res, pick_view->cell.ew_res);
    drawcell(zoom_view);
    select_current_env();
    display_ref_points(1);
    return 1;			/* pop back */
}
Beispiel #8
0
int main(int argc, char **argv)
{
    struct GModule *module;
    int i, first = 1;
    char *mapset;
    char **rast, **vect;
    int nrasts, nvects;
    struct Cell_head window, temp_window;

    G_gisinit(argv[0]);

    module = G_define_module();
    module->keywords = _("display, setup");
    module->description =
	"Sets window region so that all currently displayed raster "
	"and vector maps can be shown in a monitor.";

    if (argc > 1 && G_parser(argc, argv))
	exit(-1);


    if (R_open_driver() != 0)
	G_fatal_error(_("No graphics device selected"));

    if (D_get_cell_list(&rast, &nrasts) < 0)
	rast = NULL;

    if (D_get_dig_list(&vect, &nvects) < 0)
	vect = NULL;

    R_close_driver();

    if (rast == NULL && vect == NULL)
	G_fatal_error(_("No raster or vector map displayed"));

    G_get_window(&window);

    if (rast) {
	for (i = 0; i < nrasts; i++) {
	    mapset = G_find_cell2(rast[i], "");
	    if (mapset == NULL)
		G_fatal_error(_("Raster map <%s> not found"), rast[i]);
	    if (G_get_cellhd(rast[i], mapset, &temp_window) >= 0) {
		if (first) {
		    first = 0;
		    G_copy(&window, &temp_window, sizeof(window));
		}
		else {
		    if (window.east < temp_window.east)
			window.east = temp_window.east;
		    if (window.west > temp_window.west)
			window.west = temp_window.west;
		    if (window.south > temp_window.south)
			window.south = temp_window.south;
		    if (window.north < temp_window.north)
			window.north = temp_window.north;
		    /*
		       if(window.ns_res < nsres)
		       nsres = window.ns_res;
		       if(window.ew_res < ewres)
		       ewres = window.ew_res;
		     */
		}
	    }
	}

	G_adjust_Cell_head3(&window, 0, 0, 0);
    }

    if (vect) {
	struct Map_info Map;

	G_copy(&temp_window, &window, sizeof(window));

	Vect_set_open_level(2);
	for (i = 0; i < nvects; i++) {
	    mapset = G_find_vector2(vect[i], "");
	    if (mapset == NULL)
		G_fatal_error(_("Vector map <%s> not found"), vect[i]);
	    if (Vect_open_old_head(&Map, vect[i], mapset) == 2) {
		if (first) {
		    first = 0;
		    window.east = Map.plus.box.E;
		    window.west = Map.plus.box.W;
		    window.south = Map.plus.box.S;
		    window.north = Map.plus.box.N;
		}
		else {
		    if (window.east < Map.plus.box.E)
			window.east = Map.plus.box.E;
		    if (window.west > Map.plus.box.W)
			window.west = Map.plus.box.W;
		    if (window.south > Map.plus.box.S)
			window.south = Map.plus.box.S;
		    if (window.north < Map.plus.box.N)
			window.north = Map.plus.box.N;
		}
		Vect_close(&Map);
	    }
	}

	if (window.north == window.south) {
	    window.north += 0.5 * temp_window.ns_res;
	    window.south -= 0.5 * temp_window.ns_res;
	}
	if (window.east == window.west) {
	    window.east += 0.5 * temp_window.ew_res;
	    window.west -= 0.5 * temp_window.ew_res;
	}

	G_align_window(&window, &temp_window);
    }

    G_adjust_Cell_head3(&window, 0, 0, 0);
    G_put_window(&window);

    exit(0);
}
Beispiel #9
0
int main(int , char* [])
{
    typedef boost::adjacency_list<
    boost::mapS, boost::vecS, boost::bidirectionalS,
          boost::property<boost::vertex_color_t, boost::default_color_type,
          boost::property<boost::vertex_degree_t, int,
          boost::property<boost::vertex_in_degree_t, int,
          boost::property<boost::vertex_out_degree_t, int> > > >
          > Graph;

    Graph G(5);
    boost::add_edge(0, 2, G);
    boost::add_edge(1, 1, G);
    boost::add_edge(1, 3, G);
    boost::add_edge(1, 4, G);
    boost::add_edge(2, 1, G);
    boost::add_edge(2, 3, G);
    boost::add_edge(2, 4, G);
    boost::add_edge(3, 1, G);
    boost::add_edge(3, 4, G);
    boost::add_edge(4, 0, G);
    boost::add_edge(4, 1, G);

    typedef Graph::vertex_descriptor Vertex;

    Graph G_copy(5);
    // Array to store predecessor (parent) of each vertex. This will be
    // used as a Decorator (actually, its iterator will be).
    std::vector<Vertex> p(boost::num_vertices(G));
    // VC++ version of std::vector has no ::pointer, so
    // I use ::value_type* instead.
    typedef std::vector<Vertex>::value_type* Piter;

    // Array to store distances from the source to each vertex .  We use
    // a built-in array here just for variety. This will also be used as
    // a Decorator.
    boost::graph_traits<Graph>::vertices_size_type d[5];
    std::fill_n(d, 5, 0);

    // The source vertex
    Vertex s = *(boost::vertices(G).first);
    p[s] = s;
    boost::breadth_first_search
    (G, s,
     boost::visitor(boost::make_bfs_visitor
                    (std::make_pair(boost::record_distances(d, boost::on_tree_edge()),
                                    std::make_pair
                                    (boost::record_predecessors(&p[0],
                                            boost::on_tree_edge()),
                                     copy_graph(G_copy, boost::on_examine_edge())))) ));

    boost::print_graph(G);
    boost::print_graph(G_copy);

    if (boost::num_vertices(G) < 11) {
        std::cout << "distances: ";
#ifdef BOOST_OLD_STREAM_ITERATORS
        std::copy(d, d + 5, std::ostream_iterator<int, char>(std::cout, " "));
#else
        std::copy(d, d + 5, std::ostream_iterator<int>(std::cout, " "));
#endif
        std::cout << std::endl;

        std::for_each(boost::vertices(G).first, boost::vertices(G).second,
                      print_parent<Piter>(&p[0]));
    }

    return 0;
}