Changeset 2517 in Sophya for trunk/SophyaPI/PIext/pihisto.cc


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

GetDistanceToPoint cmv 17/03/04

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pihisto.cc

    r2469 r2517  
    33
    44#include <stdio.h>
     5#include <stdlib.h>
     6#include <iostream>
     7#include <math.h>
    58#include <typeinfo>
    69
     
    3942  SetStats();
    4043  SetError();
     44  SetFilled();
    4145  SetStatPosOffset();
    4246  SetName("HistoDrw");
     
    8084
    8185  bool oktrace=false;
     86  // Tracer d'une polyline si demandee
     87  bool drawpline=false;
     88  if(GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) drawpline=true;
    8289  // Tracer des marqueurs si demande ou si HProf
    8390  bool drawmarker=false;
     
    94101  else if(error>0) drawerr=true;
    95102  else if(error<0) drawerr=false;
     103  // Fill de l'histo ?
     104  bool drawfill=false;
     105  if(filled) drawfill=true; else drawfill=false;
     106  // Et aussi si on ne demande ni ligne ni marqueur ?
     107  if( !drawmarker && !drawpline && !drawerr ) drawfill=true;
     108
     109  // Remplissage des bins avec la couleur courante (trace en premier)
     110  if(drawfill) {
     111    oktrace = true;
     112    for(int i=0; i<mHisto->NBins(); i++) {
     113      double left   = mHisto->BinLowEdge(i);
     114      double width  = mHisto->BinWidth();
     115      double bottom = 0;
     116      double height = (*mHisto)(i);
     117      g->DrawFBox(left,bottom,width,height);
     118    }
     119  }
    96120
    97121  // Trace des marqeurs
     
    125149  }
    126150
    127   // Trace de la ligne continue
    128   // Si on ne demande pas de ligne (PI_NotDefLineAtt)
    129   // et que l'on a rien trace auparavent, on trace un FPolygon
    130   if(GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt || !oktrace) {
     151  // Trace de la ligne continue si demandee
     152  if(drawpline) {
    131153    PIGrCoord* x1 = new PIGrCoord[2*mHisto->NBins()+2];
    132154    PIGrCoord* y1 = new PIGrCoord[2*mHisto->NBins()+2];
     
    147169    y1[npt] = 0;
    148170    npt++;
    149     if(GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) {
    150       g->DrawPolygon(x1,y1,npt,false);
    151       oktrace = true;
    152     }
    153     if(!oktrace) g->DrawFPolygon(x1,y1,npt,false);
    154     delete[] x1;  delete[] y1;
     171    g->DrawPolygon(x1,y1,npt,false);
     172    delete [] x1; delete [] y1;
     173    oktrace = true;
    155174  }
    156175
     
    179198    else if(opts=="noerr")    SetError(-1);
    180199    else if(opts=="autoerr")  SetError(0);
     200    else if(opts=="fill")     SetFilled(true);
     201    else if(opts=="nofill")   SetFilled(false);
    181202    else if(opts.substr(0,11) == "statposoff=") {
    182203      float xo=0., yo=0.;
     
    204225info += "  err / nerr : draw, do not draw error bars\n";
    205226info += "  autoerr : draw error bars if Marker drawing requested OR Profile histo\n";
     227info += "  fill / nofill : fill, do not fill bars with selected color\n";
    206228info += "  statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
    207229info += "       as a fraction of total size \n";
     
    262284                       
    263285}
     286
     287
     288
     289/* --Methode-- */
     290double PIHisto::GetDistanceToPoint(double x, double y)
     291{
     292 if (!mHisto) return 1.e+9;
     293
     294 double dist = -1.e+18;
     295 for(int i=0; i<mHisto->NBins(); i++) {
     296   double xp=mHisto->BinCenter(i);
     297   double yp=(*mHisto)(i);
     298   xp = (xp-x)/(XMax()-XMin())/0.5;
     299   yp = (yp-y)/(YMax()-YMin())/0.5;
     300   xp = xp*xp+yp*yp;
     301   if(dist<0. || xp<dist) dist = xp;
     302 }
     303 dist=sqrt(fabs(dist));
     304 //cout<<dist<<"PIHisto: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()
     305 //    <<" NBins="<<mHisto->NBins()<<endl;
     306 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl;
     307
     308 return dist;
     309}
Note: See TracChangeset for help on using the changeset viewer.