Ejemplo n.º 1
0
            public void UnfoldAndLabelCurvedArcLoft()
            {
                Surface testsweep = UnfoldTestUtils.SetupArcLoft();

                var surfaces = new List <Surface>()
                {
                    testsweep
                };
                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();


                var unfoldObject = PlanarUnfolder.Unfold(trisurfaces);

                Console.WriteLine("generating tabs");

                // generate tabs
                var tabDict  = TabGeneration.GenerateTabSurfacesFromUnfold <EdgeLikeEntity, FaceLikeEntity>(unfoldObject);
                var justTabs = tabDict.Keys.SelectMany(x => tabDict[x]).ToList();

                Console.WriteLine("tabs generated");
                // next check the positions of the translated tab,

                UnfoldTestUtils.AssertTabsGoodFinalLocation <EdgeLikeEntity, FaceLikeEntity>(justTabs, unfoldObject);
            }
            public void GenBFSTreeFromArcLoft()
            {
                Surface testsweep = UnfoldTestUtils.SetupArcLoft();

                var surfaces = new List <Surface>()
                {
                    testsweep
                };
                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();


                var graph = ModelTopology.GenerateTopologyFromSurfaces(trisurfaces);

                List <Object> face_objs = trisurfaces.Select(x => x as Object).ToList();

                UnfoldTestUtils.GraphHasVertForEachFace(graph, face_objs);

                var    nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
                object tree       = nodereturn;

                var casttree = tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >;

                UnfoldTestUtils.GraphHasVertForEachFace(casttree, face_objs);
                UnfoldTestUtils.AssertAllFinishingTimesSet(graph);

                var sccs = GraphUtilities.TarjansAlgo <EdgeLikeEntity, FaceLikeEntity> .CycleDetect(casttree, GraphUtilities.EdgeType.Tree);

                UnfoldTestUtils.IsAcylic <EdgeLikeEntity, FaceLikeEntity>(sccs, casttree);
            }
Ejemplo n.º 3
0
            public void UnfoldCurvedArcSweep()
            {
                Surface testsweep = UnfoldTestUtils.SetupArcCurveSweep();

                var surfaces = new List <Surface>()
                {
                    testsweep
                };
                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 30);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();


                var unfoldsurfaces = PlanarUnfolder.Unfold(trisurfaces).UnfoldedSurfaceSet;

                UnfoldTestUtils.CheckAllUnfoldedFacesForCorrectUnfold(unfoldsurfaces);

                foreach (IDisposable item in trisurfaces)
                {
                    item.Dispose();
                }
            }
Ejemplo n.º 4
0
            public void UnfoldAndLabelCurvedArcLoft()
            {
                Surface testsweep = UnfoldTestUtils.SetupArcLoft();

                var surfaces = new List <Surface>()
                {
                    testsweep
                };
                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();


                var unfoldObject = PlanarUnfolder.Unfold(trisurfaces);

                var unfoldsurfaces = unfoldObject.UnfoldedSurfaceSet;

                Console.WriteLine("generating labels");

                // generate labels
                var labels = unfoldObject.StartingUnfoldableFaces.Select(x =>
                                                                         new PlanarUnfolder.UnfoldableFaceLabel <EdgeLikeEntity, FaceLikeEntity>(x)).ToList();

                UnfoldTestUtils.AssertLabelsGoodStartingLocationAndOrientation(labels);

                // next check the positions of the translated labels

                var transformedGeo = labels.Select(x => PlanarUnfolder.MapGeometryToUnfoldingByID(unfoldObject, x.AlignedLabelGeometry, x.ID)).ToList();

                UnfoldTestUtils.AssertLabelsGoodFinalLocationAndOrientation(labels, transformedGeo, unfoldObject);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an DesignScript.Geometry.Surface from a pointlist and returns the DynamoPlus.BuildingSurface.
        /// </summary>
        /// <param name="points">List of points</param>
        /// <param name="zone">the zone</param>
        /// <param name="name">Name of the BuildingSurface. If "default" it will be named by Zone and a counter (like "Zonename - Surface 1").</param>
        /// <param name="constructionName">a construction name</param>
        /// <param name="boundaryCondition">the OutsideBoundaryCondition</param>
        /// <param name="type">The Type of the BuildingSurface</param>
        /// <returns>A DynamoPlus BuildingSurface</returns>
        public BuildingSurface ByPoints(List <Point> points, Zone zone, string name = "default",
                                        string constructionName = "default", string boundaryCondition = "Outdoors", string type = "Wall")
        {
            var surf = Surface.ByPerimeterPoints(points);

            return(new BuildingSurface(surf, zone, name, constructionName, boundaryCondition, type));
        }
Ejemplo n.º 6
0
        public static void GetShell(ref cSapModel Model, string areaid, ref Surface BaseS, double LSF, ref string PropName) //Length Scale Factor
        {
            long ret = 0;

            int NumOfPts = 0;

            string[] PtsNames = null;
            ret = Model.AreaObj.GetPoints(areaid, ref NumOfPts, ref PtsNames);

            List <Point>      dynPts = new List <Point>();
            List <IndexGroup> igs    = new List <IndexGroup>();

            for (int i = 0; i < PtsNames.Count(); i++)
            {
                double x = 0;
                double y = 0;
                double z = 0;

                ret = Model.PointObj.GetCoordCartesian(PtsNames[i], ref x, ref y, ref z);

                Point p = Point.ByCoordinates(x * LSF, y * LSF, z * LSF);
                dynPts.Add(p);
            }

            //Mesh.ByPointsFaceIndices()
            BaseS = Surface.ByPerimeterPoints(dynPts);

            // Get assigned Property Name
            ret = Model.AreaObj.GetProperty(areaid, ref PropName);
        }
Ejemplo n.º 7
0
        public void CreateByFace_InvalidArgs()
        {
            var p1 = Point.ByCoordinates(0.0, 0.0, 0.0);
            var p2 = Point.ByCoordinates(1.0, 1.0, 0);
            var p3 = Point.ByCoordinates(2.0, 0, 0);

            var surf1 = Surface.ByPerimeterPoints(new List <Point>()
            {
                p1, p2, p3
            });

            var q1 = Point.ByCoordinates(0.0, 0.0, 2.0);
            var q2 = Point.ByCoordinates(1.0, 1.0, 2);
            var q3 = Point.ByCoordinates(2.0, 0, 2);

            var surf2 = Surface.ByPerimeterPoints(new List <Point>()
            {
                q1, q2, q3
            });

            System.Collections.Generic.List <Surface> surfaces = new System.Collections.Generic.List <Surface>()
            {
                surf1, surf2
            };

            var line = Line.ByStartPointEndPoint(p1, q1);

            Assert.Throws(typeof(System.ArgumentException), () => Dimension.ByFaces(Revit.Application.Document.Current.ActiveView, surfaces, line));
        }
Ejemplo n.º 8
0
            public void UnfoldAndLabel2ArcLofts()
            {
                // unfold cube
                Surface testloft  = UnfoldTestUtils.SetupArcLoft();
                Surface testloft2 = UnfoldTestUtils.SetupArcLoft();
                var     surfaces  = new List <Surface>()
                {
                    testloft
                };
                var surfaces2 = new List <Surface>()
                {
                    testloft
                };
                //handle tesselation here
                var pointtuples  = Tesselation.Tessellate(surfaces, -1, 512);
                var pointtuples2 = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();
                List <Surface> trisurfaces2 = pointtuples2.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();

                var unfoldObject1 = PlanarUnfolder.Unfold(trisurfaces);
                var unfoldObject2 = PlanarUnfolder.Unfold(trisurfaces2);

                var unfoldsurfaces = unfoldObject1.UnfoldedSurfaceSet.Concat(unfoldObject2.UnfoldedSurfaceSet).ToList();

                Console.WriteLine("merging unfolds");
                var unfoldObject = PlanarUnfolder.PlanarUnfolding <EdgeLikeEntity, FaceLikeEntity> .
                                   MergeUnfoldings(new List <PlanarUnfolder.PlanarUnfolding <EdgeLikeEntity, FaceLikeEntity> >() { unfoldObject1, unfoldObject2 });

                AssertMergeHasCorrectNumberOfSurfaces(unfoldObject, trisurfaces.Count * 2);
                AssertMergeHasCorrectNumberOfMaps(unfoldObject, new List <PlanarUnfolder.PlanarUnfolding <EdgeLikeEntity, FaceLikeEntity> >()
                {
                    unfoldObject1, unfoldObject2
                });

                Console.WriteLine("generating labels");

                // generate labels
                var labels = unfoldObject.StartingUnfoldableFaces.Select(x =>
                                                                         new PlanarUnfolder.UnfoldableFaceLabel <EdgeLikeEntity, FaceLikeEntity>(x)).ToList();

                UnfoldTestUtils.AssertLabelsGoodStartingLocationAndOrientation(labels);

                // next check the positions of the translated labels,

                var transformedGeo = labels.Select(x => PlanarUnfolder.MapGeometryToUnfoldingByID
                                                       (unfoldObject, x.AlignedLabelGeometry, x.ID)).ToList();

                UnfoldTestUtils.AssertLabelsGoodFinalLocationAndOrientation(labels, transformedGeo, unfoldObject);
            }
Ejemplo n.º 9
0
        // exposes node to tesselate surfaces in dynamo, returns triangular surfaces
        // Peter will hate this :)
        /// <summary>
        /// This method exposes the tessellation algorithm that is used to display
        /// geometry in Dynamo's watch3d and background preview displays as a node.
        /// It is possible this node and all dependent code in the unfolding library
        /// will be replaced by faster triangle representation that does not require
        /// conversion to a surface.
        /// </summary>
        /// <param name="surfaces"></param>
        /// <param name="tolerance"> tolerance between the surface and mesh representation</param>
        /// <param name="maxGridLines">maximum number of surface divisons that define one direction of the mesh </param>
        /// <returns name = "Surfaces"> a list of trimmed planar surfaces that represent triangles</returns>
        public static List <Surface> _TesselateSurfaces(List <Surface> surfaces, double tolerance = -1, int maxGridLines = 512)
        {
            var pointtuples = Tesselation.Tessellate(surfaces, tolerance, maxGridLines);
            //convert triangles to surfaces
            List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
            {
                x[0], x[1], x[2]
            })).ToList();

            return(trisurfaces);
        }
Ejemplo n.º 10
0
        private static Surface TestSurface()
        {
            var points = new[]
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(0, 1, 0),
                Point.ByCoordinates(1, 1, 0),
                Point.ByCoordinates(1, 0, 0)
            };

            var srf = Surface.ByPerimeterPoints(points);

            return(srf);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Method for taking a list of surfaces,tesselating them at max tesselation level,
        /// and then unfolding them.
        /// </summary>
        /// <param name="surfaces"> the surfaces to be tesselated and unfolded</param>
        /// <returns name = "surfaces"> the unfolded surfaces </returns>
        public static List <List <Surface> > __UnfoldCurvedSurfacesByTesselation(List <Surface> surfaces)
        {
            surfaces.RemoveAll(item => item == null);
            //handle tesselation here
            var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
            //convert triangles to surfaces
            List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
            {
                x[0], x[1], x[2]
            })).ToList();

            var unfoldsurfaces = PlanarUnfolder.Unfold(trisurfaces);

            return(unfoldsurfaces.UnfoldedSurfaceSet);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the corridor surfaces.
        /// </summary>
        /// <returns></returns>
        private IList <IList <Surface> > GetCorridorSurfaces()
        {
            Utils.Log(string.Format("Corridor.GetCorridorSurfaces started...", ""));

            IList <IList <Surface> > output = new List <IList <Surface> >();

            if (null != this._corridor.CorridorSurfaces)
            {
                foreach (AeccCorridorSurface s in this._corridor.CorridorSurfaces)
                {
                    IList <Surface> surfaces = new List <Surface>();

                    foreach (AeccCorridorSurfaceMask b in s.Masks)
                    {
                        IList <Point> dSpoints = new List <Point>();

                        foreach (double[] point in b.GetPolygonPoints())
                        {
                            dSpoints.Add(Point.ByCoordinates(point[0], point[1], point[2]));
                        }

                        surfaces.Add(Surface.ByPerimeterPoints(Point.PruneDuplicates(dSpoints)));  // [20181009]
                    }

                    foreach (AeccCorridorSurfaceBoundary b in s.Boundaries)
                    {
                        IList <Point> dSpoints = new List <Point>();

                        foreach (double[] point in b.GetPolygonPoints())
                        {
                            dSpoints.Add(Point.ByCoordinates(point[0], point[1], point[2]));
                        }

                        surfaces.Add(Surface.ByPerimeterPoints(Point.PruneDuplicates(dSpoints)));  // [20181009]
                    }

                    if (surfaces.Count > 0)
                    {
                        output.Add(surfaces);
                    }
                }
            }

            Utils.Log(string.Format("Corridor.GetCorridorSurfaces completed.", ""));

            //TODO raise exception for no corridor surfaces
            return(output);
        }
Ejemplo n.º 13
0
        private static PolySurface GetObjGroupMesh(Group group, LoadResult result)
        {
            var polygons = new List <Surface>();
            var points   = new List <Point>();

            foreach (var face in group.Faces)
            {
                for (int i = 0; i < face.Count; i++)
                {
                    var index = face[i].VertexIndex - 1;
                    points.Add(Point.ByCoordinates(result.Vertices[index].X, result.Vertices[index].Y, result.Vertices[index].Z));
                }
            }

            for (int i = 0; i < points.Count; i += 3)
            {
                int j = i + 1;
                int k = i + 2;

                var point1 = points[i];
                var point2 = points[j];
                var point3 = points[k];

                var facePoints = new List <Point>()
                {
                    point1, point2, point3
                };
                try
                {
                    polygons.Add(Surface.ByPerimeterPoints(facePoints));
                    point1.Dispose();
                    point2.Dispose();
                    point3.Dispose();
                }
                catch
                {
                    point1.Dispose();
                    point2.Dispose();
                    point3.Dispose();
                    continue;
                }
            }

            return(PolySurface.ByJoinedSurfaces(polygons));
        }
Ejemplo n.º 14
0
        public static Surface ExtractSurface(Autodesk.Revit.DB.PlanarFace face, IEnumerable <PolyCurve> edgeLoops)
        {
            edgeLoops = edgeLoops.ToList();

            var x = face.XVector.ToVector(false);
            var y = face.YVector.ToVector(false);

            // Construct planar surface larger than the biggest edge loop
            var or        = edgeLoops.First().StartPoint; // don't use origin provided by revit, could be anywhere
            var maxLength = edgeLoops.Max(pc => pc.Length);
            var bigx      = x.Scale(maxLength * 2);
            var bigy      = y.Scale(maxLength * 2);

            return(Surface.ByPerimeterPoints(new[] { or.Subtract(bigx).Subtract(bigy),
                                                     or.Add(bigx).Subtract(bigy),
                                                     or.Add(bigx).Add(bigy),
                                                     or.Subtract(bigx).Add(bigy) }));
        }
Ejemplo n.º 15
0
            public void FullyUnfoldConeTallFromTriSurfaces()
            {
                Solid          testCone = UnfoldTestUtils.SetupTallCone();
                List <Face>    faces    = testCone.Faces.ToList();
                List <Surface> surfaces = faces.Select(x => x.SurfaceGeometry()).ToList();

                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();


                var unfoldsurfaces = PlanarUnfolder.Unfold(trisurfaces).UnfoldedSurfaceSet;

                UnfoldTestUtils.CheckAllUnfoldedFacesForCorrectUnfold(unfoldsurfaces);
            }
Ejemplo n.º 16
0
        public static Dictionary <string, object> __UnfoldCurvedSurfacesByTessellation_AndReturnTransforms(List <Surface> surfaces)
        {
            surfaces.RemoveAll(item => item == null);
            //handle tesselation here
            var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
            //convert triangles to surfaces
            List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
            {
                x[0], x[1], x[2]
            })).ToList();

            var unfolding = PlanarUnfolder.Unfold(trisurfaces);

            return(new Dictionary <string, object>
            {
                { "surfaces", (unfolding.UnfoldedSurfaceSet) },
                { "unfoldingObject", (unfolding) },
            });
        }
Ejemplo n.º 17
0
            public void UnfoldOf300TriSurface()
            {
                var surface = UnfoldTestUtils.SetupArcLoft();

                var surfaces = new List <Surface>()
                {
                    surface
                };

                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();

                Assert.DoesNotThrow(() => PlanarUnfolder.Unfold(trisurfaces));
            }
Ejemplo n.º 18
0
            public void UnfoldEachPairOfTriangularSurfacesInAConeWideParentAsRefFace()
            {
                Solid          testCone = UnfoldTestUtils.SetupLargeCone();
                List <Face>    faces    = testCone.Faces.ToList();
                List <Surface> surfaces = faces.Select(x => x.SurfaceGeometry()).ToList();

                //handle tesselation here
                var pointtuples = Tesselation.Tessellate(surfaces, -1, 512);
                //convert triangles to surfaces
                List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
                {
                    x[0], x[1], x[2]
                })).ToList();

                //generate a graph of the cube
                var graph = ModelTopology.GenerateTopologyFromSurfaces(trisurfaces);


                UnfoldTestUtils.AssertEachFacePairUnfoldsCorrectly(graph);
            }
Ejemplo n.º 19
0
        /// <summary>
        /// Adds Surfaces on a given set of surfaces that represent windows in a size specified through the glazing percentage factor
        /// </summary>
        /// <param name="surfaces">Set of surfaces to place the windows on</param>
        /// <param name="percentage">Glazing percentage [0.05 - 0.95]</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static List <Surface> ByGlazingPercentage(List <Surface> surfaces, double percentage = 0.5)
        {
            // check for the right percentage value and throw an exeption if fails
            if (percentage < 0.05 || percentage > 0.95)
            {
                throw new ArgumentException("The glazing percentage has to be between 0.05 and 0.95");
            }

            var fenestrationsurfaceList = new List <Surface>();

            // iterate over the surfaces
            foreach (var surface in surfaces)
            {
                //surface.Tessellate(null, null);

                //var edge1 = surface.Edges.First().CurveGeometry.Length;
                //var edge2 = surface.Edges.Last();

                var vec1 = Vector.ByTwoPoints(surface.Vertices.First().PointGeometry, surface.Vertices[1].PointGeometry);
                var vec2 = Vector.ByTwoPoints(surface.Vertices[0].PointGeometry, surface.Vertices[3].PointGeometry);
                //calculate the distance from the border (offset) from the given surface
                var length = vec1.Length;
                var height = vec2.Length;
                var dist   = ((height + length) - Math.Sqrt(Math.Pow(height, 2) + Math.Pow(length, 2) + (4 * percentage - 2) * height * length)) / 4;

                //calculate new points for the FenestrationSurface
                var points = new List <Point>();
                // var coordSystem = surface.CoordinateSystemAtParameter(0.0, 0.0); // may have Problems of orientation ?!?
                var coordSystem = CoordinateSystem.ByOriginVectors(surface.Vertices[0].PointGeometry, vec1, vec2);
                points.Add(Point.ByCartesianCoordinates(coordSystem, dist, dist));
                points.Add(Point.ByCartesianCoordinates(coordSystem, length - dist, dist));
                points.Add(Point.ByCartesianCoordinates(coordSystem, length - dist, height - dist));
                points.Add(Point.ByCartesianCoordinates(coordSystem, dist, height - dist));

                var fenestrationSurface = Surface.ByPerimeterPoints(points);
                //add to List
                fenestrationsurfaceList.Add(fenestrationSurface);
            }
            //return List
            return(fenestrationsurfaceList);
        }
Ejemplo n.º 20
0
        private void ByBrepNameCategoryMaterial_Surface()
        {
            var p1 = Point.ByCoordinates(0.0, 0.0, 0.0);
            var p2 = Point.ByCoordinates(0.0, 10.0, 0.0);
            var p3 = Point.ByCoordinates(5.0, 10.0, 0.0);
            var p4 = Point.ByCoordinates(5.0, 5.0, 0.0);
            var p5 = Point.ByCoordinates(10.0, 5.0, 0.0);
            var p6 = Point.ByCoordinates(10.0, 0.0, 0.0);

            // Create a L-Shaped surface
            var s1 = Surface.ByPerimeterPoints(new List <Point>()
            {
                p1, p2, p3, p4, p5, p6
            });

            var mat = DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Material>().First();
            var ds  = DirectShape.ByGeometry(s1, Category.ByName("OST_GenericModel"), Material.ByName(mat.Name), "a l-shaped surface");

            s1.Dispose();

            Assert.NotNull(ds);

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
            DocumentManager.Regenerate();
            var Revitgeo = ds.InternalElement.get_Geometry(new Autodesk.Revit.DB.Options());

            TransactionManager.Instance.TransactionTaskDone();
            var geo = Revitgeo.First() as Autodesk.Revit.DB.Solid;

            Assert.NotNull(geo);
            // Check number of faces
            Assert.AreEqual(1, geo.Faces.Size);
            // Check number of Edges
            Assert.AreEqual(6, geo.Edges.Size);
            // Check that material is set
            Assert.AreNotEqual(-1, geo.Faces.get_Item(0).MaterialElementId.IntegerValue);

            // Check bounding box to make sure we got unit conversion right
            ds.BoundingBox.MaxPoint.ShouldBeApproximately(10.0, 10.0, 0.0);
        }
Ejemplo n.º 21
0
        public void ByMeshAndBySurfaceBothLocatedSameMetric()
        {
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            DocumentManager.Instance.CurrentDBDocument.SetUnits(new Autodesk.Revit.DB.Units(Autodesk.Revit.DB.UnitSystem.Metric));

            TransactionManager.Instance.TransactionTaskDone();

            var p1 = Point.ByCoordinates(0.0, 0.0, 0.0);
            var p2 = Point.ByCoordinates(1.0, 1.0, 0);
            var p3 = Point.ByCoordinates(2.0, 0, 0);

            var index1 = IndexGroup.ByIndices(0, 1, 2);

            var mesh = Mesh.ByPointsFaceIndices(new List <Point>()
            {
                p1, p2, p3
            }, new List <IndexGroup>()
            {
                index1
            });
            var surf = Surface.ByPerimeterPoints(new List <Point>()
            {
                p1, p2, p3
            });

            var mat = DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Material>().First();

            var ds     = DirectShape.ByMesh(mesh, Category.ByName("OST_GenericModel"), Material.ByName(mat.Name), "a mesh");
            var dsSurf = DirectShape.ByGeometry(surf, Category.ByName("OST_GenericModel"), Material.ByName(mat.Name), "a surf");

            BoundingBoxCentroid(ds).DistanceTo(BoundingBoxCentroid(dsSurf)).ShouldBeApproximately(0);

            Surface.ByPerimeterPoints((ds.Geometry().First() as Mesh).VertexPositions).Area.ShouldDifferByLessThanPercentage(
                (dsSurf.Geometry().First() as Surface).Area, ApproximateAssertExtensions.Epsilon);


            mesh.Dispose();
            surf.Dispose();
        }
Ejemplo n.º 22
0
        // The following methods may be removed from Import eventually
        #region explorationdebug
        // method is for debugging the BFS output visually in dynamo, very useful
        public static object __BFSTestTesselation(List <Surface> surfaces, double tolerance = -1, int maxGridLines = 512)
        {
            //handle tesselation here
            var pointtuples = Tesselation.Tessellate(surfaces, tolerance, maxGridLines);
            //convert triangles to surfaces
            List <Surface> trisurfaces = pointtuples.Select(x => Surface.ByPerimeterPoints(new List <Point>()
            {
                x[0], x[1], x[2]
            })).ToList();

            var graph = ModelTopology.GenerateTopologyFromSurfaces(trisurfaces);

            //perform BFS on the graph and get back the tree
            var nodereturn = ModelGraph.BFS <EdgeLikeEntity, FaceLikeEntity>(graph);
            var tree       = nodereturn;

            var treegeo = ModelGraph.ProduceGeometryFromGraph <EdgeLikeEntity, FaceLikeEntity>
                              (tree as List <GraphVertex <EdgeLikeEntity, FaceLikeEntity> >);


            return(treegeo);
        }
Ejemplo n.º 23
0
        public static Dictionary <string, object> QuadPanel(Surface Surface, double Udivision, double Vdivision)
        {
            var panels   = new List <Surface>();
            var polygons = new List <Polygon>();

            for (var i = 0; i < Udivision; i++)
            {
                for (var j = 0; j < Vdivision; j++)
                {
                    var points = new List <Point>();

                    var ustep = 1.0 / Udivision;
                    var vstep = 1.0 / Vdivision;

                    var pA = Surface.PointAtParameter(i * ustep, j * vstep);
                    var pB = Surface.PointAtParameter((i + 1) * ustep, j * vstep);
                    var pC = Surface.PointAtParameter((i + 1) * ustep, (j + 1) * vstep);
                    var pD = Surface.PointAtParameter(i * ustep, (j + 1) * vstep);

                    points.Add(pA);
                    points.Add(pB);
                    points.Add(pC);
                    points.Add(pD);

                    panels.Add(Surface.ByPerimeterPoints(points));
                    polygons.Add(Polygon.ByPoints(points));

                    pA.Dispose();
                    pB.Dispose();
                    pC.Dispose();
                    pD.Dispose();
                }
            }

            return(new Dictionary <string, object> {
                { "Panels", panels }, { "Polygons", polygons }
            });
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 将Mesh转化为PolySurface
        /// </summary>
        /// <param name="mesh">网格</param>
        /// <returns>转化后的PolySurface</returns>
        public static PolySurface ConvertToPolySurface(Mesh mesh)
        {
            List <Surface> surfaces = new List <Surface>();

            Point[]      vertexs    = mesh.VertexPositions;
            IndexGroup[] indexGroup = mesh.FaceIndices;
            foreach (var item in indexGroup)
            {
                if (item.Count == 3)
                {
                    Point   pt1     = vertexs[item.A];
                    Point   pt2     = vertexs[item.B];
                    Point   pt3     = vertexs[item.C];
                    Surface surface = Surface.ByPerimeterPoints(new Point[] { pt1, pt2, pt3 });
                    surfaces.Add(surface);
                    pt1.Dispose();
                    pt2.Dispose();
                    pt3.Dispose();
                    surface.Dispose();
                }
                else
                {
                    Point pt1 = vertexs[item.A];
                    Point pt2 = vertexs[item.B];
                    Point pt3 = vertexs[item.C];
                    Point pt4 = vertexs[item.D];

                    Surface surface = Surface.ByPerimeterPoints(new Point[] { pt1, pt2, pt3, pt4 });
                    surfaces.Add(surface);
                    pt1.Dispose();
                    pt2.Dispose();
                    pt3.Dispose();
                    surface.Dispose();
                }
            }
            return(PolySurface.ByJoinedSurfaces(surfaces));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds EnergyPlus Windows (FenestrationSurface) to a list of rectangular EnergyPlus Surfaces by a given percentage.
        /// </summary>
        /// <param name="buildingSurfaces">A list of BuildingSurfaces where the windows should be added to.</param>
        /// <param name="percentage">The glazing percentage (factor). Has to be between 0.05 and 0.95!</param>
        /// <returns></returns>
        public static List <FenestrationSurface> ByGlazingPercentage(List <BuildingSurface> buildingSurfaces, double percentage = 0.5)
        {
            // check for the right percentage value and throw an exeption if fails
            if (percentage < 0.05 || percentage > 0.95)
            {
                throw new ArgumentException("The glazing percentage has to be between 0.05 and 0.95");
            }

            var fenestrationsurfaceList = new List <FenestrationSurface>();

            // iterate over the surfaces
            foreach (var buildingSurface in buildingSurfaces)
            {
                var vec1 = Vector.ByTwoPoints(buildingSurface.Surface.Vertices[0].PointGeometry, buildingSurface.Surface.Vertices[1].PointGeometry);
                var vec2 = Vector.ByTwoPoints(buildingSurface.Surface.Vertices[0].PointGeometry, buildingSurface.Surface.Vertices[3].PointGeometry);
                //calculate the distance from the border (offset) from the given Surface
                var length = vec1.Length;
                var height = vec2.Length;
                var dist   = ((height + length) - Math.Sqrt(Math.Pow(height, 2) + Math.Pow(length, 2) + (4 * percentage - 2) * height * length)) / 4;

                //calculate new points for the FenestrationSurface
                var points      = new List <Point>();
                var coordSystem = CoordinateSystem.ByOriginVectors(buildingSurface.Surface.Vertices[0].PointGeometry, vec1, vec2);
                points.Add(Point.ByCartesianCoordinates(coordSystem, dist, dist));
                points.Add(Point.ByCartesianCoordinates(coordSystem, length - dist, dist));
                points.Add(Point.ByCartesianCoordinates(coordSystem, length - dist, height - dist));
                points.Add(Point.ByCartesianCoordinates(coordSystem, dist, height - dist));

                var surface = Surface.ByPerimeterPoints(points);

                //add to List
                fenestrationsurfaceList.Add(new FenestrationSurface(surface, buildingSurface, 1));
            }
            //return List
            return(fenestrationsurfaceList);
        }