Changeset 18628


Ignore:
Timestamp:
09/18/16 14:54:03 (8 years ago)
Author:
tbretz
Message:
Dientengle from root and Mars, added the drawing function from their previous location.
Location:
trunk/FACT++/drive
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/drive/MGImage.cc

    r18618 r18628  
    2020#include "MGImage.h"
    2121
     22#include <iostream>
     23
    2224#include <TGX11.h>
    2325#include <TMutex.h>
    2426
    25 #include "MLog.h"
    26 #include "MLogManip.h"
    27 
    28 ClassImp(MGImage);
     27#include <TMath.h>
     28
     29//#include "MLog.h"
     30//#include "MLogManip.h"
    2931
    3032using namespace std;
     
    5052    fImage  = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);
    5153
    52     gLog << all << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
     54    cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
    5355}
    5456
    5557MGImage::~MGImage()
    5658{
    57     if (fMuxPixmap->Lock()==13)
    58         cout << "MGImage::~MGImage - mutex is already locked by this thread" << endl;
    59 
    60     gLog << inf2 << "Deleting MGImage..." << endl;
     59//    if (fMuxPixmap->Lock()==13)
     60//        cout << "MGImage::~MGImage - mutex is already locked by this thread" << endl;
     61
     62    cout << "Deleting MGImage..." << endl;
    6163
    6264    gVirtualX->DeleteGC(fDefGC);
     
    6769    delete fMuxPixmap;
    6870
    69     gLog << inf2 << "MGImage destroyed." << endl;
     71    cout << "MGImage destroyed." << endl;
    7072}
    7173
     
    9092    if (TestBit(kSyncMode))
    9193        if (fMuxPixmap->UnLock()==13)
    92             gLog << warn << "MGImage::DoRedraw - tried to unlock mutex locked by other thread." << endl;
     94            cout << "MGImage::DoRedraw - tried to unlock mutex locked by other thread." << endl;
    9395}
    9496
     
    250252        cout << "MGImage::DrawColImage - tried to unlock mutex locked by other thread." << endl;
    251253}
     254
     255// --------------------------------------------------------------------------
     256//
     257// Convert root colors to arbitrary bitmap coordinates
     258//
     259UChar_t MGImage::Color(int col)
     260{
     261    switch (col)
     262    {
     263    case kBlack:  return 0;
     264    case kWhite:  return 0xff;
     265    case kYellow: return 0x0f;
     266    case kRed:    return 2;
     267    case kGreen:  return 2<<2;
     268    case kBlue:   return 2<<4;
     269    default:
     270        return 0;
     271    }
     272}
     273
     274// --------------------------------------------------------------------------
     275//
     276// Draw a line into the buffer (size w*h) from (x1, y1) to (x2, y2) with
     277// the color col and the line style style (default: solid)
     278//
     279void MGImage::DrawLine(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style)
     280{
     281    const Int_t    step = style==kSolid?1:3;
     282    const Double_t len  = TMath::Hypot(x2-x1, y2-y1);
     283    const Double_t dx   = (x2-x1)/len*step;
     284    const Double_t dy   = (y2-y1)/len*step;
     285
     286    Double_t x = x1;
     287    Double_t y = y1;
     288
     289    for (int i=0; i<len; i+=step)
     290    {
     291        x+= dx;
     292        y+= dy;
     293
     294        const Int_t iy = TMath::Nint(y);
     295        if (iy<0 || iy>=h)
     296            continue;
     297
     298        const Int_t ix = TMath::Nint(x);
     299        if (ix<0 || ix>=w)
     300            continue;
     301
     302        buf[ix+iy*w] = col;
     303    }
     304}
     305
     306// --------------------------------------------------------------------------
     307//
     308// Draw a box into the buffer (size w*h) from (x1, y1) to (x2, y2) with
     309// the color col and the line style style (default: solid)
     310//
     311void MGImage::DrawBox(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style)
     312{
     313    DrawLine(buf, w, h, x1, y1, x2, y1, col, style);
     314    DrawLine(buf, w, h, x1, y2, x2, y1, col, style);
     315    DrawLine(buf, w, h, x1, y1, x1, y2, col, style);
     316    DrawLine(buf, w, h, x2, y1, x2, y2, col, style);
     317}
     318
     319// --------------------------------------------------------------------------
     320//
     321// Draw a hexagon into the buffer (size w*h) around (x, y) with radius r and
     322// the color col.
     323//
     324void MGImage::DrawHexagon(UChar_t *buf, int w, int h, Float_t px, Float_t py, Float_t d, UChar_t col, Int_t style)
     325{
     326    const Int_t np = 6;
     327
     328    const Double_t dy[np+1] = { .5   , 0.    , -.5   , -.5   , 0.    ,  .5   , .5    };
     329    const Double_t dx[np+1] = { .2886,  .5772,  .2886, -.2886, -.5772, -.2886, .2886 };
     330
     331    //
     332    //  calculate the positions of the pixel corners
     333    //
     334    Double_t x[np+1], y[np+1];
     335    for (Int_t i=0; i<np+1; i++)
     336    {
     337        x[i] = px + dx[i]*d;
     338        y[i] = py + dy[i]*d;
     339    }
     340
     341    for (int i=0; i<6; i++)
     342        DrawLine(buf, w, h, x[i], y[i], x[i+1], y[i+1], col, style);
     343}
     344
     345// --------------------------------------------------------------------------
     346//
     347// Draw a circle into the buffer (size w*h) around (x, y) with radius r and
     348// the color col.
     349//
     350void MGImage::DrawCircle(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col)
     351{
     352    const Int_t n = TMath::Nint(sqrt(2.)*r*TMath::Pi()/2);
     353    for (int i=0; i<n-1; i++)
     354    {
     355        const Double_t angle = TMath::TwoPi()*i/n;
     356
     357        const Double_t dx = r*cos(angle);
     358        const Double_t dy = r*sin(angle);
     359
     360        const Int_t x1 = TMath::Nint(x+dx);
     361        const Int_t x2 = TMath::Nint(x-dx);
     362
     363        const Int_t y1 = TMath::Nint(y+dy);
     364        if (y1>=0 && y1<h)
     365        {
     366            if (x1>=0 && x1<w)
     367                buf[x1+y1*w] = col;
     368
     369            if (x2>=0 && x2<w)
     370                buf[x2+y1*w] = col;
     371        }
     372
     373        const Int_t y2 = TMath::Nint(y-dy);
     374        if (y2>=0 && y2<h)
     375        {
     376            if (x1>=0 && x1<w)
     377                buf[x1+y2*w] = col;
     378
     379            if (x2>=0 && x2<w)
     380                buf[x2+y2*w] = col;
     381        }
     382    }
     383}
     384
     385// --------------------------------------------------------------------------
     386//
     387// Draw a dot into the buffer (size w*h) at (x, y) with color col.
     388//
     389void MGImage::DrawDot(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, UChar_t col)
     390{
     391    const Int_t x1 = TMath::Nint(cx);
     392    const Int_t y1 = TMath::Nint(cy);
     393
     394    if (x1>=0 && y1>=0 && x1<w && y1<h)
     395        buf[x1+y1*w] = col;
     396}
     397
     398// --------------------------------------------------------------------------
     399//
     400// Draw a line into the buffer. The TObject must be a TLine.
     401// Currently only solid and non sloid line are supported.
     402//
     403/*
     404void MGImage::DrawLine(TObject *o, UChar_t *buf, int w, int h, Double_t scale)
     405{
     406    TLine *l = dynamic_cast<TLine*>(o);
     407    if (!l)
     408        return;
     409
     410    const Double_t x1 = 0.5*w-(l->GetX1()/scale);
     411    const Double_t x2 = 0.5*w-(l->GetX2()/scale);
     412    const Double_t y1 = 0.5*h-(l->GetY1()/scale);
     413    const Double_t y2 = 0.5*h-(l->GetY2()/scale);
     414
     415    const Int_t col = Color(l->GetLineColor());
     416    DrawLine(buf, w, h, x1, y1, x2, y2, col, l->GetLineStyle());
     417}
     418*/
     419void MGImage::DrawMultiply(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col)
     420{
     421    DrawLine(buf, w, h, cx-size, cy-size, cx+size, cy+size, col);
     422    DrawLine(buf, w, h, cx+size, cy-size, cx-size, cy+size, col);
     423}
     424
     425void MGImage::DrawCross(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col)
     426{
     427    DrawLine(buf, w, h, cx-size, cy, cx+size, cy, col);
     428    DrawLine(buf, w, h, cx, cy-size, cx, cy+size, col);
     429}
     430
     431// --------------------------------------------------------------------------
     432//
     433// Draw marker into the buffer. The TObject must be a TMarker.
     434// Currently kCircle, kMultiply and KDot are supported.
     435/*
     436void MGImage::DrawMarker(TObject *o, UChar_t *buf, int w, int h, Double_t scale)
     437{
     438    TMarker *m = dynamic_cast<TMarker*>(o);
     439    if (!m)
     440        return;
     441
     442    Double_t x = 0.5*w-(m->GetX()/scale);
     443    Double_t y = 0.5*h-(m->GetY()/scale);
     444
     445    Int_t col = Color(m->GetMarkerColor());
     446
     447    switch (m->GetMarkerStyle())
     448    {
     449    case kCircle:
     450        DrawCircle(buf, w, h, x, y, m->GetMarkerSize()*2+1, col);
     451        break;
     452    case kDot:
     453        DrawDot(buf, w, h, x, y, col);
     454        break;
     455    case kMultiply:
     456        DrawMultiply(buf, w, h, x, y, m->GetMarkerSize()*2+1, col);
     457        break;
     458    case kCross:
     459        DrawCross(buf, w, h, x, y, m->GetMarkerSize()*2+1, col);
     460        break;
     461    }
     462}
     463*/
  • trunk/FACT++/drive/MGImage.h

    r18618 r18628  
    5454    void DisableSyncMode() { ResetBit(kSyncMode); }
    5555
    56     ClassDef(MGImage, 0)
     56    static UChar_t Color(int col);
     57    static void    DrawCircle(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col);
     58    static void    DrawHexagon(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col, Int_t style=1);
     59    static void    DrawLine(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style=1);
     60    static void    DrawBox(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style=1);
     61    static void    DrawDot(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, UChar_t col);
     62    static void    DrawMultiply(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col);
     63    static void    DrawCross(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col);
    5764};
    5865
Note: See TracChangeset for help on using the changeset viewer.