[4dd432]: contrib / brl / bseg / bvxm / pro / processes / bvxm_create_ortho_camera_process.cxx  Maximize  Restore  History

Download this file

114 lines (98 with data), 4.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// This is brl/bseg/bvxm/pro/processes/bvxm_create_ortho_camera_process.cxx
#include "bvxm_create_ortho_camera_process.h"
//:
// \file
#include <bprb/bprb_func_process.h>
#include <bvxm/bvxm_voxel_world.h>
#include <bvxm/bvxm_image_metadata.h>
#include <bvxm/bvxm_edge_ray_processor.h>
#include <brip/brip_vil_float_ops.h>
#include <vil/vil_image_view.h>
#include <vpgl/vpgl_utm.h>
bool bvxm_create_ortho_camera_process_cons(bprb_func_process& pro)
{
using namespace bvxm_create_ortho_camera_process_globals;
vcl_vector<vcl_string> input_types_(n_inputs_);
input_types_[0] = "bvxm_voxel_world_sptr";
input_types_[1] = "bool";
if (!pro.set_input_types(input_types_))
return false;
vcl_vector<vcl_string> output_types_(n_outputs_);
output_types_[0] = "vpgl_camera_double_sptr"; // return the ortho camera of the scene, as it may be needed for other processes
return pro.set_output_types(output_types_);
}
// generates an ortho camera from the scene bounding box, GSD of the image is 1 meter
bool bvxm_create_ortho_camera_process(bprb_func_process& pro)
{
using namespace bvxm_create_ortho_camera_process_globals;
if (pro.n_inputs()<n_inputs_)
{
vcl_cout << pro.name() << " The input number should be " << n_inputs_<< vcl_endl;
return false;
}
//voxel_world
bvxm_voxel_world_sptr world = pro.get_input<bvxm_voxel_world_sptr>(0);
if (!world) {
vcl_cout << pro.name() <<" :-- Input 0 is not valid!\n";
return false;
}
bool is_utm = pro.get_input<bool>(1);
// generate vpgl_geo_camera for the scene
bvxm_world_params_sptr params = world->get_params();
vgl_box_3d<double> box = params->world_box_local();
vgl_point_3d<float> corner = params->corner();
vgl_point_3d<float> upper_left(corner.x(), (float)(corner.y() + box.height()), corner.z());
vgl_point_3d<float> lower_right((float)(corner.x()+box.width()), corner.y(), corner.z());
float voxel_length = params->voxel_length();
vpgl_lvcs_sptr lvcs = params->lvcs();
double lat, lon, elev;
lvcs->get_origin(lat, lon, elev);
vcl_cout << " lvcs origin: " << lat << " " << lon << " " << elev << vcl_endl;
// determine the upper left corner to use a vpgl_geo_cam, WARNING: assumes that the world is compass-alinged
double upper_left_lon, upper_left_lat, upper_left_elev;
lvcs->local_to_global(upper_left.x(), upper_left.y(), upper_left.z(), vpgl_lvcs::wgs84, upper_left_lon, upper_left_lat, upper_left_elev);
vcl_cout << "upper left corner in the image is: " << upper_left_lon << " lat: " << upper_left_lat << vcl_endl;
double lower_right_lon, lower_right_lat, lower_right_elev;
lvcs->local_to_global(lower_right.x(), lower_right.y(), lower_right.z(), vpgl_lvcs::wgs84, lower_right_lon, lower_right_lat, lower_right_elev);
vcl_cout << "lower right corner in the image is: " << lower_right_lon << " lat: " << lower_right_lat << vcl_endl;
vnl_matrix<double> trans_matrix(4,4,0.0);
if (is_utm) {
double scale_x = voxel_length;
double scale_y = -1*voxel_length;
// transfer upper left corner to utm system
vpgl_utm utm;
double upper_left_x, upper_left_y;
int utm_zone;
utm.transform(upper_left_lat, upper_left_lon, upper_left_x, upper_left_y, utm_zone);
vcl_cout << "upper left in utm = " << upper_left_x << " x " << upper_left_y << vcl_endl;
vcl_cout << "scale_x = " << scale_x << " scale_y = " << scale_y << vcl_endl;
trans_matrix[0][0] = scale_x;
trans_matrix[1][1] = scale_y;
trans_matrix[0][3] = upper_left_x;
trans_matrix[1][3] = upper_left_y;
vpgl_geo_camera* cam = new vpgl_geo_camera(trans_matrix, lvcs);
unsigned northing = 0;
if (upper_left_lat < 0 && lower_right_lat < 0)
northing = 1;
if (upper_left_lat*lower_right_lat < 0)
vcl_cout << "warning: scene world crosses the Equator" << vcl_endl;
cam->set_utm(utm_zone,northing);
cam->set_scale_format(true);
vpgl_camera_double_sptr camera = new vpgl_geo_camera(*cam);
pro.set_output_val<vpgl_camera_double_sptr>(0, camera);
return true;
}
else {
int ni = box.width();
int nj = box.height();
//trans_matrix[0][0] = (lower_right_lon-lon)/ni; trans_matrix[1][1] = -(upper_left_lat-lat)/nj;
// lvcs origin is not necessarily one of the corners of the scene
trans_matrix[0][0] = (lower_right_lon-upper_left_lon)/ni; trans_matrix[1][1] = -(upper_left_lat-lower_right_lat)/nj;
trans_matrix[0][3] = upper_left_lon; trans_matrix[1][3] = upper_left_lat;
vpgl_geo_camera* cam = new vpgl_geo_camera(trans_matrix, lvcs);
cam->set_scale_format(true);
vpgl_camera_double_sptr camera = new vpgl_geo_camera(*cam);
pro.set_output_val<vpgl_camera_double_sptr>(0, camera);
return true;
}
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks