|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include "ProcessByLine.h" 00003 #include "SpecialPixel.h" 00004 #include "iException.h" 00005 00006 using namespace std; 00007 using namespace Isis; 00008 00009 void circle (Buffer &in, Buffer &out); 00010 double cline,csamp,radius; // Global variables 00011 00012 void IsisMain() { 00013 // We will be processing by line 00014 ProcessByLine p; 00015 00016 // Setup the input and output cubes 00017 p.SetInputCube("FROM"); 00018 p.SetOutputCube ("TO"); 00019 00020 // Get the three points along the edge of the circle 00021 UserInterface &ui = Application::GetUserInterface(); 00022 double y1 = ui.GetDouble ("LINE1"); 00023 double y2 = ui.GetDouble ("LINE2"); 00024 double y3 = ui.GetDouble ("LINE3"); 00025 double x1 = ui.GetDouble ("SAMP1"); 00026 double x2 = ui.GetDouble ("SAMP2"); 00027 double x3 = ui.GetDouble ("SAMP3"); 00028 00029 // Compute the center line/samp and radius of the circle 00030 double x21 = x2 - x1; 00031 double y21 = y2 - y1; 00032 double x31 = x3 - x1; 00033 double y31 = y3 - y1; 00034 double den = 2.0 * (x21*y31 - x31*y21); 00035 if (den == 0.0) { 00036 string message = "The three points lie on a line so a circle can not be computed"; 00037 throw iException::Message(iException::User,message,_FILEINFO_); 00038 } 00039 00040 double sq2 = x21*x21 + y21*y21; 00041 double sq3 = x31*x31 + y31*y31; 00042 csamp = (sq2*y31 - sq3*y21) / den; 00043 cline = (sq3*x21 - sq2*x31) / den; 00044 00045 radius = sqrt(csamp*csamp + cline*cline); 00046 csamp += x1; 00047 cline += y1; 00048 00049 // Start the processing 00050 p.StartProcess(circle); 00051 p.EndProcess(); 00052 } 00053 00054 // Line processing routine 00055 void circle (Buffer &in, Buffer &out) { 00056 // Compute part of the distance (doesn't vary since the line is constant) 00057 double dist, partA, partB; 00058 partA = cline - (double) in.Line(); 00059 partA *= partA; 00060 00061 // Loop for each pixel in the line. 00062 for (int i=0; i<in.size(); i++) { 00063 // Compute the rest of the distance 00064 partB = csamp - (double) in.Sample(i); 00065 partB *= partB; 00066 dist = partA + partB; 00067 if (dist < 0.0) dist = 0.0; // Shouldn't happen 00068 dist = sqrt(dist); 00069 00070 // Mask everything outside the radius and keep what is inside 00071 if (dist <= radius) { 00072 out[i] = in[i]; 00073 } 00074 else { 00075 out[i] = NULL8; 00076 } 00077 } 00078 }