示例#1
0
static void BM_BoundingBox(benchmark::State& state) {
    while (state.KeepRunning()) {
        state.PauseTiming();
        const int num_imgs = 36;
        DataSetReader dsr(std::string(ASSETS_PATH) + "/squirrel");
        auto ds = dsr.load(num_imgs);

        for (auto idx = 0; idx < num_imgs; ++idx) {
            ds->getCamera(idx).setMask(Binarize(
                ds->getCamera(idx).getImage(), cv::Scalar(0, 0, 30)));
        }
        state.ResumeTiming();
        BoundingBox bbox =
            BoundingBox(ds->getCamera(0), ds->getCamera((num_imgs / 4) - 1));
        auto vc = ret::make_unique<VoxelCarving>(bbox.getBounds(), 128);
    }
}
示例#2
0
// Checks to see if two BoundingBoxes overlap.  Assumes axis-aligned edges
bool BoundingBox::intersects(const BoundingBox &other) const
{
    return ((_xbox.x0 < other.getBounds().x1 && _xbox.x1 > other.getBounds().x0) &&
            (_xbox.y0 < other.getBounds().y1 && _xbox.y1 > other.getBounds().y0) &&
            (_xbox.z0 < other.getBounds().z1 && _xbox.z1 > other.getBounds().z0));
}
/*!
 * \brief Static function for box intersection. Return false if they do not
 * intersect. 
 *
 * \param box_A Bounding box A.
 *
 * \param box_B Bounding box B.
 *
 * \param intersection A bounding box that is equivalent to the inersection of
 * box A and box B. Box A and B can be provided in any order (the
 * intersection of box A with box B is equal to the intersection of box B with
 * box A).
 *
 * \return Return true if the boxes intersect. False if they do not.
 */
bool BoundingBox::intersectBoxes( const BoundingBox& box_A,
				  const BoundingBox& box_B,
				  BoundingBox& intersection)
{
    Teuchos::Tuple<double,6> bounds_A = box_A.getBounds();
    Teuchos::Tuple<double,6> bounds_B = box_B.getBounds();

    double x_min, y_min, z_min, x_max, y_max, z_max;

    // Test for no overlap in X.
    if ( bounds_A[0] > bounds_B[3] || bounds_A[3] < bounds_B[0] )
    {
	return false;
    }
    // Test for no overlap in Y.
    if ( bounds_A[1] > bounds_B[4] || bounds_A[4] < bounds_B[1] )
    {
	return false;
    }
    // Test for no overlap in Z.
    if ( bounds_A[2] > bounds_B[5] || bounds_A[5] < bounds_B[2] )
    {
	return false;
    }

    // Get overlap in X.
    if ( bounds_A[0] > bounds_B[0] )
    {
	x_min = bounds_A[0];
    }
    else
    {
	x_min = bounds_B[0];
    }
    if ( bounds_A[3] > bounds_B[3] )
    {
	x_max = bounds_B[3];
    }
    else
    {
	x_max = bounds_A[3];
    }

    // Get overlap in Y.
    if ( bounds_A[1] > bounds_B[1] )
    {
	y_min = bounds_A[1];
    }
    else
    {
	y_min = bounds_B[1];
    }
    if ( bounds_A[4] > bounds_B[4] )
    {
	y_max = bounds_B[4];
    }
    else
    {
	y_max = bounds_A[4];
    }

    // Get overlap in Z.
    if ( bounds_A[2] > bounds_B[2] )
    {
	z_min = bounds_A[2];
    }
    else
    {
	z_min = bounds_B[2];
    }
    if ( bounds_A[5] > bounds_B[5] )
    {
	z_max = bounds_B[5];
    }
    else
    {
	z_max = bounds_A[5];
    }

    intersection = BoundingBox( x_min, y_min, z_min, x_max, y_max, z_max );
    return true;
}
示例#4
0
/**
  Draw a tree.

  \param node Node
  \param draw_blends If true, only objects that use blending are drawn. Otherwise objects with
         blending are not drawn.
  \return True if the tree contained one or more objects that use blending
 */
bool GLRenderInstance::drawNode(WorldObject& node, bool draw_blends)
{
  double M[16];
  BoundingBox bb;
  vec3d bmin, bmax, t, d;
  bool render_flag = true;
  bool res = false;

  WorldObject::ChildIterator it;
  for(it=node.childsBegin(); it!=node.childsEnd(); it++)
  {
    glPushMatrix();
    // Set the local transformation
    it->second->localTransform().toList(M);
    glMultMatrixd(M);
    // Draw the geom (if visible)
    boost::shared_ptr<GeomObject> geom = it->second->getGeom();
    if (geom.get()!=0 && (it->second->visible.getValue()))
    {
      // Render by default if draw_blends is false
      render_flag = !draw_blends;

      // Set material
      boost::shared_ptr<Material> mat = it->second->getMaterial();
      Material* bmat = dynamic_cast<Material*>(mat.get());
      // Check if the object should be postponed because blending is used...
      if (bmat!=0)
      {
        if (bmat->usesBlending())
        {
          res = true;
          render_flag = draw_blends;
        }
      }

      if (render_flag)
      {
        // Set material
        glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT);
        if (bmat!=0)
        {
          bmat->applyGL();
        }

        if (draw_solid)
        {
          clearGLError();
          geom->drawGL();
        }
        // Draw bounding box
        if (draw_bboxes)
        {
          bb = geom->boundingBox();
          if (!bb.isEmpty())
          {
            glDisable(GL_LIGHTING);
            bb.getBounds(bmin, bmax);
            t = 0.5*(bmax+bmin);
            d = bmax-bmin;
            glPushMatrix();
            glTranslated(t.x, t.y, t.z);
            drawWireCube(d.x, d.y, d.z);
            glPopMatrix();
            glEnable(GL_LIGHTING);
          }
        }
        glPopAttrib();  // restore material
      }
    }
    // Draw the children
    res |= drawNode(*(it->second), draw_blends);
    glPopMatrix();
  }
  return res;
}