radames commited on
Commit
4b9b93b
1 Parent(s): f9c1251

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +33 -8
index.html CHANGED
@@ -171,13 +171,30 @@
171
  const targetBox = event.target.getBoundingClientRect();
172
  const x = (event.clientX - targetBox.left) / targetBox.width;
173
  const y = (event.clientY - targetBox.top) / targetBox.height;
174
- isSegmenting = true;
175
- pointArr = [...pointArr, [x, y, !bgPointMode]];
 
 
 
 
 
 
 
 
 
 
176
  undoBtn.disabled = false;
 
 
 
 
 
 
177
  const { maskURL } = await getSegmentationMask(pointArr);
178
  isSegmenting = false;
179
  drawMask(maskURL, pointArr);
180
  });
 
181
  async function undoPoint() {
182
  if (!hasImage || isEmbedding || isSegmenting) {
183
  return;
@@ -271,15 +288,23 @@
271
  ctxMask.globalCompositeOperation = "destination-in";
272
  ctxMask.drawImage(img, 0, 0);
273
  ctxMask.globalCompositeOperation = "source-over";
274
- ctxMask.fillStyle = "rgba(0, 255, 255, 1)";
275
- for(const pt of points) {
 
 
 
 
276
  ctxMask.beginPath();
277
- ctxMask.arc(pt[0] * canvas.width, pt[1] * canvas.height, 3, 0, 2 * Math.PI);
 
 
 
 
 
 
278
  ctxMask.fill();
279
  }
280
  ctxMask.restore();
281
-
282
-
283
  };
284
  img.src = maskURL;
285
  }
@@ -484,4 +509,4 @@
484
  </div>
485
  </main>
486
  </body>
487
- </html>
 
171
  const targetBox = event.target.getBoundingClientRect();
172
  const x = (event.clientX - targetBox.left) / targetBox.width;
173
  const y = (event.clientY - targetBox.top) / targetBox.height;
174
+ const ptsToRemove = [];
175
+ for (const [idx, pts] of pointArr.entries()) {
176
+ const d = Math.sqrt((pts[0] - x) ** 2 + (pts[1] - y) ** 2);
177
+ if (d < 6 / targetBox.width) {
178
+ ptsToRemove.push(idx);
179
+ }
180
+ }
181
+ if (ptsToRemove.length > 0) {
182
+ pointArr = pointArr.filter((_, idx) => !ptsToRemove.includes(idx));
183
+ } else {
184
+ pointArr = [...pointArr, [x, y, !bgPointMode]];
185
+ }
186
  undoBtn.disabled = false;
187
+ if(pointArr.length == 0) {
188
+ ctxMask.clearRect(0, 0, canvas.width, canvas.height);
189
+ undoBtn.disabled = true;
190
+ return;
191
+ }
192
+ isSegmenting = true;
193
  const { maskURL } = await getSegmentationMask(pointArr);
194
  isSegmenting = false;
195
  drawMask(maskURL, pointArr);
196
  });
197
+
198
  async function undoPoint() {
199
  if (!hasImage || isEmbedding || isSegmenting) {
200
  return;
 
288
  ctxMask.globalCompositeOperation = "destination-in";
289
  ctxMask.drawImage(img, 0, 0);
290
  ctxMask.globalCompositeOperation = "source-over";
291
+ for (const pt of points) {
292
+ if (pt[2]) {
293
+ ctxMask.fillStyle = "rgba(0, 255, 255, 1)";
294
+ } else {
295
+ ctxMask.fillStyle = "rgba(255, 255, 0, 1)";
296
+ }
297
  ctxMask.beginPath();
298
+ ctxMask.arc(
299
+ pt[0] * canvas.width,
300
+ pt[1] * canvas.height,
301
+ 3,
302
+ 0,
303
+ 2 * Math.PI
304
+ );
305
  ctxMask.fill();
306
  }
307
  ctxMask.restore();
 
 
308
  };
309
  img.src = maskURL;
310
  }
 
509
  </div>
510
  </main>
511
  </body>
512
+ </html>