00001
00002
00003
00004
00005
00006
00007 #ifndef __UIUC_PPL_CHARM_VIEWABLE_H
00008 #define __UIUC_PPL_CHARM_VIEWABLE_H
00009
00010 #include "charm.h"
00011 #include "ckvector3d.h"
00012 #include "ckimage.h"
00013 #include "ckviewpoint.h"
00014 #include "ckhashtable.h"
00015
00020 class CkViewableID {
00021 public:
00022 enum {nId=4};
00023 int id[nId];
00024
00025 CkViewableID() {for (int i=0;i<nId;i++) id[i]=0;}
00026 CkViewableID(int len,const int *src) {
00027 int i;
00028 for (i=0;i<len;i++) id[i]=src[i];
00029 for (i=len;i<nId;i++) id[i]=0;
00030 }
00031
00032
00033 inline unsigned int hash(void) const {
00034 return id[0]+(id[1]<<8)+(id[2]<<16)+(id[3]<<24);
00035 }
00036 inline int compare(const CkViewableID &v) const {
00037 for (int i=0;i<nId;i++) if (id[i]!=v.id[i]) return 0;
00038 return 1;
00039 }
00040 static unsigned int staticHash(const void *key,size_t keyLen) {
00041 return ((const CkViewableID *)key)->hash();
00042 }
00043 static int staticCompare(const void *a,const void *b,size_t keyLen) {
00044 return ((const CkViewableID *)a)->compare(*(const CkViewableID *)b);
00045 }
00046
00047 void pup(PUP::er &p) {
00048 p(id,nId);
00049 }
00050 };
00051 PUPmarshall(CkViewableID)
00052
00053
00059 class CkReferenceCounted {
00060 int refCount;
00061 protected:
00064 virtual ~CkReferenceCounted();
00065 public:
00068 CkReferenceCounted() { refCount=1; }
00069
00072 inline void ref(void) {refCount++;}
00073
00076 inline void unref(void) {
00077 refCount--;
00078 if (refCount<0) CkAbort("Trying to unref deleted object!\n");
00079 if (refCount==0) delete this;
00080 }
00081 };
00082
00083
00084
00085
00096 class CkView : public PUP::able, public CkReferenceCounted {
00097 public:
00100 CkViewableID id;
00101 const CkViewableID &getViewable(void) const {return id;}
00102
00106 unsigned int prio;
00107
00109 int pixels;
00110
00115 PUPable_abstract(CkView);
00116
00119 virtual void pup(PUP::er &p);
00120
00131 virtual void render(double alpha,CkView *old) =0;
00132 };
00133
00136 void CkViewNodeInit(void);
00137
00141 class CkViewable {
00142 public:
00143 CkViewable() :priorityAdjust(0) {}
00144 virtual ~CkViewable();
00145
00149 int priorityAdjust;
00150
00157 virtual bool shouldRender(const CkViewpoint &univ2screen,const CkView &oldView) =0;
00158
00165 virtual CkView *renderView(const CkViewpoint &univ2screen) =0;
00166
00171 virtual double getSize(const CkViewpoint &univ2screen);
00172 };
00173
00179 class CkViewConsumer {
00180 public:
00181 virtual ~CkViewConsumer();
00182
00188 virtual void add(CkView *view) =0;
00189 };
00190
00191
00192
00193 class oglLilTex;
00194
00200 class CkImageCompressor {
00201
00202 CkAllocImage *img;
00203 public:
00204 int w,h;
00205 int gl_w, gl_h;
00206 CkImageCompressor(CkAllocImage *img_)
00207 :img(img_),w(img->getWidth()), h(img->getHeight()), gl_w(0), gl_h(0) { }
00208 void pup(PUP::er &p);
00209 CkAllocImage *getImage(void) {
00210 CkAllocImage *i=img;
00211 img=NULL;
00212 return i;
00213 }
00214 };
00215
00221 class CkQuadView : public CkView {
00222 public:
00231 enum {maxCorners=8};
00232 int nCorners;
00233 CkVector3d corners[maxCorners];
00234 CkVector3d texCoord[maxCorners];
00235
00236
00237 virtual void pup(PUP::er &p);
00238 PUPable_decl(CkQuadView);
00239 virtual ~CkQuadView();
00240
00241
00242 private:
00244 CkAllocImage s_tex;
00245 CkImageCompressor x_tex;
00246 public:
00255 CkQuadView(int w,int h,int n_colors);
00256
00257 CkAllocImage &getImage(void) {return s_tex;}
00258 const CkAllocImage &getImage(void) const {return s_tex;}
00259
00260
00261 private:
00262 oglLilTex *c_tex;
00263 void render(void);
00264 public:
00267 CkQuadView(CkMigrateMessage *m);
00268
00269 inline const oglLilTex *getTexture(void) const {return c_tex;}
00270 virtual void render(double alpha,CkView *old);
00271 };
00272
00273
00278 class CkFixedViewable : public CkViewable {
00279 CkView *v;
00280 public:
00284 CkFixedViewable(CkView *v_) :v(v_) {v->ref();}
00285 ~CkFixedViewable() {v->unref();}
00286
00287
00288 virtual bool shouldRender(const CkViewpoint &univ2screen,const CkView &oldView)
00289 {
00290 return false;
00291 }
00292
00293 virtual CkView *renderView(const CkViewpoint &univ2screen) {
00294 v->ref();
00295 return v;
00296 }
00297 };
00298
00299
00300
00307 class CkInterestSet {
00308 enum {maxInterest=8};
00309 int nInterest;
00310 CkVector3d loc[maxInterest];
00311
00312 public:
00313 CkInterestSet(void) {nInterest=0;}
00314 CkInterestSet(int nInterest_,const CkVector3d *loc_);
00315 CkInterestSet(const CkBbox3d &box);
00316
00317 int size(void) const {return nInterest;}
00318 const CkVector3d &operator[] (int i) const {return loc[i];}
00319
00320 void setPoints(int n) {nInterest=n;}
00321 CkVector3d &operator[] (int i) {return loc[i];}
00322
00323 CkBbox3d getBox(void) const {
00324 CkBbox3d box; box.empty();
00325 for (int i=0;i<nInterest;i++) box.add(loc[i]);
00326 return box;
00327 }
00328
00330 CkVector3d getMean(void) const;
00331
00332 void pup(PUP::er &p);
00333 };
00334 PUPmarshall(CkInterestSet)
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 class CkInterestView : public CkQuadView {
00345
00346 CkInterestSet univ;
00347
00348 CkInterestSet proj;
00350 CkVector3d projC,projX,projY;
00351
00352
00353 double sqrError(int i,const CkViewpoint &univ2screen) const
00354 {
00355 return univ2screen.project_noz(univ[i]) .distSqr(
00356 univ2screen.project_noz(proj[i]) );
00357 }
00358 public:
00362 CkInterestView(int w,int h,int n_colors,
00363 const CkInterestSet &univ_,
00364 const CkViewpoint &univ2texture);
00365
00368 double resRatio(const CkViewpoint &univ2screen) const;
00369
00372 double rmsError(const CkViewpoint &univ2screen) const;
00373
00376 double maxError(const CkViewpoint &univ2screen) const;
00377
00378 #define CMK_LIVEVIZ3D_INTERESTVIEWRENDER 0
00379 #if CMK_LIVEVIZ3D_INTERESTVIEWRENDER
00380 virtual void render(double alpha);
00381 #endif
00382 };
00383
00384
00385
00392 class CkInterestViewable : public CkViewable {
00393 CkInterestSet interest;
00394 CkVector3d center;
00395 CkVector3d boundCenter; double boundRadius;
00396 protected:
00398 void setUnivPoints(const CkInterestSet &univPoints_);
00399 void setCenter(const CkVector3d ¢er_) {center=center_;}
00400 public:
00402 CkInterestViewable() {}
00403
00405 virtual bool shouldRender(const CkViewpoint &univ2screen,const CkView &oldView);
00406
00410 virtual CkView *renderView(const CkViewpoint &univ2screen);
00411
00419 virtual bool newViewpoint(const CkViewpoint &univ2screen,CkViewpoint &univ2texture);
00420
00426 virtual void renderImage(const CkViewpoint &vp,CkImage &dest) =0;
00427
00429 virtual double getSize(const CkViewpoint &univ2screen);
00430 };
00431
00432 #endif