BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
BioImager.SlideRenderer Class Reference

Public Member Functions

 SlideRenderer (SlideGLArea glArea)
 
void SetSource (OpenSlideBase source)
 
void SetSource (SlideBase source)
 
bool IsSource (OpenSlideBase source)
 
bool IsSource (SlideBase source)
 
void ClearCache ()
 
async Task UpdateViewAsync (PointD pyramidalOrigin, int viewportWidth, int viewportHeight, double resolution, ZCT coordinate, BioImage? rgbZarr=null, int[]? rgbSelection=null)
 

Properties

int CurrentLevel [get]
 
int CachedTextureCount [get]
 

Detailed Description

Definition at line 14 of file SlideRenderer.cs.

Constructor & Destructor Documentation

◆ SlideRenderer()

BioImager.SlideRenderer.SlideRenderer ( SlideGLArea glArea)

Definition at line 41 of file SlideRenderer.cs.

42 {
43 _glArea = glArea;
44 _glArea.GLReady += OnGlReady;
45 }

Member Function Documentation

◆ ClearCache()

void BioImager.SlideRenderer.ClearCache ( )

Definition at line 75 of file SlideRenderer.cs.

76 {
77 _contentVersion++;
78 _contentCoordinate = null;
79 _glArea.ClearTextureCache();
80 _uploadedTiles.Clear();
81 _currentLevel = -1;
82 lock (_pendingTileFetchLock)
83 {
84 _pendingTileFetches.Clear();
85 }
86 }
void ClearTextureCache()
Clear all cached textures.

◆ IsSource() [1/2]

bool BioImager.SlideRenderer.IsSource ( OpenSlideBase source)

Definition at line 65 of file SlideRenderer.cs.

66 {
67 return _useOpenSlide && ReferenceEquals(_openSlideBase, source);
68 }

◆ IsSource() [2/2]

bool BioImager.SlideRenderer.IsSource ( SlideBase source)

Definition at line 70 of file SlideRenderer.cs.

71 {
72 return !_useOpenSlide && ReferenceEquals(_slideBase, source);
73 }

◆ SetSource() [1/2]

void BioImager.SlideRenderer.SetSource ( OpenSlideBase source)

Definition at line 47 of file SlideRenderer.cs.

48 {
49 if (IsSource(source)) return;
50 _openSlideBase = source;
51 _slideBase = null;
52 _useOpenSlide = true;
53 ClearCache();
54 }
bool IsSource(OpenSlideBase source)

◆ SetSource() [2/2]

void BioImager.SlideRenderer.SetSource ( SlideBase source)

Definition at line 56 of file SlideRenderer.cs.

57 {
58 if (IsSource(source)) return;
59 _slideBase = source;
60 _openSlideBase = null;
61 _useOpenSlide = false;
62 ClearCache();
63 }

◆ UpdateViewAsync()

async Task BioImager.SlideRenderer.UpdateViewAsync ( PointD pyramidalOrigin,
int viewportWidth,
int viewportHeight,
double resolution,
ZCT coordinate,
BioImage? rgbZarr = null,
int?[] rgbSelection = null )

Definition at line 88 of file SlideRenderer.cs.

96 {
97 _pendingPyramidalOrigin = pyramidalOrigin;
98 _pendingViewportWidth = viewportWidth;
99 _pendingViewportHeight = viewportHeight;
100 _pendingResolution = resolution;
101 _pendingCoordinate = coordinate;
102 _pendingRgbZarr = rgbZarr;
103 _pendingRgbSelection = rgbSelection?.ToArray();
104 _hasPendingView = true;
105
106 if (_openSlideBase == null && _slideBase == null)
107 return;
108 if (viewportWidth <= 1 || viewportHeight <= 1 || resolution <= 0 || !double.IsFinite(resolution))
109 return;
110 if (!_glArea.IsGLReady)
111 return;
112 if (!_renderSemaphore.Wait(0))
113 {
114 return;
115 }
116
117 try
118 {
119 var schema = _useOpenSlide ? _openSlideBase.Schema : _slideBase.Schema;
120 int level = TileUtil.GetLevel(schema.Resolutions, resolution);
121 var levelRes = schema.Resolutions[level];
122 double levelUnitsPerPixel = levelRes.UnitsPerPixel;
123
124 var contentCoordinate = (coordinate.Z, coordinate.C, coordinate.T);
125 if (_contentCoordinate != contentCoordinate || !ReferenceEquals(_rgbZarr, rgbZarr) ||
126 !SelectionsEqual(_rgbSelection, rgbSelection) || level != _currentLevel)
127 {
128 // TileIndex alone does not distinguish planes or RGB selections.
129 ClearCache();
130 _contentCoordinate = contentCoordinate;
131 _rgbZarr = rgbZarr;
132 _rgbSelection = rgbSelection?.ToArray();
133 _currentLevel = level;
134 }
135 int contentVersion = _contentVersion;
136
137 double minX = pyramidalOrigin.X;
138 double width = viewportWidth * resolution;
139 double height = viewportHeight * resolution;
140 var viewportExtent = new Extent(minX, -pyramidalOrigin.Y - height, minX + width, -pyramidalOrigin.Y);
141
142 double tileMarginX = levelRes.TileWidth * levelUnitsPerPixel;
143 double tileMarginY = levelRes.TileHeight * levelUnitsPerPixel;
144 var fetchExtent = new Extent(
145 viewportExtent.MinX - tileMarginX,
146 viewportExtent.MinY - tileMarginY,
147 viewportExtent.MaxX + tileMarginX,
148 viewportExtent.MaxY + tileMarginY);
149
150 var tileInfos = schema.GetTileInfos(fetchExtent, level).ToList();
151 if (tileInfos.Count == 0)
152 {
153 var lookupExtent = BioLib.ExtentEx.WorldToPixelInvertedY(fetchExtent, levelUnitsPerPixel);
154 tileInfos = schema.GetTileInfos(lookupExtent, level).ToList();
155 }
156 var renderInfos = new List<TileRenderInfo>();
157 var pendingFetches = new List<(TileInfo Tile, Task<byte[]> FetchTask)>();
158 foreach (var tileInfo in tileInfos)
159 {
160 if (_glArea.HasTileTexture(tileInfo.Index))
161 {
162 renderInfos.Add(CalculateScreenPosition(
163 tileInfo,
164 pyramidalOrigin,
165 resolution,
166 level,
167 schema));
168 continue;
169 }
170
171 bool alreadyPending;
172 lock (_pendingTileFetchLock)
173 {
174 alreadyPending = !_pendingTileFetches.Add((tileInfo.Index, contentVersion));
175 }
176
177 if (!alreadyPending)
178 {
179 pendingFetches.Add((tileInfo, FetchTileAsync(tileInfo, level, coordinate, schema, rgbZarr, rgbSelection?.ToArray(), RemoteTileFetchTimeout)));
180 }
181 renderInfos.Add(CalculateScreenPosition(
182 tileInfo, pyramidalOrigin, resolution, level, schema));
183 }
184
185 foreach (var pending in pendingFetches)
186 {
187 _ = ProcessPendingFetchAsync(
188 pending.Tile,
189 pending.FetchTask,
190 pyramidalOrigin,
191 resolution,
192 level,
193 schema,
194 contentVersion,
195 rgbZarr != null);
196 }
197
198 _glArea.SetTilesToRender(renderInfos);
199 _glArea.RequestRedraw();
200 }
201 finally
202 {
203 _renderSemaphore.Release();
204 }
205 }
bool IsGLReady
True after the GL context has been fully initialized and is ready for texture uploads and rendering.
void SetTilesToRender(IEnumerable< TileRenderInfo > tiles)
Prepare tiles for rendering. Call before RequestRedraw().
void RequestRedraw()
Request a redraw of the GLArea.
bool HasTileTexture(TileIndex index)
Check if a tile texture is already in the GPU cache.

Property Documentation

◆ CachedTextureCount

int BioImager.SlideRenderer.CachedTextureCount
get

Definition at line 417 of file SlideRenderer.cs.

◆ CurrentLevel

int BioImager.SlideRenderer.CurrentLevel
get

Definition at line 416 of file SlideRenderer.cs.


The documentation for this class was generated from the following file: