Example #1
0
        /// <summary>
        /// Convert a LinearElement to a Rhino Brep
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static RC.Brep ConvertToBrep(LinearElement element)
        {
            if (element.Geometry is Line)
            {
                return(ConvertToExtrusion(element)?.ToBrep());
            }
            else
            {
                Curve           perimeter = element?.Family?.Profile?.Perimeter;
                CurveCollection voids     = element?.Family?.Profile?.Voids;
                if (perimeter != null && element.Geometry != null)
                {
                    //TODO: Deal with voids!

                    RC.Curve profile = Convert(perimeter);
                    var      cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation);

                    RC.Plane startPlane = Convert(cSystem.YZPlane());
                    profile.Transform(RC.Transform.PlaneToPlane(RC.Plane.WorldXY, startPlane));
                    RC.Brep[] breps = RC.Brep.CreateFromSweep(Convert(element.Geometry), profile, false, 0.001); //TODO: Change tolerance
                    if (breps.Length > 0)
                    {
                        return(breps[0]);
                    }
                }
            }
            return(null);
        }
Example #2
0
        private void DelaunayButton_Click(object sender, RoutedEventArgs e)
        {
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0);

            int size = 100;

            Geometry.Vector[]  points = box.RandomPointsInside(rng, size);
            VertexCollection   verts  = new VertexCollection(points);
            MeshFaceCollection faces  = Mesh.DelaunayTriangulationXY(verts);

            faces.Quadrangulate();
            //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces);
            //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries();
            CurveCollection          edges    = faces.ExtractFaceBoundaries();
            VertexGeometryCollection geometry = new VertexGeometryCollection();

            foreach (var edge in edges)
            {
                var region = new PlanarRegion(edge);
                geometry.Add(region);
                region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128));
                geometry.Add(edge);
                edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0));
            }
            geometry.Add(new Cloud(verts.ExtractPoints()));
            DelaunayCanvas.Geometry = geometry;
        }
Example #3
0
        private void DelaunayRefine(int scenario)
        {
            var sw = new Stopwatch();

            sw.Start();
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0);

            int size = 50;

            Geometry.Vector[] points;
            if (scenario == 1)
            {
                points = box.RandomPointsInside(rng, size);
            }
            else if (scenario == 2)
            {
                points = new Geometry.Vector[]
                {
                    new Geometry.Vector(10, -9.5),
                    new Geometry.Vector(0, -9.5),
                    new Geometry.Vector(2, -0.5),
                    new Geometry.Vector(8, -0.5)
                    //new Geometry.Vector(4.5,-0.5),
                    //new Geometry.Vector(5.5,-0.5)
                };
            }
            else
            {
                points = new Geometry.Vector[]
                {
                    new Geometry.Vector(10, -6),
                    new Geometry.Vector(10, -2),
                    new Geometry.Vector(0, -6),
                    //new Geometry.Vector(0, -6)
                };
            }
            VertexCollection   verts = new VertexCollection(points);
            MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts);

            faces.Quadrangulate();
            faces = faces.Refine(0.5);
            //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces);
            //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries();
            CurveCollection          edges    = faces.ExtractFaceBoundaries();
            VertexGeometryCollection geometry = new VertexGeometryCollection();

            foreach (var edge in edges)
            {
                var region = new PlanarRegion(edge);
                geometry.Add(region);
                region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128));
                geometry.Add(edge);
                edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0));
            }
            geometry.Add(new Cloud(verts.ExtractPoints()));
            sw.Stop();
            MeshingTimeText.Text    = "Completed: " + faces.Count + " faces in " + sw.Elapsed;
            DelaunayCanvas.Geometry = geometry;
        }
Example #4
0
        protected override Effect GetEffect(FastBitmap source)
        {
            // Get curves either from Curves collection or ACV file.
            CurveCollection curves = GetCurves();

            // Check that there are at least 4 curves.
            if (curves.Count < 4)
            {
                throw new DynamicImageException(
                          "At least 4 curves (corresponding to Composite, Red, Green, Blue) must be specified.");
            }

            // Convert mathematical curve definitions into 4x256 lookup texture (Composite, Red, Green, Blue are the 4 "columns").
            FastBitmap curvesLookup = new FastBitmap(4, 256);

            curvesLookup.Lock();
            for (int x = 0; x < 4; ++x)
            {
                IEnumerable <CurvePoint> points = curves[x].Points.Cast <CurvePoint>();
                float[] xValues     = points.Select(p => (float)p.Input).ToArray();
                float[] yValues     = points.Select(p => (float)p.Output).ToArray();
                float[] derivatives = CubicSplineUtility.CalculateSpline(xValues, yValues);
                for (int y = 0; y < 256; ++y)
                {
                    curvesLookup[x, y] = Color.FromRgb((byte)CubicSplineUtility.InterpolateSpline(xValues, yValues, derivatives, y), 0, 0);
                }
            }
            curvesLookup.Unlock();

            return(new CurvesEffect
            {
                CurvesLookup = new ImageBrush(curvesLookup.InnerBitmap)
            });
        }
Example #5
0
        /// <summary>
        /// Convert a Nucleus Linear Element to a Rhino Extrusion, if possible
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static RC.Extrusion ConvertToExtrusion(LinearElement element)
        {
            Curve           perimeter = element?.Family?.Profile?.Perimeter;
            CurveCollection voids     = element?.Family?.Profile?.Voids;

            if (perimeter != null && element.Geometry != null)
            {
                RC.Curve profile = Convert(perimeter);
                var      cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation);
                if (element.Geometry is Line)
                {
                    //If a line, create an extrusion:
                    RC.Extrusion ext = new RC.Extrusion();
                    ext.SetPathAndUp(
                        Convert(element.Geometry.EndPoint), Convert(element.Geometry.StartPoint),
                        ConvertVector(cSystem.Z));
                    ext.SetOuterProfile(profile, true);
                    if (voids != null)
                    {
                        var voidCrvs = Convert(voids);
                        foreach (var rCrv in voidCrvs)
                        {
                            ext.AddInnerProfile(rCrv);
                        }
                    }
                    //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position)));
                    return(ext);
                }
            }
            return(null);
        }
Example #6
0
        /// <summary>
        /// Convert a Nucleus extrusion volume to a Rhino one
        /// </summary>
        /// <param name="extrusion"></param>
        /// <returns></returns>
        public static RC.Extrusion Convert(Extrusion extrusion)
        {
            if (extrusion.IsValid)
            {
                Curve           perimeter = extrusion.Profile?.Perimeter;
                CurveCollection voids     = extrusion.Profile?.Voids;
                if (perimeter != null)
                {
                    RC.Curve profile = Convert(perimeter);
                    // var cSystem = new CartesianCoordinateSystem(new Vector(), extrusion.Path);
                    //If a line, create an extrusion:
                    RC.Extrusion ext = new RC.Extrusion();

                    ext.SetPathAndUp(new RC.Point3d(0, 0, 0), Convert(extrusion.Path), RC.Vector3d.YAxis); //TODO: Test!
                    //ConvertVector(cSystem.Z));
                    ext.SetOuterProfile(profile, true);
                    if (voids != null)
                    {
                        var voidCrvs = Convert(voids);
                        foreach (var rCrv in voidCrvs)
                        {
                            ext.AddInnerProfile(rCrv);
                        }
                    }
                    //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position)));
                    return(ext);
                }
            }
            return(null);
        }
Example #7
0
        public void CanReadAcvFile()
        {
            // Act.
            CurveCollection curves = PhotoshopCurvesReader.ReadPhotoshopCurvesFile(@"Util\Cross_process___Photoshop__acv_by_LikeGravity.acv");

            // Assert.
            Assert.AreEqual(5, curves.Count);
        }
Example #8
0
 public Track()
 {
     CurveCollection collection = new CurveCollection();
     Curves = collection.CurrentList;
     CurveCollection = collection;
     LithologyCollection lithologyCollection = new LithologyCollection();
     Lithologies = lithologyCollection.CurrentList;
     LithologyCollection = lithologyCollection;
     Width = 400;
 }
Example #9
0
 /// <summary>
 /// Invalidate the stored generated geometry
 /// </summary>
 public override void InvalidateCachedGeometry()
 {
     _Perimeter = null;
     _Voids     = null;
     NotifyPropertyChanged("Perimeter");
     NotifyPropertyChanged("Voids");
     if (Section != null)
     {
         Section.NotifyProfileChanged(this);
     }
 }
Example #10
0
        private void btnOutline_Click(object sender, EventArgs e)
        {
            curveBox.outlines = null;
            var dissolvedCurves = new List <Curve>(CurveTools.Dissolve(curveBox.curves));
            //var cleanedCurves = new List<Curve>(CurveTools.RemoveOrphanedCurves(dissolvedCurves));
            var curves = new CurveCollection(dissolvedCurves).BreakApart();

            curveBox.curves   = new CurveCollection(dissolvedCurves);
            curveBox.outlines = new CurveCollection(curves.GetOutlines());
            curveBox.Invalidate();
        }
Example #11
0
        /// <summary>
        /// Convert a collection of Rhino curves to a CurveCollection
        /// </summary>
        /// <param name="curves"></param>
        /// <returns></returns>
        public static CurveCollection Convert(IList <RC.Curve> curves)
        {
            var result = new CurveCollection();

            foreach (var crv in curves)
            {
                var converted = Convert(crv);
                if (converted != null)
                {
                    result.Add(converted);
                }
            }
            return(result);
        }
Example #12
0
        /// <summary>
        /// Calculate the offset of the profile centroid from the origin (mid) point
        /// </summary>
        /// <returns></returns>
        /// <remarks>This basic version calculates the centroid from the perimeter and voids.
        /// This can be overridden for the sake of efficiency in derived classes to save having
        /// to calculate the centroid for symmetrical types where the offset is always 0,0</remarks>
        protected virtual Vector CalculateCentroidOffset(Curve perimeter, CurveCollection voids)
        {
            Vector centroid;

            if (perimeter != null)
            {
                perimeter.CalculateEnclosedArea(out centroid, voids);
            }
            else
            {
                centroid = new Vector();
            }
            return(centroid);
        }
Example #13
0
        protected override CurveCollection GenerateVoids()
        {
            CurveCollection result = new CurveCollection();

            if (Diameter / 2 > WallThickness)
            {
                Curve voidCrv = new Arc(new Circle(Diameter / 2 - WallThickness));
                if (voidCrv != null)
                {
                    result.Add(voidCrv);
                }
            }
            return(result);
        }
Example #14
0
        protected override CurveCollection GenerateVoids()
        {
            CurveCollection result  = new CurveCollection();
            Curve           voidCrv =
                PolyCurve.Rectangle(
                    Depth - 2 * FlangeThickness,
                    Width - 2 * WebThickness,
                    CornerRadius - Math.Max(FlangeThickness, WebThickness));

            if (voidCrv != null)
            {
                result.Add(voidCrv);
            }
            return(result);
        }
Example #15
0
        /// <summary>
        /// Update the stored geometry properties of this profile
        /// </summary>
        public void GenerateGeometry()
        {
            //Generate initial geometry:
            _Perimeter = GeneratePerimeter();
            _Voids     = GenerateVoids();
            if (_Perimeter != null)
            {
                _CentroidOffset = CalculateCentroidOffset(_Perimeter, _Voids);
                _OriginOffset   = CalculateOriginOffset(_CentroidOffset);

                _Perimeter.Move(_OriginOffset);
                foreach (Curve voidCrv in _Voids)
                {
                    voidCrv.Move(_OriginOffset);
                }
            }
        }
        public static CurveCollection ReadPhotoshopCurvesFile(string filePath)
        {
            CurveCollection curves = new CurveCollection();

            using (Stream fileStream = File.OpenRead(filePath))
            {
                using (BinaryReader reader = new BigEndianBinaryReader(fileStream))
                {
                    // Read version.
                    ushort version = reader.ReadUInt16();
                    //reader.ReadUInt16();

                    // Read number of curves in file.
                    ushort numCurves = reader.ReadUInt16();

                    // Read all curves.
                    for (int i = 0; i < numCurves; ++i)
                    {
                        Curve curve = new Curve();
                        curves.Add(curve);

                        // Read number of points in the curve.
                        ushort numPoints = reader.ReadUInt16();

                        // Read all points.
                        for (int j = 0; j < numPoints; ++j)
                        {
                            // First number is output.
                            ushort output = reader.ReadUInt16();

                            // Second number is input.
                            ushort input = reader.ReadUInt16();

                            curve.Points.Add(new CurvePoint
                            {
                                Input  = input,
                                Output = output
                            });
                        }
                    }
                }
            }

            return(curves);
        }
        public static CurveCollection ReadPhotoshopCurvesFile(string filePath)
        {
            CurveCollection curves = new CurveCollection();

            using (Stream fileStream = File.OpenRead(filePath))
            {
                using (BinaryReader reader = new BigEndianBinaryReader(fileStream))
                {
                    // Read version.
                    ushort version = reader.ReadUInt16();
                    //reader.ReadUInt16();

                    // Read number of curves in file.
                    ushort numCurves = reader.ReadUInt16();

                    // Read all curves.
                    for (int i = 0; i < numCurves; ++i)
                    {
                        Curve curve = new Curve();
                        curves.Add(curve);

                        // Read number of points in the curve.
                        ushort numPoints = reader.ReadUInt16();

                        // Read all points.
                        for (int j = 0; j < numPoints; ++j)
                        {
                            // First number is output.
                            ushort output = reader.ReadUInt16();

                            // Second number is input.
                            ushort input = reader.ReadUInt16();

                            curve.Points.Add(new CurvePoint
                            {
                                Input = input,
                                Output = output
                            });
                        }
                    }
                }
            }

            return curves;
        }
Example #18
0
        private void AnalysisMeshButton_Click(object sender, RoutedEventArgs e)
        {
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(1, 9, -9, -1, 0, 0);

            int size = 100;
            //Geometry.Vector[] points = box.RandomPointsInside(rng, size);
            //VertexCollection verts = new VertexCollection(points);

            VertexCollection verts = new VertexCollection();
            //verts.Add(new Vertex(1, -1));
            int divs = 5;

            for (int i = 0; i <= divs; i++)
            {
                for (int j = 0; j <= divs; j++)
                {
                    Geometry.Vector pt = new Geometry.Vector(box.X.ValueAt(((double)i) / divs), box.Y.ValueAt(((double)j) / divs));
                    verts.Add(new Vertex(pt));
                }
            }

            MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts);

            faces.Quadrangulate();
            //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces);
            //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries();
            CurveCollection          edges    = faces.ExtractFaceBoundaries();
            VertexGeometryCollection geometry = new VertexGeometryCollection();

            foreach (var edge in edges)
            {
                var region = new PlanarRegion(edge);
                geometry.Add(region);
                region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128));
                geometry.Add(edge);
                edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0));
            }
            geometry.Add(new Cloud(verts.ExtractPoints()));
            DelaunayCanvas.Geometry = geometry;
        }
        public override bool Execute(ExecutionInfo exInfo = null)
        {
            Beams = new LinearElementCollection();
            VertexCollection   verts = new VertexCollection(SupportPoints);
            MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts);

            if (Perimeter != null)
            {
                faces.CullOutsideXY(Perimeter);
            }
            faces.Quadrangulate();
            IList <MeshEdge> edges = faces.ExtractUniqueEdges();

            foreach (MeshEdge mE in edges)
            {
                LinearElement lEl = Model.Create.LinearElement(mE.ToLine(), exInfo);
                lEl.Family = BeamSection;
                Beams.Add(lEl);
            }
            PanelBoundaries = faces.ExtractFaceBoundaries();
            return(true);
        }
Example #20
0
        public override bool Execute(ExecutionInfo exInfo = null)
        {
            var elements = new LinearElementCollection();

            if (Struts != null)
            {
                elements.AddRange(Struts);
            }
            if (Ties != null)
            {
                elements.AddRange(Ties);
            }

            if (elements.Count > 0)
            {
                elements.ClearAttachedData(typeof(Spring));
                var nodes = elements.GetNodes();
                nodes.ClearAttachedData(typeof(Particle));

                var motion = new KineticDampingComponent(nodes);
                //motion.SpeedLimit = SpeedLimit;
                var gravity      = new ParticleGravityComponent(nodes);
                var springForces = new SpringForceComponent(elements);

                if (Struts != null)
                {
                    foreach (var strut in Struts)
                    {
                        if (strut.HasData <Spring>())
                        {
                            strut.GetData <Spring>().Compression = true;
                            strut.GetData <Spring>().Tension     = true;
                        }
                    }
                }

                //Set ties (temp):
                if (Ties != null)
                {
                    foreach (var tie in Ties)
                    {
                        if (tie.HasData <Spring>())
                        {
                            tie.GetData <Spring>().Compression = false;
                            tie.GetData <Spring>().Tension     = true;
                        }
                    }
                }

                var engine = new PhysicsEngine();
                engine.Components.Add(gravity);
                engine.Components.Add(springForces);
                engine.Components.Add(motion);

                engine.Start();
                for (int i = 0; i < Cycles; i++)
                {
                    engine.Cycle(1.0);
                }

                // Outputs:
                StrutDeformation = new CurveCollection();
                TieDeformation   = new CurveCollection();
                StrutForces      = new List <double>();
                TieForces        = new List <double>();

                if (Struts != null)
                {
                    foreach (var lEl in Struts)
                    {
                        if (!lEl.IsDeleted)
                        {
                            StrutDeformation.Add(
                                new Line(
                                    lEl.StartNode.GetData <Particle>().Position,
                                    lEl.EndNode.GetData <Particle>().Position));

                            StrutForces.Add(
                                lEl.GetData <Spring>().AxialForce());
                        }
                    }
                }

                if (Ties != null)
                {
                    foreach (var lEl in Ties)
                    {
                        if (!lEl.IsDeleted)
                        {
                            TieDeformation.Add(
                                new Line(
                                    lEl.StartNode.GetData <Particle>().Position,
                                    lEl.EndNode.GetData <Particle>().Position));

                            TieForces.Add(
                                lEl.GetData <Spring>().AxialForce());
                        }
                    }
                }
            }

            return(true);
        }
Example #21
0
        public GeometryVisualiserDialog(object visualise) : this()
        {
            VertexGeometryCollection geometry = new VertexGeometryCollection();


            if (_StorePath.Exists)
            {
                try
                {
                    Stream stream = new FileStream(_StorePath,
                                                   FileMode.Open,
                                                   FileAccess.Read,
                                                   FileShare.Read);
                    stream.Seek(0, SeekOrigin.Begin);

                    IFormatter formatter = new BinaryFormatter();
                    formatter.Binder = new CustomSerializationBinder();
                    var storedGeo = formatter.Deserialize(stream) as VertexGeometryCollection;
                    stream.Close();

                    if (storedGeo != null)
                    {
                        geometry.AddRange(storedGeo);
                    }
                }
                catch { }
            }

            if (visualise is MeshFace)
            {
                visualise = new MeshFaceCollection((MeshFace)visualise);
            }
            //else if (visualise is Mesh) visualise = ((Mesh)visualise).Faces;

            if (visualise is IList <VertexGeometry> )
            {
                geometry.TryAddRange((IList <VertexGeometry>)visualise);
            }
            else if (visualise is IList <Curve> )
            {
                geometry.TryAddRange((IList <Curve>)visualise);
            }
            else if (visualise is IList <PlanarRegion> )
            {
                geometry.TryAddRange((IList <PlanarRegion>)visualise);
            }
            else if (visualise is VertexGeometry)
            {
                geometry.TryAdd((VertexGeometry)visualise);
            }
            else if (visualise is MeshFaceCollection)
            {
                var             faces = (MeshFaceCollection)visualise;
                CurveCollection edges = faces.ExtractFaceBoundaries();
                foreach (var edge in edges)
                {
                    var region = new PlanarRegion(edge);
                    geometry.Add(region);
                    region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128));
                    geometry.Add(edge);
                    edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0));
                }
            }
            else if (visualise is IList <Vertex> )
            {
                var verts = (IList <Vertex>)visualise;
                var cloud = new Cloud(verts.GetPositions());
                geometry.Add(cloud);
            }
            else if (visualise is IList <Geometry.Vector> )
            {
                var v     = (IList <Geometry.Vector>)visualise;
                var cloud = new Cloud(v);
                geometry.Add(cloud);
            }
            else if (visualise is MeshDivisionEdge)
            {
                var mDE  = (MeshDivisionEdge)visualise;
                var line = new Geometry.Line(mDE.Start, mDE.End);
                geometry.Add(line);
                if (mDE.Vertices != null && mDE.Vertices.Count > 0)
                {
                    var cloud = new Cloud(mDE.Vertices.GetPositions());
                    geometry.Add(cloud);
                }
            }
            else if (visualise is IList <MeshDivisionEdge> )
            {
                foreach (var mDC in (IList <MeshDivisionEdge>)visualise)
                {
                    var mDE  = (MeshDivisionEdge)visualise;
                    var line = new Geometry.Line(mDE.Start, mDE.End);
                    geometry.Add(line);
                    if (mDE.Vertices != null && mDE.Vertices.Count > 0)
                    {
                        var cloud = new Cloud(mDE.Vertices.GetPositions());
                        geometry.Add(cloud);
                    }
                }
            }
            else if (visualise is IWidePath)
            {
                IWidePath path = (IWidePath)visualise;
                AddWidePath(geometry, path);
            }
            else if (visualise is IList <IWidePath> )
            {
                foreach (var path in (IList <IWidePath>)visualise)
                {
                    AddWidePath(geometry, path);
                }
            }
            // TODO: Convert other types to vertexgeometry


            BoundingBox bBox = geometry.BoundingBox;

            /*MinX.Text = bBox.MinX.ToString();
            *  MaxX.Text = bBox.MaxX.ToString();
            *  MinY.Text = bBox.MinY.ToString();
            *  MaxY.Text = bBox.MaxY.ToString();*/

            Canvas.CurveThickness = 0.005 * bBox.SizeVector.Magnitude();
            Canvas.PointDiameter  = 0.01 * bBox.SizeVector.Magnitude();
            Canvas.DefaultBrush   = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0));
            //Canvas.FillBrush = new SolidColorBrush(Color.FromArgb(64, 0, 0, 0));
            Canvas.Geometry = geometry;

            /*var xDivs = bBox.X.ReasonableDivisions(10);
             * var yDivs = bBox.Y.ReasonableDivisions(10);
             *
             * foreach (double x in xDivs)
             * {
             *  var line = new Geometry.Line(x, bBox.MinY - 10, x, bBox.MaxY + 10);
             *  line.Attributes = new GeometryAttributes(Rendering.Colour.Green, 0.1);
             *  Canvas.AddContents(line);
             * }*/
        }
Example #22
0
 protected override Vector CalculateCentroidOffset(Curve perimeter, CurveCollection voids)
 {
     return(new Vector());
 }
Example #23
0
 public CurvesAdjustmentFilterBuilder UsingCurves(CurveCollection curves)
 {
     Filter.Curves = curves;
     return(this);
 }
Example #24
0
        /// <summary>
        /// Recreate the displayed geometry inside this canvas
        /// </summary>
        public void RefreshContents()
        {
            BoundingBox bBox = new BoundingBox(0, 0, 0);

            Children.Clear();

            var steelGrad = new GradientStopCollection();

            steelGrad.Add(new GradientStop(Colors.LightGray, 0));
            steelGrad.Add(new GradientStop(Colors.White, 0.5));
            steelGrad.Add(new GradientStop(Colors.LightGray, 1));

            var steelBrush = new LinearGradientBrush(steelGrad, 45);

            var topLayer = new List <UIElement>();

            if (Profiles != null)
            {
                foreach (SectionProfile sp in Profiles)
                {
                    Curve perimeter = sp.Perimeter;
                    if (perimeter != null)
                    {
                        CurveCollection voids = sp.Voids;
                        bBox.Include(perimeter.BoundingBox);

                        PathGeometry perimeterPath = new PathGeometry();
                        perimeterPath.Figures.Add(ToWPF.Convert(perimeter));

                        CombinedGeometry cg = new CombinedGeometry();
                        cg.GeometryCombineMode = GeometryCombineMode.Exclude;
                        cg.Geometry1           = perimeterPath;

                        if (voids != null && voids.Count > 0)
                        {
                            PathGeometry inside = new PathGeometry();
                            foreach (Curve vCrv in voids)
                            {
                                inside.Figures.Add(ToWPF.Convert(vCrv));
                            }
                            cg.Geometry2 = inside;
                        }

                        Path path = new Path();
                        path.Fill            = steelBrush;
                        path.Stroke          = Brushes.Black;
                        path.StrokeThickness = 0.01;
                        path.Data            = cg;

                        topLayer.Add(path);
                    }
                }

                bBox.Expand(Math.Max(bBox.SizeX, bBox.SizeY) * 0.1);
                double maxSize = Math.Max(bBox.SizeX, bBox.SizeY);

                //Draw grid:

                /*var axisBrush = new RadialGradientBrush(Colors.Black, Colors.Transparent);
                 *
                 * var hAxis = new W.Line();
                 * hAxis.X1 = -maxSize;
                 * hAxis.X2 = maxSize;
                 * hAxis.Stroke = axisBrush;
                 * hAxis.StrokeThickness = maxSize*0.005;
                 * Children.Add(hAxis);*/

                //Adjust stroke:
                foreach (UIElement el in topLayer)
                {
                    if (el is Path)
                    {
                        ((Path)el).StrokeThickness = maxSize * 0.005;
                    }
                }

                foreach (UIElement el in topLayer)
                {
                    Children.Add(el);
                }

                //Draw set-out point
                Ellipse setOutPt = new Ellipse();
                setOutPt.Width  = maxSize * 0.03;
                setOutPt.Height = setOutPt.Width;
                SetLeft(setOutPt, -setOutPt.Width / 2);
                SetTop(setOutPt, -setOutPt.Height / 2);
                setOutPt.Fill = Brushes.OrangeRed;
                Children.Add(setOutPt);
            }
            Width           = bBox.SizeX;
            Height          = bBox.SizeY;
            RenderTransform = new TranslateTransform(bBox.SizeX / 2 - bBox.Mid.X, bBox.SizeY / 2 + bBox.Mid.Y);
        }
Example #25
0
 public CurveBox()
 {
     curves = new CurveCollection();
     pens   = new Dictionary <int, Pen>();
 }
Example #26
0
        /// <summary>
        /// Add geometric contents to the canvas, automatically converting from
        /// Nucleus geometry to the WPF equivalent
        /// </summary>
        /// <param name="shape"></param>
        public void AddContents(VertexGeometry shape)
        {
            if (shape is Curve)
            {
                Curve        crv     = (Curve)shape;
                PathGeometry pathGeo = new PathGeometry();
                pathGeo.Figures.Add(ToWPF.Convert(crv));

                Path path = new Path();
                path.DataContext = crv;
                //if (crv.Attributes == null || crv.Attributes.Brush == null)
                //{
                //    path.Stroke = DefaultBrush;
                //}
                //else path.Stroke = FBtoWPF.Convert(crv.Attributes.Brush);
                var strokeBinding = new Binding("Attributes.Brush");
                strokeBinding.Converter     = new Converters.BrushConverter();
                strokeBinding.FallbackValue = DefaultBrush;
                path.SetBinding(Path.StrokeProperty, strokeBinding);

                path.StrokeStartLineCap = PenLineCap.Round;
                path.StrokeEndLineCap   = PenLineCap.Round;

                //path.StrokeThickness = CurveThickness;
                //var thicknessBinding = new Binding("CurveThickness");
                //thicknessBinding.Source = this;

                if (crv.Attributes == null)
                {
                    //path.SetBinding(Path.StrokeThicknessProperty, thicknessBinding);
                    path.StrokeThickness = CurveThickness;
                }
                else
                {
                    /*var mBinding = new MultiBinding();
                     * mBinding.Converter = new Converters.MultiplicationConverter();
                     * mBinding.Bindings.Add(thicknessBinding);
                     * mBinding.Bindings.Add(new Binding("Attributes.Weight"));
                     *
                     * path.SetBinding(Path.StrokeThicknessProperty, mBinding);*/
                    path.StrokeThickness = CurveThickness * crv.Attributes.Weight;
                }

                // * scaleFactor;

                path.Data           = pathGeo;
                path.StrokeLineJoin = PenLineJoin.Round;

                if (crv.Closed && FillBrush != null)
                {
                    path.Fill = FillBrush;
                }
                //fillBrush = null;

                path.Tag = shape;

                Children.Add(path);
            }
            else if (shape is PlanarRegion)
            {
                PlanarRegion    reg       = (PlanarRegion)shape;
                Curve           perimeter = reg.Perimeter;
                CurveCollection voids     = reg.Voids;

                PathGeometry perimeterPath = new PathGeometry();
                perimeterPath.Figures.Add(ToWPF.Convert(perimeter));

                CombinedGeometry cg = new CombinedGeometry();
                cg.GeometryCombineMode = GeometryCombineMode.Exclude;
                cg.Geometry1           = perimeterPath;

                if (voids != null && voids.Count > 0)
                {
                    PathGeometry inside = new PathGeometry();
                    foreach (Curve vCrv in voids)
                    {
                        inside.Figures.Add(ToWPF.Convert(vCrv));
                    }
                    cg.Geometry2 = inside;
                }

                Path path = new Path();
                path.DataContext = shape;
                //if (reg.Attributes == null || reg.Attributes.Brush == null)
                //{
                //    path.Fill = DefaultBrush;
                //}
                //else path.Fill = FBtoWPF.Convert(reg.Attributes.Brush, 192);
                var fillBinding = new Binding("Attributes.Brush");
                fillBinding.Converter          = new Converters.BrushConverter();
                fillBinding.FallbackValue      = DefaultBrush;
                fillBinding.ConverterParameter = 192;
                path.SetBinding(Path.FillProperty, fillBinding);
                //path.Stroke = Brushes.Black;
                //path.StrokeThickness = 0.01;
                path.Data = cg;

                path.Tag = shape;

                Children.Add(path);
            }
            else if (shape is FB.Label)
            {
                FB.Label label = (FB.Label)shape;

                TextBlock tB = new TextBlock();
                tB.DataContext = label;
                tB.Padding     = new Thickness(0);
                if (label.TextBinding != null)
                {
                    tB.SetBinding(TextBlock.TextProperty, ToWPF.Convert(label.TextBinding));
                }
                else
                {
                    tB.SetBinding(TextBlock.TextProperty, new Binding("Text"));
                }
                tB.FontSize        = 1; //label.TextSize;
                tB.RenderTransform = new ScaleTransform(label.TextSize, label.TextSize);
                //tB.RenderTransformOrigin = new System.Windows.Point(0, 1);

                var fillBinding = new Binding("Attributes.Brush");
                fillBinding.Converter     = new Converters.BrushConverter();
                fillBinding.FallbackValue = DefaultBrush;
                tB.SetBinding(TextBlock.ForegroundProperty, fillBinding);

                FormattedText fT = new FormattedText(label.Text, CultureInfo.CurrentCulture, tB.FlowDirection,
                                                     new Typeface(tB.FontFamily, tB.FontStyle, tB.FontWeight, tB.FontStretch), 1, tB.Foreground);

                double xOffset;
                if (label.HorizontalSetOut == HorizontalSetOut.Left)
                {
                    xOffset = 0;
                }
                else if (label.HorizontalSetOut == HorizontalSetOut.Right)
                {
                    xOffset = fT.Width * label.TextSize;
                }
                else
                {
                    xOffset = label.TextSize * fT.Width / 2;
                }

                double yOffset;
                if (label.VerticalSetOut == VerticalSetOut.Top)
                {
                    yOffset = 0;
                }
                else if (label.VerticalSetOut == VerticalSetOut.Bottom)
                {
                    yOffset = fT.Height * label.TextSize;
                }
                else
                {
                    yOffset = label.TextSize * fT.Height / 2;
                }

                SetLeft(tB, label.Position.X - xOffset);
                SetTop(tB, -label.Position.Y - yOffset);

                tB.Tag = shape;

                Children.Add(tB);
            }
            else if (shape is Cloud || shape is FB.Point)
            {
                double diameter = PointDiameter;
                if (shape.Attributes != null)
                {
                    diameter *= shape.Attributes.Weight;
                }

                foreach (Vertex v in shape.Vertices)
                {
                    Ellipse ellipse = new Ellipse();
                    ellipse.Width       = diameter;
                    ellipse.Height      = diameter;
                    ellipse.DataContext = shape;

                    var fillBinding = new Binding("Attributes.Brush");
                    fillBinding.Converter     = new Converters.BrushConverter();
                    fillBinding.FallbackValue = DefaultBrush;
                    ellipse.SetBinding(Ellipse.FillProperty, fillBinding);

                    SetLeft(ellipse, v.X - diameter / 2.0);
                    SetTop(ellipse, -v.Y - diameter / 2.0);

                    ellipse.Tag = shape;

                    if (shape.Attributes != null && shape.Attributes.Interactive)
                    {
                        //TODO: CHANGE THIS!  TEMP ONLY!
                        ellipse.Cursor = Cursors.Hand;
                    }

                    Children.Add(ellipse);
                }
            }
        }