INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rt::Viewer Class Reference

#include <Viewer.h>

Inheritance diagram for rt::Viewer:

Public Member Functions

 Viewer ()
 Default constructor. Scene is empty.
 
void setScene (rt::Scene &aScene)
 Sets the scene.
 
void drawSomeLight (GLenum light) const
 To call the protected method drawLight.
 
void drawSomeLight (GLenum light, float zoom) const
 To call the protected method drawLight.
 

Protected Member Functions

virtual void draw ()
 Called at each draw of the window.
 
virtual void init ()
 Called before the first draw.
 
virtual QString helpString () const
 Called when pressing help.
 
virtual void keyPressEvent (QKeyEvent *e)
 Celled when pressing a key.
 

Protected Attributes

rt::SceneptrScene
 Stores the scene.
 
int maxDepth
 Maximum depth.
 

Detailed Description

This class displays the interface for placing the camera and the lights, and the user may call the renderer from it.

Definition at line 20 of file Viewer.h.

Constructor & Destructor Documentation

◆ Viewer()

rt::Viewer::Viewer ( )
inline

Default constructor. Scene is empty.

Definition at line 24 of file Viewer.h.

24: QGLViewer(), ptrScene( 0 ), maxDepth( 6 ) {}
int maxDepth
Maximum depth.
Definition Viewer.h:57
rt::Scene * ptrScene
Stores the scene.
Definition Viewer.h:54

Member Function Documentation

◆ draw()

void Viewer::draw ( )
protectedvirtual

Called at each draw of the window.

Definition at line 16 of file Viewer.cpp.

17{
18 // Set up lights
19 if ( ptrScene != 0 )
20 ptrScene->light( *this );
21 // Draw all objects
22 if ( ptrScene != 0 )
23 ptrScene->draw( *this );
24}
void light(Viewer &viewer)
This function calls the light method of each of its lights.
Definition Scene.h:62
void draw(Viewer &viewer)
This function calls the draw method of each of its objects.
Definition Scene.h:54

◆ drawSomeLight() [1/2]

void rt::Viewer::drawSomeLight ( GLenum  light) const
inline

To call the protected method drawLight.

Definition at line 33 of file Viewer.h.

34 {
35 drawLight( light );
36 }

◆ drawSomeLight() [2/2]

void rt::Viewer::drawSomeLight ( GLenum  light,
float  zoom 
) const
inline

To call the protected method drawLight.

Definition at line 38 of file Viewer.h.

39 {
40 drawLight( light, zoom );
41 }

◆ helpString()

QString Viewer::helpString ( ) const
protectedvirtual

Called when pressing help.

Definition at line 100 of file Viewer.cpp.

101{
102 QString text("<h2>S i m p l e V i e w e r</h2>");
103 text += "Use the mouse to move the camera around the object. ";
104 text += "You can respectively revolve around, zoom and translate with the three mouse buttons. ";
105 text += "Left and middle buttons pressed together rotate around the camera view direction axis<br><br>";
106 text += "Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
107 text += "Simply press the function key again to restore it. Several keyFrames define a ";
108 text += "camera path. Paths are saved when you quit the application and restored at next start.<br><br>";
109 text += "Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
110 text += "<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. ";
111 text += "See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>";
112 text += "Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). ";
113 text += "A middle button double click fits the zoom of the camera and the right button re-centers the scene.<br><br>";
114 text += "A left button double click while holding right button pressed defines the camera <i>Revolve Around Point</i>. ";
115 text += "See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>";
116 text += "Press <b>Escape</b> to exit the viewer.";
117 text += "Press <b>R</b> to render the scene (low resolution).";
118 text += "Press <b>Shift+R</b> to render the scene (medium resolution).";
119 text += "Press <b>Ctrl+R</b> to render the scene (high resolution).";
120 return text;
121}

◆ init()

void Viewer::init ( )
protectedvirtual

Called before the first draw.

Definition at line 28 of file Viewer.cpp.

29{
30 // Restore previous viewer state.
31 restoreStateFromFile();
32
33 // Add custom key description (see keyPressEvent).
34 setKeyDescription(Qt::Key_R, "Renders the scene with a ray-tracer (low resolution)");
35 setKeyDescription(Qt::SHIFT+Qt::Key_R, "Renders the scene with a ray-tracer (medium resolution)");
36 setKeyDescription(Qt::CTRL+Qt::Key_R, "Renders the scene with a ray-tracer (high resolution)");
37 setKeyDescription(Qt::Key_D, "Augments the max depth of ray-tracing algorithm");
38 setKeyDescription(Qt::SHIFT+Qt::Key_D, "Decreases the max depth of ray-tracing algorithm");
39
40 // Opens help window
41 help();
42
43 // To move lights around
44 setMouseTracking(true);
45
46 // Inits the scene
47 if ( ptrScene != 0 )
48 ptrScene->init( *this );
49
50 // Gives a bounding box to the camera
51 camera()->setSceneBoundingBox( qglviewer::Vec( -12, -12, -2 ),qglviewer::Vec( 12, 12, 22 ) );
52
53}
void init(Viewer &viewer)
This function calls the init method of each of its objects.
Definition Scene.h:46

◆ keyPressEvent()

void Viewer::keyPressEvent ( QKeyEvent *  e)
protectedvirtual

Celled when pressing a key.

Definition at line 56 of file Viewer.cpp.

57{
58 // Get event modifiers key
59 const Qt::KeyboardModifiers modifiers = e->modifiers();
60 bool handled = false;
61 if ((e->key()==Qt::Key_R) && ptrScene != 0 )
62 {
63 int w = camera()->screenWidth();
64 int h = camera()->screenHeight();
65 Renderer renderer( *ptrScene );
66 qglviewer::Vec orig, dir;
67 camera()->convertClickToLine( QPoint( 0,0 ), orig, dir );
68 Vector3 origin( orig );
69 Vector3 dirUL( dir );
70 camera()->convertClickToLine( QPoint( w,0 ), orig, dir );
71 Vector3 dirUR( dir );
72 camera()->convertClickToLine( QPoint( 0, h ), orig, dir );
73 Vector3 dirLL( dir );
74 camera()->convertClickToLine( QPoint( w, h ), orig, dir );
75 Vector3 dirLR( dir );
76 renderer.setViewBox( origin, dirUL, dirUR, dirLL, dirLR );
77 if ( modifiers == Qt::ShiftModifier ) { w /= 2; h /= 2; }
78 else if ( modifiers == Qt::NoModifier ) { w /= 8; h /= 8; }
79 Image2D<Color> image( w, h );
80 renderer.setResolution( image.w(), image.h() );
81 renderer.render( image, maxDepth );
82 ofstream output( "output.ppm" );
83 Image2DWriter<Color>::write( image, output, true );
84 output.close();
85 handled = true;
86 }
87 if (e->key()==Qt::Key_D)
88 {
89 if ( modifiers == Qt::ShiftModifier )
90 { maxDepth = std::max( 1, maxDepth - 1 ); handled = true; }
91 if ( modifiers == Qt::NoModifier )
92 { maxDepth = std::min( 20, maxDepth + 1 ); handled = true; }
93 std::cout << "Max depth is " << maxDepth << std::endl;
94 }
95
96 if (!handled) QGLViewer::keyPressEvent(e);
97}
PointVector< Real, 3 > Vector3
The type for representing a 3d point.

◆ setScene()

void rt::Viewer::setScene ( rt::Scene aScene)
inline

Sets the scene.

Definition at line 27 of file Viewer.h.

28 {
29 ptrScene = &aScene;
30 }

Member Data Documentation

◆ maxDepth

int rt::Viewer::maxDepth
protected

Maximum depth.

Definition at line 57 of file Viewer.h.

◆ ptrScene

rt::Scene* rt::Viewer::ptrScene
protected

Stores the scene.

Definition at line 54 of file Viewer.h.


The documentation for this class was generated from the following files: