int main(int argc,char *argv[]) { CkPrintf("init called\n"); CrnInitStream(&rs,0,0); int facesA[nFaces*nPer],facesB[nFaces*nPer]; const int nPoints=aPoints+bPoints; CkVector3d pts[nPoints]; FEM_Print("Fabricating points:"); CkVector3d a2bLocs(randVec(CkVector3d(10.0,90.0,50.0))); print("true offset vector "); print(a2bLocs,15); int i; //Fabricate some test points (just purely random) for (i=0;i<aPoints;i++) { pts[i]=randVec(CkVector3d(5.0,5.0,5.0)); pts[i+a2bPoints]=pts[i]+a2bLocs; } makeFaces(facesA,facesB); //Actually do the match: //verbosematchingDest dest; unionFind uf(nPoints); unionFindDest dest(uf); FEM_Print("Finding offset"); linearOffsetMatcher matcher(nFaces,nPer,facesA,facesB,0, nPoints,pts); FEM_Print("Beginning match"); matcher.match(dest); FEM_Print("Compressing paths"); uf.compress(); FEM_Print("Testing union"); testUnion(nPoints,uf.detach()); FEM_Print("Done"); }
void CkQuadView::pup(PUP::er &p) { CkView::pup(p); p.comment("Texture corners"); p|nCorners; for (int i=0;i<nCorners;i++) { p|corners[i]; p|texCoord[i]; } // Pup the image: x_tex.pup(p); #ifdef CMK_LIVEVIZ3D_CLIENT if (p.isUnpacking()) { /* immediately upload image to OpenGL */ CkAllocImage *img=x_tex.getImage(); oglTextureFormat_t fmt=oglImageFormat(*img); c_tex=new oglLilTex(img->getData(),x_tex.gl_w,x_tex.gl_h, fmt.format,fmt.type); stats::get()->add(x_tex.w*x_tex.h,op_upload_pixels); stats::get()->add(x_tex.gl_w*x_tex.gl_h,op_uploadpad_pixels); /// Scale texture coordinates from the partial image to OpenGL fractions: double tx=x_tex.w/(double)x_tex.gl_w; double ty=x_tex.h/(double)x_tex.gl_h; for (int i=0;i<nCorners;i++) texCoord[i]=c_tex->texCoord( CkVector3d(tx*texCoord[i].x,ty*texCoord[i].y,texCoord[i].z) ); //Now that we've copied the view into GL, // flush the old in-memory copy: delete img; } #endif }
main(CkArgMsg* m) { nElements=5; if(m->argc > 1) nElements = atoi(m->argv[1]); delete m; CkPrintf("Running Hello on %d processors for %d elements\n", CkNumPes(),nElements); mid = thishandle; CollideGrid3d gridMap(CkVector3d(0,0,0),CkVector3d(2,100,2)); CollideHandle collide=CollideCreate(gridMap, CollideSerialClient(printCollisionHandler,0)); arr = CProxy_Hello::ckNew(collide,nElements); arr.DoIt(); };
//Set our points as the 8 corners of this bounding box: CkInterestSet::CkInterestSet(const CkBbox3d &box) :nInterest(8) { for (int i=0;i<8;i++) { loc[i]=CkVector3d( (i&1)?box.max.x:box.min.x, (i&2)?box.max.y:box.min.y, (i&4)?box.max.z:box.min.z ); } }
/// Get our i'th clipping plane. CkHalfspace3d CkViewpoint::getClip(int i) const { double target=0, dir=1; int r=0; // matrix row switch (i) { case 0: break; case 1: target=-wid; dir=-1; break; case 2: r=1; break; case 3: target=-ht; dir=-1; r=1; break; } // Require: dir * proj(v) >= target // where proj(x)=(v dot m(r) + m(r,3))/(v dot m(3) + m(3,3)) // so (assuming w positive) // dir * (v dot m(r) + m(r,3)) >= target * (v dot m(3) + m(3,3)) // which we cast as (v dot h.n) + h.d >= 0 CkHalfspace3d h; h.n= dir*CkVector3d(m(r,0),m(r,1),m(r,2)) -target*CkVector3d(m(3,0),m(3,1),m(3,2)); h.d= dir*m(r,3) - target*m(3,3); return h; }
/** * Create a new CkInterestView for this (novel) viewpoint. * Default implementation creates a flat-on viewpoint and * calls render() to create a new texture. */ bool CkInterestViewable::newViewpoint(const CkViewpoint &univ2screen,CkViewpoint &univ2texture) { //Find our destination rectangle onscreen, to estimate our resolution needs: CkRect r; r.empty(); CkRect clipR; clipR.empty(); for (int i=0;i<interest.size();i++) { //Screen-project this interest point CkVector3d s(univ2screen.project(interest[i])); if (!(s.z>0)) continue; // Just ignore behind-the-viewer points // return false; r.add((int)s.x,(int)s.y); univ2screen.clip(s); clipR.add((int)s.x,(int)s.y); } if (clipR.area()<2) return false; if (r.l==r.r) r.r++; /* enlarge vertical sliver */ if (r.t==r.b) r.b++; /* enlarge horizontal sliver */ //Round up the texture size based on the onscreen size // (Note: OpenGL textures *MUST* be a power of two in both directions) // ( for mipmapping, the textures must also be square ) double inset=2; //Pixels to expand output region by (to ensure a clean border) int target_w=(int)(r.wid()+2*inset), target_h=(int)(r.ht()+2*inset); #if 0 /* for OpenGL: power-of-two textures */ const int start_sz=4, max_sz=512; int wid=start_sz, ht =start_sz; // Proposed size // Scale up size until both width and height are acceptable. while ((wid<target_w) || (ht<target_h)) { ht*=2; wid*=2; } #else /* non-power-of-two textures (sensible default) */ int max_sz=512; int wid=target_w, ht=target_h; #endif //Create our new view in the plane of our center, // using a perspective-scaled version of the old axes: const CkVector3d &E=univ2screen.getEye(); double eyeCenter=(center-E).mag(); double eyeViewplane=(univ2screen.projectViewplane(center)-E).mag(); double perspectiveScale=eyeCenter/(1.0e-10+eyeViewplane); // printf("PerspectiveScale=%f\n",perspectiveScale); // New axes are just scaled versions of old axes: double Xscale=perspectiveScale;//*r.wid()/(wid-2*inset); double Yscale=perspectiveScale;//*r.ht()/(ht-2*inset); // If the resulting texture is too big, scale it down: if (wid>max_sz) { wid=max_sz; Xscale*=r.wid()/(wid-2*inset); } if (ht>max_sz) { ht=max_sz; Yscale*=r.ht()/(ht-2*inset); } /* if (Xscale ==0 || Yscale==0) CmiAbort("liveViz3d> Illegal axis scaling"); */ CkVector3d X=univ2screen.getX()*Xscale; CkVector3d Y=univ2screen.getY()*Yscale; // New origin is just shifted version of old origin: CkVector3d R=perspectiveScale*(univ2screen.viewplane(CkVector3d(r.l,r.t,0))-E)+E -inset*X-inset*Y; univ2texture=CkViewpoint(E,R,X,Y,wid,ht); if (1) { /// Set priority: // const static double distCutoff=10.0; priorityAdjust=(int)( std::max(wid,ht)*(1.0/1.0) /* area boost */ // +1.0/std::max(eyeCenter,distCutoff)*(50.0/distCutoff) /* nearness boost */ // +(r==clipR)*20.0 /* fully onscreen boost */ ); } return true; }
/// Initialize this view, from this viewpoint: CkInterestView::CkInterestView(int wid,int ht,int n_colors, const CkInterestSet &univ_, const CkViewpoint &univ2texture) :CkQuadView(wid,ht,n_colors), univ(univ_) { nCorners=4; corners[0]=univ2texture.viewplane(CkVector3d(0 , 0, 0)); corners[1]=univ2texture.viewplane(CkVector3d(wid, 0, 0)); corners[2]=univ2texture.viewplane(CkVector3d(wid,ht, 0)); corners[3]=univ2texture.viewplane(CkVector3d(0 ,ht, 0)); int cx=wid/2, cy=ht/2; projC=univ2texture.viewplane(CkVector3d(cx ,cy , 0)); projX=univ2texture.viewplane(CkVector3d(cx+1,cy , 0)); projY=univ2texture.viewplane(CkVector3d(cx ,cy+1, 0)); texCoord[0]=CkVector3d(0,0,0); texCoord[1]=CkVector3d(1,0,0); texCoord[2]=CkVector3d(1,1,0); texCoord[3]=CkVector3d(0,1,0); proj.setPoints(univ.size()); for (int i=0;i<univ.size();i++) { //Back-project my interest points into the texture plane: proj[i]=univ2texture.projectViewplane(univ[i]); } }
CkVector3d randVec(const CkVector3d &scale) { return CkVector3d(randVal(scale.x),randVal(scale.y),randVal(scale.z)); }