rasdaman complete source
minterval.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
33 #ifndef _D_MINTERVAL_
34 #define _D_MINTERVAL_
35 
36 #include <iostream>
37 #include <vector>
38 using std::endl;
39 using std::vector;
40 
41 #ifdef __VISUALC__
42 // Diable warning for exception specification.
43 #pragma warning( disable : 4290 )
44 #include <strstrea.h>
45 #else
46 #include <sstream> // for istrstream
47 #endif
48 
49 class r_Edim_mismatch;
50 class r_Error;
51 class r_Einit_overflow;
52 class r_Eno_interval;
53 class r_Eno_cell;
54 class r_Error;
55 
56 
57 #include "raslib/sinterval.hh"
58 #include "raslib/point.hh"
59 
60 //@ManMemo: Module: {\bf raslib}
61 
62 /*@Doc:
63 
64  The spatial domain of an MDD is represented by an object
65  of class \Ref{r_Minterval}. It specifies lower and upper bound
66  of the point set for each dimension of an MDD. Internally,
67  the class is realized through an array of intervals of type
68  \Ref{r_Sinterval}.
69 
70  For the operations union, difference, and intersection the
71  dimensionalties of the operands must be equal, otherwise an
72  exception is raised. The semantics of the operations are
73  defined as follows for each dimension:
74 
75  | ... fixed bound \\
76  * ... open bound
77 
78  \begin{verbatim}
79 
80  class orientation union difference intersection
81  -----------------------------------------------------------
82  1 |-a-| |-b-| error a error
83 
84  2 |-a-| [a1,b2] [a1,b1] [b1,a2]
85  |-b-|
86 
87  3 |--a--| a error b
88  |-b-|
89 
90  4 |-b-| [b1,a2] [b2,a2] [a1,b2]
91  |-a-|
92 
93  5 |--b--| b error a
94  |-a-|
95 
96  6 |-b-| |-a-| error a error
97 
98  7 |-a-|-b-| [a1,b2] a [a2,a2]
99 
100  8 |-b-|-a-| [b1,a2] a [b2,b2]
101 
102  9 |--a--| a [a1,b1] b
103  |-b-|
104 
105  10 |--a--| a [b2,a2] b
106  |-b-|
107 
108  11 |-a-| a error a
109  |-b-|
110 
111  12 |--b--| b error a
112  |-a-|
113 
114  13 |--b--| b error a
115  |-a-|
116 
117  -----------------------------------------------------
118 
119  14 |--a--* a error b
120  |-b-|
121 
122  15 |--a--* a [b2,a2] b
123  |-b-|
124 
125  16 |-b-| |-a-* error a error
126 
127  17 |-b-|-a-* [b1,a2] a [b2,b2]
128 
129  18 |--a--* [b1,a2] [b2,a2] [a1,b2]
130  |-b-|
131 
132  -----------------------------------------------------
133 
134  19 *--a--| a error b
135  |-b-|
136 
137  20 *--a--| a [a1,b1] b
138  |-b-|
139 
140  21 *-a-| |-b-| error a error
141 
142  22 *-a-|-b-| [a1,b2] a [a2,a2]
143 
144  23 *--a--| [a1,b2] [a1,b1] [b1,a2]
145  |-b-|
146 
147  -----------------------------------------------------
148 
149  24 |--b--* b error a
150  |-a-|
151 
152  25 |--b--* b error a
153  |-a-|
154 
155  26 |-a-| |-b-* error a error
156 
157  27 |-a-|-b-* [a1,b2] a [a2,a2]
158 
159  28 |--b--* [a1,b2] [a1,b1] [b1,a2]
160  |-a-|
161 
162  -----------------------------------------------------
163 
164  29 *--b--| b error a
165  |-a-|
166 
167  30 *--b--| b error a
168  |-a-|
169 
170  31 *-b-| |-a-| error a error
171 
172  32 *-b-|-a-| [b1,a2] a [b2,b2]
173 
174  33 *--b--| [b1,a2] [b2,a2] [a1,b2]
175  |-a-|
176 
177  -----------------------------------------------------
178 
179  34 *-a-| |-b-* error a error
180 
181  35 *-a-|-b-* [a1,b2] a [a2,a2]
182 
183  36 *-a-| [a1,b2] [a1,b1] [b1,a2]
184  |-b-*
185 
186  -----------------------------------------------------
187 
188  37 *-b-| |-a-* error a error
189 
190  38 *-b-|-a-* [b1,a2] a [b2,b2]
191 
192  39 *-b-| [b1,a2] [a1,b1] [a1,b2]
193  |-a-*
194 
195  -----------------------------------------------------
196 
197  40 *-a-| b error a
198  *-b-|
199 
200  41 *-a-| a error a
201  *-b-|
202 
203  42 *-b-| a [b2,a2] b
204  *-a-|
205 
206  -----------------------------------------------------
207 
208  43 |-a-* a [a1,b1] b
209  |-b-*
210 
211  44 |-a-* a error a
212  |-b-*
213 
214  45 |-b-* b error a
215  |-a-*
216 
217  -----------------------------------------------------
218  46 *-a-* |-b-| a error b
219 
220  47 *-b-* |-a-| b error b
221 
222  48 *-a-* a [b2,a2] b
223  *-b-|
224 
225  49 *-a-* a [a1,b1] b
226  |-b-*
227 
228  50 *-b-* b error a
229  *-a-|
230 
231  51 *-b-* b error a
232  |-a-*
233 
234  52 *-a-* a error a
235  *-b-*
236 
237  \end{verbatim}
238 
239  Attention: The difference operation has to be reconsidered in future
240  concerning a discrete interpretation of the intervals.
241 
242  The closure operation defines an interval which is the smallest
243  interval containing the two operands.
244  The method {\tt intersects_with()} returns 0 in the error cases of the
245  intersection operation and 1 otherwise.
246 
247 */
248 
249 class r_Minterval
250 {
251 public:
253  r_Minterval( r_Dimension );
255  r_Minterval( const char* ) throw(r_Eno_interval);
257  r_Minterval( char* ) throw(r_Eno_interval);
259  r_Minterval& operator<<( const r_Sinterval& )
260  throw( r_Einit_overflow );
262  r_Minterval& operator<<( r_Range )
263  throw( r_Einit_overflow );
264 
266  r_Minterval();
268  r_Minterval( const r_Minterval& );
270  ~r_Minterval();
271 
273  void r_deactivate();
274 
276  bool intersects_with( const r_Minterval& ) const;
277 
278 #ifdef OPT_INLINE
279  inline
280 #endif
281  r_Sinterval operator[]( r_Dimension ) const;
283 #ifdef OPT_INLINE
284  inline
285 #endif
286  r_Sinterval& operator[]( r_Dimension );
288 
290  const r_Minterval& operator= ( const r_Minterval& );
291 
293  bool operator==( const r_Minterval& ) const;
294 
300  bool operator!=( const r_Minterval& ) const;
302 
304  inline const bool covers( const r_Point& pnt ) const;
309  inline const bool covers( const r_Minterval& inter ) const;
315  inline r_Dimension dimension() const;
317 
319  inline const bool is_origin_fixed() const;
320  /*@Doc:
321  Returns true if all lower bounds are fixed, otherwise false.
322  */
323 
325  r_Point get_origin() const throw(r_Error);
326  /*@Doc:
327  Returns a point with the minimum coordinates in all dimensions.
328  This is operation is only legal if all lower bounds are fixed!
329  */
330 
332  inline const bool is_high_fixed() const;
333  /*@Doc:
334  Returns true if all upper bounds are fixed, otherwise false.
335  */
336 
338  r_Point get_high() const throw(r_Error);
339  /*@Doc:
340  Returns a point with the maximum coordinates in all dimensions.
341  This is operation is only legal if all upper bounds are fixed!
342  */
343 
345  r_Point get_extent() const throw(r_Error);
346  /*@Doc:
347  Returns a point with high() - low() + 1 of this in each
348  dimension when all bounds are fixed
349  */
350 
352  bool is_mergeable(const r_Minterval& other) const;
372  //@Man: Methods for translation:
374  r_Minterval& reverse_translate( const r_Point& )
376  throw( r_Error, r_Edim_mismatch, r_Eno_interval );
377  /*@Doc:
378  Subtracts respective coordinate of a point to the lower bounds of an
379  interval. This operation is only legal if all bounds are
380  fixed!
381  */
383  r_Minterval create_reverse_translation( const r_Point& ) const
384  throw( r_Error, r_Edim_mismatch, r_Eno_interval );
385  /*@Doc:
386  Subtracts respective coordinate of a point to the lower bounds of an
387  interval. This operation is only legal if all bounds are
388  fixed!
389  */
391  r_Minterval& translate( const r_Point& )
392  throw( r_Error, r_Edim_mismatch, r_Eno_interval );
393  /*@Doc:
394  Adds respective coordinate of a point to the lower bounds of an
395  interval. This operation is only legal if all bounds are
396  fixed!
397  */
399  r_Minterval create_translation( const r_Point& ) const
400  throw( r_Error, r_Edim_mismatch, r_Eno_interval );
401  /*@Doc:
402  Adds respective coordinate of a point to the lower bounds of an
403  interval. This operation is only legal if all lower bounds are
404  fixed!
405  */
407 
408 
409  //*****************************************
410 
411  //@Man: Methods for scaling:
413  r_Minterval& scale( const double& ) throw ( r_Eno_interval );
415  /*@Doc:
416  Scales respective extents by factor.
417  */
419  r_Minterval& scale( const vector<double>& ) throw ( r_Eno_interval );
420  /*@Doc:
421  Scales respective extents by vector of factors.
422  */
424  r_Minterval create_scale( const double& ) const throw ( r_Eno_interval );
425  /*@Doc:
426  Scales respective extents by factor.
427  */
429  r_Minterval create_scale( const vector<double>& ) const throw ( r_Eno_interval );
430  /*@Doc:
431  Scales respective extents by vector of factors.
432  */
434 
435  //*****************************************
436 
437 
438 
439 
440 
441  //@Man: Methods/Operators for the union operation:
443  r_Minterval& union_of ( const r_Minterval&, const r_Minterval& )
445  throw( r_Edim_mismatch, r_Eno_interval );
447  r_Minterval& union_with ( const r_Minterval& )
448  throw( r_Edim_mismatch, r_Eno_interval );
450  r_Minterval& operator+= ( const r_Minterval& )
451  throw( r_Edim_mismatch, r_Eno_interval );
453  r_Minterval create_union ( const r_Minterval& ) const
454  throw( r_Edim_mismatch, r_Eno_interval );
456  r_Minterval operator+ ( const r_Minterval& ) const
457  throw( r_Edim_mismatch, r_Eno_interval );
459 
460 
461  //@Man: Methods/Operators for the difference operation:
463  r_Minterval& difference_of ( const r_Minterval&, const r_Minterval& )
465  throw( r_Edim_mismatch, r_Eno_interval );
467  r_Minterval& difference_with ( const r_Minterval& )
468  throw( r_Edim_mismatch, r_Eno_interval );
470  r_Minterval& operator-= ( const r_Minterval& )
471  throw( r_Edim_mismatch, r_Eno_interval );
473  r_Minterval create_difference ( const r_Minterval& ) const
474  throw( r_Edim_mismatch, r_Eno_interval );
476  r_Minterval operator- ( const r_Minterval& ) const
477  throw( r_Edim_mismatch, r_Eno_interval );
479 
480 
481  //@Man: Methods/Operators for the intersection operation:
483  r_Minterval& intersection_of ( const r_Minterval&, const r_Minterval& )
485  throw( r_Edim_mismatch, r_Eno_interval );
487  r_Minterval& intersection_with ( const r_Minterval& )
488  throw( r_Edim_mismatch, r_Eno_interval );
490  r_Minterval& operator*= ( const r_Minterval&)
491  throw( r_Edim_mismatch, r_Eno_interval);
493  r_Minterval create_intersection ( const r_Minterval& ) const
494  throw( r_Edim_mismatch, r_Eno_interval );
496  r_Minterval operator* ( const r_Minterval& ) const
497  throw( r_Edim_mismatch, r_Eno_interval );
499 
500 
501  //@Man: Methods/Operators for the closure operation:
503  r_Minterval& closure_of ( const r_Minterval&, const r_Minterval& )
505  throw( r_Edim_mismatch, r_Eno_interval );
507  r_Minterval& closure_with ( const r_Minterval& )
508  throw( r_Edim_mismatch, r_Eno_interval );
510  r_Minterval create_closure ( const r_Minterval& ) const
511  throw( r_Edim_mismatch, r_Eno_interval );
513 
514 
516  void print_status( std::ostream& s = std::cout ) const;
517 
519  char* get_string_representation() const;
527  //@Man: Methods for internal use only:
529  r_Area cell_count() const throw(r_Error);
532  r_Area cell_offset( const r_Point& ) const throw( r_Eindex_violation, r_Error );
534  r_Point cell_point( r_Area ) const throw( r_Eno_cell, r_Error );
536  void delete_dimension( r_Dimension ) throw( r_Eindex_violation );
538  r_Bytes get_storage_size( ) const;
540 
541 
542 protected:
544  r_Sinterval* intervals;
545 
547  r_Dimension dimensionality;
548 
550  r_Dimension streamInitCnt;
551 
553  void constructorinit(char* ) throw(r_Eno_interval);
554 };
555 
556 
557 
558 
559 //@ManMemo: Module: {\bf raslib}
563 extern std::ostream& operator<<( std::ostream& s, const r_Minterval& d );
564 extern std::ostream& operator<<( std::ostream& s, const std::vector<r_Minterval>& d );
565 
566 #include "raslib/minterval.icc"
567 
568 #endif
Definition: sinterval.hh:233
bool operator==(const OId::OIdPrimitive one, const OId &two)