void setPolytope(osg::Polytope& polytope, osg::Plane& referencePlane)
        {
            _referencePlane = referencePlane;

            const PlaneMask currentMask = polytope.getCurrentMask();
            PlaneMask selector_mask = 0x1;

            const PlaneList& planeList = polytope.getPlaneList();
            unsigned int numActivePlanes = 0;

            PlaneList::const_iterator itr;
            for(itr=planeList.begin(); itr!=planeList.end(); ++itr)
            {
                if (currentMask&selector_mask) ++numActivePlanes;
                selector_mask <<= 1;
            }

            _plane_mask = 0x0;
            _planes.clear();
            _planes.reserve(numActivePlanes);
            _lines.clear();

            selector_mask=0x1;
            for(itr=planeList.begin(); itr!=planeList.end(); ++itr)
            {
                if (currentMask&selector_mask)
                {
                    _planes.push_back(*itr);
                    _plane_mask <<= 1;
                    _plane_mask |= 0x1;
                }
                selector_mask <<= 1;
            }
        }
bool ossimPlanetBoundingBox::intersects(const osg::Polytope& frustum)const
{
   const osg::Polytope::PlaneList& planeList = frustum.getPlaneList();
   unsigned int idx = 0;
   unsigned int ptIdx = 0;
   unsigned int outsideCount    = 0;
   unsigned int upperBound = planeList.size();
   double testValue = 0.0;
   for(; idx < upperBound;++idx)
   {
      const osg::Vec4& plane = planeList[idx].asVec4();
      outsideCount = 0;
      for(ptIdx = 0; ptIdx < 8; ++ptIdx)
      {
         testValue =  (((((double)plane[0])*theCorners[ptIdx][0] +
                         ((double)plane[1])*theCorners[ptIdx][1] +
                         ((double)plane[2])*theCorners[ptIdx][2])) + (double)plane[3]);
         if(testValue >-FLT_EPSILON)
         {
            break;
         }
         else
         {
            ++outsideCount;
         }
      }
      if(outsideCount == 8)
      {
         return false;
      }
   }
   
   return true;
}
Esempio n. 3
0
inline bool CheckAndMultiplyBoxIfWithinPolytope
    ( osg::BoundingBox & bb, osg::Matrix & m, osg::Polytope &p )
{
    if( !bb.valid() ) return false;

    osg::Vec3 o = bb._min * m, s[3];

    for( int i = 0; i < 3; i ++ )
        s[i] = osg::Vec3( m(i,0), m(i,1), m(i,2) ) * ( bb._max[i] - bb._min[i] );

    for( osg::Polytope::PlaneList::iterator it = p.getPlaneList().begin();
         it != p.getPlaneList().end();
         ++it )
    {
        float dist = it->distance( o ), dist_min = dist, dist_max = dist;

        for( int i = 0; i < 3; i ++ ) {
            dist = it->dotProductNormal( s[i] );
            if( dist < 0 ) dist_min += dist; else dist_max += dist;
        }

        if( dist_max < 0 )
            return false;
    }

    bb._max = bb._min = o;
#if 1
    for( int i = 0; i < 3; i ++ )
        for( int j = 0; j < 3; j ++ )
            if( s[i][j] < 0 ) bb._min[j] += s[i][j]; else bb._max[j] += s[i][j];
#else
    b.expandBy( o + s[0] );
    b.expandBy( o + s[1] );
    b.expandBy( o + s[2] );
    b.expandBy( o + s[0] + s[1] );
    b.expandBy( o + s[0] + s[2] );
    b.expandBy( o + s[1] + s[2] );
    b.expandBy( o + s[0] + s[1] + s[2] );
#endif

#if ( IGNORE_OBJECTS_LARGER_THAN_HEIGHT > 0 )
   if( bb._max[2] - bb._min[2] > IGNORE_OBJECTS_LARGER_THAN_HEIGHT ) // ignore huge objects
       return false;
#endif

    return true;
}
bool
GeoCell::intersects( const osg::Polytope& tope ) const
{
    const osg::Polytope::PlaneList& planes = tope.getPlaneList();
    for( osg::Polytope::PlaneList::const_iterator i = planes.begin(); i != planes.end(); ++i )
    {
        if ( i->intersect( _boundaryPoints ) < 0 )
            return false;
    }
    return true;
}
Esempio n. 5
0
bool DebugShadowMap::ViewData::DebugPolytope
( const osg::Polytope & p, const char * name )
{
    bool result = false;
#if defined( _DEBUG    ) || defined( DEBUG )
    if( !name ) name = "";

    osg::Polytope & p_prev = _polytopeMap[ std::string( name ) ];

    result = ( p.getPlaneList() != p_prev.getPlaneList() );

    if( result ) {
        std::cout << "Polytope<" << name
                  << "> size(" << p.getPlaneList().size() << ")"
                  << std::endl;

        if( p.getPlaneList().size() == p_prev.getPlaneList().size() ) {
            for( unsigned i = 0; i < p.getPlaneList().size(); ++i )
            {
                if( p.getPlaneList()[i] != p_prev.getPlaneList()[i] )
                {
                    std::cout << "Plane<" << i
                        << "> ("
                        << p.getPlaneList()[i].asVec4()[0] << ", "
                        << p.getPlaneList()[i].asVec4()[1] << ", "
                        << p.getPlaneList()[i].asVec4()[2] << ", "
                        << p.getPlaneList()[i].asVec4()[3] << ")"
                        << std::endl;
                }
            }
        }
    }

    p_prev = p;
#endif
    return result;
}