Changeset 8030
 Timestamp:
 Oct 10, 2010, 5:13:03 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/anuga_core/source/anuga/utilities/polygon_ext.c
r8029 r8030 315 315 316 316 317 int __ polygon_triangle_overlap(double* polygon,317 int __triangle_polygon_overlap(double* polygon, 318 318 double* triangle, 319 319 int polygon_number_of_vertices) 320 320 { 321 int i, ii, j, jj ;321 int i, ii, j, jj, A, B; 322 322 double p0_x, p0_y, p1_x, p1_y, pp_x, pp_y; 323 323 double t0_x, t0_y, t1_x, t1_y, tp_x, tp_y; … … 328 328 p0_x = polygon[0]; 329 329 p0_y = polygon[1]; 330 331 A = 0; 332 B = 0; 330 333 331 334 for (i = 1; i < polygon_number_of_vertices + 1; i++) … … 350 353 351 354 tp_x = (t1_y  t0_y); //perpendicular to triangle vector 352 tp_y = t1_x  t0_x; 355 tp_y = t1_x  t0_x; //perpendicular to polygon vector 353 356 354 357 u_x = p1_x  p0_x; … … 368 371 369 372 a = v_dot_tp/u_dot_tp; 370 b = v_dot_pp/w_dot_pp;371 372 if (a >= 0.0f && a <= 1.0f )373 b = v_dot_pp/w_dot_pp; 374 375 if (a >= 0.0f && a <= 1.0f && b >=0.0f && b <=1.0f) 373 376 { 374 377 return 1; //overlap 375 378 } 376 379 377 if (b >= 0.0f && b <= 1.0f) 380 if (b >= 0.0f && b <= 1.0f && a > 1.0f) 381 { 382 A++; 383 } 384 385 if (a >= 0.0f && a <= 1.0f && b > 1.0f) 386 { 387 B++; 388 } 389 390 if (A == 4  B == 3) 378 391 { 379 392 return 1; //overlap … … 391 404 return 0; //no overlap 392 405 } 393 406 407 408 int __polygon_overlap(double* polygon, 409 double* triangles, 410 long* indices, 411 int M, //number of triangles 412 int polygon_number_of_vertices) 413 { 414 double* triangle; 415 int i, inside_index, outside_index; 416 417 inside_index = 0; // Keep track of triangles that overlap 418 outside_index = M  1; // Keep track of triangles that don't overlap (starting from end) 419 420 for (i = 0; i < M; i++) 421 { 422 triangle = triangles + 6*i; 423 424 if (__triangle_polygon_overlap(polygon, 425 triangle, 426 polygon_number_of_vertices)) 427 { 428 indices[inside_index] = i; 429 inside_index++; 430 } 431 else 432 { 433 indices[outside_index] = i; 434 outside_index = 1; 435 } 436 } 437 438 return inside_index; 439 } 394 440 395 441 … … 654 700 655 701 656 PyObject *_polygon_triangle_overlap(PyObject *self, PyObject *args) { 702 PyObject *_polygon_overlap(PyObject *self, PyObject *args) 703 { 657 704 // 658 705 // _polygon_triangle_overlap(polygon, triangle) … … 662 709 PyArrayObject 663 710 *polygon, 664 *triangle; 711 *triangles, 712 *indices; 665 713 666 714 int res; … … 669 717 670 718 // Convert Python arguments to C 671 if (!PyArg_ParseTuple(args, "OO ",719 if (!PyArg_ParseTuple(args, "OOO", 672 720 &polygon, 673 &triangle)) { 721 &triangles, 722 &indices)) { 674 723 675 724 PyErr_SetString(PyExc_RuntimeError, … … 679 728 680 729 // Call underlying routine 681 res = __polygon_triangle_overlap((double*) polygon>data, 682 (double*) triangle > data, 730 res = __polygon_overlap((double*) polygon>data, 731 (double*) triangles>data, 732 (long*) indices>data, 733 (int) triangles>dimensions[0]/3, 683 734 (int) polygon>dimensions[0]); 684 735 … … 860 911 {"_interpolate_polyline", _interpolate_polyline, 861 912 METH_VARARGS, "Print out"}, 913 {"_polygon_overlap", _polygon_overlap, 914 METH_VARARGS, "Print out"}, 862 915 {"_is_inside_triangle", _is_inside_triangle, 863 916 METH_VARARGS, "Print out"}, … … 866 919 867 920 868 869 921 // Module initialisation 870 922 void initpolygon_ext(void){
Note: See TracChangeset
for help on using the changeset viewer.