Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
CLIViewer.hpp
1 #pragma once
2 #include <Headless/CLIBaseApplication.hpp>
3 #include <Headless/OpenGLContext/OpenGLContext.hpp>
4 
5 #include <Core/Utils/Index.hpp>
6 
7 #include <functional>
8 
9 #include <glbinding/Version.h>
10 
11 namespace Ra {
12 namespace Core {
13 namespace Asset {
14 class FileLoaderInterface;
15 class Camera;
16 } // namespace Asset
17 } // namespace Core
18 
19 namespace Engine {
20 class RadiumEngine;
21 namespace Rendering {
22 class Renderer;
23 }
24 } // namespace Engine
25 
26 namespace Headless {
34 class HEADLESS_API CLIViewer : public CLIBaseApplication
35 {
36  public:
37  struct ViewerParameters {
39  bool m_animationEnable { false };
41  std::array<int, 2> m_size { { 512, 512 } };
43  std::string m_imgPrefix { "frame" };
45  std::string m_dataFile = { "" };
46  };
47 
48  public:
51 
53  const Engine::RadiumEngine* getEngine() const { return m_engine; }
54 
55  private:
57  std::unique_ptr<OpenGLContext> m_glContext;
58 
60  std::shared_ptr<Ra::Engine::Rendering::Renderer> m_renderer;
61 
63  Ra::Core::Asset::Camera* m_camera { nullptr };
64 
66  ViewerParameters m_parameters;
67 
69  bool m_engineInitialized { false };
70 
72  bool m_exposedWindow { false };
73 
74  public:
79  explicit CLIViewer( std::unique_ptr<OpenGLContext> context );
81  virtual ~CLIViewer();
82 
98  int init( int argc, const char* argv[] ) override;
99 
107  int oneFrame( float timeStep = 1.f / 60.f );
108 
113  void setRenderer( Ra::Engine::Rendering::Renderer* renderer );
114 
118  void addDataFileLoader( Ra::Core::Asset::FileLoaderInterface* loader );
119 
124  void loadScene();
125 
129  void compileScene();
130 
134  void openGlAddOns( std::function<void()> f );
135 
137  void bindOpenGLContext( bool on = true );
138 
142  void setCamera( Ra::Core::Utils::Index camIdx = 0 );
143 
145  void setImageNamePrefix( std::string s );
146 
148  const ViewerParameters& getCommandLineParameters() const;
149 
151  std::unique_ptr<unsigned char[]> grabFrame( size_t& w, size_t& h ) const;
152 
154  void showWindow( bool on = true,
155  OpenGLContext::EventMode mode = OpenGLContext::EventMode::POLL,
156  float delay = 1.f / 60.f );
157 
165  inline OpenGLContext& getWindow();
166 
168  void renderLoop( std::function<void( float )> render );
169 
173  inline std::string getDataFileName() const;
174 
178  inline void setDataFileName( std::string filename );
179 
180  protected:
182  void resize( int width, int height );
183 };
184 
185 inline std::string CLIViewer::getDataFileName() const {
186  return m_parameters.m_dataFile;
187 }
188 
189 inline void CLIViewer::setDataFileName( std::string filename ) {
190  m_parameters.m_dataFile = std::move( filename );
191 }
192 
194  return *m_glContext;
195 }
196 
197 } // namespace Headless
198 } // namespace Ra
Camera class storing the Camera frame and the projection properties The view direction is -z in camer...
Definition: Camera.hpp:16
const Engine::RadiumEngine * getEngine() const
To have the same API to access Engine than in Qt based application.
Definition: CLIViewer.hpp:53
Ra::Engine::RadiumEngine * m_engine
Instance of the radium engine.
Definition: CLIViewer.hpp:50
std::string getDataFileName() const
Definition: CLIViewer.hpp:185
void setDataFileName(std::string filename)
Definition: CLIViewer.hpp:189
OpenGLContext & getWindow()
Gives access to the window to add event processing callbacks.
Definition: CLIViewer.hpp:193
Definition: Cage.cpp:3