Changeset 3734 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Jan 29, 2010, 7:15:04 PM (16 years ago)
Author:
ansari
Message:

1/ Introduction de la classe PICMapDrawer (Traceur de ColorMap)
2/ Ajout de la possibilite d'afficher la table de couleur a l'aide de
PICMapDrawer dans la fenetre principale PIImage.
3/ Cette possibilite peut etre active avec l'attribut graphique
showcmap showcmap=no/top/right/bottom/left/horiz/vert

Reza 29/01/2010

Location:
trunk/SophyaPI/PI
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/lut.h

    r3545 r3734  
    4040  inline double Min() { return(bornes[0]); };
    4141  inline double Max() { return(bornes[nLevel]); };
     42  inline double Borne(int k) { return(bornes[k]); };
    4243  inline int Type() { return(type); };
    4344  inline int NCol() { return(nLevel+2); };
  • trunk/SophyaPI/PI/picmapview.cc

    r3545 r3734  
    55#include "sopnamsp.h"
    66#include "picmapview.h"
     7#include "strutil.h"
    78#include <math.h>
     9#include <iostream>
    810
    911//++
     
    186188}
    187189
    188 
    189 
    190 
    191 
    192 
     190//++
     191// Class        PICMapDrawer
     192// Lib          PI
     193// include      picmapview.h
     194//
     195//      Classe de traceur de colormap
     196//--
     197//++
     198// Links        Parents
     199// PIDrawer
     200//--
     201//++
     202
     203
     204/* --Methode-- */
     205PICMapDrawer::PICMapDrawer(bool fgvert)
     206  : fgvert_(fgvert), fgtext_(false), cmapp(NULL), bornes_(5)   
     207{
     208  SetLimits(0.,1.,0.,1., kAxeDirLtoR, kAxeDirDownUp);
     209  SetColMapId(CMAP_GREY32);
     210}
     211
     212/* --Methode-- */
     213PICMapDrawer::~PICMapDrawer()
     214{
     215}
     216
     217/* --Methode-- */
     218void PICMapDrawer::SetBornes(LUT& lut)
     219{
     220  fgtext_=true; 
     221  bornes_[0]=lut.Min();   bornes_[4]=lut.Max();
     222  bornes_[1]=lut.Borne((lut.NCol()-2)/4);
     223  bornes_[2]=lut.Borne((lut.NCol()-2)/2);
     224  bornes_[3]=lut.Borne(3*(lut.NCol()-2)/4);
     225  return;
     226}
     227
     228/* --Methode-- */
     229void PICMapDrawer::SetBornes(double min, double max)
     230{
     231  fgtext_=true; 
     232  bornes_[0]=min;   bornes_[4]=max;
     233  bornes_[1]=min+(max-min)*0.25;
     234  bornes_[2]=min+(max-min)*0.5;
     235  bornes_[3]=min+(max-min)*0.75;
     236  return;
     237}
     238
     239/* --Methode-- */
     240void PICMapDrawer::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/,
     241                        double /*xmax*/, double /*ymax*/)
     242{
     243  PIColorMap* cmp=cmapp;
     244  PIColorMap cmapi(cmapid_);
     245  if (cmp==NULL)  cmp=&cmapi;
     246  PIColorMap& cmap=(*cmp);
     247
     248  //  cout << " *DBG*PICMapDrawer::Draw() Sz:" << BWdgXSize() << "," << BWdgYSize()
     249  //     << " Pos:" << BWdgXPos() << "," << BWdgYPos() << endl;
     250  // On limite le nombre de carres de couleurs traces, si trop de couleur ...
     251  PIPixColIdx pixc;
     252  if (fgvert_) {   // vertical
     253    pixc.AllocateByte(0.25*BWdgXSize(), BWdgYSize());
     254    for(int j=0; j<pixc.YSize(); j++)  {
     255      int ci = j*cmap.NCol()/pixc.YSize();
     256      int jrev=pixc.YSize()-j-1;
     257      for(int i=0; i<pixc.XSize(); i++) pixc.GetByte(i,jrev)=(unsigned char)ci;
     258    }
     259    g->DrawPixmap(0.,1.,pixc, cmp);
     260  }
     261  else {    // horizontal
     262    pixc.AllocateByte(BWdgXSize(), 0.25*BWdgYSize());
     263    for(int i=0; i<pixc.XSize(); i++)  {
     264      int ci = i*cmap.NCol()/pixc.XSize();
     265      for(int j=0; j<pixc.YSize(); j++) pixc.GetByte(i,j)=(unsigned char)ci;
     266    }
     267    g->DrawPixmap(0.,0.25,pixc, cmp);
     268  }
     269
     270
     271  if (!fgtext_) return;
     272  char buff[32];
     273  double ps[5]={0.025,0.25,0.5,0.75,0.975};
     274  //  g->SelForeground(PI_White);
     275  for(int k=0; k<5; k++) {
     276    sprintf(buff,"%6.2lg",bornes_[k]);
     277    strip(buff,'B',' ');
     278    if (fgvert_) {   // vertical
     279      g->DrawLine(0.25,ps[k],0.35,ps[k]);
     280      g->DrawString(0.7, ps[k], buff, PI_TextDirectionVerticalUp|PI_HorizontalCenter|PI_VerticalCenter);
     281    }
     282    else {   // horizontal
     283      g->DrawLine(ps[k],0.25,ps[k],0.35);
     284      g->DrawString(ps[k], 0.7, buff, PI_VerticalCenter|PI_HorizontalCenter);
     285    }
     286  }
     287  return;
     288}
     289
     290
  • trunk/SophyaPI/PI/picmapview.h

    r2652 r3734  
    1111#include PIBWDG_H
    1212#include PICMAP_H
     13
     14#include "pidrawer.h"
     15#include "lut.h"
     16#include <vector>
     17
    1318
    1419class PICMapView : public PIBaseWdg
     
    3843};
    3944
     45class PICMapDrawer : public PIDrawer
     46{
     47public:
     48                     PICMapDrawer(bool fgvert=false);
     49                     ~PICMapDrawer();
     50
     51  virtual void       Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
     52  inline void        SetHorizontal()  { fgvert_=false; }
     53  inline void        SetVertical()  { fgvert_=true; }
     54
     55  inline void        SetColMapId(CMapId cmapid, bool revcidx=false)
     56                     { cmapid_=cmapid;  revcidx_=revcidx;  cmapp=NULL;  return; }
     57
     58  inline void        SetColMap(PIColorMap* cmp)
     59                     { cmapp=cmp;  return; }
     60
     61  void               SetBornes(LUT& lut);
     62  void               SetBornes(double min, double max);
     63
     64protected:
     65
     66  bool fgvert_;  // true -> vertical
     67  bool fgtext_;  // true -> ecriture des valeurs des bornes
     68  PIColorMap* cmapp; 
     69  CMapId cmapid_;
     70  bool revcidx_;  // true -> reverse color map index
     71  vector<double> bornes_; 
     72};
     73
    4074
    4175#endif
  • trunk/SophyaPI/PI/pidrawer.cc

    r3562 r3734  
    118118
    119119//++
    120 // Titre        Gestion des axes et des limites
     120// Titre        Gestion des axes, des limites et coordonnees fenetre
    121121//      Le tracé des axes 2D est pris en charge par la classe PIAxes.
    122122//--
    123123//++
     124// double BWdgXPos()  BWdgYPos()
     125//      Renvoient les positions (X,Y) du drawer dans l'objet PIBaseWdg. Ces positions ne sont
     126//      valables qu'apres appel a SetDrwWdg() - Ne peut donc etre utilise en pratique que dans
     127//      la methode Draw.
     128// double  BWdgXSize()  BWdgYSize()
     129//      Renvoient les tailles (X,Y) du drawer dans l'objet PIBaseWdg. Meme remarque que pour
     130//      BWdgXPos()  BWdgYPos().
     131//
    124132// void  SetLimits(double xmin, double xmax, double ymin, double ymax, -
    125133//                 int axrl=kAxeDirSame, int ayud=kAxeDirSame)
    126 //      Définit les limites du système de coordonnées.
     134//      Définit les limites du système de coordonnées du Drawer.
    127135//|     kAxeDirSame , kAxeDirAuto
    128136//|     kAxeDirLtoR , kAxeDirRtoL  (Axe X)
  • trunk/SophyaPI/PI/pidrawer.h

    r3562 r3734  
    6060  virtual void       HighLight(bool fgh); 
    6161
     62  // Zone de trace/accrochage dans le BaseWidget
     63  inline int         BWdgXPos() const { return xW0; }
     64  inline int         BWdgYPos() const { return yW0; }
     65  inline int         BWdgXSize() const { return xWd; }
     66  inline int         BWdgYSize() const { return yWd; }
     67
     68  // Limites et informations sur les coordonnees dans le systeme du Drawer
    6269  inline double      XMin() const {return xMin;}
    6370  inline double      XMax() const {return xMax;}
  • trunk/SophyaPI/PI/piimage.cc

    r3545 r3734  
    111111gvw = NULL;   // widget vue globale
    112112cmvw = NULL;  // widget ColorMapView
     113fgshowcmap = 0;  // 0: Pas de vue ColMap, 1: top, 2:right,  3:bottom, 4:left
     114 cmdid = -1;
    113115// Fenetre transient et Label pour affichage de l'info (texte PixVal)
    114116int tx, ty;
     
    142144
    143145mdrw = new PIElDrawer(false);
    144  mdrw->SetAxesFlags(kAxesNone);
     146mdrw->SetAxesFlags(kAxesNone);
    145147gvdrw = new PIElDrawer();
    146148AddDrawer(mdrw, true, false, false, false);
     
    666668      continue;
    667669    }
     670    if (opts == "showcmap")  UpdateCMapDrawer(1);
     671    else if (opts == "noshowcmap")  UpdateCMapDrawer(0);
     672    else if (opts.substr(0,9) == "showcmap=") {
     673      if (opts.substr(9,2) == "no")   UpdateCMapDrawer(0);
     674      else if (opts.substr(9,3) == "top")     UpdateCMapDrawer(1);
     675      else if (opts.substr(9,5) == "right")   UpdateCMapDrawer(2);
     676      else if (opts.substr(9,6) == "bottom")  UpdateCMapDrawer(3);
     677      else if (opts.substr(9,4) == "left")    UpdateCMapDrawer(4);
     678      else if (opts.substr(9,5) == "horiz")   UpdateCMapDrawer(1);
     679      else if (opts.substr(9,4) == "vert")    UpdateCMapDrawer(2);
     680      else UpdateCMapDrawer(0);
     681    }
     682
    668683    ndec--;
    669684    udopt.push_back(opts);
     
    785800{
    786801if (img == NULL)  return;
     802if (fgshowcmap>0)  {
     803  cmpd.SetColMap(GetColMap());
     804  cmpd.SetBornes(*Lut());
     805}
    787806if (mw)  { 
    788807  ComputePixmap();
     
    13791398//printf("UpdateCuts()-DBG X: %d  -> %g  , Y: %d -> %g \n", cutarrx->Size(), cutarrx->Value(0),
    13801399//       cutarry->Size(), cutarry->Value(0));
     1400}
     1401
     1402/* --Methode-- */
     1403void PIImage::UpdateCMapDrawer(int fgshow)
     1404{
     1405  if ((fgshow<0)||(fgshow>4))  fgshow=0;
     1406  if (fgshow==fgshowcmap) return;
     1407  fgshowcmap=fgshow;
     1408  switch (fgshowcmap ) {
     1409  case 0 :
     1410    RemoveDrawer(cmdid);
     1411    break;
     1412  case 1 :
     1413    cmpd.SetHorizontal();
     1414    cmdid=AddDrawer(&cmpd, 0.10, 0.02, 0.90, 0.10, true, false);
     1415    break;
     1416  case 2 :
     1417    cmpd.SetVertical();
     1418    cmdid=AddDrawer(&cmpd, 0.90, 0.1, 0.98, 0.9, true, false);
     1419    break;
     1420  case 3 :
     1421    cmpd.SetHorizontal();
     1422    cmdid=AddDrawer(&cmpd, 0.10, 0.90, 0.90, 0.98, true, false);
     1423    break;
     1424  case 4 :
     1425    cmpd.SetVertical();
     1426    cmdid=AddDrawer(&cmpd, 0.02, 0.1, 0.10, 0.9, true, false);
     1427    break;   
     1428  }
     1429  if (fgshowcmap>0) cmpd.GetGraphicAtt().SetColAtt(PI_Turquoise);
    13811430}
    13821431
  • trunk/SophyaPI/PI/piimage.h

    r3519 r3734  
    135135  void SetGloVPixmap();
    136136  void UpdateCuts();
     137  void UpdateCMapDrawer(int fgshow);
    137138
    138139  void DrawCursor(PIGraphic* g);
     
    171172// Fenetre d'affichage du ColMap
    172173  PICMapView* cmvw;
     174  int fgshowcmap;  // 0: Pas de vue ColMap, 1: top, 2:right, 3:bottom, 4:left
     175  PICMapDrawer cmpd;
     176  int cmdid;
    173177// Fenetre/champ de texte
    174178  PILabel * trtlb;
Note: See TracChangeset for help on using the changeset viewer.