Exemplo n.º 1
0
        private void OnWcsLoad(WcsImage wcsImage)
        {
            int width  = (int)wcsImage.SizeX;
            int height = (int)wcsImage.SizeY;

            Imageset imageset = Imageset.Create(
                wcsImage.Description,
                Util.GetHashCode(wcsImage.Filename).ToString(),
                ImageSetType.Sky,
                BandPass.Visible,
                ProjectionType.SkyImage,
                Util.GetHashCode(wcsImage.Filename),
                0,
                0,
                256,
                wcsImage.ScaleY,
                ".tif",
                wcsImage.ScaleX > 0,
                "",
                wcsImage.CenterX,
                wcsImage.CenterY,
                wcsImage.Rotation,
                false,
                "",
                false,
                false,
                1,
                wcsImage.ReferenceX,
                wcsImage.ReferenceY,
                wcsImage.Copyright,
                wcsImage.CreditsUrl,
                "",
                "",
                0,
                ""
                );

            imageset.WcsImage = wcsImage;
            LayerManager.AddImageSetLayer(imageset, LayerManager.GetNextFitsName());
            LayerManager.LoadTree();
            WWTControl.Singleton.GotoRADecZoom(wcsImage.CenterX / 15, wcsImage.CenterY, 10 * wcsImage.ScaleY * height, false);
        }
        internal double GuessZoomSetting(double currentZoom)
        {
            double zoom = currentZoom;

            // ScriptSharp has an issue here. Maybe because we have a field name
            // matching a class name? Right now the only implementation of
            // WcsImage is FitsImage so we can get away with this:
            WcsImage aswcs = this.wcsImage as FitsImage;

            if (Projection == ProjectionType.SkyImage)
            {
                // Untiled SkyImage: basetiledegrees is degrees per pixel
                if (aswcs != null)
                {
                    zoom = BaseTileDegrees * aswcs.SizeY * 6 * FOV_FACTOR;
                }
            }
            else if (aswcs != null)
            {
                zoom = aswcs.ScaleY * aswcs.SizeY * 6 * FOV_FACTOR;
            }
            else
            {
                // Tiled. basetiledegrees is angular height of whole image after
                // power-of-2 padding.
                zoom = BaseTileDegrees * 6 * FOV_FACTOR;
            }

            // Only zoom in, not out. Usability-wise this tends to make the most
            // sense.

            if (zoom > currentZoom)
            {
                zoom = currentZoom;
            }

            return(zoom);
        }
Exemplo n.º 3
0
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);

            if (GeometryCreated)
            {
                return(true);
            }

            if (dataset.WcsImage is FitsImage && RenderContext.UseGlVersion2)
            {
                FitsImage fitsImage = dataset.WcsImage as FitsImage;
                texture2d = PrepDevice.createTexture();
                PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);

                PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
                PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);

                Width  = fitsImage.SizeX;
                Height = fitsImage.SizeY;
            }
            else
            {
                WcsImage wcsImage = dataset.WcsImage as WcsImage;
                if (wcsImage != null)
                {
                    Bitmap bmp = wcsImage.GetBitmap();
                    texture2d = bmp.GetTexture();
                    if (bmp.Height != wcsImage.SizeY)
                    {
                        PixelCenterY += bmp.Height - wcsImage.SizeY;
                    }
                    if (renderContext.gl != null)
                    {
                        Height = bmp.Height;
                        Width  = bmp.Width;
                    }
                }
                else
                {
                    Height = texture.NaturalHeight;
                    Width  = texture.NaturalWidth;
                }
            }

            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }


            ComputeMatrix();

            double latMin = 0 + (ScaleY * (Height - PixelCenterY));
            double latMax = 0 - (ScaleY * PixelCenterY);
            double lngMin = 0 + (ScaleX * PixelCenterX);
            double lngMax = 0 - (ScaleX * (Width - PixelCenterX));


            TopLeft     = GeoTo3dTan(latMin, lngMin);
            BottomRight = GeoTo3dTan(latMax, lngMax);
            TopRight    = GeoTo3dTan(latMin, lngMax);
            BottomLeft  = GeoTo3dTan(latMax, lngMin);



            Vector3d topCenter    = Vector3d.Lerp(TopLeft, TopRight, .5f);
            Vector3d bottomCenter = Vector3d.Lerp(BottomLeft, BottomRight, .5f);
            Vector3d center       = Vector3d.Lerp(topCenter, bottomCenter, .5f);
            Vector3d rightCenter  = Vector3d.Lerp(TopRight, BottomRight, .5f);
            Vector3d leftCenter   = Vector3d.Lerp(TopLeft, BottomLeft, .5f);


            if (renderContext.gl == null)
            {
                vertexList = new List <PositionTexture>();

                vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height));

                childTriangleList = new List <Triangle>();

                if (dataset.BottomsUp)
                {
                    childTriangleList.Add(Triangle.Create(0, 1, 2));
                    childTriangleList.Add(Triangle.Create(2, 1, 3));
                }
                else
                {
                    childTriangleList.Add(Triangle.Create(0, 2, 1));
                    childTriangleList.Add(Triangle.Create(2, 3, 1));
                }

                int count = 3;
                while (count-- > 1)
                {
                    List <Triangle> newList = new List <Triangle>();
                    foreach (Triangle tri in childTriangleList)
                    {
                        tri.SubDivide(newList, vertexList);
                    }
                    childTriangleList = newList;
                }

                double miter = .6 / (Width / 256);
                foreach (Triangle tri in childTriangleList)
                {
                    PositionTexture p1 = vertexList[tri.A];
                    PositionTexture p2 = vertexList[tri.B];
                    PositionTexture p3 = vertexList[tri.C];


                    RenderTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, texture, Level, miter));
                }
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
 public void DoneLoading(WcsImage wcsImage)
 {
     loaded = true;
 }