SWE
/import/home/rettenbs/src/SWE/src/opengl/simulation.h
00001 #ifndef SIMULATION_H
00002 #define SIMULATION_H
00003 // =====================================================================
00004 // This file is part of SWE_CUDA (see file SWE_Block.cu for details).
00005 // 
00006 // Copyright (C) 2010,2011 Michael Bader, Kaveh Rahnema, Tobias Schnabel
00007 // Copyright (C) 2012      Sebastian Rettenberger
00008 // 
00009 // SWE_CUDA is free software: you can redristribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // SWE_CUDA is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with SWE_CUDA.  If not, see <http://www.gnu.org/licenses/>.
00021 // =====================================================================
00022 #include <math.h>
00023 #include <cuda_runtime.h>
00024 
00025 #include "blocks/cuda/SWE_BlockCUDA.hh"
00026 #include "scenarios/SWE_simple_scenarios.hh"
00027 #include "scenarios/SWE_VisInfo.hh"
00028 
00029 void checkCUDAError(const char *msg);
00030 
00031 class Simulation {
00032 
00033   public:
00034     // Constructor + Destructor 
00035     Simulation ();
00036     ~Simulation();
00037 
00038     // Restart simulation
00039     void restart();
00040     // Load new scenario after initialization
00041     void loadNewScenario(SWE_Scenario* scene);
00042     // Set a different resolution
00043     void resize(float factor);
00044     // Return the bathymetry data
00045     void setBathBuffer(float* output);
00046     // Simulate single timestep on graphics card
00047     void runCuda(struct cudaGraphicsResource **vbo_resource, struct cudaGraphicsResource **vbo_normals);
00048 
00049     int getNx() { return nx; }
00050     int getNy() { return ny; }
00051 
00052     const Float2D& getBathymetry() { return block->getBathymetry(); }
00053 
00054     void getScalingApproximation(float &bScale, float &bOffset, float &wScale);
00055 
00056   private:
00057     // Default scenario (used when no other scenario is specified)
00058     SWE_SplashingPoolScenario defaultScenario;
00059 
00060     // Instance of SWE_BlockCUDA 
00061     SWE_BlockCUDA* block;
00062     // Current scenario
00063     SWE_Scenario* scenario;
00064 
00065     // Cells in x dimension
00066     int nx;
00067     // Cells in y dimension
00068     int ny;
00069 
00070     // Current simulation time
00071     float curTime;
00072     // Is this our first simulation step?
00073     int isFirstStep;
00074 
00075     // Compute new water surface
00076     void calculateWaterSurface(float3* destBuffer);
00077     // Compute normals of the water surface for shading
00078     void calculateNormals(float3* vertexBuffer, float3* destBuffer);
00079 
00080     void updateVisBuffer(float3* _visBuffer);
00081     void debugVisBuffer(float3* _visBuffer);
00082 
00083     static void calculateNormal(float fVert1[], float fVert2[],
00084                                 float fVert3[], float fNormal[]);
00085 
00086 };
00087 
00088 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends