/[zanavi_public1]/navit/navit/maptool/refine/mesh.h
ZANavi

Contents of /navit/navit/maptool/refine/mesh.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 2 months ago) by zoff99
File MIME type: text/plain
File size: 14249 byte(s)
new map version, lots of fixes and experimental new features
1 /*
2 * This file is a part of Poly2Tri-C
3 * (c) Barak Itkin <lightningismyname@gmail.com>
4 * http://code.google.com/p/poly2tri-c/
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * * Neither the name of Poly2Tri nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without specific
18 * prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef __P2TC_REFINE_MESH_H__
34 #define __P2TC_REFINE_MESH_H__
35
36 #include <glib.h>
37 #include "vector2.h"
38 #include "utils.h"
39 #include "triangulation.h"
40
41 /**
42 * \defgroup P2trMesh P2trMesh - Triangular Meshes
43 * The library is designed to handle triangular meshes which are made
44 * of one continuous region, potentially with holes
45 * @{
46 */
47
48 /**
49 * A struct for representing a triangular mesh
50 */
51 struct P2trMesh_
52 {
53 /**
54 * A hash set containing pointers to all the triangles
55 * (\ref P2trTriangle) in the mesh
56 */
57 P2trHashSet *triangles;
58
59 /**
60 * A hash set containing pointers to all the edges (\ref P2trEdge) in
61 * the mesh
62 */
63 P2trHashSet *edges;
64
65 /**
66 * A hash set containing pointers to all the points (\ref P2trPoint)
67 * in the mesh
68 */
69 P2trHashSet *points;
70
71 /**
72 * A boolean flag specifying whether recording of actions on the
73 * mesh (for allowing to undo them) is taking place right now
74 */
75 gboolean record_undo;
76
77 /**
78 * A queue stroing all the actions done on the mesh since the begining
79 * of the recording
80 */
81 GQueue undo;
82
83 /**
84 * Counts the amount of references to the mesh. When this counter
85 * reaches zero, the mesh will be freed
86 */
87 guint refcount;
88 };
89
90 /**
91 * Create a new empty mesh
92 * @return The newly created mesh
93 */
94 P2trMesh* p2tr_mesh_new (void);
95
96 /**
97 * Add an existing point to the given mesh
98 * @param self The mesh to add the point to
99 * @param point The point to add
100 * @return The given point
101 */
102 P2trPoint* p2tr_mesh_add_point (P2trMesh *self,
103 P2trPoint *point);
104
105 /**
106 * Create a new point and add it to the given mesh
107 * @param mesh The mesh to add the point to
108 * @param c The coordinates of the point to create
109 * @return The newly created point
110 */
111 P2trPoint* p2tr_mesh_new_point (P2trMesh *mesh,
112 const P2trVector2 *c);
113
114 /**
115 * Create a new point and add it to the given mesh
116 * @param mesh The mesh to add the point to
117 * @param x The X coordinate of the point to create
118 * @param y The Y coordinate of the point to create
119 * @return The newly created point
120 */
121 P2trPoint* p2tr_mesh_new_point2 (P2trMesh *mesh,
122 gdouble x,
123 gdouble y);
124
125 /**
126 * Add an existing edge to the given mesh
127 * @param self The mesh to add the edge to
128 * @param edge The edge to add
129 * @return The given edge
130 */
131 P2trEdge* p2tr_mesh_add_edge (P2trMesh *self,
132 P2trEdge *point);
133
134 /**
135 * Create a new edge and add it to the given mesh
136 * @param mesh The mesh to add the edge to
137 * @param start The starting point of the edge
138 * @param end The ending point of the edge
139 * @param constrained Specify whether this edge is constrained or not
140 * @return Thew newly created edge
141 */
142 P2trEdge* p2tr_mesh_new_edge (P2trMesh *mesh,
143 P2trPoint *start,
144 P2trPoint *end,
145 gboolean constrained);
146
147 /**
148 * This function checks if an edge between two points exists, and if
149 * not it creates it. In both cases the returned edge will be returned
150 * with an extra reference, so it must be unreffed later.
151 * @param self The mesh of the returned edge
152 * @param start The starting point of the returned edge
153 * @param end The ending point of the returned edge
154 * @param constrained Specify whether this edge should be constrained
155 * or not (in case a new edge is created)
156 * @return An edge between the two points
157 */
158 P2trEdge* p2tr_mesh_new_or_existing_edge (P2trMesh *self,
159 P2trPoint *start,
160 P2trPoint *end,
161 gboolean constrained);
162
163 /**
164 * Add an existing triangle to the given mesh
165 * @param self The mesh to add the triangle to
166 * @param edge The triangle to add
167 * @return The given triangle
168 */
169 P2trTriangle* p2tr_mesh_add_triangle (P2trMesh *self,
170 P2trTriangle *tri);
171
172 /**
173 * Create a new triangle and add it to the given mesh
174 * @param mesh The mesh to add the triangle to
175 * @param AB An edge from the first point of the triangle to the second
176 * @param BC An edge from the second point of the triangle to the third
177 * @param CA An edge from the third point of the triangle to the first
178 */
179 P2trTriangle* p2tr_mesh_new_triangle (P2trMesh *mesh,
180 P2trEdge *AB,
181 P2trEdge *BC,
182 P2trEdge *CA);
183
184 /** \internal
185 * This function should be called just before a point is removed from
186 * the mesh. It is used internally to update the mesh and it should not
187 * be called by any code outside of this library.
188 * @param mesh The mesh from which the point is going to be removed
189 * @param point The point which is going to be removed
190 */
191 void p2tr_mesh_on_point_removed (P2trMesh *mesh,
192 P2trPoint *point);
193
194 /** \internal
195 * This function should be called just before an edge is removed from
196 * the mesh. It is used internally to update the mesh and it should not
197 * be called by any code outside of this library.
198 * @param mesh The mesh from which the edge is going to be removed
199 * @param edge The edge which is going to be removed
200 */
201 void p2tr_mesh_on_edge_removed (P2trMesh *mesh,
202 P2trEdge *edge);
203
204 /** \internal
205 * This function should be called just before a triangle is removed from
206 * the mesh. It is used internally to update the mesh and it should not
207 * be called by any code outside of this library.
208 * @param mesh The mesh from which the triangle is going to be removed
209 * @param triangle The triangle which is going to be removed
210 */
211 void p2tr_mesh_on_triangle_removed (P2trMesh *mesh,
212 P2trTriangle *triangle);
213
214 /**
215 * Begin recording all action performed on a mesh. Recording the
216 * actions performed on a mesh allows choosing later whether to commit
217 * those actions or whether they should be undone.
218 * \warning This function must not be called when recording is already
219 * taking place!
220 * @param self The mesh whose actions should be recorded
221 */
222 void p2tr_mesh_action_group_begin (P2trMesh *self);
223
224 /**
225 * Terminate the current session of recording mesh actions by
226 * committing all the actions to the mesh
227 * \warning This function must not be called unless recording of
228 * actions is already taking place!
229 * @param self The mesh whose actions were recorded
230 */
231 void p2tr_mesh_action_group_commit (P2trMesh *self);
232
233 /**
234 * Terminate the current session of recording mesh actions by
235 * undoing all the actions done to the mesh.
236 * \warning This function must not be called unless recording of
237 * actions is already taking place!
238 * \warning A call to this function may invalidate all references to
239 * any non virtual geometric primitives! If you plan on using
240 * this function, consider using virtual data structures!
241 * @param self The mesh whose actions were recorded
242 */
243 void p2tr_mesh_action_group_undo (P2trMesh *self);
244
245 /**
246 * Remove all triangles, edges and points from a mesh
247 * @param mesh The mesh to clear
248 */
249 void p2tr_mesh_clear (P2trMesh *mesh);
250
251 /**
252 * Clear and then free the memory used by a mesh data structure
253 * @param mesh The mesh whose memory should be freed
254 */
255 void p2tr_mesh_free (P2trMesh *mesh);
256
257 /**
258 * Decrease the reference count to this mesh by 1
259 * @param mesh The mesh whose reference count should be decreased
260 */
261 void p2tr_mesh_unref (P2trMesh *mesh);
262
263 /**
264 * Increase the reference count to this mesh by 1
265 * @param mesh The mesh whose reference count should be increased
266 * @return The given mesh (\ref mesh)
267 */
268 P2trMesh* p2tr_mesh_ref (P2trMesh *mesh);
269
270 /**
271 * Find a triangle of the mesh, containing the point at the given
272 * location
273 * @param self The mesh whose triangles should be checked
274 * @param pt The location of the point to test
275 * @return The triangle containing the given point, or NULL if the
276 * point is outside the triangulation domain
277 */
278 P2trTriangle* p2tr_mesh_find_point (P2trMesh *self,
279 const P2trVector2 *pt);
280
281 /**
282 * Exactly like \ref p2tr_mesh_find_point, except for the fact that
283 * this variant also returns the UV coordinates of the point inside the
284 * triangle
285 * @param[in] self The mesh whose triangles should be checked
286 * @param[in] pt The location of the point to test
287 * @param[out] u The U coordinate of the point inside the triangle
288 * @param[out] v The V coordinate of the point inside the triangle
289 * @return The triangle containing the given point, or NULL if the
290 * point is outside the triangulation domain
291 */
292 P2trTriangle* p2tr_mesh_find_point2 (P2trMesh *self,
293 const P2trVector2 *pt,
294 gdouble *u,
295 gdouble *v);
296
297 /**
298 * Another variant of \ref p2tr_mesh_find_point taking an initial
299 * triangle that the search should begin from its area. The search is
300 * performed first on triangles close to the given triangle, and it
301 * gradually tests farther and farther triangles until it finds the one
302 * containing the given point.
303 *
304 * This way of search should be fast when the approximate area of the
305 * point to find is known, but it will be slower if initial triangle
306 * is not near.
307 *
308 * Note that in this function, triangles are considered near depending
309 * on the length of the chain of neighbor triangles needed to go from
310 * one to the other.
311 *
312 * \warning This function may use memory which is at least linear in
313 * the amount of triangles to test. Therefor, do not use it
314 * on large mesh objects unless the initial guess is supposed
315 * to be good!
316 * @param self The mesh whose triangles should be checked
317 * @param pt The location of the point to test
318 * @param initial_guess An initial guess for which triangle contains
319 * the point, or is at least near the triangle containing it
320 * @return The triangle containing the given point, or NULL if the
321 * point is outside the triangulation domain
322 */
323 P2trTriangle* p2tr_mesh_find_point_local (P2trMesh *self,
324 const P2trVector2 *pt,
325 P2trTriangle *initial_guess);
326
327 /**
328 * Exactly like \ref p2tr_mesh_find_point_local, except for the fact
329 * that this variant also returns the UV coordinates of the point
330 * inside the triangle
331 * @param[in] self The mesh whose triangles should be checked
332 * @param[in] pt The location of the point to test
333 * @param[in] initial_guess An initial guess for which triangle
334 * contains the point, or is at least near the triangle
335 * containing it
336 * @param[out] u The U coordinate of the point inside the triangle
337 * @param[out] v The V coordinate of the point inside the triangle
338 * @return The triangle containing the given point, or NULL if the
339 * point is outside the triangulation domain
340 */
341 P2trTriangle* p2tr_mesh_find_point_local2 (P2trMesh *self,
342 const P2trVector2 *pt,
343 P2trTriangle *initial_guess,
344 gdouble *u,
345 gdouble *v);
346
347 /**
348 * Find the bounding rectangle containing this mesh.
349 * @param[in] self The mesh whose bounding rectangle should be computed
350 * @param[out] min_x The minimal X coordinate of the mesh
351 * @param[out] min_y The minimal Y coordinate of the mesh
352 * @param[out] max_x The maximal X coordinate of the mesh
353 * @param[out] max_y The maximal Y coordinate of the mesh
354 */
355 void p2tr_mesh_get_bounds (P2trMesh *self,
356 gdouble *min_x,
357 gdouble *min_y,
358 gdouble *max_x,
359 gdouble *max_y);
360 /** @} */
361 #endif

   
Visit the ZANavi Wiki