contrib/mul/vimt/vimt_load.cxx
Go to the documentation of this file.
00001 // This is mul/vimt/vimt_load.cxx
00002 
00003 //:
00004 // \file
00005 // \author Martin Roberts
00006 
00007 #include "vimt_load.h"
00008 #include <vil/vil_property.h>
00009 
00010 // Create a transform from the properties of image resource.
00011 // NB unit scaling is to convert from metres to desired world unts (e.g. 1000.0 for mm)
00012 vimt_transform_2d vimt_load_transform(const vil_image_resource_sptr& im,
00013                                       float unit_scaling)
00014 {
00015   float pixSize[2] = { 1.0f, 1.0f };
00016   bool valid_pixSize = im->get_property(vil_property_pixel_size, pixSize);
00017 
00018   float offset[2] = { 0.0f, 0.0f};
00019   bool valid_offset = im->get_property(vil_property_offset, offset);
00020   if (!valid_offset)
00021   {
00022     offset[0]=offset[1]=0.0f;
00023   }
00024 
00025   for(unsigned i=0; i<2;i++)
00026   {
00027     pixSize[i]*= unit_scaling;
00028   }
00029 
00030   vimt_transform_2d tx;
00031   if (valid_pixSize)
00032   {
00033     tx.set_zoom_only(1.0/pixSize[0], 1.0/pixSize[1],
00034                      offset[0], offset[1]); //NB offsets will be zero if offset prop invalid
00035   }
00036   else if( valid_offset)
00037   {
00038     tx.set_translation(offset[0], offset[1]);
00039   }
00040   else
00041   {
00042     //Both invalid
00043     tx.set_identity();
00044   }
00045 
00046   return tx;
00047 }
00048 
00049 // Create a transform from the properties of image resource, assuming a right-hand world frame.
00050 // NB unit scaling is to convert from metres to desired world unts (e.g. 1000.0 for mm)
00051 // This version incorporates a reflection through the x-axis so that 
00052 // the transform is put into a right-handed coordinate frame 
00053 // (with y increasing from bottom to top of image).
00054 vimt_transform_2d vimt_load_transform_right_hand(const vil_image_resource_sptr& im,
00055                                                  float unit_scaling)
00056 {
00057   float pixSize[2] = { 1.0f, 1.0f };
00058   bool valid_pixSize = im->get_property(vil_property_pixel_size, pixSize);
00059   if (!valid_pixSize)
00060   {
00061     pixSize[0] = 1.0f;
00062     pixSize[1] = 1.0f;
00063   }
00064 
00065   float offset[2] = { 0.0f, 0.0f};
00066   bool valid_offset = im->get_property(vil_property_offset, offset);
00067   if (!valid_offset)
00068   {
00069     offset[0] = offset[1] = 0.0f;
00070   }
00071 
00072   for(unsigned i=0; i<2; i++)
00073   {
00074     pixSize[i] *= unit_scaling;
00075   }
00076 
00077   // Include a reflection through the x-axis.
00078   vimt_transform_2d tx;
00079   tx.set_zoom_only(1.0/pixSize[0], -1.0/pixSize[1],
00080                    offset[0], -offset[1]);
00081 
00082   return tx;
00083 }
00084