void do_messages(UAContext *ua, const char *cmd) { char msg[2000]; int mlen; bool do_truncate = false; Pw(con_lock); pthread_cleanup_push(con_lock_release, (void *)NULL); rewind(con_fd); while (fgets(msg, sizeof(msg), con_fd)) { mlen = strlen(msg); ua->UA_sock->msg = check_pool_memory_size(ua->UA_sock->msg, mlen+1); strcpy(ua->UA_sock->msg, msg); ua->UA_sock->msglen = mlen; ua->UA_sock->send(); do_truncate = true; } if (do_truncate) { (void)ftruncate(fileno(con_fd), 0L); } console_msg_pending = FALSE; ua->user_notified_msg_pending = FALSE; pthread_cleanup_pop(0); Vw(con_lock); }
int FTPLogin(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; if( beh->IsInputActive(0)){ beh->ActivateInput(0,FALSE); HWND win = (HWND)ctx->GetMainWindow(); FtpInit(win); //HFILE hLogFile = _lcreat (LOG_FILE, 0); //FtpLogTo (hLogFile); FtpSetDefaultTimeOut (30); FtpSetPassiveMode(TRUE); FtpSetAsynchronousMode(); int Port; beh->GetInputParameterValue(3,&Port); XString Host((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString User((CKSTRING) beh->GetInputParameterReadDataPtr(1)); XString Pw((CKSTRING) beh->GetInputParameterReadDataPtr(2)); int Login = FtpLogin(Host.Str(),User.Str(),Pw.Str(),win,0); beh->SetOutputParameterValue(0,&Login); if (Login == 0)beh->ActivateOutput(0); else{ beh->ActivateOutput(2); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; } if( beh->IsInputActive(1)){ beh->ActivateInput(1,FALSE); FtpCloseConnection(); FtpRelease (); beh->ActivateOutput(1); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; }
//--------------------------------------------------------- inline TSG_Point CSG_Direct_Georeferencer::World_to_Image(double x_w, double y_w, double z_w) { TSG_Point p; CSG_Vector Pw(3), Pc; Pw[0] = x_w; Pw[1] = y_w; Pw[2] = z_w; Pc = m_Rinv * (Pw - m_T); p.x = m_O[0] - (m_f / m_s) * (Pc[0] / Pc[2]); p.y = m_O[1] - (m_f / m_s) * (Pc[1] / Pc[2]); return( p ); }
std::vector<std::shared_ptr<Shape>> CreateNURBS(const Transform *o2w, const Transform *w2o, bool reverseOrientation, const ParamSet ¶ms) { int nu = params.FindOneInt("nu", -1); if (nu == -1) { Error("Must provide number of control points \"nu\" with NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } int uorder = params.FindOneInt("uorder", -1); if (uorder == -1) { Error("Must provide u order \"uorder\" with NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } int nuknots, nvknots; const Float *uknots = params.FindFloat("uknots", &nuknots); if (uknots == nullptr) { Error("Must provide u knot vector \"uknots\" with NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } if (nuknots != nu + uorder) { Error( "Number of knots in u knot vector %d doesn't match sum of " "number of u control points %d and u order %d.", nuknots, nu, uorder); return std::vector<std::shared_ptr<Shape>>(); } Float u0 = params.FindOneFloat("u0", uknots[uorder - 1]); Float u1 = params.FindOneFloat("u1", uknots[nu]); int nv = params.FindOneInt("nv", -1); if (nv == -1) { Error("Must provide number of control points \"nv\" with NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } int vorder = params.FindOneInt("vorder", -1); if (vorder == -1) { Error("Must provide v order \"vorder\" with NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } const Float *vknots = params.FindFloat("vknots", &nvknots); if (vknots == nullptr) { Error("Must provide v knot vector \"vknots\" with NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } if (nvknots != nv + vorder) { Error( "Number of knots in v knot vector %d doesn't match sum of " "number of v control points %d and v order %d.", nvknots, nv, vorder); return std::vector<std::shared_ptr<Shape>>(); } Float v0 = params.FindOneFloat("v0", vknots[vorder - 1]); Float v1 = params.FindOneFloat("v1", vknots[nv]); bool isHomogeneous = false; int npts; const Float *P = (const Float *)params.FindPoint3f("P", &npts); if (!P) { P = params.FindFloat("Pw", &npts); if (!P) { Error( "Must provide control points via \"P\" or \"Pw\" parameter to " "NURBS shape."); return std::vector<std::shared_ptr<Shape>>(); } if ((npts % 4) != 0) { Error( "Number of \"Pw\" control points provided to NURBS shape must " "be " "multiple of four"); return std::vector<std::shared_ptr<Shape>>(); } npts /= 4; isHomogeneous = true; } if (npts != nu * nv) { Error("NURBS shape was expecting %dx%d=%d control points, was given %d", nu, nv, nu * nv, npts); return std::vector<std::shared_ptr<Shape>>(); } // Compute NURBS dicing rates int diceu = 30, dicev = 30; std::unique_ptr<Float[]> ueval(new Float[diceu]); std::unique_ptr<Float[]> veval(new Float[dicev]); std::unique_ptr<Point3f[]> evalPs(new Point3f[diceu * dicev]); std::unique_ptr<Normal3f[]> evalNs(new Normal3f[diceu * dicev]); int i; for (i = 0; i < diceu; ++i) ueval[i] = Lerp((float)i / (float)(diceu - 1), u0, u1); for (i = 0; i < dicev; ++i) veval[i] = Lerp((float)i / (float)(dicev - 1), v0, v1); // Evaluate NURBS over grid of points memset(evalPs.get(), 0, diceu * dicev * sizeof(Point3f)); memset(evalNs.get(), 0, diceu * dicev * sizeof(Point3f)); std::unique_ptr<Point2f[]> uvs(new Point2f[diceu * dicev]); // Turn NURBS into triangles std::unique_ptr<Homogeneous3[]> Pw(new Homogeneous3[nu * nv]); if (isHomogeneous) { for (int i = 0; i < nu * nv; ++i) { Pw[i].x = P[4 * i]; Pw[i].y = P[4 * i + 1]; Pw[i].z = P[4 * i + 2]; Pw[i].w = P[4 * i + 3]; } } else { for (int i = 0; i < nu * nv; ++i) { Pw[i].x = P[3 * i]; Pw[i].y = P[3 * i + 1]; Pw[i].z = P[3 * i + 2]; Pw[i].w = 1.; } } for (int v = 0; v < dicev; ++v) { for (int u = 0; u < diceu; ++u) { uvs[(v * diceu + u)].x = ueval[u]; uvs[(v * diceu + u)].y = veval[v]; Vector3f dpdu, dpdv; Point3f pt = NURBSEvaluateSurface(uorder, uknots, nu, ueval[u], vorder, vknots, nv, veval[v], Pw.get(), &dpdu, &dpdv); evalPs[v * diceu + u].x = pt.x; evalPs[v * diceu + u].y = pt.y; evalPs[v * diceu + u].z = pt.z; evalNs[v * diceu + u] = Normal3f(Normalize(Cross(dpdu, dpdv))); } } // Generate points-polygons mesh int nTris = 2 * (diceu - 1) * (dicev - 1); std::unique_ptr<int[]> vertices(new int[3 * nTris]); int *vertp = vertices.get(); // Compute the vertex offset numbers for the triangles for (int v = 0; v < dicev - 1; ++v) { for (int u = 0; u < diceu - 1; ++u) { #define VN(u, v) ((v)*diceu + (u)) *vertp++ = VN(u, v); *vertp++ = VN(u + 1, v); *vertp++ = VN(u + 1, v + 1); *vertp++ = VN(u, v); *vertp++ = VN(u + 1, v + 1); *vertp++ = VN(u, v + 1); #undef VN } } int nVerts = diceu * dicev; return CreateTriangleMesh(o2w, w2o, reverseOrientation, nTris, vertices.get(), nVerts, evalPs.get(), nullptr, evalNs.get(), uvs.get(), nullptr); }