Esempio n. 1
0
bool ON_3dPointArray::GetBoundingBox( 
  ON_BoundingBox& bbox,
  int bGrowBox
  ) const
{
  return GetBBox( &bbox.m_min.x, &bbox.m_max.x, bGrowBox );
}
/* nsIDOMSVGRect getBBox (); */
NS_IMETHODIMP
SVGLocatableElement::GetBBox(nsIDOMSVGRect **_retval)
{
  ErrorResult rv;
  *_retval = GetBBox(rv).get();
  return rv.ErrorCode();
}
	void QueueSave( CBaseEntity *pOwner, typedescription_t *pTypeDesc, void **ppPhysObj, PhysInterfaceId_t type )
	{
		if ( !pOwner )
			return;

		bool fOnlyNotingExistence = !pOwner->ShouldSavePhysics();
		
		QueuedItem_t item;
		
		item.ppPhysObj		= ppPhysObj;
		item.header.hEntity = pOwner;
		item.header.type	= type;
		item.header.nObjects = ( !fOnlyNotingExistence ) ? pTypeDesc->fieldSize : 0;
		item.header.fieldName = AllocPooledString( pTypeDesc->fieldName ); 	
																	// A pooled string is used here because there is no way
																	// right now to save a non-string_t string and have it 
																	// compressed in the save symbol tables. Furthermore,
																	// the field name would normally be in the string
																	// pool anyway. (toml 12-10-02)
		item.header.modelName = NULL_STRING;
		memset( &item.header.bbox, 0, sizeof( item.header.bbox ) );
		item.header.sphere.radius = 0;
		
		if ( !fOnlyNotingExistence && type == PIID_IPHYSICSOBJECT )
		{
			// Don't doing the box thing for things like wheels on cars
			IPhysicsObject *pPhysObj = (IPhysicsObject *)(*ppPhysObj);

			if ( pPhysObj )
			{
				item.header.modelName = GetModelName( pPhysObj );
				item.header.iCollide = physcollision->CollideIndex( pPhysObj->GetCollide() );
				if ( item.header.modelName == NULL_STRING )
				{
					BBox_t *pBBox = GetBBox( pPhysObj );
					if ( pBBox != NULL )
					{
						item.header.bbox = *pBBox;
					}
					else 
					{
						if ( pPhysObj && pPhysObj->GetSphereRadius() != 0 )
						{
							item.header.sphere.radius = pPhysObj->GetSphereRadius();
						}
						else
						{
							DevMsg( "Don't know how to save model for physics object (class \"%s\")\n", pOwner->GetClassname() );
						}
					}
				}
			}
		}

		m_QueuedSaves.Insert( item );
	}
Esempio n. 4
0
wxSVGRect wxSVGLineElement::GetResultBBox(wxSVG_COORDINATES coordinates)
{
  wxCSSStyleDeclaration style = GetResultStyle(*this);
  if (style.GetStroke().GetPaintType() == wxSVG_PAINTTYPE_NONE)
    return GetBBox(coordinates);
  WX_SVG_CREATE_M_CANVAS_ITEM
  wxSVGRect bbox = coordinates == wxSVG_COORDINATES_USER ?
    m_canvasItem->GetResultBBox(style) :
    m_canvasItem->GetResultBBox(style, GetMatrix(coordinates));
  WX_SVG_CLEAR_M_CANVAS_ITEM
  return bbox; 
}
void ShapeParabolicRectangle::computeBBox( SoAction*, SbBox3f& box, SbVec3f& /*center*/ )
{
	BBox bBox = GetBBox();
	// These points define the min and max extents of the box.
	SbVec3f min, max;

	min.setValue( bBox.pMin.x, bBox.pMin.y, bBox.pMin.z );
	max.setValue( bBox.pMax.x, bBox.pMax.y, bBox.pMax.z );;

	// Set the box to bound the two extreme points.
	box.setBounds(min, max);
}
Esempio n. 6
0
bool ASSISTANT::Oval::Overlap(int _x, int _y, float _zoomFactor)
{
   int
      x1, y1,
      x2, y2;
   
   if (!visible) return false;
   
   GetBBox(&x1,&y1,&x2,&y2);
   if ((_x < x1*_zoomFactor) || (_y < y1*_zoomFactor) || (_x > x2*_zoomFactor) || (_y > y2*_zoomFactor)) return false;
   
   return true; //canvas->Overlap(tkref,_x,_y);
}
Esempio n. 7
0
LLRegion ViewPort::GetLLRegion( const OCPNRegion &region )
{
    // todo: for these projecetions, improve this calculation by using the
    //       method in SetBoxes here
#ifndef ocpnUSE_GL
    return LLRegion(GetBBox());
#else    

    if(!glChartCanvas::CanClipViewport(*this))
        return LLRegion(GetBBox());

    OCPNRegionIterator it( region );
    LLRegion r;
    while( it.HaveRects() ) {
        wxRect rect = it.GetRect();

        int x1 = rect.x, y1 = rect.y, x2 = x1 + rect.width, y2 = y1 + rect.height;
        int p[8] = {x1, y1, x2, y1, x2, y2, x1, y2};
        double pll[8];
        for(int i=0; i<8; i+=2)
            GetLLFromPix(wxPoint(p[i], p[i+1]), pll+i, pll+i+1);

        // resolve (this works even if rectangle crosses both 0 and 180)
        //if(LLRegion::PointsCCW(4, pll))
        for(int i=0; i<8; i+=2) {
            if(pll[i+1] <= clon - 180)
                pll[i+1] += 360;
            else if(pll[i+1] >= clon + 180)
                pll[i+1] -= 360;
        }

        r.Union(LLRegion(4, pll));
        it.NextRect();
    }
    return r;
#endif    
}
Esempio n. 8
0
wxSVGRect wxSVGEllipseElement::GetResultBBox(wxSVG_COORDINATES coordinates) {
	wxSVGRect bbox = GetBBox(coordinates);
	if (GetStroke().GetPaintType() == wxSVG_PAINTTYPE_NONE)
		return bbox;

	double strokeWidthX = GetStrokeWidth();
	double strokeWidthY = strokeWidthX;
	if (coordinates != wxSVG_COORDINATES_USER) {
		wxSVGMatrix matrix = GetMatrix(coordinates);
		strokeWidthX *= matrix.GetA();
		strokeWidthY *= matrix.GetD();
	}

	return wxSVGRect(bbox.GetX() - strokeWidthX / 2, bbox.GetY() - strokeWidthY / 2, bbox.GetWidth() + strokeWidthX,
			bbox.GetHeight() + strokeWidthY);
}
Esempio n. 9
0
ON_BOOL32 
ON_Geometry::GetBoundingBox( // returns true if successful
       ON_3dPoint& boxmin,
       ON_3dPoint& boxmax,
       ON_BOOL32 bGrowBox
       ) const
{
  ON_Workspace ws;
  const int dim = Dimension();
  double *bmin, *bmax;
  if ( dim <= 3 ) {
    bmin = &boxmin.x;
    bmax = &boxmax.x;
  }
  else {
    bmin = ws.GetDoubleMemory(dim*2);
    bmax = bmin+dim;
    memset( bmin, 0, 2*dim*sizeof(*bmin) );
    if ( bGrowBox ) {
      bmin[0] = boxmin.x; bmin[1] = boxmin.y; bmin[1] = boxmin.z;
      bmax[0] = boxmax.x; bmax[1] = boxmax.y; bmax[1] = boxmax.z;
    }
  }
	// Treat invalid box on input as empty
	bool invalid=false;	//input box invalid=empty
	if(bGrowBox)
		invalid =  boxmin.x>boxmax.x || boxmin.y>boxmax.y|| boxmin.z>boxmax.z;
	if(bGrowBox && invalid)
		bGrowBox=false;

  const ON_BOOL32 rc = GetBBox( bmin, bmax, bGrowBox );
  if ( dim > 3 ) {
    boxmin.x = bmin[0]; boxmin.y = bmin[1]; boxmin.z = bmin[2];
    boxmax.x = bmax[0]; boxmax.y = bmax[1]; boxmax.z = bmax[2];
  }
  else if ( dim <= 2 ) {
    boxmin.z = 0.0;
    boxmax.z = 0.0;
    if ( dim <= 1 ) {
      boxmin.y = 0.0;
      boxmax.y = 0.0;
    }
  }
  return rc;
}
Esempio n. 10
0
void Route::DrawGL( ViewPort &vp )
{
#ifdef ocpnUSE_GL
    if( pRoutePointList->empty() || !m_bVisible ) return;

    if(!vp.GetBBox().IntersectOut(GetBBox()))
        DrawGLRouteLines(vp);

    /*  Route points  */
    for(wxRoutePointListNode *node = pRoutePointList->GetFirst(); node; node = node->GetNext()) {
        RoutePoint *prp = node->GetData();
        if ( !m_bVisible && prp->m_bKeepXRoute )
            prp->DrawGL( vp );
        else if (m_bVisible)
            prp->DrawGL( vp );
    }
#endif
}
Esempio n. 11
0
bool TMesh::ReadOffFile(char *filename)
{
    string str(filename);
    OffFileReader reader(str);

    if(reader.bad)
        return false;

    OffObj obj;
    if( reader.get_next_off_object(obj) ) {

        for(unsigned int i = 0; i < obj.vertices.size(); i ++) {
            add_vertex( VTMesh( obj.vertices[i].x, obj.vertices[i].y, obj.vertices[i].z) );
        }
        for(unsigned int i = 0; i < obj.facets.size(); i ++) {

            if(obj.facets[i].size() != 3) {
                cerr<<"Error: invalid triangle mesh."<<endl;
                return false;
            }
            unsigned int fid = add_facet( FTMesh( (obj.facets[i])[0], (obj.facets[i])[1], (obj.facets[i])[2]) );
            assert(fid == i);
        }

        //get the bounding box of mesh
        GetBBox();
        //Generate the topology for tmesh
        GenerateMeshTopo();
        //Mark the non_manifoldness
        MarkNonManifoldness();
        //debug
        //PrintMeshTopo();
        //getchar();


        return true;
    } else {
        return false;
    }
}
int
BBNode::getLeavesBoundingPoint(const ON_3dPoint &pt, std::list<BBNode *> &out)
{
    if (isLeaf()) {
	double min[3], max[3];
	GetBBox(min, max);
	if ((pt.x >= (min[0])) && (pt.x <= (max[0])) &&
	    (pt.y >= (min[1])) && (pt.y <= (max[1])) &&
	    (pt.z >= (min[2])) && (pt.z <= (max[2])))
	{
	    /* falls within BBox so put in list */
	    out.push_back(this);
	    return 1;
	}
	return 0;
    } else {
	int sum = 0;
	for (size_t i = 0; i < m_children.size(); i++) {
	    sum += m_children[i]->getLeavesBoundingPoint(pt, out);
	}
	return sum;
    }
}
Esempio n. 13
0
LLRegion ViewPort::GetLLRegion( const OCPNRegion &region )
{
    // todo: for these projecetions, improve this calculation by using the
    //       method in SetBoxes here
#ifndef ocpnUSE_GL
    return LLRegion(GetBBox());
#else

    if(!glChartCanvas::CanClipViewport(*this))
        return LLRegion(GetBBox());

    OCPNRegionIterator it( region );
    LLRegion r;
    while( it.HaveRects() ) {
        wxRect rect = it.GetRect();

        int x1 = rect.x, y1 = rect.y, x2 = x1 + rect.width, y2 = y1 + rect.height;
        int p[8] = {x1, y1, x2, y1, x2, y2, x1, y2};
        double pll[540];
        int j;

        /* if the viewport is rotated, we must split the segments as straight lines in lat/lon
           coordinates map to curves in projected coordinate space */
        if(fabs( rotation ) >= 0.0001) {
            j=0;
            double lastlat, lastlon;
            int li = 6;
            GetLLFromPix(wxPoint(p[li], p[li+1]), &lastlat, &lastlon);
            for(int i=0; i<8; i+=2) {
                double lat, lon;
                GetLLFromPix(wxPoint(p[i], p[i+1]), &lat, &lon);

                // use 2 degree grid
                double grid = 2;
                int lat_splits = floor(fabs(lat-lastlat) / grid);
                double lond = fabs(lon-lastlon);
                int lon_splits = floor((lond > 180 ? 360-lond : lond) / grid);
                int splits = wxMax(lat_splits, lon_splits) + 1;

                for(int k = 1; k<splits; k++) {
                    float d = (float)k / splits;
                    GetLLFromPix(wxPoint((1-d)*p[li] + d*p[i], (1-d)*p[li+1] + d*p[i+1]), pll+j, pll+j+1);
                    j += 2;
                }
                pll[j++] = lat;
                pll[j++] = lon;
                li = i;
                lastlat = lat, lastlon = lon;
            }
        } else {
            j=8;
            for(int i=0; i<j; i+=2)
                GetLLFromPix(wxPoint(p[i], p[i+1]), pll+i, pll+i+1);
        }

        // resolve (this works even if rectangle crosses both 0 and 180)
        for(int i=0; i<j; i+=2) {
            if(pll[i+1] <= clon - 180)
                pll[i+1] += 360;
            else if(pll[i+1] >= clon + 180)
                pll[i+1] -= 360;
        }

        r.Union(LLRegion(j/2, pll));
        it.NextRect();
    }
    return r;
#endif
}
Esempio n. 14
0
wxSVGRect wxSVGVideoElement::GetResultBBox(wxSVG_COORDINATES coordinates) {
	return GetBBox(coordinates);
}
Esempio n. 15
0
void Route::Draw( ocpnDC& dc, ViewPort &vp, const LLBBox &box )
{
    if( pRoutePointList->empty() )
        return;

    LLBBox test_box = GetBBox();
    if( box.IntersectOut( test_box ) ) // Route is wholly outside window
        return;

    int width = g_route_line_width;
    if( m_width != WIDTH_UNDEFINED ) width = m_width;

    if( m_bVisible && m_bRtIsSelected ) {
        wxPen spen = *g_pRouteMan->GetSelectedRoutePen();
        spen.SetWidth( width );
        dc.SetPen( spen );
        dc.SetBrush( *g_pRouteMan->GetSelectedRouteBrush() );
    }
    else if ( m_bVisible )
    {
        wxPenStyle style = wxPENSTYLE_SOLID;
        wxColour col;
        if( m_style != wxPENSTYLE_INVALID ) style = m_style;
        if( m_Colour == wxEmptyString ) {
            col = g_pRouteMan->GetRoutePen()->GetColour();
        } else {
            for( unsigned int i = 0; i < sizeof( ::GpxxColorNames ) / sizeof(wxString); i++ ) {
                if( m_Colour == ::GpxxColorNames[i] ) {
                    col = ::GpxxColors[i];
                    break;
                }
            }
        }
        dc.SetPen( *wxThePenList->FindOrCreatePen( col, width, style ) );
        dc.SetBrush( *wxTheBrushList->FindOrCreateBrush( col, wxBRUSHSTYLE_SOLID ) );
    }

    if( m_bVisible && m_bRtIsActive )
    {
        wxPen spen = *g_pRouteMan->GetActiveRoutePen();
        spen.SetWidth( width );
        dc.SetPen( spen );
        dc.SetBrush( *g_pRouteMan->GetActiveRouteBrush() );
    }

    wxPoint rpt1, rpt2;
    if ( m_bVisible )
        DrawPointWhich( dc, 1, &rpt1 );

    wxRoutePointListNode *node = pRoutePointList->GetFirst();
    RoutePoint *prp1 = node->GetData();
    node = node->GetNext();

    if ( !m_bVisible && prp1->m_bKeepXRoute )
        prp1->Draw( dc );

    while( node ) {

        RoutePoint *prp2 = node->GetData();
        if ( !m_bVisible && prp2->m_bKeepXRoute )
            prp2->Draw( dc );
        else if (m_bVisible)
            prp2->Draw( dc, &rpt2 );

        if ( m_bVisible )
        {
            //    Handle offscreen points
            bool b_2_on = vp.GetBBox().Contains( prp2->m_lat,  prp2->m_lon );
            bool b_1_on = vp.GetBBox().Contains( prp1->m_lat,  prp1->m_lon );

            //Simple case
            if( b_1_on && b_2_on ) RenderSegment( dc, rpt1.x, rpt1.y, rpt2.x, rpt2.y, vp, true, m_hiliteWidth ); // with arrows

            //    In the cases where one point is on, and one off
            //    we must decide which way to go in longitude
            //     Arbitrarily, we will go the shortest way

            double pix_full_circle = WGS84_semimajor_axis_meters * mercator_k0 * 2 * PI
                                     * vp.view_scale_ppm;
            double dp = pow( (double) ( rpt1.x - rpt2.x ), 2 ) + pow( (double) ( rpt1.y - rpt2.y ), 2 );
            double dtest;
            int adder;
            if( b_1_on && !b_2_on ) {
                if( rpt2.x < rpt1.x ) adder = (int) pix_full_circle;
                else
                    adder = -(int) pix_full_circle;

                dtest = pow( (double) ( rpt1.x - ( rpt2.x + adder ) ), 2 )
                        + pow( (double) ( rpt1.y - rpt2.y ), 2 );

                if( dp < dtest ) adder = 0;

                RenderSegment( dc, rpt1.x, rpt1.y, rpt2.x + adder, rpt2.y, vp, true, m_hiliteWidth );
            } else if( !b_1_on ) {
                if( rpt1.x < rpt2.x ) adder = (int) pix_full_circle;
                else
                    adder = -(int) pix_full_circle;

                float rxd = rpt2.x - ( rpt1.x + adder );
                float ryd = rpt1.y - rpt2.y;
                dtest = rxd*rxd + ryd*ryd;

                if( dp < dtest ) adder = 0;

                RenderSegment( dc, rpt1.x + adder, rpt1.y, rpt2.x, rpt2.y, vp, true, m_hiliteWidth );
            }
        }

        rpt1 = rpt2;
        prp1 = prp2;

        node = node->GetNext();
    }
}
Esempio n. 16
0
u16 VTree::Trace(const Vec3f &origin, const Vec3f &dir, u16 cmin) const {
    Vec3f idir = VInv(dir);

    BBox box = GetBBox();
    if(dir.x < 0.0f)
        Swap(box.min.x, box.max.x);
    if(dir.y < 0.0f)
        Swap(box.min.y, box.max.y);
    if(dir.z < 0.0f)
        Swap(box.min.z, box.max.z);

    float rmin = Max( Max(
                          (box.min.x - origin.x) * idir.x,
                          (box.min.y - origin.y) * idir.y),
                      (box.min.z - origin.z) * idir.z );
    float rmax = Min( Min(
                          (box.max.x - origin.x) * idir.x,
                          (box.max.y - origin.y) * idir.y),
                      (box.max.z - origin.z) * idir.z );

    rmin = Max(0.0f, rmin);
    rmax = Max(0.0f, rmax);

    struct StackElem {
        int node;
        float min, max;
    } stack[64], *top = stack;

    int signs[3] = { idir.x < 0.0f, idir.y < 0.0f, idir.z < 0.0f };
    const Node *node = &nodes[startNode];

    while(true) {
        if(node->max < cmin || rmin >= rmax) {
            if(top == stack)
                return 0;

            top--;
            rmin = top->min;
            rmax = top->max;
            node = &nodes[top->node];
            continue;
        }
        if(node->IsLeaf() || node->min == node->max)
            return node->max;

        int axis = node->axis;
        int sign = signs[axis];
        float t = (node->split - (&origin.x)[axis]) * (&idir.x)[axis];

        if(rmax <= t) {
            node = &nodes[node->child[sign]];
            continue;
        }
        if(rmin >= t) {
            node = &nodes[node->child[sign ^ 1]];
            continue;
        }

        top->min = t;
        top->max = rmax;
        top->node = node->child[sign ^ 1];
        top++;

        rmax = t;
        node = &nodes[node->child[sign]];
    }
}
Esempio n. 17
0
bool TMesh::ReadOffFile(char *filename, bool wcolor)
{
    ifstream fin_temp;
    fin_temp.open(filename);
    if( !fin_temp.good() ) {
        return false;
    }

    ofstream fout_temp;
    fout_temp.open("temp.m");
    if(!fout_temp.good()) {
        cerr<<"Failed to open file temp.m"<<endl;
        return false;
    }

    // Read the off file and skip the comments.
    // Write the comment-less off file to a file, called "temp.m".
    while(! fin_temp.eof()) {
        char line[90];
        fin_temp.getline(line, 90);
        if(line[0] == 'O' || line[0] == '#')
            ;
        else
            fout_temp << line << endl;
    }
    fin_temp.close();
    fout_temp.close();


    FILE *fp;
    if( (fp = fopen("temp.m", "r")) == NULL ) {
        cerr<<"Failed to open file temp.m"<<endl;
        return false;
    }

    unsigned int n_ver, n_facet, n_edge;
    fscanf(fp, "%d %d %d", &n_ver, &n_facet, &n_edge);

//  cerr<<"n_ver: "<<n_ver<<" n_facet: "<<n_facet<<endl;

    float x, y, z;
    //vertex information
    for(unsigned int i = 0; i < n_ver; i ++) {
        fscanf(fp, "%f %f %f", &x, &y, &z);
        //cerr<<"x y z"<<x<<" "<<y<<" "<<z<<endl;
        //VTMesh v(x, y, z);
        add_vertex( VTMesh(x, y, z) );
    }

    //cout<<"vertex done"<<endl;

    //facet information
    int nv, vid0, vid1, vid2;
    float r, g, b, a;
    for(unsigned int i = 0; i < n_facet; i ++) {
        fscanf(fp, "%d %d %d %d", &nv, &vid0, &vid1, &vid2);
        if(wcolor) fscanf(fp, "%f %f %f %f", &r, &g, &b, &a);


        unsigned int fid = add_facet( FTMesh(vid0, vid1, vid2) );
        assert(fid == i);
    }
    //cerr<<"facet done"<<endl;

    assert(v_count() == n_ver);
    assert(f_count() == n_facet);

    //get the bounding box of mesh
    GetBBox();

    //Delete the temp.m file
    system("rm temp.m");

    //Generate the topology for tmesh
    GenerateMeshTopo();
    //Mark the non_manifoldness
    MarkNonManifoldness();
    //debug
//  PrintMeshTopo();
//  getchar();

    return true;
}