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

testgeom.cxx

Go to the documentation of this file.
00001 //  Simple main to test some features of the GUI interface
00002 
00003 #include <string> // make sure gets loaded first
00004 #include "gui/CompoundCommand.h"
00005 #include "gui/GUI.h"
00006 #include "gui/SimpleCommand.h"
00007 #include "gui/PrintControl.h"
00008 #include "gui/GuiMgr.h"
00009 
00010 #include "geometry/Box.h"
00011 #include "geometry/Cone.h"
00012 #include "geometry/Ray.h"
00013 
00014 #include "gui/DisplayControl.h"
00015 #include "geomrep/ConeRep.h"
00016 
00017 # include <strstream>
00018 
00019 gui::DisplayControl* g_display;
00020 
00021 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00022 class Lines : public gui::DisplayRep {
00023 public:
00024     
00025     
00026     Lines( const gui::GraphicsVector& p, const Volume& v )
00027         : m_p(p), m_v(v){
00028         using namespace gui;    
00029         // make a key update the display
00030         CompoundCommand* cmd = 
00031             new CompoundCommand(new SimpleCommand<DisplayControl>(g_display, &DisplayControl::clear));
00032         cmd->append(new SimpleCommand<DisplayControl>(g_display,&DisplayControl::update));
00033         Menu::instance()->register_key('c',cmd);
00034     }
00035     
00036     void draw_a_line(const Vector& n){
00037         Point p( m_p.x(),m_p.y(), m_p.z() );
00038         
00039         if( !m_v.inside(p) ){
00040             // starting outside
00041             setColor("green");
00042             move_to(p);
00043             double d = m_v.distanceToEnter(Ray(p, n), 100);
00044             if (d == FLT_MAX) {
00045                 // missed, apparently
00046                 d = 100;
00047                 line_to(p+d*n);
00048                 setColor("black");
00049                 return;
00050             }else {
00051                 // make a line to instersection
00052                 Point p2 = p+d*n;
00053                 line_to(p2);
00054                 p = p2;
00055             }
00056         }
00057         // starting, or now inside - move to exit surface
00058         setColor("red");
00059         move_to(p);  // if not already
00060         double d = m_v.distanceToLeave(Ray(p, n), 100);
00061         Point p2 = p+d*n;
00062         line_to(p2);
00063         p = p2;
00064         
00065         // now outside -- finish up
00066         setColor("green");
00067         move_to(p);
00068         line_to(p+100*n);
00069         setColor("black");
00070     }
00071     
00072     
00073     void update() {
00074         Vector n(0,0,1);
00075         int count = 30;
00076         double delta = 2*M_PI/count;
00077         
00078         for(int i =0; i<count; ++i, n.rotateY(delta)){
00079             draw_a_line(n);
00080         }
00081         draw_a_line(Vector(0,1,0));
00082         draw_a_line(Vector(0,-1,0));
00083         
00084     }
00085     
00086 private:
00087     const gui::GraphicsVector& m_p;
00088     const Volume& m_v;
00089 };
00090 
00091 
00092 //----------------------------------------------------------------------------
00093 //              main
00094 
00095 int main(int argc, char* argv[])
00096 {
00097     
00098     // get pointer to the GuiMgr instance 
00099     gui::GuiMgr* guiMgr=gui::GuiMgr::instance();
00100     
00101     
00102     // get the display for below
00103     gui::DisplayControl & display = guiMgr->display();
00104     g_display = & display;
00105     
00106     
00107     // create object to test
00108     //Box box(50,50,50); 
00109     Cone cone(50, 5, 10, 30, 40);
00110     
00111     const Volume& vol =  cone;
00112     
00113     display.add(new ConeRep(cone), "object to test" );
00114     display.add(new Lines(display.reference_point(), vol), "lines to object");
00115     
00116     // start the message loop
00117     guiMgr->menu().run();
00118     
00119     return 0;
00120 }
00121 //===============================================================
00122 void WARNING(const char* s){
00123     gui::GUI::instance()->inform(s);}
00124 void FATAL(const char* s){
00125     gui::GUI::instance()->inform(s);}//cerr << s << endl; exit(-1);}
00126 //===============================================================
00127 
00128 
00129 

Generated at Mon Nov 26 18:18:45 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000