BLI_voronoi.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2012 Blender Foundation.
  19. * All rights reserved.
  20. *
  21. * Contributor(s): Sergey Sharybin
  22. *
  23. * ***** END GPL LICENSE BLOCK *****
  24. */
  25. #ifndef __BLI_VORONOI_H__
  26. #define __BLI_VORONOI_H__
  27. struct ListBase;
  28. /** \file BLI_voronoi.h
  29. * \ingroup bli
  30. */
  31. typedef struct VoronoiSite {
  32. float co[2];
  33. float color[3];
  34. } VoronoiSite;
  35. typedef struct VoronoiEdge {
  36. struct VoronoiEdge *next, *prev;
  37. float start[2], end[2]; /* start and end points */
  38. /* this fields are used during diagram computation only */
  39. float direction[2]; /* directional vector, from "start", points to "end", normal of |left, right| */
  40. float left[2]; /* point on Voronoi place on the left side of edge */
  41. float right[2]; /* point on Voronoi place on the right side of edge */
  42. float f, g; /* directional coeffitients satisfying equation y = f * x + g (edge lies on this line) */
  43. /* some edges consist of two parts, so we add the pointer to another part to connect them at the end of an algorithm */
  44. struct VoronoiEdge *neighbor;
  45. } VoronoiEdge;
  46. typedef struct VoronoiTriangulationPoint {
  47. float co[2];
  48. float color[3];
  49. int power;
  50. } VoronoiTriangulationPoint;
  51. void BLI_voronoi_compute(const VoronoiSite *sites, int sites_total, int width, int height, struct ListBase *edges);
  52. void BLI_voronoi_triangulate(const VoronoiSite *sites, int sites_total, struct ListBase *edges, int width, int height,
  53. VoronoiTriangulationPoint **triangulated_points_r, int *triangulated_points_total_r,
  54. int (**triangles_r)[3], int *triangles_total_r);
  55. #endif /* __BLI_VORONOI_H__ */