__init__.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import numpy
  2. from PF2.VectorMask import Path
  3. class VectorMask:
  4. def __init__(self):
  5. self.paths = []
  6. self.width = 0
  7. self.height = 0
  8. def set_dimentions(self, width, height):
  9. self.width = width
  10. self.height = height
  11. def get_new_path(self, brush_size, brush_feather, scale, additive):
  12. path = Path.Path(brush_size, brush_feather, scale, additive)
  13. self.paths.append(path)
  14. return path
  15. def get_mask_map(self):
  16. map = numpy.zeros((self.height, self.width, 1), dtype=numpy.uint8)
  17. print(map.shape)
  18. for path in self.paths:
  19. map = path.get_mask_map(map)
  20. print(map.shape)
  21. map32 = map.astype(numpy.float32)
  22. map32 = map32 / 255.0
  23. print(map32.shape)
  24. return map32
  25. def get_vector_mask_dict(self):
  26. paths = []
  27. for path in self.paths:
  28. paths.append(path.get_path_dict())
  29. return {
  30. "width": self.width,
  31. "height": self.height,
  32. "paths": paths
  33. }
  34. def set_from_vector_mask_dict(self, dict):
  35. self.width = dict["width"]
  36. self.height = dict["height"]
  37. paths = []
  38. for path in dict["paths"]:
  39. paths.append(Path.Path.new_from_dict(path))
  40. self.paths = paths