ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/MT/MTentry.h
Revision: 1.1
Committed: Sun May 6 00:45:52 2001 UTC (23 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 /*********************************************************************
2 * *
3 * Copyright (c) 1997,1998, 1999 *
4 * Multimedia DB Group and DEIS - CSITE-CNR, *
5 * University of Bologna, Bologna, ITALY. *
6 * *
7 * All Rights Reserved. *
8 * *
9 * Permission to use, copy, and distribute this software and its *
10 * documentation for NON-COMMERCIAL purposes and without fee is *
11 * hereby granted provided that this copyright notice appears in *
12 * all copies. *
13 * *
14 * THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE *
15 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING *
16 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR *
18 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A *
19 * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS *
20 * DERIVATIVES. *
21 * *
22 *********************************************************************/
23
24 #ifndef MTENTRY_H
25 #define MTENTRY_H
26
27 #include <string.h>
28 #include <stdio.h>
29 #ifndef MAXDOUBLE
30 #ifdef _WIN32 // for MAXDOUBLE
31 #include <float.h>
32 #define MAXDOUBLE DBL_MAX
33 #else
34 #include <values.h>
35 #endif
36 #endif
37 #include "GiST.h"
38 #include "MTobject.h"
39
40 class MTentry;
41
42 // MTkey is a covering region indicated by an object and its covering radii: obj, rmin, rmax
43 // We also throw in some standard geo operators to support various query predicates, etc.
44
45 class MTkey: public GiSTobject {
46 public:
47 Object obj; // object
48 private:
49 double rmin, rmax; // covering radii
50 public:
51 friend MTentry;
52 // constructors, destructors, assignment, etc.
53 MTkey(): rmin(0), rmax(MAXDOUBLE), distance(-maxDist()), splitted(FALSE), recomp(FALSE) { }
54
55 MTkey(const MTkey& k): obj(k.obj), rmin(k.rmin), rmax(k.rmax), distance(k.distance), splitted(k.splitted), recomp(k.recomp) { }
56
57 MTkey(Object& p_obj, const double p_rmin, const double p_rmax, const double p_distance=-maxDist(), const BOOL p_splitted=FALSE, const BOOL p_recomp=FALSE):
58 obj(p_obj), rmin(p_rmin), rmax(p_rmax), distance(p_distance), splitted(p_splitted), recomp(p_recomp) { }
59
60 GiSTobject *Copy() const { return new MTkey(*this); }
61
62 ~MTkey() { }
63 GiSTobjid IsA() { return MTKEY_CLASS; }
64
65 MTkey& operator = (const MTkey& k) {
66 obj=k.obj;
67 rmin=k.rmin;
68 rmax=k.rmax;
69 distance=k.distance;
70 splitted=k.splitted;
71 recomp=k.recomp;
72 return *this;
73 }
74
75 // covering region property and comparison methods
76 int operator==(const MTkey& k) {
77 return ((!recomp)&&(!k.recomp)&&(obj==k.obj)&&(rmin==k.rmin)&&(rmax==k.rmax)&&(distance==k.distance));
78 }
79
80 int overlap (const MTkey& k) {
81 double d=obj.distance(k.obj);
82
83 return ((d+rmax>=k.rmin)&&(d+k.rmax>=rmin)&&(d<rmax+k.rmax));
84 }
85
86 int contained(const MTkey& k) {
87 double d=obj.distance(k.obj);
88
89 return ((d-rmax>=k.rmin)&&(d+rmax<=k.rmax));
90 }
91
92 int contains(const MTkey& k) {
93 double d=obj.distance(k.obj);
94
95 return ((d-k.rmax>=rmin)&&(d+k.rmax<=rmax));
96 }
97
98 double area() { return obj.area(rmax); }
99
100 // expand this covering region to contain k
101 MTkey *expand(const MTkey& k) {
102 MTkey *result;
103 double d=obj.distance(k.obj);
104
105 result=new MTkey(obj, MIN(rmin, d), MAX(rmax, d));
106 return result;
107 }
108
109 Object object() const { return obj; }
110 double minradius() const { return rmin; }
111 double maxradius() const { return rmax; }
112
113 double distance; // Here we store the distance between the entry and its parent, only for index performance, in order to minimize the number of distance computations;
114 BOOL splitted; // indicate that the node has been splitted
115 BOOL recomp; // indicate that the node has been splitted but that no Union has been performed (thus radii are in a potentially inconsistent state): this can happen after a split
116
117 // I/O methods
118 #ifdef PRINTING_OBJECTS
119 void Print(ostream& os) const {
120 os << '"';
121 os << "(" << obj << ", " << rmin << ", " << rmax << ")" << '"';
122 }
123 #endif
124 };
125
126 #ifdef PRINTING_OBJECTS
127 inline ostream& operator<< (ostream& os, const MTkey& k) {
128 k.Print(os);
129 return os;
130 }
131 #endif
132
133 class MTpenalty: public GiSTpenalty { // we have to create a sub-class in order to add the member value distance
134 public:
135 MTpenalty(): GiSTpenalty(), distance(-maxDist()) { }
136
137 MTpenalty(const double v, const double d): GiSTpenalty(v), distance(d) { }
138
139 double distance; // this is necessary since each penalty is defined by two values: the radius increase and the distance from the entry
140 };
141
142 int sizeofEntry();
143
144 class MTentry: public GiSTentry { // this are the entries stored in each node
145 public:
146 // constructors, destructors, etc.
147 MTentry() { }
148
149 MTentry(const MTkey& k, const GiSTpage p) {
150 key=new MTkey(k);
151 ptr=p;
152 }
153
154 MTentry(const MTentry& e): GiSTentry(e) {
155 key=new MTkey(*(MTkey *)(e.key));
156 }
157
158 GiSTobjid IsA() const { return MTENTRY_CLASS; }
159
160 GiSTobject *Copy() const { return new MTentry(*this); }
161
162 void InitKey() { key=new MTkey; }
163
164 int IsEqual(const GiSTobject& obj) const {
165 if(obj.IsA()!=MTENTRY_CLASS) return 0;
166 return ((*((MTkey *)key)==(*((MTkey *)(((const MTentry&) obj).key)))));
167 }
168
169 // cast key member to class MTkey *. Prevents compiler warnings.
170 MTkey *Key() const { return (MTkey *)key; }
171
172 // basic GiST methods
173 GiSTpenalty *Penalty(const GiSTentry &newEntry) const;
174 GiSTpenalty *Penalty(const GiSTentry &newEntry, MTpenalty *minPenalty) const; // redefined in order to optimize distance computations
175
176 // Other methods we're required to supply
177 int CompressedLength() const {
178 return object().CompressedLength()+3*sizeof(double)+2*sizeof(BOOL); // compressedEntry is: Object, rmin, rmax, distance, splitted, recomp
179 }
180
181 GiSTcompressedEntry Compress() const;
182 void Decompress(const GiSTcompressedEntry entry);
183
184 // Method for ordered domains
185 int Compare(const GiSTentry& entry) const {
186 assert(entry.IsA()==MTENTRY_CLASS);
187 double d=Key()->distance-((MTentry &)entry).Key()->distance;
188 int i=0;
189
190 if(d>0) i=1;
191 else if(d<0) i=-1;
192 return i;
193 }
194
195 // I/O methods
196 #ifdef PRINTING_OBJECTS
197 void Print(ostream& os) const {
198 key->Print(os);
199 os << "->" << Ptr() << " (" << Key()->distance << ")";
200 if(Key()->splitted) os << " *";
201 if(Key()->recomp) os << " #";
202 os << endl;
203 }
204 #endif
205
206 // access to private members
207 const MTkey& cregion() const { return *Key(); }
208 Object& object() const { return Key()->obj; }
209 double minradius() const { return Key()->rmin; }
210 double maxradius() const { return Key()->rmax; }
211 void setobject(const Object& o) { Key()->obj=o; }
212 void setminradius(double d) { Key()->rmin=d; }
213 void setmaxradius(double d) { Key()->rmax=d; }
214 };
215
216 #endif