/// <summary>
        /// Clears the current graphics and initiates the cascade of events that result in viewing the scene.
        /// </summary>
        /// <param name="EntityLabels">If null loads the whole model, otherwise only elements listed in the enumerable</param>
        public void LoadGeometry(XbimModel model, bool recalcView = true)
        {
            // AddLayerToDrawingControl is the function that actually populates the geometry in the viewer.
            // AddLayerToDrawingControl is triggered by BuildRefModelScene and BuildScene below here when layers get ready.

            //reset all the visuals
            ClearGraphics(recalcView);
            short userDefinedId = 0;

            if (model == null)
            {
                return; //nothing to show
            }
            model.UserDefinedId = userDefinedId;
            Xbim3DModelContext context = new Xbim3DModelContext(model);
            XbimRegion         largest = context.GetLargestRegion();
            XbimPoint3D        c       = new XbimPoint3D(0, 0, 0);
            XbimRect3D         bb      = XbimRect3D.Empty;

            if (largest != null)
            {
                bb = new XbimRect3D(largest.Centre, largest.Centre);
            }

            foreach (var refModel in model.ReferencedModels)
            {
                XbimRegion r;
                refModel.Model.UserDefinedId = ++userDefinedId;

                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();

            _modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
            model.ReferencedModels.CollectionChanged += RefencedModels_CollectionChanged;
            //build the geometric scene and render as we go
            BuildScene(context);
            foreach (var refModel in model.ReferencedModels)
            {
                Xbim3DModelContext refContext = new Xbim3DModelContext(refModel.Model);
                BuildScene(refContext);
            }
            if (recalcView)
            {
                RecalculateView(model);
            }
        }
示例#2
0
        /// <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));
        }
示例#3
0
        /// <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);
        }
 public XbimModelPositioning(XbimModel model)
 {
     _model = model;
     Context = new Xbim3DModelContext(model);
     var supportLevel = model.GeometrySupportLevel;
   
     switch (supportLevel)
     {
         case 1:
             LargestRegion = GetLargestRegion(model);
             break;
         case 2:
             LargestRegion = Context.GetLargestRegion();
             break;
     }
 }
示例#5
0
        public XbimModelPositioning(XbimModel model)
        {
            _model  = model;
            Context = new Xbim3DModelContext(model);
            var supportLevel = model.GeometrySupportLevel;

            switch (supportLevel)
            {
            case 1:
                LargestRegion = GetLargestRegion(model);
                break;

            case 2:
                LargestRegion = Context.GetLargestRegion();
                break;
            }
        }
        /// <summary>
        /// Clears the current graphics and initiates the cascade of events that result in viewing the scene.
        /// </summary>
        /// <param name="EntityLabels">If null loads the whole model, otherwise only elements listed in the enumerable</param>
        public void LoadGeometry(XbimModel model, bool recalcView = true)
        {
            // AddLayerToDrawingControl is the function that actually populates the geometry in the viewer.
            // AddLayerToDrawingControl is triggered by BuildRefModelScene and BuildScene below here when layers get ready.

            //reset all the visuals
            ClearGraphics(recalcView);
            short userDefinedId = 0;
            if (model == null)
                return; //nothing to show
            model.UserDefinedId = userDefinedId;
            Xbim3DModelContext context = new Xbim3DModelContext(model);
            XbimRegion largest = context.GetLargestRegion();
            XbimPoint3D c = new XbimPoint3D(0, 0, 0);
            XbimRect3D bb = XbimRect3D.Empty;
            if (largest != null)
                bb = new XbimRect3D(largest.Centre, largest.Centre);

            foreach (var refModel in model.ReferencedModels)
            {

                XbimRegion r;
                refModel.Model.UserDefinedId = ++userDefinedId;

                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();
            _modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
            model.ReferencedModels.CollectionChanged += RefencedModels_CollectionChanged;
            //build the geometric scene and render as we go
            BuildScene(context);
            foreach (var refModel in model.ReferencedModels)
            {
                Xbim3DModelContext refContext = new Xbim3DModelContext(refModel.Model);
                BuildScene(refContext);
            }
            if (recalcView) RecalculateView(model);
        }
示例#7
0
        private void ShowGeometrySummary(XbimModel model)
        {
            var context = new Xbim3DModelContext(model);

            Console.WriteLine();
            Console.WriteLine("Styles");
            foreach (var styles in context.SurfaceStyles())
            {
                Console.WriteLine("{0,-6} {1,-30} {2,-6}",
                                  styles.DefinedObjectId,
                                  styles.ColourMap.First(),
                                  styles.IsTransparent);
            }
            var largest = context.GetLargestRegion();

            Console.WriteLine();
            Console.WriteLine("Regions");
            foreach (var region in context.GetRegions())
            {
                Console.WriteLine("{0,-20} {1,6} {2}",
                                  region.Name,
                                  region.Population,
                                  (region == largest));
            }



            Console.WriteLine("{0,-8}, {1,-8}, {2,6} {3,8}",
                              "Ifc Label",
                              "Label",
                              "Ref Count",
                              "Bytes");

            var geometries = GetGeom(model)
                             .OrderByDescending(o => o.Cost)
                             .Distinct()
                             .Take(10);

            var items = from inst in context.ShapeInstances()
                        join prod in model.Instances.OfType <IfcProduct>()
                        on inst.IfcProductLabel equals prod.EntityLabel
                        select new
            {
                Instance = inst,
                Geometry = context.ShapeGeometry(inst.InstanceLabel),
                Product  = prod
            };

            var expensiveProducts = items
                                    .OrderByDescending(o => (o.Geometry.IsValid ? o.Geometry.Cost : 0))
                                    .Take(20);

            foreach (var geometry in geometries)
            {
                Console.WriteLine("{0, -8}, {1,-8}, {2,6} {3,8}",
                                  geometry.IfcShapeLabel,
                                  geometry.ShapeLabel,
                                  geometry.ReferenceCount,
                                  geometry.Cost);
            }

            Console.WriteLine();
            Console.WriteLine("Top 20 expensive items");
            foreach (var item in expensiveProducts)
            {
                Console.WriteLine("{0,-6} {1,-40} {2,-20} {3,6}",
                                  item.Product.EntityLabel,
                                  item.Product.Name.ToString().Truncate(40),
                                  item.Product.GetType().Name,
                                  item.Geometry.Cost
                                  );
            }
        }