Beispiel #1
0
        private Model3D GetThrusterVisual(Vector3D location)
        {
            // Material
            MaterialGroup material = new MaterialGroup();

            material.Children.Add(new DiffuseMaterial(Brushes.DarkGray));
            material.Children.Add(new SpecularMaterial(Brushes.Gray, 100d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(3, .1, .1, .1);
            geometry.Transform    = new TranslateTransform3D(location);

            // Exit Function
            return(geometry);

            //// Model Visual
            //ModelVisual3D retVal = new ModelVisual3D();
            //retVal.Content = geometry;

            //// Exit Function
            //return retVal;
        }
Beispiel #2
0
        private static ModelVisual3D GetWPFModel(out DiffuseMaterial bodyMaterial, Color color, Color reflectionColor, double reflectionIntensity, double radius, Point3D position)
        {
            // Material
            MaterialGroup materials = new MaterialGroup();

            bodyMaterial = new DiffuseMaterial(new SolidColorBrush(color));
            materials.Children.Add(bodyMaterial);
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(reflectionColor), reflectionIntensity));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = materials;
            geometry.BackMaterial = materials;
            geometry.Geometry     = UtilityWPF.GetSphere_LatLon(5, radius, radius, radius);

            // Transform
            TranslateTransform3D transform = new TranslateTransform3D(position.ToVector());

            // Model Visual
            ModelVisual3D retVal = new ModelVisual3D();

            retVal.Content   = geometry;
            retVal.Transform = transform;

            // Exit Function
            return(retVal);
        }
Beispiel #3
0
        internal static Model3D CreateGeometry(List <MaterialColorProps> materialBrushes, List <EmissiveMaterial> selectionEmissives, Transform3D transform, Color color, SpecularMaterial specular, bool isFinal)
        {
            // Material
            MaterialGroup   material = new MaterialGroup();
            DiffuseMaterial diffuse  = new DiffuseMaterial(new SolidColorBrush(color));

            materialBrushes.Add(new MaterialColorProps(diffuse, color));
            material.Children.Add(diffuse);
            materialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            if (!isFinal)
            {
                EmissiveMaterial selectionEmissive = new EmissiveMaterial(Brushes.Transparent);
                material.Children.Add(selectionEmissive);
                selectionEmissives.Add(selectionEmissive);
            }

            // Geometry Model
            GeometryModel3D retVal = new GeometryModel3D();

            retVal.Material     = material;
            retVal.BackMaterial = material;

            int domeSegments     = isFinal ? 2 : 10;
            int cylinderSegments = isFinal ? 6 : 35;

            retVal.Geometry = UtilityWPF.GetCapsule_AlongZ(cylinderSegments, domeSegments, RADIUSPERCENTOFSCALE, 1d);

            // Transform
            retVal.Transform = transform;

            // Exit Function
            return(retVal);
        }
Beispiel #4
0
        private ShipViewerWindow ShowShipViewer(Swimbot bot, Point clickPoint)
        {
            // Make the camera follow this bean
            //TODO: Place a 2D graphic behind the selected ship
            //TODO: Zoom in on it
            #region Create Viewer

            ShipViewerWindow retVal = new ShipViewerWindow(bot, this);
            retVal.SetColorTheme_Dark_Gradient();

            #endregion

            // Place Viewer
            Point screenClickPoint = UtilityWPF.TransformToScreen(clickPoint, grdViewPort);
            ShipViewerWindow.PlaceViewerInCorner(retVal, screenClickPoint);

            // This places the viewer to the right of where they clicked - which is fine if they can't drag the item
            // around, but it's in the way if they try to move the object
            //Point popupPoint = new Point(windowClickPoint.X + 50, windowClickPoint.Y - (viewer.Height / 3d));
            //popupPoint = UtilityWPF.EnsureWindowIsOnScreen(popupPoint, new Size(viewer.Width, viewer.Height));		// don't let the popup straddle monitors
            //viewer.Left = popupPoint.X;
            //viewer.Top = popupPoint.Y;

            retVal.Show();      // it needs to be shown first to get the size

            return(retVal);
        }
Beispiel #5
0
        public NonlinearRandom()
        {
            InitializeComponent();

            _errorEffect = new DropShadowEffect()
            {
                Color       = UtilityWPF.ColorFromHex("FF0000"),
                BlurRadius  = 4,
                Direction   = 0,
                Opacity     = .5,
                ShadowDepth = 0,
            };

            txtBell2.Text =
                @"0 0
.1 .15
.9 .15
1 1";

            txtBell3.Text =
                @".4 .3
.6 .8";

            try
            {
                RebuildBell3Combo();
            }
            catch (Exception) { }

            _initialized = true;
        }
Beispiel #6
0
        private GeometryModel3D GetArrow(Quaternion rotation)
        {
            GeometryModel3D retVal   = new GeometryModel3D();
            MaterialGroup   material = new MaterialGroup();
            DiffuseMaterial diffuse  = new DiffuseMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier));

            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, diffuse.Brush, this.EditorColors.DraggableModifier));
            material.Children.Add(diffuse);
            SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier_SpecularColor), this.EditorColors.DraggableModifier_SpecularPower);

            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            retVal.Material     = material;
            retVal.BackMaterial = material;

            List <TubeRingBase> rings = new List <TubeRingBase>();

            rings.Add(new TubeRingDome(0, false, 10));
            rings.Add(new TubeRingRegularPolygon(.025, false, .05, .05, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, .05, .05, false));
            rings.Add(new TubeRingRegularPolygon(-.0375, false, .125, .125, false));
            rings.Add(new TubeRingPoint(.2, false));

            RotateTransform3D transform = new RotateTransform3D(new QuaternionRotation3D(rotation));

            retVal.Geometry = UtilityWPF.GetMultiRingedTube(35, rings, true, true, transform);

            return(retVal);
        }
Beispiel #7
0
        private void RedrawGraph(NeatGenome genome)
        {
            IBlackBox box = _experiment.GetBlackBox(genome);

            Color trueColor  = panPlot.TrueColor;
            Color falseColor = panPlot.FalseColor;

            var samples = Enumerable.Range(0, 1000).
                          Select(o =>
            {
                Vector3D pos = Math3D.GetRandomVector(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1));

                box.ResetState();

                //box.InputSignalArray.CopyFrom()
                box.InputSignalArray[0] = pos.X;
                box.InputSignalArray[1] = pos.Y;
                box.InputSignalArray[2] = pos.Z;

                box.Activate();

                double percent = box.OutputSignalArray[0];

                Color color = UtilityWPF.AlphaBlend(trueColor, falseColor, percent);

                return(Tuple.Create(pos.ToPoint(), color));
            });

            panPlot.ClearFrame();
            panPlot.AddDots(samples, .01, false);
        }
Beispiel #8
0
        private void RenderPart()
        {
            ModelVisual3D visual = new ModelVisual3D();

            visual.Content   = this.Part.Model;
            _rotateTransform = new QuaternionRotation3D(Math3D.GetRandomRotation());
            visual.Transform = new RotateTransform3D(_rotateTransform);

            // Pull the camera back far enough to see the part
            double?maxDist = UtilityWPF.GetPointsFromMesh(this.Part.Model).
                             Select(o => o.ToVector().LengthSquared).
                             OrderByDescending(o => o).
                             FirstOrDefault();

            double cameraDist = 2.1;

            if (maxDist != null)
            {
                maxDist = Math.Sqrt(maxDist.Value);

                cameraDist = maxDist.Value * 3;
            }

            _viewport.Children.Add(visual);

            _camera.Position = (_camera.Position.ToVector().ToUnit() * cameraDist).ToPoint();
        }
Beispiel #9
0
        private void InitializeLight()
        {
            _hoverLight = new PointLight(Colors.White, new Point3D(0, 0, 0));
            UtilityWPF.SetAttenuation(_hoverLight, _camera.Position.ToVector().Length * 2d, .95d);

            _selectedLight = new AmbientLight(UtilityWPF.ColorFromHex("808080"));
        }
Beispiel #10
0
        private static Model3D GetAxeSpike(double radius, double length, double scale, double yOffset, MaterialGroup materialMiddle, MaterialGroup materialEdge)
        {
            GeometryModel3D retVal = new GeometryModel3D();

            retVal.Material     = materialEdge;
            retVal.BackMaterial = materialEdge;

            double bevel = radius * .2;

            List <TubeRingBase> tubes = new List <TubeRingBase>();

            tubes.Add(new TubeRingRegularPolygon(0, false, radius, radius * 2, true));
            tubes.Add(new TubeRingPoint(length, false));

            retVal.Geometry = UtilityWPF.GetMultiRingedTube(10, tubes, true, false);

            Transform3DGroup transform = new Transform3DGroup();

            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));      // the tube is built along z, rotate so it's along x

            if (!Math1D.IsNearZero(yOffset))
            {
                transform.Children.Add(new TranslateTransform3D(0, yOffset, 0));
            }

            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

            retVal.Transform = transform;

            return(retVal);
        }
Beispiel #11
0
        private static void AddBezierPlate(int count, BezierSegment3D seg1, BezierSegment3D seg2, Model3DGroup group, Material material)
        {
            // Since the bezier curves will have the same number of points, create a bunch of squares linking them (it's up to the caller
            // to make sure the curves don't cross, or you would get a bow tie)
            Point3D[] rim1 = BezierUtil.GetPoints(count, seg1);
            Point3D[] rim2 = BezierUtil.GetPoints(count, seg2);

            Point3D[] allPoints = UtilityCore.Iterate(rim1, rim2).ToArray();

            List <TriangleIndexed> triangles = new List <TriangleIndexed>();

            for (int cntr = 0; cntr < count - 1; cntr++)
            {
                triangles.Add(new TriangleIndexed(count + cntr, count + cntr + 1, cntr, allPoints));    // bottom left
                triangles.Add(new TriangleIndexed(cntr + 1, cntr, count + cntr + 1, allPoints));        // top right
            }

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();

            geometry.Material     = material;
            geometry.BackMaterial = material;
            geometry.Geometry     = UtilityWPF.GetMeshFromTriangles(triangles.ToArray());

            group.Children.Add(geometry);
        }
Beispiel #12
0
        private static Model3D GetAxeCylinder(double radius, double height, double scale, double yOffset, MaterialGroup material)
        {
            GeometryModel3D retVal = new GeometryModel3D();

            retVal.Material     = material;
            retVal.BackMaterial = material;

            double bevel = radius * .2;

            List <TubeRingBase> tubes = new List <TubeRingBase>();

            tubes.Add(new TubeRingRegularPolygon(0, false, radius - bevel, radius - bevel, true));
            tubes.Add(new TubeRingRegularPolygon(bevel, false, radius, radius, false));
            tubes.Add(new TubeRingRegularPolygon(height - (bevel * 2), false, radius, radius, false));
            tubes.Add(new TubeRingRegularPolygon(bevel, false, radius - bevel, radius - bevel, true));

            retVal.Geometry = UtilityWPF.GetMultiRingedTube(10, tubes, true, true);

            Transform3DGroup transform = new Transform3DGroup();

            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));      // the tube is built along z, rotate so it's along y

            if (!Math1D.IsNearZero(yOffset))
            {
                transform.Children.Add(new TranslateTransform3D(0, yOffset, 0));
            }

            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

            retVal.Transform = transform;

            return(retVal);
        }
Beispiel #13
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            for (int cntr = 1; cntr <= 1; cntr++)
            {
                Color lineColor = UtilityWPF.GetRandomColor(64, 192);

                ScreenSpaceLines3D lineModel = new ScreenSpaceLines3D(false);
                lineModel.Thickness = 1d;
                lineModel.Color     = lineColor;


                Point3D fromPoint = Math3D.GetRandomVector(15d).ToPoint();
                Point3D toPoint   = Math3D.GetRandomVector(15d).ToPoint();


                //lineModel.AddLine(fromPoint, toPoint);
                lineModel.Points.Add(fromPoint);
                lineModel.Points.Add(toPoint);


                _viewport.Children.Add(lineModel);


                lineModel.CalculateGeometry();



                _lastLine = lineModel;
            }
        }
        private void RefreshColors()
        {
            Color color;

            // Background
            color = UtilityWPF.ColorFromHex(txtBackground.Text);
            grdViewPort.Background = new SolidColorBrush(color);

            _material.Children.Clear();

            // Diffuse
            if (chkDiffuse.IsChecked.Value)
            {
                color = UtilityWPF.ColorFromHex(txtDiffuse.Text);
                _material.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
            }

            // Specular
            if (chkSpecular.IsChecked.Value)
            {
                color = UtilityWPF.ColorFromHex(txtSpecular.Text);
                double power = double.Parse(txtSpecularPower.Text);

                _material.Children.Add(new SpecularMaterial(new SolidColorBrush(color), power));
            }

            // Emissive
            if (chkEmissive.IsChecked.Value)
            {
                color = UtilityWPF.ColorFromHex(txtEmissive.Text);
                _material.Children.Add(new EmissiveMaterial(new SolidColorBrush(color)));
            }
        }
Beispiel #15
0
            private void EventSource_MouseDown(object sender, MouseEventArgs e)
            {
                // By capturing the mouse, mouse events will still come in even when they are moving the mouse
                // outside the element/form
                Mouse.Capture(_eventSource, CaptureMode.SubTree);               // I had a case where I used the grid as the event source.  If they clicked one of the 3D objects, the scene would jerk.  But by saying subtree, I still get the event

                _previousPosition2D = e.GetPosition(_eventSource);
                _previousPosition3D = TrackballTransform.ProjectToTrackball(_eventSource.ActualWidth, _eventSource.ActualHeight, _previousPosition2D);

                #region Detect Autoscroll

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                }
                else if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                    }
                    else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                    }
                    else
                    {
                        _autoscroll.StartAutoScroll(_previousPosition2D, UtilityWPF.TransformToScreen(_previousPosition2D, _eventSource));
                    }
                }

                #endregion
            }
Beispiel #16
0
        private void btnBrowseImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect = false;
                dialog.Title       = "Please select an image";
                bool?result = dialog.ShowDialog();
                if (result == null || !result.Value)
                {
                    return;
                }

                BitmapSource bitmap = new BitmapImage(new Uri(dialog.FileName));

                int limit;
                if (chkLimitImageSize.IsChecked.Value && int.TryParse(txtSizeLimit.Text, out limit))
                {
                    bitmap = UtilityWPF.ResizeImage(bitmap, limit);       // this will only resize if it's too big
                }

                originalImage.Source = bitmap;
                _origImageGrays      = null;
            }
            catch (NotSupportedException)
            {
                MessageBox.Show("Not an image file", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #17
0
        private Model3D GetBall()
        {
            GeometryModel3D retVal   = new GeometryModel3D();
            MaterialGroup   material = new MaterialGroup();
            DiffuseMaterial diffuse  = new DiffuseMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier));

            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, diffuse.Brush, this.EditorColors.DraggableModifier));
            material.Children.Add(diffuse);
            SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier_SpecularColor), this.EditorColors.DraggableModifier_SpecularPower);

            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            retVal.Material     = material;
            retVal.BackMaterial = material;
            retVal.Geometry     = UtilityWPF.GetSphere_LatLon(20, .1);

            Transform3DGroup transform = new Transform3DGroup();

            transform.Children.Add(new TranslateTransform3D(_initialOffset * _radius));

            retVal.Transform = transform;

            return(retVal);
        }
Beispiel #18
0
        private static void GetModel_Rod_Klinth(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
        {
            GeometryModel3D geometry = new GeometryModel3D();

            var color = WeaponMaterialCache.GetKlinth(dna.MaterialsForCustomizable);

            finalDNA.MaterialsForCustomizable = color.Item3;

            geometry.Material     = color.Item1;
            geometry.BackMaterial = color.Item1;

            //NOTE: The dimensions shouldn't be randomized.  This should look like a manufactured, almost mass produced product.
            // Also, being a crystal, it needs to appear solid

            List <TubeRingBase> rings = new List <TubeRingBase>();

            rings.Add(new TubeRingPoint(0, false));
            rings.Add(new TubeRingRegularPolygon(.2, false, .75, .75, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(.5, false, .9, .9, false));
            rings.Add(new TubeRingRegularPolygon(1, false, .8, .8, false));
            rings.Add(new TubeRingRegularPolygon(15, false, .8, .8, false));
            rings.Add(new TubeRingRegularPolygon(1, false, .9, .9, false));
            rings.Add(new TubeRingRegularPolygon(.5, false, 1, 1, false));
            rings.Add(new TubeRingRegularPolygon(.3, false, .75, .75, false));
            rings.Add(new TubeRingPoint(.2, false));

            rings = TubeRingBase.FitNewSize(rings, dna.Radius, dna.Radius, dna.Length);

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(5, rings, false, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90)));      // the tube builds along z, but this class wants along x

            geometries.Children.Add(geometry);
        }
Beispiel #19
0
        public ThrustControllerWindow()
        {
            InitializeComponent();

            // Error Effect
            _errorEffect = new DropShadowEffect()
            {
                Color       = UtilityWPF.ColorFromHex("FF8175"),
                BlurRadius  = 9,
                Direction   = 0,
                ShadowDepth = 0,
                Opacity     = .8,
            };

            // ThrusterType Combo
            foreach (ThrusterTypeValues value in Enum.GetValues(typeof(ThrusterTypeValues)))
            {
                cboThrusterTypes.Items.Add(value);
            }
            cboThrusterTypes.SelectedItem = ThrusterTypeValues.Random;

            _graphTimer = new DispatcherTimer()
            {
                Interval  = TimeSpan.FromMilliseconds(150),
                IsEnabled = false,
            };
            _graphTimer.Tick += GraphTimer_Tick;

            _initialized = true;
        }
Beispiel #20
0
            private static Brush GetBrush(MapOctree node, Func <MapOctree, double> getValue, double valueMult, Color color)
            {
                const double MAXOPACITY = .25;

                //if (node.Items.Any(o => o.MapObject is ShipPlayer))
                //{
                //    return new SolidColorBrush(UtilityWPF.ColorFromHex("600000FF"));
                //}

                // Add up the resources
                double resourceValue = getValue(node);

                if (resourceValue.IsNearZero())
                {
                    return(null);
                }

                double area = (node.MaxRange.X - node.MinRange.X) * (node.MaxRange.Y - node.MinRange.Y);

                double opacity = (resourceValue * valueMult) / area;

                if (opacity > 1)
                {
                    opacity = 1;
                }

                Color colorFinal = UtilityWPF.AlphaBlend(color, Colors.Transparent, opacity * MAXOPACITY);

                return(new SolidColorBrush(colorFinal));
            }
Beispiel #21
0
            private static ModelVisual3D BuildDot(bool isStatic)
            {
                Color color = UtilityWPF.ColorFromHex(isStatic ? DOTCOLOR_STATIC : DOTCOLOR);

                // Material
                MaterialGroup materials = new MaterialGroup();

                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));

                // Geometry Model
                GeometryModel3D geometry = new GeometryModel3D();

                geometry.Material     = materials;
                geometry.BackMaterial = materials;
                geometry.Geometry     = UtilityWPF.GetSphere_LatLon(5, DOTRADIUS, DOTRADIUS, DOTRADIUS);

                // Model Visual
                ModelVisual3D retVal = new ModelVisual3D();

                retVal.Content = geometry;

                // Exit Function
                return(retVal);
            }
Beispiel #22
0
        private readonly double _tangent = Math.Tan(Math1D.DegreesToRadians(45 / 2));       // camera's field of view is 45, half of that is a right triangle

        //TODO: If this stays being used, get constants from CameraHelper
        private void ShowCameraView()
        {
            Transform transform = GetMapToCanvasTransform();

            ShipPlayer ship = _map.GetItems <ShipPlayer>(false).First();

            Point3D position     = ship.PositionWorld;
            Point   positionView = transform.Transform(new Point(position.X, -position.Y));

            position = new Point3D(position.X, -position.Y, 0);



            double cameraZ = 30 * ship.Radius;        // multiply by radius so that bigger ships see more



            //tan(theta)=rise/run
            //rise=tan(theta)*run
            double halfWidth = _tangent * cameraZ;

            DrawBox(position, halfWidth, new SolidColorBrush(UtilityWPF.ColorFromHex("70EEEEEE")), transform);


            // These are for the stars

            //double starMin = _boundryMin.Z * 20;
            //double starMax = _boundryMin.Z * 1.5;

            //halfWidth = _tangent * (cameraZ + Math.Abs(starMax));
            //DrawBox(position, halfWidth, Brushes.Orange, transform);

            //halfWidth = _tangent * (cameraZ + Math.Abs(starMin));
            //DrawBox(position, halfWidth, Brushes.Orange, transform);
        }
Beispiel #23
0
        private static GeometryModel3D GetModel_WoodIron_Ring_Band(double ballRadius, double z, System.Windows.Media.Media3D.Material material, TriangleIndexed[] ball, SortedList <string, double> from, SortedList <string, double> to, string prefix)
        {
            const double ENLARGE = 1.04d;

            GeometryModel3D retVal = new GeometryModel3D();

            retVal.Material     = material;
            retVal.BackMaterial = material;

            double bandHeight     = WeaponDNA.GetKeyValue(prefix + "Height", from, to, StaticRandom.NextPercent(ballRadius * .15, .5));
            double bandHeightHalf = bandHeight / 2d;

            // Slice the hull at the top and bottom band z's
            Point3D[] slice1 = Math3D.GetIntersection_Hull_Plane(ball, new Triangle(new Point3D(0, 0, z - bandHeightHalf), new Point3D(1, 0, z - bandHeightHalf), new Point3D(0, 1, z - bandHeightHalf)));
            Point3D[] slice2 = Math3D.GetIntersection_Hull_Plane(ball, new Triangle(new Point3D(0, 0, z + bandHeightHalf), new Point3D(1, 0, z + bandHeightHalf), new Point3D(0, 1, z + bandHeightHalf)));

            // Enlarge those polygons xy, leave z alone
            slice1 = slice1.Select(o => new Point3D(o.X * ENLARGE, o.Y * ENLARGE, o.Z)).ToArray();
            slice2 = slice2.Select(o => new Point3D(o.X * ENLARGE, o.Y * ENLARGE, o.Z)).ToArray();

            // Now turn those two polygons into a 3d hull
            TriangleIndexed[] band = Math3D.GetConvexHull(UtilityCore.Iterate(slice1, slice2).ToArray());

            retVal.Geometry = UtilityWPF.GetMeshFromTriangles(band);

            return(retVal);
        }
Beispiel #24
0
        private static double[] GetTrainingImage(FeatureRecognizer_Image image, ConvolutionBase2D kernel)
        {
            // Enlarge the initial image by the kernel's reduction so that after convolution, it is the desired size
            VectorInt reduction = kernel.GetReduction();

            if (reduction.X != reduction.Y)
            {
                throw new ApplicationException(string.Format("Kernel should be square: {0}x{1}", reduction.X, reduction.Y));
            }

            BitmapSource bitmap = new BitmapImage(new Uri(image.Filename));

            bitmap = UtilityWPF.ResizeImage(bitmap, IMAGESIZE + reduction.X, true);

            Convolution2D retVal = UtilityWPF.ConvertToConvolution(bitmap, 1d);

            if (retVal.Width != retVal.Height)
            {
                retVal = Convolutions.ExtendBorders(retVal, IMAGESIZE + reduction.X, IMAGESIZE + reduction.X);        //NOTE: width or height is already the desired size, this will just enlarge the other to make it square
            }

            retVal = Convolutions.Convolute(retVal, kernel);
            retVal = Convolutions.Abs(retVal);

            // It looks better when it's black on white
            double[] inverted = retVal.Values.
                                Select(o => 1d - o).
                                ToArray();

            return(inverted);
        }
Beispiel #25
0
        private void BackgroundColor_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!_isInitialized)
                {
                    return;
                }

                if (radBackBlack.IsChecked.Value)
                {
                    grid1.Background = Brushes.Black;
                }
                else if (radBackGray.IsChecked.Value)
                {
                    grid1.Background = Brushes.Gray;
                }
                else if (radBackWhite.IsChecked.Value)
                {
                    grid1.Background = Brushes.White;
                }
                else if (radBackGreen.IsChecked.Value)
                {
                    grid1.Background = new SolidColorBrush(UtilityWPF.ColorFromHex("236130"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #26
0
 private void SetInkColor()
 {
     if (radPenDark.IsChecked.Value)
     {
         penAttrib.Color  = UtilityWPF.ColorFromHex("A0A0A0");
         penAttrib.Width  = 45;
         penAttrib.Height = 45;
     }
     else if (radPenMed.IsChecked.Value)
     {
         penAttrib.Color  = UtilityWPF.ColorFromHex("C0C0C0");
         penAttrib.Width  = 25;
         penAttrib.Height = 25;
     }
     else if (radPenLight.IsChecked.Value)
     {
         penAttrib.Color  = UtilityWPF.ColorFromHex("E0E0E0");
         penAttrib.Width  = 10;
         penAttrib.Height = 10;
     }
     else
     {
         MessageBox.Show("", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
         return;
     }
 }
Beispiel #27
0
        private void grdViewPort_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (_clickPlane == null)
                {
                    return;
                }

                // Fire a ray at the mouse point
                Point clickPoint2D = e.GetPosition(grdViewPort);

                RayHitTestParameters clickRay = UtilityWPF.RayFromViewportPoint(_camera, _viewport, clickPoint2D);

                Point3D?hitPoint = Math3D.GetIntersection_Plane_Line(_clickPlane, clickRay.Origin, clickRay.Direction);
                if (hitPoint == null)
                {
                    return;
                }

                _strokes.AddPointToStroke(hitPoint.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #28
0
        private static void DrawImage(Image image, double[] values)
        {
            double widthHeight    = Math.Sqrt(values.Length);  // they should be square
            int    widthHeightInt = widthHeight.ToInt_Round();

            if (!Math1D.IsNearValue(widthHeight, widthHeightInt))
            {
                throw new ApplicationException("Expected square images");
            }

            BitmapSource source;

            //if (isColor)
            //{
            //    source = UtilityWPF.GetBitmap_RGB(example, width, height);
            //}
            //else
            //{
            source = UtilityWPF.GetBitmap(values, widthHeightInt, widthHeightInt);
            //}

            image.Source = source;
            image.Width  = source.PixelWidth;     // if this isn't set, the image will take up all of the width, and be huge
            image.Height = source.PixelHeight;
        }
Beispiel #29
0
        private Tuple <int?, RayHitTestParameters> GetMouseOver(MouseEventArgs e)
        {
            const double MAXHITDISTANCE = .035;

            // Fire a ray from the mouse point
            Point mousePoint = e.GetPosition(grdViewPort);
            var   ray        = UtilityWPF.RayFromViewportPoint(_camera, _viewport, mousePoint);

            var hit = _sketches.Sketches.
                      Select((o, i) => new
            {
                Index    = i,
                Position = o.Position,
                Dot      = Vector3D.DotProduct(ray.Direction, o.Position - ray.Origin)
            }).
                      Where(o => o.Dot > 0). // throwing out points that are behind the camera
                      Select(o => new
            {
                o.Index,
                o.Position,
                Distance = Math3D.GetClosestDistance_Line_Point(ray.Origin, ray.Direction, o.Position)
            }).
                      Where(o => o.Distance <= MAXHITDISTANCE).
                      OrderBy(o => (o.Position - ray.Origin).LengthSquared).
                      FirstOrDefault();

            // Sooooon :)
            //hit?.Index;
            int?hitIndex = hit == null ? (int?)null : hit.Index;

            return(Tuple.Create(hitIndex, ray));
        }
Beispiel #30
0
        private void AddDots(IEnumerable <Point3D> positions, double radius, Color color)
        {
            Model3DGroup group = new Model3DGroup();

            DiffuseMaterial material = new DiffuseMaterial(new SolidColorBrush(color));

            foreach (Point3D position in positions)
            {
                GeometryModel3D model = new GeometryModel3D();
                model.Material = material;

                model.Geometry = UtilityWPF.GetSphere_Ico(radius, 2, true);

                model.Transform = new TranslateTransform3D(position.ToVector());

                group.Children.Add(model);
            }

            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = group;

            _visuals.Add(visual);
            _viewport.Children.Add(visual);
        }