예제 #1
0
void Triangulator::addShape( const Shape2d &shape, float approximationScale )
{
	size_t numContours = shape.getContours().size();
	for( size_t p = 0; p < numContours; ++p ) {
		addPath( shape.getContour(p), approximationScale );
	}	
}
예제 #2
0
Shape2d	Shape2d::transformCopy( const MatrixAffine2f &matrix ) const
{
	Shape2d result;
	for( vector<Path2d>::const_iterator contIt = mContours.begin(); contIt != mContours.end(); ++contIt )
		result.appendContour( contIt->transformCopy( matrix ) );
	return result;
}
예제 #3
0
PolyLine2f calcConvexHull( const Shape2d &shape )
{
    polygon poly;
    for( auto contourIt = shape.getContours().begin(); contourIt != shape.getContours().end(); ++contourIt )
        includePathExtremeties( *contourIt, &poly );

    polygon result;
    boost::geometry::convex_hull( poly, result );

    return toPolyLine<float>( result );
}
예제 #4
0
vector<PolyLine2f> PolygonBooleanApp::makeLetterA() const
{
	vector<PolyLine2f> result;	
	Font arial( "Arial", 512 );
	Shape2d shape = arial.getGlyphShape( arial.getGlyphChar( 'a' ) );
	for( vector<Path2d>::const_iterator pathIt = shape.getContours().begin(); pathIt != shape.getContours().end(); ++pathIt ) {
		PolyLine2f contour( pathIt->subdivide() );
		contour.offset( vec2( 200, 260 ) );
		result.push_back( contour );
	}
	return result;
}
예제 #5
0
void NIUserMaskApp::update()
{
	if ( mNI.checkNewVideoFrame() )
	{
		Surface8u maskSurface = mNIUserTracker.getUserMask();

		cv::Mat cvMask, cvMaskFiltered;
		cvMask = toOcv( Channel8u( maskSurface ) );
		cv::blur( cvMask, cvMaskFiltered, cv::Size( mBlurAmt, mBlurAmt ) );

		cv::Mat dilateElm = cv::getStructuringElement( cv::MORPH_RECT,
				cv::Size( mDilateAmt, mDilateAmt ) );
		cv::Mat erodeElm = cv::getStructuringElement( cv::MORPH_RECT,
				cv::Size( mErodeAmt, mErodeAmt ) );
		cv::erode( cvMaskFiltered, cvMaskFiltered, erodeElm, cv::Point( -1, -1 ), 1 );
		cv::dilate( cvMaskFiltered, cvMaskFiltered, dilateElm, cv::Point( -1, -1 ), 3 );
		cv::erode( cvMaskFiltered, cvMaskFiltered, erodeElm, cv::Point( -1, -1 ), 1 );
		cv::blur( cvMaskFiltered, cvMaskFiltered, cv::Size( mBlurAmt, mBlurAmt ) );

		cv::threshold( cvMaskFiltered, cvMaskFiltered, mThres, 255, CV_THRESH_BINARY);

		vector< vector< cv::Point > > contours;
		cv::findContours( cvMaskFiltered, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE );

		mShape.clear();
		for ( vector< vector< cv::Point > >::const_iterator it = contours.begin();
				it != contours.end(); ++it )
		{
			vector< cv::Point >::const_iterator pit = it->begin();

			if ( it->empty() )
				continue;

			mShape.moveTo( fromOcv( *pit ) );

			++pit;
			for ( ; pit != it->end(); ++pit )
			{
				mShape.lineTo( fromOcv( *pit ) );
			}
			mShape.close();
		}
	}
}
예제 #6
0
void LocationApp::setup()
{
    // Define properties
    mHeading = 0.0f;
    timeline().apply( &mRotationAngle, 0.0f, (float)(2 * M_PI), 8.0f ).loop();
    timeline().apply( &mDotRadius, 0.0f, 0.1f, 0.5f ).loop();

    LocationManager::enable();
    LocationManager::getSignalLocationChanged().connect(
        std::bind( &LocationApp::locationChanged, this, std::_1 ) );
#if defined( CINDER_COCOA_TOUCH )
    LocationManager::getSignalHeadingChanged().connect(
        std::bind( &LocationApp::headingChanged, this, std::_1 ) );
#endif

    // Load globe texture,
    setFrameRate( 60.0f );
    mTexture = gl::Texture( loadImage( loadResource( RES_EARTH_JPG ) ) );
    mTexture.setFlipped( true );

    // Set up view
    gl::enable( GL_TEXTURE_2D );
    gl::enableAlphaBlending();

    // Set up light
    mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
    mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
    mLight->setAmbient( ColorAf::gray( 0.843f ) );
    mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
    mLight->enable();

    // Build the heading arrow
    float size = 80.0f;
    mArrow.moveTo( Vec2f(         0.0f, -size * 0.5f  ) );
    mArrow.lineTo( Vec2f(  size * 0.5f,  size * 0.5f  ) );
    mArrow.lineTo( Vec2f(         0.0f,  size * 0.25f ) );
    mArrow.lineTo( Vec2f( -size * 0.5f,  size * 0.5f  ) );
    mArrow.close();
}
Shape2d getCenteredShape2dfromSVGDoc(svg::DocRef doc) {
    Shape2d s = doc->getShape();
    s.transform( MatrixAffine2f::makeTranslate( -doc->getSize()/2 ) );
    return s;
}
예제 #8
0
void Shape2d::append( const Shape2d &shape )
{
	for( vector<Path2d>::const_iterator pathIt = shape.getContours().begin(); pathIt != shape.getContours().end(); ++pathIt )
		appendContour( *pathIt );
}