33{
   35 
   36  string  inputFile;
   39  ULong_t seed;
   41 
   42  try {
   43 
   44    JParser<> zap(
"Example program to test convex hull and enclosing circle.");
 
   45 
   51 
   52    zap(argc, argv);
   53  }
   54  catch(const exception &error) {
   55    FATAL(error.what() << endl);
 
   56  }
   57 
   58  gRandom->SetSeed(seed);
   59 
   61 
   62 
   64 
   65  typedef vector<JVector2D>::const_iterator const_iterator;
   67 
   68 
   69  if (inputFile != "") {
   70 
   71    ifstream in(inputFile.c_str());
   72 
   73    for (
double x, y; in >> 
x >> 
y; ) {
 
   75    }
   76 
   77    in.close();
   78 
   80 
   81    NOTICE(
"Seed: " << gRandom->GetSeed() << endl);
 
   82 
   84 
   85      buffer.push_back(
JVector2D(gRandom->Uniform(-1.0, +1.0),
 
   86                                 gRandom->Uniform(-1.0, +1.0)));
   87    }
   88 
   90      
   92 
   93      for (const_iterator i = buffer.begin(); i != buffer.end(); ++i)
   94        out << 
FIXED(7,3) << i->getX() << 
' '  
   95            << 
FIXED(7,3) << i->getY() << endl;
 
   96      
   97      out.close();
   98    }
   99 
  100  } else {
  101 
  102    FATAL(
"No points to draw." << endl);
 
  103  }
  104 
  105  for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
  106    DEBUG(
FIXED(7,3) << i->getX() << 
' ' << 
FIXED(7,3) << i->getY() << endl);
 
  107  }
  108 
  109  const JCircle2D circle(buffer.begin(), buffer.end());
 
  110 
  112                                                 buffer.end());
  113 
  114 
  116        << 0                                    << ' ' 
  117        << 
distance(buffer.begin(),hull.first)  << endl);
 
  118 
  120        << 
distance(buffer.begin(),hull.first)  << 
' ' 
  121        << 
distance(buffer.begin(),hull.second) << endl);
 
  122 
  123  DEBUG(
"circle: " << circle.getX() << 
' ' << circle.getY() << 
' ' << circle.getRadius() << endl);
 
  124 
  125  double area = 
getArea2D(buffer.begin(), hull.second);
 
  126  
  127  NOTICE(
"Area: " << area << endl);
 
  128 
  129 
  130  { 
  132 
  133    for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
  134      if (!
inside2D(buffer.begin(), hull.second,             *i)) { ++
n[0]; }
 
  135      if (!
inside2D(buffer.begin(), hull.first, hull.second, *i)) { ++
n[1]; }
 
  136 
  137      if (!
inside2D(buffer.begin(), hull.first, hull.second, *i)) { 
 
  138        
  139      }
  140    }
  141    
  142    for (
int i = 0; i != 
sizeof(
n)/
sizeof(
n[0]); ++i) {
 
  143      NOTICE(
"Number of points outside [" << i << 
"] " << n[i] << endl);
 
  144    }
  145  }
  146 
  147  TApplication* tp = new TApplication("user", NULL, NULL);
  148 
  149  TCanvas cv("cv", "", 400, 400);
  150 
  151  cv.SetFillStyle(4000);
  152  cv.SetFillColor(0);
  153 
  154  cv.Divide(1, 1);
  155  cv.cd(1);
  156 
  157 
  158  TEllipse  ellipse(circle.getX(), circle.getY(), circle.getRadius());
  159 
  160 
  161  const Int_t MAX_BUFFER_SIZE = buffer.size() + 1;
  162 
  163  Double_t  
x[MAX_BUFFER_SIZE];
 
  164  Double_t  
y[MAX_BUFFER_SIZE];
 
  165 
  166  int N = 0;
  167 
  168  for (const_iterator i = buffer.begin(); i != buffer.end(); ++i, ++N) {
  171  }
  172 
  173 
  174  Double_t xmin = -2.0;
  175  Double_t xmax = +2.0;
  176  Double_t ymin = -2.0;
  177  Double_t ymax = +2.0;
  178 
  179  TH2D h2("h2", "", 1, xmin, xmax, 1, ymin, ymax);
  180 
  181  h2.SetStats(kFALSE);
  182  h2.Draw();
  183 
  184 
  185  ellipse.SetLineWidth(2);
  186  ellipse.Draw();
  187 
  188 
  189  TGraph g(N, x, y);
  190 
  191  g.SetMarkerStyle(20);
  192  g.SetMarkerColor(kBlack);
  193  g.SetMarkerSize(0.7);
  194  g.Draw("P");
  195 
  196 
  197  
  198  
  199  N = 
distance(buffer.begin(), hull.first);
 
  200 
  202 
  203  g1.SetLineColor(kBlack);
 
  206 
  207 
  208  
  209 
  210  const int i = --N;
  211 
  212  N = 
distance(buffer.begin(), hull.second);
 
  213 
  216 
  217  N = N + 1 - i;
  218 
  219  TGraph g2(N, &x[i], &y[i]);
  220 
  221  g2.SetLineColor(kRed);
  222  g2.SetLineWidth(2);
  223  g2.Draw("L");
  224 
  225 
  226  cv.Update();
  227 
  228  tp->Run();
  229}
#define DEBUG(A)
Message macros.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Double_t g1(const Double_t x)
Function.
 
Data structure for circle in two dimensions.
 
Data structure for vector in two dimensions.
 
Utility class to parse command line options.
 
double getArea2D(T __begin, T __end)
Get area of a convex polygon.
 
bool inside2D(T __begin, T __end, const JVector2D &pos)
Check if given point is inside a convex polygon.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
Auxiliary data structure for floating point format specification.