/// <summary> /// calculates the tansform to convert models to metres and centre on the most populated region, includes reference models /// </summary> /// <returns></returns> private XbimMatrix3D GetGlobalModelTransform() { XbimRegion largest = _context.GetLargestRegion(); XbimRect3D bb = XbimRect3D.Empty; if (largest != null) { bb = new XbimRect3D(largest.Centre, largest.Centre); } foreach (var refModel in _context.Model.ReferencedModels) { XbimRegion r; Xbim3DModelContext refContext = new Xbim3DModelContext(refModel.Model); r = refContext.GetLargestRegion(); if (r != null) { if (bb.IsEmpty) { bb = new XbimRect3D(r.Centre, r.Centre); } else { bb.Union(r.Centre); } } } XbimPoint3D p = bb.Centroid(); var modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z); double metreFactor = 1.0 / _context.Model.ModelFactors.OneMetre; return(XbimMatrix3D.CreateTranslation(modelTranslation) * XbimMatrix3D.CreateScale(metreFactor)); }
internal void SetCenterInMeters(XbimVector3D modelTranslation) { var translation = XbimMatrix3D.CreateTranslation(modelTranslation * OneMeter); var scaling = XbimMatrix3D.CreateScale(1 / OneMeter); Transfrom = translation * scaling; }
/// <summary> /// Creates the transform based on the model dimensional unit (oneMeter) /// </summary> /// <param name="modelTranslation">The translation is expressed in meters.</param> internal void PrepareTransform(XbimVector3D modelTranslation) { var translation = XbimMatrix3D.CreateTranslation(modelTranslation * OneMeter); var scaling = XbimMatrix3D.CreateScale(1 / OneMeter); Transform = translation * scaling; }
private void worker_DoWork_IFC4(IfcStore xModel, List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> elementIdsList) { // Loop through Entities and visualze them in the viewport var res = new HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>(elementIdsList); List <ModelUIElement3D> elementList = new List <ModelUIElement3D>(); foreach (var item in xModel.Instances.OfType <Xbim.Ifc4.Kernel.IfcProduct>()) { if (res.Contains(item.GlobalId)) { XbimModelPositioningCollection ModelPositions = new XbimModelPositioningCollection(); short userDefinedId = 0; xModel.UserDefinedId = userDefinedId; ModelPositions.AddModel(xModel.ReferencingModel); if (xModel.IsFederation) { foreach (var refModel in xModel.ReferencedModels) { refModel.Model.UserDefinedId = ++userDefinedId; var v = refModel.Model as IfcStore; if (v != null) { ModelPositions.AddModel(v.ReferencingModel); } } } var ModelBounds = ModelPositions.GetEnvelopeInMeters(); var p = ModelBounds.Centroid(); var _modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z); var oneMeter = xModel.ModelFactors.OneMetre; var translation = XbimMatrix3D.CreateTranslation(_modelTranslation * oneMeter); var scaling = XbimMatrix3D.CreateScale(1 / oneMeter); XbimMatrix3D Transform = translation * scaling; var m = new MeshGeometry3D(); GetGeometryFromXbimModel_IFC4(m, item, Transform); var mat = GetStyleFromXbimModel_IFC4(item); var mb = new MeshBuilder(false, false); var element = VisualizeMesh_IFC4(mb, m, mat, item); elementList.Add(element); } // Show whole building with opacity 0.03 else { XbimModelPositioningCollection ModelPositions = new XbimModelPositioningCollection(); short userDefinedId = 0; xModel.UserDefinedId = userDefinedId; ModelPositions.AddModel(xModel.ReferencingModel); if (xModel.IsFederation) { foreach (var refModel in xModel.ReferencedModels) { refModel.Model.UserDefinedId = ++userDefinedId; var v = refModel.Model as IfcStore; if (v != null) { ModelPositions.AddModel(v.ReferencingModel); } } } var ModelBounds = ModelPositions.GetEnvelopeInMeters(); var p = ModelBounds.Centroid(); var _modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z); var oneMeter = xModel.ModelFactors.OneMetre; var translation = XbimMatrix3D.CreateTranslation(_modelTranslation * oneMeter); var scaling = XbimMatrix3D.CreateScale(1 / oneMeter); XbimMatrix3D Transform = translation * scaling; var m = new MeshGeometry3D(); GetGeometryFromXbimModel_IFC4(m, item, Transform); var mat = GetStyleFromXbimModel_IFC4(item, 0.03); var mb = new MeshBuilder(false, false); var element = VisualizeMesh_IFC4(mb, m, mat, item); elementList.Add(element); } } foreach (var element in elementList) { if (element != null) { _viewPort.Children.Add(element); } } }
/// <summary> /// Fill sheet rows for Coordinate sheet /// </summary> public override COBieSheet <COBieCoordinateRow> Fill() { //get the conversion to the COBie units (metres or feet) double conversionFactor; var cobieUnits = Context.WorkBookUnits.LengthUnit.ToLowerInvariant(); if (cobieUnits == "meters" || cobieUnits == "metres") { conversionFactor = Model.ModelFactors.OneMetre; } else if (cobieUnits == "millimeters" || cobieUnits == "millimetres") { conversionFactor = Model.ModelFactors.OneMilliMetre; } else if (cobieUnits == "feet" || cobieUnits == "foot") { conversionFactor = Model.ModelFactors.OneFoot; } else if (cobieUnits == "inch" || cobieUnits == "inches") { conversionFactor = Model.ModelFactors.OneInch; } else { throw new Exception( string.Format("The COBie units are incorrectly set, the provided value {0} is invalid.", cobieUnits)); } XbimMatrix3D globalTransform = XbimMatrix3D.CreateScale(1 / conversionFactor); var coordinates = new COBieSheet <COBieCoordinateRow>(Constants.WORKSHEET_COORDINATE); ProgressIndicator.ReportMessage("Starting Coordinates..."); //Create new sheet //Get buildings and spaces var ifcBuildingStoreys = Model.FederatedInstances.OfType <IfcBuildingStorey>(); var ifcSpaces = Model.FederatedInstances.OfType <IfcSpace>() .OrderBy(ifcSpace => ifcSpace.Name, new CompareIfcLabel()); var ifcProducts = ifcBuildingStoreys.Union <IfcProduct>(ifcSpaces); //add spaces //get component products as shown in Component sheet var relAggregates = Model.FederatedInstances.OfType <IfcRelAggregates>(); var relSpatial = Model.FederatedInstances.OfType <IfcRelContainedInSpatialStructure>(); var ifcElements = ((from x in relAggregates from y in x.RelatedObjects where !Context.Exclude.ObjectType.Component.Contains(y.GetType()) select y).Union(from x in relSpatial from y in x.RelatedElements where !Context.Exclude.ObjectType.Component.Contains(y.GetType()) select y)).OfType <IfcProduct>(); //.GroupBy(el => el.Name).Select(g => g.First()) ifcProducts = ifcProducts.Union(ifcElements); var productList = ifcProducts as IList <IfcProduct> ?? ifcProducts.ToList(); ProgressIndicator.Initialise("Creating Coordinates", productList.Count()); var m3D = new Xbim3DModelContext(Model); foreach (var ifcProduct in productList) { ProgressIndicator.IncrementAndUpdate(); //if no name to link the row name too skip it, as no way to link back to the parent object //if (string.IsNullOrEmpty(ifcProduct.Name)) // continue; var coordinate = new COBieCoordinateRow(coordinates) { Name = (string.IsNullOrEmpty(ifcProduct.Name.ToString())) ? DEFAULT_STRING : ifcProduct.Name.ToString(), CreatedBy = GetTelecomEmailAddress(ifcProduct.OwnerHistory), CreatedOn = GetCreatedOnDateAsFmtString(ifcProduct.OwnerHistory) }; // (ifcBuildingStorey == null || ifcBuildingStorey.Name.ToString() == "") ? "CoordinateName" : ifcBuildingStorey.Name.ToString(); coordinate.RowName = coordinate.Name; XbimPoint3D?ifcCartesianPointLower = null; XbimPoint3D?ifcCartesianPointUpper = null; var transBox = new TransformedBoundingBox(); if (ifcProduct is IfcBuildingStorey) { XbimMatrix3D worldMatrix = ifcProduct.ObjectPlacement.ToMatrix3D(); ifcCartesianPointLower = new XbimPoint3D(worldMatrix.OffsetX, worldMatrix.OffsetY, worldMatrix.OffsetZ); //get the offset from the world coordinates system 0,0,0 point, i.e. origin point of this object in world space coordinate.SheetName = "Floor"; coordinate.Category = "point"; ifcCartesianPointUpper = null; } else { if (ifcProduct is IfcSpace) { coordinate.SheetName = "Space"; } else { coordinate.SheetName = "Component"; } coordinate.Category = "box-lowerleft"; //and box-upperright, so two values required when we do this var boundBox = XbimRect3D.Empty; XbimMatrix3D transform = XbimMatrix3D.Identity; foreach (var shapeInstance in m3D.ShapeInstancesOf(ifcProduct)) { if (boundBox.IsEmpty) { boundBox = shapeInstance.BoundingBox; } else { boundBox.Union(shapeInstance.BoundingBox); } transform = shapeInstance.Transformation; } if (!boundBox.IsEmpty) { XbimMatrix3D m = globalTransform * transform; transBox = new TransformedBoundingBox(boundBox, m); //set points ifcCartesianPointLower = transBox.MinPt; ifcCartesianPointUpper = transBox.MaxPt; } } if (ifcCartesianPointLower.HasValue) { coordinate.CoordinateXAxis = string.Format("{0}", (double)ifcCartesianPointLower.Value.X); coordinate.CoordinateYAxis = string.Format("{0}", (double)ifcCartesianPointLower.Value.Y); coordinate.CoordinateZAxis = string.Format("{0}", (double)ifcCartesianPointLower.Value.Z); coordinate.ExtSystem = GetExternalSystem(ifcProduct); coordinate.ExtObject = ifcProduct.GetType().Name; if (!string.IsNullOrEmpty(ifcProduct.GlobalId)) { coordinate.ExtIdentifier = ifcProduct.GlobalId.ToString(); } coordinate.ClockwiseRotation = transBox.ClockwiseRotation.ToString("F4"); coordinate.ElevationalRotation = transBox.ElevationalRotation.ToString("F4"); coordinate.YawRotation = transBox.YawRotation.ToString("F4"); coordinates.AddRow(coordinate); } if (ifcCartesianPointUpper.HasValue) //we need a second row for upper point { var coordinateUpper = new COBieCoordinateRow(coordinates); coordinateUpper.Name = coordinate.Name; coordinateUpper.CreatedBy = coordinate.CreatedBy; coordinateUpper.CreatedOn = coordinate.CreatedOn; coordinateUpper.RowName = coordinate.RowName; coordinateUpper.SheetName = coordinate.SheetName; coordinateUpper.Category = "box-upperright"; coordinateUpper.CoordinateXAxis = string.Format("{0}", (double)ifcCartesianPointUpper.Value.X); coordinateUpper.CoordinateYAxis = string.Format("{0}", (double)ifcCartesianPointUpper.Value.Y); coordinateUpper.CoordinateZAxis = string.Format("{0}", (double)ifcCartesianPointUpper.Value.Z); coordinateUpper.ExtSystem = coordinate.ExtSystem; coordinateUpper.ExtObject = coordinate.ExtObject; coordinateUpper.ExtIdentifier = coordinate.ExtIdentifier; coordinateUpper.ClockwiseRotation = coordinate.ClockwiseRotation; coordinateUpper.ElevationalRotation = coordinate.ElevationalRotation; coordinateUpper.YawRotation = coordinate.YawRotation; coordinates.AddRow(coordinateUpper); } } coordinates.OrderBy(s => s.Name); ProgressIndicator.Finalise(); return(coordinates); }