options-bar.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="options-bar">
  3. <div ref="draw_box"
  4. class="image"
  5. title="draw bounding box (Q)"
  6. :class="{active: interaction === 'draw-box'}"
  7. @click="$emit('interaction', 'draw-box')">
  8. <img alt="draw bounding box" src="@/assets/icons/screen-full.svg">
  9. </div>
  10. <div ref="extreme_clicking"
  11. class="image"
  12. title="extreme clicking (E)"
  13. :class="{active: interaction === 'extreme-clicking'}"
  14. @click="$emit('interaction', interaction === 'extreme-clicking' ? 'draw-box' : 'extreme-clicking')">
  15. <img v-if="interaction === 'extreme-clicking'"
  16. alt="extreme clicking" src="@/assets/icons/check.svg">
  17. <img v-else
  18. alt="extreme clicking" src="@/assets/icons/flame.svg">
  19. </div>
  20. <div class="spacer"/>
  21. <div ref="move_box"
  22. class="image"
  23. title="move and resize bounding box (R)"
  24. :class="{active: interaction === 'move-box'}"
  25. @click="$emit('interaction', 'move-box')">
  26. <img alt="move and resize bounding box" src="@/assets/icons/four-directions.svg">
  27. </div>
  28. <div v-if="labelsEnabled"
  29. ref="labels"
  30. class="image"
  31. title="label bounding box (T)"
  32. :class="{active: interaction === 'label-box'}"
  33. @click="labelSelector=true">
  34. <img alt="extreme clicking" src="@/assets/icons/tag.svg">
  35. </div>
  36. <label-selector v-if="labelSelector"
  37. :labels="labels"
  38. @close="labelSelector=false"
  39. @label="$emit('interaction', 'label-box'); $emit('label', $event)"/>
  40. <div ref="confirm_box"
  41. class="image"
  42. title="confirm bounding box (G)"
  43. :class="{active: interaction === 'confirm-box'}"
  44. @click="$emit('interaction', 'confirm-box')">
  45. <img alt="confirm bounding box" src="@/assets/icons/check-circle.svg">
  46. </div>
  47. <div ref="remove_box"
  48. class="image"
  49. title="remove bounding box (F)"
  50. :class="{active: interaction === 'remove-box'}"
  51. @click="$emit('interaction', 'remove-box')">
  52. <img alt="remove bounding box" src="@/assets/icons/trash.svg">
  53. </div>
  54. <div class="spacer"/>
  55. <div ref="zoom_annotation"
  56. class="image"
  57. title="zoom bounding box (X)"
  58. :class="{active: interaction === 'zoom-box' || zoomBox}"
  59. @click="$emit(zoomBox ? 'unzoom' : 'interaction', 'zoom-box')">
  60. <img alt="zoom bounding box" src="@/assets/icons/codescan.svg">
  61. </div>
  62. <div ref="zoom_prev_annotation"
  63. class="image"
  64. title="zoom previous bounding box (C)"
  65. @click="$emit('prevzoom', true)">
  66. <img alt="zoom previous bounding box" src="@/assets/icons/chevron-left.svg">
  67. </div>
  68. <div ref="zoom_next_annotation"
  69. class="image"
  70. title="zoom next bounding box (V)"
  71. @click="$emit('nextzoom', true)">
  72. <img alt="zoom next bounding box" src="@/assets/icons/chevron-right.svg">
  73. </div>
  74. <div class="spacer"/>
  75. <div ref="show_user_annotations"
  76. class="image"
  77. title="show user annotations"
  78. :class="{active: filter && filter.includes('user')}"
  79. @click="invertFilter('user')">
  80. <img alt="show user annotations" src="@/assets/icons/smiley.svg">
  81. </div>
  82. <div ref="show_pipeline_annotations"
  83. class="image"
  84. title="show pipeline annotations"
  85. :class="{active: filter && filter.includes('pipeline')}"
  86. @click="invertFilter('pipeline')">
  87. <img alt="show pipeline annotations" src="@/assets/icons/cpu.svg">
  88. </div>
  89. <div class="spacer"/>
  90. <div ref="create_predictions"
  91. class="image"
  92. title="create predictions (B)"
  93. :class="{active: isPredictionRunning}"
  94. @click="predict">
  95. <img alt="create predictions" src="@/assets/icons/rocket.svg">
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. import LabelSelector from "@/components/media/label-selector";
  101. export default {
  102. name: "options-bar",
  103. components: {LabelSelector},
  104. props: ['file', 'interaction', 'filter', 'label', 'labels', 'zoomBox'],
  105. created: function () {
  106. // get data
  107. this.getJobs();
  108. this.$root.socket.get(`/projects/${this.$root.project.identifier}/model`)
  109. .then(response => response.json())
  110. .then(model => this.model = model);
  111. // subscribe to changes
  112. this.$root.socket.on('connect', this.getJobs);
  113. this.$root.socket.on('create-job', this.addJob);
  114. this.$root.socket.on('remove-job', this.removeJob);
  115. this.$root.socket.on('edit-job', this.editJob);
  116. // subscribe to keypress events
  117. window.addEventListener('keypress', this.keypressEvent);
  118. },
  119. destroyed: function () {
  120. this.$root.socket.off('connect', this.getJobs);
  121. this.$root.socket.off('create-job', this.addJob);
  122. this.$root.socket.off('remove-job', this.removeJob);
  123. this.$root.socket.off('edit-job', this.editJob);
  124. window.removeEventListener('keypress', this.keypressEvent)
  125. },
  126. data: function () {
  127. return {
  128. jobs: [],
  129. labelSelector: false,
  130. model: null
  131. }
  132. },
  133. computed: {
  134. isPredictionRunning: function () {
  135. return this.jobs.filter(j => !j.finished && j.type === 'Model Interaction').length > 0;
  136. },
  137. labelsEnabled: function () {
  138. return this.model
  139. && (
  140. this.model.supports.includes('labeled-images')
  141. || this.model.supports.includes('labeled-bounding-boxes')
  142. );
  143. }
  144. },
  145. methods: {
  146. invertFilter: function (name) {
  147. if (!this.filter)
  148. return;
  149. if (this.filter.includes(name))
  150. this.$emit('filter', this.filter.filter(f => f !== name));
  151. else
  152. this.$emit('filter', [...this.filter, name]);
  153. },
  154. predict: function () {
  155. if (!this.isPredictionRunning) {
  156. // TODO then / error
  157. this.$root.socket.post(`/data/${this.file.identifier}/predict`, {
  158. predict: true
  159. });
  160. }
  161. },
  162. keypressEvent: function (event) {
  163. switch (event.key) {
  164. case 'r':
  165. this.$refs.move_box.click();
  166. break;
  167. case 'q':
  168. this.$refs.draw_box.click();
  169. break;
  170. case 'e':
  171. this.$refs.extreme_clicking.click();
  172. break;
  173. case 't':
  174. this.$refs.labels.click();
  175. event.preventDefault();
  176. break;
  177. case 'f':
  178. this.$refs.remove_box.click();
  179. break;
  180. case 'g':
  181. this.$refs.confirm_box.click();
  182. break;
  183. case 'b':
  184. this.$refs.create_predictions.click();
  185. break;
  186. case 'x':
  187. this.$refs.zoom_annotation.click();
  188. break;
  189. case 'c':
  190. this.$refs.zoom_prev_annotation.click();
  191. break;
  192. case 'v':
  193. this.$refs.zoom_next_annotation.click();
  194. break;
  195. }
  196. },
  197. getJobs: function () {
  198. this.$root.socket.get('/jobs')
  199. .then(response => response.json())
  200. .then(jobs => {
  201. this.jobs = [];
  202. jobs.forEach(this.addJob)
  203. });
  204. },
  205. addJob: function (job) {
  206. for (let j of this.jobs)
  207. if (j.identifier === job.identifier)
  208. return;
  209. this.jobs.push(job);
  210. },
  211. removeJob: function (job) {
  212. for (let i = 0; i < this.jobs.length; i++) {
  213. if (this.jobs[i].identifier === job.identifier) {
  214. this.jobs.splice(i, 1);
  215. return;
  216. }
  217. }
  218. },
  219. editJob: function (job) {
  220. for (let i = 0; i < this.jobs.length; i++) {
  221. if (this.jobs[i].identifier === job.identifier) {
  222. this.$set(this.jobs, i, job);
  223. return;
  224. }
  225. }
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped>
  231. .options-bar {
  232. /* background-color: rgba(0, 0, 0, 0.25); */
  233. background-color: #858585;
  234. z-index: 1;
  235. }
  236. .spacer {
  237. border-top: 1px solid rgba(255, 255, 255, 0.25);
  238. }
  239. .image {
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. cursor: pointer;
  244. margin: 0.4rem;
  245. border: 1px solid whitesmoke;
  246. border-radius: 0.5rem;
  247. width: 1.6rem;
  248. height: 1.6rem;
  249. }
  250. .image.active {
  251. background-color: rgba(0, 0, 0, 0.2);
  252. box-shadow: inset 0 0 5px 0 rgba(0, 0, 0, 0.2);
  253. }
  254. img {
  255. max-width: 1.1rem;
  256. max-height: 1.1rem;
  257. filter: invert(1);
  258. }
  259. .label-selector {
  260. position: absolute;
  261. top: 0;
  262. left: 50%;
  263. z-index: 101;
  264. width: 20rem;
  265. max-width: 90vw;
  266. max-height: 90vh;
  267. animation: label-selector-animation 0.5s ease-out forwards;
  268. }
  269. @keyframes label-selector-animation {
  270. from {
  271. transform: translateX(-50%) translateY(-100%);
  272. }
  273. to {
  274. transform: translateX(-50%) translateY(0%);
  275. }
  276. }
  277. </style>