Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vimt_image_2d.cxx

Go to the documentation of this file.
00001 //:
00002 //  \file
00003 //  \brief A base class for arbitrary 2D images+transform
00004 //  \author Tim Cootes
00005 
00006 #include "vimt_image_2d.h"
00007 
00008 //: Return vector indicating size of image in pixels
00009 //  2D image is v[0] x v[1],  3D image is v[0] x v[1] x v[2]
00010 //  Somewhat inefficient: Only use when you have to
00011 vcl_vector<unsigned> vimt_image_2d::image_size() const
00012 {
00013   vcl_vector<unsigned> d(2);
00014   d[0]=image_base().ni();
00015   d[1]=image_base().nj();
00016   return d;
00017 }
00018 
00019 //: Return vectors defining bounding box containing image in world co-ords
00020 void vimt_image_2d::world_bounds(vcl_vector<double>& b_lo,
00021                                  vcl_vector<double>& b_hi) const
00022 {
00023   b_lo.resize(2); b_hi.resize(2);
00024   vgl_point_2d<double> p = world2im_.inverse()(0,0);
00025   b_lo[0]=p.x(); b_hi[0]=p.x();
00026   b_lo[1]=p.y(); b_hi[1]=p.y();
00027 
00028   // Compute each corner
00029   for (int i=0;i<2;++i)
00030     for (int j=0;j<2;++j)
00031     {
00032       p = world2im_.inverse()(i*(image_base().ni()-1),j*(image_base().nj()-1));
00033       if (p.x()<b_lo[0]) b_lo[0]=p.x();
00034       else if (p.x()>b_hi[0]) b_hi[0]=p.x();
00035       if (p.y()<b_lo[1]) b_lo[1]=p.y();
00036       else if (p.y()>b_hi[1]) b_hi[1]=p.y();
00037     }
00038 }
00039 
00040 
00041 // Related Functions
00042 
00043 // Return bounding box containing image in world co-ords as a box
00044 vgl_box_2d<double> world_bounding_box(const vimt_image_2d& img) 
00045 {
00046   vcl_vector<double> b_lo(2,0.0);
00047   vcl_vector<double> b_hi(2,0.0);
00048   img.world_bounds(b_lo,b_hi);      
00049   return vgl_box_2d<double>(b_lo[0],b_hi[0],b_lo[1],b_hi[1]);
00050 }
00051 
00052 // Translate the image so that its centre is at the origin of the world coordinate system.
00053 void vimt_centre_image_at_origin(vimt_image_2d& image)
00054 {
00055   vgl_box_2d<double> bbox = world_bounding_box(image);
00056   vgl_point_2d<double> c = bbox.centroid();
00057   vimt_transform_2d& w2i = image.world2im();
00058   w2i.set_origin(w2i(c));
00059 }

Generated on Thu Jan 10 14:43:58 2008 for contrib/mul/vimt by  doxygen 1.4.4