potential_field.hpp
Go to the documentation of this file.
00001 
00004 /*****************************************************************************
00005 ** Ifdefs
00006 *****************************************************************************/
00007 
00008 #ifndef qglv_OBJECTS_POTENTIAL_FIELD_HPP_
00009 #define qglv_OBJECTS_POTENTIAL_FIELD_HPP_
00010 
00011 /*****************************************************************************
00012 ** Includes
00013 *****************************************************************************/
00014 
00015 #include <limits>
00016 #include <memory>
00017 #include <vector>
00018 
00019 /*****************************************************************************
00020 ** Namespaces
00021 *****************************************************************************/
00022 
00023 namespace qglv {
00024 
00025 /*****************************************************************************
00026 ** Potential Field
00027 *****************************************************************************/
00028 
00033 class PotentialField {
00034 
00035 public:
00036   PotentialField(const unsigned int& nx,
00037                  const unsigned int& ny,
00038                  const float& resolution,
00039                  const std::vector<unsigned char>& potential_array
00040                 );
00041 
00042   PotentialField(const unsigned int& nx,
00043                  const unsigned int& ny,
00044                  const float& resolution,
00045                  const std::vector<float>& potential_array);
00046   virtual ~PotentialField();
00047   void draw();
00048 
00049   unsigned int number_of_cells_x, number_of_cells_y;
00050   float resolution;
00051 
00052 private:
00053   virtual void _glGenLists();
00054   int gl_id; 
00055   unsigned int gl_vertex_buffer_id, gl_index_buffer_id;
00056   std::vector< float > values;
00057 
00058   template<typename element_type>
00059   void _init(const std::vector<element_type>& potential_array) {
00060     // normalise
00061     float min_value = std::numeric_limits<float>::max();
00062     float max_value = std::numeric_limits<float>::min();
00063     for ( const auto& value : potential_array ) {
00064       if ( value != std::numeric_limits<float>::infinity() ) {
00065         if ( value < min_value ) { min_value = value; }
00066         if ( value > max_value ) { max_value = value; }
00067       }
00068     }
00069     // normalise from 0.3->0.8
00070     float range = (max_value > min_value) ? (max_value - min_value) : 1.0;
00071     for ( unsigned int i = 0; i < potential_array.size(); ++i ) {
00072       if ( potential_array[i] == std::numeric_limits<float>::infinity() ) {
00073         values[i] = 0.0;
00074       } else {
00075         values[i] = 0.1 + 0.8*(potential_array[i] - min_value)/range;
00076       }
00077     }
00078   //  for ( unsigned int y = 0; y < number_of_cells_y; ++y) {
00079   //    std::cout << y << ": ";
00080   //    for ( unsigned int x = 0; x < number_of_cells_x; ++x) {
00081   //      std::cout << values[y*number_of_cells_y + x] << " ";
00082   //    }
00083   //    std::cout << std::endl;
00084   //  }
00085     // TODO check that values is the correct size.
00086   }
00087 };
00088 
00089 /*****************************************************************************
00090  ** Typedefs
00091  *****************************************************************************/
00092 
00093 typedef std::shared_ptr<PotentialField> PotentialFieldPtr;
00094 
00095 /*****************************************************************************
00096  ** Trailers
00097  *****************************************************************************/
00098 
00099 } // namespace qglv
00100 
00101 #endif /* qglv_OBJECTS_POTENTIAL_FIELD_HPP_ */


qglv_opengl
Author(s): Daniel Stonier
autogenerated on Sat Jun 18 2016 08:19:28