示例#1
0
        /// <summary>
        /// Calculates the maximum number of points in this object, does not remove geometric duplicates
        /// </summary>
        /// <param name="sbsm"></param>
        /// <returns></returns>
        public static int NumberOfPointsMax(this IfcFaceBasedSurfaceModel fbsm)
        {
            int pointCount = 0;

            foreach (IfcConnectedFaceSet cfs in fbsm.FbsmFaces)
            {
                pointCount += cfs.NumberOfPointsMax();
            }
            return(pointCount);
        }
示例#2
0
        public IXbimShapeGeometryData Mesh(IfcFaceBasedSurfaceModel faceBasedModel)
        {
            var faceSets = new List <IEnumerable <IfcFace> >();

            foreach (var faceSet in faceBasedModel.FbsmFaces)
            {
                faceSets.Add(faceSet.CfsFaces);
            }
            return(Mesh(faceSets, faceBasedModel.EntityLabel, (float)faceBasedModel.ModelOf.ModelFactors.Precision));
        }
示例#3
0
        /// <summary>
        /// returns a Hash for the geometric behaviour of this object
        /// </summary>
        /// <param name="solid"></param>
        /// <returns></returns>
        public static int GetGeometryHashCode(this  IfcFaceBasedSurfaceModel fbsm)
        {
            int hash = fbsm.FbsmFaces.Count;

            if (hash > 30)
            {
                return(hash ^ fbsm.GetType().Name.GetHashCode());           //probably enough for a uniquish hash
            }
            foreach (var cfs in fbsm.FbsmFaces)
            {
                hash ^= cfs.GetGeometryHashCode();
            }
            return(hash);
        }
示例#4
0
        public override List <IfcBuildingElement> ToBuildingElementIfc(IfcStore model)
        {
            using (var transaction = model.BeginTransaction("Create Mesh Element"))
            {
                MeshFaceList             faces                 = Mesh.Faces;
                MeshVertexList           vertices              = Mesh.Vertices;
                List <IfcCartesianPoint> ifcVertices           = IfcTools.VerticesToIfcCartesianPoints(model, vertices);
                IfcFaceBasedSurfaceModel faceBasedSurfaceModel = IfcTools.CreateIfcFaceBasedSurfaceModel(model, faces, ifcVertices);
                var shape = IfcTools.CreateIfcShapeRepresentation(model, "Mesh");
                shape.Items.Add(faceBasedSurfaceModel);
                var ifcRelAssociatesMaterial = IfcTools.CreateIfcRelAssociatesMaterial(model, Material.Name, Material.Grade);
                var buildingElements         = IfcTools.CreateBuildingElements(model, ElementType, Name, shape, InsertPlanes,
                                                                               ifcRelAssociatesMaterial);

                transaction.Commit();

                return(buildingElements);
            }
        }
示例#5
0
        /// <summary>
        /// Compares two objects for geomtric equality
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b">object to compare with</param>
        /// <returns></returns>
        public static bool GeometricEquals(this  IfcFaceBasedSurfaceModel a, IfcRepresentationItem b)
        {
            IfcFaceBasedSurfaceModel p = b as IfcFaceBasedSurfaceModel;

            if (p == null)
            {
                return(false);           //different type
            }
            List <IfcConnectedFaceSet> fsa = a.FbsmFaces.ToList();
            List <IfcConnectedFaceSet> fsb = p.FbsmFaces.ToList();

            if (fsa.Count != fsb.Count)
            {
                return(false);
            }
            for (int i = 0; i < fsa.Count; i++)
            {
                if (!fsa[i].GeometricEquals(fsb[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
 public IXbimGeometryObjectSet CreateSurfaceModel(IfcFaceBasedSurfaceModel ifcSurface)
 {
     return(_engine.CreateSurfaceModel(ifcSurface));
 }
示例#7
0
        public override List <IfcReinforcingElement> ToReinforcingElementIfc(IfcStore model)
        {
            using (var transaction = model.BeginTransaction("Create Mesh Element"))
            {
                var rebars = new List <IfcReinforcingElement>();

                switch (SpacingType)
                {
                case RebarSpacingType.NormalSpacing:
                {
                    MeshFaceList             faces                 = OriginRebarShape.RebarMesh.Faces;
                    MeshVertexList           vertices              = OriginRebarShape.RebarMesh.Vertices;
                    List <IfcCartesianPoint> ifcVertices           = IfcTools.VerticesToIfcCartesianPoints(model, vertices);
                    IfcFaceBasedSurfaceModel faceBasedSurfaceModel =
                        IfcTools.CreateIfcFaceBasedSurfaceModel(model, faces, ifcVertices);
                    var shape = IfcTools.CreateIfcShapeRepresentation(model, "Mesh");
                    shape.Items.Add(faceBasedSurfaceModel);
                    var ifcRelAssociatesMaterial = IfcTools.CreateIfcRelAssociatesMaterial(model, Material.Name, Material.Grade);

                    foreach (var insertPlane in RebarInsertPlanes)
                    {
                        var rebar = model.Instances.New <IfcReinforcingBar>();
                        rebar.Name            = "Rebar";
                        rebar.NominalDiameter = Diameter;
                        rebar.BarLength       = (int)Math.Round(OriginRebarShape.RebarCurve.GetLength());
                        rebar.SteelGrade      = Material.Grade;

                        IfcTools.ApplyRepresentationAndPlacement(model, rebar, shape, insertPlane);

                        ifcRelAssociatesMaterial.RelatedObjects.Add(rebar);

                        rebars.Add(rebar);
                    }

                    break;
                }

                case RebarSpacingType.CustomSpacing:

                    for (int i = 0; i < RebarGroupMesh.Count; i++)
                    {
                        MeshFaceList             faces                 = RebarGroupMesh[i].Faces;
                        MeshVertexList           vertices              = RebarGroupMesh[i].Vertices;
                        List <IfcCartesianPoint> ifcVertices           = IfcTools.VerticesToIfcCartesianPoints(model, vertices);
                        IfcFaceBasedSurfaceModel faceBasedSurfaceModel =
                            IfcTools.CreateIfcFaceBasedSurfaceModel(model, faces, ifcVertices);
                        var shape = IfcTools.CreateIfcShapeRepresentation(model, "Mesh");
                        shape.Items.Add(faceBasedSurfaceModel);
                        var ifcRelAssociatesMaterial = IfcTools.CreateIfcRelAssociatesMaterial(model, Material.Name, Material.Grade);

                        var rebar = model.Instances.New <IfcReinforcingBar>();
                        rebar.Name            = "Rebar";
                        rebar.NominalDiameter = Diameter;
                        rebar.BarLength       = (int)Math.Round(RebarGroupCurves[i].GetLength());
                        rebar.SteelGrade      = Material.Grade;

                        IfcTools.ApplyRepresentationAndPlacement(model, rebar, shape, Plane.WorldXY);

                        ifcRelAssociatesMaterial.RelatedObjects.Add(rebar);

                        rebars.Add(rebar);
                    }

                    break;

                default:
                    throw new ArgumentException("Spacing type not recognized");
                }


                transaction.Commit();

                return(rebars);
            }
        }
示例#8
0
        public static Entity getEntityFromIfcRepresentationItem(IfcRepresentationItem reprItem, ViewportLayout viewportLayout1 = null, Transformation entityTrs = null)
        {
            Entity result = null;

            if (reprItem is IfcBooleanClippingResult)
            {
                IfcBooleanClippingResult bcr = (IfcBooleanClippingResult)reprItem;

                result = getSolidFromIfcBooleanClippingResult(bcr);
            }
            else if (reprItem is IfcCurve)
            {
                result = (Entity)getICurveFromIfcCurve((IfcCurve)reprItem, viewportLayout1, entityTrs);
            }
            else if (reprItem is IfcExtrudedAreaSolid)
            {
                IfcExtrudedAreaSolid extrAreaSolid = (IfcExtrudedAreaSolid)reprItem;

                // if (!viewportLayout1.Blocks.ContainsKey(extrAreaSolid.Index.ToString()))
                {
                    Plane pln = Conversion.getPlaneFromPosition(extrAreaSolid.Position);

                    Align3D align = new Align3D(Plane.XY, pln);

                    IfcDirection dir = extrAreaSolid.ExtrudedDirection;

                    Vector3D extDir = new Vector3D(dir.DirectionRatioX, dir.DirectionRatioY, dir.DirectionRatioZ);

                    //extDir.TransformBy(trs * align2);
                    extDir.TransformBy(align);

                    devDept.Eyeshot.Entities.Region region = getRegionFromIfcProfileDef(extrAreaSolid.SweptArea, viewportLayout1);

                    if (region != null)
                    {
                        //region.TransformBy(trs * align2);
                        region.TransformBy(align);

                        result = region.ExtrudeAsMesh(extDir * extrAreaSolid.Depth, 0.1, Mesh.natureType.Plain); // 0.1 tolerance must be computed according to object size

                        //viewportLayout1.Entities.Add(result, 1);
                        //Block b = new Block();
                        //b.Entities.Add(m);
                        //viewportLayout1.Blocks.Add(extrAreaSolid.Index.ToString(), b);
                    }
                }
                // BlockReference br = new IfcBlockReference(trs, extrAreaSolid.Index.ToString());
                // viewportLayout1.Entities.Add(br, 0, Color.Gray);
            }
            else if (reprItem is IfcFaceBasedSurfaceModel)
            {
                IfcFaceBasedSurfaceModel fbs = (IfcFaceBasedSurfaceModel)reprItem;

                result = new Mesh(0, 0, Mesh.natureType.Plain);

                foreach (IfcConnectedFaceSet cfs in fbs.FbsmFaces)
                {
                    Mesh global = new Mesh(0, 0, Mesh.natureType.Plain);

                    foreach (IfcFace face in cfs.CfsFaces)
                    {
                        Point3D[] outerPoints = null;

                        List <Point3D[]> innerPointsList = new List <Point3D[]>();

                        foreach (IfcFaceBound fb in face.Bounds)        // al massimo 2 ? profilo esterno e interno
                        {
                            // bool sense = ifb.mOrientation;

                            if (fb is IfcFaceOuterBound)
                            {
                                IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb;

                                IfcPolyloop pl = (IfcPolyloop)fb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < pl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                outerPoints = pLIst.ToArray();

                                if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1]))
                                {
                                    Array.Resize(ref outerPoints, outerPoints.Length + 1);

                                    outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone();
                                }
                                Array.Reverse(outerPoints);
                            }
                            else
                            {
                                IfcFaceBound ifb = (IfcFaceBound)fb;

                                IfcPolyloop inPl = (IfcPolyloop)ifb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < inPl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                Point3D[] innerPoints = pLIst.ToArray();

                                if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1]))
                                {
                                    Array.Resize(ref innerPoints, innerPoints.Length + 1);

                                    innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone();
                                }
                                Array.Reverse(innerPoints);

                                innerPointsList.Add(innerPoints);
                            }
                        }
                        if (outerPoints.Length > 3)
                        {
                            Mesh local;

                            List <LinearPath> boundLp = new List <LinearPath>();

                            boundLp.Add(new LinearPath(outerPoints));

                            foreach (Point3D[] innerPoints in innerPointsList)
                            {
                                boundLp.Add(new LinearPath(innerPoints));
                            }

                            local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain);

                            global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine
                        }
                    }
                    ((Mesh)result).MergeWith(global, true);
                }
            }
            else if (reprItem is IfcFacetedBrep)  //controllare
            {
                IfcFacetedBrep facBrep = (IfcFacetedBrep)reprItem;

                IfcClosedShell cs = facBrep.Outer;

                Mesh global = new Mesh(0, 0, Mesh.natureType.Plain);

                foreach (IfcFace face in cs.CfsFaces)
                {
                    Point3D[] outerPoints = null;

                    List <Point3D[]> innerPointsList = new List <Point3D[]>();

                    foreach (IfcFaceBound fb in face.Bounds)
                    {
                        // bool sense = ifb.mOrientation;

                        if (fb is IfcFaceOuterBound)
                        {
                            IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb;

                            IfcPolyloop pl = (IfcPolyloop)fb.Bound;

                            List <Point3D> pLIst = new List <Point3D>();

                            for (int i = 0; i < pl.Polygon.Count; i++)
                            {
                                Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]);

                                if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                {
                                    pLIst.Add(p);
                                }
                            }

                            outerPoints = pLIst.ToArray();

                            if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1]))
                            {
                                Array.Resize(ref outerPoints, outerPoints.Length + 1);

                                outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone();
                            }
                            Array.Reverse(outerPoints);
                        }
                        else
                        {
                            IfcFaceBound ifb = (IfcFaceBound)fb;

                            IfcPolyloop inPl = (IfcPolyloop)ifb.Bound;

                            List <Point3D> pLIst = new List <Point3D>();

                            for (int i = 0; i < inPl.Polygon.Count; i++)
                            {
                                Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]);

                                if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                {
                                    pLIst.Add(p);
                                }
                            }

                            Point3D[] innerPoints = pLIst.ToArray();

                            if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1]))
                            {
                                Array.Resize(ref innerPoints, innerPoints.Length + 1);

                                innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone();
                            }
                            Array.Reverse(innerPoints);

                            innerPointsList.Add(innerPoints);
                        }
                    }
                    if (outerPoints.Length > 3)
                    {
                        Mesh local;

                        List <LinearPath> boundLp = new List <LinearPath>();

                        boundLp.Add(new LinearPath(outerPoints));

                        foreach (Point3D[] innerPoints in innerPointsList)
                        {
                            boundLp.Add(new LinearPath(innerPoints));
                        }
                        local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain);

                        global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine
                    }
                }

                result = global;
            }
            //else if (repItem is IfcBoundingBox)
            //{
            //    IfcBoundingBox bBox = (IfcBoundingBox)iRep.Items[0];
            //    m = Mesh.CreateBox(bBox.XDim, bBox.YDim, bBox.ZDim);
            //    m.Translate(bBox.Corner.Coordinates.Item1, bBox.Corner.Coordinates.Item1, bBox.Corner.Coordinates.Item1);
            //}
            else if (reprItem is IfcMappedItem)
            {
                IfcMappedItem mapItem = (IfcMappedItem)reprItem;

                if (!viewportLayout1.Blocks.ContainsKey("MappingSource " + mapItem.MappingSource.Index.ToString()))
                {
                    IfcRepresentationMap reprMapSource = mapItem.MappingSource;

                    Entity mapSource = getEntityFromIfcRepresentation(reprMapSource.MappedRepresentation, viewportLayout1, entityTrs);

                    Block b = new Block();

                    if (mapSource != null)
                    {
                        Plane pln = getPlaneFromPosition((IfcPlacement)reprMapSource.MappingOrigin);

                        Align3D algn = new Align3D(Plane.XY, pln);

                        mapSource.TransformBy(algn);

                        b.Entities.Add(mapSource);
                    }

                    viewportLayout1.Blocks.Add("MappingSource " + mapItem.MappingSource.Index.ToString(), b);
                }

                IfcCartesianTransformationOperator3D iTrs = (IfcCartesianTransformationOperator3D)mapItem.MappingTarget;

                Point3D org = new Point3D(iTrs.LocalOrigin.Coordinates.Item1, iTrs.LocalOrigin.Coordinates.Item2, iTrs.LocalOrigin.Coordinates.Item3);

                Vector3D vectorX;

                if (iTrs.Axis1 != null)
                {
                    vectorX = new Vector3D(iTrs.Axis1.DirectionRatioX, iTrs.Axis1.DirectionRatioY, iTrs.Axis1.DirectionRatioZ);
                }
                else
                {
                    vectorX = new Vector3D(1, 0, 0);
                }
                vectorX = vectorX * iTrs.Scale;

                Vector3D vectorY;

                if (iTrs.Axis2 != null)
                {
                    vectorY = new Vector3D(iTrs.Axis2.DirectionRatioX, iTrs.Axis2.DirectionRatioY, iTrs.Axis2.DirectionRatioZ);
                }
                else
                {
                    vectorY = new Vector3D(0, 1, 0);
                }

                Vector3D vectorZ;

                if (iTrs.Axis1 != null)
                {
                    vectorZ = new Vector3D(iTrs.Axis3.DirectionRatioX, iTrs.Axis3.DirectionRatioY, iTrs.Axis3.DirectionRatioZ);
                }
                else
                {
                    vectorZ = new Vector3D(0, 0, 1);
                }

                if (iTrs is IfcCartesianTransformationOperator3DnonUniform)
                {
                    IfcCartesianTransformationOperator3DnonUniform nut = (IfcCartesianTransformationOperator3DnonUniform)iTrs;

                    vectorY = vectorY * nut.Scale2;

                    vectorZ = vectorZ * nut.Scale3;
                }


                Transformation targetTrs = new Transformation(org, vectorX, vectorY, vectorZ);

                result = new IfcBlockReference(targetTrs, "MappingSource " + mapItem.MappingSource.Index.ToString());
            }
            else if (reprItem is IfcShellBasedSurfaceModel)
            {
                IfcShellBasedSurfaceModel sbs = (IfcShellBasedSurfaceModel)reprItem;

                result = new Mesh(0, 0, Mesh.natureType.Plain);

                foreach (IfcShell cfs in sbs.SbsmBoundary)
                {
                    Mesh global = new Mesh(0, 0, Mesh.natureType.Plain);

                    foreach (IfcFace face in cfs.CfsFaces)
                    {
                        Point3D[] outerPoints = null;

                        List <Point3D[]> innerPointsList = new List <Point3D[]>();

                        foreach (IfcFaceBound fb in face.Bounds)        // al massimo 2 ? profilo esterno e interno
                        {
                            // bool sense = ifb.mOrientation;

                            if (fb is IfcFaceOuterBound)
                            {
                                IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb;

                                IfcPolyloop pl = (IfcPolyloop)fb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < pl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                outerPoints = pLIst.ToArray();

                                if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1]))
                                {
                                    Array.Resize(ref outerPoints, outerPoints.Length + 1);

                                    outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone();
                                }
                                Array.Reverse(outerPoints);
                            }
                            else
                            {
                                IfcFaceBound ifb = (IfcFaceBound)fb;

                                IfcPolyloop inPl = (IfcPolyloop)ifb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < inPl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                Point3D[] innerPoints = pLIst.ToArray();

                                if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1]))
                                {
                                    Array.Resize(ref innerPoints, innerPoints.Length + 1);

                                    innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone();
                                }
                                Array.Reverse(innerPoints);

                                innerPointsList.Add(innerPoints);
                            }
                        }
                        if (outerPoints.Length > 3)
                        {
                            Mesh local;

                            List <LinearPath> boundLp = new List <LinearPath>();

                            boundLp.Add(new LinearPath(outerPoints));

                            foreach (Point3D[] innerPoints in innerPointsList)
                            {
                                boundLp.Add(new LinearPath(innerPoints));
                            }

                            //devDept.Eyeshot.Entities.Region localRegion = new devDept.Eyeshot.Entities.Region(boundLp.ToArray());

                            //localRegion.TransformBy(entityTrs);

                            //viewportLayout1.Entities.Add(localRegion, 1);



                            local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain);



                            global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine
                        }
                    }
                    ((Mesh)result).MergeWith(global, true);
                }
            }
            else
            {
                if (!debug.Contains("IfcRepresentationItem not supported: " + reprItem.KeyWord))
                {
                    debug += "IfcRepresentationItem not supported: " + reprItem.KeyWord + "\n";
                }
            }

            if (result != null)
            {
                Color color;
                if (tryGetColorFromIfcRepresentationItem(reprItem, out color))
                {
                    result.ColorMethod = colorMethodType.byEntity;

                    result.Color = color;
                }
                else
                {
                    result.ColorMethod = colorMethodType.byParent;
                }
            }

            return(result);
        }