Beispiel #1
0
        /// <summary>
        /// Erstellt ein neues Informationsobjekt für ein 3D-Modell, das eine Kante darstellt.
        /// [base="pipe1", Angles3.Zero, new Vector3 (10,10,10)]
        /// </summary>
        public Pipe(IScreen screen, IGrid grid, Knot knot, Edge edge, Node node1, Node node2)
            : base(screen: screen)
        {
            UniqueKey = edge.ToString ();

            // Weise Knoten und Kante zu
            Knot = knot;
            Edge = edge;
            Grid = grid;

            // Berechne die beiden Positionen, zwischen denen die Kante gezeichnet wird
            PositionFrom = node1;
            PositionTo = node2;

            // Kanten sind verschiebbar und auswählbar
            IsMovable = true;
            IsSelectable = true;

            // Berechne die Drehung
            Rotation += RotationMap [Edge.Direction];

            // Aktualisiere die Kategorie
            Coloring.OnColorChanged += UpdateCategory;
            IsSingleColored = true;

            incomplete = true;
        }
Beispiel #2
0
 public void DeleteSpline()
 {
     if(selectedKnot != null){
         Destroy(selectedKnot.myParentSpline);
         selectedKnot = null;
         SetInputFields();
     }
 }
Beispiel #3
0
 public static Knot generateComplexKnot(string name)
 {
     Edge[] edgeList = new Edge[] {
         Edge.Up, Edge.Backward, Edge.Right, Edge.Forward, Edge.Down, Edge.Left
     };
     KnotMetaData metaData = new KnotMetaData (name, edgeList.Count<Edge>, null, null);
     Knot complexKnot = new Knot (metaData, edgeList);
     return complexKnot;
 }
Beispiel #4
0
 public static Knot generateInvalidKnot()
 {
     Edge[] edgeList = new Edge[] {
         Edge.Up, Edge.Up, Edge.Up, Edge.Up
     };
     KnotMetaData metaData = new KnotMetaData ("Invalid", edgeList.Count<Edge>, null, null);
     Knot invalidKnot = new Knot (metaData, edgeList);
     return invalidKnot;
 }
Beispiel #5
0
 /// <summary>
 /// Erstellt ein neues Objekt und setzt die \glqq Name\grqq~- und \glqq Edge\grqq~-Eigenschaften auf die
 /// im angegebenen Knoten enthaltenen Werte.
 /// </summary>
 public KnotStringIO(Knot knot)
 {
     Name = knot.Name;
     try {
         edgeLines = ToLines (knot);
     }
     catch (Exception ex) {
         Log.Debug (ex);
     }
 }
Beispiel #6
0
 public KnotStringIO(Knot knot)
 {
     Name = knot.Name;
     try {
         edgeLines = ToLines (knot);
     }
     catch (Exception ex) {
         Console.WriteLine (ex);
     }
 }
Beispiel #7
0
        public static Knot coloredKnot(string name)
        {
            string content = "\nY#FF0000FF#\nZ#FF0000FF#\ny#FF0000FF#\nz#FF0000FF#";
            content = name + content;

            KnotStringIO stringIO = new KnotStringIO (content);

            KnotMetaData metaData = new KnotMetaData (name, stringIO.Edges.ToList ().Count<Edge>, null, null);
            Knot coloredKnot = new Knot (metaData, stringIO.Edges.ToList ());
            return coloredKnot;
        }
Beispiel #8
0
 public void Save(Knot knot)
 {
     KnotStringIO parser = new KnotStringIO (knot);
     Console.WriteLine ("KnotFileIO.Save(" + knot + ") = #" + parser.Content.Length);
     if (knot.MetaData.Filename == null) {
         throw new IOException ("Error! knot has no filename: " + knot);
     }
     else {
         File.WriteAllText (knot.MetaData.Filename, parser.Content);
     }
 }
Beispiel #9
0
        public static void generateTestKnots()
        {
            Knot knot = null;
            string knotName = null;

            foreach (int knotLength in SquareKnot_TestLengths) {
                knotName = "Square-Knot_" + knotLength;
                knot = KnotGenerator.generateSquareKnot (knotLength / 4, knotName);
                Console.WriteLine ("Generating SK: " + knot.MetaData.Filename);
            }

            // todo: einstellen, dass die Testknoten nicht bei den Savegames landen.

            //knotFileIO.Save (knot);
        }
Beispiel #10
0
    Vector3 GetCurrentPointSimpleLine(Knot from,Knot to,float _t)
    {
        // line
        Vector2 result = to.position-from.position;
        result = from.position + result.normalized*result.magnitude*_t;

        return result;
    }
Beispiel #11
0
 public void RemoveKnot(Knot _knot)
 {
     if(!knots.Contains(_knot))
         return;
     knots.Remove(_knot);
 }
Beispiel #12
0
 private void OnKnotMoved(Knot newKnot)
 {
     OnEdgesChanged ();
     _playerKnot = newKnot;
     registerCurrentKnot ();
 }
Beispiel #13
0
    Vector3 GetCurrentPointsBias(Knot from,Knot to,float _t)
    {
        Vector2 P0= from.position,P1=to.position;
        Vector2 M0,M1;
        M0 = from.M1;
        M1 = to.M0;

        Vector2 result =	(2*(_t*_t*_t) - 3*(_t*_t) + 1)*P0+
                            ((_t*_t*_t)-2*(_t*_t)+_t)*M0+
                            (-2*(_t*_t*_t)+3*(_t*_t))*P1+
                            ((_t*_t*_t)-(_t*_t) )* M1;
        //result = from.position + result.normalized*result.magnitude*_t;

        return result;
    }
Beispiel #14
0
        // TODO (jemand): Wir brauchen hier noch eine bessere Lösung / Überladungen / Umgang mit "FakeKnots"
        public static Knot generateSquareKnot(int EdgeLength, string name)
        {
            Edge[] edgeList = new Edge [EdgeLength * 4];

            for (int i = 0; i < EdgeLength; i++) {
                edgeList [i] = Edge.Up;
            }
            for (int i = EdgeLength; i < EdgeLength*2; i++) {
                edgeList [i] = Edge.Right;
            }
            for (int i = EdgeLength *2; i < EdgeLength*3; i++) {
                edgeList [i] = Edge.Down;
            }
            for (int i = EdgeLength *3; i < EdgeLength*4; i++) {
                edgeList [i] = Edge.Left;
            }
            KnotMetaData metaData = new KnotMetaData (name, edgeList.Count<Edge>, null, null);
            Knot squareKnot = new Knot (metaData, edgeList);

            return squareKnot;
        }
Beispiel #15
0
 public void AddKnot(Knot knot)
 {
     knot.subKnots = new CatmullRomSpline.SubKnot[NbSubSegmentPerSegment + 1];
     knots.Add (knot);
 }
Beispiel #16
0
 void ProcessLeftButton()
 {
     if(Input.GetMouseButton(0) && Service.IsMouseInsideArea()){
         pressDownTimer +=Time.deltaTime;
         Knot _knot = GetReturnedKnot(Input.mousePosition);
         if(_knot != null){
             if(camState != CamStates.pressed){
                 if(selectedKnot != _knot)
                 {
                     _knot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(true);
                     if(selectedKnot != null)
                         selectedKnot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(false);
                 }
                 selectedKnot = _knot;
                 SetInputFields();
                 if(pressDownTimer > PDTToggle && camState != CamStates.pressed){
                     camState = CamStates.drag;
                 }
             }
         }// knot != null
         else{// knot == null
             if(camState != CamStates.drag)
                 if(pressDownTimer > PDTToggle){
                     MainCamScript.CamMove();
                     camState = CamStates.pressed;
                 }
         }// knot == null
     }// mouseButtonpressedDown
     if(Input.GetMouseButtonUp(0)){
         pressDownTimer = 0;
         camState = CamStates.none;
         MainCamScript.CamStopMoving();
         pressDownTimer = 0;
     }
     if(pressDownTimer > PDTToggle && camState == CamStates.drag && Service.IsMouseInsideArea())
         MoveKnot(selectedKnot);
 }
Beispiel #17
0
 /// <summary>
 /// Exportiert den Knoten in einem gültigen 3D-Drucker-Format.
 /// </summary>
 public virtual void Save(Knot knot,bool force)
 {
     throw new System.NotImplementedException ();
 }
Beispiel #18
0
 void DeleteKnot(Knot _knot)
 {
     //_knot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(false);
     Spline _sp = _knot.myParentSpline.GetComponent<Spline>();
     if(_knot.DeleteMe(false)){
         selectedKnot = null;
         _sp.Redraw();
         SetInputFields();
     }
 }
        /// <summary>
        /// Diese Methode wird für jede gefundene Spielstanddatei aufgerufen
        /// </summary>
        private void AddSavegameToList(string filename, KnotMetaData meta)
        {
            // Finde den Namen des Knotens
            string name = meta.Name.Length > 0 ? meta.Name : filename;

            // Erstelle die Lamdafunktionen, die beim Auswählen des Menüeintrags ausgeführt werden
            Action<GameTime> SelectStartKnot = (time) => {
                selectedStartKnot = loader.FileFormat.Load (filename);

                TryConstructChallenge ();
            };

            // Erstelle die Lamdafunktionen, die beim Auswählen des Menüeintrags ausgeführt werden
            Action<GameTime> SelectTargetKnot = (time) => {
                selectedTargetKnot = loader.FileFormat.Load (filename);

                TryConstructChallenge ();
            };

            // Erstelle die Menüeinträge
            MenuEntry buttonStart = new MenuEntry (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: name,
                onClick: SelectStartKnot
            );
            MenuEntry buttonTarget = new MenuEntry (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: name,
                onClick: SelectTargetKnot
            );
            buttonStart.IsSelectable = true;
            buttonTarget.IsSelectable = true;
            buttonStart.IsLocalized = false;
            buttonTarget.IsLocalized = false;

            startKnotMenu.Add (buttonStart);
            targetKnotMenu.Add (buttonTarget);
        }
Beispiel #20
0
 private Vector3 KnotCenter(Knot knot)
 {
     Grid nodeMap = new Grid (screen: this);
     nodeMap.Knot = knot;
     nodeMap.Update ();
     Vector3 center = Vector3.Zero;
     foreach (Edge edge in knot) {
         center += nodeMap.NodeBeforeEdge (edge);
     }
     center /= knot.Count ();
     return center;
 }
        private Point GetFivePointNurbsAverage(int[,] indices)
        {
            var knots = new Knot[] {
                        new Knot(0, 4),
                        new Knot(1, 4)
                    };

            var controlPoints = new ControlPoint[] {
                        new ControlPoint(Point.Create(tabAngles[indices[0,0]][indices[0,1]], GetSpanAt(indices[0,0], indices[0,1]),0), 1),
                        new ControlPoint(Point.Create(tabAngles[indices[1,0]][indices[1,1]], GetSpanAt(indices[1,0], indices[1,1]),0), 1),
                        new ControlPoint(Point.Create(tabAngles[indices[2,0]][indices[2,1]], GetSpanAt(indices[2,0], indices[2,1]),0), 1),
                        new ControlPoint(Point.Create(tabAngles[indices[3,0]][indices[3,1]], GetSpanAt(indices[3,0], indices[3,1]),0), 1),
                        new ControlPoint(Point.Create(tabAngles[indices[4,0]][indices[4,1]], GetSpanAt(indices[4,0], indices[4,1]),0), 1)
                    };

            NurbsData data = new NurbsData(5, false, false, knots);
            NurbsCurve curve = NurbsCurve.CreateFromControlPoints(data, controlPoints);

            Point midpoint = curve.Evaluate(0.5).Point;
            return midpoint;
        }
Beispiel #22
0
 /// <summary>
 /// Erstellt ein Challenge-Objekt aus einem gegebenen Challenge-Metadaten-Objekt.
 /// Erstellt ein Challenge-Objekt aus einer gegebenen Challenge-Datei.
 /// </summary>
 public Challenge(ChallengeMetaData meta, Knot start, Knot target)
 {
     MetaData = meta;
     Start = start;
     Target = target;
 }
Beispiel #23
0
        public static Knot noMetadataKnot(string name)
        {
            string content = "\nY#FF0000FF#\nZ#FF0000FF#\ny#FF0000FF#\nz#FF0000FF#";
            content = name + content;

            KnotStringIO stringIO = new KnotStringIO (content);

            KnotMetaData metaData = null;
            Knot noMeta = new Knot (metaData, stringIO.Edges.ToList ());
            return noMeta;
        }
Beispiel #24
0
 void ProcessRightButton()
 {
     if(Input.GetMouseButtonDown(1)){
             Knot _knot = GetReturnedKnot(Input.mousePosition);
             if(_knot == null)
             {
                 AddKnot();
             }
             else
             {
                 if(selectedKnot != _knot)
                     {
                         _knot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(true);
                         if(selectedKnot != null)
                             selectedKnot.KnotBody.GetComponent<KnotBodyScript>().SetActiveSkin(false);
                         }
                         selectedKnot = _knot;
                         SetInputFields();
                         DeleteKnot(selectedKnot);
                     }
             }
 }
Beispiel #25
0
 // Use this for initialization
 public void SetMyMaster(Knot _k)
 {
     myMaster  = _k;
 }
Beispiel #26
0
 private void OnUndo()
 {
     if (Undo.Count >= 2) {
         Knot current = Undo.Pop ();
         Knot prev = Undo.Peek ();
         Knot previous = prev.Clone () as Knot;
         Knot curr = current.Clone () as Knot;
         Redo.Push (curr);
         _playerKnot = previous;
         registerCurrentKnot ();
         _playerKnot.EdgesChanged += OnEdgesChanged;
         redoButton.IsVisible = true;
     }
     if (Undo.Count == 1) {
         undoButton.IsVisible = false;
     }
 }
        /// <summary>
        /// Initialize the Game.
        /// </summary>
        public override void Initialize()
        {
            // world
            world = new World (this);
            // input
            knotInput = new KnotInputHandler (this, world);
            // overlay
            overlay = new Overlay (this, world);
            // pointer
            pointer = new MousePointer (this);
            // picker
            picker = new ModelMouseHandler (this, world);

            // pipe renderer
            var knotRenderInfo = new GameObjectInfo ();
            knotRenderInfo.Position = Vector3.Zero;
            renderer = new KnotRenderer (this, knotRenderInfo);
            world.Add (renderer as IGameObject);

            // pipe movements
            movement = new EdgeMovement (this, world, knotRenderInfo);
            world.Add (movement as IGameObject);

            // pipe colors
            coloring = new EdgeColoring (this);

            // load nodes
            Node.Scale = 100;
            Knot = new Knot ();
        }
Beispiel #28
0
        private void OnRedo()
        {
            if (Redo.Count >= 1) {
                Knot next = Redo.Pop ();
                Knot push = next.Clone () as Knot;
                //Undo.Push (push);
                Undo.Push (push);
                _playerKnot = next;
                _playerKnot.EdgesChanged += OnEdgesChanged;
                // den Knoten den Inputhandlern und Renderern zuweisen
                registerCurrentKnot ();

                undoButton.IsVisible = true;
            }
            if (Redo.Count == 0) {
                redoButton.IsVisible = false;
            }
        }
Beispiel #29
0
    void MoveKnot(Knot _knot)
    {
        Vector3 tmpVect = MainCamera.ScreenToWorldPoint(Input.mousePosition);

        _knot.knotBodyScript.SetNewPosition(new Vector3(tmpVect.x,tmpVect.y,_knot.KnotBody.transform.position.z));
    }
using System;
using HermiteInterpolation.MathFunctions;
using HermiteInterpolation.Numerics;

using HermiteInterpolation.SplineKnots;
using HermiteInterpolation.Utils;

namespace HermiteInterpolation.Shapes.SplineInterpolation
{
    public class BiquarticHermiteSurface : BicubicHermiteSurface
    {
        private class BiquarticKnotsGenerator : KnotsGenerator
        {
            private readonly KnotsGenerator _baseGenerator;

            public BiquarticKnotsGenerator(KnotsGenerator baseGenerator)
                : base(baseGenerator.Function)
            {
                _baseGenerator = baseGenerator;
            }

            public override KnotMatrix GenerateKnots(SurfaceDimension uDimension, SurfaceDimension vDimension)
            {
                var afvOld = _baseGenerator.GenerateKnots(uDimension/2, vDimension/2);
                
                var uCountNew = uDimension.KnotCount;
                var vCountNew = vDimension.KnotCount;
                var afvNew = new KnotMatrix(uCountNew, vCountNew);

                FillNewKnots(afvNew, afvOld);

                return afvNew;
            }
      
            private void FillNewKnots(KnotMatrix newKnots,
                KnotMatrix oldKnots)
            {
                // z, dx, dy, dxy initialization
                OriginalKnots(newKnots, oldKnots);
                // z, dx, deltay, deltaxy
                VerticalKnots(newKnots);
                // z, Dx, dy, Dxy
                HorizontalKnots(newKnots);
                // z, Dx, deltay, deltaxy
                InnerKnots(newKnots);
            }

            private void InnerKnots(KnotMatrix newKnots)
            {
                for (int i = 1; i < newKnots.Rows; i += 2)
                {
                    for (int j = 1; j < newKnots.Columns; j += 2)
                    {
                        var u0v0 = newKnots[i - 1,j - 1];
                        var u1v0 = newKnots[i,j - 1];
                        var u2v0 = newKnots[i + 1,j - 1];

                        var u0v1 = newKnots[i - 1,j];
                        var u1v1 = new Knot();
                        var u2v1 = newKnots[i + 1,j];

                        var u0v2 = newKnots[i - 1,j + 1];
                        var u1v2 = newKnots[i,j + 1];
                        var u2v2 = newKnots[i + 1,j + 1];

                        var hx = Math.Abs(u2v0.X - u0v0.X) / 2;
                        var hx4 = hx * 4;
                        var hy = Math.Abs(u0v2.Y - u0v0.Y) / 2;
                        var hy4 = hy * 4;
                        var x = u0v1.X + hx;
                        var y = u1v0.Y + hy;

                        u1v1.X = x;
                        u1v1.Y = y;
                        u1v1.Z = Function.Z(x, y);
                        u1v1.Dx = -(3 * (u0v1.Z - u2v1.Z) + hx * (u0v1.Dx + u2v1.Dx)) /
                                 hx4;
                        u1v1.Dy = -(3 * (u1v0.Z - u1v2.Z) + hx * (u1v0.Dx + u1v2.Dx)) /
                                  hy4;
                        u1v1.Dxy = (u0v0.Dxy + u2v0.Dxy + u0v2.Dxy + u2v2.Dxy +
                                    (3 *
                                     ((u0v0.Dy - u2v0.Dy + u0v2.Dy - u2v2.Dy) / hx +
                                      (u0v0.Dx + u2v0.Dx - u0v2.Dx - u2v2.Dx) / hy +
                                      (3 * (u0v0.Z - u2v0.Z - u0v2.Z + u2v2.Z)) / (hx * hy)))) /
                                   16;
                        newKnots[i,j] = u1v1;
                    }
                }
            }

            private void HorizontalKnots(KnotMatrix newKnots)
            {
                for (int i = 1; i < newKnots.Rows; i += 2)
                {
                    for (int j = 0; j < newKnots.Columns; j += 2)
                    {

                        var u0 = newKnots[i - 1,j];
                        var u1 = new Knot();
                        // finished
                        var u2 = newKnots[i + 1,j];

                        var hx = Math.Abs(u2.X - u0.X) / 2;
                        var hx4 = hx * 4;
                        var x = u0.X + hx;
                        var y = u0.Y;

                        u1.X = x;
                        u1.Y = y;
                        u1.Z = Function.Z(x, y);

                        u1.Dy = Function.Dy(x, y);
                        u1.Dx = -(3 * (u0.Z - u2.Z) + hx * (u0.Dx + u2.Dx)) /
                                hx4;
                        u1.Dxy = -(3 * (u0.Dy - u2.Dy) + hx * (u0.Dxy + u2.Dxy)) /
                                 hx4;
                        // finished
                        newKnots[i,j] = u1;
                    }
                }
            }

            private void VerticalKnots(KnotMatrix newKnots)
            {

                for (int i = 0; i < newKnots.Rows; i += 2)
                {
                    for (int j = 1; j < newKnots.Columns; j += 2)
                    {

                        var v0 = newKnots[i,j - 1];
                        var v1 = new Knot();
                        // finished
                        var v2 = newKnots[i,j + 1];

                        var hy = Math.Abs(v2.Y - v0.Y) / 2;
                        var hy4 = hy * 4;
                        var x = v0.X;
                        var y = v0.Y + hy;

                        v1.X = x;
                        v1.Y = y;
                        v1.Z = Function.Z(x, y);
                        v1.Dx = Function.Dx(x, y);
                        v1.Dy = -(3 * (v0.Z - v2.Z) + hy * (v0.Dy + v2.Dy)) /
                                hy4;
                        v1.Dxy = -(3 * (v0.Dx - v2.Dx) + hy * (v0.Dxy + v2.Dxy)) /
                                 hy4;
                        // finished
                        newKnots[i,j] = v1;
                    }
                }
            }

            private static void OriginalKnots(KnotMatrix newKnots, KnotMatrix oldKnots)
            {
                for (var i = 0; i < oldKnots.Rows; i++)
                {
                    for (var j = 0; j < oldKnots.Columns; j++)
                    {
                        newKnots[2 * i,2 * j] = oldKnots[i,j];
                    }
                }
            }
        }


        public BiquarticHermiteSurface(SurfaceDimension uDimension, SurfaceDimension vDimension, MathExpression mathExpression, Derivation derivation = Derivation.Zero) : this(uDimension, vDimension, InterpolativeMathFunction.FromExpression(mathExpression), derivation)
        {
        }

        public BiquarticHermiteSurface(SurfaceDimension uDimension, SurfaceDimension vDimension, InterpolativeMathFunction interpolativeMathFunction, Derivation derivation = Derivation.Zero) : this(uDimension, vDimension, new  DirectKnotsGenerator(interpolativeMathFunction), derivation)
        {
        }

        public BiquarticHermiteSurface(SurfaceDimension uDimension, SurfaceDimension vDimension, KnotsGenerator knotsGenerator, Derivation derivation = Derivation.Zero) : base(uDimension, vDimension, new BiquarticKnotsGenerator(knotsGenerator), derivation)
        {
        }
    }
}