Ejemplo n.º 1
0
void MyFigureGlut::GetBoundingBoxOfPoints(const PointCloud& pts, Cuboid* out)
{
  assert(out);
  out->min_x = out->min_y = out->min_z =  FLT_MAX;
  out->max_x = out->max_y = out->max_z = -FLT_MAX;

  PointCloud::ConstIterator p = pts.Begin();
  while(p != pts.End()) {
    if ( p->x < out->min_x )  out->min_x = p->x;
    if ( p->y < out->min_y )  out->min_y = p->y;
    if ( -p->z < out->min_z )  out->min_z = -p->z;
    if ( p->x > out->max_x )  out->max_x = p->x;
    if ( p->y > out->max_y )  out->max_y = p->y;
    if ( -p->z > out->max_z )  out->max_z = -p->z;
	p++;
  }
}
Ejemplo n.º 2
0
//same as SetPoints except for x,y scaling
void MyFigureGlut::SetDepthPoints(PointCloud& pts, int win_width, int win_height)
{
  PointCloud::ConstIterator p = pts.Begin();
  ColoredPoint temp;
  int cnt=0;
  float x_full, y_full;
  x_full=pts.Max().x - pts.Min().x;
  y_full=pts.Max().y - pts.Min().y;

	while(p != pts.End())
	{
		if(p->x != 0)
		{
			temp.x=(float)(((float(cnt%win_width))*x_full)/win_width) + pts.Min().x;
			temp.y=(float)(((float(cnt/win_width))*y_full)/win_height) + pts.Min().y;
			temp.z=(*p).z;
			temp.color=(*p).color;
			m_pts.Add(temp);
		}
		p++;
		cnt++;
	}

  // back up viewpoint so we can see points
  {
    Cuboid box;
    GetBoundingBoxOfPoints(pts, &box);
    if(auto_adjust) {
		float zmax = box.max_z;
		// if zmax is too small, the object cannot be displayed.(?????)
		if ( zmax > 0 && zmax < 1) zmax += 1;  //zmax could be zero.
		if ( zmax == 0) zmax += 1.5;  
		SetTranslation(0, 0, -zmax);
	}
  }
}