コード例 #1
0
// -----------------------------------------------------------------------------
// CTestSDKSkins::TestFBCCSetFrameRectsL
// -----------------------------------------------------------------------------
TInt CTestSDKSkins::TestFBCCSetFrameRectsL( CStifItemParser& /*aItem*/ )
{
    TAknsItemID itemID;

    TPoint pointTL( 0, 0 );
    TPoint pointBR( KLength, KLength );
    const TInt KOutPoint = 50;
    TPoint outPoint( KOutPoint, KOutPoint );
    const TInt KInPoint = 40;
    TPoint inPoint( KInPoint, KInPoint );
    TRect outRect( pointTL, outPoint );
    TRect inRect( pointBR, inPoint );

    CAknsFrameBackgroundControlContext* context =
        CAknsFrameBackgroundControlContext::NewL( itemID,
                outRect,
                inRect,
                ETrue );
    CleanupStack::PushL( context );
    STIF_ASSERT_NOT_NULL( context );

    context->SetFrameRects( outRect, inRect );

    CleanupStack::PopAndDestroy( context );

    return KErrNone;

}
コード例 #2
0
ファイル: ImageWnd.cpp プロジェクト: sunlong0724/myworkspce
CRect CImageWnd::ValidateRoi(CRect inRect)
{
   CRect outRect(inRect);
   outRect.NormalizeRect();

   if (m_pView == NULL || m_pView->GetBuffer() == NULL)
      return outRect;

   int viewWidth = m_pView->GetBuffer()->GetWidth();
   int viewHeight = m_pView->GetBuffer()->GetHeight();

   if (outRect.left < 0)
      outRect.left = 0;

   if (outRect.right > viewWidth - 1)
      outRect.right = viewWidth - 1;

   if (outRect.top < 0)
      outRect.top = 0;

   if (outRect.bottom > viewHeight - 1)
      outRect.bottom = viewHeight - 1;

   return outRect;
}
コード例 #3
0
ファイル: IFont.cpp プロジェクト: Chameleonhider/noleafclover
		void FallbackFontRenderer::Draw(uint32_t unicode, spades::Vector2 offset,
										float size, spades::Vector4 color) {
			renderer->SetColorAlphaPremultiplied(color);
			float x = offset.x;
			float y = offset.y;
			
			auto glyph = FindGlyph(unicode);
			if(glyph.img == nullptr) {
				// no glyph found! draw box in the last resort
				IImage *img = whiteImage;
				renderer->DrawImage(img, AABB2(x, y, size, 1.f));
				renderer->DrawImage(img, AABB2(x, y + size - 1.f, size, 1.f));
				renderer->DrawImage(img, AABB2(x, y + 1.f, 1.f, size - 2.f));
				renderer->DrawImage(img, AABB2(x + size - 1.f, y + 1.f, 1.f, size - 2.f));
				return;
			}
			
			if(glyph.w == 0) {
				// null glyph.
				return;
			}
			
			float scale = size * glyph.sizeInverse;
			if(roundSize || scale < 1.f) {
				float newScale = std::max(1.f, floorf(scale));
				// vertical-align: baseline
				offset.y += (scale - newScale) * glyph.size;
				scale = newScale;
			}
			
			AABB2 inRect(glyph.x, glyph.y, glyph.w, glyph.h);
			AABB2 outRect(glyph.offX, glyph.offY, glyph.w, glyph.h);
			
			// margin to make the border completely transparent
			// (considering the OpenGL's linear interpolation)
			if(!roundSize){
				inRect.min.x -= 0.5f;
				inRect.min.y -= 0.5f;
				outRect.min.x -= 0.5f;
				outRect.min.y -= 0.5f;
				inRect.max.x += 0.5f;
				inRect.max.y += 0.5f;
				outRect.max.x += 0.5f;
				outRect.max.y += 0.5f;
			}
			
			outRect.min *= scale;
			outRect.max *= scale;
			
			outRect.min += offset;
			outRect.max += offset;
			
			renderer->DrawImage(glyph.img, outRect, inRect);
		}
コード例 #4
0
ファイル: tover.cpp プロジェクト: CroW-CZ/opentoonz
void TRop::over(const TRasterP &rout, const TRasterP &rup, const TPoint &pos)
{
	TRect outRect(rout->getBounds());
	TRect upRect(rup->getBounds() + pos);
	TRect intersection = outRect * upRect;
	if (intersection.isEmpty())
		return;

	TRasterP cRout = rout->extract(intersection);
	TRect r = intersection - pos;
	TRasterP cRup = rup->extract(r);

	TRaster32P rout32 = cRout, rup32 = cRup;
	TRaster64P rout64 = cRout, rup64 = cRup;

	TRasterGR8P rout8 = cRout, rup8 = cRup;

	TRasterCM32P routCM32 = cRout, rupCM32 = cRup;

	rout->lock();
	rup->lock();

	// TRaster64P rout64 = rout, rin64 = rin;
	if (rout32 && rup32) {
#ifdef _WIN32
		if (TSystem::getCPUExtensions() & TSystem::CpuSupportsSse2)
			do_over_SSE2(rout32, rup32);
		else
#endif
			do_overT2<TPixel32, UCHAR>(rout32, rup32);
	} else if (rout64) {
		if (!rup64) {
			TRaster64P raux(cRup->getSize());
			TRop::convert(raux, cRup);
			rup64 = raux;
		}
		do_overT2<TPixel64, USHORT>(rout64, rup64);
	} else if (rout32 && rup8)
		do_over(rout32, rup8);
	else if (rout8 && rup32)
		do_over(rout8, rup32);
	else if (rout8 && rup8)
		TRop::copy(rout8, rup8);
	else if (routCM32 && rupCM32)
		do_over(routCM32, rupCM32);
	else {
		rout->unlock();
		rup->unlock();
		throw TRopException("unsupported pixel type");
	}

	rout->unlock();
	rup->unlock();
}
コード例 #5
0
ファイル: QmlVlcVideoSurface.cpp プロジェクト: RSATom/QmlVlc
QSGNode* QmlVlcVideoSurface::updatePaintNode( QSGNode* oldNode,
        UpdatePaintNodeData* /*data*/ )
{
    SGVlcVideoNode* node = static_cast<SGVlcVideoNode*>( oldNode );
    if( !m_frame ) {
        delete node;
        return 0;
    }

    if( !node )
        node = new SGVlcVideoNode;

    QRectF outRect( 0, 0, width(), height() );
    QRectF srcRect( 0, 0, 1., 1. );

    if( Stretch != fillMode() ) {
        const uint16_t fw = m_frame->width;
        const uint16_t fh = m_frame->height;

        const qreal frameAspect = qreal( fw ) / fh;
        const qreal itemAspect = width() / height();

        if( PreserveAspectFit == fillMode() ) {
            qreal outWidth = width();
            qreal outHeight = height();
            if( frameAspect > itemAspect )
                outHeight = outWidth / frameAspect;
            else if( frameAspect < itemAspect )
                outWidth = outHeight * frameAspect;

            outRect = QRectF( ( width() - outWidth ) / 2, ( height() - outHeight ) / 2,
                              outWidth, outHeight );
        } else if( PreserveAspectCrop == fillMode() ) {
            if( frameAspect > itemAspect ) {
                srcRect.setX( ( 1. - itemAspect / frameAspect ) / 2 );
                srcRect.setWidth( 1. - srcRect.x() - srcRect.x() );
            } else if( frameAspect < itemAspect ) {
                srcRect.setY( ( 1. - frameAspect / itemAspect ) / 2 );
                srcRect.setHeight( 1. - srcRect.y() - srcRect.y() );
            }
        }
    }

    if( m_frameUpdated ) {
        node->setFrame( m_frame );
        m_frameUpdated = false;
    }
    node->setRect( outRect, srcRect );

    return node;
}
コード例 #6
0
ファイル: printwin.cpp プロジェクト: CodeSmithyIDE/wxWidgets
bool wxWindowsPrintPreview::RenderPageIntoBitmap(wxBitmap& bmp, int pageNum)
{
    // The preview, as implemented in wxPrintPreviewBase (and as used prior to
    // wx3) is inexact: it uses screen DC, which has much lower resolution and
    // has other properties different from printer DC, so the preview is not
    // quite right.
    //
    // To make matters worse, if the application depends heavily on
    // GetTextExtent() or does text layout itself, the output in preview and on
    // paper can be very different. In particular, wxHtmlEasyPrinting is
    // affected and the preview can be easily off by several pages.
    //
    // To fix this, we render the preview into high-resolution enhanced
    // metafile with properties identical to the printer DC. This guarantees
    // metrics correctness while still being fast.


    // print the preview into a metafile:
    wxPrinterDC printerDC(m_printDialogData.GetPrintData());
    wxEnhMetaFileDC metaDC(printerDC,
                           wxEmptyString,
                           printerDC.GetSize().x, printerDC.GetSize().y);

    if ( !RenderPageIntoDC(metaDC, pageNum) )
        return false;

    wxEnhMetaFile *metafile = metaDC.Close();
    if ( !metafile )
        return false;

    // now render the metafile:
    wxMemoryDC bmpDC;
    bmpDC.SelectObject(bmp);
    bmpDC.Clear();

    wxRect outRect(0, 0, bmp.GetWidth(), bmp.GetHeight());
    metafile->Play(&bmpDC, &outRect);


    delete metafile;

    // TODO: we should keep the metafile and reuse it when changing zoom level

    return true;
}
コード例 #7
0
ファイル: ImageUtils.cpp プロジェクト: techtim/ofxESCPOS
ofPixels_<unsigned char> ImageUtils::scaleAndCropTo(const ofPixels_<unsigned char>& pixels,
                                                    int width,
                                                    int height,
                                                    ofScaleMode scaleMode)
{
    ofRectangle inRect(0,0,pixels.getWidth(),pixels.getHeight());
    ofRectangle outRect(0,0,width,height);

    inRect.scaleTo(outRect,scaleMode);

    ofPixels_<unsigned char> inPixels = pixels;

    inPixels.resize(inRect.getWidth(),inRect.getHeight());

    ofPixels_<unsigned char> outPixels;

    inPixels.cropTo(outPixels,
                    outRect.x - inRect.x,
                    0,
                    outRect.width,
                    outRect.height);

    return outPixels;
}
コード例 #8
0
ファイル: MapView.cpp プロジェクト: BuildandShoot/openspades
		void MapView::Draw(){
			World *world = client->GetWorld();
			if(!world)
				return;
			
			Player *player = world->GetLocalPlayer();
			if(client->IsFollowing()){
				player = world->GetPlayer(client->followingPlayerId);
			}
			if(!player)
				return;
			
			if(largeMap)
				if(zoomState < .0001f)
					return;
			
			GameMap *map = world->GetMap();
			Vector2 mapSize = MakeVector2(map->Width(), map->Height());
			
			Vector3 pos = player->GetPosition();;
			if(player->GetTeamId() >= 2){
				pos = client->followPos;
			}
			Vector2 center = {pos.x, pos.y};
			float cfgMapSize = cg_minimapSize;
			if(cfgMapSize < 32) cfgMapSize = 32;
			if(cfgMapSize > 256) cfgMapSize = 256;
			Vector2 mapWndSize = {cfgMapSize, cfgMapSize};
			float scale = actualScale;
			
			center = Mix(center,
						 mapSize * .5f,
						 zoomState);
			
			Vector2 zoomedSize = {512, 512};
			if(renderer->ScreenWidth() < 512.f ||
			   renderer->ScreenHeight() < 512.f)
				zoomedSize = MakeVector2(256, 256);
			if(largeMap){
				float per = zoomState;
				per = 1.f - per;
				per *= per;
				per = 1.f - per;
				per = Mix(.7f, 1.f, per);
				zoomedSize = Mix(MakeVector2(0, 0),
								 zoomedSize,
								 per);
				mapWndSize = zoomedSize;
			}
			
			Vector2 inRange = mapWndSize * .5f * scale;
			AABB2 inRect(center - inRange, center + inRange);
			if(largeMap){
				inRect.min = MakeVector2(0, 0);
				inRect.max = mapSize;
			}else{
				if(inRect.GetMinX() < 0.f)
					inRect = inRect.Translated(-inRect.GetMinX(), 0.f);
				if(inRect.GetMinY() < 0.f)
					inRect = inRect.Translated(0, -inRect.GetMinY());
				if(inRect.GetMaxX() > mapSize.x)
					inRect = inRect.Translated(mapSize.x - inRect.GetMaxX(), 0.f);
				if(inRect.GetMaxY() > mapSize.y)
					inRect = inRect.Translated(0, mapSize.y - inRect.GetMaxY());
			}
			
			
			AABB2 outRect(renderer->ScreenWidth() - mapWndSize.x - 16.f, 16.f,
						  mapWndSize.x,
						  mapWndSize.y);
			if(largeMap){
				outRect.min = MakeVector2((renderer->ScreenWidth() - zoomedSize.x) * .5f,
										  (renderer->ScreenHeight() - zoomedSize.y) * .5f);
				outRect.max =MakeVector2((renderer->ScreenWidth() + zoomedSize.x) * .5f,
										 (renderer->ScreenHeight() + zoomedSize.y) * .5f);
			}
			
			float alpha = 1.f;
			if(largeMap){
				alpha = zoomState;
			}
			
			// fades bg
			if(largeMap) {
				Handle<IImage> bg = renderer->RegisterImage("Gfx/MapBg.png");
				Vector2 scrSize = {renderer->ScreenWidth(),
				renderer->ScreenHeight()};
				float size = std::max(scrSize.x, scrSize.y);
				renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0,alpha * .5f));
				renderer->DrawImage(bg,
									AABB2((scrSize.x - size) * .5f,
										  (scrSize.y - size) * .5f,
										  size, size));
			}
			
			// draw border
			Handle<IImage> border;
			float borderWidth;
			AABB2 borderRect = outRect;
			if(largeMap) {
				border = renderer->RegisterImage("Gfx/MapBorder.png");
				borderWidth = 3.f * outRect.GetHeight() / zoomedSize.y;
			}else{
				border = renderer->RegisterImage("Gfx/MinimapBorder.png");
				borderWidth = 2.f;
			}
			borderRect = borderRect.Inflate(borderWidth - 8.f);
			
			renderer->SetColorAlphaPremultiplied(MakeVector4(alpha,alpha,alpha,alpha));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMinX()-16,
									  borderRect.GetMinY()-16,
									  16, 16),
								AABB2(0, 0, 16, 16));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMaxX(),
									  borderRect.GetMinY()-16,
									  16, 16),
								AABB2(16, 0, 16, 16));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMinX()-16,
									  borderRect.GetMaxY(),
									  16, 16),
								AABB2(0, 16, 16, 16));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMaxX(),
									  borderRect.GetMaxY(),
									  16, 16),
								AABB2(16, 16, 16, 16));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMinX(),
									  borderRect.GetMinY()-16,
									  borderRect.GetWidth(), 16),
								AABB2(16, 0, 0, 16));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMinX(),
									  borderRect.GetMaxY(),
									  borderRect.GetWidth(), 16),
								AABB2(16, 16, 0, 16));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMinX()-16,
									  borderRect.GetMinY(),
									  16, borderRect.GetHeight()),
								AABB2(0, 16, 16, 0));
			renderer->DrawImage(border,
								AABB2(borderRect.GetMaxX(),
									  borderRect.GetMinY(),
									  16, borderRect.GetHeight()),
								AABB2(16, 16, 16, 0));
			
			// draw map
			renderer->SetColorAlphaPremultiplied(MakeVector4(alpha,alpha,alpha,alpha));
			renderer->DrawFlatGameMap(outRect, inRect);
			
			this->inRect = inRect;
			this->outRect = outRect;
			
			// draw grid
			
			renderer->SetColorAlphaPremultiplied(MakeVector4(0,0,0,0.8f*alpha));
			Handle<IImage> dashLine = renderer->RegisterImage("Gfx/DashLine.tga");
			for(float x = 64.f; x < map->Width(); x += 64.f){
				float wx = (x - inRect.GetMinX()) / inRect.GetWidth();
				if(wx < 0.f || wx >= 1.f)
					continue;
				wx = (wx * outRect.GetWidth()) + outRect.GetMinX();
				wx = roundf(wx);
				renderer->DrawImage(dashLine,
									MakeVector2(wx, outRect.GetMinY()),
									AABB2(0, 0, 1.f, outRect.GetHeight()));
			}
			for(float y = 64.f; y < map->Height(); y += 64.f){
				float wy = (y - inRect.GetMinY()) / inRect.GetHeight();
				if(wy < 0.f || wy >= 1.f)
					continue;
				wy = (wy * outRect.GetHeight()) + outRect.GetMinY();
				wy = roundf(wy);
				renderer->DrawImage(dashLine,
									MakeVector2(outRect.GetMinX(), wy),
									AABB2(0, 0, outRect.GetWidth(), 1.f));
			}
			
			// draw grid label
			renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(0.8f*alpha));
			Handle<IImage> mapFont = renderer->RegisterImage("Gfx/Fonts/MapFont.tga");
			for(int i = 0; i < 8; i++){
				float startX = (float)i * 64.f;
				float endX = startX + 64.f;
				if(startX > inRect.GetMaxX() ||
				   endX < inRect.GetMinX())
					continue;
				float fade = std::min((std::min(endX, inRect.GetMaxX()) -
									   std::max(startX, inRect.GetMinX())) /
									  (endX - startX) * 2.f, 1.f);
				renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(fade * .8f * alpha));
				
				float center = std::max(startX, inRect.GetMinX());
				center = .5f * (center + std::min(endX, inRect.GetMaxX()));
				
				float wx = (center - inRect.GetMinX()) / inRect.GetWidth();
				wx = (wx * outRect.GetWidth()) + outRect.GetMinX();
				wx = roundf(wx);
				
				float fntX = static_cast<float>((i & 3) * 8);
				float fntY = static_cast<float>((i >> 2) * 8);
				renderer->DrawImage(mapFont,
									MakeVector2(wx - 4.f, outRect.GetMinY() + 4),
									AABB2(fntX, fntY, 8, 8));
			}
			for(int i = 0; i < 8; i++){
				float startY = (float)i * 64.f;
				float endY = startY + 64.f;
				if(startY > inRect.GetMaxY() ||
				   endY < inRect.GetMinY())
					continue;
				float fade = std::min((std::min(endY, inRect.GetMaxY()) -
									   std::max(startY, inRect.GetMinY())) /
									  (endY - startY) * 2.f, 1.f);
				renderer->SetColorAlphaPremultiplied(MakeVector4(1,1,1,1)*(fade * .8f * alpha));
				
				float center = std::max(startY, inRect.GetMinY());
				center = .5f * (center + std::min(endY, inRect.GetMaxY()));
				
				float wy = (center - inRect.GetMinY()) / inRect.GetHeight();
				wy = (wy * outRect.GetHeight()) + outRect.GetMinY();
				wy = roundf(wy);
				
				int fntX = (i & 3) * 8;
				int fntY = (i >> 2) * 8 + 16;
				renderer->DrawImage(mapFont,
									MakeVector2(outRect.GetMinX() + 4, wy - 4.f),
									AABB2(fntX, fntY, 8, 8));
			}			
			//draw objects
			
			std::string iconmode = cg_Minimap_Player_Icon;//import variable from configuration file
			std::string colormode = cg_Minimap_Player_Color;//import variable from configuration file
			
			Handle<IImage> playerSMG = renderer->RegisterImage("Gfx/Map/SMG.png");
			Handle<IImage> playerRifle = renderer->RegisterImage("Gfx/Map/Rifle.png");
			Handle<IImage> playerShotgun = renderer->RegisterImage("Gfx/Map/Shotgun.png");
			Handle<IImage> playerIcon = renderer->RegisterImage("Gfx/Map/Player.png");
			
			{
				
				IntVector3 teamColor =
				world->GetLocalPlayer()->GetTeamId() >= 2 ?
				IntVector3::Make(200, 200, 200) :
				world->GetTeam(world->GetLocalPlayer()->GetTeamId()).color;
				Vector4 teamColorF = ModifyColor(teamColor);
				teamColorF *= alpha;
				
				// draw local player's view
				{
					Player *p = player;
					Handle<IImage> viewIcon = renderer->RegisterImage("Gfx/Map/View.png");
					if(p->IsAlive()) {
						Vector3 front = p->GetFront2D();
						float ang = atan2(front.x, -front.y);
						if(player->GetTeamId() >= 2){
							ang = client->followYaw - static_cast<float>(M_PI) * .5f;
						}
						
						renderer->SetColorAlphaPremultiplied(teamColorF * 0.9f);
						
						DrawIcon(player->GetTeamId() >= 2 ?
								 client->followPos :
								 p->GetPosition(), viewIcon, ang);
					}
				}
				
				// draw player's icon
				for(int i = 0; i < world->GetNumPlayerSlots(); i++){
					Player * p = world->GetPlayer(i);
					if(p == nullptr ||
					   p->GetTeamId() != world->GetLocalPlayer()->GetTeamId() ||
					   !p->IsAlive())
						continue;
					
					Vector3 front = p->GetFront2D();
					float ang = atan2(front.x, -front.y);
					if(player->GetTeamId() >= 2){
						ang = client->followYaw - static_cast<float>(M_PI) * .5f;
					}
					
					//use a spec color for each player
					if ( colormode=="1"){
						IntVector3 Colorplayer=IntVector3::Make(palette[i][0],palette[i][1],palette[i][2]);
						Vector4 ColorplayerF = ModifyColor(Colorplayer);
						ColorplayerF *=1.0f;
						renderer->SetColorAlphaPremultiplied(ColorplayerF);
					}	
					else {
						renderer->SetColorAlphaPremultiplied(teamColorF);
					}
					
					//use a different icon in minimap according to weapon of player
					if( iconmode=="1"){
						WeaponType weapon=world->GetPlayer(i)->GetWeaponType();
						if (weapon == WeaponType::SMG_WEAPON){
							DrawIcon(player->GetTeamId() >= 2 ?
									client->followPos :
									p->GetPosition(),playerSMG , ang);
						}
						
						else if (weapon == WeaponType::RIFLE_WEAPON){
							DrawIcon(player->GetTeamId() >= 2 ?
									client->followPos :
									p->GetPosition(), playerRifle, ang);
						}
						
						else if (weapon == WeaponType::SHOTGUN_WEAPON){
							DrawIcon(player->GetTeamId() >= 2 ?
									client->followPos :
									p->GetPosition(), playerShotgun, ang);
						}
					}
					else{//draw normal color	
						DrawIcon(player->GetTeamId() >= 2 ?
								client->followPos :
								p->GetPosition(), playerIcon, ang);
					}
				}
			}
			
			IGameMode* mode = world->GetMode();
			if( mode && IGameMode::m_CTF == mode->ModeType() ) {
				CTFGameMode *ctf = static_cast<CTFGameMode *>(mode);
				Handle<IImage> intelIcon = renderer->RegisterImage("Gfx/Map/Intel.png");
				Handle<IImage> baseIcon = renderer->RegisterImage("Gfx/Map/CommandPost.png");
				for(int tId = 0; tId < 2; tId++){
					CTFGameMode::Team& team = ctf->GetTeam(tId);
					IntVector3 teamColor = world->GetTeam(tId).color;
					Vector4 teamColorF = ModifyColor(teamColor);
					teamColorF *= alpha;
					
					// draw base
					renderer->SetColorAlphaPremultiplied(teamColorF);
					DrawIcon(team.basePos, baseIcon, 0.f);
					
					
					// draw flag
					if(!ctf->GetTeam(1-tId).hasIntel){
						renderer->SetColorAlphaPremultiplied(teamColorF);
						DrawIcon(team.flagPos, intelIcon, 0.f);
					}else if(world->GetLocalPlayer()->GetTeamId() == 1-tId){
						// local player's team is carrying
						int cId = ctf->GetTeam(1-tId).carrier;
						
						// in some game modes, carrier becomes invalid
						if(cId < world->GetNumPlayerSlots()){
							Player * carrier= world->GetPlayer(cId);
							if(carrier && carrier->GetTeamId() ==
							   world->GetLocalPlayer()->GetTeamId()){
								
								Vector4 col = teamColorF;
								col *= fabsf(sinf(world->GetTime() * 4.f));
								renderer->SetColorAlphaPremultiplied(col);
								DrawIcon(carrier->GetPosition(), intelIcon, 0.f);
							}
						}
					}
				}
			} else if( mode && IGameMode::m_TC == mode->ModeType() ) {
				TCGameMode *tc = static_cast<TCGameMode *>(mode);
				Handle<IImage> icon = renderer->RegisterImage("Gfx/Map/CommandPost.png");
				int cnt = tc->GetNumTerritories();
				for(int i = 0; i < cnt; i++){
					TCGameMode::Territory *t = tc->GetTerritory(i);
					IntVector3 teamColor = {128,128,128};
					if(t->ownerTeamId < 2){
						teamColor = world->GetTeam(t->ownerTeamId).color;
					}
					Vector4 teamColorF = ModifyColor(teamColor);
					teamColorF *= alpha;
					
					// draw base
					renderer->SetColorAlphaPremultiplied(teamColorF);
					DrawIcon(t->pos, icon, 0.f);
					
				}
			}
		}
コード例 #9
0
//显示截取矩形信息
void CCatchScreenDlg::DrawMessage(CRect &inRect,CDC * pDC)
{
	//截取矩形大小信息离鼠标间隔
	const int space=3;
    
	//设置字体颜色大小
	
	CPoint pt;
	CPen pen(PS_SOLID,1,RGB(147,147,147));

	//dc.SetTextColor(RGB(147,147,147));
	CFont font;
	CFont * pOldFont;
	font.CreatePointFont(90,"宋体");
	pOldFont=pDC->SelectObject(&font);

	//得到字体宽度和高度
	GetCursorPos(&pt);
	int OldBkMode;
	OldBkMode=pDC->SetBkMode(TRANSPARENT);

	TEXTMETRIC tm;
	int charHeight;
	CSize size;
	int	lineLength;
	pDC->GetTextMetrics(&tm);
	charHeight = tm.tmHeight+tm.tmExternalLeading;
	size=pDC->GetTextExtent("顶点位置  ",strlen("顶点位置  "));
	lineLength=size.cx;
    
	//初始化矩形, 以保证写下六行文字
	CRect rect(pt.x+space,pt.y-charHeight*6-space,pt.x+lineLength+space,pt.y-space);
    
    //创建临时矩形
    CRect rectTemp;
	//当矩形到达桌面边缘时调整方向和大小
	if((pt.x+rect.Width())>=m_xScreen)
	{
		//桌面上方显示不下矩形
		rectTemp=rect;
		rectTemp.left=rect.left-rect.Width()-space*2;
		rectTemp.right=rect.right-rect.Width()-space*2;;
		rect=rectTemp;
	}

	if((pt.y-rect.Height())<=0)
	{
		//桌面右方显示不下矩形
		rectTemp=rect;
		rectTemp.top=rect.top+rect.Height()+space*2;;
		rectTemp.bottom=rect.bottom+rect.Height()+space*2;;
		rect=rectTemp;
		
	}

	//创建空画刷画矩形
	CBrush * pOldBrush;
    pOldBrush=pDC->SelectObject(CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)));
	
	pDC->Rectangle(rect);
   	rect.top+=2;
	//在矩形中显示文字
	CRect outRect(rect.left,rect.top,rect.left+lineLength,rect.top+charHeight);
	CString string("顶点位置");
	pDC->DrawText(string,outRect,DT_CENTER);
    
	outRect.SetRect(rect.left,rect.top+charHeight,rect.left+lineLength,charHeight+rect.top+charHeight);
	string.Format("(%d,%d)",inRect.left,inRect.top);
	pDC->DrawText(string,outRect,DT_CENTER);
	

	outRect.SetRect(rect.left,rect.top+charHeight*2,rect.left+lineLength,charHeight+rect.top+charHeight*2);
	string="矩形大小";
	pDC->DrawText(string,outRect,DT_CENTER);

	outRect.SetRect(rect.left,rect.top+charHeight*3,rect.left+lineLength,charHeight+rect.top+charHeight*3);
	string.Format("(%d,%d)",inRect.Width(),inRect.Height());
    pDC->DrawText(string,outRect,DT_CENTER);

	outRect.SetRect(rect.left,rect.top+charHeight*4,rect.left+lineLength,charHeight+rect.top+charHeight*4);
	string="光标坐标";
    pDC->DrawText(string,outRect,DT_CENTER);

	outRect.SetRect(rect.left,rect.top+charHeight*5,rect.left+lineLength,charHeight+rect.top+charHeight*5);
	string.Format("(%d,%d)",pt.x,pt.y);
	pDC->DrawText(string,outRect,DT_CENTER);
    
	pDC->SetBkMode(OldBkMode);
	pDC->SelectObject(pOldFont);
	pDC->SelectObject(pOldBrush);
	
}
コード例 #10
0
// name   : detect function
// input  : image and dataset
// output : classification result and detect picture
CDetectionResult CRForest::detection(CTestDataset &testSet) const {
    int classNum = classDatabase.vNode.size();//contain class number
    std::vector<CTestPatch> testPatch;
    std::vector<const LeafNode*> result;

    //std::vector<const LeafNode*> storedLN(0);
    //std::vector<std::vector<CParamset> > cluster(0);
    //std::vector<CParamset> clusterMean(0);

    cv::vector<cv::Mat> outputImage(classNum);
    cv::vector<cv::Mat> voteImage(classNum);//voteImage(classNum);
    //cv::vector<cv::Mat_<std::vector<CParamset> > > voteParam(classNum);

    std::vector<int> totalVote(classNum,0);

    //boost::timer t;

    //boost::timer::auto_cpu_timer t;
    //boost::timer::nanosecond_type time;

    std::vector<paramHist**> voteParam2(classNum);

    //timer.start();

    testSet.loadImage(conf);

    testSet.extractFeatures(conf);

    //std::cout << "extracted feature " << t.elapsed() << " sec" << std::endl;

    //testSet.releaseImage();

    //t.restart()
    // image row and col
    int imgRow = testSet.img.at(0)->rows;
    int imgCol = testSet.img.at(0)->cols;

    #pragma omp parallel
    {
        #pragma omp for
        for(int i = 0; i < classNum; ++i) {
            outputImage.at(i) = testSet.img.at(0)->clone();
            voteImage.at(i) = cv::Mat::zeros(imgRow,imgCol,CV_32FC1);
            voteParam2.at(i) = new paramHist*[imgRow];
            for(int j = 0; j < imgRow; ++j)
                voteParam2.at(i)[j] = new paramHist[imgCol];
        }
    }

    //paramHist voteParam[testSet.img.at(0)->rows][testSet.img.at(0)->cols][classNum];
    // extract feature from test image
    //features.clear();
    //extractFeatureChannels(image.at(0), features);
    // add depth image to features
    //features.push_back(image.at(1));
    // extract patches from features

    extractTestPatches(testSet,testPatch,this->conf);

    //std::cout << "extracted feature " << t.elapsed() << " sec" << std::endl;

    std::cout << "patch num: " << testPatch.size() << std::endl;
    std::cout << "detecting..." << std::endl;
    // regression and vote for every patch

    std::cout << "class num = " << classNum << std::endl;

    for(int j = 0; j < testPatch.size(); ++j) {
        // regression current patch
        result.clear();
        this->regression(result, testPatch.at(j));

        // for each tree leaf
        for(int m = 0; m < result.size(); ++m) {
            #pragma omp parallel
            {
                #pragma omp for

                for(int l = 0; l < result.at(m)->pfg.size(); ++l) {
                    if(result.at(m)->pfg.at(l) > 0.9) {
                        int cl = classDatabase.search(result.at(m)->param.at(l).at(0).getClassName());

                        for(int n = 0; n < result.at(m)->param.at(cl).size(); ++n) {
                            cv::Point patchSize(conf.p_height/2,conf.p_width/2);

                            cv::Point rPoint = result.at(m)->param.at(cl).at(n).getCenterPoint();

                            if(conf.learningMode != 2) {
                                cv::Mat tempDepth = *testPatch[j].getDepth();
                                cv::Rect tempRect = testPatch[j].getRoi();
                                cv::Mat realDepth = tempDepth(tempRect);
                                double centerDepth = realDepth.at<ushort>(tempRect.height / 2 + 1, tempRect.width / 2 + 1) + conf.mindist;

                                rPoint *= centerDepth;
                                rPoint.x /= 1000;
                                rPoint.y /= 1000;


                            }

                            cv::Point pos(testPatch.at(j).getRoi().x + patchSize.x +  rPoint.x,
                                          testPatch.at(j).getRoi().y + patchSize.y +  rPoint.y);
                            // vote to result image
                            if(pos.x > 0 && pos.y > 0 && pos.x < voteImage.at(cl).cols && pos.y < voteImage.at(cl).rows) {
                                double v = result.at(m)->pfg.at(cl) / ( result.size() * result.at(m)->param.at(l).size());
                                voteImage.at(cl).at<float>(pos.y,pos.x) += v;//(result.at(m)->pfg.at(c) - 0.9);// * 100;//weight * 500;
                                voteParam2.at(cl)[pos.y][pos.x].roll.at<double>(0,result.at(m)->param.at(l).at(n).getAngle()[0]) += v * 10000;
                                voteParam2.at(cl)[pos.y][pos.x].pitch.at<double>(0,result.at(m)->param.at(l).at(n).getAngle()[1]) += v * 10000;
                                voteParam2.at(cl)[pos.y][pos.x].yaw.at<double>(0,result.at(m)->param.at(l).at(n).getAngle()[2]) += v * 10000;
                                //std::cout << result.at(m)->param.at(l).at(n).getAngle() << std::endl;
                                //std::cout << v << std::endl;
                                totalVote.at(cl) += 1;
                            }

                        } //for(int n = 0; n < result.at(m)->param.at(cl).size(); ++n){
                    } //if(result.at(m)->pfg.at(l) > 0.9){
                } //for(int l = 0; l < result.at(m)->pfg.size(); ++l){

            }//pragma omp parallel

        } // for every leaf
    } // for every patch

    // vote end

    #pragma omp parallel
    {
        #pragma omp for
        // find balance by mean shift
        for(int i = 0; i < classNum; ++i) {
            cv::GaussianBlur(voteImage.at(i),voteImage.at(i), cv::Size(21,21),0);
        }
    }

    // measure time
    //    double time = t.elapsed();
    //    std::cout << time << "sec" << std::endl;
    //    std::cout << 1 / (time) << "Hz" << std::endl;

    // output image to file
    std::string opath;
    //    if(!conf.demoMode){
    //        //create result directory
    //        opath = testSet.getRgbImagePath();
    //        opath.erase(opath.find_last_of(PATH_SEP));
    //        std::string imageFilename = testSet.getRgbImagePath();
    //        imageFilename.erase(imageFilename.find_last_of("."));
    //        //imageFilename.erase(imageFilename.begin(),imageFilename.find_last_of(PATH_SEP));
    //        imageFilename = imageFilename.substr(imageFilename.rfind(PATH_SEP),imageFilename.length());

    //        //opath += PATH_SEP;
    //        opath += imageFilename;
    //        std::string execstr = "mkdir -p ";
    //        execstr += opath;
    //        system( execstr.c_str() );

    //        for(int c = 0; c < classNum; ++c){
    //            std::stringstream cToString;
    //            cToString << c;
    //            std::string outputName = "output" + cToString.str() + ".png";
    //            std::string outputName2 = opath + PATH_SEP + "vote_" + classDatabase.vNode.at(c).name + ".png";
    //            //cv::imwrite(outputName.c_str(),outputImage.at(c));
    //            //cv::cvtColor(voteImage)

    //            cv::Mat writeImage;
    //            //hist.convertTo(hist, hist.type(), 200 * 1.0/second_val,0);
    //            voteImage.at(c).convertTo(writeImage, CV_8UC1, 254);
    //            cv::imwrite(outputName2.c_str(),writeImage);
    //        }
    //    }

    // create detection result
    CDetectionResult detectResult;
    detectResult.voteImage = voteImage;

    // show ground truth
    std::cout << "show ground truth" << std::endl;
    //    std::cout << dataSet.className.size() << std::endl;
    //    std::cout << dataSet.centerPoint.size() << std::endl;
    for(int i = 0; i < testSet.param.size(); ++i) {
        testSet.param.at(i).showParam();
    }

    // show detection reslut
    std::cout << "show result" << std::endl;
    // for every class
    for(int c = 0; c < classNum; ++c) {
        double min,max;
        cv::Point minLoc,maxLoc;
        cv::minMaxLoc(voteImage.at(c),&min,&max,&minLoc,&maxLoc);

        double min_pose_value[3], max_pose_value[3];
        cv::Point min_pose[3], max_pose[3];

        paramHist hist;

        for(int x = 0; x < conf.paramRadius; ++x) {
            for(int y = 0; y < conf.paramRadius; ++y) {
                if( maxLoc.x + x < imgCol &&  maxLoc.y + y < imgRow)
                    hist += voteParam2.at(c)[maxLoc.y + y][maxLoc.x + x];
                if(maxLoc.x - x > 0 && maxLoc.y - y > 0)
                    hist += voteParam2.at(c)[maxLoc.y - y][maxLoc.x - x];
            }
        }

        //hist.showHist();

        //        for(int p = 0; p < 360; ++p){
        //            std::cout << p << " " <<  voteParam2.at(c)[maxLoc.y][maxLoc.x].yaw.at<double>(0,p) << std::endl;
        //        }

        //voteParam2.at(c)[maxLoc.y][maxLoc.x].showHist();

        cv::minMaxLoc(hist.roll, &min_pose_value[0], &max_pose_value[0], &min_pose[0], &max_pose[0]);
        cv::minMaxLoc(hist.pitch, &min_pose_value[1], &max_pose_value[1], &min_pose[1], &max_pose[1]);
        cv::minMaxLoc(hist.yaw, &min_pose_value[2], &max_pose_value[2], &min_pose[2], &max_pose[2]);

        // draw detected class bounding box to result image
        // if you whant add condition of detection threshold, add here
        cv::Size tempSize = classDatabase.vNode.at(c).classSize;
        cv::Rect_<int> outRect(maxLoc.x - tempSize.width / 2,maxLoc.y - tempSize.height / 2 , tempSize.width,tempSize.height);
        cv::rectangle(outputImage.at(c),outRect,cv::Scalar(0,0,200),3);
        cv::putText(outputImage.at(c),classDatabase.vNode.at(c).name,cv::Point(outRect.x,outRect.y),cv::FONT_HERSHEY_SIMPLEX,1.2, cv::Scalar(0,0,200), 2, CV_AA);

        // draw grand truth to result image
        if(!conf.demoMode) {
            for(int i = 0; i < testSet.param.size(); ++i) {
                int tempClassNum = classDatabase.search(testSet.param.at(i).getClassName());
                if(tempClassNum != -1) {
                    cv::Size tempSize = classDatabase.vNode.at(tempClassNum).classSize;
                    cv::Rect_<int> outRect(testSet.param.at(i).getCenterPoint().x - tempSize.width / 2,testSet.param.at(i).getCenterPoint().y - tempSize.height / 2 , tempSize.width,tempSize.height);
                    cv::rectangle(outputImage.at(tempClassNum),outRect,cv::Scalar(200,0,0),3);
                    cv::putText(outputImage.at(tempClassNum),classDatabase.vNode.at(c).name,cv::Point(testSet.param.at(i).getCenterPoint().x, testSet.param.at(i).getCenterPoint().y),cv::FONT_HERSHEY_SIMPLEX,1.2, cv::Scalar(200,0,0), 2, CV_AA);
                }
            }
        }

        // show result
        std::cout << c << " Name : " << classDatabase.vNode.at(c).name <<
                  "\tvote : " << totalVote.at(c) <<
                  " Score : " << voteImage.at(c).at<float>(maxLoc.y, maxLoc.x) <<
                  " CenterPoint : " << maxLoc << std::endl <<
                  " Pose : roll " << max_pose[0].x <<
                  " pitch : " << max_pose[1].x <<
                  " yaw : " << max_pose[2].x << std::endl;

        // if not in demo mode, output image to file
        if(!conf.demoMode) {
            std::string outputName = opath + PATH_SEP + "detectionResult" + "_" + classDatabase.vNode.at(c).name + ".png";
            cv::imwrite(outputName.c_str(),outputImage.at(c));
        }

        CDetectedClass detectedClass;
        detectedClass.name = classDatabase.vNode.at(c).name;
        detectedClass.angle[0] = max_pose[0].x;

        // calc euclidean dist to nearest object
        double minError = DBL_MAX;
        std::string nearestObject;
        for(int d = 0; d < testSet.param.size(); ++d) {
            double tempError = euclideanDist(maxLoc,testSet.param.at(d).getCenterPoint());//= std::sqrt(std::pow((double)(maxLoc.x - testSet.param.at(0).getCenterPoint().x), 2) + std::pow((double)(maxLoc.y - testSet.param.at(0).getCenterPoint().y), 2));
            //std::cout << tempError << std::endl;
            if(tempError < minError) {
                minError = tempError;
                nearestObject = testSet.param.at(d).getClassName();
            }
        }

        // calc and output result
        detectedClass.error = minError;
        detectedClass.nearestClass = nearestObject;
        detectedClass.score = voteImage.at(c).at<float>(maxLoc.y, maxLoc.x);
        detectResult.detectedClass.push_back(detectedClass);
    } // for every class

    for(int k = 0; k < classNum; ++k) {
        for(int i = 0; i < imgRow; ++i) {
            delete[] voteParam2.at(k)[i];
        }
    }

    return detectResult;
}
コード例 #11
0
ファイル: celldata.cpp プロジェクト: gaoyakun/atom3d
void ATOM_CellData::onPaint (ATOM_WidgetDrawClientEvent *event)
{
	ATOM_STACK_TRACE(ATOM_CellData::onPaint);

	ATOM_Rect2Di outRect(ATOM_Point2Di(0, 0), event->canvas->getSize());
	ATOM_Rect2Di inRect(_frameOffset, _frameOffset, outRect.size.w-_frameOffset*2, outRect.size.h-_frameOffset*2);

	bool inCD = (ATOM_INVALID_IMAGEID != _cooldownImageId) && _cooldownMax;

	if (_frameImageId != ATOM_INVALID_IMAGEID)
	{
		ATOM_GUIImage *image = getValidImage (_frameImageId);
		image->draw (event->state, event->canvas, outRect);
	}

	if (_clientImageId != ATOM_INVALID_IMAGEID)
	{
		ATOM_GUIImage *image = getValidImage (_clientImageId);
		if (!image)
		{
			image = ATOM_GUIImageList::getDefaultImageList().getImage (ATOM_IMAGEID_WINDOW_BKGROUND);
			ATOM_ASSERT(image);
		}
		if(_customColor)
		{
			image->draw (event->state, event->canvas, inRect, &_customColor);
		}
		else
		{
			image->draw (event->state, event->canvas, inRect);
		}

	}

	if (!_caption.empty())
	{
		if (_textDirty)
		{
			calcTextLayout ();
			_textDirty = false;
		}

		ATOM_GUICanvas::DrawTextInfo info;
		info.textObject = _text.get();
		info.textString = _text->getString();
		info.font = _text->getFont();
		info.x = _textPosition.x;
		info.y = _textPosition.y;
		info.shadowOffsetX = 0;
		info.shadowOffsetY = 0;
		info.textColor = getFontColor();
		info.outlineColor = _widgetFontOutLineColor;
		info.shadowColor = 0;
		info.underlineColor = _underlineColor;
		info.flags = ATOM_GUICanvas::DRAWTEXT_TEXTOBJECT;
		if(_widgetFontOutLineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_OUTLINE;
		}
		if(_underlineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_UNDERLINE;
		}
		event->canvas->drawTextEx(&info);
		//event->canvas->drawText (_text.get(), _textPosition.x, _textPosition.y, getFontColor());
	}
	//»æÖÆϱê×ÖÌå
	if (!_subscriptStr.empty())
	{
		if (_subscirptTextDirty)
		{
			calcSubscriptTextLayout();
			_subscirptTextDirty = false;
		}

		ATOM_GUICanvas::DrawTextInfo info;
		info.textObject = _subscriptText.get();
		info.textString = _subscriptText->getString();
		info.font = _subscriptText->getFont();
		info.x = _subscriptTextPosition.x;
		info.y = _subscriptTextPosition.y;
		info.shadowOffsetX = 0;
		info.shadowOffsetY = 0;
		info.textColor = getFontColor();
		info.outlineColor = _widgetFontOutLineColor;
		info.shadowColor = 0;
		info.underlineColor = _underlineColor;
		info.flags = ATOM_GUICanvas::DRAWTEXT_TEXTOBJECT;
		if(_widgetFontOutLineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_OUTLINE;
		}
		if(_underlineColor.getByteA())
		{
			info.flags |= ATOM_GUICanvas::DRAWTEXT_UNDERLINE;
		}
		event->canvas->drawTextEx(&info);
		//event->canvas->drawText (_text.get(), _textPosition.x, _textPosition.y, getFontColor());
	}
	//»æÖÆϱêͼƬ
	if(_subscriptImageId != ATOM_INVALID_IMAGEID)
	{
		ATOM_GUIImage *image = getValidImage (_subscriptImageId);
		if(!image)
		{
			image = ATOM_GUIImageList::getDefaultImageList().getImage(ATOM_IMAGEID_WINDOW_BKGROUND);
			ATOM_ASSERT(image);
		}
		image->draw(event->state,event->canvas,ATOM_Rect2Di(inRect.point.x+_subscriptRect.point.x,
			inRect.point.y+_subscriptRect.point.y,_subscriptRect.size.w,_subscriptRect.size.h));
	}

	if (_selectImageId != ATOM_INVALID_IMAGEID)
	{
#if 1
		ATOM_GUIImage *image = getValidImage (_selectImageId);
#else
		const ATOM_GUIImageList *imagelist = getValidImageList ();
		ATOM_GUIImage *image = imagelist->getImage (_selectImageId);
#endif
		if (!image)
		{
			image = ATOM_GUIImageList::getDefaultImageList().getImage (ATOM_IMAGEID_WINDOW_BKGROUND);
			ATOM_ASSERT(image);
		}
		image->draw (event->state, event->canvas, outRect);
	}

	//
	//bool inCD = (ATOM_INVALID_IMAGEID != _cooldownImageId) && _cooldownMax;

	//// »­CELL±³¾°
	//if(cell->_texture.pointer)
	//{
	//	unsigned color = inCD ? 0xFF808080 : 0xFFFFFFFF;
	//	canvas->drawTexturedRectEx(ATOM_Rect2Di(x*(xCellWidth+_xSpace), y*(yCellWidth+_ySpace), xCellWidth, yCellWidth), color, cell->_texture.pointer, cell->_region, false);
	//}
	//else if (_clientImageId != ATOM_INVALID_IMAGEID)
	//{
	//	imageDefault->draw (event->state, event->canvas, ATOM_Rect2Di(x*(xCellWidth+_xSpace), y*(yCellWidth+_ySpace), xCellWidth, yCellWidth));
	//}

	//if(cell->_text.pointer)
	//{
	//	const char* str = cell->_text->getString();
	//	if (strcmp (str, ""))
	//	{
	//		ATOM_FontHandle font = ATOM_GUIFont::getFontHandle (getFont());
	//		int charmargin = ATOM_GUIFont::getFontCharMargin (getFont());
	//		int charset = ATOM_GUIFont::getFontCharSet (getFont());
	//		ATOM_SetCharMargin (charmargin);
	//		int l, t, w, h;
	//		ATOM_CalcStringBounds (font, charset, str, strlen(str), &l, &t, &w, &h);
	//		canvas->drawText (cell->_text.pointer, x*(xCellWidth+_xSpace), y*(yCellWidth+_ySpace)-t, _fontColor);
	//	}
	//}

	// »­CD
	if(inCD)
	{
#if 1
		ATOM_GUIImage *image = getValidImage (_cooldownImageId);
#else
		ATOM_GUIImage* image = getValidImageList()->getImage (_cooldownImageId);
#endif
		if(image)
		{
			ATOM_Texture* texture = image->getTexture(WST_NORMAL);
			if(texture)
			{
				ATOM_CircleDrawer drawer(event->canvas, texture);
				drawer.DrawRemove(inRect, float(_cooldown)/float(_cooldownMax));
			}
		}
#if 0
		char buffer[256];
		sprintf (buffer, "%d", _cooldown);
		event->canvas->drawText (buffer, ATOM_GUIFont::getFontHandle(ATOM_GUIFont::getDefaultFont(10, 0)), 0, 0, 0xFFFFFFFF);
#endif
	}
}