C:/Projekte/C++/FlowVIS_107/src/FlowChannel.cpp

Go to the documentation of this file.
00001 #include "FlowChannel.h"
00002 #include <math.h>
00003 
00004 
00005 void FlowChannel::moveMinimumToZero()
00006 {
00007   // gv Move minimum to origin
00008 
00009   if ( minimum != 0.0 ) 
00010   {
00011     for( int i=0; i<geom->getDimX()*geom->getDimY(); i++ )
00012       values[i] = values[i] - minimum;
00013 
00014     maximum = maximum - minimum;
00015     minimum = 0;
00016   }
00017 
00018 /*
00019   // gv TEST: search for min-value
00020   float testMin = maximum;
00021   for( int i=0; i<geom->getDimX()*geom->getDimY(); i++ )
00022   {
00023     if ( values[i] < testMin ) testMin = values[i];
00024   }
00025 
00026   std::cout << "found min: " << testMin << std::endl;
00027 */
00028 }
00029 
00030 
00031 float FlowChannel::getValue(vec3 pos)
00032 {
00033     //IDs of cell vertices
00034     int vtxID[4];
00035     //weighting coefficients for interpolation
00036     float coef[4];
00037     
00038     //let's determine the neighbouring geometry and get the interpolation coefficients
00039     //this is a general scheme... there can be various interpolation schemes used (nearest, linear) inside of the getInterpolationAt
00040     if (geom->getInterpolationAt_old(pos, vtxID, coef))
00041         return values[vtxID[0]]*coef[0] + values[vtxID[1]]*coef[1] + values[vtxID[2]]*coef[2] + values[vtxID[3]]*coef[3];
00042     else
00043     {
00044         std::cerr << "Outside of the dataset" << std::endl;
00045         return 0;
00046     }
00047 }
00048 
00049 
00050 float* FlowChannel::getData() const
00051 {
00052   return values;
00053 }
00054 
00055 float FlowChannel::getValue(int vtxID)
00056 {
00057     return values[vtxID];
00058 }
00059 
00061 float FlowChannel::getValueNormPos(vec3 pos)
00062 {
00063         //first scale the coordinates back
00064     vec3 realPos = geom->unNormalizeCoords(pos);
00065         //now make a lookup
00066     return getValue(realPos);
00067 }
00068 
00070 float FlowChannel::getValueNormPos(float x, float y)
00071 {
00072         //calls the previous method
00073     return getValueNormPos(vec3(x,y));
00074 }
00075 
00076 float FlowChannel::normalizeValue(float val)
00077 {
00078   //scales the value so that minimum would be 0 and maximum 1
00079   return (val - minimum) / (maximum - minimum); 
00080 }
00081 
00082 FlowChannel::FlowChannel(FlowGeometry* g)
00083 {
00084     geom = g;
00085 
00086     //create the appropriate storage
00087     values = new float[ geom->getDimX() * geom->getDimY() ];
00088 
00089     minimum = (float) HUGE_VAL;
00090     maximum = (float) -HUGE_VAL;
00091 
00092     //std::cout << "ok" << std::endl;    
00093 }
00094 
00095 FlowChannel::~FlowChannel()
00096 {
00097         //delete the value storage
00098     delete[] values;
00099     std::cout << "ok" << std::endl;
00100 }
00101 
00102 void FlowChannel::setValue(int vtxID, float val)
00103 {
00104     values[vtxID] = val;
00105         //update the minimum and maximum
00106     minimum = (val < minimum) ? val : minimum;
00107     maximum = (val > maximum) ? val : maximum;    
00108 }
00109 
00111 void FlowChannel::copyValues( float* rawdata, int vtxSize, int offset )
00112 {
00113   for ( int i=0; i<geom->getDimX() * geom->getDimY(); i++ )
00114   {
00115     values[i] = rawdata[ (i * vtxSize) + offset ];
00116 
00117     //update the minimum and maximum
00118     minimum = (values[i] < minimum) ? values[i] : minimum;
00119     maximum = (values[i] > maximum) ? values[i] : maximum;
00120   }
00121 
00122   /*
00123   std::cout << " - Maximum value in channel: " << maximum << std::endl;
00124   std::cout << " - Minimum value in channel: " << minimum << std::endl;    
00125   */
00126 }
00127 
00128 
00129 // gv Simply copy the values from the rawData to the channel
00130 void FlowChannel::copyValues( float* rawData )
00131 {
00132   for ( int i=0; i<geom->getDimX() * geom->getDimY(); i++ )
00133   {
00134     values[i] = rawData[i];
00135 
00136     //update the minimum and maximum
00137     minimum = (values[i] < minimum) ? values[i] : minimum;
00138     maximum = (values[i] > maximum) ? values[i] : maximum;
00139   }
00140 
00141   /*
00142   std::cout << " - Maximum value in channel: " << maximum << std::endl;
00143   std::cout << " - Minimum value in channel: " << minimum << std::endl;    
00144   */
00145 }
00146 
00147 
00148 void FlowChannel::setMax(float val)
00149 {
00150   maximum = val;
00151 }
00152 
00153 void FlowChannel::setMin(float val)
00154 {
00155  minimum = val;
00156 }
00157 
00158 float FlowChannel::getMin()
00159 {
00160     return minimum;
00161 }
00162 
00163 float FlowChannel::getMax()
00164 {
00165     return maximum;
00166 }
00167 
00168 float FlowChannel::getRange()
00169 {
00170     return maximum - minimum;
00171 }

Generated on Mon Jan 21 14:50:12 2008 for VisLU by  doxygen 1.5.4