Example #1
0
/*!
 * \param[in] d   Neighborhood search data structure.
 * \param[in] x   Test position.
 * \returns   The distance to the nearest reference position, or the cutoff
 *   value if there are no reference positions within the cutoff.
 */
real
gmx_ana_nbsearch_mindist(gmx_ana_nbsearch_t *d, rvec x)
{
    real mind;

    grid_search_start(d, x);
    grid_search(d, &mindist_action);
    mind       = sqrt(d->cutoff2);
    d->cutoff2 = sqr(d->cutoff);
    return mind;
}
Example #2
0
/*!
 * \param[in]  d   Neighborhood search data structure.
 * \param[out] jp  Index of the test position in the next pair.
 * \returns    TRUE if there are positions within the cutoff.
 */
gmx_bool
gmx_ana_nbsearch_next_within(gmx_ana_nbsearch_t *d, int *jp)
{
    if (grid_search(d, &within_action))
    {
        *jp = d->previ;
        return TRUE;
    }
    *jp = -1;
    return FALSE;
}
Example #3
0
bool compute_roof_non_connected_routing(struct flow_struct* _flow_table,
		int _num_patches, PatchTable_t *_patchTable,
		roof_geometry_t* _roof_geometry, const double* _roofs,
		const int* _impervious, const int* _patch, const int* _hill,
		const int* _zone, int _maxr, int _maxc) {
	bool result = true;

	// check input parameters
	if (_flow_table == 0) {
		fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
		result = false;
	} else if (_roof_geometry == 0) {
		fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
		result = false;
	} else if (_roofs == 0) {
		fprintf(stderr, "ERROR: Roof values pointer is NULL.\n");
		result = false;
	} else if (_impervious == 0) {
		fprintf(stderr, "ERROR: Impervious surface pointer is NULL.\n");
		result = false;
	} else {

		// make an impervious surface search context
		void* pervious_search_context;
		if (!pervious_make_context(_maxr, _maxc, _roofs, _impervious,
				&pervious_search_context)) {
			fprintf(stderr,
					"ERROR: Failed to make impervious surface search context.\n");
			result = false;
		} else {

			// loop over all of the roof squares in the roof geometry
			roof_square_t* roof_square = 0;
			if (!roof_geometry_squares(_roof_geometry, &roof_square)) {
				fprintf(stderr,
						"ERROR: Failed to retrieve the list of squares from the roof geometry.\n");
				result = false;
			} else {
				while (result && roof_square != 0) {
					int found_row = 0;
					int found_col = 0;
					bool found = false;
					int row = 0;
					int col = 0;
					if (!roof_square_row(roof_square, &row)) {
						fprintf(stderr,
								"ERROR: Failed to get the row from the roof square.\n");
						result = false;
					} else if (!roof_square_col(roof_square, &col)) {
						fprintf(stderr,
								"ERROR: Failed to get the column from the roof square.\n");
						result = false;
					} else if (!roof_square_next(roof_square, &roof_square)) {
						fprintf(stderr,
								"ERROR: Failed to get the next pointer from the roof square.\n");
						result = false;
					}
					// search for the nearest impervious surface to the roof square
					else if (!grid_search(NEAREST_NEIGHBOR_GRID_SEARCH_MAX_DIST, row, col,
							pervious_search_predicate, pervious_search_context,
							&found_row, &found_col, &found)) {
						fprintf(stderr,
								"ERROR: compute_non_connected: an error occurred while searching for the nearest impervious grid square.\n");
						result = false;
					} else {
						if (found) {
							// Here lies the sciences
							int index;
							if (!row_col_to_index(row, col, _maxr, _maxc,
									&index)) {
								fprintf(stderr,
										"ERROR: Failed to map row: %d, column: %d to an index.\n",
										row, col);
								result = false;
							}
							// The entry in the roofs table is the proportion that goes to impervious surfaces. Since this is the
							// pervious surfaces we need 1 - the roofs table value
							else if (!add_flow_to_table(row, col, found_row,
									found_col, _maxr, _maxc, _flow_table,
									_num_patches, _patchTable, _patch, _hill,
									_zone, 1.0 - _roofs[index])) {
								fprintf(stderr,
										"ERROR: Failed to add the roof flow to the flow table.\n");
								result = false;
							}
						} else {
							fprintf(stderr,
									"WARNING: No pervious surface found for square row: %d, column %d.\n",
									row, col);
						}
					}
				}
			}
		}
	}

	return result;
}
Example #4
0
/*!
 * \param[in] d   Neighborhood search data structure.
 * \param[in] x   Test position.
 * \returns   TRUE if \p x is within the cutoff of any reference position,
 *   FALSE otherwise.
 */
gmx_bool
gmx_ana_nbsearch_is_within(gmx_ana_nbsearch_t *d, rvec x)
{
    grid_search_start(d, x);
    return grid_search(d, &within_action);
}