00001
00010 #include <iostream>
00011 #include <ostream>
00012
00013
00014
00015
00016
00017
00018
00019 #include "../gsoap/soapH.h"
00020
00021
00022
00023 #include <string>
00024 #include <sstream>
00025
00026
00027
00028 hyperpoint::hyperpoint ()
00029 {
00030 __ptr = NULL;
00031 __size = 0;
00032 }
00033
00034 hyperpoint::hyperpoint (const hyperpoint & point)
00035 {
00036 __size = point.__size;
00037 __ptr = new float[__size];
00038 for (int i = 0; i < __size; i++)
00039 __ptr[i] = point.__ptr[i];
00040 }
00041
00042 hyperpoint::hyperpoint (int size)
00043 {
00044 __ptr = new float[size];
00045 __size = size;
00046 for (int i = 0; i < __size; i++)
00047 __ptr[i] = -1.0;
00048 }
00049
00050 hyperpoint::~hyperpoint ()
00051 {
00052 if (__ptr == NULL && __size == 0)
00053 return;
00054 if (__size > 1)
00055 delete [] __ptr;
00056 else if (__size == 1)
00057 delete __ptr;
00058 __ptr = NULL;
00059 __size = 0;
00060 }
00061
00062 int
00063 hyperpoint::size () const
00064 {
00065 return __size;
00066 }
00067
00068 float &
00069 hyperpoint::operator[] (int i) const
00070 {
00071 return __ptr[i];
00072 }
00073
00074 float
00075 hyperpoint::operator () (int i) const
00076 {
00077 if (i >= 0 && i < __size)
00078 return __ptr[i];
00079 return -1.0;
00080 }
00081
00082 hyperpoint & hyperpoint::operator= (const hyperpoint & point)
00083 {
00084 if (__size > 0)
00085 this->reset ();
00086 __size = point.__size;
00087 __ptr = new float[__size];
00088 for (int i = 0; i < __size; i++)
00089 __ptr[i] = point.__ptr[i];
00090 return *this;
00091 }
00092
00093 void
00094 hyperpoint::print () const
00095 {
00096 std::cout << std::endl << "Printing point of size " << this->__size << ":" << std::endl;
00097 for (int i = 0; i < __size; i++)
00098 {
00099 std::cout << "joint[" << i << "] = " << __ptr[i] << std::endl;
00100 }
00101 std::cout << std::endl;
00102 return;
00103 }
00104
00105 void
00106 hyperpoint::print (std::ostream &printstream) const
00107 {
00108 printstream << std::endl << "Printing point of size " << this->__size << ":" << std::endl;
00109 for (int i = 0; i < __size; i++)
00110 {
00111 printstream << "joint[" << i << "] = " << __ptr[i] << std::endl;
00112 }
00113 printstream << std::endl;
00114 return;
00115 }
00116
00117 void
00118 hyperpoint::initialize (int size)
00119 {
00120 if (__ptr == NULL)
00121 {
00122 __ptr = new float[size];
00123 __size = size;
00124 for (int i = 0; i < __size; i++)
00125 __ptr[i] = -1.0;
00126 }
00127 }
00128
00129 void
00130 hyperpoint::reset ()
00131 {
00132 if (__size < 0)
00133 delete __ptr;
00134 else
00135 delete[]__ptr;
00136 __ptr = NULL;
00137 __size = 0;
00138 }
00139
00140 double hyperpoint::norm2() const
00141 {
00142 double sum = 0;
00143 for (int i = 0; i < __size; i++){
00144 double val = (*this)[i];
00145 sum += val*val;
00146 }
00147 return sum;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 hyperpoint hyperpoint::operator - (const hyperpoint &y) const
00161 {
00162 hyperpoint difference(__size);
00163
00164 for (int i = 0; i < __size; i++){
00165 difference[i] = (*this)[i]-y[i];
00166 }
00167 return difference;
00168 }
00169
00170 bool hyperpoint::operator < (double threshold) const
00171 {
00172 for (int i = 0; i < __size; i++){
00173 if (fabs((*this)(i)) > threshold){
00174 std::cout << "OPERATOR < RETURNING FALSE BECAUSE " << (*this)(i) << " > " << threshold;
00175 return false;
00176 }
00177 }
00178 return true;
00179 }
00180
00181 double hyperpoint::dist2(const hyperpoint &y) const
00182 {
00183 double sum = 0;
00184 for (int i = 0; i < __size; i++){
00185 double diff = (*this)[i] - y[i];
00186 sum += diff*diff;
00187 }
00188 return sum;
00189 }
00190
00191 hyperarray::hyperarray ()
00192 {
00193 __ptr = NULL;
00194 __size = 0;
00195 }
00196
00197 hyperarray::hyperarray (int size)
00198 {
00199 __ptr = new hyperpoint[size];
00200 __size = size;
00201 }
00202
00203 hyperarray::hyperarray (const hyperarray & array)
00204 {
00205 __size = array.__size;
00206 __ptr = new hyperpoint[__size];
00207 for (int i = 0; i < __size; i++)
00208 __ptr[i] = array.__ptr[i];
00209 }
00210
00211 hyperarray::~hyperarray ()
00212 {
00213 if (__ptr == NULL && __size == 0)
00214 return;
00215 if (__size < 0)
00216 delete __ptr;
00217 else
00218 delete[]__ptr;
00219 }
00220
00221 int
00222 hyperarray::size () const
00223 {
00224 return __size;
00225 }
00226
00227 hyperpoint & hyperarray::operator[](int i) const
00228 {
00229 return __ptr[i];
00230 }
00231
00232 hyperpoint hyperarray::operator ()(int i) const
00233 {
00234 return __ptr[i];
00235 }
00236
00237 hyperarray & hyperarray::operator= (const hyperarray & array)
00238 {
00239 if (__size > 0)
00240 this->reset ();
00241 __size = array.__size;
00242 __ptr = new hyperpoint[__size];
00243 for (int i = 0; i < __size; i++)
00244 __ptr[i] = array.__ptr[i];
00245 return *this;
00246 }
00247
00248 void
00249 hyperarray::initialize (int size)
00250 {
00251 if (__ptr == NULL)
00252 {
00253 __ptr = new hyperpoint[size];
00254 __size = size;
00255 }
00256 }
00257
00258 void
00259 hyperarray::reset (void)
00260 {
00261 if (__size > 0)
00262 {
00263 for (int i = 0; i < __size; i++)
00264 {
00265 if (__ptr[i].size () > 0)
00266 __ptr[i].reset ();
00267 }
00268 }
00269 __ptr = NULL;
00270 __size = 0;
00271 }
00272
00273 void
00274 hyperarray::print (void) const
00275 {
00276 std::cout << "Printing hyperarray of size " << this->__size << std::endl;
00277 for (int i = 0; i < __size; i++)
00278 {
00279 std::cout << "Point " << i << ":" << std::endl;
00280 __ptr[i].print ();
00281 }
00282 std::cout << std::endl;
00283 return;
00284 }
00285
00286 void
00287 hyperarray::print (std::ostream &printstream) const
00288 {
00289 printstream << "Printing hyperarray of size " << this->__size << std::endl;
00290 for (int i = 0; i < __size; i++)
00291 {
00292 printstream << "Point " << i << ":" << std::endl;
00293 __ptr[i].print (printstream);
00294 }
00295 printstream << std::endl;
00296 return;
00297 }
00298