Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

renderleda.C

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 //               The Motion Strategy Library (MSL)
00003 //----------------------------------------------------------------------
00004 //
00005 // Copyright (c) 1998-2000 Iowa State University and Steve LaValle.  
00006 // All Rights Reserved.
00007 // 
00008 // Permission to use, copy, and distribute this software and its 
00009 // documentation is hereby granted free of charge, provided that 
00010 // (1) it is not a component of a commercial product, and 
00011 // (2) this notice appears in all copies of the software and
00012 //     related documentation. 
00013 // 
00014 // Iowa State University and the author make no representations
00015 // about the suitability or fitness of this software for any purpose.  
00016 // It is provided "as is" without express or implied warranty.
00017 //----------------------------------------------------------------------
00018 
00019 #include <math.h>
00020 #include <stdlib.h>
00021 
00022 #include "renderleda.h"
00023 #include "defs.h"
00024 
00025 #include <LEDA/REDEFINE_NAMES.h>
00026 
00027 
00029 //
00030 // RenderLEDA Class
00031 //
00033 
00034 RenderLeda::RenderLeda(): Render()
00035 {
00036 }
00037 
00038 
00039 RenderLeda::RenderLeda(string filepath=""): Render(filepath)
00040 {
00041 }
00042 
00043 
00044 RenderLeda::RenderLeda(Scene *s, string filepath): Render(s,filepath)
00045 {
00046 }
00047 
00048 
00049 RenderLeda::~RenderLeda()
00050 {
00051 }
00052 
00053 
00054 void RenderLeda::Init() {
00055   string fname;
00056   int i;
00057   list<polygon> plist;
00058   list<Triangle> trlist;
00059 
00060   Render::Init();
00061 
00062   TransformDim = 6;
00063   FirstFrameDisplayed = false;
00064 
00065   W = new window(600,600,"Motion Strategy Library, Iowa State University, 1998-2000");
00066   // This is one makes the video conversion easier
00067   //w = new window(600,450+37+50,"Rapidly-Exploring Random Trees          Steve LaValle, Iowa State, 1999");
00068   //w->init(-16.0,117.0,-5.0);
00069 
00070   W->display();
00071   W->set_mode(xor_mode);
00072 
00073   // Read the environment
00074   Env = array<list<polygon> >(EnvList.length());
00075   i = 0;
00076   forall(fname,EnvList) {
00077     file_istream fin(FilePath + fname);
00078     if (S->GeomDim == 3) {
00079       fin >> trlist;
00080       plist = TrianglesToPolygons(trlist); // Defined in 3Dtriangle.C
00081     }
00082     else
00083       fin >> plist;
00084     Env[i] = plist;
00085     plist.clear();  
00086     i++;
00087   }
00088   
00089   DrawEnv(); // Draw the environment
00090   
00091   // Read the bodies
00092   Bodies = array<list<polygon> >(BodyList.length());
00093   i = 0;
00094   forall(fname,BodyList) {
00095     file_istream fin(FilePath + fname);
00096     if (S->GeomDim == 3) {
00097       fin >> trlist;
00098       plist = TrianglesToPolygons(trlist); // Defined in 3Dtriangle.C
00099     }
00100     else
00101       fin >> plist;
00102     Bodies[i] = plist;
00103     plist.clear();
00104     i++;
00105   }
00106 }
00107 
00108 
00109 
00110 void RenderLeda::DrawEnv(){
00111   int i;
00112   polygon p;
00113 
00114   for (i = 0; i < Env.size(); i++) {
00115     forall(p,Env[i]) {
00116       W->draw_filled_polygon(p,black);
00117     }
00118   }
00119 }
00120 
00121 
00122 
00123 void RenderLeda::DrawBodies(const vector &x)
00124 {
00125   int i;
00126   polygon p;
00127 
00128   for (i = 0; i < Bodies.size(); i++) {
00129     forall(p,Bodies[i]) {
00130       W->draw_filled_polygon(p,green);
00131     }
00132   }
00133 }
00134 
00135 
00136 
00137 void RenderLeda::ShowCurrentAnimationFrame()
00138 {
00139   polygon p,tp;
00140   list<polygon> body;
00141   int i;
00142   vector sc;
00143 
00144   if ((!FirstFrameDisplayed)||(PreviousFrame != CurrentAnimationFrame)) {
00145 
00146     // Unshow the last frame
00147     if (FirstFrameDisplayed) {
00148       sc = PreviousFrame;
00149       for (i = 0; i < S->NumBodies; i++) {
00150         forall(p,Bodies[i]) {
00151           tp = p.rotate(sc[i*TransformDim+TransformDim-1]);  // yaw
00152           tp = tp.translate(sc[i*TransformDim],sc[i*TransformDim+1]);
00153           W->draw_filled_polygon(tp,yellow);
00154           W->draw_polygon(tp,black);
00155         }
00156       }
00157     }
00158     
00159     sc = CurrentAnimationFrame;
00160     for (i = 0; i < S->NumBodies; i++) {
00161       forall(p,Bodies[i]) {
00162         tp = p.rotate(sc[i*TransformDim+TransformDim-1]);  // yaw
00163         tp = tp.translate(sc[i*TransformDim],sc[i*TransformDim+1]);
00164         W->draw_filled_polygon(tp,yellow);
00165         W->draw_polygon(tp,black);
00166       }
00167     }
00168     
00169     PreviousFrame = sc;
00170     FirstFrameDisplayed = true;
00171   }
00172 }
00173 
00174 
00175 
00176 void RenderLeda::DrawPath()
00177 {
00178   vector sc;
00179   polygon p,tp;
00180   int i;
00181 
00182   Reset();  // Reset the window
00183 
00184   forall(sc,FrameList) {
00185     //cout << "sc: " << sc << "\n";
00186     for (i = 0; i < S->NumBodies; i++) {
00187       forall(p,Bodies[i]) {
00188         tp = p.rotate(sc[i*TransformDim+TransformDim-1]);  // yaw
00189         tp = tp.translate(sc[i*TransformDim],sc[i*TransformDim+1]);
00190         W->draw_filled_polygon(tp,yellow);
00191         W->draw_polygon(tp,black);
00192       }
00193     }
00194   }
00195 }
00196 
00197 
00198 
00199 void RenderLeda::Terminate()
00200 {
00201   // Terminate processes and exit
00202 }
00203 
00204 
00205 
00206 void RenderLeda::HandleEvents()
00207 {
00208   // Handle events from render control window
00209   Render::HandleEvents();
00210 
00211   if (AnimationActive) {
00212     SetCurrentAnimationFrame();
00213     ShowCurrentAnimationFrame();
00214   }
00215 }
00216 
00217 
00218 void RenderLeda::Reset()
00219 {
00220   W->clear();
00221   DrawEnv(); // Draw the environment
00222 }
00223 
00224 
00225 #include <LEDA/UNDEFINE_NAMES.h>
00226 
00227 
00228 
00229 
00230 
Motion Strategy Library


Web page maintained by Steve LaValle
Partial support provided by NSF CAREER Award IRI-970228 (LaValle), Honda Research, and Iowa State University.
Contributors: Anna Atramentov, Peng Cheng, James Kuffner, Steve LaValle, and Libo Yang.