LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2VoronoiDiagram.h
1 /*
2 * Copyright (c) 2013 Google, Inc.
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 #ifndef B2_VORONOI_DIAGRAM
19 #define B2_VORONOI_DIAGRAM
20 
21 #include <Box2D/Common/b2Math.h>
22 
23 class b2StackAllocator;
24 struct b2AABB;
25 
28 {
29 
30 public:
31 
32  b2VoronoiDiagram(b2StackAllocator* allocator, int32 generatorCapacity);
34 
39  void AddGenerator(const b2Vec2& center, int32 tag, bool necessary);
40 
45  void Generate(float32 radius, float32 margin);
46 
49  {
50  public:
51  virtual ~NodeCallback() {}
53  virtual void operator()(int32 a, int32 b, int32 c) = 0;
54  };
55 
58  void GetNodes(NodeCallback& callback) const;
59 
60 private:
61 
62  struct Generator
63  {
64  b2Vec2 center;
65  int32 tag;
66  bool necessary;
67  };
68 
69  struct b2VoronoiDiagramTask
70  {
71  int32 m_x, m_y, m_i;
72  Generator* m_generator;
73 
74  b2VoronoiDiagramTask() {}
75  b2VoronoiDiagramTask(int32 x, int32 y, int32 i, Generator* g)
76  {
77  m_x = x;
78  m_y = y;
79  m_i = i;
80  m_generator = g;
81  }
82  };
83 
84  b2StackAllocator *m_allocator;
85  Generator* m_generatorBuffer;
86  int32 m_generatorCapacity;
87  int32 m_generatorCount;
88  int32 m_countX, m_countY;
89  Generator** m_diagram;
90 
91 };
92 
93 #endif
void AddGenerator(const b2Vec2 &center, int32 tag, bool necessary)
Definition: b2VoronoiDiagram.cpp:45
Definition: b2StackAllocator.h:37
virtual void operator()(int32 a, int32 b, int32 c)=0
Receive tags for generators associated with a node.
A field representing the nearest generator from each point.
Definition: b2VoronoiDiagram.h:27
Callback used by GetNodes().
Definition: b2VoronoiDiagram.h:48
An axis aligned bounding box.
Definition: b2Collision.h:162
void Generate(float32 radius, float32 margin)
Definition: b2VoronoiDiagram.cpp:55
A 2D column vector.
Definition: b2Math.h:56
void GetNodes(NodeCallback &callback) const
Definition: b2VoronoiDiagram.cpp:195