def save(self, *args, **kwargs): # compute counts: if not self.num_vertices: self.num_vertices = len(self.vertices.split(',')) // 2 if not self.num_triangles: self.num_triangles = len(self.triangles.split(',')) // 3 if not self.num_segments: self.num_segments = len(self.segments.split(',')) // 2 if not self.area: from shapes.utils import complex_polygon_area self.area = complex_polygon_area(self.vertices, self.triangles) if not self.pixel_area: self.pixel_area = (self.area * self.photo.image_orig.width * self.photo.image_orig.height) if not self.synthetic: self.synthetic = self.photo.synthetic if not self.label_pos_x or not self.label_pos_y: from shapes.utils import update_shape_label_pos update_shape_label_pos(self, save=False) thumbs_dirty = (not self.id) # compute cropped image synchronously, before saving # (this way the shape only shows up after all thumbs are available) if not self.image_crop or not self.image_bbox: from shapes.utils import update_shape_image_crop update_shape_image_crop(self, save=False) thumbs_dirty = True if not self.image_pbox: from shapes.utils import update_shape_image_pbox update_shape_image_pbox(self, save=False) thumbs_dirty = True #if not self.three_js or not self.three_bin: #from shapes.utils import update_shape_three #update_shape_three(self, save=False) #if not self.dominant_rgb0: if thumbs_dirty: from shapes.utils import update_shape_dominant_rgb update_shape_dominant_rgb(self, save=False) if (not self.dominant_delta and self.dominant_rgb0 and self.dominant_rgb1): from shapes.utils import update_shape_dominant_delta update_shape_dominant_delta(self, save=False) super(Shape, self).save(*args, **kwargs)
def fill_in_pbox_task(shape): """ Helper to fill in the potentially empty image_pbox field """ update_shape_image_pbox(shape, save=True)