Go to the documentation of this file.00001
00002 #include "vtol_intensity_face.h"
00003
00004
00005
00006 #include <vcl_vector.h>
00007 #include <vnl/vnl_matrix.h>
00008 #include <vdgl/vdgl_digital_region.h>
00009 #include <vsol/vsol_curve_2d.h>
00010 #include <vsol/vsol_curve_2d_sptr.h>
00011 #include <vtol/vtol_one_chain.h>
00012 #include <vtol/vtol_one_chain_sptr.h>
00013 #include <vtol/vtol_edge.h>
00014 #include <vtol/vtol_edge_2d.h>
00015 #include <vtol/vtol_face_2d.h>
00016
00017
00018
00019
00020
00021
00022
00023 vtol_intensity_face::vtol_intensity_face(vtol_face_2d_sptr const& f)
00024 : vtol_face_2d(f),
00025 region_(new vdgl_digital_region())
00026 {
00027 }
00028
00029
00030 vtol_intensity_face::vtol_intensity_face(vtol_intensity_face_sptr const& f)
00031 : vtol_face_2d(f->cast_to_face_2d()),
00032 region_(new vdgl_digital_region(f->Npix(), f->Xj(), f->Yj(), f->Ij()))
00033 {
00034 }
00035
00036
00037
00038
00039
00040
00041 vtol_intensity_face::vtol_intensity_face(one_chain_list & one_chains)
00042 : vtol_face_2d(one_chains), region_(new vdgl_digital_region())
00043 {
00044 }
00045
00046
00047 vtol_intensity_face::vtol_intensity_face(vcl_vector<vtol_one_chain_sptr>* chains, vdgl_digital_region const& dr)
00048 : vtol_face_2d(*chains), region_(new vdgl_digital_region(dr.Npix(), dr.Xj(), dr.Yj(), dr.Ij()))
00049 {
00050 }
00051
00052
00053
00054
00055
00056
00057 vtol_intensity_face::vtol_intensity_face(vtol_face_2d_sptr const& face, int npts, float const* xp, float const* yp,
00058 unsigned short const* pix)
00059 :vtol_face_2d(face),
00060 region_(new vdgl_digital_region(npts, xp, yp, pix))
00061 {
00062 }
00063
00064
00065 vtol_intensity_face::~vtol_intensity_face()
00066 {
00067 delete region_;
00068 }
00069
00070
00071
00072
00073
00074
00075 vsol_spatial_object_2d* vtol_intensity_face::clone() const
00076 {
00077 return new vtol_intensity_face(vtol_intensity_face_sptr(const_cast<vtol_intensity_face*>(this)));
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 vnl_matrix<double> vtol_intensity_face::MomentMatrix()
00087 {
00088 vnl_matrix<double> M(3,3);
00089
00090 M(0,0) = X2()+(Ix()*Ix()/Npix()); M(0,1) = XY()+(Ix()*Iy()/Npix()); M(0,2) = Ix();
00091 M(1,0) = M(0,1); M(1,1) = Y2()+(Iy()*Iy()/Npix()); M(1,2) = Iy();
00092 M(2,0) = Ix(); M(2,1) = Iy(); M(2,2) = Npix();
00093 return M;
00094 }
00095
00096
00097
00098
00099
00100
00101 double vtol_intensity_face::perimeter()
00102 {
00103 edge_list edges; this->edges(edges);
00104 double p = 0.0;
00105
00106 for (edge_list::iterator eit = edges.begin(); eit != edges.end(); eit++)
00107 {
00108 vsol_curve_2d_sptr c = (*eit)->cast_to_edge_2d()->curve();
00109 if (c)
00110 p += c->length();
00111 }
00112 return p;
00113 }
00114
00115 #if 0 //nobody appears to call these methods
00116
00117
00118
00119 void vtol_intensity_face::extrema(vcl_vector<float>& orientation,
00120 float& fmin, float& fmax)
00121 {
00122
00123
00124 float fmin = vnl_numeric_traits<float>::maxval,
00125 fmax = -vnl_numeric_traits<float>::maxval;
00126 for (this->reset(); this->next();)
00127 {
00128
00129 float xi = float(this->X())+.5, yi = float(this->Y())+.5;
00130
00131 float c = orientation.x(), s = orientation.y();
00132 float w = (xi*c + yi*s);
00133
00134 if (w<fmin) fmin = w;
00135 if (w>fmax) fmax = w;
00136 }
00137 }
00138
00139 bool vtol_intensity_face::TaggedTransform(CoolTransform const& t)
00140 {
00141 if (this->GetId())
00142 return true;
00143
00144 if (!vtol_face_2d::TaggedTransform(t))
00145 return false;
00146
00147 return vdgl_digital_region::Transform(t);
00148 }
00149
00150
00151
00152
00153 Histogram_ref vtol_intensity_face::GetAdjacentRegionHistogram()
00154 {
00155
00156 float mini=this->get_min(), maxi=this->get_max();
00157 vcl_vector<vtol_face_2d*> adj_faces;
00158 this->GetAdjacentFaces(adj_faces);
00159
00160 iface_list afs;
00161 for (vcl_vector<vtol_face_2d*>::iterator fit = adj_faces.begin();
00162 fit != adj_faces.end(); fit++)
00163 {
00164 vtol_intensity_face_sptr af= (*fit)->cast_to_intensity_face();
00165 if (!af)
00166 continue;
00167 afs.push_back(af);
00168 if (af->get_min() < mini) mini = af->get_min();
00169 if (af->get_max() > maxi) maxi = af->get_max();
00170 }
00171
00172 Histogram_ref ha = new Histogram(100, mini, maxi);
00173 for (iface_iterator ifit = afs.begin(); ifit != afs.end(); ifit++)
00174 for ((*ifit)->reset(); (*ifit)->next();)
00175 ha->UpCount((*ifit)->I());
00176
00177 return ha;
00178 }
00179
00180
00181
00182
00183 float vtol_intensity_face::GetAdjacentRegionMean()
00184 {
00185
00186 vcl_vector<vtol_face_2d*> adj_faces;
00187 this->adjacent_faces(adj_faces);
00188
00189 float area =0;
00190 float mean = 0;
00191 for (vcl_vector<vtol_face_2d*>::iterator fit = adj_faces.begin();
00192 fit != adj_faces.end(); fit++)
00193 {
00194 vtol_intensity_face_sptr af= (*fit)->cast_to_intensity_face();
00195 if (!af)
00196 continue;
00197 float n = af->Npix();
00198 area += n;
00199 mean += n*af->Io();
00200 }
00201 if (!area)
00202 return 0;
00203 mean/=area;
00204 return mean;
00205 }
00206 #endif // 0