00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _LTI_DRAW2_D_DISTRIBUTION_H_
00034 #define _LTI_DRAW2_D_DISTRIBUTION_H_
00035
00036
00037 #include "ltiFunctor.h"
00038 #include "ltiMatrix.h"
00039 #include "ltiDrawBase.h"
00040 #include <map>
00041 #include <vector>
00042 #include "ltiBoundsFunctor.h"
00043 #include "ltiSTLIoInterface.h"
00044 #include "ltiTypeInfo.h"
00045
00046 namespace lti {
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 template<class T>
00070 class draw2DDistribution : public functor {
00071 public:
00072
00073
00074
00075
00076 class parameters : public functor::parameters {
00077 public:
00078
00079
00080
00081 parameters()
00082 : functor::parameters() {
00083 coSystem = false;
00084 scaleEqual = true;
00085
00086 background=getDefaultBackground();
00087 axisColor=getDefaultAxisColor();
00088
00089 scale=tpoint<float>(20.0,20.0);
00090 offset=tpoint<float>(400.0,400.0);
00091 autoscale=true;
00092
00093 initPalette();
00094 initMarker();
00095 };
00096
00097
00098
00099
00100
00101 parameters(const parameters& other)
00102 : functor::parameters() {
00103 copy(other);
00104 };
00105
00106
00107
00108
00109 ~parameters() {};
00110
00111
00112
00113
00114 const char* getTypeName() const {
00115 return "draw2DDistribution::parameters";
00116 };
00117
00118
00119
00120
00121
00122
00123 parameters& copy(const parameters& other){
00124 # ifndef _LTI_MSC_6
00125
00126 functor::parameters::copy(other);
00127 # else
00128
00129
00130 functor::parameters& (functor::parameters::* p_copy)
00131 (const functor::parameters&) =
00132 functor::parameters::copy;
00133 (this->*p_copy)(other);
00134 # endif
00135
00136
00137 coSystem = other.coSystem;
00138 scaleEqual = other.scaleEqual;
00139 background = other.background;
00140 axisColor = other.axisColor;
00141 marker = other.marker;
00142 palette = other.palette;
00143 scale = other.scale;
00144 offset = other.offset;
00145 autoscale = other.autoscale;
00146
00147 return *this;
00148 };
00149
00150
00151
00152
00153
00154
00155 parameters& operator=(const parameters& other) {
00156 return copy(other);
00157 };
00158
00159
00160
00161
00162
00163 virtual functor::parameters* clone() const {
00164 return new parameters(*this);
00165 };
00166
00167 # ifndef _LTI_MSC_6
00168
00169
00170
00171
00172
00173
00174
00175 bool write(ioHandler& handler,const bool complete=true) const
00176 # else
00177 bool writeMS(ioHandler& handler,const bool complete=true) const
00178 # endif
00179 {
00180 bool b = true;
00181 if (complete) {
00182 b = handler.writeBegin();
00183 }
00184
00185 if (b) {
00186
00187 lti::write(handler,"coSystem",coSystem);
00188 lti::write(handler,"scaleEqual",scaleEqual);
00189 lti::write(handler,"background",background);
00190 lti::write(handler,"axisColor",axisColor);
00191 lti::write(handler,"marker",marker);
00192 lti::write(handler,"palette",palette);
00193
00194 lti::write(handler,"scale",scale);
00195 lti::write(handler,"offset",offset);
00196 lti::write(handler,"autoscale",autoscale);
00197 }
00198
00199 # ifndef _LTI_MSC_6
00200
00201
00202 b = b && functor::parameters::write(handler,false);
00203 # else
00204 bool (functor::parameters::* p_writeMS)(ioHandler&,const bool) const =
00205 functor::parameters::writeMS;
00206 b = b && (this->*p_writeMS)(handler,false);
00207 # endif
00208
00209 if (complete) {
00210 b = b && handler.writeEnd();
00211 }
00212
00213 return b;
00214 }
00215
00216 # ifdef _LTI_MSC_6
00217
00218
00219
00220
00221
00222
00223
00224 bool write(ioHandler& handler,const bool complete) const {
00225
00226 return writeMS(handler,complete);
00227 }
00228 # endif
00229
00230
00231
00232
00233
00234
00235
00236
00237 # ifndef _LTI_MSC_6
00238 bool read(ioHandler& handler,const bool complete=true)
00239 # else
00240 bool readMS(ioHandler& handler,const bool complete=true)
00241 # endif
00242 {
00243 bool b = true;
00244 if (complete) {
00245 b = handler.readBegin();
00246 }
00247
00248 if (b) {
00249 lti::read(handler,"coSystem",coSystem);
00250 lti::read(handler,"scaleEqual",scaleEqual);
00251 lti::read(handler,"background",background);
00252 lti::read(handler,"axisColor",axisColor);
00253
00254 lti::read(handler,"marker",marker);
00255 lti::read(handler,"palette",palette);
00256
00257 lti::read(handler,"scale",scale);
00258 lti::read(handler,"offset",offset);
00259 lti::read(handler,"autoscale",autoscale);
00260 }
00261
00262 # ifndef _LTI_MSC_6
00263
00264
00265 b = b && functor::parameters::read(handler,false);
00266 # else
00267 bool (functor::parameters::* p_readMS)(ioHandler&,const bool) =
00268 functor::parameters::readMS;
00269 b = b && (this->*p_readMS)(handler,false);
00270 # endif
00271
00272 if (complete) {
00273 b = b && handler.readEnd();
00274 }
00275
00276 return b;
00277 }
00278
00279 # ifdef _LTI_MSC_6
00280
00281
00282
00283
00284
00285
00286
00287 bool read(ioHandler& handler,const bool complete) {
00288
00289
00290 return readMS(handler,complete);
00291 }
00292 # endif
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 bool coSystem;
00303
00304
00305
00306
00307
00308
00309 bool scaleEqual;
00310
00311
00312
00313
00314 tpoint<float> scale;
00315
00316
00317
00318
00319
00320
00321 tpoint<float> offset;
00322
00323
00324
00325
00326
00327 bool autoscale;
00328
00329
00330
00331
00332 T background;
00333
00334
00335
00336
00337 T axisColor;
00338
00339
00340
00341
00342 std::vector<T> palette;
00343
00344
00345
00346
00347 std::vector<char> marker;
00348
00349 private:
00350
00351 T getDefaultAxisColor() {
00352 return T(0);
00353 };
00354
00355 T getDefaultBackground() {
00356 return T(0);
00357 };
00358
00359
00360
00361
00362 void initPalette()
00363
00364
00365
00366 # ifdef _LTI_MSC_6
00367 {
00368
00369 palette.push_back(getDefaultAxisColor());
00370 palette.push_back(typeInfo<T>::suggestedNorm()/3);
00371 palette.push_back(typeInfo<T>::suggestedNorm()*2/3);
00372 }
00373 #endif
00374 ;
00375
00376
00377
00378
00379 void initMarker() {
00380 marker.push_back('o');
00381 marker.push_back('s');
00382 marker.push_back('d');
00383 marker.push_back('^');
00384 marker.push_back('v');
00385 marker.push_back('<');
00386 marker.push_back('>');
00387 }
00388
00389 };
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 draw2DDistribution();
00400
00401
00402
00403
00404
00405 draw2DDistribution(const draw2DDistribution& other);
00406
00407
00408
00409
00410 virtual ~draw2DDistribution();
00411
00412
00413
00414
00415 virtual const char* getTypeName() const;
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 bool apply(drawBase<T>& drawer, const dmatrix& dist, const bool& hold=false,
00426 const char* style="ow0") const;
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 bool apply(drawBase<T>& drawer,
00441 const dmatrix& dist,
00442 const int first,
00443 const int second,
00444 const bool hold=false,
00445 const char* style="ow") const;
00446
00447
00448
00449
00450
00451 bool apply(drawBase<T>& drawer,const dvector& x,const dvector& y,
00452 const bool hold=false,const char* style="ow") const;
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463 bool apply(drawBase<T>& drawer, const dmatrix& dist,const ivector& ids,
00464 const bool& hold=false) const;
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 bool apply(drawBase<T>& drawer, const dmatrix& dist1,const ivector& ids1,
00482 const dmatrix& dist2,const ivector& ids2,
00483 const bool& hold=false) const;
00484
00485
00486
00487
00488
00489
00490 draw2DDistribution<T>& copy(const draw2DDistribution<T>& other);
00491
00492
00493
00494
00495
00496
00497 draw2DDistribution<T>& operator=(const draw2DDistribution<T>& other);
00498
00499
00500
00501
00502 virtual functor* clone() const;
00503
00504
00505
00506
00507 const parameters& getParameters() const;
00508
00509 protected:
00510
00511
00512
00513
00514 dmatrix *testDist;
00515
00516
00517
00518
00519 ivector *testIds;
00520
00521
00522
00523
00524 dmatrix *trainDist;
00525
00526
00527
00528
00529 ivector *trainIds;
00530
00531
00532
00533
00534 std::map<int,char* > *styles;
00535
00536
00537
00538
00539 std::map<int,T > *colorMap;
00540
00541
00542 };
00543
00544 }
00545
00546 #endif