Skip to content

Commit

Permalink
Merge pull request #95 from BiodataMiningGroup/rare
Browse files Browse the repository at this point in the history
Random/regular sampling
  • Loading branch information
mzur authored Feb 27, 2018
2 parents bce4453 + d3dc146 commit 3b3944d
Show file tree
Hide file tree
Showing 31 changed files with 922 additions and 414 deletions.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions src/public/assets/scripts/main.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

95 changes: 65 additions & 30 deletions src/resources/assets/js/annotations/annotatorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ biigle.$viewModel('annotator-container', function (element) {
sidebarTab: biigle.$require('core.components.sidebarTab'),
annotationsTab: biigle.$require('annotations.components.annotationsTab'),
labelsTab: biigle.$require('annotations.components.labelsTab'),
annotationModesTab: biigle.$require('annotations.components.annotationModesTab'),
colorAdjustmentTab: biigle.$require('annotations.components.colorAdjustmentTab'),
imageLabelTab: biigle.$require('annotations.components.imageLabelTab'),
settingsTab: biigle.$require('annotations.components.settingsTab'),
Expand All @@ -38,15 +39,12 @@ biigle.$viewModel('annotator-container', function (element) {
mapCenter: undefined,
mapResolution: undefined,
selectedLabel: null,
// Specifies what to cycle on the previous/next buttons or the arrow keys.
// Default is the image, others can be annotations (Volare) or image
// sections (lawnmower mode).
cycleMode: 'default',
// Index of the focussed annotation in the 'volare' cycle mode.
annotationMode: 'default',
focussedAnnotationIndex: null,
// Determines if the current image section is the last (Infinity) or the
// first (0) one.
focussedImageSectionIndex: null,
// For lawnmower and sampling modes: When switching images, this determines
// if the first (0) or the last (Infinity) image section/sampling location
// should be shown.
annotationModeCarry: null,
showMousePosition: false,
showZoomLevel: false,
showAnnotationTooltip: false,
Expand Down Expand Up @@ -82,14 +80,17 @@ biigle.$viewModel('annotator-container', function (element) {
focussedAnnotation: function () {
return this.filteredAnnotations[this.focussedAnnotationIndex];
},
isDefaultCycleMode: function () {
return this.cycleMode === 'default';
isDefaultAnnotationMode: function () {
return this.annotationMode === 'default';
},
isVolareCycleMode: function () {
return this.cycleMode === 'volare';
isVolareAnnotationMode: function () {
return this.annotationMode === 'volare';
},
isLawnmowerCycleMode: function () {
return this.cycleMode === 'lawnmower';
isLawnmowerAnnotationMode: function () {
return this.annotationMode === 'lawnmower';
},
isSamplingAnnotationMode: function () {
return this.annotationMode.endsWith('Sampling');
},
imagesIds: function () {
// Look for a sequence of image IDs in local storage. This sequence is
Expand Down Expand Up @@ -145,7 +146,7 @@ biigle.$viewModel('annotator-container', function (element) {
return;
}

if (this.isVolareCycleMode) {
if (this.isVolareAnnotationMode) {
if (this.focussedAnnotationIndex < (this.filteredAnnotations.length - 1)) {
this.focussedAnnotationIndex++;
return;
Expand All @@ -154,15 +155,22 @@ biigle.$viewModel('annotator-container', function (element) {
// don't return.
this.focussedAnnotationIndex = -Infinity;
}
} else if (this.isLawnmowerCycleMode) {
} else if (this.isLawnmowerAnnotationMode) {
// This returns false if the image section can't be advanced (i.e.
// the last section is shown).
if (this.$refs.canvas.showNextImageSection()) {
return;
} else {
// Show the first image section in the next image in this case,
// so don't return.
this.focussedImageSectionIndex = 0;
this.annotationModeCarry = 0;
}
} else if (this.isSamplingAnnotationMode) {
// Similar mechanism than for Lanwmower Mode.
if (this.$refs.canvas.showNextSamplingLocation()) {
return;
} else {
this.annotationModeCarry = 0;
}
}

Expand All @@ -174,7 +182,7 @@ biigle.$viewModel('annotator-container', function (element) {
return;
}

if (this.isVolareCycleMode) {
if (this.isVolareAnnotationMode) {
if (this.focussedAnnotationIndex > 0) {
this.focussedAnnotationIndex--;
return;
Expand All @@ -183,23 +191,30 @@ biigle.$viewModel('annotator-container', function (element) {
// so don't return.
this.focussedAnnotationIndex = Infinity;
}
} else if (this.isLawnmowerCycleMode) {
} else if (this.isLawnmowerAnnotationMode) {
// This returns false if the image section can't be reversed (i.e.
// the first section is shown).
if (this.$refs.canvas.showPreviousImageSection()) {
return;
} else {
// Show the last image section in the previous image in this
// case, so don't return.
this.focussedImageSectionIndex = Infinity;
this.annotationModeCarry = Infinity;
}
} else if (this.isSamplingAnnotationMode) {
// Similar mechanism than for Lanwmower Mode.
if (this.$refs.canvas.showPreviousSamplingLocation()) {
return;
} else {
this.annotationModeCarry = Infinity;
}
}

// Show previous image.
this.imageIndex = this.getPreviousIndex(this.imageIndex);
},
maybeUpdateFocussedAnnotation: function () {
if (this.isVolareCycleMode) {
if (this.isVolareAnnotationMode) {
if (this.filteredAnnotations.length > 0) {
if (this.focussedAnnotationIndex === Infinity) {
// Show the last annotation if the previous image is shown.
Expand All @@ -219,14 +234,32 @@ biigle.$viewModel('annotator-container', function (element) {
}
},
maybeUpdateShownImageSection: function () {
if (this.isLawnmowerCycleMode) {
if (this.focussedImageSectionIndex === Infinity) {
if (this.isLawnmowerAnnotationMode) {
if (this.annotationModeCarry === Infinity) {
this.$refs.canvas.showLastImageSection();
} else {
this.$refs.canvas.showFirstImageSection();
}
}
},
maybeUpdateShownSampling: function (data) {
if (this.isSamplingAnnotationMode) {
this.$refs.canvas.setSamplingData(this.annotationMode, data);

if (this.annotationModeCarry === Infinity) {
// Use nextTick so the annotationMode can propagate down to the
// annotationCanvas before the sampling location is shown.
this.$nextTick(this.$refs.canvas.showLastSamplingLocation);
} else {
this.$nextTick(this.$refs.canvas.showFirstSamplingLocation);
}
}
},
maybeUpdateAnnotationMode: function (data) {
this.maybeUpdateFocussedAnnotation();
this.maybeUpdateShownImageSection();
this.maybeUpdateShownSampling(data);
},
handleMapMoveend: function (viewport) {
this.mapCenter = viewport.center;
this.mapResolution = viewport.resolution;
Expand Down Expand Up @@ -382,11 +415,6 @@ biigle.$viewModel('annotator-container', function (element) {
case 'annotationOpacity':
this.annotationOpacity = value;
break;
case 'cycleMode':
this.cycleMode = value;
this.maybeUpdateFocussedAnnotation();
this.maybeUpdateShownImageSection();
break;
case 'mousePosition':
this.showMousePosition = value;
break;
Expand All @@ -401,6 +429,11 @@ biigle.$viewModel('annotator-container', function (element) {
break;
}
},
handleAnnotationModeChange: function (mode, data) {
this.annotationMode = mode;
this.annotationModeCarry = null;
this.maybeUpdateAnnotationMode(data);
},
handleOpenedTab: function (name) {
settings.set('openTab', name);
},
Expand All @@ -410,6 +443,9 @@ biigle.$viewModel('annotator-container', function (element) {
handleLoadingError: function (message) {
messages.danger(message);
},
createSampledAnnotation: function () {
this.$refs.canvas.createSampledAnnotation();
},
},
watch: {
imageId: function (id) {
Expand All @@ -419,8 +455,7 @@ biigle.$viewModel('annotator-container', function (element) {
.catch(this.handleLoadingError)
.then(this.setCurrentImageAndAnnotations)
.then(this.updateUrlSlug)
.then(this.maybeUpdateFocussedAnnotation)
.then(this.maybeUpdateShownImageSection)
.then(this.maybeUpdateAnnotationMode)
.then(this.emitImageChanged)
// When everything is loaded, pre-fetch the data of the next and
// previous images so they can be switched fast.
Expand Down
Loading

0 comments on commit 3b3944d

Please sign in to comment.