Skip to content

Commit

Permalink
Minor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Jan 16, 2025
1 parent 8e0fb1a commit 4260bc1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
14 changes: 7 additions & 7 deletions src/asp/Core/CartographyUtils.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// __BEGIN_LICENSE__
// Copyright (c) 2009-2013, United States Government as represented by the
// Copyright (c) 2009-2025, United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration. All
// rights reserved.
//
Expand All @@ -23,24 +23,24 @@ namespace asp {
// Auto-compute a local projection. It is assumed that the datum is known.
// For Earth, use UTM or polar stereographic. For other datums, use
// local stereographic.
void setAutoProj(double lat, double lon,
void setAutoProj(double lat, double lon,
vw::cartography::GeoReference & output_georef) {

vw::cartography::Datum datum = output_georef.datum();
if (datum.name().find("WGS_1984") != std::string::npos) {

vw::cartography::Datum user_datum = output_georef.datum();
if (lat > 84)
if (lat > 84)
output_georef.set_proj4_projection_str("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs");
else if (lat < -80)
output_georef.set_proj4_projection_str("+proj=stere +lat_0=-90 +lat_ts=-70 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs");
else
else
output_georef.set_UTM(vw::cartography::getUTMZone(lat, lon));

} else {
output_georef.set_stereographic(lat, lon, 1, 0, 0);
}

return;
}

Expand Down
83 changes: 42 additions & 41 deletions src/asp/Tools/camera_footprint.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// __BEGIN_LICENSE__
// Copyright (c) 2009-2013, United States Government as represented by the
// Copyright (c) 2009-2025, United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration. All
// rights reserved.
//
Expand Down Expand Up @@ -73,7 +73,7 @@ void handle_arguments(int argc, char *argv[], Options& opt) {
("dem-file", po::value(&opt.dem_file)->default_value(""),
"Instead of using a longitude-latitude-height box, sample the surface of this DEM.");

general_options.add( vw::GdalWriteOptionsDescription(opt) );
general_options.add(vw::GdalWriteOptionsDescription(opt));

po::options_description positional("");
positional.add_options()
Expand All @@ -92,36 +92,35 @@ void handle_arguments(int argc, char *argv[], Options& opt) {
positional, positional_desc, usage,
allow_unregistered, unregistered);

if ( opt.image_file.empty() )
vw_throw( ArgumentErr() << "Missing input image.\n" << usage << general_options );
if (opt.image_file.empty())
vw_throw(ArgumentErr() << "Missing input image.\n" << usage << general_options);

if (boost::iends_with(opt.image_file, ".cub") && opt.stereo_session == "" )
if (boost::iends_with(opt.image_file, ".cub") && opt.stereo_session == "")
opt.stereo_session = "isis";

// Need this to be able to load adjusted camera models. That will happen
// in the stereo session.
asp::stereo_settings().bundle_adjust_prefix = opt.bundle_adjust_prefix;


// Must specify the DEM or the datum somehow
if (opt.dem_file.empty() && opt.datum_str.empty() && opt.target_srs_string.empty())
vw_throw( ArgumentErr() << "Need to provide a DEM, a datum, or a t_srs string.\n" << usage << general_options );

vw_throw(ArgumentErr() << "Need to provide a DEM, a datum, or a t_srs string.\n" << usage << general_options);

//// Convert from width and height to min and max
//if (!opt.image_crop_box.empty()) {
// BBox2 b = opt.image_crop_box; // make a copy
// opt.image_crop_box = BBox2i(b.min().x(), b.min().y(), b.max().x(), b.max().y());
//}

// This is a bug fix. The user by mistake passed in an empty projection string.
if (!vm["t_srs"].defaulted() && opt.target_srs_string.empty())
vw_throw(ArgumentErr()
vw_throw(ArgumentErr()
<< "The value of --t_srs is empty. Then it must not be set at all.\n");

}

int main( int argc, char *argv[] ) {
int main(int argc, char *argv[]) {

Options opt;
try {
Expand All @@ -135,30 +134,30 @@ int main( int argc, char *argv[] ) {
opt.camera_file, opt.camera_file,
"",
"",
false) ); // Do not allow promotion from normal to map projected session
false)); // Do not allow promotion from normal to map projected session

if (opt.camera_file.empty())
vw_throw(ArgumentErr() << "Missing input camera.\n");

if ( opt.camera_file.empty() )
vw_throw( ArgumentErr() << "Missing input camera.\n" );


boost::shared_ptr<CameraModel> cam = session->camera_model(opt.image_file, opt.camera_file);

// The input nodata value
float input_nodata_value = -std::numeric_limits<float>::max();
float input_nodata_value = -std::numeric_limits<float>::max();
vw::read_nodata_val(opt.image_file, input_nodata_value);

// Just get the image size
vw::Vector2i image_size = vw::file_image_size(opt.image_file);

// // The bounding box -> Add this feature in the future!
// BBox2 image_box = bounding_box(input_img);
// if (!opt.image_crop_box.empty())
// if (!opt.image_crop_box.empty())
// image_box.crop(opt.image_crop_box);

// Perform the computation

GeoReference target_georef;

BBox2 footprint_bbox;
float mean_gsd=0;
std::vector<Vector3> coords;
Expand All @@ -178,32 +177,34 @@ int main( int argc, char *argv[] ) {
Vector3 proj_coord(coords2[i][0], coords2[i][1], 0.0);
coords.push_back(target_georef.point_to_geodetic(proj_coord));
}

} else { // DEM provided, intersect with it.

// Load the DEM
float dem_nodata_val = -std::numeric_limits<float>::max();
float dem_nodata_val = -std::numeric_limits<float>::max();
vw::read_nodata_val(opt.dem_file, dem_nodata_val);
ImageViewRef< PixelMask<double> > dem = create_mask
(channel_cast<double>(DiskImageView<float>(opt.dem_file)), dem_nodata_val);
ImageViewRef<PixelMask<float>> dem
= create_mask(DiskImageView<float>(opt.dem_file), dem_nodata_val);

GeoReference dem_georef;
if (!read_georeference(dem_georef, opt.dem_file))
vw_throw( ArgumentErr() << "Missing georef.\n");
vw_throw(ArgumentErr() << "Missing georef.\n");

target_georef = dem_georef; // return box in this projection
vw_out() << "Using georef: " << target_georef << std::endl;

footprint_bbox = camera_bbox(dem, dem_georef, target_georef, cam,
image_size[0], image_size[1], mean_gsd, opt.quick, &coords);

footprint_bbox = camera_bbox(dem, dem_georef,
target_georef, cam,
image_size[0], image_size[1],
mean_gsd, opt.quick, &coords);
for (size_t i=0; i<coords.size(); ++i)
coords[i] = target_georef.datum().cartesian_to_geodetic(coords[i]);
}
// Print out the results

// Print out the results
vw_out() << "Computed footprint bounding box:\n" << footprint_bbox << std::endl;
vw_out() << "Computed mean gsd: " << mean_gsd << std::endl;

if (opt.output_kml == "")
return 0;

Expand All @@ -214,18 +215,18 @@ int main( int argc, char *argv[] ) {

// Placemark Style
const bool HIDE_LABELS = true;
kml.append_style( "dot", "", 1.2,
"http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png",
kml.append_style("dot", "", 1.2,
"http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png",
HIDE_LABELS);
kml.append_style( "dot_highlight", "", 1.4,
kml.append_style("dot_highlight", "", 1.4,
"http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png");
kml.append_stylemap( "placemark", "dot",
"dot_highlight" );
kml.append_stylemap("placemark", "dot",
"dot_highlight");

kml.append_line(coords, "intersections", "placemark");
vw_out() << "Writing: " << opt.output_kml << std::endl;
vw_out() << "Writing: " << opt.output_kml << std::endl;
kml.close_kml();

} ASP_STANDARD_CATCHES;

return 0;
Expand Down
10 changes: 3 additions & 7 deletions src/asp/Tools/mapproject_single.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,11 @@ Vector2 demPixToCamPix(Vector2i const& dem_pixel,
ImageViewRef<DemPixelT> const& dem,
GeoReference const &dem_georef) {
Vector2 lonlat = dem_georef.point_to_lonlat(dem_georef.pixel_to_point(dem_pixel));
//vw_out() << "lonlat = " << lonlat << "\n";
DemPixelT height = dem(dem_pixel[0], dem_pixel[1]);
Vector3 xyz = dem_georef.datum().geodetic_to_cartesian
(Vector3(lonlat[0], lonlat[1], height.child()));
//vw_out() << "xyz = " << xyz << "\n";
// Throws if the projection fails ???
Vector2i camera_pixel = camera_model->point_to_pixel(xyz);
//vw_out() << "camera_pixel = " << camera_pixel << "\n";
return camera_pixel;
}

Expand All @@ -200,7 +197,7 @@ void expandBboxToContainCornerIntersections(vw::CamPtr camera_model,
dem_pixel_list[2] = Vector2(dem.cols()-1, dem.rows()-1);
dem_pixel_list[3] = Vector2(0, dem.rows()-1);

for (int i=0; i<4; ++i) {
for (int i=0; i<4; i++) {
try{
// Project the DEM corner into the input image
Vector2 dem_pixel = dem_pixel_list[i];
Expand All @@ -210,10 +207,9 @@ void expandBboxToContainCornerIntersections(vw::CamPtr camera_model,
Vector2 groundLoc = dem_georef.pixel_to_point(dem_pixel);

// If there was in intersection
if ((cam_pixel.x() >= 0) && (cam_pixel.y() > 0) &&
(cam_pixel.x() < image_size.x()) && (cam_pixel.y() < image_size.y())) {
if (cam_pixel.x() >= 0 && cam_pixel.y() > 0 &&
cam_pixel.x() < image_size.x() && cam_pixel.y() < image_size.y()) {
bbox_on_ground.grow(groundLoc);
} else {
}
} catch(...) {} // projection failed
} // End loop through DEM points
Expand Down

0 comments on commit 4260bc1

Please sign in to comment.