public HistogramEqualization(FitsImage image, double min, double max) { this.min = min; this.max = max; factor = max - min; Histogram = image.ComputeHistogram(buckets); maxHistogramValue = Histogram[buckets]; lookup = new Byte[buckets]; int totalCounts = image.Width * image.Height; int sum = 0; for (int i = 0; i < buckets; i++) { sum += Histogram[i]; lookup[i] = (Byte)(Math.Min(255, ((sum * 255.0)) / totalCounts) + .5); } }
public override void LoadData(TourDocument tourDoc, string filename) { if (extension.ToLowerCase().StartsWith(".fit")) { System.Html.Data.Files.Blob blob = tourDoc.GetFileBlob(filename.Replace(".txt", extension)); FitsImage fi = new FitsImage("image.fit", blob, DoneLoading); imageSet.WcsImage = fi; if (max > 0 || min > 0) { fi.lastBitmapMax = max; fi.lastBitmapMin = min; fi.lastScale = lastScale; } } else { loaded = true; } }
public override void LoadData(TourDocument tourDoc, string filename) { if (extension.ToLowerCase().StartsWith(".fit")) { System.Html.Data.Files.Blob blob = tourDoc.GetFileBlob(filename.Replace(".txt", extension)); FitsImage fi; if (RenderContext.UseGlVersion2) { fi = new FitsImage(imageSet, "image.fit", blob, DoneLoading); } else { fi = new FitsImageJs(imageSet, "image.fit", blob, DoneLoading); } imageSet.WcsImage = fi; } else { loaded = true; } }
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); }
public virtual void RequestImage() { if (dataset.Extension.ToLowerCase().IndexOf("fits") > -1) { if (!Downloading && !ReadyToRender) { Downloading = true; if (RenderContext.UseGlVersion2) { fitsImage = new FitsImageTile(dataset, URL, delegate(WcsImage wcsImage) { Downloading = false; errored = fitsImage.errored; TileCache.RemoveFromQueue(this.Key, true); if (!fitsImage.errored) { // For a non-HiPS tiled FITS, this is our // mechanism for notifying the layer creator // that the initial FITS data have loaded and // the FitsProperties can be trusted. if (Level == 0) { dataset.FitsProperties.FireMainImageLoaded(fitsImage); fitsImage.ApplyDisplaySettings(); } texReady = true; ReadyToRender = texReady && (DemReady || !demTile); RequestPending = false; MakeTexture(); } }); } else { fitsImage = FitsImageJs.CreateTiledFits(dataset, URL, delegate(WcsImage wcsImage) { if (Level == 0) { dataset.FitsProperties.FireMainImageLoaded(fitsImage); } texReady = true; Downloading = false; errored = fitsImage.errored; ReadyToRender = texReady && (DemReady || !demTile); RequestPending = false; TileCache.RemoveFromQueue(this.Key, true); texture2d = wcsImage.GetBitmap().GetTexture(); }); } } } else { if (Dataset.WcsImage != null) { texReady = true; Downloading = false; errored = false; ReadyToRender = true; RequestPending = false; TileCache.RemoveFromQueue(this.Key, true); return; } if (!Downloading && !ReadyToRender) { Downloading = true; texture = (ImageElement)Document.CreateElement("img"); CrossDomainImage xdomimg = (CrossDomainImage)(object)texture; texture.AddEventListener("load", delegate(ElementEvent e) { texReady = true; Downloading = false; errored = false; ReadyToRender = texReady && (DemReady || !demTile); RequestPending = false; TileCache.RemoveFromQueue(this.Key, true); MakeTexture(); }, false); texture.AddEventListener("error", delegate(ElementEvent e) { if (!texture.HasAttribute("proxyattempt")) { texture.SetAttribute("proxyattempt", true); // NOTE: `this.URL` is dynamically generated using // URLHelpers.rewrite(). Say that we request tiles from // example.com, which requires CORS proxying. Say also // that this callback is called for a request to a tile // that should in fact be available. If a different // request fails before this callback is called, // activateProxy() will be called on the example.com // domain, making it so that `this.URL` in the following // call goes through the proxy, making it so that // `new_url` is null, making it so that this tile is // erroneously marked as failed when it should not be. // The solution: make sure to check proxy activation // with the *original* request URL, `texture.Src`, not // the one that may have been updated, `this.URL`. string new_url = URLHelpers.singleton.activateProxy(texture.Src); if (new_url != null) { // null => don't bother: we know that the proxy won't help texture.Src = new_url; return; } } Downloading = false; ReadyToRender = false; errored = true; RequestPending = false; TileCache.RemoveFromQueue(this.Key, true); }, false); xdomimg.crossOrigin = "anonymous"; texture.Src = this.URL; } } }
public ImageSetLayer LoadFitsLayer(string url, string name, bool gotoTarget, ImagesetLoaded loaded) { if (string.IsNullOrWhiteSpace(name)) { name = LayerManager.GetNextFitsName(); } ImageSetLayer imagesetLayer = new ImageSetLayer(); FitsImage img = new FitsImage(url, null, delegate(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; imagesetLayer.ImageSet = imageset; LayerManager.AddFitsImageSetLayer(imagesetLayer, name); LayerManager.LoadTree(); if (gotoTarget) { WWTControl.Singleton.GotoRADecZoom(wcsImage.CenterX / 15, wcsImage.CenterY, 10 * wcsImage.ScaleY * height, false); } if (loaded != null) { loaded(imagesetLayer); } }); return(imagesetLayer); }
public void LoadFits(string url) { FitsImage img = new FitsImage(url, null, OnWcsLoad); }