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"); } } }
protected override void GenerateInstance(IfcBuilding building) { DatabaseIfc db = building.Database; IfcBlock block = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(db, 0, 0, 0)), 2000, 800, 800); IfcRoundedRectangleProfileDef roundedRectangle = new IfcRoundedRectangleProfileDef(db, "VoidProfile", 1800, 600, 200); IfcExtrudedAreaSolid extrudedAreaSolid = new IfcExtrudedAreaSolid(roundedRectangle, new IfcAxis2Placement3D(new IfcCartesianPoint(db, 1000, 400, 100)), new IfcDirection(db, 0, 0, 1), 700); IfcBooleanResult booleanResult = new IfcBooleanResult(IfcBooleanOperator.DIFFERENCE, block, extrudedAreaSolid); IfcCsgSolid csgSolid = new IfcCsgSolid(booleanResult); IfcRepresentationMap representationMap = new IfcRepresentationMap(csgSolid); IfcMaterial ceramic = new IfcMaterial(db, "Ceramic"); IfcSanitaryTerminalType sanitaryTerminalType = new IfcSanitaryTerminalType(db, "Bath", IfcSanitaryTerminalTypeEnum.BATH) { MaterialSelect = ceramic }; sanitaryTerminalType.RepresentationMaps.Add(representationMap); IfcElement element = sanitaryTerminalType.GenerateMappedItemElement(building, new IfcCartesianTransformationOperator3D(db)); db.Context.AddDeclared(sanitaryTerminalType); //Unique ids assigned to generate constant IfcScript sample files, remove otherwise sanitaryTerminalType.GlobalId = "1HarmwaPv3OeJSXpaoPKpg"; ceramic.Associates.GlobalId = "0Pkhszwjv1qRMYyCFg9fjB"; sanitaryTerminalType.ObjectTypeOf.GlobalId = "1lO$X3e3j9lfVMhNy4MzKB"; element.GlobalId = "3$$o7C03j0KQeLnoj018fc"; }
public void RotationTest() { // ==== Rotate IfcSweptAreaSolid var operandStack = new Stack(); IfcPolyline outerCurve = IfcGeom.CreatePolyLine(new List <double[]>() { new double[] { -1, -1 }, new double[] { -1, 1 }, new double[] { 1, 1 }, new double[] { 1, -1 }, new double[] { -1, -1 } }); IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA, null, outerCurve); operandStack.Push(profileDef.Extrude(1)); operandStack.Push("[-90,0,90]"); ConstructionOperations.ExecuteOperation(OperationName.ROTATION, operandStack); Assert.Single(operandStack); var response = operandStack.Pop(); Assert.IsAssignableFrom <IfcSweptAreaSolid>(response); Assert.Equal(0, ((IfcSweptAreaSolid)response).Position.RefDirection.DirectionRatios[0].Value, 10); Assert.Equal(0, ((IfcSweptAreaSolid)response).Position.RefDirection.DirectionRatios[1].Value, 10); Assert.Equal(-1, ((IfcSweptAreaSolid)response).Position.RefDirection.DirectionRatios[2].Value, 10); // ==== Rotate IfcBooleanResult operandStack.Clear(); IfcCsgPrimitive3D union_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0, 0, 0), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcCsgPrimitive3D union_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0.5, 0.5, 0.5), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); operandStack.Push(union_first.Union(union_second)); operandStack.Push("[-90,0,90]"); ConstructionOperations.ExecuteOperation(OperationName.ROTATION, operandStack); Assert.Single(operandStack); response = operandStack.Pop(); Assert.IsAssignableFrom <IfcBooleanResult>(response); Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).FirstOperand).Position.RefDirection.DirectionRatios[0].Value, 10); Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).FirstOperand).Position.RefDirection.DirectionRatios[1].Value, 10); Assert.Equal(-1, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).FirstOperand).Position.RefDirection.DirectionRatios[2].Value, 10); Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).SecondOperand).Position.RefDirection.DirectionRatios[0].Value, 10); Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).SecondOperand).Position.RefDirection.DirectionRatios[1].Value, 10); Assert.Equal(-1, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).SecondOperand).Position.RefDirection.DirectionRatios[2].Value, 10); }
protected override void GenerateData(STPModelData md, IfcBuilding building) { IfcBlock block = new IfcBlock(md,Plane.WorldXY, 2000,800,800); IfcRoundedRectangleProfileDef roundedRectangle = new IfcRoundedRectangleProfileDef(md, "VoidProfile", 600,1800,200); IfcExtrudedAreaSolid extrudedAreaSolid = new IfcExtrudedAreaSolid(roundedRectangle,new IfcAxis2Placement3D(md,new Plane(new Point3d( 1000,400,100),Vector3d.XAxis,Vector3d.YAxis)),new IfcDirection(md,0,0,1),700); IfcBooleanResult booleanResult = new IfcBooleanResult(IfcBooleanOperator.DIFFERENCE, block, extrudedAreaSolid); IfcCsgSolid csgSolid = new IfcCsgSolid(booleanResult); IfcRepresentationMap representationMap = new IfcRepresentationMap(csgSolid); IfcMaterial ceramic = new IfcMaterial(md, "Ceramic", "", ""); ceramic.Associates.GlobalId = "0Pkhszwjv1qRMYyCFg9fjB"; IfcSanitaryTerminalType sanitaryTerminalType = new IfcSanitaryTerminalType(md, "Bath", IfcSanitaryTerminalTypeEnum.BATH) { GlobalId = "1HarmwaPv3OeJSXpaoPKpg", MaterialSelect = ceramic, RepresentationMaps = new List<IfcRepresentationMap>() {representationMap } }; sanitaryTerminalType.ObjectTypeOf.GlobalId = "1lO$X3e3j9lfVMhNy4MzKB"; IfcElement element = sanitaryTerminalType.GenerateMappedItemElement(building, Plane.WorldXY); element.GlobalId = "3$$o7C03j0KQeLnoj018fc"; }
protected override void GenerateData(STPModelData md, IfcBuilding building) { IfcBlock block = new IfcBlock(md, Plane.WorldXY, 2000, 800, 800); IfcRoundedRectangleProfileDef roundedRectangle = new IfcRoundedRectangleProfileDef(md, IfcProfileTypeEnum.AREA, "VoidProfile", null, 600, 1800, 200); IfcExtrudedAreaSolid extrudedAreaSolid = new IfcExtrudedAreaSolid(roundedRectangle, new IfcAxis2Placement3D(md, new Plane(new Point3d(1000, 400, 100), Vector3d.XAxis, Vector3d.YAxis)), new IfcDirection(md, 0, 0, 1), 700); IfcBooleanResult booleanResult = new IfcBooleanResult(IfcBooleanOperator.DIFFERENCE, block, extrudedAreaSolid); IfcCsgSolid csgSolid = new IfcCsgSolid(booleanResult); IfcRepresentationMap representationMap = new IfcRepresentationMap(csgSolid); IfcMaterial ceramic = new IfcMaterial(md, "Ceramic", "", ""); ceramic.Associates.GlobalId = "0Pkhszwjv1qRMYyCFg9fjB"; IfcSanitaryTerminalType sanitaryTerminalType = new IfcSanitaryTerminalType(md, new IfcElemTypeParams("1HarmwaPv3OeJSXpaoPKpg", "Bath", "", "", ""), ceramic, representationMap, null, IfcSanitaryTerminalTypeEnum.BATH); sanitaryTerminalType.ObjectTypeOf.GlobalId = "1lO$X3e3j9lfVMhNy4MzKB"; sanitaryTerminalType.GenerateMappedItemElement(building, Plane.WorldXY, new IfcElemParams("3$$o7C03j0KQeLnoj018fc", "", "", "", "")); }
public void IntersectionTest() { var operandStack = new Stack(); IfcCsgPrimitive3D first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0, 0, 0), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcCsgPrimitive3D second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0.5, 0.5, 0.5), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); operandStack.Push(first); operandStack.Push(second); ConstructionOperations.ExecuteOperation(OperationName.INTERSECTION, operandStack); Assert.Single(operandStack); var response = operandStack.Pop(); Assert.IsType <IfcBooleanResult>(response); Assert.Equal(IfcBooleanOperator.INTERSECTION, ((IfcBooleanResult)response).Operator); Assert.Equal(0, ((IfcBlock)((IfcBooleanResult)response).FirstOperand).Position.Location.Coordinates[0].Value); Assert.Equal(0.5, ((IfcBlock)((IfcBooleanResult)response).SecondOperand).Position.Location.Coordinates[0].Value); }
public void BooleanOperatorTest() { //Set up project hierarchy IfcProject project = IfcInit.CreateProject(null, null, null); IfcSite site = IfcInit.CreateSite(null, null, null); project.Aggregate(site, null); IfcBuilding building = IfcInit.CreateBuilding(null, null, null, null); site.Aggregate(building, null); IfcBuildingStorey storey = IfcInit.CreateBuildingStorey(null, null, null, null); building.Aggregate(storey, null); //Create shape representation IfcCsgPrimitive3D union_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0, 0, 0), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcCsgPrimitive3D union_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0.5, 0.5, 0.5), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcRepresentationItem unionRepresentation = union_first.Union(union_second); IfcCsgPrimitive3D diff_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(2, 0, 0), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcCsgPrimitive3D diff_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(2.5, 0.5, 0.5), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcRepresentationItem diffRepresentation = diff_first.Difference(diff_second); IfcCsgPrimitive3D inter_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(4, 0, 0), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcCsgPrimitive3D inter_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(4.5, 0.5, 0.5), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcRepresentationItem interRepresentation = inter_first.Intersection(inter_second); IfcPolyline outerCurve = IfcGeom.CreatePolyLine(new List <double[]>() { new double[] { 6, 0 }, new double[] { 6, 1 }, new double[] { 7, 1 }, new double[] { 7, 0 }, new double[] { 6, 0 } }); IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA, null, outerCurve); IfcSweptAreaSolid cut_reference = profileDef.Extrude(1); IfcPlane plane = IfcGeom.CreatePlane(new double[] { 6.5, 0.5, 0 }, new double[] { 1, 1, 0 }); IfcRepresentationItem cutRepresentation = cut_reference.ClipByPlane(plane); //Create product with representation and place in storey var contextEnum = project.RepresentationContexts.GetEnumerator(); contextEnum.MoveNext(); IfcShapeRepresentation shapeRepresentation = new IfcShapeRepresentation(contextEnum.Current, new IfcLabel("union shape"), new IfcLabel("BooleanResult"), new IfcRepresentationItem[] { unionRepresentation, diffRepresentation, interRepresentation, cutRepresentation }); IfcProxy product = IfcInit.CreateProxy(null, null, null, storey.ObjectPlacement, null); product.Representation = new IfcProductDefinitionShape(null, null, new IfcRepresentation[] { shapeRepresentation }); storey.Contains(product, null); //Write to IFC file using (FileStream fs = File.Create("./constructive_geom_test.ifc")) { project.SerializeToStep(fs, "IFC2X3", null); } }
public IXbimSolid CreateSolid(IfcBlock ifcSolid) { return(_engine.CreateSolid(ifcSolid)); }