forked from KeckCAVES/SARndbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sandbox.h
189 lines (168 loc) · 8.46 KB
/
Sandbox.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/***********************************************************************
Sandbox - Vrui application to drive an augmented reality sandbox.
Copyright (c) 2012-2016 Oliver Kreylos
This file is part of the Augmented Reality Sandbox (SARndbox).
The Augmented Reality Sandbox 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 2 of the
License, or (at your option) any later version.
The Augmented Reality Sandbox 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 the Augmented Reality Sandbox; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***********************************************************************/
#ifndef SANDBOX_INCLUDED
#define SANDBOX_INCLUDED
#include <Threads/TripleBuffer.h>
#include <Geometry/Box.h>
#include <Geometry/OrthonormalTransformation.h>
#include <Geometry/ProjectiveTransformation.h>
#include <GL/gl.h>
#include <GL/GLColorMap.h>
#include <GL/GLMaterial.h>
#include <GL/GLObject.h>
#include <GL/GLGeometryVertex.h>
#include <GLMotif/ToggleButton.h>
#include <GLMotif/TextFieldSlider.h>
#include <Vrui/Tool.h>
#include <Vrui/GenericToolFactory.h>
#include <Vrui/TransparentObject.h>
#include <Vrui/Application.h>
#include <Kinect/FrameBuffer.h>
#include <Kinect/FrameSource.h>
#include "Types.h"
/* Forward declarations: */
namespace Misc {
template <class ParameterParam>
class FunctionCall;
}
class GLContextData;
namespace GLMotif {
class PopupMenu;
class PopupWindow;
class TextField;
}
namespace Vrui {
class Lightsource;
}
namespace Kinect {
class Camera;
}
class FrameFilter;
class DepthImageRenderer;
class ElevationColorMap;
class DEM;
class SurfaceRenderer;
class WaterTable2;
class HandExtractor;
typedef Misc::FunctionCall<GLContextData&> AddWaterFunction;
class WaterRenderer;
class Sandbox:public Vrui::Application,public GLObject
{
/* Embedded classes: */
private:
typedef Geometry::Box<Scalar,3> Box; // Type for bounding boxes
typedef Geometry::OrthonormalTransformation<Scalar,3> ONTransform; // Type for rigid body transformations
typedef Kinect::FrameSource::DepthCorrection::PixelCorrection PixelDepthCorrection; // Type for per-pixel depth correction factors
struct DataItem:public GLObject::DataItem
{
/* Elements: */
public:
double waterTableTime; // Simulation time stamp of the water table in this OpenGL context
GLsizei shadowBufferSize[2]; // Size of the shadow rendering frame buffer
GLuint shadowFramebufferObject; // Frame buffer object to render shadow maps
GLuint shadowDepthTextureObject; // Depth texture for the shadow rendering frame buffer
/* Constructors and destructors: */
DataItem(void);
virtual ~DataItem(void);
};
struct RenderSettings // Structure to hold per-window rendering settings
{
/* Elements: */
public:
bool fixProjectorView; // Flag whether to allow viewpoint navigation or always render from the projector's point of view
PTransform projectorTransform; // The calibrated projector transformation matrix for fixed-projection rendering
bool projectorTransformValid; // Flag whether the projector transformation is valid
bool hillshade; // Flag whether to use augmented reality hill shading
GLMaterial surfaceMaterial; // Material properties to render the surface in hill shading mode
bool useShadows; // Flag whether to use shadows in augmented reality hill shading
ElevationColorMap* elevationColorMap; // Pointer to an elevation color map
bool useContourLines; // Flag whether to draw elevation contour lines
GLfloat contourLineSpacing; // Spacing between adjacent contour lines in cm
bool renderWaterSurface; // Flag whether to render the water surface as a geometric surface
GLfloat waterOpacity; // Opacity factor for water when rendered as texture
SurfaceRenderer* surfaceRenderer; // Surface rendering object for this window
WaterRenderer* waterRenderer; // A renderer to render the water surface as geometry
/* Constructors and destructors: */
RenderSettings(void); // Creates default rendering settings
RenderSettings(const RenderSettings& source); // Copy constructor
~RenderSettings(void); // Destroys rendering settings
/* Methods: */
void loadProjectorTransform(const char* projectorTransformName); // Loads a projector transformation from the given file
void loadHeightMap(const char* heightMapName); // Loads the selected height map
};
friend class GlobalWaterTool;
friend class LocalWaterTool;
friend class DEMTool;
/* Elements: */
private:
Kinect::FrameSource* camera; // The Kinect camera device
unsigned int frameSize[2]; // Width and height of the camera's depth frames
PixelDepthCorrection* pixelDepthCorrection; // Buffer of per-pixel depth correction coefficients
Kinect::FrameSource::IntrinsicParameters cameraIps; // Intrinsic parameters of the Kinect camera
FrameFilter* frameFilter; // Processing object to filter raw depth frames from the Kinect camera
bool pauseUpdates; // Pauses updates of the topography
Threads::TripleBuffer<Kinect::FrameBuffer> filteredFrames; // Triple buffer for incoming filtered depth frames
DepthImageRenderer* depthImageRenderer; // Object managing the current filtered depth image
ONTransform boxTransform; // Transformation from camera space to baseplane space (x along long sandbox axis, z up)
Box bbox; // Bounding box around the surface
WaterTable2* waterTable; // Water flow simulation object
double waterSpeed; // Relative speed of water flow simulation
unsigned int waterMaxSteps; // Maximum number of water simulation steps per frame
GLfloat rainStrength; // Amount of water deposited by rain tools and objects on each water simulation step
HandExtractor* handExtractor; // Object to detect splayed hands above the sand surface to make rain
const AddWaterFunction* addWaterFunction; // Render function registered with the water table
bool addWaterFunctionRegistered; // Flag if the water adding function is currently registered with the water table
std::vector<RenderSettings> renderSettings; // List of per-window rendering settings
Vrui::Lightsource* sun; // An external fixed light source
Vrui::Point navCenter;
Vrui::Scalar navSize;
Vrui::Vector navUp;
DEM* activeDem; // The currently active DEM
GLMotif::PopupMenu* mainMenu;
GLMotif::ToggleButton* pauseUpdatesToggle;
GLMotif::PopupWindow* waterControlDialog;
GLMotif::TextFieldSlider* waterSpeedSlider;
GLMotif::TextFieldSlider* waterMaxStepsSlider;
GLMotif::TextField* frameRateTextField;
GLMotif::TextFieldSlider* waterAttenuationSlider;
int controlPipeFd; // File descriptor of an optional named pipe to send control commands to a running AR Sandbox
/* Private methods: */
void rawDepthFrameDispatcher(const Kinect::FrameBuffer& frameBuffer); // Callback receiving raw depth frames from the Kinect camera; forwards them to the frame filter and rain maker objects
void receiveFilteredFrame(const Kinect::FrameBuffer& frameBuffer); // Callback receiving filtered depth frames from the filter object
void toggleDEM(DEM* dem); // Sets or toggles the currently active DEM
void addWater(GLContextData& contextData) const; // Function to render geometry that adds water to the water table
void pauseUpdatesCallback(GLMotif::ToggleButton::ValueChangedCallbackData* cbData);
void showWaterControlDialogCallback(Misc::CallbackData* cbData);
void waterSpeedSliderCallback(GLMotif::TextFieldSlider::ValueChangedCallbackData* cbData);
void waterMaxStepsSliderCallback(GLMotif::TextFieldSlider::ValueChangedCallbackData* cbData);
void waterAttenuationSliderCallback(GLMotif::TextFieldSlider::ValueChangedCallbackData* cbData);
GLMotif::PopupMenu* createMainMenu(void);
GLMotif::PopupWindow* createWaterControlDialog(void);
/* Constructors and destructors: */
public:
Sandbox(int& argc,char**& argv);
virtual ~Sandbox(void);
/* Methods from Vrui::Application: */
virtual void toolDestructionCallback(Vrui::ToolManager::ToolDestructionCallbackData* cbData);
virtual void frame(void);
virtual void display(GLContextData& contextData) const;
virtual void resetNavigation(void);
virtual void eventCallback(EventID eventId,Vrui::InputDevice::ButtonCallbackData* cbData);
/* Methods from GLObject: */
virtual void initContext(GLContextData& contextData) const;
};
#endif