Skip to content

Commit

Permalink
Merge branch 'geo_upload' into context_fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
mtiessen1175 authored Nov 13, 2024
2 parents 771b888 + 8693f2d commit c2f9cd5
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 51 deletions.
52 changes: 52 additions & 0 deletions src/Jobs/TileSingleOverlay.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use FileCache;
use Biigle\Modules\Geo\GeoOverlay;
use File;
use Jcupitt\Vips\Image as VipsImage;

class TileSingleOverlay extends TileSingleObject
{
Expand Down Expand Up @@ -55,4 +56,55 @@ public function handle()
File::deleteDirectory($this->tempPath);
}
}

/**
* Generate tiles for the object and put them to temporary storage.
*
* @param File $file
* @param string $path Path to the cached image file.
*/
public function generateTiles($file, $path)
{
$vipsImage = $this->getVipsImage($path);
// exclude the NoData values (-99999) of the geoTIFF file when searching the min
$min = $vipsImage->equal(-99999)->ifthenelse(0, $vipsImage)->min();
$max = $vipsImage->max();

if($min < 0 || $min > 255 || $max < 0 || $max > 255) {
$this->imageNormalization($vipsImage, $min, $max)->dzsave($this->tempPath, [
'layout' => 'zoomify',
'container' => 'fs',
'strip' => true,
]);
} else {
parent::generateTiles($file, $path);
}
}

/**
* Get the vips image instance.
*
* @param string $path
*
* @return \Jcupitt\Vips\Image
*/
protected function getVipsImage($path)
{
return VipsImage::newFromFile($path);
}

/**
* Normalize the image band to 0 to 255
*
* @param \Jcupitt\Vips\Image $vipsImage
* @param float $min minimum value of color-level of the input image
* @param float $max maximum value of color-level of the input image
*
* @return \Jcupitt\Vips\Image
*/
protected function imageNormalization($vipsImage, $min, $max)
{
// band intensity normalization x' = (x - $min) / ($max - $min) * 255
return $vipsImage->linear(($vipsImage - $min) / ($max - $min) * 255);
}
}
2 changes: 1 addition & 1 deletion src/public/assets/scripts/volumes.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/public/assets/styles/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/public/mix-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"/assets/scripts/volumes.js": "/assets/scripts/volumes.js?id=ead6c2afb75060312c61a6d68ad4b28d",
"/assets/scripts/annotations.js": "/assets/scripts/annotations.js?id=4c1eb02d73360d78996dd306466b2d38",
"/assets/styles/main.css": "/assets/styles/main.css?id=bf09d95dc04208c3ee738dafbf8e123c"
}
}
4 changes: 0 additions & 4 deletions src/resources/assets/js/volumes/api/geoOverlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export default Vue.resource('api/v1/geo-overlays{/id}', {}, {
method: 'POST',
url: 'api/v1/volumes{/id}/geo-overlays/geotiff',
},
getGeoTiffOverlayUrlTemplate: {
method: 'GET',
url: 'api/v1/volumes{/id}/geo-overlays/geotiff/url',
},
// WebMap
saveWebMap: {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion src/resources/assets/js/volumes/components/geoMapModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
<div class="cell cell-content">
<p class="text-muted">
<em>Hint:</em> Select image locations on the volume map by drawing an encompassing rectangle. To do this, press and hold <kbd>Ctrl</kbd> as well as the left mouse button and move the cursor on the map.
<em>Hint:</em> Select image locations on the volume map by drawing an encompassing rectangle. To do this, press and hold <kbd>Ctrl</kbd> (<kbd>Cmd &#8984;</kbd> on Mac) as well as the left mouse button and move the cursor on the map.
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<script>
import Api from '../api/geoOverlays';
import {LoaderMixin} from '../import';
export default {
mixins: [
LoaderMixin,
],
props: {
volumeId: {
type: Number,
Expand All @@ -16,13 +11,11 @@ export default {
data() {
return {
error: false,
success: false,
};
},
methods: {
handleSuccess(response) {
this.error = false;
this.success = true;
this.$emit('success', response.data);
},
handleError(response) {
Expand Down Expand Up @@ -59,7 +52,7 @@ export default {
data.append('volumeId', this.volumeId);
this.upload(data)
.then(this.handleSuccess, this.handleError)
.finally(this.$emit('upload', false));
.finally(() => this.$emit('upload', false));
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/resources/assets/js/volumes/components/overlayItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,9 @@ td:nth-child(6) {
td:not(.start) {
text-align: center;
}
/* center the delete button */
.close {
float: none;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div class="table-responsive">
<table v-if="overlays.length !== 0" class="table table-sm" v-cloak>
<caption><b><slot name="title"></slot></b></caption>
<thead>
<tr>
<slot name="header">
Expand Down Expand Up @@ -114,6 +113,7 @@ export default {
table {
table-layout: auto;
margin-bottom: 0px;
}
th {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import geoApi from '../api/geoOverlays';
import {LoaderMixin} from '../import';
export default {
data() {
Expand All @@ -9,9 +8,6 @@ export default {
success: false,
};
},
mixins: [
LoaderMixin,
],
props: {
volumeId: {
type: Number,
Expand Down Expand Up @@ -46,7 +42,7 @@ export default {
data.append('volumeId', this.volumeId);
geoApi.saveWebMap({id: this.volumeId}, data)
.then(this.handleSuccess, this.handleError)
.finally(this.$emit('upload', false))
.finally(() => this.$emit('upload', false))
},
},
};
Expand Down
5 changes: 0 additions & 5 deletions src/resources/assets/sass/_volumesEditRight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
flex: 0;
}


#volume-geo-overlay-upload.panel {
margin-bottom: 80px;
}

.toggle-btn {
background-color: grey;
text-decoration: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
<form class="form" v-on:submit.prevent="submitGeoTiff">
<div class="form-group">
<input class="hidden" ref="geoTiffInput" type="file" name="file" v-on:change="uploadGeoTiff" accept=".tif,.tiff">
<button class="btn btn-default" type="submit" :disabled="loading">Upload geoTIFF</button>
<button class="btn btn-default" type="submit">Upload geoTIFF</button>
</div>
</form>
<div class="alert alert-danger" v-if="error" v-text="error" v-cloak></div>
<div class="alert alert-success" v-if="success" v-cloak>
The geoTIFF-file was successfully uploaded.
</div>
</div>
3 changes: 0 additions & 3 deletions src/resources/views/volumes/edit/webmapOverlayForm.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@ class="form-control"
</div>
</form>
<div class="alert alert-danger" v-if="error" v-text="error" v-cloak></div>
<div class="alert alert-success" v-if="success" v-cloak>
The web-map-service was successfully embedded.
</div>
</div>
1 change: 0 additions & 1 deletion src/resources/views/volumesEditRight.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</div>
<div v-if="hasOverlays('geoOverlays')">
<overlay-table :overlays="geoOverlays" v-on:remove="handleRemove" :volume-id="{{ $volume->id }}" :project-id="{{ $volume->projects->pluck('id')->first() }}" >
<template v-slot:title>Geo Overlays</template>
<template v-slot:header>
<th></th>
<th>#</th>
Expand Down
34 changes: 18 additions & 16 deletions tests/Jobs/TileSingleOverlayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Biigle\Modules\Geo\Jobs\TileSingleOverlay;
use Biigle\Tests\Modules\Geo\GeoOverlayTest;
use Biigle\Modules\Geo\GeoOverlay;
use Biigle\FileCache\GenericFile;
use File;
use FileCache;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Jcupitt\Vips\Image;
Expand All @@ -20,28 +22,28 @@ public function testGenerateOverlayTiles()
$overlay = GeoOverlayTest::createGeotiffOverlay();

// save fake UploadedFile to geo-overlay storage
$overlayFile = UploadedFile::fake()->create($overlay->name, 20, 'image/tiff');
// $overlayFile = UploadedFile::fake()->create($overlay->name, 20, 'image/tiff');
$overlayFile = new UploadedFile(
__DIR__."/../files/geotiff_standardEPSG2013.tif",
'standardEPSG2013.tif',
'image/tiff',
null,
true
);

$disk = config('geo.tiles.overlay_storage_disk');
$overlay->storeFile($overlayFile);
$this->assertTrue(Storage::disk('geo-overlays')->exists($overlay->path));
// $testCorrectFile = Storage::disk('geo-overlays')->path($overlay->path);
// dd("{$disk}://{$overlay->path}", $testCorrectFile);

// retreive fake UploadedFile from geo-overlay storage and cast to GenericFile
$disk = config('geo.tiles.overlay_storage_disk');
$file = new GenericFile("{$disk}://{$overlay->path}");

// retreive UploadedFile from geo-overlay storage and cast to GenericFile
$file = new GenericFile("{$disk}://{$overlay->path}");
$targetPath = "{$overlay->id}/{$overlay->id}_tiles";
$job = new TileSingleOverlayStub($overlay, $disk, $targetPath);
$mock = Mockery::mock(Image::class);
$mock->shouldReceive('dzsave')
->once()
->with($job->tempPath, [
'layout' => 'zoomify',
'container' => 'fs',
'strip' => true,
]);

$job->mock = $mock;
$job = new TileSingleOverlay($overlay, $disk, $targetPath);

$job->generateTiles($file, '');
FileCache::getOnce($file, [$job, 'generateTiles']);
}

public function testUploadOverlayToStorage()
Expand Down

0 comments on commit c2f9cd5

Please sign in to comment.