Ejemplo n.º 1
0
dias::mbr get_segment_mbr (const bbp::Segment & s,
                           const dias::global_transformer & gtrafo)
{
  bbp::Vector_3D<bbp::Micron> gbegin = gtrafo * s.begin().center();
  bbp::Vector_3D<bbp::Micron> gend = gtrafo * s.end().center();

  float transformed_begin_radius = transform_distance(gtrafo,
                                                      s.begin().radius());
  float transformed_end_radius = transform_distance(gtrafo, s.end().radius());

  bbp::Box<bbp::Micron> box
    = bbp::AABBCylinder::calculateAABBForCylinder(gbegin,
                                                  transformed_begin_radius,
                                                  gend,
                                                  transformed_end_radius);
  vect low, high;
  low[0] = box.center().x() - box.dimensions().x() / 2;
  high[0] = box.center().x() + box.dimensions().x() / 2;
  low[1] = box.center().y() - box.dimensions().y() / 2;
  high[1] = box.center().y() + box.dimensions().y() / 2;
  low[2] = box.center().z() - box.dimensions().z() / 2;
  high[2] = box.center().z() + box.dimensions().z() / 2;

  return dias::mbr (low, high);
}
Ejemplo n.º 2
0
double
transform_polyline_length(enum projection pro, struct coord *c, int count)
{
	double ret=0;
	int i;

	for (i = 0 ; i < count-1 ; i++) 
		ret+=transform_distance(pro, &c[i], &c[i+1]);
	return ret;
}
Ejemplo n.º 3
0
void
compass_draw(struct compass *comp, struct container *co)
{
	struct point p;
	struct coord *pos, *dest;
	double *vehicle_dir,dir,distance;
	int dx,dy;
	char buffer[16];

	if (! co->vehicle)
		return;

	vehicle_dir=vehicle_dir_get(co->vehicle);
	comp->gr->draw_mode(comp->gr, draw_mode_begin);
	p.x=0;
	p.y=0;
	comp->gr->draw_rectangle(comp->gr, comp->bg, &p, 60, 80);
	p.x=30;
	p.y=30;
	comp->gr->draw_circle(comp->gr, comp->white, &p, 50);
	if (co->flags->orient_north)
		handle(comp->gr,comp->white, &p, 20,0);
	else
		handle(comp->gr, comp->white, &p, 20, -*vehicle_dir);
#if 0 /* FIXME */
	dest=route_get_destination(co->route);
	if (dest) {
		pos=vehicle_pos_get(co->vehicle);	
		dx=dest->x-pos->x;
		dy=dest->y-pos->y;
		dir=atan2(dx,dy)*180.0/M_PI;
#if 0
		printf("dx %d dy %d dir=%f vehicle_dir=%f\n", dx, dy, dir, *vehicle_dir);
#endif
		if (! co->flags->orient_north)
			dir-=*vehicle_dir;
		handle(comp->gr, comp->green, &p, 20, dir);
		p.x=8;
		p.y=72;
		distance=transform_distance(pos, dest)/1000.0;
		if (distance >= 100)
			sprintf(buffer,"%.0f km", distance);
		else if (distance >= 10)
			sprintf(buffer,"%.1f km", distance);
		else
			sprintf(buffer,"%.2f km", distance);

		comp->gr->draw_text(comp->gr, comp->green, NULL, comp->font, buffer, &p, 0x10000, 0);
	}
#endif
	comp->gr->draw_mode(comp->gr, draw_mode_end);
}
Ejemplo n.º 4
0
static void
vehicle_demo_timer(struct vehicle_priv *priv)
{
	struct coord c, c2, pos, ci;
	int slen, len, dx, dy;
	struct route *route=NULL;
	struct map *route_map=NULL;
	struct map_rect *mr=NULL;
	struct item *item=NULL;

	len = (priv->config_speed * priv->interval / 1000)/ 3.6;
	dbg(1, "###### Entering simulation loop\n");
	if (!priv->config_speed)
		return;
	if (priv->route)
		route=priv->route;
	else if (priv->navit) 
		route=navit_get_route(priv->navit);
	if (route)
		route_map=route_get_map(route);
	if (route_map)
		mr=map_rect_new(route_map, NULL);
	if (mr)
		item=map_rect_get_item(mr);
	if (item && item->type == type_route_start)
		item=map_rect_get_item(mr);
	while(item && item->type!=type_street_route)
		item=map_rect_get_item(mr);
	if (item && item_coord_get(item, &pos, 1)) {
		priv->position_set=0;
		dbg(1, "current pos=0x%x,0x%x\n", pos.x, pos.y);
		dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y);
		if (priv->last.x == pos.x && priv->last.y == pos.y) {
			dbg(1, "endless loop\n");
		}
		priv->last = pos;
		while (item && priv->config_speed) {
			if (!item_coord_get(item, &c, 1)) {
				item=map_rect_get_item(mr);
				continue;
			}
			dbg(1, "next pos=0x%x,0x%x\n", c.x, c.y);
			slen = transform_distance(projection_mg, &pos, &c);
			dbg(1, "len=%d slen=%d\n", len, slen);
			if (slen < len) {
				len -= slen;
				pos = c;
			} else {
				if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) {
					dx = c.x - pos.x;
					dy = c.y - pos.y;
					ci.x = pos.x + dx * len / slen;
					ci.y = pos.y + dy * len / slen;
					priv->direction =
					    transform_get_angle_delta(&pos, &c, 0);
					priv->speed=priv->config_speed;
				} else {
					ci.x = pos.x;
					ci.y = pos.y;
					priv->speed=0;
					dbg(0,"destination reached\n");
				}
				dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y);
				transform_to_geo(projection_mg, &ci,
						 &priv->geo);
				callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
				break;
			}
		}
	} else {
		if (priv->position_set) 
			callback_list_call_attr_0(priv->cbl, attr_position_coord_geo);
	}
	if (mr)
		map_rect_destroy(mr);
}
Ejemplo n.º 5
0
static void
navit_window_items_open(struct menu *men, struct navit *this_, struct navit_window_items *nwi)
{
	struct map_selection sel;
	struct coord c,*center;
	struct mapset_handle *h;
	struct map *m;
	struct map_rect *mr;
	struct item *item;
	struct attr attr;
	int idist,dist;
	struct param_list param[5];
	char distbuf[32];
	char dirbuf[32];
	char coordbuf[64];
	
	dbg(0, "distance=%d\n", nwi->distance);
	if (nwi->distance == -1) 
		dist=40000000;
	else
		dist=nwi->distance*1000;
	param[0].name="Distance";
	param[1].name="Direction";
	param[2].name="Type";
	param[3].name="Name";
	param[4].name=NULL;
	sel.next=NULL;
#if 0
	sel.order[layer_town]=18;
	sel.order[layer_street]=18;
	sel.order[layer_poly]=18;
#else
	sel.order[layer_town]=0;
	sel.order[layer_street]=0;
	sel.order[layer_poly]=0;
#endif
	center=transform_center(this_->trans);
	sel.rect.lu.x=center->x-dist;
	sel.rect.lu.y=center->y+dist;
	sel.rect.rl.x=center->x+dist;
	sel.rect.rl.y=center->y-dist;
	dbg(2,"0x%x,0x%x - 0x%x,0x%x\n", sel.rect.lu.x, sel.rect.lu.y, sel.rect.rl.x, sel.rect.rl.y);
	nwi->click=callback_new_2(navit_window_items_click, this_, nwi);
	nwi->win=gui_datawindow_new(this_->gui, nwi->name, nwi->click, NULL);
	h=mapset_open(navit_get_mapset(this_));
        while ((m=mapset_next(h, 1))) {
		dbg(2,"m=%p %s\n", m, map_get_filename(m));
		mr=map_rect_new(m, &sel);
		dbg(2,"mr=%p\n", mr);
		while ((item=map_rect_get_item(mr))) {
			if (item_coord_get(item, &c, 1)) {
				if (coord_rect_contains(&sel.rect, &c) && g_hash_table_lookup(nwi->hash, &item->type)) {
					if (! item_attr_get(item, attr_label, &attr)) 
						attr.u.str="";
					idist=transform_distance(center, &c);
					if (idist < dist) {
						get_direction(dirbuf, transform_get_angle_delta(center, &c, 0), 1);
						param[0].value=distbuf;	
						param[1].value=dirbuf;
						param[2].value=item_to_name(item->type);
						sprintf(distbuf,"%d", idist/1000);
						param[3].value=attr.u.str;
						sprintf(coordbuf, "0x%x,0x%x", c.x, c.y);
						param[4].value=coordbuf;
						datawindow_add(nwi->win, param, 5);
					}
					/* printf("gefunden %s %s %d\n",item_to_name(item->type), attr.u.str, idist/1000); */
				}
				if (item->type >= type_line) 
					while (item_coord_get(item, &c, 1));
			}
		}
		map_rect_destroy(mr);	
	}
	mapset_close(h);
}
Ejemplo n.º 6
0
static int
vehicle_demo_timer(struct vehicle_priv *priv)
{
	struct route_path_coord_handle *h;
	struct coord *c, *pos, ci;
	int slen, len, dx, dy;

	priv->speed = 40;
	len = priv->speed / 3.6;
	dbg(1, "###### Entering simulation loop\n");
	if (!priv->navit) {
		dbg(1, "vehicle->navit is not set. Can't simulate\n");
		return 1;
	}
	struct route *vehicle_route = navit_get_route(priv->navit);
	if (!vehicle_route) {
		dbg(1, "navit_get_route NOK\n");
		return 1;
	}

	h = route_path_coord_open(vehicle_route);
	if (!h) {
		dbg(1, "navit_path_coord_open NOK\n");
		return 1;
	}
	pos = route_path_coord_get(h);
	dbg(1, "current pos=%p\n", pos);
	if (pos) {
		dbg(1, "current pos=0x%x,0x%x\n", pos->x, pos->y);
		if (priv->last.x == pos->x && priv->last.y == pos->y) {
			dbg(1, "endless loop\n");
		}
		priv->last = *pos;
		for (;;) {
			c = route_path_coord_get(h);
			dbg(1, "next pos=%p\n", c);
			if (!c)
				break;
			dbg(1, "next pos=0x%x,0x%x\n", c->x, c->y);
			slen = transform_distance(projection_mg, pos, c);
			dbg(1, "len=%d slen=%d\n", len, slen);
			if (slen < len) {
				len -= slen;
				pos = c;
			} else {
				dx = c->x - pos->x;
				dy = c->y - pos->y;
				ci.x = pos->x + dx * len / slen;
				ci.y = pos->y + dy * len / slen;
				priv->direction =
				    transform_get_angle_delta(pos, c, 0);
				dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y);
				transform_to_geo(projection_mg, &ci,
						 &priv->geo);
				callback_list_call_0(priv->cbl);
				break;
			}
		}
	}
	return 1;
}