/// <summary> /// Returns interpolated value based on the <paramref name="weights"/> /// </summary> /// <param name="weights">Interpolation weights</param> /// <param name="elmt1Value">Element 1 value matching <see cref="Weights.Element1Index"/></param> /// <param name="elmt2Value">Element 2 value matching <see cref="Weights.Element2Index"/></param> /// <param name="nodeValue">Node value matching <see cref="Weights.NodeIndex"/></param> /// <returns>Interpolated value</returns> public double GetValue(Weights weights, double elmt1Value, double elmt2Value, double nodeValue) { // Do interpolation inside (element-element-node) triangle, // disregarding any delete values. if (elmt1Value != DelVal) { double value = elmt1Value * weights.Element1Weight; double weight = weights.Element1Weight; if (elmt2Value != DelVal) { CircularValueHandler.ToReference(CircularType, ref elmt2Value, elmt1Value); value += elmt2Value * weights.Element2Weight; weight += weights.Element2Weight; } if (nodeValue != DelVal) { CircularValueHandler.ToReference(CircularType, ref nodeValue, elmt1Value); value += nodeValue * weights.NodeWeight; weight += weights.NodeWeight; } value /= weight; CircularValueHandler.ToCircular(CircularType, ref value); return(value); } return(DelVal); }
/// <summary> /// Interpolate source values to target /// </summary> public void Interpolate(float[] sourceValues, double[] targetValues) { // Loop over all target elements/nodes for (int i = 0; i < _interpData.Length; i++) { InterPData interPData = _interpData[i]; double value = 0; double weight = 0; int[] indices = interPData.Indices; double[] weights = interPData.Weights; if (_circularType != CircularValueTypes.Normal) { // For angular-type data, find reference value double refValue = 0; for (int j = 0; j < indices.Length; j++) { double sourceValue = sourceValues[indices[j]]; if (sourceValue != _deleteValue) { // First one found is good, break out. refValue = sourceValue; break; } } // Loop over all source elements connected to target for (int j = 0; j < indices.Length; j++) { double sourceValue = sourceValues[indices[j]]; if (sourceValue != _deleteValue) { // For angular type values, correct to match reference value CircularValueHandler.ToReference(_circularType, ref sourceValue, refValue); value += sourceValue * weights[j]; weight += weights[j]; } } if (weight == 0) // all element values were delete values { targetValues[i] = _deleteValue; } else { value /= weight; // For angular type values, correct to match angular span. CircularValueHandler.ToCircular(_circularType, ref value); targetValues[i] = value; } } else { // Loop over all source elements connected to target for (int j = 0; j < indices.Length; j++) { double sourceValue = sourceValues[indices[j]]; if (sourceValue != _deleteValue) { value += sourceValue * weights[j]; weight += weights[j]; } } if (weight == 0) // all element values were delete values { targetValues[i] = _deleteValue; } else { value /= weight; targetValues[i] = value; } } } }