Exemplo n.º 1
0
        public override void ClickSelection(Vector2 point)
        {
            if(LineX > 0)
            {
                _lastSelection = (_lastSelection + 1) % LineX;
                Vec3 vec = new Vec3((Vec2)point, 0);
                if (_velocity.Grid.InGrid(vec))
                {
                    Vector3[] line = _integrator.IntegrateLineForRendering(vec).Points.ToArray();
                    Line newLine = new Line() { Positions = line };
                    var set = new LineSet(new Line[] { newLine }) { Color = _flipColor? Vector3.UnitX : Vector3.UnitZ};

                    set.Thickness *= 3;
                    var ball = new LineBall(Plane, set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                    _selections.Add(ball);

                    if (_selections.Count > LineX)
                    {
                        _selections.RemoveAt(0);
                        _selectionsAngle.RemoveAt(0);
                        _steadySelection.RemoveAt(0);
                    }

                    Graph2D[] angle = FieldAnalysis.GetDistanceToAngle(_core, Vector2.Zero, new LineSet(new Line[] { newLine }));
                    Debug.Assert(angle.Length == 1);

                    for(int p = 0; p < newLine.Length; ++p)
                    {
                    //    if(angle[0].X[p] > _velocity.Size.T - 1)
                    //    {
                    //        newLine.Resize(p);
                    //        break;
                    //    }

                        Vector3 sph = FieldAnalysis.SphericalPosition(_core[0], (float)(angle[0].X[p] * 0.5f / Math.PI), angle[0].Fx[p]);
                        newLine[p] = new Vector3(sph.X, sph.Y, angle[0].X[p] - angle[0].X[0]);
                    }
                    set = new LineSet(new Line[] { newLine }) { Color = _flipColor ? Vector3.UnitX : Vector3.UnitZ };
                    set.Thickness *= 3;
                    ball = new LineBall(Plane, set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                    _selectionsAngle.Add(ball);

                    _integrator.Field = _steadyField;
                    _integrator.MaxNumSteps = 50;
                    line = _integrator.IntegrateLineForRendering(new Vec2(vec.X, vec.Y)).Points.ToArray();
                    newLine = new Line() { Positions = line };
                    set = new LineSet(new Line[] { newLine }) { Color = _flipColor ? Vector3.UnitX : Vector3.UnitZ };
                    set.Thickness *= 3;
                    ball = new LineBall(new Plane(Plane, Vector3.UnitZ * 0.1f), set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                    _steadySelection.Add(ball);
                    _integrator.Field = _velocity;
                    _integrator.MaxNumSteps = 10000;

                    _flipColor = !_flipColor;
                    //var set = new LineSet(_selections.ToArray()) { Color = _selections.Count % 2 == 0 ? Vector3.UnitX : Vector3.UnitY };
                    //_lines = new LineBall(Plane, set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                }
            }
        }
Exemplo n.º 2
0
        protected override void TraceCore(int member = 0, int startSubstep = 0)
        {
            int rad = NEIGHBOORHOOD_CP * (Core == CoreAlgorithm.ROUGH_STREAM_CONNECTION ? 4 : 1);
            string corename = RedSea.Singleton.CoreFileName + member + Core.ToString() + "cc.line";
            if (System.IO.File.Exists(corename))
            {
                GeometryWriter.ReadFromFile(corename, out _cores);
                LoadField(0, MemberMain, 1);
            }
            else
            {
                Vec3[] bases = new Vec3[] {
                    new Vec3(463.1f, 53.6f, 0),
                    new Vec3(366.4f, 34.4f, 0),
                    new Vec3(230.1f, 218.6f, 0)};

                if (Core == CoreAlgorithm.CLICK)
                {
                    Line[] lines = new Line[bases.Length];
                    for(int b = 0; b < bases.Length; ++b)
                        lines[b] = new Line() { Positions = new Vector3[] { (Vector3)bases[b], (Vector3)bases[b] + Vector3.UnitZ * (float)(RedSea.Singleton.NumSubstepsTotal / _everyNthTimestep) } };

                    _cores = new LineSet(lines);
                    LoadField(0, MemberMain, 1);
                    return;
                }

                int numSlices = RedSea.Singleton.NumSubstepsTotal / _everyNthTimestep;
                int stepSize = Core != CoreAlgorithm.ROUGH_STREAM_CONNECTION ? 1 : ROUGH_MULTIPLIER; // RedSea.Singleton.NumSubstepsTotal / _everyNthTimestep - 1;
                _cores = new LineSet(new Line[bases.Length]);
                for (int b = 0; b < _cores.Length; ++b)
                {
                    _cores[b] = new Line((int)Math.Ceiling((float)(numSlices -1)/ stepSize)+1);
                    //_cores[b][0] = (Vector3)bases[b];
                }

                int idx = 0;
                // Connect to other slices.
                for(int slice = 0; slice < numSlices; slice += stepSize)
                {
                    LoadField(Math.Min(slice, numSlices - 2), member, 2);

                    VectorField field = _velocity;
                    if (Core == CoreAlgorithm.PATHLINE)
                    {
                        var acc= new VectorFieldUnsteady(_velocity, FieldAnalysis.Acceleration, 2);
                        field = acc.GetTimeSlice(slice);
                    }
                    else
                    {
                        field = _velocity.GetTimeSlice(slice);
                    }

                    for (int b = 0; b < _cores.Length; ++b)
                    {
                        Vector3 lastCP = idx > 0? _cores[b][idx-1] : (Vector3)bases[b];
                        Int2 x = new Int2((int)lastCP.X - rad, (int)Math.Ceiling(lastCP.X) + rad);
                        Int2 y = new Int2((int)lastCP.Y - rad, (int)Math.Ceiling(lastCP.Y) + rad);
                        CriticalPointSet2D points = FieldAnalysis.ComputeCriticalPointsRegularSubdivision2DRange(field, x, y);

                        float minDist = float.MaxValue;
                        CriticalPoint2D nearest = null;

                        foreach(CriticalPoint2D point in points.Points)
                        {
                            float dist = (lastCP - point.Position).LengthSquared();
                            if(dist< minDist)
                            {
                                minDist = dist;
                                nearest = point;
                            }
                        }

                        _cores[b][idx] = nearest?.Position ?? lastCP;
                        _cores[b].Positions[idx].Z = slice;
                    }
                    idx++;

                    // Reverse-engineered: Always include the last possible slice.
                    if (slice + stepSize >= numSlices && slice + 1 < numSlices)
                        slice = numSlices - 1 - stepSize;
                }
                GeometryWriter.WriteToFile(corename, _cores);
            }
        }
Exemplo n.º 3
0
 public static Vec3 Cross(Vec3 a, Vec3 b)
 {
     Vec3 ret = new Vec3();
     ret[0] = a.Y * b.Z - a.Z * b.Y;
     ret[1] = a.Z * b.X - a.X * b.Z;
     ret[2] = a.X * b.Y - a.Y * b.X;
     return ret;
 }
Exemplo n.º 4
0
 public Vec3(Vec3 copy)
     : base(copy)
 {
 }
Exemplo n.º 5
0
        public override void ClickSelection(Vector2 point)
        {
            if (LineX > 0)
            {
                _lastSelection = (_lastSelection + 1) % LineX;
                Vec3 vec = new Vec3((Vec2)point, 0);
                if (_velocity.Grid.InGrid(vec))
                {
                    Vector3[] line    = _integrator.IntegrateLineForRendering(vec).Points.ToArray();
                    Line      newLine = new Line()
                    {
                        Positions = line
                    };
                    var set = new LineSet(new Line[] { newLine })
                    {
                        Color = _flipColor? Vector3.UnitX : Vector3.UnitZ
                    };

                    set.Thickness *= 3;
                    var ball = new LineBall(Plane, set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                    _selections.Add(ball);

                    if (_selections.Count > LineX)
                    {
                        _selections.RemoveAt(0);
                        _selectionsAngle.RemoveAt(0);
                        _steadySelection.RemoveAt(0);
                    }

                    Graph2D[] angle = FieldAnalysis.GetDistanceToAngle(_core, Vector2.Zero, new LineSet(new Line[] { newLine }));
                    Debug.Assert(angle.Length == 1);

                    for (int p = 0; p < newLine.Length; ++p)
                    {
                        Vector3 sph = FieldAnalysis.SphericalPosition(_core[0], (float)(angle[0].X[p] * 0.5f / Math.PI), angle[0].Fx[p]);
                        newLine[p] = new Vector3(sph.X, sph.Y, angle[0].X[p] - angle[0].X[0]);
                    }
                    set = new LineSet(new Line[] { newLine })
                    {
                        Color = _flipColor ? Vector3.UnitX : Vector3.UnitZ
                    };
                    set.Thickness *= 3;
                    ball           = new LineBall(Plane, set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                    _selectionsAngle.Add(ball);

                    _integrator.Field       = _steadyField;
                    _integrator.MaxNumSteps = 50;
                    line    = _integrator.IntegrateLineForRendering(new Vec2(vec.X, vec.Y)).Points.ToArray();
                    newLine = new Line()
                    {
                        Positions = line
                    };
                    set = new LineSet(new Line[] { newLine })
                    {
                        Color = _flipColor ? Vector3.UnitX : Vector3.UnitZ
                    };
                    set.Thickness *= 3;
                    ball           = new LineBall(new Plane(Plane, Vector3.UnitZ * 0.1f), set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                    _steadySelection.Add(ball);
                    _integrator.Field       = _velocity;
                    _integrator.MaxNumSteps = 10000;

                    _flipColor = !_flipColor;
                    //var set = new LineSet(_selections.ToArray()) { Color = _selections.Count % 2 == 0 ? Vector3.UnitX : Vector3.UnitY };
                    //_lines = new LineBall(Plane, set, LineBall.RenderEffect.DEFAULT, Colormap, false);
                }
            }
        }