コード例 #1
0
        public void run()
        {
            Recordset rc = dv.GetRecordset(false, CursorType.Dynamic);
            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            foreach (KeyValuePair <int, Feature> item in feas)
            {
                GeoModel gm = item.Value.GetGeometry() as GeoModel;
                Console.WriteLine("==" + gm.Position + "==");

                //GeoModel model = new ModelIncubation.CuboidModel(10, 10, 10);
                Point3Ds p3ds = new Point3Ds();
                for (int i = 0; i < 7; i++)
                {
                    double seta = 2 * Math.PI * i / 7;
                    p3ds.Add(new Point3D(Math.Sin(seta) * 10, Math.Cos(seta) * 10, 0));
                }
                GeoModel model = new ModelIncubation.PrismModel(p3ds, 30);

                //临时处理,未知原因导致Position.Z属性设置无效,手动偏移模型实体
                model.OffsetModel(new Point3D(0, 0, 1650));
                model.Position = gm.Position;
                model.MergeMeshs();
                Console.WriteLine("");

                model.Position = gm.Position;
                model.ComputeBoundingBox();
                scene.TrackingLayer.Add(model, model.Position.ToString());
                scene.Refresh();
                GeoModel m = scene.TrackingLayer.Get(0) as GeoModel;
                Thread.Sleep(1000);

                break;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ly774508966/FaceMeGUI_BIM2SM
        public void run()
        {
            Recordset rc = dv.GetRecordset(false, CursorType.Dynamic);

            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            foreach (KeyValuePair <int, Feature> item in feas)
            {
                GeoModel gm = item.Value.GetGeometry() as GeoModel;
                Console.WriteLine("==" + gm.Position + "==");

                GeoModel model = new GeoModel();
                model.Position = gm.Position;
                foreach (Mesh m in gm.Meshes)
                {
                    if (m.Material.TextureFile.Length > 1)
                    {
                        //Console.WriteLine(m.Material.TextureFile.ToString());
                        Point3Ds p3ds = new Point3Ds();

                        for (int i = 0; i < m.Vertices.Length; i += 3)
                        {
                            bool repition = false;
                            foreach (Point3D p in p3ds)
                            {
                                if (p.X == m.Vertices[i] && p.Y == m.Vertices[i + 1] && p.Z == m.Vertices[i + 2])
                                {
                                    repition = true;
                                }
                            }
                            if (!repition)
                            {
                                p3ds.Add(new Point3D(m.Vertices[i], m.Vertices[i + 1], m.Vertices[i + 2]));
                            }
                        }

                        foreach (Point3D p3d in p3ds)
                        {
                            Console.WriteLine(string.Format(" {0},{1},{2}", p3d.X, p3d.Y, p3d.Z));
                            scene.TrackingLayer.Add(new GeoPoint3D(p3d.X, p3d.Y, p3d.Z), "");
                        }
                        //model.Meshes.Add(MakeMeshPot(p3ds));
                        Mesh mesh = new Mesh(m);
                        mesh.Material.TextureFile = @".\78310a55b319ebc41f7810198326cffc1e171629.png";
                        model.Meshes.Add(mesh);


                        #region 写属性表
                        Dictionary <string, double> fields = new Dictionary <string, double>();
                        fields.Add("FaceMeshCenterX", model.Position.X);
                        fields.Add("FaceMeshCenterY", model.Position.Y);
                        fields.Add("FaceMeshCenterZ", model.Position.Z);
                        fields.Add("FaceMeshLx", p3ds.leftbottom().X);
                        fields.Add("FaceMeshLy", p3ds.leftbottom().Y);
                        fields.Add("FaceMeshLz", p3ds.leftbottom().Z);
                        fields.Add("FaceMeshUx", p3ds.rightup().X);
                        fields.Add("FaceMeshUy", p3ds.rightup().Y);
                        fields.Add("FaceMeshUz", p3ds.rightup().Z);


                        foreach (KeyValuePair <string, double> field in fields)
                        {
                            if (dv.FieldInfos.IndexOf(field.Key) < 0)
                            {
                                FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double);
                                dv.FieldInfos.Add(fieldInf);
                            }

                            string fieldName  = field.Key;
                            double fieldValue = field.Value;
                            try
                            {
                                rc.SeekID(item.Value.GetID());
                                rc.Edit();
                                rc.SetFieldValue(fieldName, fieldValue);
                                rc.Update();
                            }
                            catch
                            {
                                Console.WriteLine("error!");
                            }
                            //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue));
                        }
                        #endregion
                    }
                }
                Console.WriteLine("");

                model.ComputeBoundingBox();
                scene.TrackingLayer.Add(model, gm.Position.ToString());
                scene.Refresh();
            }
        }
コード例 #3
0
        void addBox(DatasetVector dv, string file)
        {
            FileStream   f;
            StreamWriter sw;
            Recordset    rc = dv.GetRecordset(false, CursorType.Dynamic);

            Console.WriteLine(dv.Name + "\t::\t" + dv.Type.ToString() + "\t::\t" + dv.RecordCount);

            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            f  = new FileStream(file, FileMode.OpenOrCreate);
            sw = new StreamWriter(f);

            foreach (Feature item in feas.Values)
            {
                Point3D lower, uper, center;

                if ((item.GetGeometry() as Geometry3D) != null)
                {
                    lower  = (item.GetGeometry() as Geometry3D).BoundingBox.Lower;
                    uper   = (item.GetGeometry() as Geometry3D).BoundingBox.Upper;
                    center = (item.GetGeometry() as Geometry3D).BoundingBox.Center;

                    sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6}", item.GetID(), lower.X, lower.Y, lower.Z, uper.X, uper.Y, uper.Z));
                    if (!dv.IsOpen)
                    {
                        dv.Open();
                    }

                    Dictionary <string, double> fields = new Dictionary <string, double>();
                    fields.Add("Lx", lower.X);
                    fields.Add("Ly", lower.Y);
                    fields.Add("Lz", lower.Z);
                    fields.Add("Ux", uper.X);
                    fields.Add("Uy", uper.Y);
                    fields.Add("Uz", uper.Z);


                    foreach (KeyValuePair <string, double> field in fields)
                    {
                        if (dv.FieldInfos.IndexOf(field.Key) < 0)
                        {
                            FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double);
                            dv.FieldInfos.Add(fieldInf);
                        }

                        string fieldName  = field.Key;
                        double fieldValue = field.Value;
                        try
                        {
                            rc.SeekID(item.GetID());
                            rc.Edit();
                            rc.SetFieldValue(fieldName, fieldValue);
                            rc.Update();
                        }
                        catch
                        {
                            Console.WriteLine("error!");
                        }
                        //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue));
                    }
                    //Console.WriteLine("=="+item.GetID()+"==");
                }
            }
            Console.WriteLine(dv.Name + " done!");
            sw.Close();
            f.Close();
            rc.Close();
            dv.Close();
        }