コード例 #1
0
void TVizMapContext::PaintKeyWds(PGks Gks, const int& KeyWdFontSize, 
        TVec<TFltRect>& PointNmRectV) {

    // set font
    Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize, ColorKeyWdFont));
    // prepare parameters
    TFltRect ZoomRect = GetZoomRect();    
    const double MnZoomRectSize = TFlt::GetMn(ZoomRect.GetXLen(), ZoomRect.GetYLen());
    const double MnRptDist = RelMnRptDist * MnZoomRectSize;
    const double Sparsity = RelSparsity * MnZoomRectSize;
    TVizMapKeyWdV OkKeyWdV;
    // start drawing the keywords
    int KeyWds = VizMapFrame->GetKeyWds();
    //SysConsole->PutLn(TStr::Fmt("Starting to draw %d keywords", KeyWds));
    for (int KeyWdN = 0; KeyWdN < KeyWds; KeyWdN++) {
        PVizMapKeyWd KeyWd = VizMapFrame->GetKeyWd(KeyWdN);
        TStr KeyWdStr = KeyWd->GetKeyWdStr().GetLc();
        const double KeyWdX = KeyWd->GetKeyWdX();
        const double KeyWdY = KeyWd->GetKeyWdY();
        if (ZoomRect.IsXYIn(KeyWdX, KeyWdY)) {
            // get coordinates in pixels
            const int X = GetScreenCoord(KeyWdX, ZoomRect.GetMnX(), 
                ZoomRect.GetXLen(), Gks->GetWidth());
            const int Y = GetScreenCoord(KeyWdY, ZoomRect.GetMnY(), 
                ZoomRect.GetYLen(), Gks->GetHeight());
            // calculate string position on the screen
            const int HalfTxtWidth = Gks->GetTxtWidth(KeyWdStr) / 2;
            const int HalfTxtHeight = Gks->GetTxtHeight(KeyWdStr) / 2;
            TFltRect KeyWdRect(X - HalfTxtWidth, Y - HalfTxtHeight,
                X + HalfTxtWidth, Y + HalfTxtHeight);
            // should we draw it?
            bool DoDrawP = true; const int Rects = PointNmRectV.Len();
            for (int RectN = 0; RectN < Rects; RectN++) {
                if (TFltRect::Intersection(KeyWdRect, PointNmRectV[RectN])) { 
                    DoDrawP = false; break; }
            }
            if (!DoDrawP) { continue; } // word overlaps, we skip it
            // check if it fits the sparsity and repetition constraint
            TFltV KeyWdCoodV = TFltV::GetV(KeyWdX, KeyWdY);
            //SysConsole->PutLn(TStr::Fmt("Keyword: %s (%.2f, %.2f)", KeyWdStr.CStr(), KeyWdX, KeyWdY));            
            const int OkKeyWds = OkKeyWdV.Len(); bool KeyWdOkP = true;
            for (int OkKeyWdN = 0; OkKeyWdN < OkKeyWds; OkKeyWdN++) {
                PVizMapKeyWd OkKeyWd = OkKeyWdV[OkKeyWdN];
                TStr OkKeyWdStr = OkKeyWd->GetKeyWdStr().GetLc();
                const double Dist = TLinAlg::EuclDist(KeyWdCoodV, OkKeyWd->GetCoordV());
                if (Dist < Sparsity) { KeyWdOkP = false; break; }
                if (OkKeyWdStr == KeyWdStr) {
                    //SysConsole->PutLn(TStr::Fmt("  Comparing to %s(%.2f, %.2f): %.2f / %.2f / %.2f",
                    //    OkKeyWdStr.CStr(), OkKeyWd->GetKeyWdX(), OkKeyWd->GetKeyWdY(), Dist, Sparsity, MnRptDist));
                    if (Dist < MnRptDist) { KeyWdOkP = false; break; }
                }
            }
            if (!KeyWdOkP) { continue; } // word repeats or is to dense, we skip it
            //SysConsole->PutLn("  All ok");
            // draw it!
            Gks->PutTxt(KeyWdStr, X - HalfTxtWidth, Y - HalfTxtHeight); 
            PointNmRectV.Add(KeyWdRect); OkKeyWdV.Add(KeyWd);
        }
    }
}
コード例 #2
0
void TVizMapContext::PaintLinks(PGks Gks) {
    int Links = VizMapFrame->GetLinks();
    //InfoNotify(TStr::Fmt("Links %d", Links));
    TFltRect ZoomRect = GetZoomRect();
    for (int LinkN = 0; LinkN < Links; LinkN++) {
        PVizMapLink Link = VizMapFrame->GetLink(LinkN);
        //if (!SelPointV.IsInBin(Link->GetSrcPointN()) &&
        //    !SelPointV.IsInBin(Link->GetDstPointN())) { continue; }
        // get link coordinates
        PVizMapPoint SrcPoint = VizMapFrame->GetPoint(Link->GetSrcPointN());
        PVizMapPoint DstPoint = VizMapFrame->GetPoint(Link->GetDstPointN());
        const double SrcPointX = SrcPoint->GetPointX(), SrcPointY = SrcPoint->GetPointY();
        const double DstPointX = DstPoint->GetPointX(), DstPointY = DstPoint->GetPointY();
        //TODO: check if link crosses ZoomRect
        // get coordinates in pixels
        const int SrcX = GetScreenCoord(SrcPointX, ZoomRect.GetMnX(), 
            ZoomRect.GetXLen(), Gks->GetWidth());
        const int SrcY = GetScreenCoord(SrcPointY, ZoomRect.GetMnY(), 
            ZoomRect.GetYLen(), Gks->GetHeight());
        const int DstX = GetScreenCoord(DstPointX, ZoomRect.GetMnX(), 
            ZoomRect.GetXLen(), Gks->GetWidth());
        const int DstY = GetScreenCoord(DstPointY, ZoomRect.GetMnY(), 
            ZoomRect.GetYLen(), Gks->GetHeight());
        // draw arrow
        PaintArrow(Gks, SrcX, SrcY, DstX, DstY, 3);
    }
}
コード例 #3
0
ファイル: HtmlOverlay.cpp プロジェクト: johndragon/ld3d
	bool HtmlOverlay::Initialize(RenderManagerPtr pRenderManager, WebpageRendererPtr pRenderer, const std::string& name, const math::RectI& rect)
	{
		if(pRenderer == nullptr)
		{
			return false;
		}

		m_pRenderManager				= pRenderManager;
		m_name							= name;
		m_rect							= rect;

		m_pTexOverlay = alloc_object<TextureOverlay>(m_pUIManager);
		if(false == m_pTexOverlay->Initialize(m_pRenderManager, name + "_internal_", math::RectI(0, 0, rect.width(), rect.height()), TexturePtr()))
		{
			return false;
		}

		m_pTexOverlay->LinkTo(shared_from_this());
	
		if(false == ResizeTexture(m_rect.width(), m_rect.height()))
		{
			return false;
		}

		m_pPageRenderer = pRenderer;

		m_pPageRenderer->SetRenderTarget(m_pTexture);

		int x = 0;
		int y = 0;
		GetScreenCoord(x, y);
		m_pPageRenderer->SetScreenCoord(x, y);
		return true;
	}
コード例 #4
0
ファイル: HtmlOverlay.cpp プロジェクト: johndragon/ld3d
	RenderDataPtr HtmlOverlay::PrepareRenderData()
	{
		int x = 0;
		int y = 0;
		GetScreenCoord(x, y);
		m_pPageRenderer->SetScreenCoord(x, y);

		return RenderDataPtr();
	}
コード例 #5
0
ファイル: Ploter.cpp プロジェクト: haitaka/halgebra
void halg::Ploter::DrawPlot( Plot const * plot )
{
    QPainter painter(this);

    painter.setPen( plot->GetColor( ) );

    double x = plot->GetXMin();
    double val = plot->GetVal( x );
    double max = plot->GetXMax();
    double step = 1. / m_scale;
    while( x  < max )
    {
        double nextX = x + step;
        double nextVal = plot->GetVal( nextX );
        painter.drawLine(
            GetScreenCoord( x, val ),
            GetScreenCoord( nextX, nextVal )
        );
        val = nextVal;
        x = nextX;
    }
}
コード例 #6
0
	RenderDataPtr TextureOverlay::PrepareRenderData()
	{
		if(IsVisible() == false)
		{
			return nullptr;
		}
		float screen_w = (float)m_pRenderManager->GetFrameBufferWidth();
		float screen_h = (float)m_pRenderManager->GetFrameBufferHeight();

		if(m_pParamScreenSize)
		{
			m_pParamScreenSize->SetParameterVector(math::Vector2(screen_w, screen_h));
		}
		
		m_pParamImage = m_pMaterial->GetParameterByName("overlay_image");
		if(m_pParamImage)
		{
			m_pParamImage->SetParameterTexture(m_pTexture);
		}

		math::Matrix44 trans;
		trans.MakeIdentity();
		trans.SetScale(math::Vector3(m_rect.width(), m_rect.height(), 1));

		int x = 0;
		int y = 0;
		GetScreenCoord(x, y);
		trans.SetTranslation(math::Vector3((float)x, (float)y, 0));

		m_pParamTrans = m_pMaterial->GetParameterByName("trans");
		if(m_pParamTrans)
		{
			m_pParamTrans->SetParameterMatrix(trans);
		}

		return m_pRenderData;
	}
コード例 #7
0
void TVizMapContext::PaintCatNms(PGks Gks, const int& KeyWdFontSize, 
        TVec<TFltRect>& PointNmRectV) {
        
    // calculate frequency of categories
    TIntH CatH; TIntFltPrH CatPosH;
    PBowDocBs BowDocBs = VizMapFrame->GetKeyWdBow();
    const int Points = VizMapFrame->GetPoints();
    for (int PointN = 0; PointN < Points; PointN++) {
        PVizMapPoint Point = VizMapFrame->GetPoint(PointN);
        const int DId = Point->GetDocId();
        const int CIds = BowDocBs->GetDocCIds(DId);
        for (int CIdN = 0; CIdN < CIds; CIdN++) {
            const int CId = BowDocBs->GetDocCId(DId, CIdN);
            CatH.AddDat(CId)++;
            CatPosH.AddDat(CId).Val1 += Point->GetPointX();
            CatPosH.AddDat(CId).Val2 += Point->GetPointY();
        }
        
    }
    CatH.SortByDat(false); 

    // draw the top cats
    const int TopCats = Points > 100 ? 6 : 4; 
    TFltRect ZoomRect = GetZoomRect();    
    Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize + 3, ColorCatNmFont));
    TVec<TFltRect> CatNmRectV; TVec<TFltV> CatNmPosV;
    const int MnSize = TInt::GetMn(Gks->GetWidth(), Gks->GetHeight());
    const int MnDist = TFlt::Round(0.3 * double(MnSize));
    int Cats = 0, CatKeyId = CatH.FFirstKeyId();
    while (CatH.FNextKeyId(CatKeyId)) {
        if (Cats == TopCats) { break; } 
        if (double(CatH[CatKeyId]) / double(Points) < 0.05) { break; } 
        const int CId = CatH.GetKey(CatKeyId);
        // get name
        TStr CatNm = BowDocBs->GetCatNm(CId);
        if (CatFullNmH.IsKey(CatNm)) {
            CatNm = CatFullNmH.GetDat(CatNm);
        } else { continue; }
        // get position
        TFltPr CatPos = CatPosH.GetDat(CId);
        const int CatCount = CatH.GetDat(CId); IAssert(CatCount > 0);
        const double CatX = CatPos.Val1 / double(CatCount);
        const double CatY = CatPos.Val2 / double(CatCount);
        // is it within the zoom?
        if (!ZoomRect.IsXYIn(CatX, CatY)) { continue; }
        // calculate string size on the screen
        const int HalfTxtWidth = Gks->GetTxtWidth(CatNm) / 2;
        const int HalfTxtHeight = Gks->GetTxtHeight(CatNm) / 2;
        // get coordinates in pixels
        const int X = GetScreenCoord(CatX , ZoomRect.GetMnX(), 
            ZoomRect.GetXLen(), Gks->GetWidth());
        const int Y = GetScreenCoord(CatY, ZoomRect.GetMnY(), 
            ZoomRect.GetYLen(), Gks->GetHeight());
        // is it to close to any of the most prominent categories
        int CatNmDist = MnSize; TFltV CatNmPos = TFltV::GetV(double(X), double(Y));
        for (int CatNmPosN = 0; CatNmPosN < CatNmPosV.Len(); CatNmPosN++) {
            const double Dist = TLinAlg::EuclDist(CatNmPosV[CatNmPosN], CatNmPos);
            CatNmDist = TInt::GetMn(TFlt::Round(Dist), CatNmDist);
        }
        if (CatNmDist < MnDist) { continue; }
        // does it overlap with any of hte most prominent categories
        TFltRect CatNmRect(X - HalfTxtWidth, Y - HalfTxtHeight,
            X + HalfTxtWidth, Y + HalfTxtHeight);
        bool DoDraw = true; const int Rects = CatNmRectV.Len();
        for (int RectN = 0; (RectN < Rects) && DoDraw; RectN++) {
            DoDraw = !TFltRect::Intersection(CatNmRect, CatNmRectV[RectN]); }
        if (!DoDraw) { continue; }
        // draw it!
        Gks->PutTxt(CatNm, X - HalfTxtWidth, Y - HalfTxtHeight); 
        // remember string area
        CatNmRectV.Add(CatNmRect); Cats++;
        // remember string position
        CatNmPosV.Add(CatNmPos);
    }
    PointNmRectV.AddV(CatNmRectV);
}
コード例 #8
0
void TVizMapContext::PaintPoints(PGks Gks, const int& PointFontSize, 
        const int& PointNmFontScale, const double& PointWgtThreshold, 
        const int& CatId, const bool& ShowMgGlassP,
        TVec<TFltRect>& PointNmRectV) {

    int Points = VizMapFrame->GetPoints();
    TFltRect ZoomRect = GetZoomRect();
    for (int PointN = 0; PointN < Points; PointN++) {
        PVizMapPoint Point = VizMapFrame->GetPoint(PointN);
        // we ignore selected and nearest point in the first run
        bool IsSelPointP = SelPointV.IsInBin(PointN);
        if (IsSelPointP || ((NearPointN == PointN) && !ShowMgGlassP)) { continue; }
        const double PointX = Point->GetPointX(), PointY = Point->GetPointY();
        if (ZoomRect.IsXYIn(PointX, PointY)) {
            // get coordinates in pixels
            const int X = GetScreenCoord(PointX, ZoomRect.GetMnX(), 
                ZoomRect.GetXLen(), Gks->GetWidth());
            const int Y = GetScreenCoord(PointY, ZoomRect.GetMnY(), 
                ZoomRect.GetYLen(), Gks->GetHeight());
            // check if point has given category
            bool IsCatP = Point->IsCatId(CatId);
            // check if the point is under threshold
            if (Point->IsPointNm() && 
                ((Point->GetWgt() > PointWgtThreshold) || IsSelPointP)) {

                // write full point name
                PointNmRectV.Add(PaintPointNm(Gks, Point, X, Y, 
                    PointFontSize, PointNmFontScale, IsSelPointP, IsCatP));
            } else {
                // draw a cross
                PaintPointCross(Gks, X, Y, IsSelPointP, IsCatP);
            }
        }
    }
    // paint selected points
    for (int SelPointN = 0; SelPointN < SelPointV.Len(); SelPointN++) {
        const int PointN = SelPointV[SelPointN];
        if ((NearPointN == PointN) && !ShowMgGlassP) { continue; }
        PVizMapPoint Point = VizMapFrame->GetPoint(PointN);
        const double PointX = Point->GetPointX(), PointY = Point->GetPointY();
        if (ZoomRect.IsXYIn(PointX, PointY)) {
            // get coordinates in pixels
            const int X = GetScreenCoord(PointX, ZoomRect.GetMnX(), 
                ZoomRect.GetXLen(), Gks->GetWidth());
            const int Y = GetScreenCoord(PointY, ZoomRect.GetMnY(), 
                ZoomRect.GetYLen(), Gks->GetHeight());
            // check if point has given category
            bool IsCatP = Point->IsCatId(CatId);
            // check if the point is under threshold
            if (Point->IsPointNm()) {
                // write full point name
                PointNmRectV.Add(PaintPointNm(Gks, Point, X, Y, 
                    PointFontSize, PointNmFontScale, true, IsCatP));
            } else {
                // draw a cross
                PaintPointCross(Gks, X, Y, true, IsCatP);
            }
        }
    }
    // paint nearest point
    if (!ShowMgGlassP && (NearPointN != -1)) {
        PVizMapPoint Point = VizMapFrame->GetPoint(NearPointN);
        const double PointX = Point->GetPointX(), PointY = Point->GetPointY();
        if (ZoomRect.IsXYIn(PointX, PointY)) {
            // get coordinates in pixels
            const int X = GetScreenCoord(PointX, ZoomRect.GetMnX(), 
                ZoomRect.GetXLen(), Gks->GetWidth());
            const int Y = GetScreenCoord(PointY, ZoomRect.GetMnY(), 
                ZoomRect.GetYLen(), Gks->GetHeight());
            // check if point has given category
            bool IsCatP = Point->IsCatId(CatId);
            // check if point is selected
            bool IsSelPointP = SelPointV.IsInBin(NearPointN);
            // check if the point is under threshold
            if (Point->IsPointNm()) {
                // write full point name
                PointNmRectV.Add(PaintPointNm(Gks, Point, X, Y, 
                    PointFontSize, PointNmFontScale, IsSelPointP, IsCatP));
            } else {
                // draw a cross
                PaintPointCross(Gks, X, Y, IsSelPointP, IsCatP);
            }
        }
    }
}