Kinetic Visualization (Visualisierung 2 - S2012)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
AppletParticleKinematicImpl.h
Go to the documentation of this file.
1 #ifndef _APPLET_PARTICLE_KINEMATIC_IMPL
2 #define _APPLET_PARTICLE_KINEMATIC_IMPL
3 
5 #include "Particle.h"
6 
7 #include <vlVolume/RaycastVolume.hpp>
8 #include <vlVolume/VolumeUtils.hpp>
9 #include <vlGraphics/Applet.hpp>
10 #include <vlGraphics/Rendering.hpp>
11 #include <vlGraphics/Text.hpp>
12 #include <vlGraphics/FontManager.hpp>
13 #include <vlGraphics/GLSL.hpp>
14 #include <vlGraphics/GeometryPrimitives.hpp>
15 #include <vlCore/VisualizationLibrary.hpp>
16 #include <vlCore/ResourceDatabase.hpp>
17 #include <vlCore/Time.hpp>
18 #include <vlGraphics/Geometry.hpp>
19 #include <vlGraphics/FramebufferObject.hpp>
20 #include <vlGraphics/FrameBuffer.hpp>
21 #include <vlGraphics/Texture.hpp>
22 
23 #include <vector>
24 #include <algorithm>
25 #include <memory>
26 
28 
32 {
33 public:
35 
36  virtual ~AppletParticleKinematicImpl(void);
37 
38  virtual vl::String appletInfo();
39 
40  virtual void initEvent();
41 
42  void fileDroppedEvent(const std::vector<vl::String>& files);
43 
44  void updateText();
45 
46  virtual void updateScene();
47 
48  virtual void keyPressEvent(unsigned short, vl::EKey key);
49 
50  void initialize();
51 
52  vl::Rendering* volumeRendering()
53  {
54  return _volumeRendering.get();
55  }
56 
57  vl::Rendering* particleRendering()
58  {
59  return _particleRendering.get();
60  }
61 
62  // change runtime config
63  void setStickParticleToDensityLevel(bool stick);
64  void setParticleCurvatureK(float k);
65  void setParticleFlockingK(float k);
66  void setParticleRepulsionK(float k);
67  void setParticleFlockingSigma(float s);
68  void setParticleRepulsionSigma(float s);
69  void setUserPreferredDirection(const vl::vec3 &direction);
70  void setUserPreferredDirectionK(float k);
71  void setCrowdedThreshold(float mu);
72  void setCrowdedSigma(float sigma);
73  void enableDying(bool d);
74 
75  // change preprocessing/initialization config
76  void setPreprocessingSigma(float k);
77  void setDensityLevel(float d);
78  void enableGaussianPreprocessing(bool doGaussian);
79  void setGradientMagnitudeThreshold(float threshold);
80  void setMaxNumParticles(int maxParticles);
81  void setNeighbourRadius(int radius);
82 
83  // change rendering config
84  void setSampleStep(float step);
85  void setShadingIntensity(float intensity);
86  void setGradientIntensity(float intensity);
87  void setOpacityIntensity(float intensity);
88  void setParticleSize(float size);
89  void setRenderSmoothedImage(bool render);
92  void setRenderModeByIndex(int mode);
93 
94  // sets the transfer function
95  void setTransferFunction(vl::ref<vl::Image> img);
96 
97  // returns the volumetric image
98  vl::Image* getImage()
99  {
100  return _volumeImage.get();
101  }
102 
104  {
105  _listeners.push_back(l);
106  }
107 
109  {
110  _listeners.erase(std::find(_listeners.begin(), _listeners.end(), l));
111  }
112 
113  void setVolumeFilename(const std::string& filename)
114  {
115  _volumeFilename = filename;
116  }
117 
118  vl::String getVolumeFilename()
119  {
120  return _volumeFilename;
121  }
122 
123 private:
125  void setupScene();
126 
128  void setupVolume();
129 
131  void setupParticles();
132 
135 
137  void updateParticles();
138 
139  void fireListeners();
140 
143 
144  // runtime constants
157  float SAMPLE_STEP;
164 
166  {
168  }
169  MODE;
170 
171  // initialization constants
178 
180 
182  vl::String _volumeFilename;
183 
185  vl::ref<vl::Transform> _volumeTr;
186 
188  vl::ref<vl::Transform> _light0Tr;
189 
191  vl::ref<vl::Light> _light0;
192 
193  // some uniforms used in rendering
194  vl::ref<vl::Uniform> _shadingIntensityUniform;
195  vl::ref<vl::Uniform> _sampleStepUniform;
196  vl::ref<vl::Uniform> _gradientIntensityUniform;
197  vl::ref<vl::Uniform> _opacityIntensityUniform;
198  vl::ref<vl::Uniform> _particleSizeUniform;
199  vl::ref<vl::Uniform> _particlesEnabledUniform;
200 
201  vl::ref<vl::Uniform> _particlesShadingEnabledUniform;
202 
203  // displayed text
204  vl::ref<vl::Text> _valThresholdText;
205 
207  vl::ref<vl::GLSLProgram> _GLSL;
209  vl::ref<vl::GLSLProgram> _particleProgram;
210 
212  vl::ref<vl::Actor> _volumeAct;
213 
215  vl::ref<vl::RaycastVolume> _raycastVolume;
216 
218  vl::ref<vl::Image> _volumeImage;
220  vl::ref<vl::Image> _volumeSmoothedImage;
222  vl::ref<vl::Image> _volumeGradient;
224  vl::ref<vl::Image> _volumeNormalizedGradient;
226  vl::ref<vl::Image> _volumeCurvature;
227  // min-max normalization for gradient used for shaders...
228  vl::vec3 _gradientMin;
229  vl::vec3 _gradientMax;
230 
232  std::vector<std::shared_ptr<Particle>> _particles;
234  std::shared_ptr<ParticleMap> _particleMap;
236  std::vector<vl::vec3> _particleCandidatePositions;
237 
239  vl::ref<vl::Geometry> _glParticles;
240 
242  vl::ref<vl::Texture> _particleTexture;
244  vl::ref<vl::Texture> _particleDepthTexture;
246  vl::ref<vl::Texture> _particleColorTexture;
248  vl::ref<vl::Texture> _normalizedGradientTexture;
249 
250  // FBOs Texture Attachments for the particle rendering pass
251  vl::ref<vl::FBOTexture2DAttachment> _particleDepthAttachment;
252  vl::ref<vl::FBOTexture2DAttachment> _particleColorAttachment;
253 
254  // the fbo for the particle rendering pass
255  vl::ref<vl::FramebufferObject> _fboParticles;
256 
258  vl::ref<vl::Rendering> _volumeRendering;
260  vl::ref<vl::Rendering> _particleRendering;
261 
263  vl::ref<vl::Image> _transferFunction;
264 
266  std::vector<AppletParticleKinematicListener*> _listeners;
267 };
268 
269 #endif // _APPLET_PARTICLE_KINEMATIC_IMPL