SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SRInterface.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2013 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 /// \author James Hughes
30 /// \date February 2013
31 
32 #ifndef SPIRE_APPSPECIFIC_SCIRUN_SCIRUNINTERFACE_H
33 #define SPIRE_APPSPECIFIC_SCIRUN_SCIRUNINTERFACE_H
34 
35 #include <cstdint>
36 
38 #include <boost/shared_ptr.hpp>
39 
41 #include <spire/Interface.h>
42 #include <gl-state/GLState.hpp>
43 
44 namespace SCIRun {
45 namespace Gui {
46 
47 class SRCamera;
48 class SciBall;
49 
50 // This class will be executing on a remote thread using boost lock free
51 // structures. The view scene dialog on qt widgets only serve one purpose:
52 // to relay information to this thread so that rendering can take place.
53 // Information such as mouse clicks and user settings.
55 {
56 public:
57  SRInterface(std::shared_ptr<spire::Context> context,
58  const std::vector<std::string>& shaderDirs,
59  spire::Interface::LogFunction logFP = spire::Interface::LogFunction());
60  ~SRInterface();
61 
62  /// Call this whenever the window is resized. This will modify the viewport
63  /// appropriately.
64  void eventResize(size_t width, size_t height);
65 
66  /// \todo Specify what buttons are pressed.
67  /// @{
69  {
74  };
75 
76  enum MouseMode
77  {
80  };
81 
82  void inputMouseDown(const glm::ivec2& pos, MouseButton btn);
83  void inputMouseMove(const glm::ivec2& pos, MouseButton btn);
84  void inputMouseUp(const glm::ivec2& pos, MouseButton btn);
85  /// @}
86 
87  void inputMouseWheel(int32_t delta);
88 
89  /// \todo Selecting objects...
90 
91  /// \todo Obtaining data from mesh objects in order to spatially partition
92  /// them and provide quick object feedback.
93 
94  /// Screen width retrieval. Dimensions are pixels.
95  size_t getScreenWidthPixels() const {return mScreenWidth;}
96  size_t getScreenHeightPixels() const {return mScreenHeight;}
97 
98  /// Reads an asset file and returns the associated vertex buffer and index
99  /// buffer.
100  void readAsset(const std::string& filename,
101  std::vector<uint8_t> vbo, std::vector<uint8_t> ibo);
102 
103  /// Remove all SCIRun 5 objects.
104  void removeAllGeomObjects();
105 
106  /// Garbage collect all invalid objects not given in the valid objects vector.
107  void gcInvalidObjects(const std::vector<std::string>& validObjects);
108 
109  /// Handles a new geometry object.
110  void handleGeomObject(boost::shared_ptr<Core::Datatypes::GeometryObject> object);
111 
112  /// Performs a frame.
113  void doFrame();
114 
115  /// Sets the mouse interaction mode.
116  void setMouseMode(MouseMode mode);
117 
118  /// Retrieves mouse interaction mode.
120 
121  /// Performs an autoview.
122  void doAutoView();
123 
124 private:
125 
126  class SRObject
127  {
128  public:
129  SRObject(const std::string& name, const spire::M44& objToWorld,
130  const Core::Geometry::BBox& bbox, boost::optional<std::string> colorMap) :
131  mName(name),
132  mObjectToWorld(objToWorld),
133  mBBox(bbox),
134  mColorMap(colorMap)
135  {}
136 
137  // Different types of uniform transformations that are associated
138  // with the object (based off of the unsatisfied uniforms detected
139  // by the Spire object).
140  enum ObjectTransforms
141  {
142  OBJECT_TO_WORLD,
143  OBJECT_TO_CAMERA,
144  OBJECT_TO_CAMERA_PROJECTION,
145  };
146 
147  struct SRPass
148  {
149  SRPass(const std::string& name) :
150  passName(name)
151  {}
152 
153  std::string passName;
154  std::list<ObjectTransforms> transforms;
155  };
156 
157  std::string mName;
158  spire::M44 mObjectToWorld;
159  std::list<SRPass> mPasses;
160  Core::Geometry::BBox mBBox; ///< Objects bounding box (calculated from VBO).
161 
162  boost::optional<std::string> mColorMap;
163  };
164 
165  // Begins the frame.
166  void beginFrame();
167 
168  void generateColormaps();
169 
170  std::shared_ptr<spire::Interface> mSpire;
171 
172  MouseMode mMouseMode; ///< Current mouse mode.
173 
174  size_t mScreenWidth; ///< Screen width in pixels.
175  size_t mScreenHeight; ///< Screen height in pixels.
176 
177  GLuint mRainbowCMap; ///< Rainbow color map.
178  GLuint mGrayscaleCMap; ///< Grayscale color map.
179 
180  std::unique_ptr<SRCamera> mCamera; ///< Primary camera.
181  std::vector<SRObject> mSRObjects; ///< All SCIRun objects.
182  Core::Geometry::BBox mSceneBBox; ///< Scene's AABB. Recomputed per-frame.
183 
184  std::string mArrowVBOName; ///< VBO for one axis of the coordinate axes.
185  std::string mArrowIBOName; ///< IBO for one axis of the coordinate axes.
186  std::string mArrowObjectName; ///< Object name for profile arrow.
187 
188 };
189 
190 } // namespace Gui
191 } // namespace SCIRun
192 
193 #endif
void setMouseMode(MouseMode mode)
Sets the mouse interaction mode.
Definition: SRInterface.cc:126
MouseButton
Definition: SRInterface.h:68
SRInterface(std::shared_ptr< spire::Context > context, const std::vector< std::string > &shaderDirs, spire::Interface::LogFunction logFP=spire::Interface::LogFunction())
Definition: SRInterface.cc:53
void doFrame()
Performs a frame.
Definition: SRInterface.cc:367
std::list< ObjectTransforms > transforms
Definition: SRInterface.h:154
void handleGeomObject(boost::shared_ptr< Core::Datatypes::GeometryObject > object)
Handles a new geometry object.
Definition: SRInterface.cc:180
MouseMode
Definition: SRInterface.h:76
void inputMouseDown(const glm::ivec2 &pos, MouseButton btn)
Definition: SRInterface.cc:150
void readAsset(const std::string &filename, std::vector< uint8_t > vbo, std::vector< uint8_t > ibo)
void doAutoView()
Performs an autoview.
Definition: SRInterface.cc:168
Definition: SRInterface.h:79
Definition: SRInterface.h:70
Definition: SRInterface.h:71
Definition: BBox.h:46
~SRInterface()
Definition: SRInterface.cc:118
Definition: SRInterface.h:147
void inputMouseWheel(int32_t delta)
Definition: SRInterface.cc:162
const char * name[]
Definition: BoostGraphExampleTests.cc:87
void eventResize(size_t width, size_t height)
Definition: SRInterface.cc:138
void inputMouseUp(const glm::ivec2 &pos, MouseButton btn)
Definition: SRInterface.cc:175
void removeAllGeomObjects()
Remove all SCIRun 5 objects.
Definition: SRInterface.cc:320
Definition: SRInterface.h:72
Definition: SRInterface.h:73
Definition: SRInterface.h:54
void gcInvalidObjects(const std::vector< std::string > &validObjects)
Garbage collect all invalid objects not given in the valid objects vector.
Definition: SRInterface.cc:332
MouseMode getMouseMode()
Retrieves mouse interaction mode.
Definition: SRInterface.cc:132
std::string passName
Definition: SRInterface.h:153
void inputMouseMove(const glm::ivec2 &pos, MouseButton btn)
Definition: SRInterface.cc:156
SRPass(const std::string &name)
Definition: SRInterface.h:149
Definition: SRInterface.h:78
size_t getScreenHeightPixels() const
Definition: SRInterface.h:96
size_t getScreenWidthPixels() const
Screen width retrieval. Dimensions are pixels.
Definition: SRInterface.h:95