USGS

Isis 3.0 Application Source Code Reference

Home

circle.cpp

Go to the documentation of this file.
00001 #include "Isis.h"
00002 #include "ProcessByLine.h"
00003 #include "SpecialPixel.h"
00004 
00005 using namespace std; 
00006 using namespace Isis;
00007 
00008 void circle (Buffer &in, Buffer &out);
00009 double cline,csamp,radius;  // Global variables
00010 
00011 void IsisMain() {
00012   // We will be processing by line
00013   ProcessByLine p;
00014 
00015   // Setup the input and output cubes
00016   Cube *icube = p.SetInputCube("FROM");
00017   p.SetOutputCube ("TO");
00018   
00019   // Compute the defaults for user parameters
00020   cline = icube->Lines() / 2;
00021   csamp = icube->Samples() / 2;
00022   radius = (cline < csamp) ? cline : csamp;
00023 
00024   // Override the defaults if the user entered a value
00025   UserInterface &ui = Application::GetUserInterface();
00026   if (ui.WasEntered ("LINE")) cline = ui.GetDouble ("LINE");
00027   if (ui.WasEntered ("SAMPLE")) csamp = ui.GetDouble ("SAMPLE");
00028   if (ui.WasEntered ("RADIUS")) radius = ui.GetDouble ("RADIUS");
00029 
00030   // Start the processing
00031   p.StartProcess(circle);
00032   p.EndProcess();
00033 }
00034 
00035 // Line processing routine
00036 void circle (Buffer &in, Buffer &out) {
00037   // Compute part of the distance (doesn't vary since the line is constant)
00038   double dist, partA, partB;
00039   partA = cline - (double) in.Line();
00040   partA *= partA; 
00041 
00042   // Loop for each pixel in the line. 
00043   for (int i=0; i<in.size(); i++) {
00044     // Compute the rest of the distance
00045     partB = csamp - (double) in.Sample(i);
00046     partB *= partB;
00047     dist = partA + partB;
00048     if (dist < 0.0) dist = 0.0; // Shouldn't happen
00049     dist = sqrt(dist);
00050 
00051     // Mask everything outside the radius and keep what is inside
00052     if (dist <= radius) {
00053       out[i] = in[i];
00054     }
00055     else {
00056       out[i] = NULL8;
00057     }
00058   }
00059 }