options-bar.vue 8.8 KB

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