Esempio n. 1
0
Camera
cameraFromBBox(AxisAlignedBox3 const & bbox, int width, int height, Matrix3 const & rotation)
{
  static Real const DIST = 10;

  Real aspect_ratio = (width / (Real)height);
  Real left, right, bottom, top;
  if (aspect_ratio > 1)
  {
    left = -aspect_ratio;
    right = aspect_ratio;
    bottom = -1;
    top = 1;
  }
  else
  {
    left = -1;
    right = 1;
    bottom = -1.0f / aspect_ratio;
    top = 1.0f / aspect_ratio;
  }

  Vector3 rot_z = rotation * Vector3::unitZ();
  Vector3 rot_y = rotation * Vector3::unitY();

  Vector3 c = bbox.getCenter();
  Real scale = bbox.getExtent().length();
  CoordinateFrame3 cframe = CoordinateFrame3::fromViewFrame(c + DIST * scale * rot_z, c, rot_y);

  return Camera(cframe, Camera::ProjectionType::PERSPECTIVE, left / DIST, right / DIST, bottom / DIST, top / DIST,
                1.7f, (DIST + 1) * scale, Camera::ProjectedYDirection::UP);
}
Esempio n. 2
0
bool is_tetra_inside(Tetrahedral tetra, AxisAlignedBox3 bbox){
	assert(bbox.isNull()!=true);

	list<Vector3> points = tetra.get_sample_points();
	bool is_inside=false;

	assert(points.size()==4);

	for(auto it_pt= points.begin();it_pt!=points.end();++it_pt)
		is_inside = is_inside || bbox.contains(*it_pt);

	return is_inside;
}
void PointKDTree::rangeQuery(AxisAlignedBox3 const & query, std::vector<Point *> & points_in_range) const
{
  points_in_range.clear();

  // Write a helper function rangeQuery(node, query, points_in_range):
  //   - If node->bbox does not intersect query, return
  //   - If node->lo && node->lo->bbox intersects query, rangeQuery(node->lo, query, points_in_range)
  //   - If node->hi && node->hi->bbox intersects query, rangeQuery(node->hi, query, points_in_range)
  if(!(root->bbox).intersects(query))
		return;
	if((root->points).size()!=0)
	{
		for(int i=0;i<(int)(root->points).size();i++)
		{
			Vector3 rootPoint = root->points[i]->getPosition();
			if(query.contains(rootPoint))
				points_in_range.push_back(root->points[i]);
		}
		return;
	}
	if((root->lo->bbox).intersects(query))
		rangeQuery(root->lo, query, points_in_range);
	if((root->hi->bbox).intersects(query))
		rangeQuery(root->hi, query, points_in_range);
  
}
Esempio n. 4
0
void find_grid(AxisAlignedBox3 bbox, float reso,vector<unsigned int> *no_planes){
	/*This function finds the number of x, y and z planes that can fit in a given bounding box. The resolution(scaling factor) needed for the grid is specified as reso. This function fills up the no_planes vector by the number of x,y and z planes which will be able to fit in the bounding box. Assuming that th vector that will be passed to this function will be already initialized to length three. Since the bounding box is not to be treated too seriously to the point of one extra sample in one dimension, we will not specify two different fields for x direction size in no_planes.*/
	Vector3 lengths= bbox.getExtent();
	cout<<no_planes->size()<<endl;
	assert(no_planes->size()==3);

	(*no_planes)[0] = (unsigned int)floor(lengths[0]/(dist_x*reso));
	(*no_planes)[1] = (unsigned int)floor(lengths[1]/(dist_y*reso));
	(*no_planes)[2] = (unsigned int)floor(lengths[2]/(dist_z*reso));

	return;
}
void PointKDTree::rangeQuery(Node *node, AxisAlignedBox3 const & query, std::vector<Point *> & points_in_range) const
{
	if(!(node->bbox).intersects(query))
		return;
	if(node->lo == NULL && node->hi == NULL && (node->points).size()!=0)
	{
		for(int i=0;i<(int)(node->points).size();i++)
		{
			Vector3 nodePoint = node->points[i]->getPosition();
			if(query.contains(nodePoint))
				points_in_range.push_back(node->points[i]);
		}
		return;
	}
	
	if((node->lo->bbox).intersects(query) && node->lo !=NULL)
		rangeQuery(node->lo, query, points_in_range);
	if((node->hi->bbox).intersects(query) && node->hi !=NULL)
		rangeQuery(node->hi, query, points_in_range);
}
Esempio n. 6
0
void
Viewer::drawOutlineBox(AxisAlignedBox3 const & bbox)
{
  if (!render_system)
    return;

  render_system->pushShader();
    render_system->setShader(NULL);

    render_system->beginPrimitive(Graphics::RenderSystem::Primitive::LINES);
      Vector3 p, q;
      for (int i = 0; i < 12; ++i)
      {
        bbox.getEdge(i, p, q);
        render_system->sendVertex(p);
        render_system->sendVertex(q);
      }
    render_system->endPrimitive();

  render_system->popShader();
}
Esempio n. 7
0
void create_iterator(AxisAlignedBox3 bbox, float reso, vector<unsigned int> no_planes, vector<vector<float>> *grid_lines){
	/*This function creates four lists and puts them in a vector. The first list is a list of valid x coordinates. The second list is also a list of valid x coordinates. You see, the second list of valid x coordinates is shifted by 1/sqrt(2) from the first list. The third contains valid y coordinates. The third list contains valid z coordinates. All these lists are in the gid_lines vector.*/
	Vector3 start = bbox.getLow();	

	vector<float> x1 (no_planes[0]);
	vector<float> y1 (no_planes[1]);
	vector<float> z1 (no_planes[2]);
	(*grid_lines)[0] = x1;
	(*grid_lines)[1] = x1;
	(*grid_lines)[2] = y1;
	(*grid_lines)[3] = z1;

	for(unsigned int i=0;i<no_planes[0];++i)
		(*grid_lines)[0][i] = start.x()+reso*dist_x*i;
	for(unsigned int i=0;i<no_planes[0];++i)
		(*grid_lines)[1][i] = start.x()+reso*dist_x/2+reso*dist_x*i;
	for(unsigned int i=0;i<no_planes[1];++i)
		(*grid_lines)[2][i] = start.y()+reso*dist_y*i;
	for(unsigned int i=0;i<no_planes[2];++i)
		(*grid_lines)[3][i] = start.z()+reso*dist_z*i;

	return;
}
 /** Add a point, specified by its position and normal, to the point cloud. */
 void addPoint(Vector3 const & p, Vector3 const & n) { points.push_back(Point(p, n)); bbox.merge(p); }
 /** Add a point to the point cloud. */
 void addPoint(Point const & p) { points.push_back(p); bbox.merge(p.getPosition()); }
 /** Reset the point cloud to an empty state. */
 void clear() { points.clear(); bbox.setNull(); }