public void TransformSolidRectangularProfileDef() { using (var m = new MemoryModel(new Xbim.Ifc4.EntityFactoryIfc4())) { using (var txn = m.BeginTransaction("Test")) { var profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1); var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40); var solid = _geomEngine.CreateSolid(extrude); var transform = new XbimMatrix3D(); //test first with identity var solid2 = (IXbimSolid)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 = (IXbimSolid)solid.Transform(transform); Assert.IsTrue(Math.Abs(solid.Volume - solid2.Volume) < 0.001, "Volume differs"); transform.Invert(); solid2 = (IXbimSolid)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"); } txn.Commit(); } } }
public void IfcHalfspace_Test() { using (var m = new MemoryModel(new Ifc4.EntityFactoryIfc4())) { using (var txn = m.BeginTransaction("")) { var halfSpace = m.Instances.New <IfcHalfSpaceSolid>(); halfSpace.AgreementFlag = false; var baseSurface = m.Instances.New <IfcPlane>(); baseSurface.Position = m.Instances.New <IfcAxis2Placement3D>(); baseSurface.Position.Location = m.Instances.New <IfcCartesianPoint>(); baseSurface.Position.Location.X = 0; baseSurface.Position.Location.Y = 0; baseSurface.Position.Location.Z = 10; halfSpace.BaseSurface = baseSurface; //make an extrusion var profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1); var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40); var solid = geomEngine.CreateSolid(extrude, logger); var halfSpaceSolid = geomEngine.CreateSolid(halfSpace, logger); var cut = solid.Cut(halfSpaceSolid, 1e-5); Assert.IsTrue(cut.Count > 0); Assert.IsTrue(Math.Abs((solid.Volume * .25) - cut.First.Volume) < 1e-5); //move the halfspace plane up baseSurface.Position.Location.Z = 30; halfSpaceSolid = geomEngine.CreateSolid(halfSpace, logger); cut = solid.Cut(halfSpaceSolid, 1e-5); Assert.IsTrue(Math.Abs((solid.Volume * .75) - cut.First.Volume) < 1e-5); //reverse halfspace agreement halfSpace.AgreementFlag = true; halfSpaceSolid = geomEngine.CreateSolid(halfSpace, logger); cut = solid.Cut(halfSpaceSolid, 1e-5); Assert.IsTrue(Math.Abs((solid.Volume * .25) - cut.First.Volume) < 1e-5); } } }
public void IfcPolygonalBoundedHalfspace_Test() { using (var m = new MemoryModel(new Ifc4.EntityFactoryIfc4())) { using (var txn = m.BeginTransaction("")) { var polygonalBoundedHalfspace = m.Instances.New <IfcPolygonalBoundedHalfSpace>(); polygonalBoundedHalfspace.AgreementFlag = false; var plane = m.Instances.New <IfcPlane>(); plane.Position = m.Instances.New <IfcAxis2Placement3D>(); plane.Position.Location = m.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0)); polygonalBoundedHalfspace.BaseSurface = plane; //create the polygonal bound var polyLine = m.Instances.New <IfcPolyline>(); polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(0, 2.5))); polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(5, 2.5))); polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(5, -2.5))); polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(0, -2.5))); polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(0, 2.5))); polygonalBoundedHalfspace.PolygonalBoundary = polyLine; var basePos = m.Instances.New <IfcAxis2Placement3D>(); basePos.Location = m.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0)); polygonalBoundedHalfspace.Position = basePos; //make an extrusion var profile = IfcModelBuilder.MakeRectangleProfileDef(m, 20, 10); var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40); var solid = geomEngine.CreateSolid(extrude, logger); var halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger); var cut = solid.Cut(halfSpaceSolid, 1e-5); Assert.IsTrue(cut.Count > 0); Assert.IsTrue(Math.Abs((solid.Volume) - cut.First.Volume - 1000) < 1e-5); //reverse halfspace agreement polygonalBoundedHalfspace.AgreementFlag = true; halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger); cut = solid.Cut(halfSpaceSolid, 1e-5); Assert.IsTrue(Math.Abs(solid.Volume - cut.First.Volume) < 1e-5); //move the plane up plane.Position.Location.Z = 20; halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger); cut = solid.Cut(halfSpaceSolid, 1e-5); Assert.IsTrue(Math.Abs(solid.Volume - cut.First.Volume - 500) < 1e-5); //some realistic data polyLine.Points[0].SetXY(0, 0); polyLine.Points[1].SetXY(0, 2850); polyLine.Points[2].SetXY(-350, 2850); polyLine.Points[3].SetXY(-350, 0); polyLine.Points[4].SetXY(0, 0); plane.Position.Location.SetXYZ(-5240.7742616303667, -33052.9790707385, 0.0); plane.Position.Axis = m.Instances.New <IfcDirection>(d => d.SetXYZ(0, -1, 0)); plane.Position.RefDirection = m.Instances.New <IfcDirection>(d => d.SetXYZ(1, 0, 0)); basePos.Location.SetXYZ(-5240.7742616303667, -33052.9790707385, 0); basePos.Axis = plane.Position.Axis; basePos.RefDirection = plane.Position.RefDirection; halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger); profile.XDim = 350; profile.YDim = 125; profile.Position.Location.SetXY(-5415.7742616303676, -32932.529070738507); extrude.Depth = 2850; solid = geomEngine.CreateSolid(extrude, logger); cut = solid.Cut(halfSpaceSolid, 1e-5); //everything should be cut Assert.IsTrue(cut.Count == 0); } } }