36 #include <Structure.h>
42 #include <ServerFunctionsList.h>
73 const string wrong_args =
"Wrong number of arguments to bbox_union(). Expected one or more bounding boxes and a string naming the operation (2+ arguments)";
75 unsigned int rank = 0;
76 string operation =
"";
82 throw Error(malformed_expr, wrong_args);
90 for (
int i = 1; i < argc-1; ++i)
92 throw Error(malformed_expr,
"In function bbox_union(): All bounding boxes must be the same shape to form their union.");
94 operation = extract_string_argument(argv[argc-1]);
104 vector<slice> result(rank);
106 for (
unsigned int i = 0; i < rank; ++i) {
113 result.at(i).start = start;
114 result.at(i).stop = stop;
115 result.at(i).name = name;
119 for (
int i = 1; i < argc-1; ++i) {
121 Array *bbox =
static_cast<Array*
>(argv[i]);
123 for (
unsigned int i = 0; i < rank; ++i) {
129 if (result.at(i).name != name)
130 throw Error(
"In function bbox_union(): named dimensions must match in the bounding boxes");
132 if (operation ==
"union") {
133 result.at(i).start =
min(result.at(i).start, start);
134 result.at(i).stop =
max(result.at(i).stop, stop);
136 else if (operation ==
"inter" || operation ==
"intersection") {
137 result.at(i).start =
max(result.at(i).start, start);
138 result.at(i).stop =
min(result.at(i).stop, stop);
140 if (result.at(i).stop < result.at(i).start)
141 throw Error(
"In bbox_union(): The intersection of the bounding boxes is empty (dimension " + long_to_string(i) +
").");
144 throw Error(malformed_expr,
"In bbox_union(): Unknown operator '" + operation +
"'; expected 'union', 'intersection' or 'inter'.");
151 for (
unsigned int i = 0; i < rank; ++i) {
153 response->set_vec_nocopy(i, slice);
157 *btpp = response.release();
176 throw Error(malformed_expr,
"Not yet implemented for DAP4 functions.");
void roi_bbox_get_slice_data(Array *slices, unsigned int i, int &start, int &stop, string &name)
This method extracts values from one element of the Bounding Box (i.e., Array of Structures).
BaseType * function_dap4_bbox_union(D4RValueList *, DMR &)
Combine several bounding boxes, forming their union.
unsigned int roi_valid_bbox(BaseType *btp)
Is the bound box valid?
Structure * roi_bbox_build_slice(unsigned int start_value, unsigned int stop_value, const string &dim_name)
Build a single element of a bounding box.
static class NCMLUtil overview
auto_ptr< Array > roi_bbox_build_empty_bbox(unsigned int num_dim, const string &bbox_name)
Build an empty Bounding Box using DAP variables.
void function_dap2_bbox_union(int argc, BaseType *argv[], DDS &, BaseType **btpp)
Combine several bounding boxes, forming their union.