Example #1
0
 /// <summary>
 /// Compare the value to the defined invalid value.
 /// </summary>
 /// <param name="gridPosition"></param>
 /// <returns></returns>
 public bool IsValid(Index gridPosition)
 {
     return(InvalidValue == null || Sample(gridPosition) != InvalidValue);
 }
Example #2
0
        /// <summary>
        /// Get the derivative at a data point. Not checking for InvalidValue.
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public SquareMatrix SampleDerivative(Index pos)
        {
            //Debug.Assert(NumVectorDimensions == Size.Length);
            int          size     = Math.Max(Size.Length, NumVectorDimensions);
            SquareMatrix jacobian = new SquareMatrix(size);

            // For all dimensions, so please reset each time.
            Index samplePos = new Index(pos);

            for (int dim = 0; dim < Size.Length; ++dim)
            {
                // Just to be sure, check thst no value was overwritten.
                int posCpy = samplePos[dim];

                // See whether a step to the right/left is possible.
                samplePos[dim]++;
                bool rightValid = (samplePos[dim] < Size[dim]) && Scalars[0].Sample(samplePos) != InvalidValue;
                samplePos[dim] -= 2;
                bool leftValid = (samplePos[dim] >= 0) && Scalars[0].Sample(samplePos) != InvalidValue;
                samplePos[dim]++;

                if (rightValid)
                {
                    if (leftValid)
                    {
                        // Regular case. Interpolate.
                        samplePos[dim]++;
                        jacobian[dim]   = Sample(samplePos).ToVec(size);
                        samplePos[dim] -= 2;
                        jacobian[dim]  -= Sample(samplePos).ToVec(size);
                        jacobian[dim]  *= 0.5f;
                        samplePos[dim]++;
                    }
                    else
                    {
                        // Left border.
                        samplePos[dim]++;
                        jacobian[dim] = Sample(samplePos).ToVec(size);
                        samplePos[dim]--;
                        jacobian[dim] -= Sample(samplePos).ToVec(size);
                    }
                }
                else
                {
                    if (leftValid)
                    {
                        // Right border.
                        jacobian[dim] = Sample(samplePos).ToVec(size);
                        samplePos[dim]--;
                        jacobian[dim] -= Sample(samplePos).ToVec(size);
                        samplePos[dim]++;
                    }
                    else
                    {
                        // Weird case.
                        jacobian[dim] = new Vector(0, size);
                    }
                }
                Debug.Assert(posCpy == samplePos[dim]);
            }

            return(jacobian);
        }
Example #3
0
 /// <summary>
 /// Returns a value from the grid.
 /// </summary>
 /// <param name="gridPosition"></param>
 /// <returns></returns>
 public abstract float Sample(Index gridPosition);