public XbimTriangulatedModel(byte[] triangles, XbimRect3D bounds, int representationLabel, int surfaceStylelabel)
 {
     Triangles = triangles;
     RepresentationLabel = representationLabel;
     SurfaceStyleLabel = surfaceStylelabel;
     Bounds = bounds;
 }
Beispiel #2
0
        static public XbimRect3D Inflate(XbimRect3D original, double x, double y, double z)
        {
            XbimPoint3D  p = new XbimPoint3D(original.X - x, original.Y - y, original.Z - z);
            XbimVector3D v = new XbimVector3D(original.SizeX + (x * 2), original.SizeY + (y * 2), original.SizeZ + (z * 2));

            return(new XbimRect3D(p, v));
        }
Beispiel #3
0
        public bool Intersects(XbimRect3D rect)
        {
            //Martin Cerny: I don't think this is correct as this will find only one specific intersection case but it is not general.
            //I propose variant based on size and envelope bounding box which would be invariant

            //XbimRect3D envelope = XbimRect3D.Empty;
            //envelope.Union(rect);
            //envelope.Union(this);

            //var xSize = rect.SizeX + this.SizeX;
            //var ySize = rect.SizeY + this.SizeY;
            //var zSize = rect.SizeZ + this.SizeZ;

            //return
            //    xSize >= envelope.SizeX &&
            //    ySize >= envelope.SizeY &&
            //    zSize >= envelope.SizeZ
            //    ;

            if (this.IsEmpty || rect.IsEmpty)
            {
                return(false);
            }
            return(((((rect._x <= (this._x + this._sizeX)) && ((rect._x + rect._sizeX) >= this._x)) && ((rect._y <= (this._y + this._sizeY)) && ((rect._y + rect._sizeY) >= this._y))) && (rect._z <= (this._z + this._sizeZ))) && ((rect._z + rect._sizeZ) >= this._z));
        }
Beispiel #4
0
        static public XbimRect3D Inflate(XbimRect3D original, double inflate)
        {
            XbimPoint3D  p = new XbimPoint3D(original.X - inflate, original.Y - inflate, original.Z - inflate);
            XbimVector3D v = new XbimVector3D(original.SizeX + (inflate * 2), original.SizeY + (inflate * 2), original.SizeZ + (inflate * 2));

            return(new XbimRect3D(p, v));
        }
 private static void HaveSameLocation(XbimRect3D r1, XbimRect3D r2)
 {
     const double delta = 0.00001;
     Assert.AreEqual(r1.Location.X, r2.Location.X, delta, "Position X out of error margin.");
     Assert.AreEqual(r1.Location.Y, r2.Location.Y, delta, "Position Y out of error margin.");
     Assert.AreEqual(r1.Location.Z, r2.Location.Z, delta, "Position Z out of error margin.");
 }
Beispiel #6
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);
        }
 private static void HaveSameSize(XbimRect3D r1, XbimRect3D r2)
 {
     const double delta = 0.00001;
     Assert.AreEqual(r1.SizeX, r2.SizeX, delta, "Size X out of error margin.");
     Assert.AreEqual(r1.SizeY, r2.SizeY, delta, "Size Y out of error margin.");
     Assert.AreEqual(r1.SizeZ, r2.SizeZ, delta, "Size Z out of error margin.");
 }
Beispiel #8
0
 public XbimRegion(string name, XbimRect3D bounds, int population)
 {
     this.Name = name;
     this.Size = new XbimVector3D(bounds.SizeX,bounds.SizeY,bounds.SizeZ);
     this.Centre = bounds.Centroid();
     this.Population = population;
 }
Beispiel #9
0
        static public XbimRect3D Inflate(double d)
        {
            XbimRect3D rect = new XbimRect3D();

            rect.X     -= d; rect.Y -= d; rect.Z -= d;
            rect.SizeX += d * 2; rect.SizeY += d * 2; rect.SizeZ += d * 2;
            return(rect);
        }
Beispiel #10
0
        static public XbimRect3D Inflate(double x, double y, double z)
        {
            XbimRect3D rect = new XbimRect3D();

            rect.X     -= x; rect.Y -= y; rect.Z -= z;
            rect.SizeX += x * 2; rect.SizeY += y * 2; rect.SizeZ += z * 2;
            return(rect);
        }
Beispiel #11
0
 public XbimRegion(string name, XbimRect3D bounds, int population, XbimMatrix3D worldCoordinateSystem)
 {
     Name                  = name;
     Size                  = new XbimVector3D(bounds.SizeX, bounds.SizeY, bounds.SizeZ);
     Centre                = bounds.Centroid();
     Population            = population;
     WorldCoordinateSystem = worldCoordinateSystem;
 }
Beispiel #12
0
 public XbimBBoxClusterElement(int geomteryId, XbimRect3D bound)
 {
     GeometryIds = new List <int>(1)
     {
         geomteryId
     };
     Bound = bound;
 }
Beispiel #13
0
 /// <summary>
 /// Looks at the maximum distance (between all axis) between two boxes and compares it with a specified threshold.
 /// </summary>
 /// <param name="r1">Bounding box 1</param>
 /// <param name="r2">Bounding box 2</param>
 /// <param name="eps">the threshold distance</param>
 /// <returns>True if the maximum distance is under the threshold.</returns>
 private static bool ValidDistance(XbimRect3D r1, XbimRect3D r2, double eps)
 {
     //if (r2.SizeZ > 2000000)
     //    Console.WriteLine("v big");
     double dx = AxisDistance(r1.X, r1.SizeX, r2.X, r2.SizeX);
     double dy = AxisDistance(r1.Y, r1.SizeY, r2.Y, r2.SizeY);
     double dz = AxisDistance(r1.Z, r1.SizeZ, r2.Z, r2.SizeZ);
     double max = Math.Max(Math.Max(dx, dy), dz);
     return (max < eps);
 }
Beispiel #14
0
 /// <summary>
 /// Rounds the values of the bounding box to the specified precision and returns a copy
 /// </summary>
 /// <param name="r"></param>
 /// <param name="digits"></param>
 /// <returns></returns>
 public static XbimRect3D Round(XbimRect3D r, int digits)
 {
     return(new XbimRect3D(Math.Round(r.X, digits),
                           Math.Round(r.Y, digits),
                           Math.Round(r.Z, digits),
                           Math.Round(r.SizeX, digits),
                           Math.Round(r.SizeY, digits),
                           Math.Round(r.SizeZ, digits)
                           ));
 }
Beispiel #15
0
 public bool Contains(XbimRect3D rect)
 {
     if (this.IsEmpty)
     {
         return(false);
     }
     return
         (this.Contains(rect.Min)
          &&
          this.Contains(rect.Max));
 }
Beispiel #16
0
 public XbimShapeInstance(int id = -1)
 {
     _instanceLabel         = id;
     _expressTypeId         = 0;
     _ifcProductLabel       = 0;
     _styleLabel            = 0;
     _shapeLabel            = -1;
     _representationContext = 0;
     _representationType    = XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded;
     _transformation        = XbimMatrix3D.Identity;
     _boundingBox           = XbimRect3D.Empty;
 }
Beispiel #17
0
        /// <summary>
        /// true if the rect fits inside thsi rectangle when it is either inflated or defalted by the tolerance
        /// </summary>
        /// <param name="xbimRect3D"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public bool IsSimilar(XbimRect3D rect, double tolerance)
        {
            double t  = Math.Abs(tolerance);
            double t2 = 2 * t;

            return
                (Math.Abs(_x - rect.X) <= t &&
                 Math.Abs(_y - rect.Y) <= t &&
                 Math.Abs(_z - rect.Z) <= t &&
                 Math.Abs(_sizeX - rect.SizeX) <= t2 &&
                 Math.Abs(_sizeY - rect.SizeY) <= t2 &&
                 Math.Abs(_sizeZ - rect.SizeZ) <= t2);
        }
Beispiel #18
0
 public void Union(XbimRect3D bb)
 {
     if (IsEmpty)
     {
         this = bb;
     }
     else if (!bb.IsEmpty)
     {
         double numX = Math.Min(X, bb.X);
         double numY = Math.Min(Y, bb.Y);
         double numZ = Math.Min(Z, bb.Z);
         _sizeX = Math.Max((X + _sizeX), (bb.X + bb._sizeX)) - numX;
         _sizeY = Math.Max((Y + _sizeY), (bb.Y + bb._sizeY)) - numY;
         _sizeZ = Math.Max((Z + _sizeZ), (bb.Z + bb._sizeZ)) - numZ;
         X      = numX;
         Y      = numY;
         Z      = numZ;
     }
 }
Beispiel #19
0
        /// <summary>
        /// Transforms a bounding rect so that it is still axis aligned
        /// </summary>
        /// <param name="rect3d"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static public XbimRect3D TransformBy(XbimRect3D rect3d, XbimMatrix3D m)
        {
            XbimPoint3D  min      = rect3d.Min;
            XbimPoint3D  max      = rect3d.Max;
            XbimVector3D up       = m.Up;
            XbimVector3D right    = m.Right;
            XbimVector3D backward = m.Backward;
            var          xa       = right * min.X;
            var          xb       = right * max.X;

            var ya = up * min.Y;
            var yb = up * max.Y;

            var za = backward * min.Z;
            var zb = backward * max.Z;

            return(new XbimRect3D(
                       XbimVector3D.Min(xa, xb) + XbimVector3D.Min(ya, yb) + XbimVector3D.Min(za, zb) + m.Translation,
                       XbimVector3D.Max(xa, xb) + XbimVector3D.Max(ya, yb) + XbimVector3D.Max(za, zb) + m.Translation
                       ));
        }
Beispiel #20
0
        public void Init()
        {
            XbimGeometryHandleCollection ghc;
            _ModelTransform = new XbimMatrix3D[1];
            _ModelBoxes = new XbimRect3D[1];
            ghc = model.GetGeometryHandles(XbimGeometryType.TriangulatedMesh, XbimGeometrySort.OrderByIfcSurfaceStyleThenIfcType);
            SetupModel(ghc, model, 0);
            SetupCamera(model, 0);
            //check if we have a valid bounding box for the model, and throw if we don't
            if (IsRectEmpty(_ModelBounds))
            {
                throw new Exception("Region Undefined");// RegionUndefinedException();
            }

            //move the bounding box to 0,0
            _ModelBounds = _ModelBounds.Transform(_modelTranslation);

            //Set Global Units
            IfcGlobalUnits = new ConcurrentDictionary<string, string>();
            SetGlobalUnits(model);
        }
Beispiel #21
0
        /// <summary>
        /// Reinitialises the rectangle 3D from the byte array
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="array">6 doubles, definine, min and max values of the boudning box</param>
        public static XbimRect3D FromArray(byte[] array)
        {
            MemoryStream ms   = new MemoryStream(array);
            BinaryReader bw   = new BinaryReader(ms);
            XbimRect3D   rect = new XbimRect3D();

            if (array.Length == 6 * sizeof(float)) //it is in floats
            {
                double srXmin = bw.ReadSingle();
                double srYmin = bw.ReadSingle();
                double srZmin = bw.ReadSingle();
                rect.Location = new XbimPoint3D(srXmin, srYmin, srZmin);

                double srXSz = bw.ReadSingle(); // all ToArray functions store position and size (bugfix: it was previously reading data as max)
                double srYSz = bw.ReadSingle();
                double srZSz = bw.ReadSingle();
                rect.SizeX = srXSz;
                rect.SizeY = srYSz;
                rect.SizeZ = srZSz;
            }
            else //go for doubles
            {
                double srXmin = bw.ReadDouble();
                double srYmin = bw.ReadDouble();
                double srZmin = bw.ReadDouble();
                rect.Location = new XbimPoint3D(srXmin, srYmin, srZmin);

                double srXSz = bw.ReadDouble(); // all ToArray functions store position and size (bugfix: it was previously reading data as max)
                double srYSz = bw.ReadDouble();
                double srZSz = bw.ReadDouble();
                rect.SizeX = srXSz;
                rect.SizeY = srYSz;
                rect.SizeZ = srZSz;
            }


            return(rect);
        }
        public XbimRect3D GetBounds()
        {
            bool first = true;
            XbimRect3D boundingBox = XbimRect3D.Empty;
            foreach (var pos in Positions)
            {
                if (first)
                {
                    boundingBox = new XbimRect3D(pos);
                    first = false;
                }
                else
                    boundingBox.Union(pos);

            }
            return boundingBox;
        }
Beispiel #23
0
        /// <summary>
        /// true if the rect fits inside thsi rectangle when it is either inflated or defalted by the tolerance
        /// </summary>
        /// <param name="xbimRect3D"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public bool IsSimilar(XbimRect3D rect, double tolerance)
        {
            double t = Math.Abs(tolerance);
            double t2 = 2 * t;
            return 
                Math.Abs(_x - rect.X) <= t &&
                Math.Abs(_y - rect.Y) <= t &&
                Math.Abs(_z - rect.Z) <= t &&
                Math.Abs(_sizeX - rect.SizeX) <= t2 &&
                Math.Abs(_sizeY - rect.SizeY) <= t2 &&
                Math.Abs(_sizeZ - rect.SizeZ) <= t2;

        }
Beispiel #24
0
 /// <summary>
 /// Rounds the values of the bounding box to the specified precision and returns a copy
 /// </summary>
 /// <param name="r"></param>
 /// <param name="digits"></param>
 /// <returns></returns>
 public static XbimRect3D Round(XbimRect3D r, int digits)
 {
     return new XbimRect3D(Math.Round(r.X, digits),
         Math.Round(r.Y, digits),
         Math.Round(r.Z, digits),
         Math.Round(r.SizeX, digits),
         Math.Round(r.SizeY, digits),
         Math.Round(r.SizeZ, digits)
         );
 }
Beispiel #25
0
 public bool Contains(XbimRect3D rect)
 {
     if (this.IsEmpty)
         return false;
     return 
         this.Contains(rect.Min) 
         && 
         this.Contains(rect.Max);
 }
        /// <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);
        }
Beispiel #27
0
 static  XbimRect3D()
 {
     _empty = new XbimRect3D { _x = float.PositiveInfinity, _y = float.PositiveInfinity, _z = float.PositiveInfinity, _sizeX = float.NegativeInfinity, _sizeY = float.NegativeInfinity, _sizeZ = float.NegativeInfinity };
 }
Beispiel #28
0
 static public XbimRect3D Inflate( double x, double y, double z)
 {
     XbimRect3D rect = new XbimRect3D();
     rect.X -= x; rect.Y -= y; rect.Z -= z;
     rect.SizeX += x * 2; rect.SizeY += y * 2; rect.SizeZ += z * 2;
     return rect;
 }
Beispiel #29
0
 static public XbimRect3D Inflate(double d)
 {
     XbimRect3D rect = new XbimRect3D();
     rect.X -= d; rect.Y -= d; rect.Z -= d;
     rect.SizeX += d * 2; rect.SizeY += d * 2; rect.SizeZ += d * 2;
     return rect;
 }
Beispiel #30
0
 static  XbimRect3D()
 {
     _empty = new XbimRect3D { _x = double.PositiveInfinity, _y = double.PositiveInfinity, _z = double.PositiveInfinity, _sizeX = double.NegativeInfinity, _sizeY = double.NegativeInfinity, _sizeZ = double.NegativeInfinity };
 }
Beispiel #31
0
        /// <summary>
        /// Reinitialises the rectangle 3D from the byte array
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="array">6 doubles, definine, min and max values of the boudning box</param>
        public static XbimRect3D FromArray(byte[] array)
        {
            MemoryStream ms = new MemoryStream(array);
            BinaryReader bw = new BinaryReader(ms);
            XbimRect3D rect = new XbimRect3D();
            if (array.Length == 6 * sizeof(float)) //it is in floats
            {
                double srXmin = bw.ReadSingle();
                double srYmin = bw.ReadSingle();
                double srZmin = bw.ReadSingle();
                rect.Location = new XbimPoint3D(srXmin, srYmin, srZmin);

                double srXSz = bw.ReadSingle(); // all ToArray functions store position and size (bugfix: it was previously reading data as max)
                double srYSz = bw.ReadSingle();
                double srZSz = bw.ReadSingle();
                rect.SizeX = srXSz;
                rect.SizeY = srYSz;
                rect.SizeZ = srZSz;
            }
            else //go for doubles
            {
                double srXmin = bw.ReadDouble();
                double srYmin = bw.ReadDouble();
                double srZmin = bw.ReadDouble();
                rect.Location = new XbimPoint3D(srXmin, srYmin, srZmin);

                double srXSz = bw.ReadDouble(); // all ToArray functions store position and size (bugfix: it was previously reading data as max)
                double srYSz = bw.ReadDouble();
                double srZSz = bw.ReadDouble();
                rect.SizeX = srXSz;
                rect.SizeY = srYSz;
                rect.SizeZ = srZSz;
            }
           

            return rect;
        }
Beispiel #32
0
        private void txtCommand_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter &&
                (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                )
            {
            #if DEBUG
                // stores the commands being launched
                var fname = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "xbimquerying.txt");
                using (StreamWriter writer = File.CreateText(fname))
                {
                    writer.Write(txtCommand.Text);
                    writer.Flush();
                    writer.Close();
                }
            #endif

                e.Handled = true;
                if (bDoClear)
                    txtOut.Document = new FlowDocument();

                string[] CommandArray = txtCommand.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (txtCommand.SelectedText != string.Empty)
                    CommandArray = txtCommand.SelectedText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var cmd_f in CommandArray)
                {
                    ReportAdd("> " + cmd_f, Brushes.ForestGreen);
                    var cmd = cmd_f;
                    int i = cmd.IndexOf("//");
                    if (i > 0)
                    {
                        cmd = cmd.Substring(0, i);
                    }
                    if (cmd.TrimStart().StartsWith("//"))
                        continue;

                    // put here all commands that don't require a database open
                    var mdbclosed = Regex.Match(cmd, @"help", RegexOptions.IgnoreCase);
                    if (mdbclosed.Success)
                    {
                        DisplayHelp();
                        continue;
                    }

                    mdbclosed = Regex.Match(cmd, @"xplorer", RegexOptions.IgnoreCase);
                    if (mdbclosed.Success)
                    {
                        if (ParentWindow != null)
                            ParentWindow.Focus();
                        else
                        {
                            // todo: bonghi: open the model in xplorer if needed.
                            XplorerMainWindow xp = new XplorerMainWindow();
                            ParentWindow = xp;
                            xp.Show();
                        }
                        continue;
                    }

                    mdbclosed = Regex.Match(cmd, @"clear *\b(?<mode>(on|off))*", RegexOptions.IgnoreCase);
                    if (mdbclosed.Success)
                    {
                        try
                        {
                            string option = mdbclosed.Groups["mode"].Value;

                            if (option == "")
                            {
                                txtOut.Document = new FlowDocument();
                                continue;
                            }
                            else if (option == "on")
                                bDoClear = true;
                            else if (option == "off")
                                bDoClear = false;
                            else
                            {
                                ReportAdd(string.Format("Autoclear not changed ({0} is not a valid option).", option));
                                continue;
                            }
                            ReportAdd(string.Format("Autoclear set to {0}", option.ToLower()));
                            continue;
                        }
                        catch (Exception)
                        {
                        }
                        txtOut.Document = new FlowDocument();
                        continue;
                    }

                    if (Model == null)
                    {
                        ReportAdd("Plaese open a database.", Brushes.Red);
                        continue;
                    }

                    // all commands here
                    //
                    var m = Regex.Match(cmd, @"^(entitylabel|el) (?<el>\d+)(?<recursion> -*\d+)*", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        int recursion = 0;
                        int v = Convert.ToInt32(m.Groups["el"].Value);
                        try
                        {
                            recursion = Convert.ToInt32(m.Groups["recursion"].Value);
                        }
                        catch (Exception)
                        {
                        }

                        ReportAdd(ReportEntity(v, recursion));
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(Header|he)$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        if (Model.Header == null)
                        {
                            ReportAdd("Model header is not defined.", Brushes.Red);
                            continue;
                        }
                        ReportAdd("FileDescription:");
                        foreach (var item in Model.Header.FileDescription.Description)
                        {
                            ReportAdd(string.Format("- Description: {0}", item));
                        }
                        ReportAdd(string.Format("- ImplementationLevel: {0}", Model.Header.FileDescription.ImplementationLevel));
                        ReportAdd(string.Format("- EntityCount: {0}", Model.Header.FileDescription.EntityCount));

                        ReportAdd("FileName:");
                        ReportAdd(string.Format("- Name: {0}", Model.Header.FileName.Name));
                        ReportAdd(string.Format("- TimeStamp: {0}", Model.Header.FileName.TimeStamp));
                        foreach (var item in Model.Header.FileName.Organization)
                        {
                            ReportAdd(string.Format("- Organization: {0}", item));
                        }
                        ReportAdd(string.Format("- OriginatingSystem: {0}", Model.Header.FileName.OriginatingSystem));
                        ReportAdd(string.Format("- PreprocessorVersion: {0}", Model.Header.FileName.PreprocessorVersion));
                        foreach (var item in Model.Header.FileName.AuthorName)
                        {
                            ReportAdd(string.Format("- AuthorName: {0}", item));
                        }

                        ReportAdd(string.Format("- AuthorizationName: {0}", Model.Header.FileName.AuthorizationName));
                        foreach (var item in Model.Header.FileName.AuthorizationMailingAddress)
                        {
                            ReportAdd(string.Format("- AuthorizationMailingAddress: {0}", item));
                        }

                        ReportAdd("FileSchema:");
                        foreach (var item in Model.Header.FileSchema.Schemas)
                        {
                            ReportAdd(string.Format("- Schema: {0}", item));
                        }
                        continue;
                    }

                    // SelectionHighlighting [WholeMesh|Normals]
                    m = Regex.Match(cmd, @"^(SelectionHighlighting|sh) (?<mode>(wholemesh|normals))+", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string mode = m.Groups["mode"].Value.ToLowerInvariant();
                        if (mode == "normals")
                        {
                            ReportAdd("Selection visual style set to 'Normals'");
                            ParentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.Normals;
                        }
                        else
                        {
                            ReportAdd("Selection visual style set to 'WholeMesh'");
                            ParentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.WholeMesh;
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(IfcSchema|is) (?<mode>(list|count|short|full) )*(?<type>.+)", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string type = m.Groups["type"].Value;
                        string mode = m.Groups["mode"].Value;

                        if (type == "/")
                        {
                        }
                        else if (type == PrepareRegex(type)) // there's not a regex expression, we will prepare one assuming the search for a bare name.
                        {
                            type = @".*\." + type + "$"; // any character repeated then a dot then the name and the end of line
                        }
                        else
                            type = PrepareRegex(type);

                        var TypeList = MatchingTypes(type);

                        if (mode.ToLower() == "list ")
                        {
                            foreach (var item in TypeList)
                                ReportAdd(item);
                        }
                        else if (mode.ToLower() == "count ")
                        {
                            ReportAdd("count: " + TypeList.Count());
                        }
                        else
                        {
                            // report
                            int  BeVerbose = 1;
                            if (mode.ToLower() == "short ")
                                BeVerbose = 0;
                            if (mode.ToLower() == "full ")
                                BeVerbose = 2;
                            foreach (var item in TypeList)
                            {
                                ReportAdd(ReportType(item, BeVerbose));
                            }
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(reload|re) *(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string start = m.Groups["entities"].Value;
                        IEnumerable<int> labels = tointarray(start, ',');
                        if (labels.Count() > 0)
                        {
                            ParentWindow.DrawingControl.LoadGeometry(Model, labels);
                        }
                        else
                        {
                            ParentWindow.DrawingControl.LoadGeometry(Model);
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(GeometryInfo|gi) (?<mode>(binary|viewer) )*(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string start = m.Groups["entities"].Value;
                        string mode = m.Groups["mode"].Value;
                        IEnumerable<int> labels = tointarray(start, ',');
                        foreach (var item in labels)
                        {
                            ReportAdd("Geometry for: " + item.ToString(), Brushes.Green);
                            ReportAdd(GeomQuerying.GeomInfoBoundBox(Model, item));
                            ReportAdd(GeomQuerying.GeomLayers(Model, item, ParentWindow.DrawingControl.scenes));
                            if (mode == "binary ")
                            {
                                ReportAdd(GeomQuerying.GeomInfoMesh(Model, item));
                            }
                            if (mode == "viewer ")
                            {
                                ReportAdd(
                                    GeomQuerying.Viewerdata(ParentWindow.DrawingControl, Model, item)
                                    );
                            }
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^(select|se) (?<mode>(count|list|short) )*(?<tt>(transverse|tt) )*(?<hi>(highlight|hi) )*(?<start>([\d,-]+|[^ ]+)) *(?<props>.*)", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string start = m.Groups["start"].Value;
                        string props = m.Groups["props"].Value;
                        string mode = m.Groups["mode"].Value;

                        // transverse tree mode
                        bool transverseT = false;
                        string transverse = m.Groups["tt"].Value;
                        if (transverse != "")
                            transverseT = true;

                        bool Highlight = false;
                        string HighlightT = m.Groups["hi"].Value;
                        if (HighlightT != "")
                            Highlight = true;

                        IEnumerable<int> labels = tointarray(start, ',');
                        IEnumerable<int> ret = null;
                        if (labels.Count() == 0)
                        {
                            // see if it's a type string instead
                            SquareBracketIndexer sbi = new SquareBracketIndexer(start);
                            labels = QueryEngine.EntititesForType(sbi.Property, Model);
                            labels = sbi.getItem(labels);
                        }
                        ret = QueryEngine.RecursiveQuery(Model, props, labels, transverseT);

                        // textual report
                        if (mode.ToLower() == "count ")
                        {
                            ReportAdd(string.Format("Count: {0}", ret.Count()));
                        }
                        else if (mode.ToLower() == "list ")
                        {
                            foreach (var item in ret)
                            {
                                ReportAdd(item.ToString());
                            }
                        }
                        else
                        {
                            bool BeVerbose = true;
                            if (mode.ToLower() == "short ")
                                BeVerbose = false;
                            foreach (var item in ret)
                            {
                                ReportAdd(ReportEntity(item, 0, Verbose: BeVerbose));
                            }
                        }
                        // visual selection
                        if (Highlight)
                        {
                            EntitySelection s = new EntitySelection();
                            foreach (var item in ret)
                            {
                                s.Add(Model.Instances[item]);
                            }
                            ParentWindow.DrawingControl.Selection = s;
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^zoom (" +
                        @"(?<RegionName>.+$)" +
                        ")", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string RName = m.Groups["RegionName"].Value;
                        var regionData = Model.GetGeometryData(Xbim.XbimExtensions.XbimGeometryType.Region).FirstOrDefault();
                        if (regionData == null)
                        {
                            ReportAdd("data not found");
                        }
                        XbimRegionCollection regions = XbimRegionCollection.FromArray(regionData.ShapeData);
                        var reg = regions.Where(x => x.Name == RName).FirstOrDefault();
                        if (reg != null)
                        {
                            XbimMatrix3D mcp = XbimMatrix3D.Copy(ParentWindow.DrawingControl.wcsTransform);
                            var bb = reg.Centre;
                            var tC = mcp.Transform(reg.Centre);
                            var tS = mcp.Transform(reg.Size);
                            XbimRect3D r3d = new XbimRect3D(
                                tC.X - tS.X / 2, tC.Y - tS.Y / 2, tC.Z - tS.Z / 2,
                                tS.X, tS.X, tS.Z
                                );
                            ParentWindow.DrawingControl.ZoomTo(r3d);
                            ParentWindow.Activate();
                            continue;
                        }
                        else
                        {
                            ReportAdd(string.Format("Something wrong with region name: '{0}'", RName));
                            ReportAdd("Names that should work are: ");
                            foreach (var str in regions)
                            {
                                ReportAdd(string.Format(" - '{0}'", str.Name));
                            }
                            continue;
                        }
                    }

                    m = Regex.Match(cmd, @"^clip off$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        ParentWindow.DrawingControl.ClearCutPlane();
                        ReportAdd("Clip removed");
                        ParentWindow.Activate();
                        continue;
                    }

                    m = Regex.Match(cmd, @"^clip (" +
                        @"(?<elev>[-+]?([0-9]*\.)?[0-9]+) *$" +
                        "|" +
                        @"(?<px>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<py>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<pz>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<nx>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<ny>[-+]?([0-9]*\.)?[0-9]+) *, *" +
                        @"(?<nz>[-+]?([0-9]*\.)?[0-9]+)" +
                        "|" +
                        @"(?<StoreyName>.+$)" +
                        ")", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        double px = 0, py = 0, pz = 0;
                        double nx = 0, ny = 0, nz = -1;

                        if (m.Groups["elev"].Value != string.Empty)
                        {
                            pz = Convert.ToDouble(m.Groups["elev"].Value);
                        }
                        else if (m.Groups["StoreyName"].Value != string.Empty)
                        {
                            string msg = "";
                            string storName = m.Groups["StoreyName"].Value;
                            var storey = Model.Instances.OfType<Xbim.Ifc2x3.ProductExtension.IfcBuildingStorey>().Where(x => x.Name == storName).FirstOrDefault();
                            if (storey != null)
                            {
                                //get the object position data (should only be one)
                                Xbim.XbimExtensions.XbimGeometryData geomdata = Model.GetGeometryData(storey.EntityLabel, Xbim.XbimExtensions.XbimGeometryType.TransformOnly).FirstOrDefault();
                                if (geomdata != null)
                                {
                                    Xbim.Common.Geometry.XbimPoint3D pt = new Xbim.Common.Geometry.XbimPoint3D(0, 0, geomdata.Transform.OffsetZ);
                                    Xbim.Common.Geometry.XbimMatrix3D mcp = Xbim.Common.Geometry.XbimMatrix3D.Copy(ParentWindow.DrawingControl.wcsTransform);
                                    var transformed = mcp.Transform(pt);
                                    msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1);
                                    pz = transformed.Z + 1;
                                }
                            }
                            if (msg == "")
                            {
                                ReportAdd(string.Format("Something wrong with storey name: '{0}'", storName));
                                ReportAdd("Names that should work are: ");
                                var strs = Model.Instances.OfType<Xbim.Ifc2x3.ProductExtension.IfcBuildingStorey>();
                                foreach (var str in strs)
                                {
                                    ReportAdd(string.Format(" - '{0}'", str.Name));
                                }
                                continue;
                            }
                            ReportAdd(msg);
                        }
                        else
                        {
                            px = Convert.ToDouble(m.Groups["px"].Value);
                            py = Convert.ToDouble(m.Groups["py"].Value);
                            pz = Convert.ToDouble(m.Groups["pz"].Value);
                            nx = Convert.ToDouble(m.Groups["nx"].Value);
                            ny = Convert.ToDouble(m.Groups["ny"].Value);
                            nz = Convert.ToDouble(m.Groups["nz"].Value);
                        }

                        ParentWindow.DrawingControl.ClearCutPlane();
                        ParentWindow.DrawingControl.SetCutPlane(
                            px, py, pz,
                            nx, ny, nz
                            );

                        ReportAdd("Clip command sent");
                        ParentWindow.Activate();
                        continue;
                    }

                    m = Regex.Match(cmd, @"^Styler (?<command>.+)", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        var st = ParentWindow.DrawingControl.LayerStyler as Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyleExtended;
                        if (st != null)
                        {
                            string command = m.Groups["command"].Value;
                            ReportAdd(
                                st.SendCommand(command, ParentWindow.DrawingControl.Selection)
                                );
                            ParentWindow.DrawingControl.ReloadModel();
                        }
                        else
                        {
                            ReportAdd("Command not valid under current styler configuration.");
                        }
                        continue;
                    }

                    m = Regex.Match(cmd, @"^Visual (?<action>list|tree|on|off|mode)( (?<Name>[^ ]+))*", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string Name = m.Groups["Name"].Value;
                        if (m.Groups["action"].Value.ToLowerInvariant() == "list")
                        {
                            foreach (var item in ParentWindow.DrawingControl.ListItems(Name))
                            {
                                ReportAdd(item);
                            }
                        }
                        else if (m.Groups["action"].Value.ToLowerInvariant() == "tree")
                        {
                            foreach (var item in ParentWindow.DrawingControl.LayersTree())
                            {
                                ReportAdd(item);
                            }
                        }
                        else if (m.Groups["action"].Value.ToLowerInvariant() == "mode")
                        {
                            string t = Name.ToLowerInvariant();
                            if (t == "type")
                            {
                                ReportAdd("Visual mode set to EntityType.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyle();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else if (t == "entity")
                            {
                                ReportAdd("Visual mode set to EntityLabel.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerPerEntity();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else if (t == "oddeven")
                            {
                                ReportAdd("Visual mode set to Odd/Even.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerEvenOdd();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else if (t == "demo")
                            {
                                ReportAdd("Visual mode set to Demo.");
                                ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyleExtended();
                                ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll);
                            }
                            else
                                ReportAdd(string.Format("mode not understood: {0}.", t));
                        }
                        else
                        {
                            bool bVis = false;
                            if (m.Groups["action"].Value.ToLowerInvariant() == "on")
                                bVis = true;
                            ParentWindow.DrawingControl.SetVisibility(Name, bVis);
                        }
                        continue;
                        }
                    m = Regex.Match(cmd, @"^SimplifyGUI$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        XbimXplorer.Simplify.IfcSimplify s = new Simplify.IfcSimplify();
                        s.Show();
                        continue;
                    }

                    m = Regex.Match(cmd, @"^test$", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        int iPass = -728;
                        ReportAdd(RunTestCode(iPass));
                        continue;
                    }
                    ReportAdd(string.Format("Command not understood: {0}.", cmd));
                }
            }
        }
Beispiel #33
0
 static public XbimRect3D Inflate( double x, double y, double z)
 {
     XbimRect3D rect = new XbimRect3D();
     rect.X -= (float)x; rect.Y -= (float)y; rect.Z -= (float)z;
     rect.SizeX += (float)x * 2; rect.SizeY += (float)y * 2; rect.SizeZ += (float)z * 2;
     return rect;
 }
Beispiel #34
0
 static public XbimRect3D Inflate(float x, float y, float z)
 {
     XbimRect3D rect = new XbimRect3D();
     rect.X -= x; rect.Y -= y; rect.Z -= z;
     rect.SizeX += x * 2; rect.SizeY += y * 2; rect.SizeZ += z * 2;
     return rect;
 }
        public static XbimMeshGeometry3D MakeBoundingBox(XbimRect3D r3D, XbimMatrix3D transform)
        {
            XbimMeshGeometry3D mesh = new XbimMeshGeometry3D(8);
            XbimPoint3D p0 = transform.Transform(r3D.Location);
            XbimPoint3D p1 = p0;
            p1.X += r3D.SizeX;
            XbimPoint3D p2 = p1;
            p2.Z += r3D.SizeZ;
            XbimPoint3D p3 = p2;
            p3.X -= r3D.SizeX;
            XbimPoint3D p4 = p3;
            p4.Y += r3D.SizeY;
            XbimPoint3D p5 = p4;
            p5.Z -= r3D.SizeZ;
            XbimPoint3D p6 = p5;
            p6.X += r3D.SizeX;
            XbimPoint3D p7 = p6;
            p7.Z += r3D.SizeZ;

            mesh.Positions.Add(p0);
            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.Positions.Add(p3);
            mesh.Positions.Add(p4);
            mesh.Positions.Add(p5);
            mesh.Positions.Add(p6);
            mesh.Positions.Add(p7);

            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(2);

            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);

            mesh.TriangleIndices.Add(4);
            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(3);

            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(3);

            mesh.TriangleIndices.Add(7);
            mesh.TriangleIndices.Add(6);
            mesh.TriangleIndices.Add(4);

            mesh.TriangleIndices.Add(6);
            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(4);

            mesh.TriangleIndices.Add(2);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(7);

            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(6);
            mesh.TriangleIndices.Add(7);

            mesh.TriangleIndices.Add(4);
            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(7);

            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(2);
            mesh.TriangleIndices.Add(7);

            mesh.TriangleIndices.Add(6);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(5);

            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(5);

            return mesh;
        }
 public XbimRect3D GetEnvelopOfCentes()
 {
     var bb = XbimRect3D.Empty;
     foreach (var r in _collection.Values.Select(positioning => positioning.LargestRegion).Where(r => r != null))
     {
         if (bb.IsEmpty)
             bb = new XbimRect3D(r.Centre, r.Centre);
         else
             bb.Union(r.Centre);
     }
     return bb;
 }
Beispiel #37
0
 static XbimRect3D()
 {
     _empty = new XbimRect3D {
         _x = double.PositiveInfinity, _y = double.PositiveInfinity, _z = double.PositiveInfinity, _sizeX = double.NegativeInfinity, _sizeY = double.NegativeInfinity, _sizeZ = double.NegativeInfinity
     };
 }
        /// <summary>
        /// This version uses the new Geometry representation
        /// </summary>
        /// <param name="model"></param>
        /// <param name="context"></param>
        /// <param name="exclude">List of type to exclude, by default excplict openings and spaces are excluded if exclude = null</param>
        /// <returns></returns>
        private void BuildScene(Xbim3DModelContext context)
        {
           
            //get a list of all the unique styles
            Dictionary<int, WpfMaterial> styles = new Dictionary<int, WpfMaterial>();
            Dictionary<int, MeshGeometry3D> shapeGeometries = new Dictionary<int, MeshGeometry3D>();
            Dictionary<int, WpfMeshGeometry3D> meshSets = new Dictionary<int, WpfMeshGeometry3D>();
            Model3DGroup opaques = new Model3DGroup();
            Model3DGroup transparents = new Model3DGroup();

            foreach (var shapeGeom in context.ShapeGeometries())
            {
                MeshGeometry3D wpfMesh = new MeshGeometry3D();
                wpfMesh.SetValue(TagProperty, shapeGeom); //don't read the geometry into the mesh yet as we do not know where the instance is located
                shapeGeometries.Add(shapeGeom.ShapeLabel, wpfMesh);
            }


            foreach (var style in context.SurfaceStyles())
            {
                WpfMaterial wpfMaterial = new WpfMaterial();
                wpfMaterial.CreateMaterial(style);
                styles.Add(style.DefinedObjectId, wpfMaterial);
                WpfMeshGeometry3D mg = new WpfMeshGeometry3D(wpfMaterial, wpfMaterial);
                meshSets.Add(style.DefinedObjectId, mg);
                if (style.IsTransparent)
                    transparents.Children.Add(mg);
                else
                    opaques.Children.Add(mg);

            }

            ////if (!styles.Any()) return ; //this should always have something unless the model is empty
            ////double metre = model.ModelFactors.OneMetre;
            ////XbimMatrix3D wcsTransform = XbimMatrix3D.CreateTranslation(_modelTranslation) * XbimMatrix3D.CreateScale((float)(1 / metre));

            ////foreach (var shapeInstance in context.ShapeInstances()
            ////        .Where(s => s.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsIncluded &&
            ////            !typeof(IfcFeatureElement).IsAssignableFrom(IfcMetaData.GetType(s.IfcTypeId)) &&
            ////            !typeof(IfcSpace).IsAssignableFrom(IfcMetaData.GetType(s.IfcTypeId))))
            ////{
            ////    int styleId = shapeInstance.StyleLabel > 0 ? shapeInstance.StyleLabel : shapeInstance.IfcTypeId * -1;

            ////    //GET THE ACTUAL GEOMETRY 
            ////    MeshGeometry3D wpfMesh;
            ////    //see if we have already read it
            ////    if (shapeGeometries.TryGetValue(shapeInstance.ShapeGeometryLabel, out wpfMesh))
            ////    {
            ////        GeometryModel3D mg = new GeometryModel3D(wpfMesh, styles[styleId]);
            ////        mg.SetValue(TagProperty, new XbimInstanceHandle(model, shapeInstance.IfcProductLabel, shapeInstance.IfcTypeId));
            ////        mg.BackMaterial = mg.Material;
            ////        mg.Transform = XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform).ToMatrixTransform3D();
            ////        if (styles[styleId].IsTransparent)
            ////            transparents.Children.Add(mg);
            ////        else
            ////            opaques.Children.Add(mg);
            ////    }
            ////    else //we need to get the shape geometry
            ////    {
            ////        XbimShapeGeometry shapeGeom = context.ShapeGeometry(shapeInstance.ShapeGeometryLabel);
            ////        if (shapeGeom.ReferenceCount > 1) //only store if we are going to use again
            ////        {
            ////            wpfMesh = new MeshGeometry3D();
            ////            wpfMesh.Read(shapeGeom.ShapeData);
            ////            shapeGeometries.Add(shapeInstance.ShapeGeometryLabel, wpfMesh);
            ////            GeometryModel3D mg = new GeometryModel3D(wpfMesh, styles[styleId]);
            ////            mg.SetValue(TagProperty, new XbimInstanceHandle(model, shapeInstance.IfcProductLabel, shapeInstance.IfcTypeId));
            ////            mg.BackMaterial = mg.Material;
            ////            mg.Transform = XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform).ToMatrixTransform3D();
            ////            if (styles[styleId].IsTransparent)
            ////                transparents.Children.Add(mg);
            ////            else
            ////                opaques.Children.Add(mg);
            ////        }
            ////        else //it is a one off, merge it with shapes of a similar material
            ////        {
            ////            WpfMeshGeometry3D mg = meshSets[styleId];
            ////            mg.Add(shapeGeom.ShapeData,
            ////                shapeInstance.IfcTypeId,
            ////                shapeInstance.IfcProductLabel,
            ////                shapeInstance.InstanceLabel,
            ////                XbimMatrix3D.Multiply(shapeInstance.Transformation, wcsTransform), 0);
            ////        }
            ////    }

            ////}

            if (opaques.Children.Any())
            {
                ModelVisual3D mv = new ModelVisual3D();
                mv.Content = opaques;
                Opaques.Children.Add(mv);
                if (_modelBounds.IsEmpty) _modelBounds = mv.Content.Bounds.ToXbimRect3D();
                else _modelBounds.Union(mv.Content.Bounds.ToXbimRect3D());
            }
            if (transparents.Children.Any())
            {
                ModelVisual3D mv = new ModelVisual3D();
                mv.Content = transparents;
                Transparents.Children.Add(mv);
                if (_modelBounds.IsEmpty) _modelBounds = mv.Content.Bounds.ToXbimRect3D();
                else _modelBounds.Union(mv.Content.Bounds.ToXbimRect3D());
            }

        }
Beispiel #39
0
        /// <summary>
        /// Reinitialises the rectangle 3D from the byte array
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="array">6 doubles, definine, min and max values of the boudning box</param>
        public static XbimRect3D FromArray(byte[] array)
        {
            MemoryStream ms = new MemoryStream(array);
            BinaryReader bw = new BinaryReader(ms);
            XbimRect3D rect = new XbimRect3D();
            float srXmin = (float)bw.ReadDouble(); //legacy when using windows rect3d and doubles
            float srYmin = (float)bw.ReadDouble();
            float srZmin = (float)bw.ReadDouble();
            rect.Location = new XbimPoint3D(srXmin, srYmin, srZmin);

            float srXSz = (float)bw.ReadDouble(); // all ToArray functions store position and size (bugfix: it was previously reading data as max)
            float srYSz = (float)bw.ReadDouble();
            float srZSz = (float)bw.ReadDouble();
            rect.SizeX = srXSz;
            rect.SizeY = srYSz;
            rect.SizeZ = srZSz;

            return rect;
        }
Beispiel #40
0
 public bool Intersects(XbimRect3D rect)
 {
     if (this.IsEmpty || rect.IsEmpty)
     {
         return false;
     }
     return (((((rect._x <= (this._x + this._sizeX)) && ((rect._x + rect._sizeX) >= this._x)) && ((rect._y <= (this._y + this._sizeY)) && ((rect._y + rect._sizeY) >= this._y))) && (rect._z <= (this._z + this._sizeZ))) && ((rect._z + rect._sizeZ) >= this._z));
 }
Beispiel #41
0
        /// <summary>
        /// Transforms a bounding rect so that it is still axis aligned
        /// </summary>
        /// <param name="rect3d"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static public XbimRect3D TransformBy(XbimRect3D rect3d, XbimMatrix3D m)
        {
            XbimPoint3D min = rect3d.Min;
            XbimPoint3D max = rect3d.Max;
            XbimVector3D up = m.Up;
            XbimVector3D right = m.Right;
            XbimVector3D backward = m.Backward;
            var xa = right * min.X;
            var xb = right * max.X;

            var ya = up * min.Y;
            var yb = up * max.Y;

            var za = backward * min.Z;
            var zb = backward * max.Z;

            return new XbimRect3D(
                XbimVector3D.Min(xa, xb) + XbimVector3D.Min(ya, yb) + XbimVector3D.Min(za, zb) + m.Translation,
                XbimVector3D.Max(xa, xb) + XbimVector3D.Max(ya, yb) + XbimVector3D.Max(za, zb) + m.Translation
            );
            
        }
        private void ClearGraphics(bool recalcView = true)
        {
           
            _selection = new EntitySelection();
         //   UserModeledDimension.Clear();

            Opaques.Children.Clear();
            Transparents.Children.Clear();
            Extras.Children.Clear();
           // this.ClearCutPlane();
            Highlighted.Mesh = null;

            if (recalcView)
            {
                _modelBounds = XbimRect3D.Empty;
                _viewBounds = new XbimRect3D(0, 0, 0, 10, 10, 5);
                Viewport.ResetCamera();
            }

        }
 public XbimBBoxClusterElement(int geomteryId, XbimRect3D bound)
 {
     GeometryIds = new List <int>(1);
     this.GeometryIds.Add(geomteryId);
     this.Bound = bound;
 }
Beispiel #44
0
 public void Union(XbimRect3D bb)
 {
     if (IsEmpty)
     {
         this = bb;
     }
     else if (!bb.IsEmpty)
     {
         double numX = Math.Min(X, bb.X);
         double numY = Math.Min(Y, bb.Y);
         double numZ = Math.Min(Z, bb.Z);
         _sizeX = Math.Max((X + _sizeX), (bb.X + bb._sizeX)) - numX;
         _sizeY = Math.Max((Y + _sizeY), (bb.Y + bb._sizeY)) - numY;
         _sizeZ = Math.Max((Z + _sizeZ), (bb.Z + bb._sizeZ)) - numZ;
         X = numX;
         Y = numY;
         Z = numZ;
     }
 }
Beispiel #45
0
        public bool Intersects(XbimRect3D rect)
        {
            //Martin Cerny: I don't think this is correct as this will find only one specific intersection case but it is not general.
            //I propose variant based on size and envelope bounding box which would be invariant

            //XbimRect3D envelope = XbimRect3D.Empty;
            //envelope.Union(rect);
            //envelope.Union(this);

            //var xSize = rect.SizeX + this.SizeX;
            //var ySize = rect.SizeY + this.SizeY;
            //var zSize = rect.SizeZ + this.SizeZ;

            //return
            //    xSize >= envelope.SizeX &&
            //    ySize >= envelope.SizeY &&
            //    zSize >= envelope.SizeZ
            //    ;

            if (this.IsEmpty || rect.IsEmpty)
            {
                return false;
            }
            return (((((rect._x <= (this._x + this._sizeX)) && ((rect._x + rect._sizeX) >= this._x)) && ((rect._y <= (this._y + this._sizeY)) && ((rect._y + rect._sizeY) >= this._y))) && (rect._z <= (this._z + this._sizeZ))) && ((rect._z + rect._sizeZ) >= this._z));
        }
Beispiel #46
0
 public bool Contains(XbimRect3D rect)
 {
     if (this.IsEmpty)
         return false;
     return 
         this.ContainsCoords(rect.X, rect.Y, rect.Z) 
         && 
         this.ContainsCoords(rect.X + rect.SizeX, rect.Y + rect.SizeY, rect.Z+rect.SizeZ);
 }