contrib/mul/vimt3d/vimt3d_load.cxx
Go to the documentation of this file.
00001 // This is mul/vimt3d/vimt3d_load.cxx
00002 #include "vimt3d_load.h"
00003 //:
00004 // \file
00005 // \author Ian Scott
00006 
00007 #include <vil3d/vil3d_property.h>
00008 
00009 //: Create a transform from the properties of image resource.
00010 // The transform will be from world co-ordinates in metres to image co-ordinates (or mm if requested).
00011 vimt3d_transform_3d vimt3d_load_transform(const vil3d_image_resource_sptr &im, bool use_millimetres)
00012 {
00013   float width[3] = { 1.0f, 1.0f, 1.0f };
00014   bool valid_width = im->get_property(vil3d_property_voxel_size, width);
00015 
00016   if (use_millimetres)
00017   {
00018       width[0] *= 1000;
00019       width[1] *= 1000;
00020       width[2] *= 1000;
00021   }
00022 
00023   float offset[3] = { 0.0f, 0.0f, 0.0f };
00024   bool valid_offset = im->get_property(vil3d_property_origin_offset, offset);
00025 
00026   vimt3d_transform_3d t;
00027 
00028   if (!valid_width)
00029     if (!valid_offset)
00030     {
00031       t.set_identity();
00032       return t;
00033     }
00034     else
00035     {
00036       t.set_translation(offset[0], offset[1], offset[2]);
00037       return t;
00038     }
00039   else
00040     if (!valid_offset)
00041     {
00042       t.set_zoom_only(1.0/width[0], 1.0/width[1], 1.0/width[2], 0.0f, 0.0f, 0.0f);
00043       return t;
00044     }
00045     else
00046     {
00047       t.set_zoom_only(1.0/width[0], 1.0/width[1], 1.0/width[2],
00048         offset[0], offset[1], offset[2]);
00049       return t;
00050     }
00051 }