TestAlg.cpp

00001 #include "TestAlg.h"
00002 #include "tcastypes.h"
00003 #include <iostream>
00004 #include <math.h>
00005 
00006 TestAlg::TestAlg()
00007 {
00008         algName = "Invert Algorithm";
00009         srand( time(NULL) );
00010 }
00011 
00012 TestAlg::~TestAlg()
00013 {
00014 }
00015 
00016 void TestAlg::processFrame(QImage *frame)
00017 {
00018         // We'll do some real simple things here.
00019         // 1)Invert the pixmap colors (our sample "image processing" technique)
00020         // 2)Generate an obstacle 5% of the time
00021         // 3)Randomly select obstacle location,type,and direction
00022         // 3)Signal that we found an obstacle to whoever is listening (perhaps the TCAS widget is connected to us?)
00023         // 4)Send a message string out to whoever is listening 
00024         
00025         QImage newImage = frame->copy();
00026         newImage.invertPixels();
00027         emit imageReady(&newImage);
00028         
00029         // Let's randomly find an obstacle and report it.
00030         // Say a 5% chance of seeing an obstacle this frame.
00031         // In reality, an algorithm must not only detect obstacles, 
00032         // but also keep track of them!  Here we are just simulating
00033         // finding new obstacles, but we're not keeping track of them. If
00034         // you run this algorithm long enough, you'll end up with a screen
00035         // full of obstacles. :-)
00036 
00037         
00038         int j = 1 + (int) (100.0 * (rand() / (RAND_MAX + 1.0)));
00039         if (j <= 5)
00040         {
00041                 // Found an obstacle, now decide what type and direction, relative alitutude
00042                 int t = 1 + (int) (100.0 * (rand() / (RAND_MAX + 1.0)));
00043                 int d = 1 + (int) (100.0 * (rand() / (RAND_MAX + 1.0)));
00044                 int a = 1 + (int) (200.0 * (rand() / (RAND_MAX + 1.0)));
00045                 a = a - 100;
00046                 threatType typ;
00047                 trendDir dir;
00048                 if (t <25 ) {typ = threatOther; emit foundOther();}
00049                 else if ( t >= 25 && t < 50) {typ = threatProximate; emit foundProximate();}
00050                 else if ( t >= 50 && t < 75) {typ = threatIntruding; emit foundIntruding();}
00051                 else {typ = threatReal; emit foundReal();}
00052                 
00053                 if (d <= 50) dir = ascending;
00054                 else dir = descending;
00055                 
00056                 // Now get random x and y positions, between 0 and 500 (width), 0 and 400 (height)
00057                 int w = 1 + (int) (500.0 * (rand() / (RAND_MAX + 1.0)));
00058                 int h = 1 + (int) (400.0 * (rand() / (RAND_MAX + 1.0)));
00059                 
00060                 // Now, generate a position-independent obstacle 
00061                 // for the pie-display.  Get a random orientation and location
00062                 // for the pie display. Notify anyone who is listening that an obstacle was "found"
00063                  
00064                 unsigned long key;
00065                 
00066                 if ( h <= 200)
00067                 {
00068                         int ang = 1 + (int) (180.0 * (rand() / (RAND_MAX + 1.0))) - 90;// ang=atan( (250-w)/(200-h));
00069                         //ang = -(ang * 180 / 3.14159);         
00070                         int orient= 1 + (int) (360.0 * (rand() / (RAND_MAX + 1.0)));
00071                         trendDir n = none; // Set it to 'none' so that the pie widget will display this, and not the TCAS widget. 
00072                         emit foundObstacle(typ,n,a,ang,orient,key);
00073                 }
00074                 
00075                 // The returned key would normally be kept so that the obstacle
00076                 // can be tracked later on by this algorithm or other user-defined classes.
00077                 // The key is needed to remove the obstacle from the widget displays
00078                 // Now we will notify anyone listening to a position-dependant 
00079                 // signal of an obstacle (TCAS)
00080         
00081                 
00082                 emit foundObstacle(typ,dir,a,w,h,key);
00083                 QString str = "Found obstacle at ";
00084                 str.append(QString::number(w));
00085                 str.append(",");
00086                 str.append(QString::number(h));
00087                 str.append(" with relative altitude of ");
00088                 str.append(QString::number(a));
00089                 emit displayMessage(&str);
00090         }       
00091 }

Generated on Thu Aug 17 12:14:56 2006 for VisualODF by  doxygen 1.4.7