Changeset 2516 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Mar 17, 2004, 7:04:25 PM (22 years ago)
Author:
cmv
Message:

GetDistanceToPoint et preparation des axes centres avec x0,y0

quelconques cmv 17/03/04

Location:
trunk/SophyaPI/PI
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/piaxes.cc

    r2349 r2516  
    111111
    112112    // Les axes
     113    double x0axes = (xMin+xMax)/2.;
     114    double y0axes = (yMin+yMax)/2.;
     115    // POUR REZA: ici si on a demande de forcer les axes en x0,y0
     116    // alors on le fait ici: il faut faire a peu pres ca:
     117    // > if(getaxescenter()) getaxescenter(x0axes,y0axes);
     118    if(x0axes<xMin || x0axes>xMax) x0axes = (xMin+xMax)/2.;
     119    if(y0axes<yMin || y0axes>yMax) y0axes = (yMin+yMax)/2.;
    113120   
    114     g->DrawLine(xMin, (yMin+yMax)/2., xMax, (yMin+yMax)/2.);
    115     g->DrawLine((xMin+xMax)/2., yMin, (xMin+xMax)/2., yMax);
     121    g->DrawLine(xMin, y0axes, xMax, y0axes);
     122    g->DrawLine(x0axes, yMin, x0axes, yMax);
    116123    //    PIArrowMarker amk = g->GetArrowMarker();
    117124    //    if (amk == PI_NotDefArrowMarker)
     
    120127    //    g->SelArrowMarker(5, g->GetArrowMarker());
    121128    double xm2 = g->DeltaUCX(xMax, yMajTickLen*2.);
    122     g->DrawArrowMarker(xMax, (yMin+yMax)/2., xm2, (yMin+yMax)/2., true);
     129    g->DrawArrowMarker(xMax, y0axes, xm2, y0axes, true);
    123130    double ym2 = g->DeltaUCY(yMax, xMajTickLen*2.);
    124     g->DrawArrowMarker((xMin+xMax)/2., yMax, (xMin+xMax)/2., ym2, true);
     131    g->DrawArrowMarker(x0axes, yMax, x0axes, ym2, true);
    125132    // La grille en pointilles
    126133
     
    130137 
    131138    if (flags & kMajTicks) {
    132         DrawHTicks(g, (yMin+yMax)/2., xMajTickLen, xMajTickLen, xMajTicks);
    133         DrawVTicks(g, (xMin+xMax)/2., yMajTickLen, yMajTickLen, yMajTicks);
     139        DrawHTicks(g, y0axes, xMajTickLen, xMajTickLen, xMajTicks);
     140        DrawVTicks(g, x0axes, yMajTickLen, yMajTickLen, yMajTicks);
    134141    }
    135142   
     
    137144 
    138145    if (flags & kMinTicks) {
    139         DrawHTicks(g, (yMin+yMax)/2., xMinTickLen, xMinTickLen, xMinTicks);
    140         DrawVTicks(g, (xMin+xMax)/2., yMinTickLen, yMinTickLen, yMinTicks);
     146        DrawHTicks(g, y0axes, xMinTickLen, xMinTickLen, xMinTicks);
     147        DrawVTicks(g, x0axes, yMinTickLen, yMinTickLen, yMinTicks);
    141148    }
    142149   
     
    146153      double declab = 2*xMajTickLen;
    147154      if (!aYdir)
    148         DrawHLabels(g, (yMin+yMax)/2.-declab, xMajTicks, PI_VerticalTop);
     155        DrawHLabels(g, y0axes-declab, xMajTicks, PI_VerticalTop);
    149156      else
    150         DrawHLabels(g, (yMin+yMax)/2.+declab, xMajTicks, PI_VerticalTop);
     157        DrawHLabels(g, y0axes+declab, xMajTicks, PI_VerticalTop);
    151158
    152159      declab = 2.*yMajTickLen;
    153160      if (!aXdir)
    154         DrawVLabels(g, (xMin+xMax)/2.-declab, yMajTicks, PI_HorizontalRight);
     161        DrawVLabels(g, x0axes-declab, yMajTicks, PI_HorizontalRight);
    155162      else
    156         DrawVLabels(g, (xMin+xMax)/2.+declab, yMajTicks, PI_HorizontalRight);
     163        DrawVLabels(g, x0axes+declab, yMajTicks, PI_HorizontalRight);
    157164    }
    158165   
  • trunk/SophyaPI/PI/pidrawer.cc

    r2503 r2516  
    6565  SetAxesFlags(kAxesNone);   // Pas de trace d'axes par defaut
    6666  SetAxesAutoFontSize();
     67  SetAxesCenter();
    6768
    6869  mDndfg = false;  // Pour controle de l'appel de Detach() si delete
     
    142143//|     kMajTicks , kMinTicks , kLabels , kGridOn
    143144//|     kAxesDflt , kAxesNone
     145// void  SetAxesCenter(bool fset,double x0,double y0)
     146//      Force axe center to be at (x0,y0) or let it be in the middle
    144147// void SetAxesAutoFontSize(bool fg=true)
    145148//      Si "fg==true", la taille de la fonte pour les labels d'axes (chiffres) est
     
    488491}
    489492
     493void
     494PIDrawer::SetAxesCenter(bool fset,double x0,double y0)
     495{
     496 axesCenter = fset;
     497 if(!axesCenter) return;
     498 axesCentX0 = x0;
     499 axesCentY0 = y0;
     500}
    490501
    491502void
  • trunk/SophyaPI/PI/pidrawer.h

    r2503 r2516  
    3030
    3131  virtual void       SetAxesFlags(unsigned int flags=kAxesNone);
     32  virtual void       SetAxesCenter(bool fset=false,double x0=0.,double y0=0.);
    3233  inline  void       SetAxesAutoFontSize(bool fg=true) { axesAFSz = fg; }
    3334
     
    6364
    6465  inline unsigned int GetAxesFlags() { return(axesFlags); }
    65   inline  bool       isAxesAutoFontSize() { return axesAFSz; }
     66  inline  bool        GetAxesCenter() { return(axesCenter); }
     67  inline  bool        GetAxesCenter(double &x0,double& y0)
     68                       {x0=axesCentX0; y0=axesCentY0; return(axesCenter);}
     69  inline  bool        isAxesAutoFontSize() { return axesAFSz; }
    6670
    6771  inline PIGraphicUC*    GetGraphicUC() { return(mGrUC); }
     
    128132  unsigned int axesFlags;
    129133  bool axesAFSz;
     134  bool axesCenter; double axesCentX0,axesCentY0;
    130135  PIBaseWdgGen* mBWdg;
    131136  PIGraphicUC* mGrUC;
  • trunk/SophyaPI/PI/pieldrw.cc

    r2503 r2516  
    563563    else if (opts == "nogrid")
    564564      SetAxesFlags(GetAxesFlags() & ~kGridOn);
     565    else if (opts.substr(0,11) == "axescenter=") {
     566      if(opts == "axescenter=") {
     567        SetAxesCenter();
     568      } else {
     569        double x0=0., y0=0.;
     570        sscanf(opts.substr(11).c_str(),"%lf,%lf",&x0,&y0);
     571        SetAxesCenter(true,x0,y0);
     572      }
     573    }
    565574
    566575    else if (opts.substr(0,13) == "autofontsize=") {
  • trunk/SophyaPI/PI/piyfxdrw.cc

    r2242 r2516  
    44
    55#include "machdefs.h"
     6#include <stdlib.h>
     7#include <iostream>
    68#include <math.h>
    79#include "piyfxdrw.h"
     
    5456  mAy = ay;
    5557  mName = "YfXDrawer";
     58  NptDraw = 0;
    5659}
    5760
     
    119122    }
    120123  if (mSz <= 0)  return;
     124  NptDraw=0;
    121125
    122126//  Trace des markers
     
    128132      if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
    129133      g->DrawMarker(xp, yp);
     134      NptDraw++;
    130135    }
    131136  }
     
    134139
    135140// Trace des lignes
     141  NptDraw=0;
    136142  double xp2, yp2;
    137143  if (mAy) { xp2 = mAx->Value(0); yp2 = mAy->Value(0); }
     
    144150         ((xp2 < xmin) || (xp2 > xmax) || (yp2 < ymin) || (yp2 > ymax)) )  continue;
    145151    g->DrawLine(xp, yp, xp2, yp2);
     152    NptDraw++;
    146153  }
    147 }
     154
     155}
     156
     157
     158/* --Methode-- */
     159double PIYfXDrawer::GetDistanceToPoint(double x, double y)
     160{
     161 if(mSz<=0)  return 1.e+9;
     162
     163 const int nessai = 100;
     164 long inc = (NptDraw>nessai) ? (long)(NptDraw/nessai)+1 : 1;
     165
     166 double dist = -1.e+18;
     167 long n = 0;
     168 for(long i=0; i<mSz; i++) {
     169   double xp,yp;
     170   if(mAy) {xp=mAx->Value(i); yp=mAy->Value(i);}
     171     else  {xp=mAx->X(i);     yp=mAx->Value(i);}
     172   if(xp<XMin() || xp>XMax()) continue;
     173   if(yp<YMin() || yp>YMax()) continue;
     174   if(n%inc==0) {
     175     xp = (xp-x)/(XMax()-XMin())/0.5;
     176     yp = (yp-y)/(YMax()-YMin())/0.5;
     177     xp = xp*xp+yp*yp;
     178     if(dist<0. || xp<dist) dist = xp;
     179   }
     180   n++;
     181 }
     182 dist=sqrt(fabs(dist));
     183 //cout<<"PIYfXDrawer: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()
     184 //    <<" mSz="<<mSz<<" inc="<<inc<<endl;
     185 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<" NptDraw="<<NptDraw<<endl;
     186
     187 return dist;
     188}
     189
     190
     191
    148192
    149193
     
    176220/* --Methode-- */
    177221PIFuncDrawer::PIFuncDrawer(PIFuncDrawer::FUNC f)
    178 : mFunc(f)
     222  : mFunc(f)
    179223{}
    180224
     
    209253}
    210254
     255
     256/* --Methode-- */
     257double PIFuncDrawer::GetDistanceToPoint(double x, double y)
     258{
     259 if(mFunc==NULL) return 1.e+9;
     260
     261 double xStep = (XMax()-XMin())/50;
     262 double dist = -1.e+18;
     263 for(double xx=XMin()+xStep; xx<XMax(); xx+=xStep) {
     264   double xp = (xx-x)/(XMax()-XMin())/0.5;
     265   double yp = (mFunc(xp)-y)/(YMax()-YMin())/0.5;
     266   xp = xp*xp+yp*yp;
     267   if(dist<0. || xp<dist) dist = xp;
     268 }
     269 dist=sqrt(fabs(dist));
     270 //cout<<"PIFuncDrawer: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()<<endl;
     271 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl;
     272
     273 return dist;
     274}
  • trunk/SophyaPI/PI/piyfxdrw.h

    r1904 r2516  
    2525  virtual void       UpdateLimits();
    2626 
    27        
     27 // Renvoie une distance au point x,y
     28  virtual double     GetDistanceToPoint(double x, double y);
     29
    2830protected:
    2931  P1DArrayAdapter* mAx;
     
    3133  int mSz;
    3234  bool mAdDO;
     35  long NptDraw; // nombre de points effectivement dessines dans la fenetre
    3336};
    3437
     
    4447 
    4548  virtual void       Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
     49
     50 // Renvoie une distance au point x,y
     51  virtual double     GetDistanceToPoint(double x, double y);
     52
    4653protected:
    4754  FUNC               mFunc;
Note: See TracChangeset for help on using the changeset viewer.