Go to the documentation of this file.00001
00004
00005
00006
00007
00008 #ifndef qglv_OBJECTS_POTENTIAL_FIELD_HPP_
00009 #define qglv_OBJECTS_POTENTIAL_FIELD_HPP_
00010
00011
00012
00013
00014
00015 #include <limits>
00016 #include <memory>
00017 #include <vector>
00018
00019
00020
00021
00022
00023 namespace qglv {
00024
00025
00026
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
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
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
00079
00080
00081
00082
00083
00084
00085
00086 }
00087 };
00088
00089
00090
00091
00092
00093 typedef std::shared_ptr<PotentialField> PotentialFieldPtr;
00094
00095
00096
00097
00098
00099 }
00100
00101 #endif