/* *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* */ /* ** Copyright UCAR (c) 1990 - 2016 */ /* ** University Corporation for Atmospheric Research (UCAR) */ /* ** National Center for Atmospheric Research (NCAR) */ /* ** Boulder, Colorado, USA */ /* ** BSD licence applies - redistribution and use in source and binary */ /* ** forms, with or without modification, are permitted provided that */ /* ** the following conditions are met: */ /* ** 1) If the software is modified to produce derivative works, */ /* ** such modified software should be clearly marked, so as not */ /* ** to confuse it with the version available from UCAR. */ /* ** 2) Redistributions of source code must retain the above copyright */ /* ** notice, this list of conditions and the following disclaimer. */ /* ** 3) Redistributions in binary form must reproduce the above copyright */ /* ** notice, this list of conditions and the following disclaimer in the */ /* ** documentation and/or other materials provided with the distribution. */ /* ** 4) Neither the name of UCAR nor the names of its contributors, */ /* ** if any, may be used to endorse or promote products derived from */ /* ** this software without specific prior written permission. */ /* ** DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS */ /* ** OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ /* ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* */ /* * NAME * bdry_graph.c * * PURPOSE * * Build a graph consisting of the boundary points of a clump. This * graph will demonstrate the connections between such boundary points * and hence can be used to find the boundary of the clump. The function * bdry_graph outputs a number of boundary nodes containing the graph * information. * * * * NOTES * * * HISTORY * wiener - May 11, 1992: Created. */ /* includes */ #include #include #include #include static void merge_lists(int *top_list, int top_size, int *bot_list, int bot_size, Node *node); static void set_node_list(Node *node, int node_ct, int dir, int bit, int value); /* * DESCRIPTION: * This function builds a graph consisting of the boundary nodes * of a clump of intervals. * * INPUTS: * row_hdr - interval control block * rowh_dim - dimension of row_hdr * num_cols - number of columns in a row * num_nodes - size of output array node * clump_id - If 0, all intervals from row_hdr are used in * determining the boundary. If greater than 0, only those intervals * having id == clump_id will be used in determining the boundary. * * OUTPUTS: * node - array of boundary points for clump * * RETURNS: * 0 if successful, -1 on memory allocation failure * * METHOD: * 1. Determine rectangles for all intervals by adjusting interval * endpoints using OFFSET_X in x and OFFSET_Y in y. * * 2. Build a boundary edge graph using the information in 2. * * Note that another function is used to do a depth first search of * the boundary edge graph in 2) in order to determine the actual * boundary boundary of the clump. * * NOTES: * This function assumes that the input intervals belong to one * clump. One can call EG_rclump_2d() or a related function to do the * clumping. Such functions set the id in the interval structure to the * appropriate clump_id. This is required since the function merge_lists * used below tacitly assumes that the boundary points all belong to one * clump. The x and y values for a node are derived from the original x * and y values for the parent interval. */ int EG_bdry_graph(Row_hdr *row_hdr, int rowh_dim, int num_cols, Node *node, int num_nodes, int clump_id) { float bottom; int i; int j; float left; int *list; int list_ct = 0; int list_size; int *next_list; int next_list_ct = 0; int node_ct = 0; int *previous_list; int previous_list_ct = 0; float right; int *temp_list; float top; list_size = 2*num_cols; /* max number of corner pts on a line */ /* allocate memory for list, next_list, previous_list */ list = EG_malloc(list_size*sizeof(int)); next_list = EG_malloc(list_size*sizeof(int)); previous_list = EG_malloc(list_size*sizeof(int)); if (list == NULL || next_list == NULL || previous_list == NULL) return(-1); /* initialize list counts to 0 */ list_ct = 0; next_list_ct = 0; previous_list_ct = 0; /* initialize the node adjacency list to -1 */ for (i=0; i