Ignore:
Timestamp:
07/08/02 17:31:20 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mgui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mgui/MCamDisplay.cc

    r1384 r1390  
    3535#include <math.h>
    3636#include <fstream.h>
     37#include <iostream.h>
    3738
    3839#include <TClonesArray.h>
     
    4142#include <TBox.h>
    4243#include <TText.h>
     44#include <TButton.h>
    4345
    4446#include "MHexagon.h"
     
    5052#include "MCerPhotEvt.h"
    5153
    52 #define kItemsLegend 25 // see SetPalette(1,0)
     54#define kItemsLegend 50 // see SetPalette(1,0)
    5355
    5456ClassImp(MCamDisplay);
     
    8688    //
    8789#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
    88     gStyle->SetPalette(1, 0);
     90    SetPalette(1, 0);
    8991#else
    90     gStyle->SetPalette(51, 0);
     92    SetPalette(51, 0);
    9193#endif
    9294
     
    102104        TText *newtxt = new ((*fLegText)[i]) TText;
    103105
    104         const Float_t lvl = 50. / kItemsLegend * i;
    105 
    106         newbox->SetFillColor(GetColor(lvl));
     106        newbox->SetFillColor(fColors[i]);
    107107
    108108        newtxt->SetTextSize(0.025);
     
    186186    //
    187187    gPad->Range(-fRange, -y, x, y);
     188}
     189
     190// ------------------------------------------------------------------------
     191//
     192//  With this function you can change the color palette. For more
     193// information see TStyle::SetPalette. Only palettes with 50 colors
     194// are allowed.
     195// In addition you can use SetPalette(52, 0) to create an inverse
     196// deep blue sea palette
     197//
     198void MCamDisplay::SetPalette(Int_t ncolors, Int_t *colors)
     199{
     200    //
     201    // If not enough colors are specified skip this.
     202    //
     203    if (ncolors>1 && ncolors<50)
     204    {
     205        cout << "MCamDisplay::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
     206        return;
     207    }
     208
     209    //
     210    // If ncolors==52 create a reversed deep blue sea palette
     211    //
     212    if (ncolors==52)
     213    {
     214        gStyle->SetPalette(51, NULL);
     215        Int_t c[50];
     216        for (int i=0; i<50; i++)
     217            c[49-i] = gStyle->GetColorPalette(i);
     218        gStyle->SetPalette(50, c);
     219    }
     220    else
     221        gStyle->SetPalette(ncolors, colors);
     222
     223    if (fDrawingPad)
     224    {
     225        //
     226        // Set the colors of the legend
     227        //
     228        for (int i=0; i<kItemsLegend; i++)
     229        {
     230            Int_t col = GetBox(i)->GetFillColor();
     231
     232            //
     233            // Make sure, that the legend is already colored
     234            //
     235            if (col==10 || col==22)
     236                continue;
     237            GetBox(i)->SetFillColor(gStyle->GetColorPalette(i));
     238        }
     239
     240        //
     241        // Change the colors of the pixels
     242        //
     243        for (unsigned int i=0; i<fNumPixels; i++)
     244        {
     245            //
     246            // Get the old color index and check whether it is
     247            // background or transparent
     248            //
     249            Int_t col = (*this)[i].GetFillColor();
     250            if (col==10 || col==22)
     251                continue;
     252
     253            //
     254            // Search for the color index (level) in the color table
     255            //
     256            int idx;
     257            for (idx=0; idx<kItemsLegend; idx++)
     258                if (col==fColors[idx])
     259                    break;
     260            //
     261            // Should not happen
     262            //
     263            if (idx==kItemsLegend)
     264            {
     265                cout << "MCamDisplay::SetPalette: Strange... FIXME!" << endl;
     266                continue;
     267            }
     268
     269            //
     270            // Convert the old color index (level) into the new one
     271            //
     272            (*this)[i].SetFillColor(gStyle->GetColorPalette(idx));
     273        }
     274
     275        //
     276        // Update the pad on the screen
     277        //
     278        fDrawingPad->Modified();
     279        fDrawingPad->Update();
     280    }
     281
     282    //
     283    // Store the color palette used for a leter reverse lookup
     284    //
     285    for (int i=0; i<kItemsLegend; i++)
     286        fColors[i] = gStyle->GetColorPalette(i);
    188287}
    189288
     
    226325
    227326    //
     327    // Create and draw the buttons which allows changing the
     328    // color palette of the display
     329    //
     330    TButton *but;
     331    char txt[100];
     332    sprintf(txt, "((MCamDisplay*)%p)->SetPalette(1,0);", this);
     333    but = new TButton("Pretty", txt, 0.01, 0.95, 0.15, 0.99);
     334    but->Draw();
     335    sprintf(txt, "((MCamDisplay*)%p)->SetPalette(51,0);", this);
     336    but = new TButton("Deap Sea", txt, 0.16, 0.95, 0.30, 0.99);
     337    but->Draw();
     338    sprintf(txt, "((MCamDisplay*)%p)->SetPalette(52,0);", this);
     339    but = new TButton("Blue Inv", txt, 0.31, 0.95, 0.45, 0.99);
     340    but->Draw();
     341
     342    //
    228343    // Setup the correct environment
    229344    //
    230 #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
    231     gStyle->SetPalette(1, 0);
    232 #else
    233     gStyle->SetPalette(51, 0);
    234 #endif
    235 
    236345    gPad->SetFillColor(22);
    237346
     
    241350    //
    242351    for (UInt_t i=0; i<fNumPixels; i++)
     352    {
     353        (*this)[i].SetFillColor(22);
    243354        (*this)[i].Draw();
    244 
    245     //
    246     // draw legend
     355    }
     356
     357    //
     358    // initialize and draw legend
    247359    //
    248360    const Float_t H = 0.9*fRange;
     
    258370        box->SetY1(H*( i   *h - 1.));
    259371        box->SetY2(H*((i+1)*h - 1.));
     372        box->SetFillColor(22);
    260373        box->Draw();
    261374
     
    305418
    306419    fDrawingPad->cd();
     420
     421    for (int i=0; i<kItemsLegend; i++)
     422        GetBox(i)->SetFillColor(fColors[i]);
    307423
    308424    //
     
    374490    //   first treat the over- and under-flows
    375491    //
    376     const Int_t maxcolidx = 49;
     492    const Int_t maxcolidx = kItemsLegend-1;
    377493
    378494    if (val >= fMaxPhe)
    379         return gStyle->GetColorPalette(maxcolidx);
     495        return fColors[maxcolidx];
    380496
    381497    if (val <= fMinPhe)
    382         return gStyle->GetColorPalette(0);
     498        return fColors[0];
    383499
    384500    //
     
    388504    const Int_t   colidx = (Int_t)(ratio*maxcolidx + .5);
    389505
    390     return gStyle->GetColorPalette(colidx);
     506    return fColors[colidx];
    391507}
    392508
     
    400516    char text[10];
    401517
    402     for (Int_t i=0; i<kItemsLegend; i++)
     518    for (Int_t i=0; i<kItemsLegend; i+=3)
    403519    {
    404520        const Float_t val = fMinPhe + (Float_t)i/kItemsLegend * (fMaxPhe-fMinPhe) ;
  • trunk/MagicSoft/Mars/mgui/MCamDisplay.h

    r1384 r1390  
    3030    Float_t        fMinPhe;      // The minimal number of Phe
    3131    Float_t        fMaxPhe;      // The maximum number of Phe
     32
     33    Int_t          fColors[50];
    3234
    3335    TClonesArray  *fPixels;      // array of all hexagons
     
    6466    void SavePrimitive(ofstream &out, Option_t *);
    6567
     68    void SetPalette(Int_t ncolors, Int_t *colors);
     69
    6670    ClassDef(MCamDisplay, 0) // Displays the magic camera
    6771};
Note: See TracChangeset for help on using the changeset viewer.