forked from nlichtenberg/OpenGL_Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSurfaceDynamicsVisualization.h
More file actions
336 lines (283 loc) · 12 KB
/
SurfaceDynamicsVisualization.h
File metadata and controls
336 lines (283 loc) · 12 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//============================================================================
// Distributed under the MIT License. Author: Raphael Menges
//============================================================================
#ifndef SURFACE_DYNAMICS_VISUALIZATION_H
#define SURFACE_DYNAMICS_VISUALIZATION_H
#include <memory>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <set>
#include "ShaderTools/ShaderProgram.h"
#include "SurfaceExtraction/GPUProtein.h"
#include "SurfaceExtraction/GPUSurfaceExtraction.h"
#include "SurfaceExtraction/SurfaceValidation.h"
#include "Framebuffer.h"
#include "Path.h"
#include "SurfaceExtraction/GPUHullSamples.h"
#include "Utils/Logger.h"
#include "SurfaceExtraction/GPURenderTexture.h"
// Notes:
// - Calculations done in angstrom
// - Some shaders do not need mesh data and do not bind a VAO. The currently bound VAO is left bound and not used
// TODO:
// - averageLayersDeltaAccumulation and updateGroupAnalysis share functionality. Try to merge!
// Forward declaration
class Protein;
class GPUProtein;
class OrbitCamera;
// Class
class SurfaceDynamicsVisualization
{
public:
// Constructor
SurfaceDynamicsVisualization(std::string filepathPDB, std::string filepathXTC = "");
// Destructor
virtual ~SurfaceDynamicsVisualization();
// Render
void renderLoop();
// Set window title displaying progress (hides processing part when progress is equal one)
void setProgressDisplay(std::string task, float progress = 1.0f);
private:
// Enumeration for rendering
enum Rendering
{
HULL, ASCENSION, ELEMENTS, AMINOACIDS, ANALYSIS, LAYERS, RESIDUE_SURFACE_PROXIMITY
};
// Enumeration for background cubemaps
enum Background
{
NONE, SCIENTIFIC, COMPUTERVISUALISTIK, BEACH, WHITE
};
// Keyboard callback for GLFW
void keyCallback(int key, int scancode, int action, int mods);
// Mouse button callback for GLFW
void mouseButtonCallback(int button, int action, int mods);
// Scroll callback for GLFW
void scrollCallback(double xoffset, double yoffset);
// Render GUI
void renderGUI();
// Update computation information
void updateComputationInformation(std::string device, float computationTime);
// Set frame. Returns whether frame has been changed
bool setFrame(int frame);
// Compute layers
void computeLayers(bool useGPU);
// Compute hull samples
void computeHullSamples();
// Compute ascension
void computeAscension();
// Get atom beneath cursor. Returns -1 when fails
int getAtomBeneathCursor() const;
// Calculate approximated surface of molecule
float approximateSurfaceArea(std::vector<GLuint> indices, int frame) const;
// Update global analysis
void updateGlobalAnalysis();
// Update group analysis
void updateGroupAnalysis();
// Update amino acids analysis
void updateAminoAcidsAnaylsis();
// Get whether frame was computed (otherwise prohibit doing thing which would go wrong)
bool frameComputed() const { return (mFrame >= mComputedStartFrame) && (mFrame <= mComputedEndFrame); }
// Reset path
void resetPath(std::string& rPath, std::string appendage = "") const;
// Load cubemap texture. Returns texture handle
GLuint createCubemapTexture(
std::string filepathPosX,
std::string filepathNegX,
std::string filepathPosY,
std::string filepathNegY,
std::string filepathPosZ,
std::string filepathNegZ) const;
// Setup
const float mCameraSmoothDuration = 1.5f;
const float mSamplePointSize = 2.f;
const float mPathPointSize = 3.f;
const float mMinDrawingExtentOffset = -5.f;
const float mMaxDrawingExtentOffset = 5.f;
const float mCameraDefaultAlpha = 90.f;
const float mCameraDefaultBeta = 45.f;
const glm::vec3 mInternalAtomColor = glm::vec3(0.75f, 0.75f, 0.75f);
const glm::vec3 mSurfaceAtomColor = glm::vec3(1.f, 0.25f, 0.f);
const glm::vec3 mInternalValidationSampleColor = glm::vec3(1.f, 0.9f, 0.0f);
const glm::vec3 mSurfaceValidationSampleColor = glm::vec3(0.f, 1.0f, 0.2f);
const float mClippingPlaneMin = 0.f;
const float mClippingPlaneMax = 200.f;
const std::string mWindowTitle = "Surface Dynamics Visualization";
const float mDepthDarkeningMaxEnd = 1000.f;
const int mInitialWindowWidth = 1280;
const int mInitialWindowHeight = 720;
const float mOutlineWidth = 0.15f;
const glm::vec4 mOutlineColor = glm::vec4(1.f, 1.f, 0.f, 0.9f);
const glm::vec3 mPastPathColor = glm::vec3(1.f, 0.f, 0.f);
const glm::vec3 mFuturePathColor = glm::vec3(0.f, 1.f, 0.f);
const int mCameraAutoCenterSmoothFrameRadius = 10;
const glm::vec3 mInternalHullSampleColor = glm::vec3(0.0f, 0.0f, 0.0f);
const glm::vec3 mSurfaceHullSampleColor = glm::vec3(1.0f, 1.0f, 1.0f);
const glm::vec3 mFallbackAtomColor = glm::vec3(0.7f, 0.7f, 0.7f);
const float mAscensionColorOffsetAngle = 1.25f * glm::pi<float>();
const float mSurfaceMarkPointSize = 5.f;
const glm::vec3 mSelectionColor = glm::vec3(0.2f, 1.0f, 0.0f);
const bool mFrameLogging = false;
const std::string mNoComputedFrameMessage = "Frame was not computed.";
const GLuint mKBufferLayerCount = 32; // remember to adapt value in shaders as well
// Colors for rendering layers (outer to inner, repeating if too many)
const std::vector<glm::vec3> mLayerColors =
{
glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f)
};
// Controllable parameters
bool mShowCameraWindow = true;
bool mShowInformationWindow = true;
bool mShowValidationWindow = false;
bool mShowRenderingWindow = false;
bool mShowVisualizationWindow = true;
bool mShowComputationWindow = true;
bool mRotateCamera = false;
bool mMoveCamera = false;
int mSelectedAtom = 0;
bool mRenderWithProbeRadius = false;
bool mUsePerspectiveCamera = false; // removed from GUI since both spheres
// and cut of spheres is only correct
// for orthographic projection
bool mShowInternal = true;
bool mShowSurface = true;
float mComputationProbeRadius = 1.4f;
int mCPUThreads = 8;
int mSurfaceValidationAtomSampleCount = 20;
bool mShowValidationSamples = true;
float mClippingPlane = 0.f;
int mSurfaceValidationSeed = 0;
bool mShowAxesGizmo = false;
bool mPlayAnimation = false;
int mPlayAnimationRate = 15;
bool mShowInternalSamples = true;
bool mShowSurfaceSamples = true;
int mStartFrame = 0;
int mEndFrame = 0;
int mComputationStartFrame = 0;
int mComputationEndFrame = 0;
bool mExtractLayers = true;
bool mRepeatAnimation = false;
int mSmoothAnimationRadius = 0;
float mSmoothAnimationMaxDeviation = 5;
float mDepthDarkeningStart = 100.f;
float mDepthDarkeningEnd = 500.f;
bool mShowAnalysisWindow = true;
bool mShowPath = true;
int mPathFrameRadius = 5; // radius of frames which are visualized
int mPathSmoothRadius = 0; // radius of frames which are used for smoothing the path
Rendering mRendering = HULL;
Background mBackground = WHITE;
int mHullSampleCount = 250; // sample count per atom
bool mRenderHullSamples = false;
bool mRenderOutline = true;
bool mShowTooltips = true;
float mAscensionUpToHotFrameCount = 100.f;
float mAscensionDownToHotFrameCount = 100.f;
float mAscensionUpToColdFrameCount = 100.f;
float mAscensionDownToColdFrameCount = 100.f;
float mAscensionChangeRadiusMultiplier = 0.f;
bool mMarkSurfaceAtoms = false;
bool mRepeatOnlyComputed = false;
bool mSuperSampling = true;
int mPathLengthStartFrame = 0;
int mPathLengthEndFrame = 0;
bool mRenderSelection = true;
int mNewGroupAtomsStartIndex = 0;
int mNewGroupAtomsEndIndex = 0;
float mNoneGroupOpacity = 1.f;
bool mRenderGroupOnTop = false;
float mAvgLayersDeltaAcc = 0.f;
// Report output
std::string mComputeInformation = "No computation info available.";
std::string mValidationInformation = "No validation info available.";
// Molecule and surface
std::unique_ptr<GPUProtein> mupGPUProtein; // protein on GPU
std::unique_ptr<GPUSurfaceExtraction> mupGPUSurfaceExtraction; // factory for GPUSurfaces
// (unique pointer because has to be constructed after OpenGL initialization)
std::vector<std::unique_ptr<GPUSurface> > mGPUSurfaces; // vector with surfaces
// Camera
std::unique_ptr<OrbitCamera> mupCamera; // camera for visualization
glm::vec2 mCameraDeltaRotation;
float mCameraRotationSmoothTime;
// Lighting
glm::vec3 mLightDirection;
// State
std::string mPDBFilepath = "";
std::string mXTCFilepath = "";
int mFrame = 0; // do not set it directly, let it be done by setFrame() method!
int mLayer = 0;
float mFramePlayTime = 0; // time of displaying a molecule state at playing the animation
int mComputedStartFrame = -1;
int mComputedEndFrame = -1;
float mComputedProbeRadius = 0.f;
float mAccTime = 0; // since only float precision, reset after a certain time
// Window
GLFWwindow* mpWindow;
int mWindowWidth;
int mWindowHeight;
// Ascension
std::unique_ptr<GPUBuffer<GLfloat> > mupAscension; // values have range [0..2Pi]
// Cubemaps
GLuint mScientificCubemapTexture;
GLuint mCVCubemapTexture;
GLuint mBeachCubemapTexture;
GLuint mWhiteCubemapTexture;
// Framebuffer
std::unique_ptr<Framebuffer> mupMoleculeFramebuffer;
std::unique_ptr<Framebuffer> mupSelectedAtomFramebuffer;
std::unique_ptr<Framebuffer> mupOverlayFramebuffer;
std::unique_ptr<GPUTextureBuffer> mupOutlineAtomIndices;
// Analysis
std::unique_ptr<GPUHullSamples> mupHullSamples;
std::set<GLuint> mAnalyseGroup;
std::unique_ptr<GPUBuffer<GLfloat> > mupGroupIndicators; // zero for atoms which are not in group
int mNextAnalyseAtomIndex = 0;
std::vector<float> mAnalysisSurfaceAmount;
std::vector<float> mAnalysisSurfaceArea;
std::vector<float> mAnalysisGroupMinLayers;
std::vector<float> mAnalysisGroupAvgLayers;
std::vector<float> mAnalysisGroupSurfaceAmount;
std::vector<float> mAnalysisGroupSurfaceArea;
std::unique_ptr<Path> mupPath;
std::string mSurfaceIndicesFilePath = "";
std::string mGlobalAnalysisFilePath = "";
std::string mGroupAnalysisFilePath = "";
std::string mAminoAcidAnalysisAccumulatedFilePath = "";
std::string mAminoAcidAnalysisAvgLayersFilePath = "";
std::string mAminoAcidAnalysisInverseAvgLayersFilePath = "";
std::string mAminoAcidAnalysisAvgLayersDeltaFilePath = "";
std::string mAminoAcidAnalysisInverseAvgLayersDeltaFilePath = "";
// Surface validation
std::unique_ptr<SurfaceValidation> mupSurfaceValidation;
int mSurfaceValidationSampleCount = 0;
// Texture for rendering group atoms on top of molecule
std::unique_ptr<GPURenderTexture> mupGroupRenderingTexture;
std::unique_ptr<GPUTextureBuffer> mupGroupRenderingSemaphore;
// Residue surface proximity rendering buffers
std::unique_ptr<GPURenderTexture> mupKBufferCounter;
std::unique_ptr<GPURenderTexture> mupKBufferTexture;
std::unique_ptr<GPUBuffer<GLfloat> > mupLayersDeltaBuffer;
// Ascension helper texture
GLuint mAscensionHelperTexture;
int mAscensionHelperWidth = 0;
int mAscensionHelperHeight = 0;
// Amino acid calculations
struct AminoAcidAnalysis
{
std::string name = "";
int startIndex = -1;
int endIndex = -1;
float averageLayersDeltaAccumulation = -1;
float inverseAverageLayersDeltaAccumulation = -1;
std::vector<float> averageLayers;
std::vector<float> inverseAverageLayers;
std::vector<float> averageLayersDelta;
std::vector<float> inverseAverageLayersDelta;
};
std::vector<AminoAcidAnalysis> mAminoAcidAnalysis;
};
#endif // SURFACE_DYNAMICS_VISUALIZATION_H