Example #1
0
        /// <summary>
        /// Class to define a slice to be loaded. Dimensions may be either included completely, or only one value is taken.
        /// </summary>
        //public partial class SliceRange
        //{
        //    public SliceRange(LoaderNCF file, RedSea.Variable var) : base()
        //    {
        //        // Query number of dimensions of variable.
        //        int numDims;
        //        NetCDF.ResultCode ncState = NetCDF.nc_inq_varndims(file.GetID(), (int)var, out numDims);
        //        Debug.Assert(ncState == NetCDF.ResultCode.NC_NOERR);
        //        int[] dimIDs = new int[numDims];

        //        // Query relevant dimensions.
        //        ncState = NetCDF.nc_inq_vardimid(file.GetID(), (int)var, dimIDs);
        //        Debug.Assert(ncState == NetCDF.ResultCode.NC_NOERR);

        //        Initialize(dimIDs, var);
        //    }
        //}

        //        public delegate string FilenameFromIndex(int index);
        public static VectorFieldUnsteady LoadTimeSeries(SliceRange[] vars, int starttime, int timelength)
        {
            ScalarField[][] slices = new ScalarField[vars.Length][];
            for (int var = 0; var < vars.Length; ++var)
            {
                slices[var] = new ScalarField[timelength];
            }


            LoaderNCF ncFile;

            for (int time = 0; time < timelength; ++time)
            {
                ncFile = RedSea.Singleton.GetLoaderNCF(time + starttime);// path + (time + 1) + filename);
                for (int var = 0; var < vars.Length; ++var)
                {
                    slices[var][time] = ncFile.LoadFieldSlice(vars[var]);
                }
                ncFile.Close();
            }

            ScalarFieldUnsteady[] scalars = new ScalarFieldUnsteady[vars.Length];
            for (int var = 0; var < vars.Length; ++var)
            {
                scalars[var] = new ScalarFieldUnsteady(slices[var], starttime);
            }

            return(new VectorFieldUnsteady(scalars));
        }
Example #2
0
 public virtual void ScaleToGrid(Vector scale)
 {
     Debug.Assert(Scalars.Length == scale.Length);
     for (int dim = 0; dim < Scalars.Length; ++dim)
     {
         ScalarFieldUnsteady field = _scalarsUnsteady[dim];
         field.ScaleToGrid(scale[dim]);
     }
     SpreadInvalidValue();
 }
Example #3
0
        public override VectorFieldUnsteady LoadTimeVectorField(SliceRange[] slices, int starttime, int timelength)
        {
            ScalarFieldUnsteady[] fields = new ScalarFieldUnsteady[slices.Length];

            for (int i = 0; i < slices.Length; ++i)
            {
                fields[i] = LoadTimeSlices(slices[i]);
            }

            return(new VectorFieldUnsteady(fields));
        }
Example #4
0
        public VectorFieldUnsteady(VectorFieldUnsteady field, VFJFunction function, int outputDim)
        {
            int       scalars  = outputDim;
            FieldGrid gridCopy = field._scalarsUnsteady[0].TimeSlices[0].Grid.Copy();

            _scalarsUnsteady = new ScalarFieldUnsteady[outputDim];

            // Reserve the space.
            for (int comp = 0; comp < outputDim; ++comp)
            {
                ScalarField[] fields = new ScalarField[field.Size.T]; //(field.Grid);

                for (int t = 0; t < field.Size.T; ++t)

                {
                    fields[t] = new ScalarField(gridCopy);
                }

                _scalarsUnsteady[comp]              = new ScalarFieldUnsteady(fields);
                _scalarsUnsteady[comp].TimeOrigin   = field[0].TimeOrigin ?? 0;
                _scalarsUnsteady[comp].InvalidValue = field.InvalidValue;
                _scalarsUnsteady[comp].DoNotScale();
            }

            this.InvalidValue = field.InvalidValue;
            this.TimeOrigin   = field.TimeOrigin;

            Grid = field.Grid.Copy();

            // Since the time component is in the grid size as well, we do not need to account for time specially.
            GridIndex indexIterator = new GridIndex(field.Size);

            foreach (GridIndex index in indexIterator)
            {
                Vector v = field.Sample((int)index);

                if (v[0] == InvalidValue)
                {
                    for (int dim = 0; dim < Scalars.Length; ++dim)
                    {
                        _scalarsUnsteady[dim][(int)index] = (float)InvalidValue;
                    }
                    continue;
                }

                SquareMatrix J         = field.SampleDerivative(index);
                Vector       funcValue = function(v, J);

                for (int dim = 0; dim < Scalars.Length; ++dim)
                {
                    Scalars[dim][(int)index] = funcValue[dim];
                }
            }
        }
Example #5
0
        public static VectorFieldUnsteady LoadTimeSeries(SliceRange[] slices)
        {
            ScalarFieldUnsteady[] fields = new ScalarFieldUnsteady[slices.Length];
            LoaderRaw             loader = new LoaderRaw(RedSea.Variable.VELOCITY_X);

            for (int i = 0; i < slices.Length; ++i)
            {
                fields[i] = loader.LoadTimeSlices(slices[i]);
            }

            return(new VectorFieldUnsteady(fields));
        }
Example #6
0
        public VectorFieldUnsteady(VectorFieldUnsteady field, VFJFunction function, int outputDim)
        {
            int scalars = outputDim;
            FieldGrid gridCopy = field._scalarsUnsteady[0].TimeSlices[0].Grid.Copy();
            _scalarsUnsteady = new ScalarFieldUnsteady[outputDim];

            // Reserve the space.
            for (int comp = 0; comp < outputDim; ++comp)
            {
                ScalarField[] fields = new ScalarField[field.Size.T]; //(field.Grid);

                for (int t = 0; t < field.Size.T; ++t)

                {
                    fields[t] = new ScalarField(gridCopy);
                }

                _scalarsUnsteady[comp] = new ScalarFieldUnsteady(fields);
                _scalarsUnsteady[comp].TimeOrigin = field[0].TimeOrigin ?? 0;
                _scalarsUnsteady[comp].InvalidValue = field.InvalidValue;
                _scalarsUnsteady[comp].DoNotScale();
            }

            this.InvalidValue = field.InvalidValue;
            this.TimeOrigin = field.TimeOrigin;

            Grid = field.Grid.Copy();

            // Since the time component is in the grid size as well, we do not need to account for time specially.
            GridIndex indexIterator = new GridIndex(field.Size);
            foreach (GridIndex index in indexIterator)
            {
                Vector v = field.Sample((int)index);

                if (v[0] == InvalidValue)
                {
                    for (int dim = 0; dim < Scalars.Length; ++dim)
                        _scalarsUnsteady[dim][(int)index] = (float)InvalidValue;
                    continue;
                }

                SquareMatrix J = field.SampleDerivative(index);
                Vector funcValue = function(v, J);

                for (int dim = 0; dim < Scalars.Length; ++dim)
                {
                    Scalars[dim][(int)index] = funcValue[dim];
                }
            }
        }
Example #7
0
 public VectorFieldUnsteady(ScalarFieldUnsteady[] fields)
     : base()
 {
     _scalarsUnsteady = fields;
 }
        public List <Renderable> ShowPaths()
        {
            bool mapLines = false;

            // Setup an integrator.
            VectorField.Integrator intVF = VectorField.Integrator.CreateIntegrator(Velocity, _currentSetting.IntegrationType);
            intVF.MaxNumSteps = 10000;
            intVF.StepSize    = _currentSetting.StepSize;

            if (_lastSetting == null ||
                IntegrationTypeChanged ||
                StepSizeChanged)
            {
                // ~~~~~~~~~~~ Line Integration ~~~~~~~~~~~ \\
                // Clear the raw lines.
                int timeLength = Velocity.Size.T;
                _rawLines = new LineSet[Velocity.Size.T];

                // Initialize the firth
                _rawLines[0] = new LineSet(new Line[0]);
                ScalarField[] lengths = new ScalarField[timeLength];
                lengths[0] = new ScalarField(Velocity.ScalarsAsSFU[0].TimeSlices[0], (v, J) => 0);

                _minLength = new float[timeLength];
                _maxLength = new float[timeLength];

                // Integrate the path line segments between each neighboring pair of time slices.
                for (int time = 1; time < timeLength; ++time)
                {
                    _minLength[time] = float.MaxValue;
                    _maxLength[time] = float.MinValue;

                    // Integrate last points until next time slice.
                    _pathlineSegments[time - 1]       = intVF.Integrate(_intersectTimeSlices[time - 1], false, time)[0];
                    _pathlineSegments[time - 1].Color = Vector3.UnitZ * (float)time / timeLength;

                    //                    if(time == timeLength - 1)
                    _intersectTimeSlices[time] = _pathlineSegments[time - 1].GetValidEndPoints();//VectorField.Integrator.Status.BORDER);
                    //else
                    //    _intersectTimeSlices[time] = _pathlineSegments[time - 1].GetEndPoints(VectorField.Integrator.Status.TIME_BORDER);
                    _points[time] = new PointCloud(Plane, _intersectTimeSlices[time].ToBasicSet());

                    // Set all positions to 0, or invalid value.
                    lengths[time] = new ScalarField(lengths[time - 1], (s, g) => s, false);
                    int i = 0;
                    for (int p = 0; p < _intersectTimeSlices[time].Points.Length; ++p)
                    {
                        EndPoint pP = _intersectTimeSlices[time].Points[p];
                        ++i;
                        // Map floating position to int position.
                        int   iPos        = _fieldPositionOfValidCell[p];
                        float timeStepped = (pP.Position.Z - (time - 1));
                        lengths[time][iPos] += timeStepped > 0 ? pP.LengthLine / timeStepped : 0;
                        float tmp = lengths[time][iPos];
                        _minLength[time] = Math.Min(lengths[time][iPos], _minLength[time]);
                        _maxLength[time] = Math.Max(lengths[time][iPos], _maxLength[time]);


                        if (_minLength[time] < 0 || pP.Status != VectorField.Integrator.Status.TIME_BORDER)
                        {
                            i += 0;
                        }
                        //Console.WriteLine(lengths[time][iPos]);
                    }
                    Console.WriteLine("Integrated lines until time " + time);
                }

                lengths[0]    = new VectorField(Velocity.GetTimeSlice(0), FieldAnalysis.VFLength, 1, false).Scalars[0] as ScalarField;
                _minLength[0] = 0;
                _maxLength[0] = RedSea.Singleton.NumTimeSlices;
                _pathLengths  = new ScalarFieldUnsteady(lengths);
                mapLines      = true;
            }

            if (_lastSetting == null ||
                SliceTimeMainChanged ||
                ShaderChanged)
            {
                ScalarField f = _pathLengths.GetTimeSlice(_currentSetting.SliceTimeMain);
                f.TimeOrigin = 0;
                VectorField vecField;
                switch (_currentSetting.Shader)
                {
                case FieldPlane.RenderEffect.LIC:
                    VectorField slice = Velocity.GetTimeSlice(0);
                    slice.TimeSlice = 0;
                    vecField        = new VectorField(new Field[] { slice.Scalars[0], slice.Scalars[1], f });
                    break;

                case FieldPlane.RenderEffect.LIC_LENGTH:
                    vecField           = Velocity.GetTimeSlice(_currentSetting.SliceTimeMain);
                    vecField.TimeSlice = 0;
                    break;

                default:
                case FieldPlane.RenderEffect.COLORMAP:
                case FieldPlane.RenderEffect.DEFAULT:
                    vecField = new VectorField(new Field[] { f });
                    break;
                }
                _plane = new FieldPlane(Plane, vecField /*Velocity.GetSlice(_currentSetting.SliceTimeReference)*/, _currentSetting.Shader);
            }

            // The line settings have changed. Create new renderables from the lines.
            if (mapLines || LineSettingChanged)
            {
                _lines = new Renderable[_pathlineSegments.Length];

                switch (_currentSetting.LineSetting)
                {
                // Map the vertices to colored points.
                case RedSea.DisplayLines.POINTS_2D_LENGTH:
                    for (int i = 0; i < _pathlineSegments.Length; ++i)
                    {
                        PointSet <Point> linePoints = Velocity.ColorCodeArbitrary(_pathlineSegments[i], RedSea.DisplayLineFunctions[(int)_currentSetting.LineSetting]);
                        _lines[i] = new PointCloud(Plane, linePoints);
                    }
                    break;

                // Render as line.
                default:
                case RedSea.DisplayLines.LINE:
                    for (int i = 0; i < _pathlineSegments.Length; ++i)
                    {
                        _lines[i] = new LineBall(Plane, _pathlineSegments[i]);
                    }
                    break;
                }
            }

            // Set mapping values.
            //_plane.UpperBound = 0; //= (1 + _currentSetting.WindowWidth) * (_maxLength[_currentSetting.SliceTimeMain] - _minLength[_currentSetting.SliceTimeMain]) /2 + _minLength[_currentSetting.SliceTimeMain];
            _plane.UpperBound = _currentSetting.WindowWidth + _currentSetting.WindowStart; ///= _currentSetting.SliceTimeMain;
            //_plane.LowerBound = 0; //= (1 - _currentSetting.WindowWidth) * (_maxLength[_currentSetting.SliceTimeMain] - _minLength[_currentSetting.SliceTimeMain]) /2 + _minLength[_currentSetting.SliceTimeMain];
            _plane.LowerBound = _currentSetting.WindowStart;                               ///= _currentSetting.SliceTimeMain;
            _plane.UsedMap    = _currentSetting.Colormap;
            _plane.SetRenderEffect(_currentSetting.Shader);

            List <Renderable> result = new List <Renderable>(50);

            result.Add(_plane);
            switch (_currentSetting.Tracking)
            {
            case RedSea.DisplayTracking.LINE:
            case RedSea.DisplayTracking.LINE_POINTS:
                Renderable[] lines = new Renderable[_currentSetting.SliceTimeMain];
                Array.Copy(_lines, lines, _currentSetting.SliceTimeMain);
                result = result.Concat(lines).ToList();
                break;

            case RedSea.DisplayTracking.POINTS:
                result.Add(_points[_currentSetting.SliceTimeMain]);
                break;

            case RedSea.DisplayTracking.LINE_SELECTION:
                VectorField.StreamLine <Vector3> line = intVF.IntegrateLineForRendering(new Vec3(_startPoint.X, _startPoint.Y, 0));
                LineSet set = new LineSet(new Line[] { new Line()
                                                       {
                                                           Positions = line.Points.ToArray()
                                                       } });
                if (_currentSetting.Flat)
                {
                    set.FlattenLines(_currentSetting.SliceTimeMain);
                }
                result.Add(new LineBall(Plane, set));
                break;

            default:
                break;
            }

            return(result);
        }
Example #9
0
        public static VectorFieldUnsteady LoadTimeSeries(SliceRange[] slices)
        {
            ScalarFieldUnsteady[] fields = new ScalarFieldUnsteady[slices.Length];
            LoaderRaw loader = new LoaderRaw(RedSea.Variable.VELOCITY_X);
            for (int i = 0; i < slices.Length; ++i)
                fields[i] = loader.LoadTimeSlices(slices[i]);

            return new VectorFieldUnsteady(fields);
        }
Example #10
0
        public override VectorFieldUnsteady LoadTimeVectorField(SliceRange[] slices, int starttime, int timelength)
        {
            ScalarFieldUnsteady[] fields = new ScalarFieldUnsteady[slices.Length];

            for (int i = 0; i < slices.Length; ++i)
                fields[i] = LoadTimeSlices(slices[i]);

            return new VectorFieldUnsteady(fields);
        }
        public List<Renderable> ShowPaths()
        {
            bool mapLines = false;

            // Setup an integrator.
            VectorField.Integrator intVF = VectorField.Integrator.CreateIntegrator(Velocity, _currentSetting.IntegrationType);
            intVF.MaxNumSteps = 10000;
            intVF.StepSize = _currentSetting.StepSize;

            if (_lastSetting == null ||
                IntegrationTypeChanged ||
                StepSizeChanged)
            {
                // ~~~~~~~~~~~ Line Integration ~~~~~~~~~~~ \\
                // Clear the raw lines.
                int timeLength = Velocity.Size.T;
                _rawLines = new LineSet[Velocity.Size.T];

                // Initialize the firth
                _rawLines[0] = new LineSet(new Line[0]);
                ScalarField[] lengths = new ScalarField[timeLength];
                lengths[0] = new ScalarField(Velocity.ScalarsAsSFU[0].TimeSlices[0], (v, J) => 0);

                _minLength = new float[timeLength];
                _maxLength = new float[timeLength];

                // Integrate the path line segments between each neighboring pair of time slices.
                for (int time = 1; time < timeLength; ++time)
                {
                    _minLength[time] = float.MaxValue;
                    _maxLength[time] = float.MinValue;

                    // Integrate last points until next time slice.
                    _pathlineSegments[time-1] = intVF.Integrate(_intersectTimeSlices[time - 1], false, time)[0];
                    _pathlineSegments[time - 1].Color = Vector3.UnitZ * (float)time / timeLength;

                    //                    if(time == timeLength - 1)
                    _intersectTimeSlices[time] = _pathlineSegments[time - 1].GetValidEndPoints();//VectorField.Integrator.Status.BORDER);
                    //else
                    //    _intersectTimeSlices[time] = _pathlineSegments[time - 1].GetEndPoints(VectorField.Integrator.Status.TIME_BORDER);
                    _points[time] = new PointCloud(Plane, _intersectTimeSlices[time].ToBasicSet());

                    // Set all positions to 0, or invalid value.
                    lengths[time] = new ScalarField(lengths[time-1], (s, g) => s, false);
                    int i = 0;
                    for (int p = 0; p < _intersectTimeSlices[time].Points.Length; ++p)
                    {
                        EndPoint pP = _intersectTimeSlices[time].Points[p];
                        ++i;
                        // Map floating position to int position.
                        int iPos = _fieldPositionOfValidCell[p];
                        float timeStepped = (pP.Position.Z - (time-1));
                        lengths[time][iPos] += timeStepped > 0 ? pP.LengthLine / timeStepped : 0;
                        float tmp = lengths[time][iPos];
                        _minLength[time] = Math.Min(lengths[time][iPos], _minLength[time]);
                        _maxLength[time] = Math.Max(lengths[time][iPos], _maxLength[time]);

                        if (_minLength[time] < 0 || pP.Status != VectorField.Integrator.Status.TIME_BORDER)
                            i += 0;
                        //Console.WriteLine(lengths[time][iPos]);
                    }
                    Console.WriteLine("Integrated lines until time " + time);
                }

                lengths[0] = new VectorField(Velocity.GetTimeSlice(0), FieldAnalysis.VFLength, 1, false).Scalars[0] as ScalarField;
                _minLength[0] = 0;
                _maxLength[0] = RedSea.Singleton.NumTimeSlices;
                _pathLengths = new ScalarFieldUnsteady(lengths);
                mapLines = true;
            }

            if (_lastSetting == null ||
                SliceTimeMainChanged||
                ShaderChanged)
            {
                ScalarField f = _pathLengths.GetTimeSlice(_currentSetting.SliceTimeMain);
                f.TimeOrigin = 0;
                VectorField vecField;
                switch(_currentSetting.Shader)
                {
                    case FieldPlane.RenderEffect.LIC:
                        VectorField slice = Velocity.GetTimeSlice(0);
                        slice.TimeSlice = 0;
                        vecField = new VectorField(new Field[] { slice.Scalars[0], slice.Scalars[1], f });
                        break;
                    case FieldPlane.RenderEffect.LIC_LENGTH:
                        vecField = Velocity.GetTimeSlice(_currentSetting.SliceTimeMain);
                        vecField.TimeSlice = 0;
                        break;
                    default:
                    case FieldPlane.RenderEffect.COLORMAP:
                    case FieldPlane.RenderEffect.DEFAULT:
                        vecField = new VectorField(new Field[] { f });
                        break;
                }
                _plane = new FieldPlane(Plane, vecField /*Velocity.GetSlice(_currentSetting.SliceTimeReference)*/, _currentSetting.Shader);
            }

            // The line settings have changed. Create new renderables from the lines.
            if (mapLines || LineSettingChanged)
            {
                _lines = new Renderable[_pathlineSegments.Length];

                switch (_currentSetting.LineSetting)
                {
                    // Map the vertices to colored points.
                    case RedSea.DisplayLines.POINTS_2D_LENGTH:
                        for (int i = 0; i < _pathlineSegments.Length; ++i)
                        {
                            PointSet<Point> linePoints = Velocity.ColorCodeArbitrary(_pathlineSegments[i], RedSea.DisplayLineFunctions[(int)_currentSetting.LineSetting]);
                            _lines[i] = new PointCloud(Plane, linePoints);
                        }
                        break;

                    // Render as line.
                    default:
                    case RedSea.DisplayLines.LINE:
                        for (int i = 0; i < _pathlineSegments.Length; ++i)
                        {
                            _lines[i] = new LineBall(Plane, _pathlineSegments[i]);
                        }
                        break;
                }
            }

            // Set mapping values.
            //_plane.UpperBound = 0; //= (1 + _currentSetting.WindowWidth) * (_maxLength[_currentSetting.SliceTimeMain] - _minLength[_currentSetting.SliceTimeMain]) /2 + _minLength[_currentSetting.SliceTimeMain];
            _plane.UpperBound = _currentSetting.WindowWidth + _currentSetting.WindowStart; ///= _currentSetting.SliceTimeMain;
            //_plane.LowerBound = 0; //= (1 - _currentSetting.WindowWidth) * (_maxLength[_currentSetting.SliceTimeMain] - _minLength[_currentSetting.SliceTimeMain]) /2 + _minLength[_currentSetting.SliceTimeMain];
            _plane.LowerBound = _currentSetting.WindowStart; ///= _currentSetting.SliceTimeMain;
            _plane.UsedMap = _currentSetting.Colormap;
            _plane.SetRenderEffect(_currentSetting.Shader);

            List<Renderable> result = new List<Renderable>(50);
            result.Add(_plane);
            switch(_currentSetting.Tracking)
            {
                case RedSea.DisplayTracking.LINE:
                case RedSea.DisplayTracking.LINE_POINTS:
                    Renderable[] lines = new Renderable[_currentSetting.SliceTimeMain];
                    Array.Copy(_lines, lines, _currentSetting.SliceTimeMain);
                    result = result.Concat(lines).ToList();
                    break;
                case RedSea.DisplayTracking.POINTS:
                    result.Add(_points[_currentSetting.SliceTimeMain]);
                    break;
                case RedSea.DisplayTracking.LINE_SELECTION:
                    VectorField.StreamLine<Vector3> line = intVF.IntegrateLineForRendering(new Vec3(_startPoint.X, _startPoint.Y, 0));
                    LineSet set = new LineSet(new Line[] { new Line() { Positions = line.Points.ToArray() } });
                    if(_currentSetting.Flat)
                        set.FlattenLines(_currentSetting.SliceTimeMain);
                    result.Add(new LineBall(Plane, set));
                    break;
                default:
                    break;
            }

            return result;
        }