OpenGlViewer.hpp

00001 // This file is part of the imaging2 class library.
00002 //
00003 // University of Innsbruck, Infmath Imaging, 2009.
00004 // http://infmath.uibk.ac.at
00005 //
00006 // All rights reserved.
00007 
00008 
00009 #ifndef GRAPHICS_OPENGLVIEWER_H
00010 #define GRAPHICS_OPENGLVIEWER_H
00011 
00012 #include <graphics/ObjectInterface.hpp>
00013 #include <graphics/DummyGraphics.hpp>
00014 
00015 #include <map>
00016 #include <set>
00017 #include <boost/shared_ptr.hpp>
00018 #include <pthread.h>
00019 
00020 
00021 namespace imaging
00022 {
00023   namespace open_gl_viewer_impl
00024   {
00025     class WriteImage;
00026     class Image;
00027   }
00028 
00032   class OpenGlViewer : public DummyGraphics
00033   {
00034     friend class open_gl_viewer_impl::WriteImage;
00035     
00036     static const float_t PI;
00037     static const int NUM_CIRCLE_POINTS = 64;
00038 
00039     pthread_mutex_t _object_mutex;
00040 
00041     size_t _redisplay;
00042     StreamStatus _current_stream_status;
00043     
00044     std::map<size_t, boost::shared_ptr<open_gl_viewer_impl::ObjectInterface> > _objects;
00045     std::set<boost::shared_ptr<open_gl_viewer_impl::ObjectInterface> > _new_objects; // objects which have not been initialized
00046     std::multimap<size_t, size_t> _group_object_map;
00047     size_t _current_object_index;
00048     bool _exit_mode;
00049     
00050     static int _argc;
00051     static char** _argv;
00052     static size_t _window_width;
00053     static size_t _window_height;
00054     static bool _glut_active;
00055     
00056     ublas::fixed_vector<float_t, 2> _x_axis_interval;
00057     ublas::fixed_vector<float_t, 2> _y_axis_interval;
00058     
00059     enum keycodes { ESC = 27, RETURN_LINUX = 13 };
00060     
00061     /* This functions assume that the objects are locked. BEGIN */
00062     /* GLUT thread only BEGIN */
00063     static void static_idle_function() { out.idle_function(); }
00064     static void static_reshape(int w, int h) { out.reshape(w, h); }
00065     static void static_display_function() { out.display_function(); }
00066     static void static_keyfunc(unsigned char key, int x, int y) { out.keyfunc(key, x, y); }
00067     
00068     void idle_function();
00069     void reshape(int w, int h);
00070     void display_function();
00071     void keyfunc(unsigned char key, int x, int y);
00072     /* GLUT thread only END */
00073     
00074     void request_redisplay();
00075     void set_viewport(int width, int height);
00076     void set_viewport(int width, int height, const ublas::fixed_vector<float_t, 2> & x_axis_interval, const ublas::fixed_vector<float_t, 2> & y_axis_interval);
00077     
00078     void add_to_stream(boost::shared_ptr<open_gl_viewer_impl::ObjectInterface> object);
00079     void add_to_group(boost::shared_ptr<open_gl_viewer_impl::ObjectInterface> object);
00080     /* This functions assume that the objects are locked. END */
00081     
00082     void lock_objects();
00083     void unlock_objects();
00084 
00085   public:
00086     static OpenGlViewer out;
00087     
00088     static void * display(void *);
00089 
00090     OpenGlViewer();
00091 
00092     virtual ~OpenGlViewer();
00093 
00094     virtual void init(int argc, char** argv,
00095                                const ublas::fixed_vector<float_t, 2> & lower_left,
00096                                const ublas::fixed_vector<float_t, 2> & upper_right,
00097                                size_t window_width = STD_WINDOW_SIZE,
00098                                size_t window_height = STD_WINDOW_SIZE);
00099                                
00100     virtual void clear();
00101                                
00102     virtual void set_coordinates(const ublas::fixed_vector<float_t, 2> & lower_left, const ublas::fixed_vector<float_t, 2> & upper_right);
00103 
00104     virtual void circle(const ublas::fixed_vector<float_t, 2> & center, float_t radius);
00105     
00106     virtual void polygon(const std::vector< ublas::fixed_vector<float_t, 2> > & vertices);
00107     
00108     virtual void fill_polygon(const std::vector< ublas::fixed_vector<float_t, 2> > & vertices);
00109     
00110     virtual void polyline(const std::vector< ublas::fixed_vector<float_t, 2> > & vertices);
00111     
00112     virtual void vertex(const ublas::fixed_vector<float_t, 2> & vertex);
00113     
00114     virtual void image(const ColorImage2d & image, const ublas::fixed_vector<float_t, 2> x_interval, const ublas::fixed_vector<float_t, 2> y_interval);
00115     
00116     virtual void spline_curve(const Bspline< ublas::fixed_vector<float_t, 2> > & spline_curve);
00117 
00118     virtual GraphicsInterface & operator<<(const StreamStatus & status);
00119     
00120     virtual GraphicsInterface & operator<<(const CommandInterface & command);
00121 
00122     virtual const StreamStatus & get_stream_status() { return _current_stream_status; }
00123 
00124     virtual void write_image(const std::string & file_name, const int image_format = IMAGE_FORMAT_DETERMINE)
00125     {
00126       write_image(file_name,
00127                   size_t(_x_axis_interval(1) - _x_axis_interval(0) + 0.5),
00128                   size_t(_y_axis_interval(1) - _y_axis_interval(0) + 0.5),
00129                   image_format);
00130     }
00131     
00132     virtual void write_image(const std::string & file_name, size_t width, size_t height,
00133                      const int image_format = IMAGE_FORMAT_DETERMINE);
00134   };
00135 }
00136 
00137 #endif
00138 

Generated on Tue Feb 10 10:01:30 2009 for imaging2 by  doxygen 1.5.5