Exemplo n.º 1
0
        private void ReadDataSource(string file)
        {
            // look for file-type
            foreach (FileType type in fileTypes)
            {
                if (type.IsFileType(file))
                {
                    fType = type;
                    break;
                }
            }
            if (fType == null)
                throw new Exception(String.Format("Unable to match file type for {0}", fType));
            
            // load data-source
            reader = new GDALReader();
            reader.OpenFile(file, fType);
            
            // build source layers for UI
            dsInfo = reader.Info;
            DataSourceControl.DataSourcePreviewInfo info = new DataSourceControl.DataSourcePreviewInfo();
            info.Dimensions = dsInfo.Resolution;
            info.Type = fType.Name;
            info.DataType = dsInfo.BppType;
            info.Groups = new DataSourceControl.DataSourceImageGroup[2];
            DataSourceControl.DataSourcePreviewImage[] images = new DataSourceControl.DataSourcePreviewImage[dsInfo.Bands.Length];
            for (int i = 0; i < dsInfo.Bands.Length; i++)
            {
                images[i] = new DataSourceControl.DataSourcePreviewImage(dsInfo.Bands[i].Image,
                                                                         dsInfo.Bands[i].Name,
                                                                         new Size(64, 64));
            }
            DataSourceControl.DataSourcePreviewImage[] buildInImages = new DataSourceControl.DataSourcePreviewImage[2];
            buildInImages[0] = new DataSourceControl.DataSourcePreviewImage(null, "NormalMap", new Size(64, 64));
            buildInImages[1] = new DataSourceControl.DataSourcePreviewImage(/*Image.FromFile(file)*/null, "TextureMap", new Size(64, 64));

            info.Groups[1] = new DataSourceControl.DataSourceImageGroup(images);
            info.Groups[0] = new DataSourceControl.DataSourceImageGroup(buildInImages);
            dataSourceControl1.DataSource = info;
            
            // load profiles for data-type
            List<DataProfile> profiles = new List<DataProfile>();
            foreach (DataProfile profile in dataProfiles)
            {
                if (profile.MatchProfile(fType))
                    profiles.Add(profile);
            }
            compatibleProfiles = profiles.ToArray();

            dataProfileControl1.Profiles = compatibleProfiles;
        }
Exemplo n.º 2
0
        public void LoadVisualization(DataProfile dataProfile, DataProfile.SubProfile subProfile,
                                      IDataSourceReader dataSrcReader, DataSourceInfo dataSrcInfo)
        {
            renderFrame = true;
            renderingThread.Start();

            controlStatus = ControlStatus.Loading;
            rContext.LoadingLayer.SetProgress(0);
            rContext.LoadingLayer.SetText("Loading... DEM Geometry");
            rContext.LoadingLayer.Visible = true;
            Render();

            // load data from dlg into database
            database = new RasterDatabase.RasterDatabase();
            object filteredData = subProfile.Filter.FilterData(dataSrcReader);
            if (filteredData is byte[])
            {
                DataLayer dataLayer = new DataLayer("DEM", 8, "byte");
                dataLayer.AddArea(new ByteArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution),
                                  new RectangleF(0, 0, 1, 1),
                                  (byte[])filteredData, dataSrcReader.Info.Resolution));
                database.AddLayer(dataLayer);
            }
            else if (filteredData is float[])
            {
                DataLayer dataLayer = new DataLayer("DEM", 32, "float");
                dataLayer.AddArea(new FloatArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution),
                                  new RectangleF(0, 0, 1, 1),
                                  (float[])filteredData, dataSrcReader.Info.Resolution));
                database.AddLayer(dataLayer);
            }

            // load data source(s)
            DataSourceItem item = new DataSourceItem(dataSrcInfo.BppType,
                                                     (Bitmap)PreviewRasterizer.DrawRotatedBandPreview(dataSrcInfo.Bands,
                                                                                                      64, dataSrcInfo));
            heightDataSrcs.Add(item);

            // load diffuse sources
            // grey-scale for height
            GreyScaleDEMSampler srcImgSampler = new GreyScaleDEMSampler();
            Bitmap srcImg = srcImgSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]);
            item = new DataSourceItem("Height", srcImg);
            item.DEMSampler = srcImgSampler;
                                      //(Bitmap)PreviewRasterizer.DrawRotatedBandPreview(new DataSourceInfo.DataBandInfo[] { new DataSourceInfo.DataBandInfo("Source", srcImg) },
                                                                                       //64, null));
            diffuseDataSrcs.Add(item);

            // load colour image if possible as other source (i.e the original if an RGB img)
            if (dataSrcReader.Info.SupportsRGB())
            {
                item = new DataSourceItem("SourceRGB",
                                          SourceDataDiffuseSampler.SampleRGBDiffuseMap((GDALReader)dataSrcReader,
                                                                                       new Size(64, 64)));
                diffuseDataSrcs.Add(item);
                reader = (GDALReader)dataSrcReader;
            }

            // height band range
            HeightBandRange hbr = new HeightBandRange();
            hbr.AddBand(0, Color.DarkGreen);
            hbr.AddBand(0.25f, Color.Blue);
            hbr.AddBand(0.4f, Color.DarkGreen);
            hbr.AddBand(0.5f, Color.Green);
            hbr.AddBand(0.8f, Color.Gray);
            hbr.AddBand(1, Color.White);
            HeightBandDEMSampler hBandSampler = new HeightBandDEMSampler(hbr);
            item = new DataSourceItem("HeightBands",
                                      hBandSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]));
            item.DEMSampler = hBandSampler;
            diffuseDataSrcs.Add(item);

            // load database into visualization
            dem = new DigitalElevationMap(database.Area.Size, database, rContext.DevIf, (GDALReader)dataSrcReader/*,
                                          hBandSampler.GenerateBitmap(new Size(512, 512),
                                          database.Layers[0].Areas[0])*/
                                                                        );
            rContext.SetDEM(dem);

            // setup geometry layers
            geometryLayers.Add(new GeometryVisLayer("Diffuse", item.Thumbnail, true));
            geometryLayers.Add(new GeometryVisLayer("Overlay Grid", null, true));

            rContext.DevIf.LocalSettings["GeometryVisLayer.Diffuse"] = geometryLayers[0];
            rContext.DevIf.LocalSettings["GeometryVisLayer.Overlay"] = geometryLayers[1];

            // now load default texture
            SetDiffuseSource(0);

            rContext.LoadingLayer.SetProgress(100);
            Render();
            Thread.Sleep(500);

            rContext.LoadingLayer.Visible = false;
            controlStatus = ControlStatus.Idle;
            Render();
        }
Exemplo n.º 3
0
 public static Image DrawRotatedBandPreview(DataSourceInfo.DataBandInfo[] bands, int imgSize, DataSourceInfo info)
 {
     Image img = new Bitmap(info != null ? imgSize * 2 : imgSize, imgSize);
     DrawRotateBandPreviewToImg(bands, img, info);
     return img;
 }
Exemplo n.º 4
0
        public static void DrawRotateBandPreviewToImg(DataSourceInfo.DataBandInfo[] bands, Image image, DataSourceInfo info)
        {
            int sz = info != null ? image.Width / 2 : image.Width;
            int rectSz = (int)Math.Sqrt(((float)sz * sz * 0.8f) / 2f);

            Graphics g = Graphics.FromImage(image);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            g.TranslateTransform(sz / 2, sz / 2);
            Rectangle rect = new Rectangle(-rectSz / 2,
                                           -rectSz / 2,
                                           rectSz,
                                           rectSz);
            float angle = 0;
            int fontSz = 16;
            Font font = new Font("Tahoma", 16);
            for (int i = bands.Length - 1; i >= 0; i--)
            {
                angle += -22.5f;
                if (i != 0)
                    g.RotateTransform(angle);

                if (bands[i].Image != null)
                    g.DrawImage(bands[i].Image, rect);
                else
                {
                    g.FillRectangle(Brushes.White, rect);
                    g.DrawRectangle(Pens.Black, rect);
                }

                if (i == 0 && bands[i].Name != null && bands[i].Name.Length > 0)
                {
                    SizeF strSz;
                    while (true)
                    {
                        strSz = g.MeasureString(bands[i].Name, font);
                        if (strSz.Width > (rectSz * 0.8))
                            font = new Font("Tahoma", --fontSz);
                        else 
                            break;
                    }
                    
                    g.DrawString(bands[i].Name, font, Brushes.Black, -strSz.Width / 2, -strSz.Height / 2);
                }

                if (i != 0)
                    g.RotateTransform(-angle);
            }

            if (info != null)
            {
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                font = new Font("Tahoma", 10);
                g.TranslateTransform(sz / 2, 0);
                g.DrawString(string.Format("{0} x {1}", info.Resolution.Width, info.Resolution.Height),
                             font, Brushes.Black, 10, -sz / 4);
                g.DrawString(info.Bpp + "-bit", font, Brushes.Black, 10, sz / 4);
            }

            g.Flush();
            g.Dispose();
        }