00001 #include "bdgl_curve_region.h" 00002 //----------------------------------------------------------------------------- 00003 //: 00004 // \file 00005 // \author P.L. Bazin 00006 //----------------------------------------------------------------------------- 00007 00008 #include <vdgl/vdgl_edgel.h> 00009 #include <vdgl/vdgl_edgel_chain.h> 00010 #include <vdgl/vdgl_edgel_chain_sptr.h> 00011 #include <vcl_cmath.h> 00012 00013 //----------------------------------------------------------------------------- 00014 void bdgl_curve_region::init(vdgl_edgel_chain_sptr curve) 00015 { 00016 vdgl_edgel ed; 00017 double dist; 00018 int N = (*curve).size(); 00019 00020 if (N==0){ 00021 center_.set(0,0); 00022 radius_ = 0.0; 00023 return; 00024 } 00025 00026 center_.set(0,0); 00027 for (int i = 0; i<N; i++) { 00028 ed = curve->edgel(i); 00029 center_.set(center_.x() + ed.get_x(), center_.y() + ed.get_y()); 00030 } 00031 center_.set( center_.x()/(double)N , center_.y()/(double)N ); 00032 00033 radius_ = 0.0; 00034 for (int i = 0; i<N; i++) { 00035 ed = curve->edgel(i); 00036 dist = vcl_sqrt( (center_.x()-ed.get_x())*(center_.x()-ed.get_x()) 00037 + (center_.y()-ed.get_y())*(center_.y()-ed.get_y()) ); 00038 if (dist > radius_) radius_ = dist; 00039 } 00040 00041 //vcl_cout<<" region: ["<<floor(center_.x())<<','<<floor(center_.y())<<"] "<<radius_<<'\n'; 00042 00043 return; 00044 } 00045 00046 //-----------------------------------------------------------------------------