YetAnotherCoupler
2.4.2

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "geometry.h"
#include "clipping.h"
#include "area.h"
#include "ensure_array_size.h"
#include "utils.h"
Go to the source code of this file.
Data Structures  
struct  point_list_element 
struct  point_list 
Macros  
#define  NORM_TOL (1e6) 
Enumerations  
enum  intersect_results { P_ON_A = 1 , Q_ON_A = 2 , P_ON_B = 4 , Q_ON_B = 8 , SAME_PLANE = 16 } 
Functions  
static void  init_point_list (struct point_list *list) 
static void  reset_point_list (struct point_list *list) 
static size_t  generate_point_list (struct point_list *list, struct grid_cell cell) 
static struct point_list_element *  get_free_point_list_element (struct point_list *list) 
static size_t  remove_points (struct point_list *list) 
static size_t  remove_zero_length_edges (struct point_list *list) 
returns number of edges/corners More...  
static void  free_point_list (struct point_list *list) 
static int  get_cell_points_ordering (struct point_list *cell) 
static void  generate_overlap_cell (struct point_list *list, struct grid_cell *cell) 
static enum yac_cell_type  get_cell_type (struct grid_cell target_cell) 
static struct grid_cell *  get_overlap_cell_buffer (size_t N) 
void  yac_compute_overlap_areas (size_t N, struct grid_cell *source_cell, struct grid_cell target_cell, double *partial_areas) 
calculates partial areas for all overlapping parts of the source cells with triangular target cells. This is required for conservative remapping More...  
static int  edge_has_zero_length (double *a, double *b) 
void  yac_compute_concave_overlap_info (size_t N, struct grid_cell *source_cell, struct grid_cell target_cell, double target_node_xyz[3], double *overlap_areas, double(*overlap_barycenters)[3]) 
calculates partial areas for all overlapping parts of the source cells with arbitrary target cells, this is required for conservative remapping. In addition, the barycenter of each overlap is calculated. More...  
static double  dotproduct (double a[], double b[]) 
void  yac_compute_concave_overlap_areas (size_t N, struct grid_cell *source_cell, struct grid_cell target_cell, double target_node_xyz[3], double *partial_areas) 
calculates partial areas for all overlapping parts of the source cells with arbitrary target cells, this is required for conservative remapping. More...  
static void  compute_norm_vector (double a[], double b[], double norm[]) 
static void  compute_lat_circle_z_value (double a[], double b[], double z[]) 
static int  is_inside_gc (double point[], double norm_vec[]) 
static int  is_inside_latc (double point[], double z) 
static int  is_inside (double point[], double help_vec[], enum yac_edge_type edge_type, int cell_points_ordering) 
static void  point_list_clipping (struct point_list *source_list, int source_ordering, struct point_list target_list, int target_ordering, size_t nct, double *tgt_edge_norm_vec) 
static void  copy_point_list (struct point_list in, struct point_list *out) 
void  yac_cell_clipping (size_t N, struct grid_cell *source_cell, struct grid_cell target_cell, struct grid_cell *overlap_buffer) 
cell clipping to get the cells describing the intersections More...  
void  yac_correct_weights (size_t nSourceCells, double *weight) 
correct interpolation weights More...  
static int  is_empty_gc_cell (struct point_list *list, size_t num_edges) 
Variables  
static double const  tol = 1.0e12 
static struct grid_cell *  overlap_cell_buffer = NULL 
static size_t  overlap_cell_buffer_size = 0 
Definition in file clipping.c.
#define NORM_TOL (1e6) 
enum intersect_results 
Enumerator  

P_ON_A  
Q_ON_A  
P_ON_B  
Q_ON_B  
SAME_PLANE 
Definition at line 67 of file clipping.c.

static 
Definition at line 319 of file clipping.c.

static 
Definition at line 304 of file clipping.c.

static 
Definition at line 909 of file clipping.c.

inlinestatic 

inlinestatic 
Definition at line 166 of file clipping.c.

static 

static 
Definition at line 1392 of file clipping.c.

static 
Definition at line 1268 of file clipping.c.

static 
Definition at line 1135 of file clipping.c.

static 
Definition at line 367 of file clipping.c.

static 

inlinestatic 
Definition at line 118 of file clipping.c.

static 

static 
Definition at line 1350 of file clipping.c.

static 
Definition at line 367 of file clipping.c.

static 
Determines whether a given point is on a hemisphere that is defined by a plane through the middle of the sphere.
The plane is defined by its norm vector.
[in]  point  point to be checked 
[in]  norm_vec  norm vector of the plane dividing the sphere 
Definition at line 344 of file clipping.c.

static 

static 
cell clipping using SutherlandHodgman algorithm;
Definition at line 434 of file clipping.c.

static 
Definition at line 1181 of file clipping.c.

static 
returns number of edges/corners
Definition at line 1237 of file clipping.c.

static 
void yac_cell_clipping  (  size_t  N, 
struct grid_cell *  source_cell,  
struct grid_cell  target_cell,  
struct grid_cell *  overlap_buffer  
) 
cell clipping to get the cells describing the intersections
The routine takes (a list of) source cells and a target cell. It sets the target cell data and does some further initialisation. Thus it needs to be called for each new target cell intersection calculation
The vertices of source and target cells can be either provided in a clockwise or anticlockwise sense. However, the same sense must be used for source and target cells.
[in]  N  number of source cells 
[in]  source_cell  list of source cells 
[in]  target_cell  target cell 
[in]  overlap_buffer  buffer for the overlaps between the target and the source cells 
Definition at line 934 of file clipping.c.
void yac_compute_concave_overlap_areas  (  size_t  N, 
struct grid_cell *  source_cell,  
struct grid_cell  target_cell,  
double  target_node_xyz[3],  
double *  partial_areas  
) 
calculates partial areas for all overlapping parts of the source cells with arbitrary target cells, this is required for conservative remapping.
Some of the underlying concepts can be found in
See e.g. Joseph O'Rourke, Computational Geometry in C, 2nd Ed., 1998 Sec. 7.6 Intersections of Convex Polygons, page 253.
The routine takes (a list of) source cells and a target cell. It determines the clipping points of the intersection between a source and the target cells using cell_clipping internally. In a second step areas are calculated for each intersection described in the overlap cells. If a target cell is fully covered by N source cells the N partial areas should add up to the area of the target cell.
[in]  N  number of source cells 
[in]  source_cell  list of source cells 
[in]  target_cell  target cell 
[in]  target_node_xyz  cartesian coordinate of target cell node or center point 
[out]  partial_areas  list of N partial weights, one weight for each sourcetarget intersection 
Definition at line 292 of file clipping.c.
void yac_compute_concave_overlap_info  (  size_t  N, 
struct grid_cell *  source_cell,  
struct grid_cell  target_cell,  
double  target_node_xyz[3],  
double *  overlap_areas,  
double(*)  overlap_barycenters[3]  
) 
calculates partial areas for all overlapping parts of the source cells with arbitrary target cells, this is required for conservative remapping. In addition, the barycenter of each overlap is calculated.
Some of the underlying concepts can be found in
See e.g. Joseph O'Rourke, Computational Geometry in C, 2nd Ed., 1998 Sec. 7.6 Intersections of Convex Polygons, page 253.
The routine takes (a list of) source cells and a target cell. It determines the clipping points of the intersection between a source and the target cells using cell_clipping internally. In a second step areas are calculated for each intersection described in the overlap cells. If a target cell is fully covered by N source cells the N partial areas should add up to the area of the target cell.
[in]  N  number of source cells 
[in]  source_cell  list of source cells 
[in]  target_cell  target cell 
[in]  target_node_xyz  cartesian coordinate of target cell node or center point 
[out]  overlap_areas  list of N partial weights, one weight for each sourcetarget intersection 
[out]  overlap_barycenters  coordinates of the barycenters of the overlap cell 
Definition at line 170 of file clipping.c.
void yac_compute_overlap_areas  (  size_t  N, 
struct grid_cell *  source_cell,  
struct grid_cell  target_cell,  
double *  partial_areas  
) 
calculates partial areas for all overlapping parts of the source cells with triangular target cells. This is required for conservative remapping
Some of the underlying concepts can be found in
See e.g. Joseph O'Rourke, Computational Geometry in C, 2nd Ed., 1998 Sec. 7.6 Intersections of Convex Polygons, page 253.
The routine takes (a list of) source cells and a convex target cell. As a triangle is always convex we recommend to use this routine only for triangular target cells. It determines the clipping points of the intersection between a source and the target cells using cell_clipping internally. In a second step areas are calculated for each intersection described in the overlap cells. If a target cell is fully covered by N source cells the N partial areas should add up to the area of the target cell.
[in]  N  number of source cells 
[in]  source_cell  list of source cells 
[in]  target_cell  target cell 
[out]  partial_areas  list of N partial weights, one weight for each sourcetarget intersection 
Definition at line 138 of file clipping.c.
void yac_correct_weights  (  size_t  N, 
double *  weight  
) 
correct interpolation weights
Returns weights with a sum close to 1.0
[in]  N  number of source cells 
[out]  weight  list of N partial weights 
Definition at line 1097 of file clipping.c.

static 
Definition at line 115 of file clipping.c.

static 
Definition at line 116 of file clipping.c.

static 
Definition at line 65 of file clipping.c.