Пример #1
0
 /// <summary>
 /// Produce the average red, green and blue values for a region in a Bitmap.
 /// </summary>
 /// <param name="image">The Bitmap to analyse.</param>
 /// <param name="region">The region within the Bitmap to consider.</param>
 /// <returns>An array containing three elements  (0=red, 1=green, 2=blue).</returns>
 private static double[] AveragePixelColour(Bitmap image, RectangularRegion region) =>
 new double[]
 {
     MapRegions(region, (x, y) => image.GetPixel(x, y).R),
     MapRegions(region, (x, y) => image.GetPixel(x, y).G),
     MapRegions(region, (x, y) => image.GetPixel(x, y).B)
 };
        public void Outset(int x, int y, int x2, int y2, int delta, int expectedX, int expectedY, int expectedX2,
                           int expectedY2)
        {
            var region = new RectangularRegion(new Vector(x, y), new Vector(x2, y2));

            var region2 = (RectangularRegion)region.Outset(delta);

            Assert.That(region2.Position1, Is.EqualTo(new Vector(expectedX, expectedY)));
            Assert.That(region2.Position2, Is.EqualTo(new Vector(expectedX2, expectedY2)));
        }
Пример #3
0
        /// <summary>
        /// Obtém uma flor na qual as folhas se encontram no interior do rectângulo central.
        /// </summary>
        /// <returns>O tuplo que contém o par centro / folhas da flor.</returns>
        private Tuple <RectangularRegion <int>, List <RectangularRegion <int> > > GetInnerLeafsFlower()
        {
            var center = new RectangularRegion <int>(1, 1, 6, 6);
            var leafs  = new List <RectangularRegion <int> >();

            for (int i = 1; i < 6; i += 2)
            {
                for (int j = 1; j < 6; j += 2)
                {
                    leafs.Add(new RectangularRegion <int>(i, j, i + 1, j + 1));
                }
            }

            return(Tuple.Create(center, leafs));
        }
Пример #4
0
        public void NonIntersectiongRegionSet_TryAddCrossBorderIntersectingRegionTest()
        {
            var target             = new NonIntersectingMergingRegionsSet <int, RectangularRegion <int> >();
            var rectangularRegions = this.GetNonIntersectionFlower();

            target.Add(rectangularRegions.Item1);
            for (int i = 0; i < rectangularRegions.Item2.Count; ++i)
            {
                target.Add(rectangularRegions.Item2[i]);
            }

            // Tenta adicionar uma região que se intersecte com as anteriores
            var addingRegion = new RectangularRegion <int>(2, 2, 3, 3);

            target.Add(addingRegion);
        }
Пример #5
0
        /// <summary>
        /// Permite obter uma configuração de rectângulos que intersectam um rectângulo central
        /// e cuja intersecção possui área não vazia.
        /// </summary>
        /// <returns>O tuplo que contém o par centro / folhas da flor.</returns>
        private Tuple <RectangularRegion <int>, List <RectangularRegion <int> > > GetIntersectionFlower()
        {
            var leafs  = new List <RectangularRegion <int> >();
            var center = new RectangularRegion <int>(2, 2, 8, 8);

            for (int i = 1; i < 9; i += 3)
            {
                leafs.Add(new RectangularRegion <int>(i, 1, i + 2, 3));
                leafs.Add(new RectangularRegion <int>(i, 7, i + 2, 9));
            }

            leafs.Add(new RectangularRegion <int>(1, 4, 3, 6));
            leafs.Add(new RectangularRegion <int>(7, 4, 9, 6));

            return(Tuple.Create(center, leafs));
        }
Пример #6
0
        /// <summary>
        /// Permite obter uma configuração de rectângulos que tocam um rectângulo central
        /// mas cuja intersecção resulta numa área nula.
        /// </summary>
        /// <returns>O tuplo que contém o par centro / folhas da flor.</returns>
        private Tuple <RectangularRegion <int>, List <RectangularRegion <int> > > GetBorderIntersectionFlower()
        {
            var leafs  = new List <RectangularRegion <int> >();
            var center = new RectangularRegion <int>(2, 2, 5, 5);

            for (int i = 1; i < 6; i += 2)
            {
                leafs.Add(new RectangularRegion <int>(i, 1, i + 1, 2));
                leafs.Add(new RectangularRegion <int>(i, 5, i + 1, 6));
            }

            leafs.Add(new RectangularRegion <int>(1, 3, 2, 4));
            leafs.Add(new RectangularRegion <int>(5, 3, 6, 4));

            return(Tuple.Create(center, leafs));
        }
Пример #7
0
        public void RectangularRegion_OverlapTest()
        {
            // Testes com rectângulos arbitrários
            var rect1 = new RectangularRegion <int>(1, 1, 5, 5);
            var rect2 = new RectangularRegion <int>(2, 2, 4, 4);
            var rect3 = new RectangularRegion <int>(3, 3, 5, 5);
            var rect4 = new RectangularRegion <int>(6, 1, 7, 2);
            var rect5 = new RectangularRegion <int>(8, 2, 10, 4);
            var rect6 = new RectangularRegion <int>(8, 1, 11, 2);

            Assert.IsTrue(rect1.OverLaps(rect1));
            Assert.IsTrue(rect1.OverLaps(rect2));
            Assert.IsTrue(rect2.OverLaps(rect1));
            Assert.IsTrue(rect1.OverLaps(rect3));
            Assert.IsTrue(rect3.OverLaps(rect1));
            Assert.IsTrue(rect2.OverLaps(rect3));
            Assert.IsTrue(rect3.OverLaps(rect2));
            Assert.IsFalse(rect1.OverLaps(rect4));
            Assert.IsTrue(rect5.OverLaps(rect6));
            Assert.IsTrue(rect6.OverLaps(rect5));

            // Flor que não intersecta
            var flower = this.GetNonIntersectionFlower();

            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                Assert.IsFalse(flower.Item1.OverLaps(flower.Item2[i]));
            }

            // Flor que toca
            flower = this.GetBorderIntersectionFlower();
            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                Assert.IsTrue(flower.Item1.OverLaps(flower.Item2[i]));
            }

            // Flor que intersecta
            flower = this.GetIntersectionFlower();
            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                Assert.IsTrue(flower.Item1.OverLaps(flower.Item2[i]));
            }
        }
Пример #8
0
        /// <summary>
        /// Permite obter uma configuração de rectângulos que não se intersectam
        /// nem tocam em forma de flor.
        /// </summary>
        /// <returns>O tuplo que contém o par centro / folhas da flor.</returns>
        private Tuple <RectangularRegion <int>, List <RectangularRegion <int> > > GetNonIntersectionFlower()
        {
            // As folhas
            var leafs = new List <RectangularRegion <int> >();

            // O centro
            var center = new RectangularRegion <int>(3, 3, 8, 8);

            // As linhas inferior e superior
            for (int i = 1; i < 10; i += 2)
            {
                leafs.Add(new RectangularRegion <int>(i, 1, i + 1, 2));
                leafs.Add(new RectangularRegion <int>(i, 9, i + 1, 10));
            }

            // As colunas esquerda e direita
            for (int i = 3; i < 8; i += 2)
            {
                leafs.Add(new RectangularRegion <int>(1, i, 2, i + 1));
                leafs.Add(new RectangularRegion <int>(9, i, 10, i + 1));
            }

            return(Tuple.Create(center, leafs));
        }
Пример #9
0
        public void RectangularRegion_MergeTest()
        {
            var centerRect = new RectangularRegion <int>(6, 6, 8, 8);
            var actual     = centerRect.Merge(centerRect, i => ++ i, j => ++ j);

            Assert.AreEqual(centerRect, actual);

            // Os rectângulos encontram-se espaçados
            var rectangularRegionList = new List <RectangularRegion <int> >();

            rectangularRegionList.Add(new RectangularRegion <int>(6, 1, 8, 3));
            rectangularRegionList.Add(new RectangularRegion <int>(1, 6, 3, 8));
            rectangularRegionList.Add(new RectangularRegion <int>(6, 10, 8, 12));
            rectangularRegionList.Add(new RectangularRegion <int>(10, 6, 12, 8));
            for (int i = 0; i < rectangularRegionList.Count; ++i)
            {
                var currentRectangularRegion = rectangularRegionList[i];
                var error = false;
                try
                {
                    centerRect.Merge(
                        currentRectangularRegion,
                        j => { return(++j); },
                        j => { return(--j); });
                }
                catch (UtilitiesDataException)
                {
                    error = true;
                }

                Assert.IsTrue(error);
            }

            // Os rectângulos são todos vizinhos do rectângulo central
            var topRect    = new RectangularRegion <int>(6, 3, 8, 5);
            var leftRect   = new RectangularRegion <int>(3, 6, 5, 8);
            var bottomRect = new RectangularRegion <int>(6, 9, 8, 11);
            var rightRect  = new RectangularRegion <int>(9, 6, 11, 8);

            var topExpected    = new RectangularRegion <int>(6, 3, 8, 8);
            var leftExpected   = new RectangularRegion <int>(3, 6, 8, 8);
            var bottomExpected = new RectangularRegion <int>(6, 6, 8, 11);
            var rightExpected  = new RectangularRegion <int>(6, 6, 11, 8);

            Assert.AreEqual(topExpected, centerRect.Merge(topRect, i => ++ i, i => -- i));
            Assert.AreEqual(leftExpected, centerRect.Merge(leftRect, i => ++ i, i => -- i));
            Assert.AreEqual(bottomExpected, centerRect.Merge(bottomRect, i => ++ i, i => -- i));
            Assert.AreEqual(rightExpected, centerRect.Merge(rightRect, i => ++ i, i => -- i));

            // Os rectângulos intersectam o rectângulo central
            topRect    = new RectangularRegion <int>(6, 3, 8, 7);
            leftRect   = new RectangularRegion <int>(3, 6, 7, 8);
            bottomRect = new RectangularRegion <int>(6, 7, 8, 11);
            rightRect  = new RectangularRegion <int>(7, 6, 11, 8);

            topExpected    = new RectangularRegion <int>(6, 3, 8, 8);
            leftExpected   = new RectangularRegion <int>(3, 6, 8, 8);
            bottomExpected = new RectangularRegion <int>(6, 6, 8, 11);
            rightExpected  = new RectangularRegion <int>(6, 6, 11, 8);

            Assert.AreEqual(topExpected, centerRect.Merge(topRect, i => ++ i, i => -- i));
            Assert.AreEqual(leftExpected, centerRect.Merge(leftRect, i => ++ i, i => -- i));
            Assert.AreEqual(bottomExpected, centerRect.Merge(bottomRect, i => ++ i, i => -- i));
            Assert.AreEqual(rightExpected, centerRect.Merge(rightRect, i => ++ i, i => -- i));
        }
Пример #10
0
        public void RectangularRegion_SubtractTest()
        {
            var rect     = new RectangularRegion <int>(1, 1, 5, 5);
            var expected = new List <RectangularRegion <int> >();
            var actual   = rect.Subtract(
                rect,
                j => { return(++j); },
                j => { return(--j); });

            CollectionAssert.AreEquivalent(expected, actual);

            // Flor constituída por rectângulos que não se intersectam
            var flower = this.GetNonIntersectionFlower();

            expected = new List <RectangularRegion <int> >();
            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                expected.Clear();
                expected.Add(flower.Item1);
                actual = flower.Item1.Subtract(
                    flower.Item2[i],
                    j => { return(++j); },
                    j => { return(--j); });
                CollectionAssert.AreEquivalent(expected, actual);
            }

            // Flor constituída por rectângulos que se intersectam na fronteira
            flower = this.GetBorderIntersectionFlower();
            var expectedList = new List <List <RectangularRegion <int> > >();

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 3, 5, 5),
                new RectangularRegion <int>(3, 2, 5, 2)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 5, 4),
                new RectangularRegion <int>(3, 5, 5, 5)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 2, 5),
                new RectangularRegion <int>(3, 3, 5, 5),
                new RectangularRegion <int>(5, 2, 5, 2)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 5, 4),
                new RectangularRegion <int>(2, 5, 2, 5),
                new RectangularRegion <int>(5, 5, 5, 5)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 4, 5),
                new RectangularRegion <int>(5, 3, 5, 5)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 5, 4),
                new RectangularRegion <int>(2, 5, 4, 5)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 5, 2),
                new RectangularRegion <int>(2, 5, 5, 5),
                new RectangularRegion <int>(3, 3, 5, 4)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 5, 2),
                new RectangularRegion <int>(2, 3, 4, 5),
                new RectangularRegion <int>(5, 5, 5, 5)
            });

            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                expected = expectedList[i];
                actual   = flower.Item1.Subtract(flower.Item2[i],
                                                 j => { return(++j); },
                                                 j => { return(--j); });
                CollectionAssert.AreEqual(expected, actual);
            }

            expectedList.Clear();
            flower = this.GetIntersectionFlower();
            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 4, 8, 8),
                new RectangularRegion <int>(4, 2, 8, 3)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 8, 6),
                new RectangularRegion <int>(4, 7, 8, 8)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 3, 8),
                new RectangularRegion <int>(4, 4, 8, 8),
                new RectangularRegion <int>(7, 2, 8, 3)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 8, 6),
                new RectangularRegion <int>(2, 7, 3, 8),
                new RectangularRegion <int>(7, 7, 8, 8)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 6, 8),
                new RectangularRegion <int>(7, 4, 8, 8)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 8, 6),
                new RectangularRegion <int>(2, 7, 6, 8)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 8, 3),
                new RectangularRegion <int>(2, 7, 8, 8),
                new RectangularRegion <int>(4, 4, 8, 6)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(2, 2, 8, 3),
                new RectangularRegion <int>(2, 4, 6, 8),
                new RectangularRegion <int>(7, 7, 8, 8)
            });

            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                expected = expectedList[i];
                actual   = flower.Item1.Subtract(flower.Item2[i],
                                                 j => { return(++j); },
                                                 j => { return(--j); });
                CollectionAssert.AreEqual(expected, actual);
            }

            expectedList.Clear();
            flower = this.GetInnerLeafsFlower();
            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 3, 6, 6),
                new RectangularRegion <int>(3, 1, 6, 2)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 6, 2),
                new RectangularRegion <int>(1, 5, 6, 6),
                new RectangularRegion <int>(3, 3, 6, 4)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 6, 4),
                new RectangularRegion <int>(3, 5, 6, 6)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 2, 6),
                new RectangularRegion <int>(3, 3, 6, 6),
                new RectangularRegion <int>(5, 1, 6, 2)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 6, 2),
                new RectangularRegion <int>(1, 3, 2, 6),
                new RectangularRegion <int>(3, 5, 6, 6),
                new RectangularRegion <int>(5, 3, 6, 4)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 6, 4),
                new RectangularRegion <int>(1, 5, 2, 6),
                new RectangularRegion <int>(5, 5, 6, 6)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 4, 6),
                new RectangularRegion <int>(5, 3, 6, 6)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 6, 2),
                new RectangularRegion <int>(1, 3, 4, 6),
                new RectangularRegion <int>(5, 5, 6, 6)
            });

            expectedList.Add(new List <RectangularRegion <int> >()
            {
                new RectangularRegion <int>(1, 1, 6, 4),
                new RectangularRegion <int>(1, 5, 4, 6)
            });

            for (int i = 0; i < flower.Item2.Count; ++i)
            {
                expected = expectedList[i];
                actual   = flower.Item1.Subtract(flower.Item2[i],
                                                 j => { return(++j); },
                                                 j => { return(--j); });
                CollectionAssert.AreEqual(expected, actual);
            }
        }
        public void Position2(int x, int y)
        {
            var region = new RectangularRegion(Vector.Zero, new Vector(x, y));

            Assert.That(region.Position2, Is.EqualTo(new Vector(x, y)));
        }
        public void LowerBound(int x, int y, int x2, int y2, int expectedX, int expectedY)
        {
            var region = new RectangularRegion(new Vector(x, y), new Vector(x2, y2));

            Assert.That(region.LowerBound, Is.EqualTo(new Vector(expectedX, expectedY)));
        }
        public void Contains(int x, int y, int x2, int y2, int testX, int testY, bool expected)
        {
            var region = new RectangularRegion(new Vector(x, y), new Vector(x2, y2));

            Assert.That(region.Contains(new Vector(testX, testY)), Is.EqualTo(expected));
        }
Пример #14
0
        public static devDept.Eyeshot.Entities.Region getRegionFromIfcProfileDef(IfcProfileDef ipd, ViewportLayout viewportLayout1)
        {
            devDept.Eyeshot.Entities.Region region = null;

            if (ipd is IfcCircleProfileDef)
            {
                IfcCircleProfileDef crProfDef = (IfcCircleProfileDef)ipd;

                region = new CircularRegion(crProfDef.Radius);
            }
            else if (ipd is IfcIShapeProfileDef) // IfcIShapeProfileDef and all derived from
            {
                IfcIShapeProfileDef shProfDef = (IfcIShapeProfileDef)ipd;
                double     halfWidth          = shProfDef.OverallWidth / 2;
                double     halfDepth          = shProfDef.OverallDepth / 2;
                LinearPath lp = new LinearPath(Plane.XY,
                                               new Point2D(-halfWidth, -halfDepth),
                                               new Point2D(halfWidth, -halfDepth),
                                               new Point2D(halfWidth, -halfDepth + shProfDef.FlangeThickness),
                                               new Point2D(shProfDef.WebThickness / 2, -halfDepth + shProfDef.FlangeThickness),
                                               new Point2D(shProfDef.WebThickness / 2, +halfDepth - shProfDef.FlangeThickness),
                                               new Point2D(halfWidth, +halfDepth - shProfDef.FlangeThickness),
                                               new Point2D(halfWidth, halfDepth),
                                               new Point2D(-halfWidth, halfDepth),
                                               new Point2D(-halfWidth, halfDepth - shProfDef.FlangeThickness),
                                               new Point2D(-shProfDef.WebThickness / 2, halfDepth - shProfDef.FlangeThickness),
                                               new Point2D(-shProfDef.WebThickness / 2, -halfDepth + shProfDef.FlangeThickness),
                                               new Point2D(-halfWidth, -halfDepth + shProfDef.FlangeThickness),
                                               new Point2D(-halfWidth, -halfDepth)
                                               );

                region = new devDept.Eyeshot.Entities.Region(lp);
            }
            else if (ipd is IfcRectangleProfileDef)
            {
                IfcRectangleProfileDef recProfDef = (IfcRectangleProfileDef)ipd;

                region = new RectangularRegion(recProfDef.XDim, recProfDef.YDim, true);
            }
            else if (ipd is IfcArbitraryClosedProfileDef)
            {
                IfcArbitraryClosedProfileDef arProfDef = (IfcArbitraryClosedProfileDef)ipd;

                ICurve cc = getICurveFromIfcCurve(arProfDef.OuterCurve);

                if (cc != null)
                {
                    //foreach(Entity xx in cc.CurveList)
                    //    viewportLayout1.Entities.Add((Entity)xx.Clone(), 1);

                    //viewportLayout1.Entities.Add((Entity)cc.Clone(), 2);

                    region = new devDept.Eyeshot.Entities.Region(cc);
                }
            }
            else
            {
                if (!debug.Contains("IfcProfileDef not supported: " + ipd.KeyWord))
                {
                    debug += "IfcProfileDef not supported: " + ipd.KeyWord + "\n";
                }
            }
            if (ipd is IfcParameterizedProfileDef)
            {
                IfcParameterizedProfileDef parProfDef = (IfcParameterizedProfileDef)ipd;

                if (parProfDef.Position != null && region != null)
                {
                    Plane plane = getPlaneFromPosition(parProfDef.Position);

                    Align3D algn = new Align3D(Plane.XY, plane);

                    region.TransformBy(algn);

                    //region.Translate(parProfDef.Position.Location.Coordinates.Item1, parProfDef.Position.Location.Coordinates.Item2, parProfDef.Position.Location.Coordinates.Item3);
                }
            }
            return(region);
        }
Пример #15
0
        private static Solid getSolidFromIfcBooleanClippingResult(IfcBooleanClippingResult bcr)
        {
            Solid op1 = null, op2 = null;
            Solid mmm = null;

            Entity e;

            if (bcr.FirstOperand is IfcBooleanClippingResult)
            {
                op1 = getSolidFromIfcBooleanClippingResult((IfcBooleanClippingResult)bcr.FirstOperand);
            }
            else
            {
                e = getEntityFromIfcRepresentationItem((IfcRepresentationItem)bcr.FirstOperand);

                if (e != null)// && (e is Solid || e is Mesh))
                {
                    if (e is Mesh)
                    {
                        op1 = ((Mesh)e).ConvertToSolid();
                    }
                    else
                    {
                        op1 = (Solid)e;
                    }
                }
            }

            //m = getMeshFromIfcRepresentationItem((IfcRepresentationItem)bcr.SecondOperand);

            //if (m != null)
            //    op2 = m.ConvertToSolid();

            if (bcr.SecondOperand is IfcPolygonalBoundedHalfSpace)
            {
                IfcPolygonalBoundedHalfSpace polB = (IfcPolygonalBoundedHalfSpace)bcr.SecondOperand;

                IfcPlane baseSurface = (IfcPlane)polB.BaseSurface;

                Plane cutPln = Conversion.getPlaneFromPosition(baseSurface.Position);


                devDept.Eyeshot.Entities.Region r = new RectangularRegion(cutPln, 100, 100, true);
                mmm = r.ExtrudeAsSolid(cutPln.AxisZ * 0.1, 0.1);


                Plane boundaryPlane = Conversion.getPlaneFromPosition(polB.Position);

                Align3D align = new Align3D(Plane.XY, boundaryPlane);

                ICurve boundary = getICurveFromIfcCurve(polB.PolygonalBoundary);

                if (boundary != null)
                {
                    devDept.Eyeshot.Entities.Region region = new devDept.Eyeshot.Entities.Region(boundary);

                    region.TransformBy(align);

                    Vector3D extDir = boundaryPlane.AxisZ;

                    op2 = region.ExtrudeAsSolid(extDir * 20, 0.1); // 0.1 tolerance must be computed according to object size

                    if (!polB.AgreementFlag)
                    {
                        cutPln.Flip();
                    }

                    op2.CutBy(cutPln);
                }
            }
            else if (bcr.SecondOperand is IfcHalfSpaceSolid)
            {
                IfcHalfSpaceSolid hs = (IfcHalfSpaceSolid)bcr.SecondOperand;

                IfcPlane ip = (IfcPlane)hs.BaseSurface;

                Plane pln = Conversion.getPlaneFromPosition(ip.Position);

                if (!hs.AgreementFlag)
                {
                    pln.Flip();
                }

                if (op1 != null)
                {
                    op1.CutBy(pln);
                }
                return(op1);
            }

            if (op1 == null || op2 == null)
            {
                return(null);
            }

            //op1.TransformBy(trs);
            //op2.TransformBy(trs);

            //viewportLayout1.Entities.Add(op1, testLayer, Color.Red);
            //viewportLayout1.Entities.Add(op2, testLayer, Color.Blue);
            //return null;

            Solid[] result;

            double tolerance = 0.01;

            switch (bcr.Operator)
            {
            case IfcBooleanOperator.DIFFERENCE:
                result = Solid.Difference(op1, op2, tolerance);        //su dll nuova e' possibile inserire parametro di tolleranza
                break;

            case IfcBooleanOperator.UNION:
                result = Solid.Union(op1, op2, tolerance);
                break;

            case IfcBooleanOperator.INTERSECTION:
                result = Solid.Intersection(op1, op2, tolerance);
                break;

            default:
                return(null);
            }

            //WriteSTL ws = new WriteSTL(new Entity[] { op1, op2, mmm }, new Layer[] { new Layer("Default") }, new Dictionary<string, Block>(), @"c:\devdept\booleanError\gino" + count + ".stl", 0.01, true);
            //count++;
            //ws.DoWork();

            if (result != null)
            {
                return(result[0]);
            }
            else
            {
                WriteSTL ws = new WriteSTL(new Entity[] { op1, op2 }, new Layer[] { new Layer("Default") }, new Dictionary <string, Block>(), @"c:\devdept\booleanError\gino" + bcr.Index + ".stl", 0.01, true);
                count++;
                ws.DoWork();
                debug += "Error in boolean operation\n";
                return(op1);
            }
        }