00001 /**************************************************************************** 00002 ** ui.h extension file, included from the uic-generated form implementation. 00003 ** 00004 ** If you want to add, delete, or rename functions or slots, use 00005 ** Qt Designer to update this file, preserving your code. 00006 ** 00007 ** You should not define a constructor or destructor in this file. 00008 ** Instead, write your code in functions called init() and destroy(). 00009 ** These will automatically be called by the form's constructor and 00010 ** destructor. 00011 *****************************************************************************/ 00012 #include "Util/StringConversions.H" 00013 #include "Image/DrawOps.H" 00014 #include "Image/ColorOps.H" 00015 #include "Ice/RobotBrainObjects.ice.H" 00016 #include "Raster/Raster.H" 00017 00018 #include <string.h> 00019 #include <qevent.h> 00020 #include <iostream> 00021 #include <fstream> 00022 #include <string> 00023 00024 #define H2SV_TYPE PixH2SV2 00025 00026 void SeaBee3MainDisplayForm::pushFwdRectangle( ImageIceMod::QuadrilateralIce quad) 00027 { 00028 itsDataMutex.lock(); 00029 itsFwdRectangles.push_back(quad); 00030 itsDataMutex.unlock(); 00031 } 00032 00033 void SeaBee3MainDisplayForm::setSensorVotes( std::vector<ImageIceMod::SensorVote> votes ) 00034 { 00035 itsDataMutex.lock(); 00036 itsSensorVotes = votes; 00037 itsDataMutex.unlock(); 00038 } 00039 00040 void SeaBee3MainDisplayForm::setCompositeHeading( int heading ) 00041 { 00042 itsDataMutex.lock(); 00043 itsCompositeHeading = heading; 00044 itsDataMutex.unlock(); 00045 } 00046 00047 00048 void SeaBee3MainDisplayForm::setCompositeDepth( int depth ) 00049 { 00050 itsDataMutex.lock(); 00051 itsCompositeDepth = depth; 00052 itsDataMutex.unlock(); 00053 } 00054 00055 void SeaBee3MainDisplayForm::pushRectRatio(float r) 00056 { 00057 itsDataMutex.lock(); 00058 itsRectRatios.push_back(r); 00059 itsDataMutex.unlock(); 00060 } 00061 00062 void SeaBee3MainDisplayForm::pushRectAngle(float a) 00063 { 00064 itsDataMutex.lock(); 00065 itsRectAngles.push_back(a); 00066 itsDataMutex.unlock(); 00067 } 00068 00069 void SeaBee3MainDisplayForm::pushContourPoint(Point2D<int> p) 00070 { 00071 itsDataMutex.lock(); 00072 itsRectangles.push_back(p); 00073 itsDataMutex.unlock(); 00074 } 00075 00076 void SeaBee3MainDisplayForm::setSalientPoint(Point2D<float> p) 00077 { 00078 itsDataMutex.lock(); 00079 itsSalientPoint = p; 00080 itsDataMutex.unlock(); 00081 } 00082 00083 Image<PixRGB<byte> > SeaBee3MainDisplayForm::makeCompassImage(int heading) 00084 { 00085 headingHist.push_front(heading); 00086 if(headingHist.size() > 10) 00087 headingHist.pop_back(); 00088 00089 int w =CompassCanvas->width(); 00090 int h = CompassCanvas->height(); 00091 00092 Image<PixRGB<byte> > compassImage(w,h,ZEROS); 00093 00094 drawCircle(compassImage,Point2D<int>(w/2,h/2), .9*std::min(w,h)/2, PixRGB<byte>(255,0,0)); 00095 00096 std::list<int>::reverse_iterator it = headingHist.rbegin(); 00097 float opacity=0; 00098 float opacity_step =1/float(headingHist.size()); 00099 for(;it != headingHist.rend(); ++it) 00100 { 00101 //LINFO("Opacity:%f, Step: %f", opacity, opacity_step); 00102 int x = (int)(.9*std::min(w,h)/2*cos((*it-90)*(M_PI/180))); //shift by 90 so that 0 is up 00103 int y = (int)(.9*std::min(w,h)/2*sin((*it-90)*(M_PI/180))); 00104 drawArrow(compassImage, Point2D<int>(w/2,h/2), Point2D<int>(w/2+x,h/2+y), PixRGB<byte>(0,255*opacity*.5,255*opacity*.5)); 00105 opacity+=opacity_step; 00106 } 00107 00108 int x = (int)(.9*std::min(w,h)/2*cos((*(headingHist.begin())-90)*(M_PI/180))); //shift by 90 so that 0 is up 00109 int y = (int)(.9*std::min(w,h)/2*sin((*(headingHist.begin())-90)*(M_PI/180))); 00110 drawArrow(compassImage, Point2D<int>(w/2,h/2), Point2D<int>(w/2+x,h/2+y), PixRGB<byte>(0,255,0)); 00111 00112 00113 // int dx = (int)(100.0*cos((itsDesiredHeading-90)*(M_PI/180))); //shift by 90 so that 0 is up 00114 // int dy = (int)(100.0*sin((itsDesiredHeading-90)*(M_PI/180))); 00115 // drawArrow(itsSubImage, Point2D<int>(128,128), Point2D<int>(128+dx,128+dy), PixRGB<byte>(0,0,255)); 00116 00117 return compassImage; 00118 } 00119 void SeaBee3MainDisplayForm::Image1Click( int a, int b, int c ) 00120 { 00121 LINFO("a: %d b: %d c: %d", a, b, c); 00122 00123 } 00124 00125 void SeaBee3MainDisplayForm::init( ModelManager *mgr ) 00126 { 00127 00128 initRandomNumbers(); 00129 itsMgr = mgr; 00130 00131 int minCurrent = 0; 00132 int maxCurrent = 100; 00133 currentMeter0= new SimpleMeter(ThrusterCurrentMeterCanvas0->width(), ThrusterCurrentMeterCanvas0->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00134 00135 currentMeter1= new SimpleMeter(ThrusterCurrentMeterCanvas1->width(), ThrusterCurrentMeterCanvas1->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00136 00137 currentMeter2= new SimpleMeter(ThrusterCurrentMeterCanvas2->width(), ThrusterCurrentMeterCanvas2->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00138 00139 currentMeter3= new SimpleMeter(ThrusterCurrentMeterCanvas3->width(), ThrusterCurrentMeterCanvas3->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00140 00141 currentMeter4= new SimpleMeter(ThrusterCurrentMeterCanvas4->width(), ThrusterCurrentMeterCanvas4->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00142 00143 currentMeter5= new SimpleMeter(ThrusterCurrentMeterCanvas5->width(), ThrusterCurrentMeterCanvas5->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00144 00145 currentMeter6= new SimpleMeter(ThrusterCurrentMeterCanvas6->width(), ThrusterCurrentMeterCanvas6->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00146 00147 currentMeter7= new SimpleMeter(ThrusterCurrentMeterCanvas7->width(), ThrusterCurrentMeterCanvas7->height(), minCurrent, maxCurrent, (maxCurrent-minCurrent)*.60+minCurrent, (maxCurrent-minCurrent)*.90+minCurrent); 00148 00149 Image<PixRGB<byte> > meter0Img = currentMeter0->render(0); 00150 ThrusterCurrentMeterCanvas0->setImage(meter0Img); 00151 00152 Image<PixRGB<byte> > meter1Img = currentMeter1->render(0); 00153 ThrusterCurrentMeterCanvas1->setImage(meter1Img); 00154 00155 Image<PixRGB<byte> > meter2Img = currentMeter2->render(0); 00156 ThrusterCurrentMeterCanvas2->setImage(meter2Img); 00157 00158 Image<PixRGB<byte> > meter3Img = currentMeter3->render(0); 00159 ThrusterCurrentMeterCanvas3->setImage(meter3Img); 00160 00161 Image<PixRGB<byte> > meter4Img = currentMeter4->render(0); 00162 ThrusterCurrentMeterCanvas4->setImage(meter4Img); 00163 00164 Image<PixRGB<byte> > meter5Img = currentMeter5->render(0); 00165 ThrusterCurrentMeterCanvas5->setImage(meter5Img); 00166 00167 Image<PixRGB<byte> > meter6Img = currentMeter6->render(0); 00168 ThrusterCurrentMeterCanvas6->setImage(meter6Img); 00169 00170 Image<PixRGB<byte> > meter7Img = currentMeter7->render(0); 00171 ThrusterCurrentMeterCanvas7->setImage(meter7Img); 00172 00173 itsCompositeHeading = 0; 00174 itsCurrentHeading = 0; 00175 itsCurrentDepth = 0; 00176 } 00177 00178 void SeaBee3MainDisplayForm::setImage(Image<PixRGB<byte> > &img, std::string cameraID) 00179 { 00180 if(cameraID=="FwdCamera") 00181 { 00182 ImageDisplay0->setImage(img); 00183 00184 itsDataMutex.lock(); 00185 00186 img = luminance(img); 00187 00188 // draw movement controller related images 00189 Image<PixRGB<byte> > movementImg = img; 00190 Image<PixRGB<byte> > headingImg = Image<PixRGB<byte> >(movementImg.getDims(), ZEROS); 00191 Image<PixRGB<byte> >bufferImg(img.getDims(), ZEROS); 00192 std::vector<PixRGB<byte> > sensorVoteColors; 00193 sensorVoteColors.push_back(PixRGB<byte>(255,0,0)); 00194 sensorVoteColors.push_back(PixRGB<byte>(0,255,0)); 00195 sensorVoteColors.push_back(PixRGB<byte>(0,0,255)); 00196 sensorVoteColors.push_back(PixRGB<byte>(0,0,255)); 00197 00198 uint w = movementImg.getWidth(); 00199 uint h = movementImg.getHeight(); 00200 00201 for(uint i = 0; i < itsSensorVotes.size(); i++) 00202 { 00203 ImageIceMod::SensorVote sv = itsSensorVotes[i]; 00204 00205 std::vector<Point2D<int> > pts; 00206 pts.push_back(Point2D<int>((w/2) - 20 , 0)); 00207 pts.push_back(Point2D<int>((sv.heading.val - itsCurrentHeading)+ w/2, 00208 (sv.depth.val - itsCurrentDepth)+ h/2)); 00209 pts.push_back(Point2D<int>((w/2) - 20 , h)); 00210 pts.push_back(Point2D<int>((w/2) + 20 , h)); 00211 pts.push_back(Point2D<int>((sv.heading.val - itsCurrentHeading)+ w/2, 00212 (sv.depth.val - itsCurrentDepth)+ h/2)); 00213 pts.push_back(Point2D<int>((w/2) + 20 , 0)); 00214 drawFilledPolygon(bufferImg, 00215 pts, 00216 (PixRGB<byte>)(sensorVoteColors.at(i%sensorVoteColors.size()) * 00217 (sv.heading.weight + sv.depth.weight)/2)); 00218 headingImg += bufferImg; 00219 } 00220 00221 headingImg = headingImg * 0.9; 00222 movementImg += headingImg; 00223 00224 MovementDisplay0->setImage(movementImg); 00225 movementImg = img; 00226 00227 Image<PixRGB<byte> > compHeadingImg = Image<PixRGB<byte> >(movementImg.getDims(), ZEROS); 00228 std::vector<Point2D<int> > pts; 00229 pts.push_back(Point2D<int>((w/2) - 20 , 0)); 00230 pts.push_back(Point2D<int>((itsCompositeHeading - itsCurrentHeading)+ w/2, 00231 (itsCompositeDepth - itsCurrentDepth)+ h/2)); 00232 pts.push_back(Point2D<int>((w/2) - 20 , h)); 00233 pts.push_back(Point2D<int>((w/2) + 20 , h)); 00234 pts.push_back(Point2D<int>((itsCompositeHeading - itsCurrentHeading)+ w/2, 00235 (itsCompositeDepth - itsCurrentDepth)+ h/2)); 00236 pts.push_back(Point2D<int>((w/2) + 20 , 0)); 00237 drawFilledPolygon(compHeadingImg,pts,PixRGB<byte>(0,255,0)); 00238 00239 compHeadingImg = compHeadingImg * 0.9; 00240 movementImg += compHeadingImg; 00241 00242 MovementDisplay1->setImage(movementImg); 00243 00244 // draw fwd rectangles 00245 for(uint i = 0; i < itsFwdRectangles.size(); i++) 00246 { 00247 ImageIceMod::QuadrilateralIce quad = itsFwdRectangles[i]; 00248 00249 drawLine(img,Point2D<int>(quad.tr.i,quad.tr.j), 00250 Point2D<int>(quad.br.i,quad.br.j), 00251 PixRGB<byte>(0,255,0),2); 00252 drawLine(img,Point2D<int>(quad.br.i,quad.br.j), 00253 Point2D<int>(quad.bl.i,quad.bl.j), 00254 PixRGB<byte>(0,255,0),2); 00255 drawLine(img,Point2D<int>(quad.bl.i,quad.bl.j), 00256 Point2D<int>(quad.tl.i,quad.tl.j), 00257 PixRGB<byte>(0,255,0),2); 00258 drawLine(img,Point2D<int>(quad.tl.i,quad.tl.j), 00259 Point2D<int>(quad.tr.i,quad.tr.j), 00260 PixRGB<byte>(0,255,0),2); 00261 00262 char* str = new char[20]; 00263 sprintf(str,"%d,%d",quad.center.i,quad.center.j); 00264 writeText(img,Point2D<int>(quad.center.i,quad.center.j),str); 00265 delete [] str; 00266 } 00267 00268 itsFwdRectangles.clear(); 00269 // draw salient point 00270 Point2D<int> drawSalientPoint((float)(img.getWidth())*itsSalientPoint.i,(float)(img.getHeight())*itsSalientPoint.j); 00271 drawCircle(img,drawSalientPoint,7,PixRGB<byte>(100,0,0),3); 00272 drawCross(img,drawSalientPoint,PixRGB<byte>(255,0,0),5); 00273 drawCircle(img,drawSalientPoint,7,PixRGB<byte>(255,0,0)); 00274 itsDataMutex.unlock(); 00275 00276 ImageDisplay1->setImage(img); 00277 00278 } 00279 else if(cameraID=="DwnCamera") 00280 { 00281 ImageDisplay2->setImage(img); 00282 00283 itsDataMutex.lock(); 00284 if(itsRectangles.size() > 0) 00285 { 00286 std::vector<Point2D<int> >::iterator iter; 00287 std::vector<Point2D<int> > temp; 00288 00289 for( uint i = 0; i < itsRectangles.size(); i++ ) { 00290 temp.push_back(itsRectangles[i]); 00291 00292 if((i % 4)== 3) 00293 { 00294 Point2D<int> fp = temp[0]; 00295 00296 for(uint j = 0; j < temp.size(); j++) 00297 { 00298 drawLine(img,temp[j],temp[(j + 1) % 4],PixRGB<byte>(0,255,0),3); 00299 } 00300 00301 if(itsRectRatios.size() > 0 && itsRectAngles.size() > 0) 00302 { 00303 char* str = new char[20]; 00304 sprintf(str,"%1.2f, %2.1f",itsRectRatios.front(),itsRectAngles.front()); 00305 writeText(img,fp,str); 00306 delete [] str; 00307 00308 itsRectRatios.pop_front(); 00309 itsRectAngles.pop_front(); 00310 } 00311 temp.clear(); 00312 } 00313 } 00314 00315 itsRectangles.clear(); 00316 } 00317 00318 itsDataMutex.unlock(); 00319 00320 ImageDisplay3->setImage(img); 00321 } 00322 00323 } 00324 00325 //There must be a better way to do this... --Rand 00326 void SeaBee3MainDisplayForm::ToggleCamera0() 00327 { 00328 static bool toggle = true; 00329 toggle = !toggle; 00330 ToggleCamera("Camera0", toggle); 00331 } 00332 void SeaBee3MainDisplayForm::ToggleCamera1() 00333 { 00334 static bool toggle = true; 00335 toggle = !toggle; 00336 ToggleCamera("Camera1", toggle); 00337 } 00338 void SeaBee3MainDisplayForm::ToggleCamera2() 00339 { 00340 static bool toggle = true; 00341 toggle = !toggle; 00342 ToggleCamera("Camera2", toggle); 00343 } 00344 void SeaBee3MainDisplayForm::ToggleCamera3() 00345 { 00346 static bool toggle = true; 00347 toggle = !toggle; 00348 ToggleCamera("Camera3", toggle); 00349 } 00350 00351 void SeaBee3MainDisplayForm::ToggleCamera(std::string cameraID, bool active) 00352 { 00353 LINFO("Sending Toggle Camera Message"); 00354 GUIComm->toggleCamera(cameraID,active); 00355 } 00356 00357 00358 void SeaBee3MainDisplayForm::registerCommunicator( nub::soft_ref<SeaBee3GUICommunicator> c ) 00359 { 00360 LINFO("Registering Communicator"); 00361 GUIComm = c; 00362 } 00363 00364 00365 00366 void SeaBee3MainDisplayForm::setJSAxis( int axis, float val ) 00367 { 00368 /* std::string dispTxt; 00369 char b[4]; 00370 sprintf(b,"%2.0f",val*100); 00371 dispTxt += b; 00372 00373 switch(axis) 00374 { 00375 case 0: 00376 field_js_XAxis->setText(dispTxt); 00377 break; 00378 case 1: 00379 field_js_YAxis->setText(dispTxt); 00380 break; 00381 }*/ 00382 } 00383 00384 00385 void SeaBee3MainDisplayForm::setSensorValues( int heading, int pitch, int roll, 00386 int intPressure, int extPressure, int headingValue, 00387 int depthValue ) 00388 { 00389 00390 Image<PixRGB<byte> > compassImage = makeCompassImage(heading); 00391 CompassCanvas->setImage(compassImage); 00392 00393 /*intPressHist.push_back(intPressure); 00394 if(intPressHist.size() > 40) intPressHist.pop_front(); 00395 std::vector<float> intPressVec(intPressHist.begin(), intPressHist.end()); 00396 00397 int imin=0; 00398 int imax=0; 00399 if(IntPressAuto->isChecked()) 00400 { 00401 imin = *(std::min_element(intPressVec.begin(), intPressVec.end())); 00402 imax = *(std::max_element(intPressVec.begin(), intPressVec.end())); 00403 IntPressMin->setValue(imin); 00404 IntPressMax->setValue(imax); 00405 } 00406 else 00407 { 00408 imin = IntPressMin->value(); 00409 imax = IntPressMax->value(); 00410 } 00411 00412 Image<PixRGB<byte> > intPressImage = linePlot(intPressVec, 00413 IPressureCanvas->width(), 00414 IPressureCanvas->height(), 00415 imin, 00416 imax); 00417 IPressureCanvas->setImage(intPressImage); 00418 00419 00420 extPressHist.push_back(extPressure); 00421 if(extPressHist.size() > 40) extPressHist.pop_front(); 00422 std::vector<float> extPressVec(extPressHist.begin(), extPressHist.end()); 00423 00424 int emin=0; 00425 int emax=0; 00426 if(ExtPressAuto->isChecked()) 00427 { 00428 emin = *(std::min_element(extPressVec.begin(), extPressVec.end())); 00429 emax = *(std::max_element(extPressVec.begin(), extPressVec.end())); 00430 ExtPressMin->setValue(emin); 00431 ExtPressMax->setValue(emax); 00432 } 00433 else 00434 { 00435 emin = ExtPressMin->value(); 00436 emax = ExtPressMax->value(); 00437 } 00438 00439 Image<PixRGB<byte> > extPressImage = linePlot(extPressVec, 00440 EPressureCanvas->width(), 00441 EPressureCanvas->height(), 00442 emin, 00443 emax 00444 ); 00445 EPressureCanvas->setImage(extPressImage);*/ 00446 00447 00448 itsCurrentHeading = heading; 00449 00450 field_heading->setText(toStr<int>(heading)); 00451 field_int_press->setText(toStr<int>(intPressure)); 00452 field_ext_press->setText(toStr<int>(extPressure)); 00453 heading_output_field->setText(toStr<int>(headingValue)); 00454 depth_output_field->setText(toStr<int>(depthValue)); 00455 } 00456 00457 00458 void SeaBee3MainDisplayForm::updateDesiredHeading( ) 00459 { 00460 QString val = desired_heading_field->text(); 00461 // check that val is a number and that it is not empty 00462 if(strspn(val,"1234567890") != strlen(val) || strlen(val) == 0) return; 00463 00464 int headingVal; 00465 convertFromString(val,headingVal); 00466 GUIComm->updatePoseSettings(1,headingVal,-1,-1); 00467 } 00468 00469 00470 00471 00472 void SeaBee3MainDisplayForm::updateDesiredDepth() 00473 { 00474 QString val = desired_depth_field->text(); 00475 // check that val is a number and that it is not empty 00476 if(strspn(val,"1234567890") != strlen(val) || strlen(val) == 0) return; 00477 00478 int depthVal; 00479 convertFromString(val,depthVal); 00480 GUIComm->updatePoseSettings(2,-1,depthVal,-1); 00481 } 00482 00483 00484 void SeaBee3MainDisplayForm::updateDesiredSpeed() 00485 { 00486 QString val = desired_speed_field->text(); 00487 // check that val is a number and that it is not empty 00488 if(strspn(val,"1234567890") != strlen(val) || strlen(val) == 0) return; 00489 00490 int speedVal; 00491 convertFromString(val,speedVal); 00492 GUIComm->updatePoseSettings(3,-1,-1,speedVal); 00493 } 00494 00495 00496 void SeaBee3MainDisplayForm::updateHeadingPID() 00497 { 00498 QString kVal = field_heading_k->text(); 00499 QString pVal = field_heading_p->text(); 00500 QString iVal = field_heading_i->text(); 00501 QString dVal = field_heading_d->text(); 00502 00503 // check that val is a number and that it is not empty 00504 if(strspn(kVal,"1234567890.") != strlen(kVal) || strlen(kVal) == 0) return; 00505 if(strspn(pVal,"1234567890.") != strlen(pVal) || strlen(pVal) == 0) return; 00506 if(strspn(iVal,"1234567890.") != strlen(iVal) || strlen(iVal) == 0) return; 00507 if(strspn(dVal,"1234567890.") != strlen(dVal) || strlen(dVal) == 0) return; 00508 00509 float k,p,i,d; 00510 convertFromString(kVal,k); 00511 convertFromString(pVal,p); 00512 convertFromString(iVal,i); 00513 convertFromString(dVal,d); 00514 GUIComm->updatePID(1,k,p,i,d); 00515 } 00516 00517 00518 void SeaBee3MainDisplayForm::updateDepthPID() 00519 { 00520 QString kVal = field_depth_k->text(); 00521 QString pVal = field_depth_p->text(); 00522 QString iVal = field_depth_i->text(); 00523 QString dVal = field_depth_d->text(); 00524 00525 // check that val is a number and that it is not empty 00526 if(strspn(kVal,"1234567890.") != strlen(kVal) || strlen(kVal) == 0) return; 00527 if(strspn(pVal,"1234567890.") != strlen(pVal) || strlen(pVal) == 0) return; 00528 if(strspn(iVal,"1234567890.") != strlen(iVal) || strlen(iVal) == 0) return; 00529 if(strspn(dVal,"1234567890.") != strlen(dVal) || strlen(dVal) == 0) return; 00530 00531 float k,p,i,d; 00532 convertFromString(kVal,k); 00533 convertFromString(pVal,p); 00534 convertFromString(iVal,i); 00535 convertFromString(dVal,d); 00536 GUIComm->updatePID(0,k,p,i,d); 00537 } 00538 00539 00540 00541 00542 void SeaBee3MainDisplayForm::manualClicked() 00543 { 00544 GUIComm->disablePID(); 00545 } 00546 00547 00548 void SeaBee3MainDisplayForm::autoClicked() 00549 { 00550 GUIComm->enablePID(); 00551 } 00552 00553 //For SeaBeeInjector Tab 00554 void SeaBee3MainDisplayForm::sendInitDone(){ 00555 GUIComm->SeaBeeInjectorMsg(1,0,0,0,0,0,0,0,0,0); 00556 } 00557 void SeaBee3MainDisplayForm::sendGateFound(){ 00558 GUIComm->SeaBeeInjectorMsg(0,1,0,0,0,0,0,0,0,0); 00559 } 00560 void SeaBee3MainDisplayForm::sendGateDone(){ 00561 GUIComm->SeaBeeInjectorMsg(0,0,1,0,0,0,0,0,0,0); 00562 } 00563 void SeaBee3MainDisplayForm::sendContourFoundFlare(){ 00564 GUIComm->SeaBeeInjectorMsg(0,0,0,1,0,0,0,0,0,0); 00565 } 00566 void SeaBee3MainDisplayForm::sendFlareDone(){ 00567 GUIComm->SeaBeeInjectorMsg(0,0,0,0,1,0,0,0,0,0); 00568 } 00569 void SeaBee3MainDisplayForm::sendContourFoundBarbwire(){ 00570 GUIComm->SeaBeeInjectorMsg(0,0,0,0,0,1,0,0,0,0); 00571 } 00572 void SeaBee3MainDisplayForm::sendBarbwireDone(){ 00573 GUIComm->SeaBeeInjectorMsg(0,0,0,0,0,0,1,0,0,0); 00574 } 00575 void SeaBee3MainDisplayForm::sendContourFoundBoxes(){ 00576 GUIComm->SeaBeeInjectorMsg(0,0,0,0,0,0,0,1,0,0); 00577 } 00578 void SeaBee3MainDisplayForm::sendBombingRunDone(){ 00579 GUIComm->SeaBeeInjectorMsg(0,0,0,0,0,0,0,0,1,0); 00580 } 00581 void SeaBee3MainDisplayForm::sendBriefcaseFound(){ 00582 GUIComm->SeaBeeInjectorMsg(0,0,0,0,0,0,0,0,0,1); 00583 } 00584 00585 00586 /* 00587 void SeaBee3MainDisplayForm::drawPipe(int x, int y){ 00588 DrawRandomCirc(); 00589 } 00590 00591 00592 00593 void SeaBee3MainDisplayForm::drawBuoy(int x, int y){ 00594 00595 } 00596 00597 00598 void SeaBee3MainDisplayForm::drawBin(int x, int y){ 00599 00600 } 00601 00602 00603 void SeaBee3MainDisplayForm::drawBarbedWire(int x, int y){ 00604 00605 } 00606 00607 00608 void SeaBee3MainDisplayForm::drawMachineGunNest(int x, int y){ 00609 00610 } 00611 00612 00613 void SeaBee3MainDisplayForm::drawOctagonSurface(int x, int y){ 00614 00615 } 00616 */ 00617 00618 void SeaBee3MainDisplayForm::addPlatform(){ 00619 ObjectList->insertItem("Platform"); 00620 MapperI::MapObject mapObject = {Point2D<float>(), Point2D<float>(), RobotSimEvents::PLATFORM}; 00621 mapObjects.push_back(mapObject); 00622 } 00623 00624 void SeaBee3MainDisplayForm::addGate(){ 00625 ObjectList->insertItem("Gate"); 00626 MapperI::MapObject mapObject = {Point2D<float>(), Point2D<float>(), RobotSimEvents::GATE}; 00627 mapObjects.push_back(mapObject); 00628 } 00629 00630 void SeaBee3MainDisplayForm::addPipe(){ 00631 ObjectList->insertItem("Pipe"); 00632 MapperI::MapObject mapObject = {Point2D<float>(), Point2D<float>(), RobotSimEvents::PIPE}; 00633 mapObjects.push_back(mapObject); 00634 } 00635 00636 void SeaBee3MainDisplayForm::addFlare(){ 00637 ObjectList->insertItem("Flare"); 00638 MapperI::MapObject mapObject = {Point2D<float>(), Point2D<float>(),RobotSimEvents::FLARE}; 00639 mapObjects.push_back(mapObject); 00640 } 00641 00642 void SeaBee3MainDisplayForm::addBin(){ 00643 ObjectList->insertItem("Bin"); 00644 MapperI::MapObject mapObject = {Point2D<float>(), Point2D<float>(), RobotSimEvents::BIN}; 00645 mapObjects.push_back(mapObject); 00646 } 00647 00648 00649 void SeaBee3MainDisplayForm::addBarbwire(){ 00650 ObjectList->insertItem("Barbwire"); 00651 MapperI::MapObject mapObject = {Point2D<float>(), Point2D<float>(), RobotSimEvents::BARBWIRE}; 00652 mapObjects.push_back(mapObject); 00653 } 00654 00655 00656 void SeaBee3MainDisplayForm::addMachineGunNest(){ 00657 ObjectList->insertItem("MachineGunNest"); 00658 MapperI::MapObject mapObject = {Point2D<float>(),Point2D<float>(), RobotSimEvents::MACHINEGUN}; 00659 mapObjects.push_back(mapObject); 00660 } 00661 00662 00663 void SeaBee3MainDisplayForm::addOctagonSurface(){ 00664 ObjectList->insertItem("OctagonSurface"); 00665 MapperI::MapObject mapObject = {Point2D<float>(),Point2D<float>(), RobotSimEvents::OCTAGON}; 00666 mapObjects.push_back(mapObject); 00667 } 00668 00669 void SeaBee3MainDisplayForm::selectObject(int index){ 00670 selectedIndex = index; 00671 MapObjectX->setText(convertToString(mapObjects[index].pos.i)); 00672 MapObjectY->setText(convertToString(mapObjects[index].pos.j)); 00673 } 00674 00675 void SeaBee3MainDisplayForm::refreshMapImage(){ 00676 00677 MapImage = Image<PixRGB<byte> >(MapCanvas->width(), MapCanvas->height(), ZEROS); 00678 PngParser *parser = NULL; 00679 for (unsigned int i=0; i<mapObjects.size(); i++){ 00680 if (mapObjects[i].type == RobotSimEvents::PLATFORM){ 00681 parser = new PngParser("platform.png"); 00682 } 00683 else if (mapObjects[i].type == RobotSimEvents::GATE){ 00684 parser = new PngParser("gate_final.png"); 00685 } 00686 else if (mapObjects[i].type == RobotSimEvents::PIPE){ 00687 parser = new PngParser("pipe_final.png"); 00688 } 00689 else if (mapObjects[i].type == RobotSimEvents::FLARE){ 00690 parser = new PngParser("flare_final.png"); 00691 } 00692 else if (mapObjects[i].type == RobotSimEvents::BIN){ 00693 parser = new PngParser("bin_horizontal.png"); 00694 } 00695 else if (mapObjects[i].type == RobotSimEvents::BARBWIRE){ 00696 parser = new PngParser("barbwire_final.png"); 00697 } 00698 else if (mapObjects[i].type == RobotSimEvents::MACHINEGUN){ 00699 parser = new PngParser("machinegun_final.png"); 00700 } 00701 else if (mapObjects[i].type == RobotSimEvents::OCTAGON){ 00702 parser = new PngParser("octagon_final.png"); 00703 } 00704 Image<PixRGB<byte> > src = parser->getFrame().asRgb(); 00705 inplacePaste(MapImage, src, Point2D<int>(mapObjects[i].pos.i, mapObjects[i].pos.j)); 00706 delete parser; 00707 } 00708 MapCanvas->setImage(MapImage); 00709 } 00710 00711 void SeaBee3MainDisplayForm::moveObject(){ 00712 int x = 0; 00713 int y = 0; 00714 convertFromString(MapObjectX->text(), x); 00715 convertFromString(MapObjectY->text(), y); 00716 if ( !(x > MapCanvas->width()-50 || x < 0 || y > MapCanvas->height()-50 || y < 0) ){ 00717 mapObjects[selectedIndex].pos = Point2D<float>(x,y); 00718 refreshMapImage(); 00719 } 00720 // Draw image to canvas 00721 // Raster/PngParser.H 00722 //PngParser parser("pipe_final.png"); 00723 // Raster/GenericFrame.H 00724 00725 /* Put a dummy image up there for now 00726 MapImage = Image<PixRGB<byte> >(MapCanvas->width(), MapCanvas->height(), ZEROS); 00727 Image<PixRGB<byte> > src = parser.getFrame().asRgb(); 00728 inplacePaste(MapImage, src, Point2D<int>(x,y)); 00729 MapCanvas->setImage(MapImage); 00730 */ 00731 } 00732 00733 void SeaBee3MainDisplayForm::deleteObject(){ 00734 mapObjects.erase(mapObjects.begin() + selectedIndex); 00735 ObjectList->removeItem(selectedIndex); 00736 refreshMapImage(); 00737 } 00738 00739 void SeaBee3MainDisplayForm::saveMap(){ 00740 ofstream ostream; 00741 string filename = MapName->text(); 00742 if (filename.length() > 0){ 00743 ostream.open(filename.c_str()); 00744 if (ostream.is_open()){ 00745 MapName->setText(""); 00746 for (unsigned int i=0; i<mapObjects.size(); i++){ 00747 ostream << mapObjects[i].type << " " << mapObjects[i].pos.i << " " << mapObjects[i].pos.j << endl; 00748 } 00749 ostream.close(); 00750 } 00751 } 00752 } 00753 00754 void SeaBee3MainDisplayForm::loadMap(){ 00755 string input; 00756 //RobotSimEvents::SeaBeeObjectType type; 00757 int x, y, z; 00758 ifstream istream; 00759 string filename = MapName->text(); 00760 if (filename.length() > 0){ 00761 istream.open(filename.c_str()); 00762 if (istream.is_open()){ 00763 MapName->setText(""); 00764 mapObjects.clear(); 00765 ObjectList->clear(); 00766 while (true){ 00767 istream >> z >> x >> y; 00768 if (istream.eof()){ 00769 break; 00770 } 00771 //cout << z << " " << x << " " << y << endl; 00772 MapperI::MapObject mapObject = {Point2D<float>(x,y),Point2D<float>(), (RobotSimEvents::SeaBeeObjectType)z}; 00773 mapObjects.push_back(mapObject); 00774 if (mapObject.type == RobotSimEvents::PLATFORM){ 00775 ObjectList->insertItem("Platform"); 00776 } 00777 else if (mapObject.type == RobotSimEvents::GATE){ 00778 ObjectList->insertItem("Gate"); 00779 } 00780 else if (mapObject.type == RobotSimEvents::PIPE){ 00781 ObjectList->insertItem("Pipe"); 00782 } 00783 else if (mapObject.type == RobotSimEvents::FLARE){ 00784 ObjectList->insertItem("Flare"); 00785 } 00786 else if (mapObject.type == RobotSimEvents::BIN){ 00787 ObjectList->insertItem("Bin"); 00788 } 00789 else if (mapObject.type == RobotSimEvents::BARBWIRE){ 00790 ObjectList->insertItem("Barbwire"); 00791 } 00792 else if (mapObject.type == RobotSimEvents::MACHINEGUN){ 00793 ObjectList->insertItem("Machinegun"); 00794 } 00795 else if (mapObject.type == RobotSimEvents::OCTAGON){ 00796 ObjectList->insertItem("Octagon"); 00797 } 00798 else{ 00799 cout << "Error: Object undefined " << mapObject.type << endl; 00800 } 00801 } 00802 refreshMapImage(); 00803 } 00804 //cout << ObjectList->count() << " " << mapObjects.size(); 00805 } 00806 } 00807 00808 00809 00810 00811 void SeaBee3MainDisplayForm::setThrusterMeters( int zero, int one, int two, int three, int four, int five, int six, int seven ) 00812 { 00813 00814 00815 Image<PixRGB<byte> > meter1Img = currentMeter1->render(abs(one)); 00816 ThrusterCurrentMeterCanvas1->setImage(meter1Img); 00817 00818 Image<PixRGB<byte> > meter2Img = currentMeter2->render(abs(two)); 00819 ThrusterCurrentMeterCanvas2->setImage(meter2Img); 00820 00821 Image<PixRGB<byte> > meter3Img = currentMeter3->render(abs(three)); 00822 ThrusterCurrentMeterCanvas3->setImage(meter3Img); 00823 00824 Image<PixRGB<byte> > meter4Img = currentMeter4->render(abs(four)); 00825 ThrusterCurrentMeterCanvas4->setImage(meter4Img); 00826 00827 Image<PixRGB<byte> > meter5Img = currentMeter5->render(abs(five)); 00828 ThrusterCurrentMeterCanvas5->setImage(meter5Img); 00829 00830 Image<PixRGB<byte> > meter6Img = currentMeter6->render(abs(six)); 00831 ThrusterCurrentMeterCanvas6->setImage(meter6Img); 00832 00833 } 00834 00835 Image<PixRGB<byte> > itsInput; 00836 Image<PixH2SV2<float> > itsConvert; 00837 00838 void SeaBee3MainDisplayForm::loadColorPickerImg( ) 00839 { 00840 std::string filename = colorFileLoadText->text(); 00841 00842 if(filename != "") 00843 { 00844 LINFO("Reading %s",filename.c_str()); 00845 itsInput = Raster::ReadRGB(filename); 00846 Image<PixRGB<float> > finput = itsInput; 00847 00848 itsConvert = static_cast<Image<PixH2SV2<float> > >(finput); 00849 00850 ColorPickerImg->setImage(itsInput); 00851 } 00852 } 00853 00854 void SeaBee3MainDisplayForm::clickColorPickerImg(int x, int y, int but) 00855 { 00856 LINFO("Clicked!"); 00857 }