Ejemplo n.º 1
0
        public static PointCollection ConvertToPointCollection(int[] values)
        {
            PointCollection points = new PointCollection();

            if (values == null)
            {
                points.Freeze();
                return(points);
            }

            values = SmoothHistogram(values);

            int max = values.Max();


            // first point (lower-left corner)
            points.Add(new Point(0, max));
            // middle points
            for (int i = 0; i < values.Length; i++)
            {
                points.Add(new Point(i, max - values[i]));
            }
            // last point (lower-right corner)
            points.Add(new Point(values.Length - 1, max));
            points.Freeze();
            return(points);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Rebuild connection points.
        /// </summary>
        private void ComputeConnectionPoints()
        {
            var computedPoints = new PointCollection();

            computedPoints.Add(SourceConnectorHotspot);

            var deltaX = Math.Abs(DestConnectorHotspot.X - SourceConnectorHotspot.X);
            var deltaY = Math.Abs(DestConnectorHotspot.Y - SourceConnectorHotspot.Y);

            if (deltaX > deltaY)
            {
                var midPointX = SourceConnectorHotspot.X + ((DestConnectorHotspot.X - SourceConnectorHotspot.X) / 2);
                computedPoints.Add(new Point(midPointX, SourceConnectorHotspot.Y));
                computedPoints.Add(new Point(midPointX, DestConnectorHotspot.Y));
            }
            else
            {
                var midPointY = SourceConnectorHotspot.Y + ((DestConnectorHotspot.Y - SourceConnectorHotspot.Y) / 2);
                computedPoints.Add(new Point(SourceConnectorHotspot.X, midPointY));
                computedPoints.Add(new Point(DestConnectorHotspot.X, midPointY));
            }

            computedPoints.Add(DestConnectorHotspot);
            computedPoints.Freeze();

            Points = computedPoints;
        }
Ejemplo n.º 3
0
        protected ModelVisual3D MakeVisualModel(LoadResult objmesh, ZipArchiveEntry texture)
        {
            var r = new ModelVisual3D();

            r.Content = MakeModel(objmesh, texture);
            Points.Freeze();               // We won't change them anymore
            Normals.Freeze();
            Indices.Freeze();
            TexCoords.Freeze();

            r.Transform = new Transform3DGroup();
            Transform3DGroup     transformGroup = r.Transform as Transform3DGroup;
            TranslateTransform3D translation    = new TranslateTransform3D(
                -(r.Content.Bounds.X + r.Content.Bounds.SizeX / 2),
                -(r.Content.Bounds.Y + r.Content.Bounds.SizeY / 2),
                -(r.Content.Bounds.Z + r.Content.Bounds.SizeZ / 2)
                );

            transformGroup.Children.Add(translation);

            double scale = Math.Abs(1 / (r.Content.Bounds.SizeX));

            scale = Math.Min(scale, Math.Abs(1 / (r.Content.Bounds.SizeY)));
            scale = Math.Min(scale, Math.Abs(1 / (r.Content.Bounds.SizeZ)));
            ScaleTransform3D scaletr = new ScaleTransform3D(scale, scale, scale);

            transformGroup.Children.Add(scaletr);

            return(r);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Rebuild connection points.
        /// </summary>
        private void ComputeConnectionPoints()
        {
            PointCollection computedPoints = new PointCollection();

            computedPoints.Add(this.SourceConnectorHotspot);

            double deltaX = Math.Abs(this.DestConnectorHotspot.X - this.SourceConnectorHotspot.X);
            double deltaY = Math.Abs(this.DestConnectorHotspot.Y - this.SourceConnectorHotspot.Y);

            if (deltaX > deltaY)
            {
                double midPointX = this.SourceConnectorHotspot.X + ((this.DestConnectorHotspot.X - this.SourceConnectorHotspot.X) / 2);
                computedPoints.Add(new Point(midPointX, this.SourceConnectorHotspot.Y));
                computedPoints.Add(new Point(midPointX, this.DestConnectorHotspot.Y));
            }
            else
            {
                double midPointY = this.SourceConnectorHotspot.Y + ((this.DestConnectorHotspot.Y - this.SourceConnectorHotspot.Y) / 2);
                computedPoints.Add(new Point(this.SourceConnectorHotspot.X, midPointY));
                computedPoints.Add(new Point(this.DestConnectorHotspot.X, midPointY));
            }

            computedPoints.Add(this.DestConnectorHotspot);
            computedPoints.Freeze();

            this.Points = computedPoints;
        }
Ejemplo n.º 5
0
 protected static void OnPointsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is ViewportPolylineBase polyline)
     {
         var points = new PointCollection(e.NewValue as IEnumerable <Point> ?? Enumerable.Empty <Point>());
         points.Freeze();
         polyline.Points = points;
     }
 }
        private PointCollection ConvertToPointCollection(int[] values)
        {
            int max = values.Max();

            PointCollection points = new PointCollection();

            points.Add(new Point(0, max));
            for (int i = 0; i < values.Length; i++)
            {
                points.Add(new Point(i, max - values[i]));
            }
            points.Add(new Point(values.Length - 1, max));
            points.Freeze();
            return(points);
        }
Ejemplo n.º 7
0
        public PointCollection GetPoints(int MaxPixelSpan)
        {
            if (PrevValues == null)
            {
                return(null);
            }
            if (Max == Min)
            {
                return(null);
            }
            var k      = (Max - Min) / MaxPixelSpan;
            var Points = PrevValues.Select((x, index) => new Point(index * 10, (MaxPixelSpan - ((x - Min) / k)))).ToList();
            var pc     = new PointCollection(Points);

            pc.Freeze();
            return(pc);
        }
Ejemplo n.º 8
0
        protected void CreateTextCoordinates()
        {
            PointCollection coordsCol = new PointCollection(this.Points.Length);

            for (int x = 0; x < this.Points.GetLength(0); x++)
            {
                for (int y = 0; y < this.Points.GetLength(1); y++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        coordsCol.Add(this.TextureBuilder.GetTextureMapping(this.Points[x, y].Z));
                    }
                }
            }
            coordsCol.Freeze();
            _mesh.TextureCoordinates = coordsCol;
        }
Ejemplo n.º 9
0
        private PointCollection ConvertToPointCollection(int[] values)
        {
            values = SmoothHistogram(values);

            int max = values.Max();

            PointCollection points = new PointCollection();

            // first point (lower-left corner)
            points.Add(new System.Windows.Point(0, max));
            // middle points
            for (int i = 0; i < values.Length; i++)
            {
                points.Add(new System.Windows.Point(i, max - values[i]));
            }
            // last point (lower-right corner)
            points.Add(new System.Windows.Point(values.Length - 1, max));
            points.Freeze();
            return(points);
        }
Ejemplo n.º 10
0
 protected void CreateTextCoordinates()
 {
     if (_linePoints != null && this.TextureBuilder != null)
     {
         PointCollection coordsCol = new PointCollection(_linePoints.Count * 2);
         for (int i = 0; i < _linePoints.Count / 2; i++)
         {
             double j = _linePoints[i * 2].Z;
             j += _linePoints[i * 2 + 1].Z;
             j /= 2.0;
             Point pt = this.TextureBuilder.GetTextureMapping(j);
             for (int k = 0; k < 4; k++)
             {
                 coordsCol.Add(pt);
             }
         }
         coordsCol.Freeze();
         _mesh.TextureCoordinates = coordsCol;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Rebuild connection points.
        /// </summary>
        private void ComputeConnectionPoints()
        {
            const double offset = 120.0;

            double srcDeltaX  = offset;
            double destDeltaX = -offset;

            if (SourceConnector != null)
            {
                if (SourceConnector.Type == ConnectorType.Input ||
                    SourceConnector.Type == ConnectorType.VariableInput)
                {
                    srcDeltaX = -offset;
                }
                else if (SourceConnector.Type == ConnectorType.Output ||
                         SourceConnector.Type == ConnectorType.VariableOutput)
                {
                    srcDeltaX = offset;
                }
            }

            if (DestConnector != null)
            {
                if (DestConnector.Type == ConnectorType.Output ||
                    DestConnector.Type == ConnectorType.VariableOutput ||
                    DestConnector.Type == ConnectorType.VariableInputOutput)
                {
                    destDeltaX = offset;
                }
            }

            PointCollection computedPoints = new PointCollection();

            computedPoints.Add(SourceConnectorHotspot);
            computedPoints.Add(new Point(SourceConnectorHotspot.X + srcDeltaX, SourceConnectorHotspot.Y));
            computedPoints.Add(new Point(DestConnectorHotspot.X + destDeltaX, this.DestConnectorHotspot.Y));
            computedPoints.Add(DestConnectorHotspot);
            computedPoints.Freeze();

            this.Points = computedPoints;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Rebuild connection points.
        /// </summary>
        private void ComputeConnectionPoints()
        {
            PointCollection computedPoints = new PointCollection();

            computedPoints.Add(this.SourceConnectorHotspot);

            double midPointX = this.SourceConnectorHotspot.X + ((this.DestConnectorHotspot.X - this.SourceConnectorHotspot.X) / 2);

            computedPoints.Add(new Point(midPointX, this.SourceConnectorHotspot.Y));
            computedPoints.Add(new Point(midPointX, this.DestConnectorHotspot.Y));

            //Add an extra point to the curve that allows the line into the destination look visually pleasing.
            const double precedingPoint = 2.5;

            if ((this.DestConnectorHotspot.X - precedingPoint) > midPointX)
            {
                computedPoints.Add(new Point(this.DestConnectorHotspot.X - precedingPoint, this.DestConnectorHotspot.Y));
            }

            computedPoints.Add(this.DestConnectorHotspot);
            computedPoints.Freeze();

            this.Points = computedPoints;
        }
Ejemplo n.º 13
0
        private void CreateSurface()
        {
            if (this.Points != null && this.TextureBuilder != null)
            {
                Material           texture     = this.TextureBuilder.CreateTexture();
                int                xWidth      = this.Points.GetLength(0);
                int                yWidth      = this.Points.GetLength(1);
                int                capacity    = (xWidth - 1) * (yWidth - 1);
                Point3DCollection  positions   = new Point3DCollection(capacity);
                Int32Collection    indices     = new Int32Collection(capacity);
                PointCollection    texCoords   = new PointCollection(capacity);
                Vector3DCollection normals     = new Vector3DCollection(capacity);
                int                indiceCount = 0;
                for (int ix = 0; ix < xWidth - 1; ix++)
                {
                    if (!double.IsNaN(this.Points[ix, 0].Z))
                    {
                        if (!double.IsNaN(this.Points[ix + 1, 0].Z))
                        {
                            for (int iy = 0; iy < yWidth - 1; iy++)
                            {
                                // V0-----V3
                                // |       |
                                // |       |
                                // V1-----V2

                                //Add Triangle V0--V1--V2

                                positions.Add(this.Points[ix, iy]);
                                positions.Add(this.Points[ix + 1, iy]);
                                positions.Add(this.Points[ix + 1, iy + 1]);
                                double middleZ   = (this.Points[ix, iy].Z + this.Points[ix + 1, iy].Z + this.Points[ix + 1, iy + 1].Z + this.Points[ix, iy + 1].Z) / 4.0;
                                Point  texturePt = this.TextureBuilder.GetTextureMapping(middleZ);
                                texCoords.Add(texturePt);
                                texCoords.Add(texturePt);
                                texCoords.Add(texturePt);
                                indices.Add(indiceCount++);
                                indices.Add(indiceCount++);
                                indices.Add(indiceCount++);
                                Vector3D normal = MathHelper.CalculateNormal(this.Points[ix + 1, iy + 1], this.Points[ix + 1, iy], this.Points[ix, iy]);
                                normals.Add(normal);
                                normals.Add(normal);
                                normals.Add(normal);

                                //Add Triangle V2--V3-V0

                                positions.Add(this.Points[ix + 1, iy + 1]);
                                positions.Add(this.Points[ix, iy + 1]);
                                positions.Add(this.Points[ix, iy]);
                                texCoords.Add(texturePt);
                                texCoords.Add(texturePt);
                                texCoords.Add(texturePt);
                                indices.Add(indiceCount++);
                                indices.Add(indiceCount++);
                                indices.Add(indiceCount++);
                                Vector3D normal2 = MathHelper.CalculateNormal(this.Points[ix, iy], this.Points[ix, iy + 1], this.Points[ix + 1, iy + 1]);
                                normals.Add(normal2);
                                normals.Add(normal2);
                                normals.Add(normal2);
                            }
                        }
                    }
                }
                positions.Freeze();
                _mesh.Positions = positions;
                indices.Freeze();
                _mesh.TriangleIndices = indices;
                texCoords.Freeze();
                _mesh.TextureCoordinates = texCoords;
                normals.Freeze();
                _mesh.Normals         = normals;
                _model3D.Material     = texture;
                _model3D.BackMaterial = texture;
            }
        }
Ejemplo n.º 14
0
        public Transition3D()
            : base(new Viewport3D())
        {
            // camera to ue
            WrappedElement.Camera = new PerspectiveCamera();

            // the model visual 3D
            ModelVisual3D mv3D = new ModelVisual3D();

            mv3D.Content = new PointLight(Colors.White, new Point3D(0, 0, 0));

            WrappedElement.Children.Add(mv3D);

            MeshGeometry3D    plane     = new MeshGeometry3D();
            Point3DCollection positions = new Point3DCollection();

            positions.Add(new Point3D(-1, -1, 0));
            positions.Add(new Point3D(-1, 1, 0));
            positions.Add(new Point3D(1, 1, 0));
            positions.Add(new Point3D(1, -1, 0));
            positions.Freeze();
            plane.Positions = positions;

            PointCollection textureCoords = new PointCollection();

            textureCoords.Add(new Point(0, 1));
            textureCoords.Add(new Point(0, 0));
            textureCoords.Add(new Point(1, 0));
            textureCoords.Add(new Point(1, 1));
            textureCoords.Freeze();
            plane.TextureCoordinates = textureCoords;

            Int32Collection indices = new Int32Collection();

            indices.Add(0);
            indices.Add(3);
            indices.Add(1);
            indices.Add(1);
            indices.Add(3);
            indices.Add(2);
            indices.Freeze();
            plane.TriangleIndices = indices;

            Material planeMaterial = new DiffuseMaterial(Brushes.Blue);

            planeMaterial.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);

            m_visual3D          = new Viewport2DVisual3D();
            m_visual3D.Geometry = plane;
            m_visual3D.Material = planeMaterial;

            Transform3DGroup transform = new Transform3DGroup();

            m_rotation    = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 35);
            m_scale       = new ScaleTransform3D(0, 0, 0);
            m_translation = new TranslateTransform3D(-2.5, 0, -10);

            transform.Children.Add(m_scale);
            transform.Children.Add(new RotateTransform3D(m_rotation));
            transform.Children.Add(m_translation);

            m_visual3D.Transform = transform;

            WrappedElement.Children.Add(m_visual3D);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Rebuild connection points.
        /// </summary>
        private void ComputeConnectionPoints()
        {
            PointCollection computedPoints = new PointCollection();

            computedPoints.Add(this.SourceConnectorHotspot);

            // get the middle of the arc
            if ((this.SourceConnectorHotspot.X > 0 || this.SourceConnectorHotspot.Y > 0) &&
                (this.DestConnectorHotspot.X > 0 || this.DestConnectorHotspot.Y > 0))
            {
                var startPoint = Points[0];
                var lastPoint  = Points[Points.Count - 1];

                // Make an arc.
                ArcSegment arc = new ArcSegment();
                arc.Point      = lastPoint;
                arc.IsLargeArc = true;

                Size arcRadius = new Size();
                var  distance  = startPoint - lastPoint;
                if (distance.Length < 30)
                {
                    arc.SweepDirection = SweepDirection.Clockwise;
                    arc.IsLargeArc     = true;
                    arcRadius.Width    = 25;
                    arcRadius.Height   = 25;
                }
                else
                {
                    arc.SweepDirection = SweepDirection.Counterclockwise;
                    arc.IsLargeArc     = false;
                    int arcRadiusMin = 100;
                    arcRadius.Width  = Math.Abs(startPoint.X - lastPoint.X);
                    arcRadius.Height = Math.Abs(startPoint.Y - lastPoint.Y);
                    if (arcRadius.Width < arcRadiusMin)
                    {
                        arcRadius.Width = arcRadiusMin;
                    }
                    if (arcRadius.Height < arcRadiusMin)
                    {
                        arcRadius.Height = arcRadiusMin;
                    }
                }
                arc.Size = arcRadius;

                // Make an arc.
                PathFigure fig = new PathFigure();
                fig.IsClosed   = false;
                fig.IsFilled   = false;
                fig.StartPoint = startPoint;
                fig.Segments.Add(arc);

                PathGeometry pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(fig);

                double fractionHalf = 0.5;    //the relative point of the curve
                Point  ptHalf;                //the absolute point of the curve
                Point  tgHalf;                //the tangent point of the curve
                pathGeometry.GetPointAtFractionLength(
                    fractionHalf,
                    out ptHalf,
                    out tgHalf);

                // TODO
                if (distance.Length < 30)
                {
                    ptHalf.X -= 15;
                    ptHalf.Y -= 58;
                }
                else
                {
                    ptHalf.X -= 5;
                    ptHalf.Y += 3;
                }

                computedPoints.Add(ptHalf);

                double fractionArrow = 0.9;    //the relative point of the curve
                Point  ptArrow;                //the absolute point of the curve
                Point  tgArrow;                //the tangent point of the curve
                pathGeometry.GetPointAtFractionLength(
                    fractionArrow,
                    out ptArrow,
                    out tgArrow);

                computedPoints.Add(ptArrow);
            }
            else
            {
                computedPoints.Add(this.SourceConnectorHotspot);
            }

            computedPoints.Add(this.DestConnectorHotspot);
            computedPoints.Freeze();

            this.Points = computedPoints;
            LabelPoint  = new Thickness(computedPoints[1].X, computedPoints[1].Y, 0, 0);
        }
Ejemplo n.º 16
0
        private void UpdateUIRepresentation()
        {
            if (isUpdating)
            {
                return;
            }

            if (plotter == null)
            {
                return;
            }

            IPointDataSource dataSource = DataSource;

            if (dataSource == null)
            {
                return;
            }

            visibleWhileUpdate = plotter.Viewport.Visible;

            isUpdating = true;

            panel.Children.Clear();

            DependencyObject dependencyDataSource = dataSource as DependencyObject;

            if (dependencyDataSource != null)
            {
                DataSource2dContext.SetVisibleRect(dependencyDataSource, plotter.Viewport.Visible);
                DataSource2dContext.SetScreenRect(dependencyDataSource, plotter.Viewport.Output);
            }

            IEnumerable <Point> viewportPoints = dataSource;

            var transform = plotter.Viewport.Transform;

            if (!(transform.DataTransform is IdentityTransform))
            {
                viewportPoints = dataSource.DataToViewport(transform.DataTransform);
            }

            var screenPoints   = viewportPoints.ViewportToScreen(transform);
            var filteredPoints = filters.Filter(screenPoints, plotter.Viewport);

            DataRect bounds = DataRect.Empty;

            double strokeThickness = 3;

            bool  first = true;
            Point lastPointOfPrevLine = new Point();

            int overallCount = 0;

            panel.BeginBatchAdd();

            const int ptsInPolyline = 500;

            foreach (var pointGroup in filteredPoints.Split(ptsInPolyline))
            {
                int ptsCount = ptsInPolyline;

                if (!first)
                {
                    ptsCount++;
                }

                PointCollection pointCollection = new PointCollection(ptsCount);

                if (!first)
                {
                    pointCollection.Add(lastPointOfPrevLine);
                }
                else
                {
                    first = false;
                }

                pointCollection.AddMany(pointGroup);

                overallCount += pointCollection.Count - 1;

                if (pointCollection.Count == 0)
                {
                    break;
                }

                lastPointOfPrevLine = pointCollection[pointCollection.Count - 1];

                pointCollection.Freeze();

                DataRect ithBounds = BoundsHelper.GetViewportBounds(pointCollection.ScreenToViewport(transform));
#if geom
                UIElement line = null;

                StreamGeometry geometry = new StreamGeometry();
                using (var dc = geometry.Open())
                {
                    dc.BeginFigure(pointCollection[0], false, false);
                    dc.PolyLineTo(pointCollection, true, false);
                }
                geometry.Freeze();
                GeometryDrawing drawing = new GeometryDrawing {
                    Geometry = geometry, Pen = new Pen(Brushes.Blue, 1)
                };
                drawing.Freeze();
                DrawingBrush brush = new DrawingBrush {
                    Drawing = drawing
                };
                brush.Freeze();

                var rectangle = new Rectangle {
                    Fill = brush, IsHitTestVisible = false
                };
                Rect ithScreenBounds = ithBounds.ViewportToScreen(transform);
                if (true || ithScreenBounds.Width > 2000 || ithScreenBounds.Height > 2000 || ithScreenBounds.Width < 1 || ithScreenBounds.Height < 1)
                {
                    line = rectangle;
                }
                else
                {
                    Size intSize = new Size((int)ithScreenBounds.Width, (int)ithScreenBounds.Height);
                    rectangle.Measure(intSize);
                    rectangle.Arrange(new Rect(intSize));

                    RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)ithScreenBounds.Width, (int)ithScreenBounds.Height, 96, 96, PixelFormats.Pbgra32);
                    renderBitmap.Render(rectangle);
                    renderBitmap.Freeze();
                    line = new Image {
                        Source = renderBitmap
                    };
                }
#else
                var line = CreateLine();
                line.Points = pointCollection;
#endif

                bounds.Union(ithBounds);

                ViewportRectPanel.SetViewportBounds(line, ithBounds);
#if !geom
                ViewportMarginPanel.SetScreenMargin(line, new Size(strokeThickness / 2, strokeThickness / 2));
#endif
                panel.Children.Add(line);

                isUpdating = false;
            }

            panel.EndBatchAdd();

            Debug.WriteLine("OverallCount = " + (overallCount + 1));

            Viewport2D.SetContentBounds(this, bounds);

            isUpdating = false;
        }