Beispiel #1
0
static void generate_grid(DATA *d, double samplespacing, int neighbourhood) {
	DPOINT pt;
	int i, j, n;

	d->n_list = d->n_sel = 0;
	qtree_free(d->qtree_root);
	d->qtree_root = NULL;
	pt.z = 0.0;
	pt.attr = 0.0;
	n = floor(sqrt(neighbourhood)) / 2 + 1;
	d->maxX = d->maxY = n * samplespacing;
	d->minX = d->minY = -n * samplespacing;
	gl_split = 4 * n * n;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			pt.x = (i + 0.5) * samplespacing;
			pt.y = (j + 0.5) * samplespacing;
			push_point(d, &pt); /* NE */
			pt.y *= -1;
			push_point(d, &pt); /* SE */
			pt.x *= -1;
			push_point(d, &pt); /* SW */
			pt.y *= -1;
			push_point(d, &pt); /* NE */
		}
	}
	d->sel_max = neighbourhood;
	return;
}
Beispiel #2
0
void path_points::best_filtration(m2::PointD const & pt)
{
  if (m_hasPrevPt)
  {
    m2::PointD prev = m_prev;
    m2::PointD curr = pt;

    double const segLen = curr.Length(prev);

    if ((m_startLength != 0) && (m_endLength != 0))
    {
      if ((m_startLength >= m_length) && (m_startLength < m_length + segLen))
        m_startLength = m_length;

      if ((m_endLength > m_length) && (m_endLength <= m_length + segLen))
        m_endLength = m_length + segLen;
    }

    if ((m_length >= m_startLength) && (m_endLength >= m_length + segLen))
    {
      /// we're in the dead zone. add without clipping
      if (m_newPL)
        StartPL(prev);

      push_point(curr);
    }
    else
    {
      if (!m2::Intersect(m_rect, prev, curr))
        m_newPL = true;
      else
      {
        if (!equal_glb_pts(prev, m_prev))
          m_newPL = true;

        if (m_newPL)
          StartPL(prev);

        push_point(curr);

        if (!equal_glb_pts(curr, pt))
          m_newPL = true;
      }
    }

    m_length += segLen;
  }
  else
  {
    m_hasPrevPt = true;
    m_length = 0.0;
  }

  m_prev = pt;
}
Beispiel #3
0
void cut_path_intervals::operator()(m2::PointD const & pt)
{
  if (m_hasPrevPt)
  {
    double const segLen = pt.Length(m_prev);

    for (; m_pos != m_intervals->size(); m_pos += 2)
    {
      double const start = (*m_intervals)[m_pos];
      if (start >= m_length + segLen)
        break;

      m2::PointD const dir = (pt - m_prev) / segLen;

      if (start >= m_length)
      {
        m_points.push_back(PathInfo(start));
        push_point(m_prev + dir * (start - m_length));
      }

      double const end = (*m_intervals)[m_pos+1];
      if (end >= m_length + segLen)
      {
        push_point(pt);
        break;
      }

      if (end < m_length + segLen)
      {
        push_point(m_prev + dir * (end - m_length));
#ifdef DEBUG
        double const len = m_points.back().GetLength();
        ASSERT_LESS_OR_EQUAL ( fabs(len - (end - start)), 1.0E-4, (len, end - start) );
#endif
      }
    }

    m_prev = pt;
    m_length += segLen;
  }
  else
  {
    m_hasPrevPt = true;
    m_prev = pt;
  }
}
Beispiel #4
0
void path_points::StartPL(m2::PointD const & pt)
{
  EndPL();

  m_points.push_back(PathInfo(m_length + m_prev.Length(pt)));
  push_point(pt);

  m_newPL = false;
}
Beispiel #5
0
DATA *get_area_centre(DATA *area, DATA *d) {
	int i, j;
	DPOINT p;

	d->n_list = d->n_max = 0; 
	d->variable = area->variable;
	d->x_coord = area->x_coord;
	d->y_coord = area->y_coord;
	d->z_coord = area->z_coord;
	d->type = data_types[area->type.type];
	d->fname = "";

	p.x = p.y = p.z = 0.0;
	p.u.stratum = 0;
	d->n_X = area->n_X;
	if (area->n_X > 0) {
		p.X = (double *) emalloc(area->n_X * sizeof(double));
		d->colX = (int *) emalloc(area->n_X * sizeof(int));
		for (j = 0; j < area->n_X; j++) {
			p.X[j] = 0.0;
			d->colX[j] = area->colX[j];
		}
	} else {
		p.X = NULL;
		d->colX = NULL;
	}
	for (i = 0; i < area->n_list; i++) {
		p.x += area->list[i]->x;
		p.y += area->list[i]->y;
		p.z += area->list[i]->z;
		for (j = 0; j < area->n_X; j++)
			p.X[j] += area->list[i]->X[j]; 
	}
	p.x /= area->n_list;
	p.y /= area->n_list;
	p.z /= area->n_list;
	for (j = 0; j < area->n_X; j++)
		p.X[j] /= area->n_list;
	p.attr = 0.0;

	printlog("prediction centre at x=%g, y=%g, z=%g",p.x,p.y,p.z);
	if (d->n_X) {
		printlog(" where x0 averages [");
		for (j = 0; j < area->n_X; j++)
			printlog("%g%s", p.X[j], j<area->n_X-1?",":"");
		printlog("]\n");
	} else
		printlog("\n");
	push_point(d, &p);
	d->minX = d->maxX = p.x;
	d->minY = d->maxY = p.y;
	d->minZ = d->maxZ = p.z;
	d->mode = area->mode;
	d->n_X = area->n_X;
	calc_data_mean_std(d);
	return d;
}
Beispiel #6
0
void SimplePolylineConvex::push_point(PointD const& p)
{
    if (vertices_.size() < 2
            || is_left(*(vertices_.end() - 2), *(vertices_.end() - 1), p))
        vertices_.push_back(p);
    else {
        // the middle point (the last one currently in vertices_) is not convex
        // remove it and check again the last three points
        vertices_.pop_back();
        push_point(p);
    }
}
Beispiel #7
0
void handle_mouse(const int btn, const int state, const int x, const int y)
{
  if(state != GLUT_DOWN) return;
  switch(btn) {
  case GLUT_LEFT_BUTTON:
    push_point(x, y);
    break;
  case GLUT_RIGHT_BUTTON:
    discard_top();
    break;
  default: break;
  }
  glutPostRedisplay();
}
Beispiel #8
0
	bool KL2Map_Base::FindPath(int_r from, int_r to, __Nodes& st, VALUE_T& cost)
	{	PERF_COUNTER(KL2Map_Base_FindPath);

		cost = 0;
		st.clear();
		if (from == to)
		{
			const _Node_Lite * p = Find(from);
			if (p)
			{
				push_point(st, p);
			}
			return st.size() != 0;
		}

		JG_C::DynArray<int_r> nodeIDs;
		if (m_pFinder)
		{
			if (m_pFinder->GetPath(from, to, nodeIDs, cost) > 0)
			{
				int_r d1 = nodeIDs[0];
				int_r d2 = 0;
				for (int_r i = 1; i < nodeIDs.size(); i++)
				{
					d2 = nodeIDs[i];
					const __OneRoad * pr = GetRoad(d1, d2);
					if ( pr != NULL )
					{
						//正向填充
						for (int_r j = 0; j < pr->m_Road.size(); j++)
						{
							if (st.size() > 0 && st[st.size() - 1] == pr->m_Road[j])
							{
								continue;
							}
							st.push_back(pr->m_Road[j]);
						}
					}
					d1 = d2;
				}
				return true;
			}
			else
			{
				return false;
			}
		}
		return false;
	}
Beispiel #9
0
void add_virtual_obstacles(){

    int dis_Y = Y1 - Y0;
    int dis_X = X1 - X0;
    int interval_Y = dis_Y / (VIRTUAL_NUMBER - 1);
    int interval_X = dis_X / (VIRTUAL_NUMBER - 1);
    printf("-------------------print the virtual obstacles---------------\n");
    int i=1;
    for (; i<VIRTUAL_NUMBER-1 ; i++){
        int p_x = X0 + i*interval_X;
        point_t p_with_Y0 = build_point(p_x, Y0);
        point_t p_with_Y1 = build_point(p_x, Y1);

        print_point(&p_with_Y0);
        print_point(&p_with_Y1);
        push_point(p_with_Y0);
        push_point(p_with_Y1);
    }
    i = 1;
    for(; i<VIRTUAL_NUMBER-1; i++){
        int p_y = Y0 + i*interval_Y;
        point_t p_with_X0 = build_point(X0, p_y);
        point_t p_with_X1 = build_point(X1, p_y);

        print_point(&p_with_X0);
        print_point(&p_with_X1);
        push_point(p_with_X0);
        push_point(p_with_X1);
    }

    point_t X0Y0 = build_point(X0, Y0);
    point_t X0Y1 = build_point(X0, Y1);
    point_t X1Y0 = build_point(X1, Y0);
    point_t X1Y1 = build_point(X1, Y1);
    push_point(X0Y0);
    push_point(X0Y1);
    push_point(X1Y0);
    push_point(X1Y1);

    print_point(&X0Y0);
    print_point(&X0Y1);
    print_point(&X1Y0);
    print_point(&X1Y1);
    printf("----------------virtual obstacles---------------\n");

 }
Beispiel #10
0
void path_points::simple_filtration(m2::PointD const & pt)
{
  if (m_hasPrevPt)
  {
    if (!m2::RectD(m_prev, pt).IsIntersect(m_rect))
      m_newPL = true;
    else
    {
      if (m_newPL)
        StartPL(m_prev);

      push_point(pt);
    }

    m_length += m_prev.Length(pt);
  }
  else
  {
    m_hasPrevPt = true;
    m_length = 0.0;
  }

  m_prev = pt;
}
Beispiel #11
0
void area_tess_points::operator() (m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3)
{
  push_point(p1);
  push_point(p2);
  push_point(p3);
}
Beispiel #12
0
void generate_voronoi(struct point *p_array, int num){
    init_voronoi();
    //  printf("init memory succed\n");
    X0=0;
    Y0=0;
    X1=2000;
    Y1=2000;

    if(num >= POINT_POOL_SIZE){
        v_error("the number of points is out of bound");
        return;
    }

    int i;
    for (i=0; i<num; i++){
        push_point(p_array[i]);
        //   printf("%f, %f\n", p_array[i].x,  p_array[i].y);
        if(p_array[i].x < X0) X0 = p_array[i].x;
        if(p_array[i].y < Y0) Y0 = p_array[i].y;
        if(p_array[i].x > X1) X1 = p_array[i].x;
        if(p_array[i].y > Y1) Y1 = p_array[i].y;

    }
    add_virtual_obstacles();
    points_quicksort();

    /* X0=0; */
    /* Y0=0; */
    /* X1=2500; */
    /* Y1=2500; */
    //   printf("quicksort finished \n");
    //   printf("%f, %f, %f, %f\n\n\n", X0, Y0, X1,Y1);

    //add 20% margins to the bounding box
    /* double dx = (X1-X0+1)/5.0; */
    /* double dy = (Y1-Y0+1)/5.0; */
    /* X0 -= dx; */
    /* X1 += dx; */
    /* Y0 -= dy; */
    /* Y1 += dy; */
    // printf("%f, %f, %f, %f\n\n\n", X0, Y0, X1,Y1);

    while (!is_pp_empty()){
        if(!is_ep_empty()){
             event_t * top_e = top_event();
             point_t top_p = top_point();
             if(top_e->x <= top_p.x){
                 process_event();
             }else{
                 process_point();
             }

        }else{
            process_point();
        }

    }

    //   print_arc_list();
    while(!is_ep_empty()){
        process_event();
    }
    finish_edges();
    rebuild_seg_list(&seg_list);
    int k;
    char *buf=malloc(sizeof(char)*1024);
    int pcount=0;
    for(k=0;k<seg_list.segs_count;k++){
        pcount+=sprintf(&buf[pcount],"%d;%d;%d;%d",k,seg_list.segs[k]->start.x,seg_list.segs[k]->start.y,seg_list.segs[k]->end.x,seg_list.segs[k]->end.y);
    }
    send_raw_eth_chn(34,buf,603);
}