bool Clipping::clip(Object* obj){
    switch(obj->getType()){
    case ObjType::OBJECT:
        break;
    case ObjType::POINT:
        return clipPoint(obj->getNCoord(0));
    case ObjType::LINE:
        return clipLine(obj->getNCoord(0), obj->getNCoord(1));
    case ObjType::POLYGON:
        return clipPolygon(obj);
    case ObjType::BEZIER_CURVE:
    case ObjType::BSPLINE_CURVE:
        return clipCurve(obj);
    case ObjType::OBJECT3D:{
        Object3D *obj3d = (Object3D*) obj;
        bool draw = false;
        for(auto &face : obj3d->getFaceList()){
            bool tmp = clipPolygon(&face);
            if(!tmp){ face.getNCoords().clear(); }
            draw |= tmp;
        }
        return draw;
    }case ObjType::BEZIER_SURFACE:
    case ObjType::BSPLINE_SURFACE:{
        Surface *surf = (Surface*) obj;
        bool draw = false;
        for(auto &curve : surf->getCurveList()){
            bool tmp = clipCurve(&curve);
            if(!tmp){ curve.getNCoords().clear(); }
            draw |= tmp;
        }
        return draw;
    }}
    return false;
}
示例#2
0
GeoDataDocument *VectorClipper::clipTo(const GeoDataLatLonBox &tileBoundary, int zoomLevel)
{
    bool const useBaseClipper = false;
    if (useBaseClipper) {
        return clipToBaseClipper(tileBoundary);
    }

    bool const filterSmallAreas = zoomLevel > 10 && zoomLevel < 17;
    GeoDataDocument* tile = new GeoDataDocument();
    auto const clip = clipPath(tileBoundary, zoomLevel);
    GeoDataLinearRing ring;
    ring << GeoDataCoordinates(tileBoundary.west(), tileBoundary.north());
    ring << GeoDataCoordinates(tileBoundary.east(), tileBoundary.north());
    ring << GeoDataCoordinates(tileBoundary.east(), tileBoundary.south());
    ring << GeoDataCoordinates(tileBoundary.west(), tileBoundary.south());
    qreal const minArea = filterSmallAreas ? 0.01 * area(ring) : 0.0;
    foreach (GeoDataPlacemark const * placemark, potentialIntersections(tileBoundary)) {
        GeoDataGeometry const * const geometry = placemark ? placemark->geometry() : nullptr;
        if (geometry && tileBoundary.intersects(geometry->latLonAltBox())) {
            if(geometry->nodeType() == GeoDataTypes::GeoDataPolygonType) {
                clipPolygon(placemark, clip, minArea, tile);
            } else if (geometry->nodeType() == GeoDataTypes::GeoDataLineStringType) {
                clipString<GeoDataLineString>(placemark, clip, minArea, tile);
            } else if (geometry->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
                clipString<GeoDataLinearRing>(placemark, clip, minArea, tile);
            } else {
                tile->append(new GeoDataPlacemark(*placemark));
            }
        }
    }
bool Clipping::clip(Object* obj){
    switch(obj->getType()){
    case ObjType::POINT:
        return clipPoint(obj->getNCoord(0));
    case ObjType::LINE:
        return clipLine(obj->getNCoord(0), obj->getNCoord(1));
    case ObjType::POLYGON:
        return clipPolygon(obj);
    case ObjType::BEZIER_CURVE:
        return clipCurve(obj);
    default:
        return false;
    }
}
示例#4
0
// A succession of move and vector is gathered in a single polygon
// to make drawing faster
void QtGnuplotScene::flushCurrentPolygon()
{
	if (m_currentPolygon.size() < 2) {
		m_currentPolygon.clear();
		return;
	}

	clipPolygon(m_currentPolygon);
	QPainterPath path;
	path.addPolygon(m_currentPolygon);
	QGraphicsPathItem *pathItem;
	pathItem = addPath(path, m_currentPen, Qt::NoBrush);
	pathItem->setZValue(m_currentZ++);
	m_currentPolygon.clear();
	if (!m_inKeySample)
		m_currentGroup.append(pathItem);
}
示例#5
0
// A succession of move and vector is gathered in a single polygon
// to make drawing faster
void QtGnuplotScene::flushCurrentPolygon()
{
	if (m_currentPolygon.size() < 2) {
		m_currentPolygon.clear();
		return;
	}

	clipPolygon(m_currentPolygon);
	if (!m_inKeySample)
		m_currentPointsItem->addPolygon(m_currentPolygon, m_currentPen);
	else
	{
		flushCurrentPointsItem();
		// Including the polygon in a path is necessary to avoid closing the polygon
		QPainterPath path;
		path.addPolygon(m_currentPolygon);
		QGraphicsPathItem *pathItem;
		pathItem = addPath(path, m_currentPen, Qt::NoBrush);
		pathItem->setZValue(m_currentZ++);
	}
	m_currentPolygon.clear();
}
示例#6
0
void display( void ) {

	glClear( GL_COLOR_BUFFER_BIT );

	/*
	** Begin by drawing all the clip regions in black
	** using a solid line of width 1
	*/

	glColor3f( 0.0, 0.0, 0.0 );
	glLineStipple( 1, 0xffff );
	glLineWidth( 1.0 );
	print_poly( 4, clip1 );
	print_poly( 4, clip2 );

	/*
	** For each polygon, print the polygon before and after
	** clipping in a polygon-specific color; print the original
	** using a dotted line of width 2, and the clipped using a
	** solid line of width 3
	*/

	/* 
	** first polygon:  entirely within region
	*/

	wl = 0;
	glColor3f( 1.0, 0.0, 0.0 );		/* red */
	glLineStipple( 1, 0x0f0f ); glLineWidth( 2.0 );
	print_poly( 4, quad1 );
	clipPolygon( 4, quad1, &wl, w,
			clip1[0][0], clip1[0][1], clip1[2][0], clip1[2][1] );
	glLineStipple( 1, 0xffff ); glLineWidth( 3.0 );
	print_poly( wl, w );

	/*
	** second polygon:  entirely outside region
	*/

	wl = 0;
	glColor3f( 0.0, 1.0, 0.0 );		/* green */
	glLineStipple( 1, 0x0f0f ); glLineWidth( 2.0 );
	print_poly( 4, quad2 );
	clipPolygon( 4, quad2, &wl, w,
			clip1[0][0], clip1[0][1], clip1[2][0], clip1[2][1] );
	/* shouldn't draw anything! */
	if( wl > 0 ) {
		glLineStipple( 1, 0xffff ); glLineWidth( 3.0 );
		print_poly( wl, w );
	}

	/*
	** third polygon: triangle, one point outside region
	*/

	wl = 0;
	glColor3f( 0.0, 1.0, 1.0 );             /* cyan */
	glLineStipple( 1, 0x0f0f ); glLineWidth( 2.0 );
	print_poly( 3, tri1 );
	clipPolygon( 3, tri1, &wl, w,
		        clip2[0][0], clip2[0][1], clip2[2][0], clip2[2][1] );
	glLineStipple( 1, 0xffff ); glLineWidth( 3.0 );
	print_poly( wl, w );

	/*
	** fourth polygon:  part outside on right
	*/

	wl = 0;
	glColor3f( 1.0, 0.0, 1.0 );		/* magenta */
	glLineStipple( 1, 0x0f0f ); glLineWidth( 2.0 );
	print_poly( 4, quad4 );
	clipPolygon( 4, quad4, &wl, w,
			clip1[0][0], clip1[0][1], clip1[2][0], clip1[2][1] );
	glLineStipple( 1, 0xffff ); glLineWidth( 3.0 );
	print_poly( wl, w );

	/*
	** fifth polygon:  halfway outside on left
	*/

	wl = 0;
	glColor3f( 0.0, 0.0, 1.0 );		/* blue */
	glLineStipple( 1, 0x0f0f ); glLineWidth( 2.0 );
	print_poly( 4, quad3 );
	clipPolygon( 4, quad3, &wl, w,
			clip2[0][0], clip2[0][1], clip2[2][0], clip2[2][1] );
	glLineStipple( 1, 0xffff ); glLineWidth( 3.0 );
	print_poly( wl, w );

	/* 
	** Ensure that everything is displayed
	*/
	glFlush();

}
示例#7
0
void display( void ) {
    int i;

    /*
     * Clear window
     */
    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glClear( GL_COLOR_BUFFER_BIT );

    /*
     * Set the viewWindow
     */
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    gluOrtho2D( 0, 300, 0, 300 );

    /*
     * Set the viewport to match the viewWindow
     */
    glViewport( 0, 0, 299, 299 );

    /*
     * first polygon:  entirely within region
     */

    wl = 0;
    clipPolygon( 4, quad1x, quad1y, &wl, wx, wy, 10, 10, 50, 50 );
    glColor3f( 1.0, 0.0, 0.0 );		/* red */
    print_loop( 4, quad1x, quad1y );
    print_poly( wl, wx, wy );

    /*
     * second polygon:  entirely outside region
     */

    wl = 0;
    clipPolygon( 4, quad2x, quad2y, &wl, wx, wy, 10, 10, 50, 50 );
    /* shouldn't draw anything! */
    if( wl > 0 ) {
        glColor3f( 0.0, 1.0, 0.0 );		/* green */
        print_loop( 4, quad2x, quad2y );
        print_poly( wl, wx, wy );
    }

    /*
     * third polygon:  halfway outside on left
     */

    wl = 0;
    clipPolygon( 4, quad3x, quad3y, &wl, wx, wy, 30, 10, 70, 80 );
    glColor3f( 0.0, 0.0, 1.0 );		/* blue */
    print_loop( 4, quad3x, quad3y );
    print_poly( wl, wx, wy );

    /*
     * fourth polygon:  part outside on right
     */

    wl = 0;
    clipPolygon( 4, quad4x, quad4y, &wl, wx, wy, 10, 10, 50, 50 );
    glColor3f( 1.0, 0.0, 1.0 );		/* magenta */
    print_loop( 4, quad4x, quad4y );
    print_poly( wl, wx, wy );

    /*
     * fifth polygon:  enclosing
     */

    wl = 0;
    clipPolygon( 5, pent1x, pent1y, &wl, wx, wy, 90, 20, 100, 30 );
    glColor3f( 0.5, 0.5, 1.0 );		/* reddish-greenish-blue ? */
    print_loop( 5, pent1x, pent1y );
    print_poly( wl, wx, wy );

    /*
     * sixth polygon:  outside on left and bottom
     */

    wl = 0;
    clipPolygon( 5, pent1x, pent1y, &wl, wx, wy, 90, 34, 120, 60 );
    glColor3f( 1.0, 0.5, 1.0 );		/* red-greenish-blue ? */
    print_loop( 5, pent1x, pent1y );
    print_poly( wl, wx, wy );

    /*
     * seventh polygon:  outside on top, right, and bottom
     */

    wl = 0;
    clipPolygon( 7, hept1x, hept1y, &wl, wx, wy, 90, 80, 130, 110 );
    glColor3f( 0.0, 0.0, 0.0 );		/* black */
    print_loop( 7, hept1x, hept1y );
    print_poly( wl, wx, wy );

    /*
     * Flushs OpenGL commands to display
     */
    glFlush();

}