static int __uh_raw_recv(struct client *cl, char *buf, int len, int sec, int (*rfn) (struct client *, char *, int)) { ssize_t rv; int fd = cl->fd.fd; while (true) { if ((rv = rfn(cl, buf, len)) < 0) { if (errno == EINTR) { continue; } else if ((sec > 0) && (errno == EAGAIN || errno == EWOULDBLOCK)) { if (!uh_socket_wait(fd, sec, false)) return -1; } else { D("IO: FD(%d) read error: %s\n", fd, strerror(errno)); return -1; } } else if (rv == 0) { D("IO: FD(%d) appears closed\n", fd); return 0; } else { D("IO: FD(%d) read %d bytes\n", fd, rv); return rv; } } }
void Fish:: generateHead( double Zmax, size_t N, double thickness) { //-------------------------------------------------------------------------- // // Setup: find the ratio of the last slice // //-------------------------------------------------------------------------- clear(); if(Zmax<=0||Zmax>0.5) throw exception("Invalid Zmax=%g",Zmax); zfunction<double> rfn( this, & Profile::getZ, Zmax); zfind<double> solve(0); const double rho_max = solve(rfn.call,0,1); std::cerr << "rho_max=" << rho_max << std::endl; N = max_of<size_t>(1,N); const double delta = rho_max / (N); const size_t n = max_of<size_t>(2,ceil(maxP/delta))-2; const size_t M = 2+2*n; std::cerr << "\tn=" << n << ", M=" << M << std::endl; //-------------------------------------------------------------------------- // // Outer Shell // //-------------------------------------------------------------------------- { //______________________________________________________________________ // // compute the slices position //______________________________________________________________________ for(size_t i=1;i<=N;++i) { const double ratio = i*delta; const pSlice pS( new Slice( getZ(ratio) ) ); slices.push_back(pS); } //______________________________________________________________________ // // head point //______________________________________________________________________ pPoint p0( new Point() ); points.push_back(p0); //______________________________________________________________________ // // body points //______________________________________________________________________ for(size_t i=1;i<=N;++i) { Slice &slice = *slices[i]; const double w = W(slice.z); const double h = H(slice.z); //std::cerr << "w=" << width << ", h=" << height << std::endl; for(size_t j=0;j<M;++j) { const double theta = (j*numeric<double>::two_pi)/M; pPoint pp( new Point() ); pp->r.x = w * cos(theta); pp->r.y = h * sin(theta); pp->r.z = slice.z; slice.points.push_back(pp); points.push_back(pp); } } std::cerr << "-- Computing Triangles" << std::endl; std::cerr << "\t Head..." << std::endl; //______________________________________________________________________ // // head //______________________________________________________________________ { const Slice &slice = *slices[1]; for(size_t i=1;i<=M;++i) { size_t ip = i+1; if(ip>M) ip = 1; const Triangle tr(p0,slice.points[i],slice.points[ip]); triangles.push_back(tr); } } std::cerr << "\t Body..." << std::endl; //______________________________________________________________________ // // inside //______________________________________________________________________ for(size_t j=1;j<N;++j) { const array<pPoint> &P0 = slices[j]->points; const array<pPoint> &P1 = slices[j+1]->points; // loop over quads for(size_t i=1;i<=M;++i) { size_t ip = i+1; if(ip>M) ip = 1; const pPoint &P00 = P0[i]; const pPoint &P01 = P0[ip]; const pPoint &P10 = P1[i]; const pPoint &P11 = P1[ip]; { const Triangle tr(P00,P01,P11); triangles.push_back(tr); } { const Triangle tr(P00,P10,P11); triangles.push_back(tr); } } } } pPoint pN( new Point); pN->r.z = Zmax; points.push_back(pN); // tail { const Slice &slice = *slices[N]; for(size_t i=1;i<=M;++i) { size_t ip = i+1; if(ip>M) ip = 1; Triangle tr(pN,slice.points[i],slice.points[ip]); tr.inverse(); triangles.push_back(tr); } } #if 0 //-------------------------------------------------------------------------- // // Inner Shell // //-------------------------------------------------------------------------- { vector<pPoint> inner_points; vector<pSlice> inner_slices; vector<Triangle> inner_tr; pPoint p0( new Point() ); inner_points.push_back(p0); rfn.target = thickness; const double rho_min = solve(rfn.call,0,1); p0->r.z = thickness; const double delta_in = (rho_max - rho_min)/N; //______________________________________________________________________ // // inner slices //______________________________________________________________________ for(size_t i=1;i<=N;++i) { const double ratio = rho_min + (i*delta_in); const pSlice pS( new Slice( getZ(ratio) ) ); inner_slices.push_back(pS); } //______________________________________________________________________ // // inner body points //______________________________________________________________________ for(size_t i=1;i<=N;++i) { Slice &slice = *inner_slices[i]; const double w0 = W(slice.z); const double h0 = H(slice.z); const double th = thickness; const double w = max_of(w0/2,w0 - th); const double h = max_of(h0/2,h0 - th); //std::cerr << "w=" << width << ", h=" << height << std::endl; for(size_t j=0;j<M;++j) { const double theta = (j*numeric<double>::two_pi)/M; pPoint pp( new Point() ); pp->r.x = w * cos(theta); pp->r.y = h * sin(theta); pp->r.z = slice.z; slice.points.push_back(pp); inner_points.push_back(pp); } } std::cerr << "-- Computing Inner Triangles" << std::endl; std::cerr << "\t Head..." << std::endl; //______________________________________________________________________ // // inner triangles head //______________________________________________________________________ { const Slice &slice = *inner_slices[1]; for(size_t i=1;i<=M;++i) { size_t ip = i+1; if(ip>M) ip = 1; const Triangle tr(p0,slice.points[i],slice.points[ip]); inner_tr.push_back(tr); } } std::cerr << "\t Body..." << std::endl; //______________________________________________________________________ // // inside //______________________________________________________________________ for(size_t j=1;j<N;++j) { const array<pPoint> &P0 = inner_slices[j]->points; const array<pPoint> &P1 = inner_slices[j+1]->points; // loop over quads for(size_t i=1;i<=M;++i) { size_t ip = i+1; if(ip>M) ip = 1; const pPoint &P00 = P0[i]; const pPoint &P01 = P0[ip]; const pPoint &P10 = P1[i]; const pPoint &P11 = P1[ip]; { const Triangle tr(P00,P01,P11); inner_tr.push_back(tr); } { const Triangle tr(P00,P10,P11); inner_tr.push_back(tr); } } } //______________________________________________________________________ // // fusion of inner triangles with shell //______________________________________________________________________ for(size_t i=1;i<=inner_points.size();++i) { points.push_back(inner_points[i]); } for(size_t i=1;i<=inner_tr.size();++i) { Triangle &tr = inner_tr[i]; tr.inverse(); triangles.push_back( inner_tr[i] ); } //______________________________________________________________________ // // closing the shell //______________________________________________________________________ std::cerr << "-- Closing the shell" << std::endl; const Slice &S_out = *slices.back(); const Slice &S_ins = *inner_slices.back(); { const array<pPoint> &P0 = S_out.points; const array<pPoint> &P1 = S_ins.points; // loop over quads for(size_t i=1;i<=M;++i) { size_t ip = i+1; if(ip>M) ip = 1; const pPoint &P00 = P0[i]; const pPoint &P01 = P0[ip]; const pPoint &P10 = P1[i]; const pPoint &P11 = P1[ip]; { Triangle tr(P00,P01,P11); if(tr.n.z<=0) tr.inverse(); triangles.push_back(tr); } { Triangle tr(P00,P10,P11); if(tr.n.z<=0) tr.inverse(); triangles.push_back(tr); } } } } #endif }