Пример #1
0
BoundingSphere Group::computeBound() const
{
    BoundingSphere bsphere;
    if (_children.empty())
    {
        return bsphere;
    }

    // note, special handling of the case when a child is an Transform,
    // such that only Transforms which are relative to their parents coordinates frame (i.e this group)
    // are handled, Transform relative to and absolute reference frame are ignored.

    BoundingBox bb;
    bb.init();
    NodeList::const_iterator itr;
    for(itr=_children.begin();
        itr!=_children.end();
        ++itr)
    {
        osg::Node* child = itr->get();
        const osg::Transform* transform = child->asTransform();
        if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
        {
            osg::Drawable* drawable = child->asDrawable();
            if (drawable)
            {
                bb.expandBy(drawable->getBoundingBox());
            }
            else
            {
                const osg::BoundingSphere& bs = child->getBound();
                bb.expandBy(bs);
            }
        }
    }

    if (!bb.valid())
    {
        return bsphere;
    }

    bsphere._center = bb.center();
    bsphere._radius = 0.0f;
    for(itr=_children.begin();
        itr!=_children.end();
        ++itr)
    {
        osg::Node* child = itr->get();
        const osg::Transform* transform = child->asTransform();
        if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
        {
            const BoundingSphere& bs = child->getBound();
            bsphere.expandRadiusBy(bs);
        }
    }

    return bsphere;
}
Пример #2
0
bool BezierCurve::intersectTetrahedron(unsigned icomponent, const Vector3F * tet)
{
	BoundingBox tbox;
    tbox.expandBy(tet[0]);
	tbox.expandBy(tet[1]);
	tbox.expandBy(tet[2]);
	tbox.expandBy(tet[3]);
	
	BezierSpline sp;
	getSegmentSpline(icomponent, sp);   
	return intersectTetrahedron(sp, tet, tbox);
}
Пример #3
0
bool BccLattice::intersectTetrahedron(const Vector3F * tet, BezierSpline * splines, unsigned numSplines) const
{
	unsigned i = 0;
	for(; i<numSplines; i++) {
		BoundingBox tbox;
		tbox.expandBy(tet[0]);
		tbox.expandBy(tet[1]);
		tbox.expandBy(tet[2]);
		tbox.expandBy(tet[3]);
		if(BezierCurve::intersectTetrahedron(splines[i], tet, tbox))
			return true;
	}
	return false;
}
Пример #4
0
void BlockBccMeshBuilder::addAnchorByThreshold(ATetrahedronMesh * mesh, 
					unsigned istripe,
					const Matrix33F & invspace, 
					const Vector3F & center,
					float threshold,
					bool isLower,
					unsigned tri)
{
	unsigned tetMax = mesh->numTetrahedrons() * 4;
	if(istripe < indexDrifts.size() -1)
		tetMax = indexDrifts[istripe + 1];
		
	BoundingBox box;
	Vector3F q;
	unsigned i = indexDrifts[istripe];
	unsigned j;
	for(;i<tetMax;i+=4) {
		unsigned * tet = mesh->tetrahedronIndices(i/4);
		box.reset();
        for(j=0; j< 4; j++)
            box.expandBy(mesh->points()[tet[j]], 1e-3f); 
			
		q = invspace.transform(box.center() - center);
		if(isLower) {
			if(q.x > threshold) continue;
		}
		else {
			if(q.x < threshold) continue;
		}
		
		for(j=0; j< 4; j++)
			mesh->anchors()[tet[j]] = (1<<24 | tri);
	}
}
Пример #5
0
const std::deque<Vector3F> RayMarch::touched(const float & threshold, BoundingBox & limit) const
{
	std::deque<Vector3F> r;
	const Vector3F u(threshold, threshold, threshold);
	const Vector3F p0 = m_path.m_origin - u;
	const Vector3F p1 = m_path.m_origin + u;
	const int ng = threshold * 2.f / m_gridSize + 1;
	int i, j, k;
	Vector3F p;
	for(k= 0; k <= ng; k++) {
		p.z = p0.z + m_gridSize * k;
		for(j= 0; j <= ng; j++) {
			p.y = p0.y + m_gridSize * j;
			for(i= 0; i <= ng; i++) {
				p.x = p0.x + m_gridSize * i;
				if(m_limit.isPointInside(p)) r.push_back(p);
			}
		}
	}
	
	const BoundingBox blo = computeBBox(p0);
	const BoundingBox bhi = computeBBox(p1);
	
	limit.reset();
	limit.expandBy(blo);
	limit.expandBy(bhi);
	limit.shrinkBy(m_limit);
	return r;
}
Пример #6
0
const BoundingBox BezierCurve::calculateBBox() const
{
	BoundingBox b;
	const unsigned ns = numSegments();
    for(unsigned i=0; i < ns; i++)
		b.expandBy(calculateBBox(i));
	return b;
}
Пример #7
0
BoundingSphere Patch::computeBound() const
{
    BoundingSphere bsphere;
    if (!_trile[0][0].valid())
        return bsphere;
    BoundingBox bb;
    bb.init();
    for (int res = 0; res < 2; ++res)
        for (int i = 0; i < 4; ++i)
            bb.expandBy(_trile[res][i]->getBoundingBox());
    for (int strip = 0; strip < 4; ++strip)
        for (int i = 0; i < 4; ++i)
            bb.expandBy(_strip[strip][i]->getBoundingBox());
    if (!bb.valid())
        return bsphere;
    bsphere.expandBy(bb);
    return bsphere;
}
Пример #8
0
void PositionDragger::adjustSize()
{
    BoundingBox bb;
    for(int i=0; i < numChildren(); ++i){
        SgNode* node = child(i);
        if(node != translationDragger_ && node != rotationDragger_){
            bb.expandBy(node->boundingBox());
        }
    }
    adjustSize(bb);
}
Пример #9
0
bool BezierCurve::intersectTetrahedron(const Vector3F * tet)
{
    BoundingBox tbox;
    tbox.expandBy(tet[0]);
	tbox.expandBy(tet[1]);
	tbox.expandBy(tet[2]);
	tbox.expandBy(tet[3]);
	
    BoundingBox ab = calculateBBox();

    if(!ab.intersect(tbox)) return false;
    
	const unsigned ns = numSegments();
    for(unsigned i=0; i < ns; i++) {
        BezierSpline sp;
        getSegmentSpline(i, sp);   
        if(intersectTetrahedron(sp, tet, tbox)) return true;
    }
	
	return false;
}
Пример #10
0
bool BezierCurve::intersectTetrahedron(BezierSpline & spline, const Vector3F * tet, const BoundingBox & box)
{
    BoundingBox abox;
	spline.getAabb(&abox);
	
	if(!abox.intersect(box)) return false;
	
	BezierSpline stack[96];
	int stackSize = 2;
	spline.deCasteljauSplit(stack[0], stack[1]);
	Vector3F q;
	while(stackSize > 0) {
		BezierSpline c = stack[stackSize - 1];
		stackSize--;
		
		abox.reset();
		abox.expandBy(c.cv[0]);
		abox.expandBy(c.cv[1]);
		abox.expandBy(c.cv[2]);
		abox.expandBy(c.cv[3]);
		
		if(abox.intersect(box)) {
			if(c.straightEnough()) {
			    if(tetrahedronLineIntersection(tet, c.cv[0], c.cv[3], q))
			        return true;
			}
			else {
                BezierSpline a, b;
                c.deCasteljauSplit(a, b);
                
                stack[ stackSize ] = a;
                stackSize++;
                stack[ stackSize ] = b;
                stackSize++;
			}
		}
	}
	
	return false;
}
Пример #11
0
bool BezierCurve::intersectBox(BezierSpline & spline, const BoundingBox & box)
{
	BoundingBox abox;
	spline.getAabb(&abox);
	
	if(!abox.intersect(box)) return false;
	
	if(abox.inside(box)) return true;
	
	BezierSpline stack[64];
	int stackSize = 2;
	spline.deCasteljauSplit(stack[0], stack[1]);
	
	while(stackSize > 0) {
		BezierSpline c = stack[stackSize - 1];
		stackSize--;
		
		abox.reset();
		abox.expandBy(c.cv[0]);
		abox.expandBy(c.cv[1]);
		abox.expandBy(c.cv[2]);
		abox.expandBy(c.cv[3]);
		
		if(abox.inside(box)) return true;
		
		if(abox.intersect(box)) {
			if(abox.area() < 0.0001f) return true;
			
			BezierSpline a, b;
			c.deCasteljauSplit(a, b);
			
			stack[ stackSize ] = a;
			stackSize++;
			stack[ stackSize ] = b;
			stackSize++;
		}
	}
	
	return false;
}
Пример #12
0
BoundingBox DrawPixels::computeBound() const
{
    // really needs to be dependent of view position and projection... will implement simple version right now.
    BoundingBox bbox;
    float diagonal = 0.0f;
    if (_useSubImage)
    {
        diagonal = sqrtf(_width*_width+_height*_height);
    }
    else
    {
        diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t());
    }
    
    bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal));
    bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal));
    return bbox;
}
Пример #13
0
BoundingSphere Switch::computeBound() const
{
    BoundingSphere bsphere;
    if (_children.empty())
    {
        return bsphere;
    }

    // note, special handling of the case when a child is an Transform,
    // such that only Transforms which are relative to their parents coordinates frame (i.e this group)
    // are handled, Transform relative to and absolute reference frame are ignored.

    BoundingBox bb;
    bb.init();
    for(unsigned int pos=0;pos<_children.size();++pos)
    {
        const osg::Transform* transform = _children[pos]->asTransform();
        if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
        {
            if( _values[pos] == true )
                bb.expandBy(_children[pos]->getBound());
        }
    }

    if (!bb.valid())
    {
        return bsphere;
    }

    bsphere._center = bb.center();
    bsphere._radius = 0.0f;
    for(unsigned int pos=0;pos<_children.size();++pos)
    {
        const osg::Transform* transform = _children[pos]->asTransform();
        if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
        {
            if( _values[pos] == true )
                bsphere.expandRadiusBy(_children[pos]->getBound());
        }
    }
    return bsphere;
}
Пример #14
0
BoundingSphere OccluderNode::computeBound() const
{
    BoundingSphere bsphere(Group::computeBound());

    if (getOccluder())
    {
        BoundingBox bb;
        const ConvexPlanarPolygon::VertexList& vertexList = getOccluder()->getOccluder().getVertexList();
        for(ConvexPlanarPolygon::VertexList::const_iterator itr=vertexList.begin();
            itr!=vertexList.end();
            ++itr)
        {
            bb.expandBy(*itr);
        }
        if (bb.valid())
        {
            bsphere.expandBy(bb);
        }
    }
    return bsphere;
}