00001 #region Using Statements 00002 using System; 00003 using System.Collections.Generic; 00004 using System.Linq; 00005 using System.Text; 00006 using Microsoft.Xna.Framework; 00007 #endregion 00008 00009 namespace visLU2 00010 { 00014 public struct SingleChannel 00015 { 00016 float[] values; 00017 float[] normalizedValues; 00018 List<int> distinctValues; 00019 float minVal; 00020 float maxVal; 00021 00022 #region Properties 00023 public float[] ChannelValues 00024 { 00025 set { values = value; } 00026 get { return values; } 00027 } 00028 00029 public List<int> DistinctValues 00030 { 00031 get 00032 { 00033 if (distinctValues.Count() == 0) 00034 { 00035 groupValues(); 00036 } 00037 return distinctValues; 00038 } 00039 } 00040 00041 public float[] NormValues 00042 { 00043 get 00044 { 00045 if (normalizedValues == null) 00046 { 00047 normalizeValues(); 00048 } 00049 return normalizedValues; 00050 } 00051 } 00052 00053 public float MinValue 00054 { 00055 set { minVal = value; } 00056 get { return minVal; } 00057 } 00058 00059 public float MaxValue 00060 { 00061 set { maxVal = value; } 00062 get { return maxVal; } 00063 } 00064 #endregion 00065 00066 public SingleChannel(int dimX, int dimY) 00067 { 00068 values = new float[dimX * dimY]; 00069 normalizedValues = null; 00070 distinctValues = new List<int>(); 00071 minVal = 0; 00072 maxVal = 0; 00073 } 00074 00078 private void normalizeValues() 00079 { 00080 normalizedValues = new float[values.Length]; 00081 00082 for (int i = 0; i < values.Length; i++) 00083 { 00084 normalizedValues[i] = (values[i] - minVal) / (maxVal - minVal); 00085 } 00086 } 00087 00091 private void groupValues() 00092 { 00093 List<float> valuesTmp = new List<float>(); 00094 valuesTmp = NormValues.ToList<float>(); 00095 valuesTmp.Sort(); 00096 int globalCount = 0; //debug 00097 00098 for (int i = 0; i < valuesTmp.Count(); i++) 00099 { 00100 int value1 = (int)(valuesTmp[i] * 255); 00101 int count = 1; 00102 00103 while (i < (valuesTmp.Count() - 1)) 00104 { 00105 int value2 = (int)(valuesTmp[i + 1] * 255); 00106 if ((value1 == value2)) 00107 { 00108 count++; 00109 i++; 00110 } 00111 else 00112 { 00113 break; 00114 } 00115 00116 } 00117 00118 distinctValues.Add(value1); 00119 globalCount += count; 00120 } 00121 } 00122 00123 } 00124 00128 public struct VelocityChannel 00129 { 00130 Vector3[] values; 00131 Vector3 minVal; 00132 Vector3 maxVal; 00133 00134 #region Properties 00135 public Vector3[] VelocityValues 00136 { 00137 set { values = value; } 00138 get { return values; } 00139 } 00140 00141 public Vector3 MinValue 00142 { 00143 set { minVal = value; } 00144 get { return minVal; } 00145 } 00146 00147 public Vector3 MaxValue 00148 { 00149 set { maxVal = value; } 00150 get { return maxVal; } 00151 } 00152 #endregion 00153 00154 public VelocityChannel(int dimX, int dimY) 00155 { 00156 values = new Vector3[dimX * dimY]; 00157 minVal = Vector3.Zero; 00158 maxVal = Vector3.Zero; 00159 } 00160 00161 00162 } 00163 00167 public struct FlowChannel 00168 { 00169 VelocityChannel velocity; 00170 SingleChannel[] addChannels; 00171 00172 int timestepIdx; 00173 00174 //float timestep; 00175 00176 #region Properties 00177 public VelocityChannel Velocity 00178 { 00179 get { return velocity; } 00180 set { velocity = value; } 00181 } 00182 00183 public SingleChannel[] AddChannels 00184 { 00185 get { return addChannels; } 00186 set { addChannels = value; } 00187 } 00188 00189 public int TimestepIdx 00190 { 00191 get { return timestepIdx; } 00192 set { timestepIdx = value; } 00193 } 00194 #endregion 00195 00196 00197 #region Contructor 00198 public FlowChannel(int xDim, int yDim, int addChannelsCount, int timestepIndex) 00199 { 00200 velocity = new VelocityChannel(xDim, yDim); 00201 addChannels = new SingleChannel[addChannelsCount]; 00202 for (int i = 0; i < addChannelsCount; i++) 00203 { 00204 addChannels[i] = new SingleChannel(xDim, yDim); 00205 } 00206 timestepIdx = timestepIndex; 00207 00208 } 00209 #endregion 00210 00211 #region Methods 00212 public void setMinVelocity(Vector3 minVal) 00213 { 00214 velocity.MinValue = minVal; 00215 } 00216 00217 public void setMaxVelocity(Vector3 maxVal) 00218 { 00219 velocity.MaxValue = maxVal; 00220 } 00221 00222 public void setChannelMinVal(int channelIdx, float minVal) 00223 { 00224 addChannels[channelIdx].MinValue = minVal; 00225 } 00226 public void setChannelMaxVal(int channelIdx, float maxVal) 00227 { 00228 addChannels[channelIdx].MaxValue = maxVal; 00229 } 00230 #endregion 00231 } 00232 }