Ejemplo n.º 1
0
        public TrimmedSurface(Surface surface, double angleTolerance = 60)
        {
            this.internalSurface = surface;
            this.curvesByDirections = new Dictionary<Vector, TwoCurves>();
            this.tolerance = angleTolerance;

            // Walk through all perimeter curves
            foreach (Curve curve in internalSurface.PerimeterCurves())
            {
                // get the curves direction
                Vector direction = Vector.ByTwoPoints(curve.StartPoint, curve.EndPoint);

                // If there hasnt been any curve collected add this as the first one
                if (curvesByDirections.Count == 0)
                    curvesByDirections.Add(direction, new TwoCurves(curve));
                else
                {
                    // indicator to check if any curve matches its direction
                    bool matchingOrientation = false;

                    // Walk through all collected curves and check if the direction vectors are
                    // more or less parallel.
                    foreach (Vector vector in curvesByDirections.Keys.ToList())
                    {
                        if (direction.Parallel(vector, tolerance))
                        {
                            matchingOrientation = true;

                            // If there is a matching direction already in the dictionary,
                            // Add this curve to the existing curve
                            TwoCurves existingCurve = curvesByDirections[vector];
                            existingCurve.AddToMatchingCurve(curve);
                        }
                    }

                    // If there is no matching direction, this seems to be a new
                    // Side of the surface
                    if (!matchingOrientation)
                    {
                        curvesByDirections.Add(direction, new TwoCurves(curve));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void CreateorUpdateArea(ref cSapModel Model, Surface s, ref string Id, bool update, double SF, ref string error)
        {
            Curve[] PerimeterCrvs = s.PerimeterCurves();
            List<Point> SurfPoints = new List<Point>();
            long ret = 0;
            int counter = 0;
            foreach (var crv in PerimeterCrvs)
            {
                SurfPoints.Add(crv.StartPoint);
            }

            if (!update) // Create new
            {
                List<string> ProfilePts = new List<string>();
                foreach (var v in SurfPoints)
                {
                    string dummy = null;
                    ret = Model.PointObj.AddCartesian(v.X * SF, v.Y * SF, v.Z * SF, ref dummy);
                    ProfilePts.Add(dummy);
                }

                string[] names = ProfilePts.ToArray();
                string dummyarea = string.Empty;
                ret = Model.AreaObj.AddByPoint(ProfilePts.Count(), ref names, ref dummyarea);
                if (ret == 1) counter++;
                Id = dummyarea;
            }
            else
            {  // TODO: Update Shell

                // Existing
                int eNumberofPts = 0;
                string[] ePtNames = null;
                ret = Model.AreaObj.GetPoints(Id, ref eNumberofPts, ref ePtNames);

                // Compare the number of points
                if (eNumberofPts == SurfPoints.Count())
                {
                    for (int i = 0; i < eNumberofPts; i++)
                    {
                        ret = Model.EditPoint.ChangeCoordinates_1(ePtNames[i], SurfPoints[i].X * SF, SurfPoints[i].Y * SF, SurfPoints[i].Z * SF);
                        if (ret == 1) counter++;
                    }
                }
                else if (eNumberofPts > SurfPoints.Count()) // remove Points
                {
                    for (int i = 0; i < eNumberofPts; i++)
                    {
                        if (i < SurfPoints.Count())
                        {
                            ret = Model.EditPoint.ChangeCoordinates_1(ePtNames[i], SurfPoints[i].X * SF, SurfPoints[i].Y * SF, SurfPoints[i].Z * SF);
                        }
                        else
                        {
                            ret = Model.SelectObj.ClearSelection();
                            ret = Model.AreaObj.SetSelected(Id, true);
                            ret = Model.PointObj.SetSelected(ePtNames[i], true);
                            ret = Model.EditArea.PointRemove();
                        }
                    }
                    if (ret == 1) counter++;
                }
                else if (eNumberofPts < SurfPoints.Count()) // add points
                {
                    for (int i = 0; i < SurfPoints.Count(); i++)
                    {
                        if (i < eNumberofPts)
                        {
                            ret = Model.EditPoint.ChangeCoordinates_1(ePtNames[i], SurfPoints[i].X * SF, SurfPoints[i].Y * SF, SurfPoints[i].Z * SF);
                        }
                        else
                        {
                            // add point to latest edge
                            ret = Model.SelectObj.ClearSelection();
                            int a = i - 1;
                            ret = Model.AreaObj.SetSelectedEdge(Id, a, true);

                            ret = Model.EditArea.PointAdd();

                            // the repeat the first step so # of name and has updated
                            int tempnumb = 0;
                            string[] TempPtNames = null;
                            ret = Model.AreaObj.GetPoints(Id, ref tempnumb, ref TempPtNames);

                            ret = Model.EditPoint.ChangeCoordinates_1(TempPtNames[i], SurfPoints[i].X * SF, SurfPoints[i].Y * SF, SurfPoints[i].Z * SF);
                        }
                    }
                    if (ret == 1) counter++;

                }

            }
            if (counter > 0) error = string.Format("Error creating Mesh{0}", Id);
        }
Ejemplo n.º 3
0
        public static Dictionary <string, Autodesk.DesignScript.Geometry.Curve[]> OffsetPerimeterCurves(this Autodesk.DesignScript.Geometry.Surface surface, double offset)
        {
            List <Autodesk.DesignScript.Geometry.Curve> srfPerimCrvs = surface.PerimeterCurves().ToList();

            Autodesk.DesignScript.Geometry.PolyCurve plyCrv = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(srfPerimCrvs);

            double inOffset;
            double outOffset;

            if (offset < 0)
            {
                inOffset  = offset;
                outOffset = -offset;
            }
            else
            {
                inOffset  = -offset;
                outOffset = offset;
            }

            Autodesk.DesignScript.Geometry.Curve[] inPerimCrvs;
            try
            {
                List <Autodesk.DesignScript.Geometry.Curve> inOffsetCrv = new List <Autodesk.DesignScript.Geometry.Curve>()
                {
                    (plyCrv.Offset(inOffset))
                };
                Autodesk.DesignScript.Geometry.PolyCurve    inOffsetPolyCrv = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(inOffsetCrv);
                List <Autodesk.DesignScript.Geometry.Curve> inOffsetCrvList = inOffsetPolyCrv.Curves().ToList();
                List <Autodesk.DesignScript.Geometry.Point> inPts           = new List <Autodesk.DesignScript.Geometry.Point>();
                foreach (Autodesk.DesignScript.Geometry.Curve c in inOffsetCrvList)
                {
                    inPts.Add(c.StartPoint);
                }
                Autodesk.DesignScript.Geometry.PolyCurve inOffsetPolyCrv2 = PolyCurve.ByPoints(inPts, true);
                Autodesk.DesignScript.Geometry.Surface   inOffsetSrf      = Autodesk.DesignScript.Geometry.Surface.ByPatch(inOffsetPolyCrv2);
                inPerimCrvs = inOffsetSrf.PerimeterCurves();
                inOffsetSrf.Dispose();
                inOffsetPolyCrv.Dispose();
                inOffsetPolyCrv2.Dispose();
            }
            catch (Exception)
            {
                inPerimCrvs = null;
            }

            Autodesk.DesignScript.Geometry.Curve[] outPerimCrvs;
            try
            {
                List <Autodesk.DesignScript.Geometry.Curve> outOffsetCrv = new List <Autodesk.DesignScript.Geometry.Curve>()
                {
                    (plyCrv.Offset(outOffset))
                };
                Autodesk.DesignScript.Geometry.PolyCurve    outOffsetPolyCrv = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(outOffsetCrv);
                List <Autodesk.DesignScript.Geometry.Curve> outOffsetCrvList = outOffsetPolyCrv.Curves().ToList();
                List <Autodesk.DesignScript.Geometry.Point> outPts           = new List <Autodesk.DesignScript.Geometry.Point>();
                foreach (Autodesk.DesignScript.Geometry.Curve c in outOffsetCrvList)
                {
                    outPts.Add(c.StartPoint);
                }
                Autodesk.DesignScript.Geometry.PolyCurve outOffsetPolyCrv2 = PolyCurve.ByPoints(outPts, true);
                Autodesk.DesignScript.Geometry.Surface   outOffsetSrf      = Autodesk.DesignScript.Geometry.Surface.ByPatch(outOffsetPolyCrv2);
                outPerimCrvs = outOffsetSrf.PerimeterCurves();
                outOffsetSrf.Dispose();
                outOffsetPolyCrv.Dispose();
                outOffsetPolyCrv2.Dispose();
            }
            catch (Exception)
            {
                outPerimCrvs = null;
            }


            Dictionary <string, Autodesk.DesignScript.Geometry.Curve[]> newOutput;

            newOutput = new Dictionary <string, Autodesk.DesignScript.Geometry.Curve[]>
            {
                { "insetCrvs", inPerimCrvs },
                { "outsetCrvs", outPerimCrvs }
            };

            //Dispose all redundant geometry

            plyCrv.Dispose();
            foreach (Autodesk.DesignScript.Geometry.Curve c in srfPerimCrvs)
            {
                c.Dispose();
            }

            return(newOutput);
        }
Ejemplo n.º 4
0
        public static Dictionary <string, Autodesk.DesignScript.Geometry.Surface> Create(
            Autodesk.DesignScript.Geometry.Surface surface,
            double offset,
            double depth)
        {
            // offset perimeter curves by the specified offset and create new surface.
            // makes sure there are space between outer perimeter and the amenity space
            List <Curve> inCrvs = surface.OffsetPerimeterCurves(offset)["insetCrvs"].ToList();
            Surface      inSrf  = Surface.ByPatch(PolyCurve.ByJoinedCurves(inCrvs));

            // get longest curve of the inSrf
            Curve        max;
            List <Curve> others;
            Dictionary <string, dynamic> dict = inCrvs.MaximumLength();

            if (dict["maxCrv"].Count < 1)
            {
                max = dict["otherCrvs"][0] as Curve;
                int          count = dict["otherCrvs"].Count;
                List <Curve> rest  = dict["otherCrvs"];
                others = rest.GetRange(1, (count - 1));
            }
            else
            {
                max    = dict["maxCrv"][0] as Curve;
                others = dict["otherCrvs"];
            }

            // get perimeter curves of input surface
            List <Curve> perimCrvs = surface.PerimeterCurves().ToList();
            List <Curve> matchCrvs = max.FindMatchingVectorCurves(perimCrvs);

            // get longest curve
            Curve max2;
            Dictionary <string, dynamic> dict2 = matchCrvs.MaximumLength();

            if (dict2["maxCrv"].Count < 1)
            {
                max2 = dict2["otherCrvs"][0] as Curve;
            }
            else
            {
                max2 = dict2["maxCrv"][0] as Curve;
            }

            Vector vec = max2.ByTwoCurves(max);

            Curve transLine  = max.Translate(vec, depth) as Curve;
            Line  extendLine = transLine.ExtendAtBothEnds(1);


            List <Curve> crvList = new List <Curve>()
            {
                max, extendLine
            };
            Surface loftSrf = Surface.ByLoft(crvList);

            List <bool> boolLst = new List <bool>();

            foreach (var crv in others)
            {
                bool b = max.DoesIntersect(crv);
                boolLst.Add(b);
            }

            List <Curve> intersectingCurves = others
                                              .Zip(boolLst, (name, filter) => new { name, filter, })
                                              .Where(item => item.filter == true)
                                              .Select(item => item.name)
                                              .ToList();
            List <Curve> extendCurves = new List <Curve>();

            foreach (Curve crv in intersectingCurves)
            {
                var l = crv.ExtendAtBothEnds(1);
                extendCurves.Add(l);
            }

            List <Surface> split = loftSrf
                                   .SplitPlanarSurfaceByMultipleCurves(extendCurves)
                                   .OfType <Surface>()
                                   .ToList();

            Surface amenitySurf = split.MaximumArea()["maxSrf"] as Surface;

            Surface remainSurf = inSrf.Split(amenitySurf)[0] as Surface;

            Dictionary <string, Surface> newOutput;

            newOutput = new Dictionary <string, Surface>
            {
                { amenitySurfaceOutputPort, amenitySurf },
                { remainingSurfaceOutputPort, remainSurf }
            };

            //Dispose redundant geometry
            inCrvs.ForEach(crv => crv.Dispose());
            inSrf.Dispose();
            max.Dispose();
            perimCrvs.ForEach(crv => crv.Dispose());
            matchCrvs.ForEach(crv => crv.Dispose());
            max2.Dispose();
            vec.Dispose();
            transLine.Dispose();
            extendLine.Dispose();
            crvList.ForEach(crv => crv.Dispose());
            loftSrf.Dispose();
            intersectingCurves.ForEach(crv => crv.Dispose());
            extendCurves.ForEach(crv => crv.Dispose());

            return(newOutput);
        }