FlowVis 1.0

FlowVis/Framework/FlowChannel.cpp

00001 #include "FlowChannel.h"
00002 #include <math.h>
00003 
00004 float FlowChannel::getValue(vec3 pos)
00005 {
00006     //IDs of cell vertices in the neighborhood of the sampled point
00007     int vtxID[4];
00008     //weighting coefficients for interpolation
00009     float coef[4];
00010     
00011     //let's determine the neighbouring geometry and get the interpolation coefficients
00012     //this is a general scheme... there can be various interpolation schemes used (nearest, linear) inside of the getInterpolationAt. It's up to you, what you implement.
00013     if (geom->getInterpolationAt(pos, vtxID, coef))
00014         return values[vtxID[0]]*coef[0] + values[vtxID[1]]*coef[1] + values[vtxID[2]]*coef[2] + values[vtxID[3]]*coef[3];
00015     else
00016     {
00017         std::cerr << "Outside of the dataset" << std::endl;
00018         return 0;
00019     }
00020 }
00021 
00022 float FlowChannel::getValue(int vtxID)
00023 {
00024     return values[vtxID];
00025 }
00026 
00028 float FlowChannel::getValueNormPos(vec3 pos)
00029 {
00030         //first scale the coordinates back
00031     vec3 realPos = geom->unNormalizeCoords(pos);
00032         //now make a lookup
00033     return getValue(realPos);
00034 }
00035 
00037 float FlowChannel::getValueNormPos(float x, float y)
00038 {
00039         //calls the previous method
00040     return getValueNormPos(vec3(x,y));
00041 }
00042 
00043 float FlowChannel::normalizeValue(float val)
00044 {
00045         //scales the value so that minimum will be 0 and maximum 1
00046     return (val-minimum)/(maximum-minimum);
00047 }
00048 
00049 FlowChannel::FlowChannel(FlowGeometry* g)
00050 {
00051     geom = g;
00052     //create the appropriate storage
00053     values = new float[geom->getDimX()*geom->getDimY()];
00054     minimum = HUGE_VAL;
00055     maximum = -HUGE_VAL;
00056     std::cout << "ok" << std::endl;    
00057 }
00058 
00059 FlowChannel::~FlowChannel()
00060 {
00061         //delete the value storage
00062     delete[] values;
00063     std::cout << "ok" << std::endl;
00064 }
00065 
00066 void FlowChannel::setValue(int vtxID, float val)
00067 {
00068     values[vtxID] = val;
00069         //update the minimum and maximum
00070     minimum = (val < minimum) ? val : minimum;
00071     maximum = (val > maximum) ? val : maximum;    
00072 }
00073 
00074 //takes an array containing all attributes for a vertex and copies the attribute specified in offset to this channel
00075 void FlowChannel::copyValues(float* rawdata, int vtxSize, int offset)
00076 {
00077     for (int i = 0; i < geom->getDimX()*geom->getDimY(); i++)
00078     {
00079         values[i] = rawdata[(i*vtxSize) + offset];
00080                 //update the minimum and maximum
00081         minimum = (values[i] < minimum) ? values[i] : minimum;
00082         maximum = (values[i] > maximum) ? values[i] : maximum;
00083     }
00084     std::cout << "Maximum value in channel: " << maximum << std::endl;
00085     std::cout << "Minimum value in channel: " << minimum << std::endl;    
00086 }
00087 
00088 float FlowChannel::getMin()
00089 {
00090     return minimum;
00091 }
00092 
00093 float FlowChannel::getMax()
00094 {
00095     return maximum;
00096 }
00097 
00098 float FlowChannel::getRange()
00099 {
00100     return maximum - minimum;
00101 }
 All Classes Functions Variables Friends