コード例 #1
0
 public void MoveAndCopyTest()
 {
     //this test checks that a object is correctly copied and moved
     //create a box
     using (
         var m = IfcStore.Create(new XbimEditorCredentials(), IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel)
         )
     {
         using (var txn = m.BeginTransaction())
         {
             var block = IfcModelBuilder.MakeBlock(m, 10, 10, 10);
             var solid = _geomEngine.CreateSolid(block);
             var ax3D  = IfcModelBuilder.MakeAxis2Placement3D(m);
             ax3D.Location.Y = 100;
             var solidA = _geomEngine.Moved(solid, ax3D) as IXbimSolid;
             Assert.IsNotNull(solidA, "Should be the same type as the master");
             Assert.IsTrue(Math.Abs(solidA.Volume - solid.Volume) < 1e-9, "Volume has changed");
             var displacement = solidA.BoundingBox.Centroid() - solid.BoundingBox.Centroid();
             Assert.IsTrue(displacement == new XbimVector3D(0, 100, 0));
             var bbA    = solidA.BoundingBox;
             var solidB = _geomEngine.Moved(solid, ax3D);
             Assert.IsTrue(bbA.Centroid() - solidB.BoundingBox.Centroid() == new XbimVector3D(0, 0, 0));
         }
     }
 }
コード例 #2
0
 public void ScaleAndCopyTest()
 {
     //this test checks that a object is correctly copied and moved
     //create a box
     using (
         var m = IfcStore.Create(new XbimEditorCredentials(), IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel)
         )
     {
         using (var txn = m.BeginTransaction())
         {
             var block     = IfcModelBuilder.MakeBlock(m, 10, 10, 10);
             var solid     = _geomEngine.CreateSolid(block);
             var transform = IfcModelBuilder.MakeCartesianTransformationOperator3D(m);
             transform.Scale = 2;
             var solidA = _geomEngine.Transformed(solid, transform);
             var bb     = solid.BoundingBox;
             var bbA    = solidA.BoundingBox;
             Assert.IsTrue(Math.Abs(bb.Volume - 1000) < 1e-9, "Bounding box volume is incorrect in original shape");
             Assert.IsTrue(Math.Abs(bbA.Volume - 8000) < 1e-9, "Bounding box volume is incorrect in scaled shape");
             var transformNonUniform = IfcModelBuilder.MakeCartesianTransformationOperator3DnonUniform(m);
             transformNonUniform.Scale3 = 100;
             var solidB = _geomEngine.Transformed(solid, transformNonUniform);
             Assert.IsTrue(Math.Abs(solidB.BoundingBox.Volume - 100000) < 1e-9, "Bounding box volume is incorrect in non uniform scaled shape");
             Assert.IsTrue(Math.Abs(bb.Volume - 1000) < 1e-9, "Bounding box volume of original shape as been changed");
         }
     }
 }
コード例 #3
0
        public void ObjectPlacementTest()
        {
            //this test checks that a object is correctly copied and moved
            //create a box
            using (
                var m = IfcStore.Create(new XbimEditorCredentials(), IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel)
                )
            {
                using (var txn = m.BeginTransaction())
                {
                    var block     = IfcModelBuilder.MakeBlock(m, 50, 10, 10);
                    var solid     = _geomEngine.CreateSolid(block);
                    var placement = IfcModelBuilder.MakeLocalPlacement(m);
                    ((IfcAxis2Placement3D)placement.RelativePlacement).Location.X = 100;
                    var bb     = solid.BoundingBox;
                    var solidA = _geomEngine.Moved(solid, placement) as IXbimSolid;
                    Assert.IsNotNull(solidA, "Should be the same type as the master");
                    var displacement = solidA.BoundingBox.Centroid() - solid.BoundingBox.Centroid();
                    Assert.IsTrue(displacement == new XbimVector3D(100, 0, 0));

                    var placementRelTo = ((IfcLocalPlacement)placement.PlacementRelTo);
                    var zDir           = m.Instances.New <IfcDirection>(d => d.SetXYZ(0, 0, 1));
                    ((IfcAxis2Placement3D)placementRelTo.RelativePlacement).Axis = zDir;
                    var yDir = m.Instances.New <IfcDirection>(d => d.SetXYZ(0, 1, 0));
                    ((IfcAxis2Placement3D)placementRelTo.RelativePlacement).RefDirection = yDir; //point in Y
                    ((IfcAxis2Placement3D)placementRelTo.RelativePlacement).Location.X   = 2000;
                    var solidB = _geomEngine.Moved(solid, placement) as IXbimSolid;
                    displacement = solidB.BoundingBox.Centroid() - solid.BoundingBox.Centroid();
                    var meshbuilder = new MeshHelper();
                    _geomEngine.Mesh(meshbuilder, solidB, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
                    var box = meshbuilder.BoundingBox;
                    Assert.IsTrue(displacement == new XbimVector3D(1970, 120, 0));
                }
            }
        }
コード例 #4
0
        public void IntersectFacetedSolidFromFacetedSolid()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var ifcBlock1 = IfcModelBuilder.MakeBlock(m, 1000, 2000, 3000);
                    var ifcBlock2 = IfcModelBuilder.MakeBlock(m, 200, 200, 3000);
                    var ifcBlock3 = IfcModelBuilder.MakeBlock(m, 200, 200, 3000);
                    ifcBlock2.Position.Location.X -= 180;
                    ifcBlock2.Position.Location.Y += 200;
                    ifcBlock3.Position.Location.X -= 180;
                    ifcBlock3.Position.Location.Y += 600;
                    var solid1   = XbimGeometryCreator.CreateSolid(ifcBlock1);
                    var solid2   = XbimGeometryCreator.CreateSolid(ifcBlock2);
                    var faceted1 = XbimGeometryCreator.CreateFacetedSolid(XbimGeometryCreator.CreateSolid(ifcBlock3), m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
                    var geom1    = solid1.Union(solid2, m.ModelFactors.Precision);
                    var solidSet = (IXbimSolidSet)geom1;
                    Assert.IsTrue(solidSet.Count == 1, "Cutting these two solids should return a single solid");
                    var faceted2 = XbimGeometryCreator.CreateFacetedSolid(solidSet.First, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
                    var geom2    = faceted2.Intersection(faceted1, m.ModelFactors.Precision);
                    solidSet = (IXbimSolidSet)geom2;
                    Assert.IsTrue(solidSet.Count == 1, "Cutting these two solids should return a single solid");
                    var faceted3 = solidSet.First;

                    var solid6 = XbimGeometryCreator.CreateSolid(faceted3);
                    //var w = new XbimOccWriter();
                    //w.Write(solid6, "d:\\xbim\\s");
                    Assert.IsTrue(Math.Abs(solid6.BoundingBox.SizeX - 20) < m.ModelFactors.Precision * 3, "BoundingBox size X error");
                    Assert.IsTrue(Math.Abs(solid6.BoundingBox.SizeY - 200) < m.ModelFactors.Precision * 3, "BoundingBox size Y error");
                    Assert.IsTrue(Math.Abs(solid6.BoundingBox.SizeZ - 3000) < m.ModelFactors.Precision * 3, "BoundingBox size Z error");
                    Assert.IsTrue(Math.Abs(solid6.Volume - 20 * 3000 * 200) <= m.ModelFactors.Precision, "Error in volume calc");
                }
            }
        }
コード例 #5
0
        public void CutFacetedSolidFromFacetedSolid()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    IfcBlock ifcBlock1 = IfcModelBuilder.MakeBlock(m, 1000, 2000, 3000);
                    IfcBlock ifcBlock2 = IfcModelBuilder.MakeBlock(m, 200, 200, 3000);
                    IfcBlock ifcBlock3 = IfcModelBuilder.MakeBlock(m, 200, 200, 3000);
                    ifcBlock2.Position.Location.X += 200;
                    ifcBlock2.Position.Location.Y += 200;
                    ifcBlock3.Position.Location.X += 200;
                    ifcBlock3.Position.Location.Y += 600;
                    var solid1   = XbimGeometryCreator.CreateSolid(ifcBlock1);
                    var solid2   = XbimGeometryCreator.CreateSolid(ifcBlock2);
                    var faceted1 = XbimGeometryCreator.CreateFacetedSolid(XbimGeometryCreator.CreateSolid(ifcBlock3), m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
                    var geom1    = solid1.Cut(solid2, m.ModelFactors.Precision);
                    var solidSet = (IXbimSolidSet)geom1;
                    Assert.IsTrue(solidSet.Count == 1, "Cutting these two solids should return a single solid");
                    var faceted2 = XbimGeometryCreator.CreateFacetedSolid(solidSet.First, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
                    var geom2    = faceted2.Cut(faceted1, m.ModelFactors.Precision);
                    solidSet = (IXbimSolidSet)geom2;
                    Assert.IsTrue(solidSet.Count == 1, "Cutting these two solids should return a single solid");
                    var faceted3 = solidSet.First;

                    var solid6 = XbimGeometryCreator.CreateSolid(faceted3);

                    Assert.IsTrue(Math.Abs(solid1.BoundingBox.SizeX - solid6.BoundingBox.SizeX) < m.ModelFactors.Precision * 3, "BoundingBox size X error");
                    Assert.IsTrue(Math.Abs(solid1.BoundingBox.SizeY - solid6.BoundingBox.SizeY) < m.ModelFactors.Precision * 3, "BoundingBox size Y error");
                    Assert.IsTrue(Math.Abs(solid1.BoundingBox.SizeZ - solid6.BoundingBox.SizeZ) < m.ModelFactors.Precision * 3, "BoundingBox size Z error");
                    Assert.IsTrue(Math.Abs(solid6.Volume - faceted3.Volume) <= m.ModelFactors.Precision, "Error in volume calc");
                    Assert.IsTrue(Math.Abs(solid6.Volume - faceted3.Volume) <= m.ModelFactors.Precision, "Error in volume calc");
                }
            }
        }
コード例 #6
0
ファイル: IfcCSGTests.cs プロジェクト: jv112602/XbimGeometry
        public void IfcBlockTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var block = IfcModelBuilder.MakeBlock(m, 10, 15, 20);

                    var solid = _xbimGeometryCreator.CreateSolid(block);

                    Assert.IsTrue(solid.Faces.Count == 6, "6 faces are required of a block");
                    Assert.IsTrue(solid.Vertices.Count == 8, "8 vertices are required of a block");
                }
            }
        }
コード例 #7
0
        public void ConvertIfcBlockToBRepTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var block = IfcModelBuilder.MakeBlock(m, 10, 15, 20);

                    var solid = _xbimGeometryCreator.CreateSolid(block);
                    var brep  = _xbimGeometryCreator.CreateFacetedBrep(m, solid);
                    var xrep  = _xbimGeometryCreator.CreateSolidSet(brep);
                    Assert.IsTrue(xrep.Count == 1, "Expected one solid");
                    Assert.IsTrue(solid.Volume - xrep.First.Volume <= m.ModelFactors.Precision, "Volume of round tripped block is not the same");
                    IfcCsgTests.GeneralTest(xrep.First);
                }
            }
        }
コード例 #8
0
 public void CreateXbimFacetedSolidFromIfcBlock()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var ifcBlock = IfcModelBuilder.MakeBlock(m, 1000, 2000, 3000);
             var solid    = XbimGeometryCreator.CreateSolid(ifcBlock);
             var faceted  = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
             Assert.IsTrue(faceted.Faces.First.OuterBound.Edges.Count == 4, "Should have four edges");
             Assert.IsTrue(faceted.Vertices.Count == 8, "there should be 8 points in a block");
             Assert.IsTrue(Math.Abs(faceted.BoundingBox.SizeX - 1000) <= m.ModelFactors.Precision, "Error in X value");
             Assert.IsTrue(Math.Abs(faceted.BoundingBox.SizeY - 2000) <= m.ModelFactors.Precision, "Error in Y value");
             Assert.IsTrue(Math.Abs(faceted.BoundingBox.SizeZ - 3000) <= m.ModelFactors.Precision, "Error in Z value");
             Assert.IsTrue(Math.Abs(solid.Volume - faceted.Volume) <= m.ModelFactors.Precision, "Error in volume calc");
         }
     }
 }
コード例 #9
0
        public void BooleanPerformanceTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var ifcBlock1 = IfcModelBuilder.MakeBlock(m, 1000, 2000, 3000);
                    var ifcBlock2 = IfcModelBuilder.MakeBlock(m, 200, 200, 3000);
                    //var ifcBlock1 = IfcModelBuilder.MakeRightCircularCylinder(m, 2000, 3000);
                    //var ifcBlock2 = IfcModelBuilder.MakeRightCircularCylinder(m, 2000, 3000);
                    //var ifcBlock1 = IfcModelBuilder.MakeExtrudedAreaSolid(m, IfcModelBuilder.MakeRectangleHollowProfileDef(m, 2000, 3000, 500), 4000);
                    //var ifcBlock2 = IfcModelBuilder.MakeExtrudedAreaSolid(m, IfcModelBuilder.MakeRectangleHollowProfileDef(m, 2000, 3000, 500), 4000);

                    ifcBlock2.Position.Location.X -= 180;
                    ifcBlock2.Position.Location.Y += 200;

                    var solid1   = XbimGeometryCreator.CreateSolid(ifcBlock1);
                    var solid2   = XbimGeometryCreator.CreateSolid(ifcBlock2);
                    var faceted1 = XbimGeometryCreator.CreateFacetedSolid(XbimGeometryCreator.CreateSolid(ifcBlock1), m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 1);
                    var faceted2 = XbimGeometryCreator.CreateFacetedSolid(XbimGeometryCreator.CreateSolid(ifcBlock2), m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 1);
                    var solid3   = solid1.Cut(solid2, m.ModelFactors.Precision);
                    solid3 = faceted1.Cut(faceted2, m.ModelFactors.Precision);

                    var sw = new Stopwatch();
                    sw.Start();
                    for (int i = 0; i < 10; i++)
                    {
                        solid3 = solid1.Cut(solid2, m.ModelFactors.Precision);
                    }
                    double time1 = sw.ElapsedMilliseconds;
                    sw.Restart();
                    for (int i = 0; i < 10; i++)
                    {
                        solid3 = faceted1.Cut(faceted2, m.ModelFactors.Precision);
                    }
                    double time2 = sw.ElapsedMilliseconds;
                    Assert.IsTrue(time2 < time1, "Performance error");
                }
            }
        }
コード例 #10
0
        public void SectionFacetedSolidFromBlockTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var block = IfcModelBuilder.MakeBlock(m, 10, 15, 20);


                    var      solid    = XbimGeometryCreator.CreateSolid(block);
                    var      faceted1 = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance);
                    IfcPlane plane    = IfcModelBuilder.MakePlane(m, new XbimPoint3D(block.Position.Location.X + 5, block.Position.Location.Y, block.Position.Location.Z), new XbimVector3D(-1, 0, 0), new XbimVector3D(0, 1, 0));
                    var      cutPlane = XbimGeometryCreator.CreateFace(plane);

                    var section = faceted1.Section(cutPlane, m.ModelFactors.PrecisionBoolean);
                    if (section.First == null)
                    {
                        Assert.IsTrue(section.First != null, "Result should be a single face");
                        Assert.IsTrue(section.First.OuterBound.Edges.Count == 4, "4 edges are required of a section of a block");
                    }
                }
            }
        }
コード例 #11
0
 public void GridPlacementTest()
 {
     //this test checks that a object is correctly copied and moved
     //create a box
     using (
         var m = IfcStore.Create(new XbimEditorCredentials(), IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel)
         )
     {
         using (var txn = m.BeginTransaction())
         {
             var block         = IfcModelBuilder.MakeBlock(m, 10, 10, 10);
             var solid         = _geomEngine.CreateSolid(block);
             var grid          = IfcModelBuilder.MakeGrid(m, 3, 100);
             var gridPlacement = m.Instances.New <IfcGridPlacement>();
             gridPlacement.PlacementLocation = m.Instances.New <IfcVirtualGridIntersection>();
             gridPlacement.PlacementLocation.IntersectingAxes.Add(grid.UAxes.Last());
             gridPlacement.PlacementLocation.IntersectingAxes.Add(grid.VAxes.Last());
             var solidA = _geomEngine.Moved(solid, gridPlacement) as IXbimSolid;
             Assert.IsNotNull(solidA, "Should be the same type as the master");
             var displacement = solidA.BoundingBox.Centroid() - solid.BoundingBox.Centroid();
             Assert.IsTrue(displacement == new XbimVector3D(200, 200, 0));
         }
     }
 }