Пример #1
0
	bool EditorUtility::calculateMeshBounds(const HSceneObject& object, AABox& bounds)
	{
		bounds = AABox(Vector3::ZERO, Vector3::ZERO);
		if (object.isDestroyed())
			return false;

		bool foundOne = false;
		const Vector<HComponent>& components = object->getComponents();
		for (auto& component : components)
		{
			Bounds curBounds;
			if (component->calculateBounds(curBounds))
			{
				if (!foundOne)
				{
					bounds = curBounds.getBox();
					foundOne = true;
				}
				else
					bounds.merge(curBounds.getBox());
			}
			else
			{
				if (!foundOne)
					bounds = curBounds.getBox();
			}
		}

		return foundOne;
	}
Пример #2
0
    tmv::SymMatrix<double, tmv::FortranStyle|tmv::Upper> calculateCovarianceSymMatrix(
        const SBProfile& sbp, const Bounds<int>& bounds, double dx)
    {
        // Calculate the required dimensions
        int idim = 1 + bounds.getXMax() - bounds.getXMin();
        int jdim = 1 + bounds.getYMax() - bounds.getYMin();
        int covdim = idim * jdim;

        int k, ell; // k and l are indices that refer to image pixel separation vectors in the 
                    // correlation func.
        double x_k, y_ell; // physical vector separations in the correlation func, dx * k etc.

        tmv::SymMatrix<double, tmv::FortranStyle|tmv::Upper> cov = tmv::SymMatrix<
            double, tmv::FortranStyle|tmv::Upper>(covdim);

        for (int i=1; i<=covdim; i++){ // note that the Image indices use the FITS convention and 
                                       // start from 1!!
            for (int j=i; j<=covdim; j++){

                k = ((j - 1) / jdim) - ((i - 1) / idim);  // using integer division rules here
                ell = ((j - 1) % jdim) - ((i - 1) % idim);
                x_k = double(k) * dx;
                y_ell = double(ell) * dx;
                Position<double> p = Position<double>(x_k, y_ell);
                cov(i, j) = sbp.xValue(p); // fill in the upper triangle with the correct value

            }

        }
        return cov;
    }
Пример #3
0
bool Intersect::RayBounds (const Vector3f& origin, const Vector3f& dir, const Bounds& bounds)
{
	const Vector3f& max		= bounds.GetMax();
	const Vector3f& center	= bounds.GetCenter();

	Vector3f ext  (max		- center);
	Vector3f diff (origin	- center);

	if (Float::Abs(diff.x) > ext.x && Float::IsProductPositive(diff.x, dir.x)) return false;
	if (Float::Abs(diff.y) > ext.y && Float::IsProductPositive(diff.y, dir.y)) return false;
	if (Float::Abs(diff.z) > ext.z && Float::IsProductPositive(diff.z, dir.z)) return false;

	Vector3f adir (Float::Abs(dir.x), Float::Abs(dir.y), Float::Abs(dir.z));

	float a = dir.y * diff.z - dir.z * diff.y;
	float b = ext.y * adir.z + ext.z * adir.y;

	if (Float::Abs(a) > b) return false;
	
	a = dir.z * diff.x - dir.x * diff.z;
	b = ext.x * adir.z + ext.z * adir.x;

	if (Float::Abs(a) > b) return false;
	
	a = dir.x * diff.y - dir.y * diff.x;
	b = ext.x * adir.y + ext.y * adir.x;

	return !(Float::Abs(a) > b);
}
Пример #4
0
void Font::render(const vec3& pos, const std::string& text) const {
    if (simpleLayout_) {
        float delta = 0;

        std::string line;
        std::stringstream ss(text);
        std::getline(ss, line);
        FTPoint point(static_cast<double>(pos.x),
                      static_cast<double>(pos.y),
                      static_cast<double>(pos.z));
        FTBBox box = font_->BBox(line.c_str(), -1, point);
        delta -= box.Upper().Yf() - box.Lower().Yf(); // height of first line

        Bounds bounds = getBounds(pos, text);
        float height = bounds.getURB().y - bounds.getLLF().y;
        switch(vAlign_) {
            case Font::Top:
                delta += height;
                break;
            case Font::Middle:
                delta += height * 0.5f;
                break;
            case Font::Bottom:
                break;
        }
        vec3 dpos = vec3(pos.x, pos.y + delta, pos.z);
        glPushMatrix();
        glRasterPos3f(dpos.x, dpos.y, dpos.z);
        glTranslatef(dpos.x, dpos.y, dpos.z);
        simpleLayout_->Render(text.c_str(), -1, FTPoint(dpos.x, dpos.y, dpos.z));
        glPopMatrix();
    }
}
Пример #5
0
bool Bounds::inside(const Bounds& bounds) const {
    tgtAssert(       isDefined(), "This Box ist not defined.");
    tgtAssert(bounds.isDefined(), "Box b ist not defined.");

    vec3 llfb = bounds.getLLF();
    vec3 urbb = bounds.getURB();

    float r0x = min(llf_[0], urb_[0]);
    float r1x = max(llf_[0], urb_[0]);
    float r0y = min(llf_[1], urb_[1]);
    float r1y = max(llf_[1], urb_[1]);
    float r0z = min(llf_[2], urb_[2]);
    float r1z = max(llf_[2], urb_[2]);

    float r2x = min(llfb[0], urbb[0]);
    float r3x = max(llfb[0], urbb[0]);
    float r2y = min(llfb[1], urbb[1]);
    float r3y = max(llfb[1], urbb[1]);
    float r2z = min(llfb[2], urbb[2]);
    float r3z = max(llfb[2], urbb[2]);

    return (r0x >= r2x) && (r1x <= r3x)
        && (r0y >= r2y) && (r1y <= r3y)
        && (r0z >= r2z) && (r1z <= r3z);
}
Пример #6
0
      bool
      remove(const Bounds& area, const Bounds& b)
      {
        if (m_leaf)
          return area.contains(m_data.item);

        int cdel = 0;

        for (int i = 0; i < 4; ++i)
        {
          Node** c = m_data.children + i;

          if (!*c)
            continue;

          Bounds cb = b.quadrant(i);

          if (area.intersects(cb) && (*c)->remove(area, cb))
          {
            delete *c;
            * c = 0;
            ++cdel;
          }
        }
        return cdel == 4;   // true if all sub-nodes were removed
      }
Пример #7
0
FilterContext
ScaleFilter::push( FeatureList& input, FilterContext& cx )
{
    for( FeatureList::iterator i = input.begin(); i != input.end(); ++i )
    {
        Feature* input = i->get();
        if ( input && input->getGeometry() )
        {
            Bounds envelope = input->getGeometry()->getBounds();

            // now scale and shift everything
            GeometryIterator scale_iter( input->getGeometry() );
            while( scale_iter.hasMore() )
            {
                Geometry* geom = scale_iter.next();
                for( osg::Vec3dArray::iterator v = geom->begin(); v != geom->end(); v++ )
                {
                    double xr = (v->x() - envelope.xMin()) / envelope.width();
                    v->x() += (xr - 0.5) * _scale;

                    double yr = (v->y() - envelope.yMin()) / envelope.height();
                    v->y() += (yr - 0.5) * _scale;
                }
            }
        }
    }

    return cx;
}
Пример #8
0
//=================================================================================
/*virtual*/ Node::ValueStringError BoundedPointListNode::SetValueFromString( const std::string& valueString )
{
	VarMap varMap;
	if( !ConvertValueStringToVarMap( valueString, varMap ) )
		return VSE_SYNTAX;

	Bounds trialBounds = bounds;
	if( varMap.end() != varMap.find( "xMin" ) )
		trialBounds.min.set_e1( varMap[ "xMin" ] );
	if( varMap.end() != varMap.find( "xMax" ) )
		trialBounds.max.set_e1( varMap[ "xMax" ] );
	if( varMap.end() != varMap.find( "yMin" ) )
		trialBounds.min.set_e2( varMap[ "yMin" ] );
	if( varMap.end() != varMap.find( "yMax" ) )
		trialBounds.max.set_e2( varMap[ "yMax" ] );

	if( trialBounds == bounds )
		return VSE_NO_CHANGE;
	if( !trialBounds.IsValid() )
		return VSE_INVALID;
	if( !SetBounds( trialBounds ) )
		return VSE_INVALID;

	return VSE_NONE;
}
Пример #9
0
	void ModelViewer::focus( ) {
		float fov = ( 5.0f / 12.0f ) * glm::pi<float>( );
		uint meshCount = m_model.numMeshes( );

		if ( !meshCount ) {
			return;
		}

		// Calculate complete bounds
		Bounds bounds = m_model.bounds( );
		float height = bounds.max.z - bounds.min.z;
		if ( height <= 0 ) {
			return;
		}

		float distance = bounds.min.y - ( ( height * 0.5f ) / ::tanf( fov * 0.5f ) );
		if ( distance < 0 ) {
			distance *= -1;
		}

		// Update camera and render
		XMFLOAT3 dxBounds;
		glm::vec3 glmBounds = bounds.center( );
		dxBounds.x = glmBounds.x;
		dxBounds.y = glmBounds.y;
		dxBounds.z = glmBounds.z;

		m_camera.setPivot( dxBounds );

		//m_camera.setPivot( bounds.center( ) );
		m_camera.setDistance( distance );
		this->render( );
	}
Пример #10
0
int
seed( osg::ArgumentParser& args )
{    
    //Read the min level
    unsigned int minLevel = 0;
    while (args.read("--min-level", minLevel));
    
    //Read the max level
    unsigned int maxLevel = 5;
    while (args.read("--max-level", maxLevel));
    

    std::vector< Bounds > bounds;
    // restrict packaging to user-specified bounds.    
    double xmin=DBL_MAX, ymin=DBL_MAX, xmax=DBL_MIN, ymax=DBL_MIN;
    while (args.read("--bounds", xmin, ymin, xmax, ymax ))
    {        
        Bounds b;
        b.xMin() = xmin, b.yMin() = ymin, b.xMax() = xmax, b.yMax() = ymax;
        bounds.push_back( b );
    }    

    //Read the cache override directory
    std::string cachePath;
    while (args.read("--cache-path", cachePath));

    //Read the cache type
    std::string cacheType;
    while (args.read("--cache-type", cacheType));

    bool verbose = args.read("--verbose");

    //Read in the earth file.
    osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles( args );
    if ( !node.valid() )
        return usage( "Failed to read .earth file." );

    MapNode* mapNode = MapNode::findMapNode( node.get() );
    if ( !mapNode )
        return usage( "Input file was not a .earth file" );

    CacheSeed seeder;
    seeder.setMinLevel( minLevel );
    seeder.setMaxLevel( maxLevel );

    for (unsigned int i = 0; i < bounds.size(); i++)
    {
        GeoExtent extent(mapNode->getMapSRS(), bounds[i]);
        OE_DEBUG << "Adding extent " << extent.toString() << std::endl;
        seeder.addExtent( extent );
    }    
    if (verbose)
    {
        seeder.setProgressCallback(new ConsoleProgressCallback);
    }
    seeder.seed( mapNode->getMap() );

    return 0;
}
Пример #11
0
Bounds
Geometry::getBounds() const
{
    Bounds bounds;
    for( const_iterator i = begin(); i != end(); ++i )
        bounds.expandBy( i->x(), i->y(), i->z() );
    return bounds;
}
Пример #12
0
// TODO: Support transformed bounds using stencil
void UIContext::PushScissor(const Bounds &bounds) {
	Flush();
	Bounds clipped = bounds;
	if (scissorStack_.size())
		clipped.Clip(scissorStack_.back());
	scissorStack_.push_back(clipped);
	ActivateTopScissor();
}
Пример #13
0
	void ScriptMesh::internal_GetBounds(ScriptMesh* thisPtr, AABox* box, Sphere* sphere)
	{
		HMesh mesh = thisPtr->getHandle();

		Bounds bounds = mesh->getProperties().getBounds();
		*box = bounds.getBox();
		*sphere = bounds.getSphere();
	}
Пример #14
0
bool
Bounds::contains(const Bounds& rhs) const
{
    return 
        isValid() && rhs.isValid() && 
        xMin() <= rhs.xMin() && xMax() >= rhs.xMax() &&
        yMin() <= rhs.yMin() && yMax() >= rhs.yMax();
}
Пример #15
0
int
main(int argc, char** argv)
{
    osg::ArgumentParser args(&argc,argv);    

    // verbosity?
    bool verbose = !args.read( "--quiet" );
     
    Bounds bounds;
    // restrict user-specified bounds.    
    double xmin=DBL_MAX, ymin=DBL_MAX, xmax=DBL_MIN, ymax=DBL_MIN;
    while (args.read("--bounds", xmin, ymin, xmax, ymax ))
    {                
        bounds.set( xmin, ymin, 0, xmax, ymax, 1 );        
    }        

    // min level to backfill to
    unsigned minLevel = 0;
    args.read( "--min-level", minLevel );

    // max level to which to generate
    unsigned maxLevel = ~0;
    args.read( "--max-level", maxLevel );  

    std::string dbOptions;
    args.read("--db-options", dbOptions);
    std::string::size_type n = 0;
    while ((n=dbOptions.find('"', n))!=dbOptions.npos)
    {
        dbOptions.erase(n,1);
    }

    osg::ref_ptr<osgDB::Options> options = new osgDB::Options(dbOptions);


    std::string tmsPath;

    //Get the first argument that is not an option
    for(int pos=1;pos<args.argc();++pos)
    {
        if (!args.isOption(pos))
        {
            tmsPath  = args[ pos ];
        }
    }

    if (tmsPath.empty())
    {
        return usage( "Please provide a path to a TMS TileMap" );
    }
    

    TMSBackFiller backfiller;
    backfiller.setMinLevel( minLevel );
    backfiller.setMaxLevel( maxLevel );
    backfiller.setBounds( bounds );
    backfiller.process( tmsPath, options.get() );
}
Пример #16
0
// Convert a Bounds object (assumed to be in screen co-ordinates) to a QRect
QRect boundsToQRect( Bounds bounds )
{
	Vec3 extents, center;
	bounds.getExtents(extents);
	bounds.getCenter(center);
	return QRect(
		QPoint(center.x - extents.x, center.y - extents.y),
		QPoint(center.x + extents.x, center.y + extents.y));
}
Пример #17
0
GeoExtent::GeoExtent( const SpatialReference* srs, const Bounds& bounds ) :
_srs( srs ),
_xmin( bounds.xMin() ),
_ymin( bounds.yMin() ),
_xmax( bounds.xMax() ),
_ymax( bounds.yMax() )
{
    //nop
}
Пример #18
0
bool
GeoExtent::contains( const Bounds& rhs ) const
{
    return 
        rhs.xMin() >= _xmin &&
        rhs.yMin() >= _ymin &&
        rhs.xMax() <= _xmax &&
        rhs.yMax() <= _ymax;
}
Пример #19
0
Bounds
MultiGeometry::getBounds() const
{
    Bounds bounds;
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
    {
        bounds.expandBy( i->get()->getBounds() );
    }
    return bounds;
}
Пример #20
0
// Orders Bounds by their midpoint.  This is really only useful if the bounds
// are arranged in a grid and are of equal size (like during a MetaQuery).
inline bool operator<(const Bounds& lhs, const Bounds& rhs)
{
    const auto& lhsMid(lhs.mid());
    const auto& rhsMid(rhs.mid());

    return
        (lhsMid.x < rhsMid.x) ||
        (lhsMid.x == rhsMid.x && lhsMid.y < rhsMid.y) ||
        (lhsMid.x == rhsMid.x && lhsMid.y == rhsMid.y && lhsMid.z < rhsMid.z);
}
Пример #21
0
BOOL Bounds::IntersectsOBB(const Bounds &test, const Matrix &transform) const
{
    Bounds testT = test.GetTransformedBounds(transform);
    Bounds thisT = GetTransformedBounds(transform.GetTranspose());

    if(Intersects(testT) && thisT.Intersects(test))
        return TRUE;

    return FALSE;
}
Пример #22
0
 /** @brief Test if two bounds overlap
  * @param _first first bounds
  * @param _second second bounds
  * @return true if _first and _second share some points
  * @attention assertion when _first or _second are not valid
  */
 friend bool overlap(const Bounds& _first, const Bounds& _second)
 {
   TOMO_ASSERT(_first.valid() && _second.valid());
   TOMO_FOREACH_DIM(i)
   {
     if (_first.min_[i] > _second.max_[i] || _first.max_[i] < _second.min_[i]) 
       return false;
   }
   return true;
 }
Пример #23
0
 // The bounds of clip ops need to be adjusted for the paints of saveLayers they're inside.
 void updateClipBoundsForClipOp(const SkIRect& devBounds) {
     Bounds clip = SkRect::Make(devBounds);
     // We don't call adjustAndMap() because as its last step it would intersect the adjusted
     // clip bounds with the previous clip, exactly what we can't do when the clip grows.
     if (this->adjustForSaveLayerPaints(&clip)) {
         fCurrentClipBounds = clip.intersect(fCullRect) ? clip : Bounds::MakeEmpty();
     } else {
         fCurrentClipBounds = fCullRect;
     }
 }
Пример #24
0
double Molecule::dist(Molecule &other) {
    double minSqr = 1e9; //large value;
    Bounds bounds = state->bounds;
    for (int id : ids) {
        Vector pos = state->idToAtom(id).pos;
        for (int idOther : other.ids) {
            minSqr = fmin(minSqr, bounds.minImage((pos - state->idToAtom(idOther).pos)).lenSqr() );
        }
    }
    return sqrt(minSqr);
}
Пример #25
0
GeoExtent
GeoExtent::intersectionSameSRS( const Bounds& rhs ) const
{
    Bounds b(
        osg::maximum( xMin(), rhs.xMin() ),
        osg::maximum( yMin(), rhs.yMin() ),
        osg::minimum( xMax(), rhs.xMax() ),
        osg::minimum( yMax(), rhs.yMax() ) );

    return b.width() > 0 && b.height() > 0 ? GeoExtent( getSRS(), b ) : GeoExtent::INVALID;
}
Пример #26
0
    // Returns true if these Bounds share any area in common with another.
    bool overlaps(const Bounds& other, bool force2d = false) const
    {
        Point otherMid(other.mid());

        return
            std::abs(m_mid.x - otherMid.x) <=
                width() / 2.0 + other.width() / 2.0 &&
            std::abs(m_mid.y - otherMid.y) <=
                depth() / 2.0 + other.depth() / 2.0 &&
            (force2d || std::abs(m_mid.z - otherMid.z) <=
                height() / 2.0 + other.height() / 2.0);
    }
Пример #27
0
void Molecule::unwrap() {
    Vector weightedPos(0, 0, 0);
    double sumMass = 0;
    Vector firstPos = state->idToAtom(ids[0]).pos;
    Bounds bounds = state->bounds;
    for (int id : ids) {
		int idx = state->idToIdx[id];
		Atom &a = state->atoms[idx];
        a.pos = firstPos + bounds.minImage(a.pos - firstPos);

    }
}
Пример #28
0
    void generateRandomParticles(
        ParticleStore& particles,
        Bounds const& bounds,
        Generator& gen
    ) {
        typedef typename ParticleStore::value_type Particle;
        typedef typename ParticleStore::iterator PvIter;

        for(PvIter p(particles.begin()); p!=particles.end(); ++p) {
            generateRandomPosition(bounds.begin(), bounds.end(), p->beginPosition(), gen);
        }
    }
Пример #29
0
Bounds Bounds::transform(const mat4& m) const {
    Bounds b;
    b.addPoint(m * vec3(llf_.x, llf_.y, llf_.z));
    b.addPoint(m * vec3(urb_.x, llf_.y, llf_.z));
    b.addPoint(m * vec3(llf_.x, urb_.y, llf_.z));
    b.addPoint(m * vec3(llf_.x, llf_.y, urb_.z));
    b.addPoint(m * vec3(urb_.x, urb_.y, llf_.z));
    b.addPoint(m * vec3(llf_.x, urb_.y, urb_.z));
    b.addPoint(m * vec3(urb_.x, llf_.y, urb_.z));
    b.addPoint(m * vec3(urb_.x, urb_.y, urb_.z));
    return b;
}
Пример #30
0
 // Restore holds the devBounds for the clip after the {save,saveLayer}/restore block completes.
 void updateClipBounds(const Restore& op) {
     // This is just like the clip ops above, but we need to skip the effects (if any) of our
     // paired saveLayer (if it is one); it has not yet been popped off the save stack.  Our
     // devBounds reflect the state of the world after the saveLayer/restore block is done,
     // so they are not affected by the saveLayer's paint.
     const int kSavesToIgnore = 1;
     Bounds clip = SkRect::Make(op.devBounds);
     if (this->adjustForSaveLayerPaints(&clip, kSavesToIgnore)) {
         fCurrentClipBounds = clip.intersect(fCullRect) ? clip : Bounds::MakeEmpty();
     } else {
         fCurrentClipBounds = fCullRect;
     }
 }