// Code to create and display objects goes here.
        public MainWindow()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main Canvas, whose name is "GraphPaper"
            gp = this.FindName("Paper") as GraphPaper;

            // Initialize triangles, texture image, display image
            initTextureImage();
            DrawImage(lowerLeft.X, lowerLeft.Y, textureImage, sourceSize, sourceSize);
            double[] s = new double[3];
            barycentricCoordinates(A.X, A.Y, s);
            barycentricCoordinates(B.X, B.Y, s);
            barycentricCoordinates(C.X, C.Y, s);

            initializeBarycentricCoords();
            initDisplayImage();

            displayRects = DrawImage(0, 0, displayImage, targetSize, targetSize);
            updateDisplayImage();

            rightTriangle = makeTri(A, B, C);
            initDraggableTriangle();
            gp.Children.Add(rightTriangle);

            // fix so that when the dots move, the DisplayImage is updated...

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #2
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;


            // A triangle, whose top point can be moved using the slider.
            bgr = new Rectangle
            {
                Width  = 50.0,
                Height = 50.0,
                Fill   = new SolidColorBrush(Color.FromArgb(255, bgrInitialColor, bgrInitialColor, bgrInitialColor))
            };
            gp.Children.Add(bgr);

            stripeCanvas = new Canvas();
            gp.Children.Add(stripeCanvas);

            RecreateStripes();

            ready = true;             // Now we're ready to have sliders and buttons influence the display.
        }
Пример #3
0
        /// <summary>
        /// Create and display the objects (a set of axes, three points, and a circle passing through the three points).
        /// </summary>
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();
            // Now add some graphical items in the main Canvas, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            myDots    = new Dot[3];
            myDots[0] = new Dot(new Point(-40, 60));
            myDots[1] = new Dot(new Point(40, 60));
            myDots[2] = new Dot(new Point(40, -60));
            for (int i = 0; i < 3; i++)
            {
                myDots[i].MakeDraggable(gp);
                gp.Children.Add(myDots[i]);
            }
            myCircle = new Circle(new Point(0, 0), 0.0);
            updateCircle(myDots[0].Position, myDots[1].Position, myDots[2].Position);
            gp.Children.Add(myCircle);
        }
Пример #4
0
        /// <summary>
        /// Create and display the objects (a set of axes, three points, and a circle passing through the three points).
        /// </summary>
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();
            // Now add some graphical items in the main Canvas, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            myDots    = new Dot[3];
            myDots[0] = new Dot(new Point(-40, 60));
            myDots[1] = new Dot(new Point(40, 60));
            myDots[2] = new Dot(new Point(40, -60));
            for (int i = 0; i < 3; i++)
            {
                myDots[i].MakeDraggable(gp);
                gp.Children.Add(myDots[i]);
            }
            myCircle = new Circle(new Point(0, 0), 0.0);
            updateCircle(myDots[0].Position, myDots[1].Position, myDots[2].Position);
            gp.Children.Add(myCircle);

            DependencyPropertyDescriptor dotDescr = DependencyPropertyDescriptor.FromProperty(Dot.PositionProperty, typeof(Dot));

            if (dotDescr != null)
            {
                dotDescr.AddValueChanged(myDots[0], OnDotMove);
                dotDescr.AddValueChanged(myDots[1], OnDotMove);
                dotDescr.AddValueChanged(myDots[2], OnDotMove);
            }
        }
Пример #5
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();
            // Now add some graphical items in the main Canvas, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;

            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;


            #region Images

            initializeImages();

            gp.Children.Add(original);
            gp.Children.Add(damaged);
            gp.Children.Add(restored);
            #endregion
            #region Text label

            myText          = new Text("Improvements: " + improvementCount.ToString());
            myText.Position = new Point(5, 5);
            gp.Children.Add(myText);

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #6
0
        bool ready    = false; // Flag for allowing sliders, etc., to influence display.
        public MainWindow()
        {
            InitializeComponent();
            InitializeCommands();
            // Now add some graphical items in the main Canvas, whose name is "GraphPaper"
            gp = this.FindName("Paper") as GraphPaper;
            // Build a table of vertices:
            const int nPoints = 8;
            const int nEdges  = 12;

            double[,] vtable = new double[nPoints, 3]
            {
                { -0.5, -0.5, 2.5 },
                { -0.5, 0.5, 2.5 },
                { 0.5, 0.5, 2.5 },
                { 0.5, -0.5, 2.5 },
                { -0.5, -0.5, 3.5 },
                { -0.5, 0.5, 3.5 },
                { 0.5, 0.5, 3.5 },
                { 0.5, -0.5, 3.5 }
            };
            // Build a table of edges
            int [,] etable = new int[nEdges, 2] {
                { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, // one face
                { 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 }, // joining edges
                { 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 }
            };                                          // opposite face
            double xmin = -0.5;
            double xmax = 0.5;
            double ymin = -0.5;
            double ymax = 0.5;

            Point [] pictureVertices = new Point[nPoints];
            double   scale           = 100;

            for (int i = 0; i < nPoints; i++)
            {
                double x      = vtable[i, 0];
                double y      = vtable[i, 1];
                double z      = vtable[i, 2];
                double xprime = x / z;
                double yprime = y / z;
                pictureVertices[i].X = scale * (1 - (xprime - xmin) / (xmax - xmin));
                pictureVertices[i].Y = scale * (yprime - ymin) / (ymax - ymin); // x / z
                gp.Children.Add(new Dot(pictureVertices[i].X, pictureVertices[i].Y));
            }
            for (int i = 0; i < nEdges; i++)
            {
                int n1 = etable[i, 0];
                int n2 = etable[i, 1];
                gp.Children.Add(new Segment(pictureVertices[n1], pictureVertices[n2]));
            }
            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #7
0
        public MainWindow()
        {
            InitializeComponent();
            InitializeCommands();

            gp = this.FindName("Paper") as GraphPaper;
            ResetTransformation();
            geometryStartingIndex = gp.Children.Count;
            shapeFile             = "geometry/cube.json";

            RebuildGeometry();

            ready = true;             // Now we're ready to have sliders and buttons influence the display.
        }
Пример #8
0
        // Code to create and display objects goes here.

        /// <summary>
        /// Create a window containing a polygon (with no vertices) to which the user can ad verts with
        /// left-clicks. A click on the "subdivide" button makes a subdivided polygon appear in dark red,
        /// with the original in black. Subsequent clicks make the red polygon black, and create a new
        /// sub-sub-divided polygon, and so on.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            InitializeCommands();
            InitializeInteraction();

            // Now add some graphical items in the main Canvas, whose name is "GraphPaper"
            gp = this.FindName("Paper") as GraphPaper;
            initPoly(myPolygon, Brushes.Black);
            initPoly(mySubdivPolygon, Brushes.Firebrick);
            gp.Children.Add(myPolygon);
            gp.Children.Add(mySubdivPolygon);

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #9
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            myDots      = new List <Dot>();
            graph       = new Dictionary <Tuple <Dot, Dot>, Segment>();
            myTriangle  = new List <int>();
            myTriangles = new Dictionary <Tuple <int, int, int>, Polygon>();

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #10
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            myDots                     = new List <Dot>();
            myPolyline                 = new Polyline();
            myPolyline.Stroke          = Brushes.Black;
            myPolyline.StrokeThickness = 0.25; // 0.25 mm thick line
            gp.Children.Add(myPolyline);

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #11
0
        // Code to create and display objects goes here.
        public MainWindow()
        {
            InitializeComponent();
            InitializeCommands();
            InitializeInteraction();

            // Now add some graphical items in the main Canvas, whose name is "GraphPaper"
            gp = this.FindName("Paper") as GraphPaper;

            #region Triangles, segments, dots
            // A triangle, whose top point will be dragged by the slider.
            myPolygon = new Polygon();
            //myPolygon.Points.Add(new Point(0, 0));
            myPolygon.Stroke           = Brushes.Black;
            myPolygon.StrokeThickness  = 0.25; // 0.25 mm thick line
            myPolygon.StrokeMiterLimit = 1;    // no long pointy bits at vertices
            myPolygon.Fill             = Brushes.LightSeaGreen;
            gp.Children.Add(myPolygon);

            #endregion


            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #12
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaperAlt;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            #region Triangles, segments, dots
            // A triangle, whose top point will be dragged by the slider.
            myTriangle = new Polygon();
            myTriangle.Points.Add(new Point(0, 10));
            myTriangle.Points.Add(new Point(10, 0));
            myTriangle.Points.Add(new Point(0, -10));
            myTriangle.Points.Add(new Point(-10, 0));

            myTriangle.Stroke          = Brushes.Black;
            myTriangle.StrokeThickness = 1; // 1 mm thick line
            myTriangle.Fill            = Brushes.LightSeaGreen;
            gp.Children.Add(myTriangle);

            // A draggable Dot, which is the basepoint of an arrow.
            Dot dd = new Dot(new Point(-40, 60));
            dd.MakeDraggable(gp);
            gp.Children.Add(dd);

            Circle cc = new Circle(20, 20, 20); // This circle wasn't included in the first testbed!
            gp.Children.Add(cc);

            Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END);
            gp.Children.Add(ee);

            // a dot and a segment that's attached to it; the dot is animated
            Dot p1 = new Dot(new Point(20, 20));
            gp.Children.Add(p1);
            Point   p2        = new Point(50, 50);
            Segment mySegment = new Segment(p1, p2);
            gp.Children.Add(mySegment);

            PointAnimation animaPoint1 = new PointAnimation(
                new Point(-20, -20),
                new Point(-40, 20),
                new Duration(new TimeSpan(0, 0, 5)));
            animaPoint1.AutoReverse    = true;
            animaPoint1.RepeatBehavior = RepeatBehavior.Forever;
            p1.BeginAnimation(Dot.PositionProperty, animaPoint1);
            #endregion
            #region Images

            // And a photo from a file; note that because our Y-coordinate increases "up",
            // but WPF Y-coordinates increase "down", the photo shows up inverted.
            // We'll add a second photo, right-side-up, afterwards, and a third that's
            // created on-the-fly instead of read from a file.

            myImage1          = new GImage("foo.jpg");
            myImage1.Width    = GraphPaper.wpf(200);
            myImage1.Position = new Point(10, 40);

            gp.Children.Add(myImage1);

            // Create source
            // Now add a second image, based on first building an array of color values
            // Create source array
            byte[, ,] stripes = createStripeImageArray();

            myImage2 = new GImage(stripes);

            // Establish the width and height for this image on the GraphPaper
            myImage2.Width  = GraphPaper.wpf(128);
            myImage2.Height = GraphPaper.wpf(128);

            myImage2.Position = new Point(-40, 20);
            gp.Children.Add(myImage2);

            #endregion
            #region Mesh, Quiver, and Text labels

            myMesh = this.createSampleMesh();
            gp.Children.Add(myMesh);

            Text myText = new Text("THIS IS TEXT", false); // the second arg says that y increases down
            myText.Position = new Point(20, 50);
            gp.Children.Add(myText);

            Text myText2 = new Text("THIS IS UPSIDE DOWN TEXT, because we didn't set the yUp flag to false");
            myText2.Position = new Point(-20, -50);
            gp.Children.Add(myText2);

            myQuiver = makeQuiver();
            foreach (Shape q in myQuiver)
            {
                gp.Children.Add(q);
            }

            #endregion
            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #13
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            #region Triangles, segments, dots
            // A triangle, whose top point can be moved using the slider.
            myTriangle = new Polygon();
            myTriangle.Points.Add(new Point(0, 10));
            myTriangle.Points.Add(new Point(10, 0));
            myTriangle.Points.Add(new Point(-10, 0));
            myTriangle.Stroke          = Brushes.Black;
            myTriangle.StrokeThickness = 1; // 1 mm thick line
            myTriangle.Fill            = Brushes.LightSeaGreen;
            gp.Children.Add(myTriangle);

            // A draggable Dot, which is the basepoint of an arrow.
            Dot dd = new Dot(new Point(-40, 60));
            dd.MakeDraggable(gp);
            gp.Children.Add(dd);

            Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END);
            gp.Children.Add(ee);

            // a dot and a segment that's attached to it; the dot is animated
            Dot p1 = new Dot(new Point(20, 20));
            gp.Children.Add(p1);
            Point   p2        = new Point(50, 50);
            Segment mySegment = new Segment(p1, p2);
            gp.Children.Add(mySegment);

            PointAnimation animaPoint1 = new PointAnimation(
                new Point(-20, -20),
                new Point(-40, 20),
                new Duration(new TimeSpan(0, 0, 5)));
            animaPoint1.AutoReverse    = true;
            animaPoint1.RepeatBehavior = RepeatBehavior.Forever;
            p1.BeginAnimation(Dot.PositionProperty, animaPoint1);
            #endregion
            #region Images

            // And a photo from a file, then another that's
            // created on-the-fly instead of read from a file.

            myImage1          = new GImage("./foo.jpg");
            myImage1.Width    = GraphPaper.wpf(200);
            myImage1.Position = new Point(10, 40);
            Point pq = new Point(10, 40);

            gp.Children.Add(myImage1);

            // Now add a second image, based on first building an array of color values
            // Create source array
            byte[, ,] stripes = createStripeImageArray();

            myImage2 = new GImage(stripes);

            // Establish the width and height for this image on the GraphPaper
            myImage2.Width  = GraphPaper.wpf(128);
            myImage2.Height = GraphPaper.wpf(128);

            myImage2.Position = new Point(-40, 20);
            gp.Children.Add(myImage2);
            #endregion
            #region Mesh, Quiver, and Text labels

            myMesh = this.createSampleMesh();
            gp.Children.Add(myMesh);

            Text myText = new Text("THIS IS TEXT");
            myText.Position = new Point(20, 50);
            gp.Children.Add(myText);

            myQuiver = makeQuiver();
            foreach (Shape q in myQuiver)
            {
                gp.Children.Add(q);
            }

            #endregion
            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }