コード例 #1
0
 public void CreateXbimFacetedSolidFromIfcRectangleHollowProfileDef()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1);
             var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var solid   = XbimGeometryCreator.CreateSolid(extrude);
             var faceted = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
             foreach (var face in faceted.Faces)
             {
                 Assert.IsTrue(face.OuterBound.Edges.Count == 4, "Each face should have four outer edges");
             }
             int hasInnerCount = 0;
             foreach (var face in faceted.Faces)
             {
                 if (face.InnerBounds.Count == 1)
                 {
                     hasInnerCount++;
                     Assert.IsTrue(face.InnerBounds.First.Edges.Count == 4, "Each face should have four inner edges");
                 }
             }
             Assert.IsTrue(hasInnerCount == 2, "There should be two faces with an innerbound");
             Assert.IsTrue(faceted.Shells.Count == 1, "Should only be one shell");
             Assert.IsTrue(faceted.Vertices.Count == faceted.Shells.First.Vertices.Count, "Should be one shell with the same number of vertices");
         }
     }
 }
コード例 #2
0
 public void RectangleHollowProfileDefTest()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var prof = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 30, 5);
             var face = _xbimGeometryCreator.CreateFace(prof);
             Assert.IsTrue(face.Area > 0);
         }
     }
 }
コード例 #3
0
        public void ConvertIfcRectangleHollowProfileToBRepTest()
        {
            using (var m = IfcModelBuilder.CreateandInitModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    //add a shape
                    //Create a Definition shape to hold the geometry
                    var shape = m.Instances.New <IfcShapeRepresentation>();
                    shape.ContextOfItems           = m.IfcProject.ModelContext();
                    shape.RepresentationType       = "Brep";
                    shape.RepresentationIdentifier = "Body";

                    //Create a Product Definition and add the model geometry to the wall
                    var rep = m.Instances.New <IfcProductDefinitionShape>();
                    rep.Representations.Add(shape);
                    var building = m.Instances.OfType <IfcBuilding>().FirstOrDefault();
                    Assert.IsNotNull(building, "Failed to find Building");
                    building.Representation = rep;



                    var block = IfcModelBuilder.MakeExtrudedAreaSolid(m, IfcModelBuilder.MakeRectangleHollowProfileDef(m, 10, 20, 1), 30);
                    var solid = _xbimGeometryCreator.CreateSolid(block);

                    var brep = _xbimGeometryCreator.CreateFacetedBrep(m, solid);

                    shape.Items.Add(brep);

                    var solid2 = _xbimGeometryCreator.CreateSolidSet(brep); //round trip it

                    txn.Commit();
                    try
                    {
                        //Uncomment below to see the results in Ifc
                        //m.SaveAs("brep.ifc", XbimStorageType.IFC);
                    }
                    catch (Exception)
                    {
                        Assert.IsTrue(false, "Failed to save the results to Ifc");
                    }
                    Assert.IsTrue(solid2.Count == 1, "Expected one solid");
                    IfcCsgTests.GeneralTest(solid2.First);
                    int volDiff = (int)Math.Abs(solid.Volume - solid2.First.Volume); //nearest cubic millimetre
                    Assert.IsTrue(volDiff == 0, "Volume of round tripped solid is not the same");
                }
            }
        }
コード例 #4
0
 public void ReadWriteTriangulationOfPlanarSolidTest()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var        profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1);
             var        extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var        solid   = XbimGeometryCreator.CreateSolid(extrude);
             TextWriter tw      = new StringWriter();
             XbimGeometryCreator.WriteTriangulation(tw, solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 0.5);
             TextReader          tr   = new StringReader(tw.ToString());
             IXbimGeometryObject geom = XbimGeometryCreator.ReadTriangulation(tr);
             var triangulatedSold     = geom as IXbimSolid;
             Assert.IsNotNull(triangulatedSold, "Invalid solid returned");
             Assert.IsTrue(Math.Abs(solid.Volume - triangulatedSold.Volume) < 0.001, "Volume differs");
         }
     }
 }
コード例 #5
0
 public void ConvertXbimSolidFromXbimFacetedSolidPlanarTest()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1);
             var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var solid   = XbimGeometryCreator.CreateSolid(extrude);
             var faceted = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision,
                                                                  m.ModelFactors.DeflectionTolerance);
             var solid2 = XbimGeometryCreator.CreateSolid(faceted);
             Assert.IsTrue(solid.Shells.Count == solid2.Shells.Count, "Shell count differs");
             Assert.IsTrue(solid.Faces.Count == solid2.Faces.Count, "Face count differs");
             Assert.IsTrue(solid.Edges.Count == solid2.Edges.Count, "Edge count differs");
             Assert.IsTrue(solid.Vertices.Count == solid2.Vertices.Count, "Vertex count differs");
             Assert.IsTrue(Math.Abs(solid.Volume - solid2.Volume) < 0.001, "Volume differs");
         }
     }
 }
コード例 #6
0
 public void TransformFacetedSolidRectangularProfileDef()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1);
             var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var solid   = XbimGeometryCreator.CreateSolid(extrude);
             solid = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 0.5);
             var transform = new XbimMatrix3D(); //test first with identity
             var solid2    = solid.Transform(transform);
             var s1Verts   = solid.Vertices.ToList();
             var s2Verts   = solid2.Vertices.ToList();
             for (int i = 0; i < s1Verts.Count; i++)
             {
                 XbimVector3D v = s1Verts[i].VertexGeometry - s2Verts[i].VertexGeometry;
                 Assert.IsTrue(v.Length < m.ModelFactors.Precision, "vertices not the same");
             }
             transform.RotateAroundXAxis(Math.PI / 2);
             transform.RotateAroundYAxis(Math.PI / 4);
             transform.RotateAroundZAxis(Math.PI);
             transform.OffsetX += 100;
             transform.OffsetY += 200;
             transform.OffsetZ += 300;
             solid2             = solid.Transform(transform);
             Assert.IsTrue(Math.Abs(solid.Volume - solid2.Volume) < 0.001, "Volume differs");
             transform.Invert();
             solid2  = solid2.Transform(transform);
             s1Verts = solid.Vertices.ToList();
             s2Verts = solid2.Vertices.ToList();
             for (int i = 0; i < s1Verts.Count; i++)
             {
                 XbimVector3D v = s1Verts[i].VertexGeometry - s2Verts[i].VertexGeometry;
                 Assert.IsTrue(v.Length < m.ModelFactors.Precision, "vertices not the same");
             }
         }
     }
 }