Пример #1
0
        public static Relation OverlapOperator(ModelInfo modelInfo1, ModelInfo modelInfo2)
        {
            if (modelInfo1 != null && modelInfo2 != null)
            {
            }
            else
            {
                return(null);
            }
            // QL4BIMspatial.IContainOperator

            // Call the Singleton Class to get the actual loaded elements -> Connection to the DataModel
            ModelController _modelController = ModelController.Instance;

            var model1 = _modelController.GetModel(modelInfo1.modelId) as IfcModel;
            var model2 = _modelController.GetModel(modelInfo2.modelId) as IfcModel;

            var result        = new Relation(Guid.Parse(modelInfo1.modelId), Guid.Parse(modelInfo2.modelId));
            var resCollection = result.Collection as ObservableCollection <Tuple <Guid, Guid> >;

            var elements1 = model1.GetElements(modelInfo1.elementIds);
            var elements2 = model1.GetElements(modelInfo2.elementIds);

            var list_1 = GeometryHandler.CreateTriangleMeshes(elements1, model1.xModelContext);
            var list_2 = GeometryHandler.CreateTriangleMeshes(elements2, model2.xModelContext);

            // Init the Settings for the operators
            var settings = container.Resolve <ISettings>();

            settings.Direction.RaysPerSquareMeter = 100;
            settings.Direction.PositiveOffset     = 100;
            // The mapping of the operators is because of the transformation of the model
            // Init the Operator

            var op = container.Resolve <IOverlapOperator>();

            // var op = container.Resolve<ITouchOperator>();


            foreach (var item1 in list_1)
            {
                foreach (var item2 in list_2)
                {
                    var abs = op.Overlap(item1, item2);
                    if (abs)
                    {
                        resCollection.Add(new Tuple <Guid, Guid>(IfcGuid.FromIfcGuid(item1.Name), IfcGuid.FromIfcGuid(item2.Name)));
                    }
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// QL4BIM GeometryOperation Function
        /// </summary>
        /// <param name="elements"></param>
        /// <param name="xModelContext"></param>
        /// <returns></returns>
        public static List <TriangleMesh> CreateTriangleMeshes(List <IIfcProduct> elements, Xbim3DModelContext xModelContext)
        {
            var resList = new List <TriangleMesh>();

            foreach (var item in elements)
            {
                //  var mesh = GeometryHandler.WriteTriangles(item, xModelContext, new XbimMatrix3D())

                var mesh = GeometryHandler.WriteAllTriangles(item, xModelContext, new XbimMatrix3D());


                // Transformation
                // var vertices = jObject.SelectToken("vertices").ToList().Select(value => value.Value<double>()).ToArray();
                // var indices = jObject.SelectToken("faces").ToList().Select(value => value.Value<int>()).ToArray();
                // var faceSet = new IndexedFaceSet(item.Id.ToString(), indices, vertices);

                var vertices = new List <Tuple <double, double, double> >();

                // var posList = new List<double>();
                foreach (var pos in mesh.Positions)
                {
                    vertices.Add(new Tuple <double, double, double>(pos.X, pos.Y, pos.Z));
                    // posList.Add(pos.X);
                    // posList.Add(pos.Y);
                    // posList.Add(pos.Z);
                }

                var indices = new List <Tuple <int, int, int> >();
                for (int i = 0; i < mesh.TriangleIndices.Count; i = i + 3)
                {
                    indices.Add(new Tuple <int, int, int>(mesh.TriangleIndices[i], mesh.TriangleIndices[i + 1], mesh.TriangleIndices[i + 2]));
                }

                if (vertices.Count == 0 || indices.Count == 0)
                {
                    continue;
                }

                var faceSet = new IndexedFaceSet(vertices.ToArray(), indices.ToArray(), item.GlobalId.ToString(), 1);

                // var faceSet = new IndexedFaceSet(item.GlobalId.ToString(), mesh.TriangleIndices.ToArray(), posList.ToArray());
                resList.Add(faceSet.CreateMesh());
            }

            return(resList);
        }