USGS

Isis 3.0 Application Source Code Reference

Home

camtrim.cpp

Go to the documentation of this file.
00001 #include "Isis.h"
00002 #include "Camera.h"
00003 #include "ProcessByLine.h"
00004 #include "SpecialPixel.h"
00005 #include "ProjectionFactory.h"
00006 
00007 using namespace std; 
00008 using namespace Isis;
00009 
00010 // Global variables
00011 Cube *icube;
00012 Camera *cam;
00013 Projection *proj;
00014 double minlat; 
00015 double maxlat; 
00016 double minlon;
00017 double maxlon;
00018 int lastBand;
00019 
00020 void camtrim (Buffer &in, Buffer &out);
00021 
00022 void IsisMain() {
00023   // We will be processing by line
00024   ProcessByLine p;
00025 
00026   // Setup the input and get the camera model
00027   icube = p.SetInputCube("FROM");
00028   cam = icube->Camera();
00029 
00030   // Create the output cube
00031   p.SetOutputCube ("TO");
00032 
00033   // Get the lat/lon range to trim
00034   UserInterface &ui = Application::GetUserInterface();
00035   minlat = ui.GetDouble("MINLAT");
00036   maxlat = ui.GetDouble("MAXLAT");
00037   minlon = ui.GetDouble("MINLON");
00038   maxlon = ui.GetDouble("MAXLON");
00039   
00040   // Get map projection to determine what type of 
00041   // lat/lons the user wants
00042   if (ui.WasEntered("MAP")) {
00043     Pvl lab;
00044     lab.Read(ui.GetFilename("MAP"));
00045     proj = ProjectionFactory::Create(lab);
00046 
00047     // add mapping to print.prt
00048     PvlGroup mapping = proj->Mapping(); 
00049     Application::Log(mapping); 
00050   }
00051   else {
00052     proj = NULL;
00053   }
00054 
00055   // Start the processing
00056   lastBand = 0;
00057   p.StartProcess(camtrim);
00058   p.EndProcess();
00059 }
00060 
00061 // Line processing routine
00062 void camtrim (Buffer &in, Buffer &out) {
00063   // See if there is a change in band which would change the camera model
00064   if (in.Band() != lastBand) {
00065     lastBand = in.Band();
00066     cam->SetBand(icube->PhysicalBand(lastBand));
00067   }
00068 
00069   // Loop for each pixel in the line. 
00070   double samp,lat,lon;
00071   double line = in.Line();
00072   for (int i=0; i<in.size(); i++) {
00073     samp = in.Sample(i);
00074     cam->SetImage(samp,line);
00075     if (cam->HasSurfaceIntersection()) {
00076       lat = cam->UniversalLatitude();
00077       lon = cam->UniversalLongitude();
00078       if (proj != NULL) {
00079         proj->SetUniversalGround(lat,lon);
00080         lat = proj->Latitude();
00081         lon = proj->Longitude();
00082       }
00083       // Pixel is outside range
00084       if ((lat < minlat) || (lat > maxlat) || 
00085           (lon < minlon) || (lon > maxlon)) {
00086         out[i] = NULL8;
00087       }
00088       // Pixel inside range
00089       else {
00090         out[i] = in[i];
00091       }
00092     }
00093     // Trim outerspace
00094     else {
00095       out[i] = NULL8;
00096     }
00097   }
00098 }