Example #1
0
        public SkyLabel(RenderContext11 renderContext, Vector3d point, string text, LabelSytle style)
        {
            Text  = text;
            Style = style;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Properties.Resources.circle, 0);
            }


            pos = point;

            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(80);

            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                Text3d t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                // This will produce sky or orbit aligned text
                textBatch.Add(new Text3d(pos, new Vector3d(0, 1, 0), text, 20, .01));
            }
        }
Example #2
0
        public KmlLabels()
        {
            texture = Texture11.FromBitmap(Properties.Resources.circle, 0);
            star    = Texture11.FromBitmap(Properties.Resources.icon_rating_star_large_on, 0);

            center    = new Vector3(10, 10, 0);
            positions = new List <Vector3>();
            names     = new List <string>();
        }
Example #3
0
        internal void Draw(RenderContext11 renderContext)
        {
            if (reticleImage == null)
            {
                reticleImage = Texture11.FromBitmap(Properties.Resources.Reticle);
            }

            ComputePoints();

            Sprite2d.Draw(renderContext, points, 4, reticleImage, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
Example #4
0
        public void SetTexture(Bitmap bmp)
        {
            if (this.texture != null)
            {
                this.texture.Dispose();
                GC.SuppressFinalize(texture);
                this.texture = null;
            }

            texture = Texture11.FromBitmap(RenderContext11.PrepDevice, bmp);
            Width   = bmp.Width;
            Height  = bmp.Height;
        }
Example #5
0
        public SkyLabel(RenderContext11 renderContext, double ra, double dec, string text, LabelSytle style, double distance)
        {
            RA    = ra;
            Dec   = dec;
            Text  = text;
            Style = style;

            Distance = distance;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Properties.Resources.circle, 0);
            }

            Vector3d up      = new Vector3d();
            Vector3d textPos = new Vector3d();

            if (Earth3d.MainWindow.SolarSystemMode)
            {
                pos = Coordinates.RADecTo3d(ra, -dec, distance);
                up  = Coordinates.RADecTo3d(ra, -dec + 90, distance);

                pos.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                pos.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));

                up.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                up.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));
            }
            else
            {
                pos     = Coordinates.RADecTo3d(ra + 12, dec, distance);
                textPos = Coordinates.RADecTo3d(ra + 12, dec + 2, distance);
                up      = Coordinates.RADecTo3d(ra + 12, dec + 92, distance);
            }
            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(24);
            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                Text3d t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                up.Normalize();
                textPos.Normalize();
                textBatch.Add(new Text3d(textPos, up, text, 20, .0005));
            }
        }
Example #6
0
        public static Texture11 GetTexture(Bitmap bitmap)
        {
            return(Texture11.FromBitmap(RenderContext11.PrepDevice, bitmap));

            //todo11 reenable the pooling of textures
            //if (bitmap.Width != 256 || bitmap.Height != 256 | !(bitmap.PixelFormat == PixelFormat.Format32bppArgb | bitmap.PixelFormat == PixelFormat.Format24bppRgb))
            //{
            //    return UiTools.LoadTextureFromBmp(Tile.prepDevice, bitmap);
            //}

            //Texture11 texture = null;
            //if (TexturePool256.Count > 0)
            //{
            //    texture = TexturePool256.Pop();
            //}
            //else
            //{
            //    texture = new Texture11(Tile.prepDevice, 256, 256, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);

            //}

            //if (bitmap.PixelFormat == PixelFormat.Format32bppArgb | bitmap.PixelFormat == PixelFormat.Format24bppRgb)
            //{
            //    BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            //    int pitch;
            //    GraphicsStream textureData = texture.LockRectangle(0, LockFlags.Discard, out pitch);
            //    unsafe
            //    {
            //        uint* texturePointer = (uint*)textureData.InternalDataPointer;
            //        for (int y = 0; y < bitmap.Height; y++)
            //        {
            //            uint* bitmapLinePointer = (uint*)bitmapData.Scan0 + y * (bitmapData.Stride / sizeof(int));
            //            uint* textureLinePointer = texturePointer + y * (pitch / sizeof(int));
            //            int length = bitmap.Width;

            //            while (--length >= 0)
            //            {
            //                *textureLinePointer++ = *bitmapLinePointer++;
            //            }

            //        }
            //    }

            //    bitmap.UnlockBits(bitmapData);
            //    texture.UnlockRectangle(0);
            //    //   texture.GenerateMipSubLevels();
            //}

            //return texture;
        }
        private Bitmap GetChartImageBitmap(Earth3d window)
        {
            Bitmap bmp = null;

            if (chartType == ChartTypes.Histogram)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetSingleColumnHistogram(TargetColumn);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);
            }

            else if (chartType == ChartTypes.BarChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDomainValueBarChart(domainColumn, targetColumn, denominatorColumn, statType);
                }
                bmp = GetBarChartBitmap(Stats);


                texture = Texture11.FromBitmap(bmp, 0);
            }
            else if (chartType == ChartTypes.TimeChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDateHistogram(TargetColumn, DateFilter);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);
            }

            Width  = bmp.Width;
            Height = bmp.Height;
            Top    = (int)window.RenderContext11.ViewPort.Height - (Height + 120);
            Left   = (int)window.RenderContext11.ViewPort.Width / 2 - (Width / 2);

            return(bmp);
        }
Example #8
0
        public void Draw3D(RenderContext11 renderContext, float transparancy)
        {
            ratio = 1116f / (float)Earth3d.MainWindow.RenderWindow.ClientRectangle.Height;

            if (SingleSelectHandles == null)
            {
                SingleSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, (Bitmap)global::TerraViewer.Properties.Resources.Selhand);
            }

            if (MultiSelectHandles == null)
            {
                MultiSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, (Bitmap)global::TerraViewer.Properties.Resources.MultiSelhand);
            }

            if (FocusHandles == null)
            {
                FocusHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, (Bitmap)global::TerraViewer.Properties.Resources.FocusHandles);
            }

            if (selectionSet.Count > 1)
            {
                foreach (Overlay overlay in selectionSet)
                {
                    if (overlay == focus)
                    {
                        DrawSelectionHandles(renderContext, overlay, FocusHandles);
                    }
                    else
                    {
                        DrawSelectionHandles(renderContext, overlay, MultiSelectHandles);
                    }
                }
            }
            else
            {
                foreach (Overlay overlay in selectionSet)
                {
                    DrawSelectionHandles(renderContext, overlay, SingleSelectHandles);
                }
            }
        }
Example #9
0
        public static Texture11 GetPushPinTexture(int pinId)
        {
            if (pinTextureCache.ContainsKey(pinId))
            {
                return(pinTextureCache[pinId]);
            }

            Bitmap bmp = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Graphics gOut = Graphics.FromImage(bmp);

            int row = pinId / 16;
            int col = pinId % 16;

            gOut.DrawImage(Pins, new Rectangle(0, 0, 32, 32), (col * 32), (row * 32), 32, 32, GraphicsUnit.Pixel);

            gOut.Flush();
            gOut.Dispose();
            Texture11 tex = Texture11.FromBitmap(bmp, 0xFF000000);

            bmp.Dispose();
            pinTextureCache.Add(pinId, tex);
            return(tex);
        }
Example #10
0
        public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent)
        {
            InViewFrustum      = true;
            RenderedGeneration = CurrentRenderGeneration;
            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);
                return(false);
            }

            InViewFrustum = true;

            if (starVertexBuffer == null)
            {
                starProfile = Texture11.FromBitmap(Properties.Resources.StarProfile);

                int count = stars.Count;
                int index = 0;
                starCount = count;

                starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);

                PositionColorSize[] points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)
                foreach (Star star in stars)
                {
                    Vector3d pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f);
                    points[index].Position = pos.Vector3;
                    points[index].Color    = star.Col;
                    double radDec = (.5) / Math.Pow(1.6, star.Magnitude);
                    points[index].size = (float)radDec;
                    index++;
                }
                starVertexBuffer.Unlock();
            }

            renderContext.SetVertexBuffer(starVertexBuffer);
            renderContext.BlendMode        = BlendMode.Additive;
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();
            PointSpriteShader11.WVPMatrix = mvp;
            PointSpriteShader11.Color     = SharpDX.Color.White;

            float adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360));

            PointSpriteShader11.ViewportScale     = new SharpDX.Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale);
            PointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10000.0f);
            PointSpriteShader11.Use(renderContext.Device.ImmediateContext);

            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView);


            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
            renderContext.devContext.Draw(starCount, 0);

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);

            // Reset blend mode so we don't mess up subsequent sky layer rendering
            renderContext.BlendMode = BlendMode.Alpha;

            return(true);
        }
Example #11
0
        private void CalcOrMake(bool makeTexture)
        {
            gridSize = 1;

            while ((gridSize * gridSize) < GlyphItems.Count)
            {
                gridSize *= 2;
            }

            int cellSize = 2;

            while (cellSize < cellHeight)
            {
                cellSize *= 2;
            }
            cellHeight = cellSize;

            int textureSize = cellHeight * gridSize;

            TextObject.Text     = "";
            TextObject.FontSize = (float)cellHeight * .50f;


            System.Drawing.Font font = TextObject.Font;
            StringFormat        sf   = new StringFormat();

            sf.Alignment = StringAlignment.Near;

            Bitmap bmp;

            if (makeTexture)
            {
                bmp = new Bitmap(textureSize, textureSize);
            }
            else
            {
                bmp = new Bitmap(20, 20);
            }

            Graphics g = Graphics.FromImage(bmp);

            int count = 0;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;


            CharacterRange[] ranges = new CharacterRange[1];
            ranges[0] = new CharacterRange(0, 1);

            sf.SetMeasurableCharacterRanges(ranges);



            foreach (GlyphItem item in GlyphItems.Values)
            {
                int    x    = (int)(count % gridSize) * cellHeight;
                int    y    = (int)(count / gridSize) * cellHeight;
                string text = new string(item.Glyph, 1);
                item.Size = g.MeasureString(text, font);
                Region[]   reg   = g.MeasureCharacterRanges(text, font, new RectangleF(new PointF(0, 0), item.Size), sf);
                RectangleF rectf = reg[0].GetBounds(g);
                item.Extents = new SizeF(rectf.Width, rectf.Height);

                if (item.Extents.Width == 0)
                {
                    item.Extents = item.Size;
                }

                float div = textureSize;
                item.UVRect = new RectangleF(x / div, y / div, item.Size.Width / div, item.Size.Height / div);
                item.UVRect = new RectangleF((x + rectf.X) / div, (y + rectf.Y) / div, rectf.Width / div, rectf.Height / div);
                if (makeTexture)
                {
                    g.DrawString(text, font, Brushes.White, x, y, sf);
                }
                count++;
            }

            g.Dispose();
            GC.SuppressFinalize(g);
            if (makeTexture)
            {
                if (texture != null)
                {
                    texture.Dispose();
                    GC.SuppressFinalize(texture);
                    texture = null;
                }
                texture      = Texture11.FromBitmap(RenderContext11.PrepDevice, bmp);
                textureDirty = false;
            }
            else
            {
                textureDirty = true;
            }
            bmp.Dispose();
            GC.SuppressFinalize(bmp);
            dirty = false;
        }
Example #12
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null || (Volitile && !ReadyToRender))
            {
                GetParameters();
                if (ImageData != null)
                {
                    try
                    {
                        MemoryStream ms = new MemoryStream(ImageData);

                        Texture11 old = this.texture;

                        texture = Texture11.FromStream(RenderContext11.PrepDevice, ms);

                        ReadyToRender = true;
                        if (old != null)
                        {
                            old.Dispose();
                            GC.SuppressFinalize(old);
                        }

                        if (Width == 0 && Height == 0)
                        {
                            Width  = texture.Width;
                            Height = texture.Height;
                            if (dataset.WcsImage != null)
                            {
                                if (dataset.WcsImage.SizeX != 0)
                                {
                                    Width = dataset.WcsImage.SizeX;
                                }
                                if (dataset.WcsImage.SizeY != 0)
                                {
                                    Height = dataset.WcsImage.SizeY;
                                }
                            }
                        }
                        ms.Dispose();
                        ImageData = null;
                    }
                    catch
                    {
                        return(false);
                    }
                }

                if (TextureReady)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }
                }
                if (this.texture == null)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }

                    if (TextureReady)
                    {
                        paintColor = Color.White;
                        if (dataset.WcsImage != null)
                        {
                            paintColor = dataset.WcsImage.Color;
                            blend      = !dataset.WcsImage.ColorCombine;
                        }


                        if (string.IsNullOrEmpty(FileName))
                        {
                            texture       = Texture11.FromBitmap(RenderContext11.PrepDevice, Image);
                            ReadyToRender = true;
                        }
                        else
                        {
                            try
                            {
                                texture       = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                ReadyToRender = true;


                                ReadyToRender = true;
                                if (Width == 0 && Height == 0)
                                {
                                    Width  = texture.Width;
                                    Height = texture.Height;
                                    if (dataset.WcsImage != null)
                                    {
                                        if (dataset.WcsImage.SizeX != 0)
                                        {
                                            Width = dataset.WcsImage.SizeX;
                                        }
                                        if (dataset.WcsImage.SizeY != 0)
                                        {
                                            Height = dataset.WcsImage.SizeY;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                try
                                {
                                    //texture = Texture.FromBitmap(prepDevice, bmp, Usage.AutoGenerateMipMap, Tile.PoolToUse);

                                    texture       = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                    ReadyToRender = true;
                                    Width         = texture.Width;
                                    Height        = texture.Height;
                                    if (dataset.WcsImage.SizeX != 0)
                                    {
                                        Width = dataset.WcsImage.SizeX;
                                    }
                                    if (dataset.WcsImage.SizeY != 0)
                                    {
                                        Height = dataset.WcsImage.SizeY;
                                    }
                                }
                                catch
                                {
                                    errored = true;
                                }
                            }
                        }
                    }
                }
            }

            if (vertexBuffer == null)
            {
                GetParameters();
                vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), 4, RenderContext11.PrepDevice);
                indexBuffer  = new IndexBuffer11(typeof(short), 6, RenderContext11.PrepDevice);
                this.OnCreateVertexBuffer(vertexBuffer);
            }



            return(true);
        }