triangle_mesh_viewer_display.h 3.7 KB
Newer Older
Jonathan Carter's avatar
Jonathan Carter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
/**************************************************************************/
/*  Copyright 2009 Tim Day                                                */
/*                                                                        */
/*  This file is part of Fracplanet                                       */
/*                                                                        */
/*  Fracplanet is free software: you can redistribute it and/or modify    */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation, either version 3 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/*  Fracplanet is distributed in the hope that it will be useful,         */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
/*  GNU General Public License for more details.                          */
/*                                                                        */
/*  You should have received a copy of the GNU General Public License     */
/*  along with Fracplanet.  If not, see <http://www.gnu.org/licenses/>.   */
/**************************************************************************/

/*! \file
  \brief Interface for class TriangleMeshViewerDisplay.
*/

#ifndef _triangle_mesh_viewer_display_h_
#define _triangle_mesh_viewer_display_h_

#include <deque>

#include "common.h"
#include "parameters_render.h"
#include "qtcommon.h"
#include "random.h"
#include "triangle_mesh.h"

class TriangleMeshViewer;

//! Contains the actual rendering functionality of a TriangleMeshViewer.
class TriangleMeshViewerDisplay : public QGLWidget
{
 private:

  Q_OBJECT;

 public:

  //! Constructor.
  TriangleMeshViewerDisplay(TriangleMeshViewer* parent,const QGLFormat& format,const ParametersRender* param,const std::vector<const TriangleMesh*>& m,bool verbose
);

  //! Destructor
  ~TriangleMeshViewerDisplay();

  //! Specify a minimum size
  QSize minimumSizeHint() const;

  //! Guideline size
  QSize sizeHint() const;

  //! Set the mesh being rendered.
  void set_mesh(const std::vector<const TriangleMesh*>& m);

 protected:

  //! Called to repaint GL area.
  void paintGL();

  //! Set up OpenGL.
  void initializeGL();

  //! Deal with resize.
  void resizeGL(int w,int h);
  
 public slots:
  
  //! Called to redisplay scene
  void draw_frame(const XYZ& p,const XYZ& l,const XYZ& u,float r,float t);

 private:

  //! Need to know this to update framerate text
  TriangleMeshViewer& _notify;

  //! Control logging
  const bool _verbose;

  //! The meshes being displayed.
  /*! NB NOT owned here
   */
  std::vector<const TriangleMesh*> mesh;

  //! Pointer to the rendering parameters.
  const ParametersRender* parameters;

  //! GL display list index
  /*! Zero is not a valid value according to red book, so use zero to designate unset */
  uint gl_display_list_index;

  

  //! Frame count.
  uint frame_number;
  
  //! Display area width.
  uint width;

  //! Display area height.
  uint height;

  //! Time frames for FPS measurement.
  QTime frame_time;
  
  //! Time since FPS last reported.
  QTime frame_time_reported;

  //! Queue of frame times to average.
  std::deque<uint> frame_times;

  //@{
  //! Parameter of camera position.
  XYZ camera_position;
  XYZ camera_lookat;
  XYZ camera_up;
  //@}

  //@{
  //! Parameters of object
  float object_tilt;
  float object_rotation;
  //@}

  void check_for_gl_errors(const char*) const;
  
  //! Compute background colour from render parameters and camera height
  const FloatRGBA background_colour() const;
};

#endif