YetAnotherCoupler  2.4.2
Data Structures | Macros | Enumerations | Functions | Variables
clipping.c File Reference
#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"
Include dependency graph for clipping.c:

Go to the source code of this file.

Data Structures

struct  point_list_element
 
struct  point_list
 

Macros

#define NORM_TOL   (1e-6)
 

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_elementget_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_cellget_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.0e-12
 
static struct grid_celloverlap_cell_buffer = NULL
 
static size_t overlap_cell_buffer_size = 0
 

Detailed Description

Version
1.0
Author
Moritz Hanke hanke.nosp@m.@dkr.nosp@m.z.de Rene Redler rene..nosp@m.redl.nosp@m.er@mp.nosp@m.imet.nosp@m..mpg..nosp@m.de

Definition in file clipping.c.

Macro Definition Documentation

◆ NORM_TOL

#define NORM_TOL   (1e-6)

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ compute_lat_circle_z_value()

static void compute_lat_circle_z_value ( double  a[],
double  b[],
double  z[] 
)
static

Definition at line 319 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_norm_vector()

static void compute_norm_vector ( double  a[],
double  b[],
double  norm[] 
)
static

Definition at line 304 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_point_list()

static void copy_point_list ( struct point_list  in,
struct point_list out 
)
static

Definition at line 909 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dotproduct()

static double dotproduct ( double  a[],
double  b[] 
)
inlinestatic

Definition at line 285 of file clipping.c.

Here is the caller graph for this function:

◆ edge_has_zero_length()

static int edge_has_zero_length ( double *  a,
double *  b 
)
inlinestatic

Definition at line 166 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_point_list()

static void free_point_list ( struct point_list list)
static

Definition at line 1328 of file clipping.c.

Here is the caller graph for this function:

◆ generate_overlap_cell()

static void generate_overlap_cell ( struct point_list list,
struct grid_cell cell 
)
static
Todo:
test whether all points of the cell are on a single great circle --> empty cell

Definition at line 1392 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_point_list()

static size_t generate_point_list ( struct point_list list,
struct grid_cell  cell 
)
static

Definition at line 1268 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cell_points_ordering()

static int get_cell_points_ordering ( struct point_list cell)
static

Definition at line 1135 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cell_type()

static enum yac_cell_type get_cell_type ( struct grid_cell  target_cell)
static

Definition at line 367 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_free_point_list_element()

static struct point_list_element * get_free_point_list_element ( struct point_list list)
static

Definition at line 1300 of file clipping.c.

Here is the caller graph for this function:

◆ get_overlap_cell_buffer()

static struct grid_cell* get_overlap_cell_buffer ( size_t  N)
inlinestatic

Definition at line 118 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_point_list()

static void init_point_list ( struct point_list list)
static

Definition at line 1163 of file clipping.c.

Here is the caller graph for this function:

◆ is_empty_gc_cell()

static int is_empty_gc_cell ( struct point_list list,
size_t  num_edges 
)
static

Definition at line 1350 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_inside()

static int is_inside ( double  point[],
double  help_vec[],
enum yac_edge_type  edge_type,
int  cell_points_ordering 
)
static
Examples
test_point_in_cell.c.

Definition at line 367 of file clipping.c.

Here is the caller graph for this function:

◆ is_inside_gc()

static int is_inside_gc ( double  point[],
double  norm_vec[] 
)
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.

Parameters
[in]pointpoint to be checked
[in]norm_vecnorm vector of the plane dividing the sphere
Returns
0 if the point is not inside the hemisphere 1 if the point is inside the hemisphere 2 if the point is in the plane

Definition at line 344 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_inside_latc()

static int is_inside_latc ( double  point[],
double  z 
)
static

Definition at line 359 of file clipping.c.

Here is the caller graph for this function:

◆ point_list_clipping()

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

cell clipping using Sutherland-Hodgman algorithm;

Definition at line 434 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_points()

static size_t remove_points ( struct point_list list)
static

Definition at line 1181 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_zero_length_edges()

static size_t remove_zero_length_edges ( struct point_list list)
static

returns number of edges/corners

Definition at line 1237 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_point_list()

static void reset_point_list ( struct point_list list)
static

Definition at line 1169 of file clipping.c.

Here is the caller graph for this function:

◆ yac_cell_clipping()

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.

Parameters
[in]Nnumber of source cells
[in]source_celllist of source cells
[in]target_celltarget cell
[in]overlap_bufferbuffer for the overlaps between the target and the source cells
Remarks
source and target cells have to be convex
cells in overlap_buffer can be concave
overlap_buffer must contain valid grid_cells (have to be initialised using yac_init_grid_cell; initialisation have to be done only once, in consecutive calls, the cells can be reused with have to be reinitialised)
Examples
test_area.c, and test_clipping.c.

Definition at line 934 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_compute_concave_overlap_areas()

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.

Parameters
[in]Nnumber of source cells
[in]source_celllist of source cells
[in]target_celltarget cell
[in]target_node_xyzcartesian coordinate of target cell node or center point
[out]partial_areaslist of N partial weights, one weight for each source-target intersection
Remarks
source and target cell have to be convex
Examples
test_compute_overlap_area.c.

Definition at line 292 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_compute_concave_overlap_info()

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.

Parameters
[in]Nnumber of source cells
[in]source_celllist of source cells
[in]target_celltarget cell
[in]target_node_xyzcartesian coordinate of target cell node or center point
[out]overlap_areaslist of N partial weights, one weight for each source-target intersection
[out]overlap_barycenterscoordinates of the barycenters of the overlap cell
Remarks
source and target cell have to be convex
Examples
test_partial_areas.c.

Definition at line 170 of file clipping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_compute_overlap_areas()

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.

Parameters
[in]Nnumber of source cells
[in]source_celllist of source cells
[in]target_celltarget cell
[out]partial_areaslist of N partial weights, one weight for each source-target intersection
Remarks
source and target cell have to be convex
Examples
test_compute_overlap_area.c, and test_partial_areas.c.

Definition at line 138 of file clipping.c.

Here is the call graph for this function:

◆ yac_correct_weights()

void yac_correct_weights ( size_t  N,
double *  weight 
)

correct interpolation weights

Returns weights with a sum close to 1.0

Parameters
[in]Nnumber of source cells
[out]weightlist of N partial weights
Examples
test_partial_areas.c.

Definition at line 1097 of file clipping.c.

Here is the caller graph for this function:

Variable Documentation

◆ overlap_cell_buffer

struct grid_cell* overlap_cell_buffer = NULL
static

Definition at line 115 of file clipping.c.

◆ overlap_cell_buffer_size

size_t overlap_cell_buffer_size = 0
static

Definition at line 116 of file clipping.c.

◆ tol

double const tol = 1.0e-12
static

Definition at line 65 of file clipping.c.