changeset 341:f14e81852a6c

first successful on-the-fly rendering
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 07 Dec 2024 15:05:17 +0100
parents 82a922ecd03c
children 39936650edc1
files Framework/Inputs/OnTheFlyPyramid.cpp ViewerPlugin/OrthancExplorer.js ViewerPlugin/viewer.js
diffstat 3 files changed, 115 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Inputs/OnTheFlyPyramid.cpp	Sat Dec 07 14:36:41 2024 +0100
+++ b/Framework/Inputs/OnTheFlyPyramid.cpp	Sat Dec 07 15:05:17 2024 +0100
@@ -64,7 +64,7 @@
     }
 
     if (fromWidth == tileWidth_ &&
-      fromHeight == tileHeight_)
+        fromHeight == tileHeight_)
     {
       source.GetRegion(target, x, y, tileWidth_, tileHeight_);
     }
@@ -72,11 +72,11 @@
     {
       uint8_t red, green, blue;
       GetBackgroundColor(red, green, blue);
-      Orthanc::ImageProcessing::Set(target, 255, green, blue, 255);
+      Orthanc::ImageProcessing::Set(target, red, green, blue, 255);
 
       Orthanc::ImageAccessor from, to;
       source.GetRegion(from, x, y, fromWidth, fromHeight);
-      target.GetRegion(to, x, y, fromWidth, fromHeight);
+      target.GetRegion(to, 0, 0, fromWidth, fromHeight);
       Orthanc::ImageProcessing::Copy(to, from);
     }
   }
--- a/ViewerPlugin/OrthancExplorer.js	Sat Dec 07 14:36:41 2024 +0100
+++ b/ViewerPlugin/OrthancExplorer.js	Sat Dec 07 15:05:17 2024 +0100
@@ -118,3 +118,26 @@
     });
   });
 });
+
+
+$('#instance').live('pagebeforeshow', function() {
+  var instanceId = $.mobile.pageData.uuid;
+
+  $('#wsi-instance-button').remove();
+
+  var b = $('<a>')
+    .attr('id', 'wsi-button')
+    .attr('data-role', 'button')
+    .attr('href', '#')
+    .attr('data-icon', 'search')
+    .attr('data-theme', 'e')
+    .text('On-the-fly pyramid viewer')
+    .button();
+
+  b.insertAfter($('#instance-info'));
+  b.click(function() {
+    if ($.mobile.pageData) {
+      window.open('../wsi/app/viewer.html?instance=' + instanceId);
+    }
+  });
+});
--- a/ViewerPlugin/viewer.js	Sat Dec 07 14:36:41 2024 +0100
+++ b/ViewerPlugin/viewer.js	Sat Dec 07 15:05:17 2024 +0100
@@ -48,81 +48,105 @@
 };
 
 
+function InitializePyramid(pyramid, tilesBaseUrl)
+{
+  $('#map').css('background', pyramid['BackgroundColor']);  // New in WSI 2.1
+
+  var width = pyramid['TotalWidth'];
+  var height = pyramid['TotalHeight'];
+  var countLevels = pyramid['Resolutions'].length;
+
+  // Maps always need a projection, but Zoomify layers are not geo-referenced, and
+  // are only measured in pixels.  So, we create a fake projection that the map
+  // can use to properly display the layer.
+  var proj = new ol.proj.Projection({
+    code: 'pixel',
+    units: 'pixels',
+    extent: [0, 0, width, height]
+  });
+
+  var extent = [0, -height, width, 0];
+
+  // Disable the rotation of the map, and inertia while panning
+  // http://stackoverflow.com/a/25682186
+  var interactions = ol.interaction.defaults({
+    altShiftDragRotate : false,
+    pinchRotate : false,
+    dragPan: false
+  }).extend([
+    new ol.interaction.DragPan({kinetic: false})
+  ]);
+
+  var layer = new ol.layer.Tile({
+    extent: extent,
+    source: new ol.source.TileImage({
+      projection: proj,
+      tileUrlFunction: function(tileCoord, pixelRatio, projection) {
+        return (tilesBaseUrl + (countLevels - 1 - tileCoord[0]) + '/' + tileCoord[1] + '/' + (-tileCoord[2] - 1));
+      },
+      tileGrid: new ol.tilegrid.TileGrid({
+        extent: extent,
+        resolutions: pyramid['Resolutions'].reverse(),
+        tileSizes: pyramid['TilesSizes'].reverse()
+      })
+    }),
+    wrapX: false,
+    projection: proj
+  });
+
+
+  var map = new ol.Map({
+    target: 'map',
+    layers: [ layer ],
+    view: new ol.View({
+      projection: proj,
+      center: [width / 2, -height / 2],
+      zoom: 0,
+      minResolution: 1   // Do not interpelate over pixels
+    }),
+    interactions: interactions
+  });
+
+  map.getView().fit(extent, map.getSize());
+}
+
 
 $(document).ready(function() {
   var seriesId = GetUrlParameter('series');
-  if (seriesId.length == 0)
-  {
-    alert('Error - No series ID specified!');
-  }
-  else
+  var instanceId = GetUrlParameter('instance');
+
+  if (seriesId.length != 0)
   {
     $.ajax({
       url : '../pyramids/' + seriesId,
       error: function() {
         alert('Error - Cannot get the pyramid structure of series: ' + seriesId);
       },
-      success : function(series) {
-        $('#map').css('background', series['BackgroundColor']);  // New in WSI 2.1
-
-        var width = series['TotalWidth'];
-        var height = series['TotalHeight'];
-        var countLevels = series['Resolutions'].length;
-
-        // Maps always need a projection, but Zoomify layers are not geo-referenced, and
-        // are only measured in pixels.  So, we create a fake projection that the map
-        // can use to properly display the layer.
-        var proj = new ol.proj.Projection({
-          code: 'pixel',
-          units: 'pixels',
-          extent: [0, 0, width, height]
-        });
-
-        var extent = [0, -height, width, 0];
-        
-        // Disable the rotation of the map, and inertia while panning
-        // http://stackoverflow.com/a/25682186
-        var interactions = ol.interaction.defaults({
-          altShiftDragRotate : false, 
-          pinchRotate : false,
-          dragPan: false
-        }).extend([
-          new ol.interaction.DragPan({kinetic: false})
-        ]);
-
-        var layer = new ol.layer.Tile({
-          extent: extent,
-          source: new ol.source.TileImage({
-            projection: proj,
-            tileUrlFunction: function(tileCoord, pixelRatio, projection) {
-              return ('../tiles/' + seriesId + '/' + 
-                      (countLevels - 1 - tileCoord[0]) + '/' + tileCoord[1] + '/' + (-tileCoord[2] - 1));
-            },
-            tileGrid: new ol.tilegrid.TileGrid({
-              extent: extent,
-              resolutions: series['Resolutions'].reverse(),
-              tileSizes: series['TilesSizes'].reverse()
-            })
-          }),
-          wrapX: false,
-          projection: proj
-        });
-
-
-        var map = new ol.Map({
-          target: 'map',
-          layers: [ layer ],
-          view: new ol.View({
-            projection: proj,
-            center: [width / 2, -height / 2],
-            zoom: 0,
-            minResolution: 1   // Do not interpelate over pixels
-          }),
-          interactions: interactions
-        });
-
-        map.getView().fit(extent, map.getSize());
+      success : function(pyramid) {
+        InitializePyramid(pyramid, '../tiles/' + seriesId + '/');
       }
     });
   }
+  else if (instanceId.length != 0)
+  {
+    var frameNumber = GetUrlParameter('frame');
+    if (frameNumber.length == 0)
+    {
+      frameNumber = 0;
+    }
+
+    $.ajax({
+      url : '../frames-pyramids/' + instanceId + '/' + frameNumber,
+      error: function() {
+        alert('Error - Cannot get the pyramid structure of frame ' + frameNumber + ' of instance: ' + instanceId);
+      },
+      success : function(pyramid) {
+        InitializePyramid(pyramid, '../frames-tiles/' + instanceId + '/' + frameNumber + '/');
+      }
+    });
+  }
+  else
+  {
+    alert('Error - No series ID and no instance ID specified!');
+  }
 });