JNIEXPORT jlong JNICALL Java_org_grammaticalframework_pgf_Expr_initApp(JNIEnv* env, jclass clazz, jstring jfun, jobjectArray args, jlong jpool) { GuPool* pool = l2p(jpool); PgfExpr expr; GuString fun = (*env)->GetStringUTFChars(env, jfun, 0); PgfExprFun* e = gu_new_flex_variant(PGF_EXPR_FUN, PgfExprFun, fun, strlen(fun)+1, &expr, pool); strcpy(e->fun, fun); (*env)->ReleaseStringUTFChars(env, jfun, fun); size_t n_args = (*env)->GetArrayLength(env, args); for (size_t i = 0; i < n_args; i++) { PgfExpr fun = expr; PgfExpr arg = gu_variant_from_ptr(get_ref(env, (*env)->GetObjectArrayElement(env, args, i))); PgfExprApp* e = gu_new_variant(PGF_EXPR_APP, PgfExprApp, &expr, pool); e->fun = fun; e->arg = arg; } return expr; }
bool Beam2d :: computeGtoLRotationMatrix(FloatMatrix &answer) { double sine, cosine; int ndofs = computeNumberOfGlobalDofs(); answer.resize(ndofs, ndofs); answer.zero(); sine = sin( this->givePitch() ); cosine = cos(pitch); answer.at(1, 1) = cosine; answer.at(1, 2) = sine; answer.at(2, 1) = -sine; answer.at(2, 2) = cosine; answer.at(3, 3) = 1.; answer.at(4, 4) = cosine; answer.at(4, 5) = sine; answer.at(5, 4) = -sine; answer.at(5, 5) = cosine; answer.at(6, 6) = 1.; for ( int i = 7; i <= ndofs; i++ ) { answer.at(i, i) = 1.0; } if ( this->hasDofs2Condense() ) { int condensedDofCounter = 0; DofIDItem dofids[] = { D_u, D_w, R_v }; FloatMatrix l2p(6, ndofs); // local -> primary l2p.zero(); // loop over nodes for ( int inode = 0; inode < 2; inode++ ) { // loop over DOFs for ( int idof = 0; idof < 3; idof++ ) { int eq = inode * 3 + idof + 1; if ( ghostNodes [ inode ] ) { if ( ghostNodes [ inode ]->hasDofID(dofids [ idof ]) ) { condensedDofCounter++; l2p.at(eq, 6 + condensedDofCounter) = 1.0; continue; } } l2p.at(eq, eq) = 1.0; } } FloatMatrix g2l(answer); answer.beProductOf(l2p, g2l); } return true; }
JNIEXPORT jobject JNICALL Java_org_grammaticalframework_pgf_TokenIterator_fetchTokenProb(JNIEnv* env, jclass clazz, jlong enumRef, jobject jpool) { GuEnum* res = (GuEnum*) l2p(enumRef); PgfTokenProb* tp = gu_next(res, PgfTokenProb*, get_ref(env, jpool)); if (tp == NULL) return NULL; jclass tp_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/TokenProb"); jmethodID tp_constrId = (*env)->GetMethodID(env, tp_class, "<init>", "(Ljava/lang/String;D)V"); jobject jtp = (*env)->NewObject(env, tp_class, tp_constrId, gu2j_string(env,tp->tok), tp->prob); return jtp; }
Matrix3 plMaxNodeBase::GetWorldToParent(TimeValue t) { // This may look back-ass-ward, but that's only because it // is. If we've got inheritance filtering on, then our localtoworld // is no longer parentl2w * l2p, because we'll be ignoring // some of our parent's transform. More precisely, we'll be // clobbering parts of the product of our parent's current transform // and our current local to parent. So we're going to calculate // a parent to world transform here that would get us to the // right point and orientation in space, even though it has // little or nothing to do with our parent's real transform. // Note that we only go through this charade if we've got // filtering of inheritance active for this node. plMaxNodeBase* parent = (plMaxNodeBase*)GetParentNode(); if( !GetFilterInherit() ) return parent->GetWorldToLocal(t); // l2w = l2p * parentL2W // l2w * parentW2L = l2p // parentW2L = w2l * l2p Point3 pos; float rot[4]; ScaleValue scl; Interval posInv; Interval rotInv; Interval sclInv; Matrix3Indirect parentMatrix(parent->GetNodeTM(t)); TMComponentsArg cmpts(&pos, &posInv, rot, &rotInv, &scl, &sclInv); GetTMController()->GetLocalTMComponents(t, cmpts, parentMatrix); Quat q; if( cmpts.rotRep == TMComponentsArg::RotationRep::kQuat ) q = Quat(rot); else EulerToQuat(rot, q, cmpts.rotRep); Matrix3 l2p(true); l2p.PreTranslate(pos); PreRotateMatrix(l2p, q); l2p.PreScale(scl.s); PreRotateMatrix(l2p, scl.q); Matrix3 w2l = GetWorldToLocal(t); return w2l * l2p; }
JNIEXPORT jstring JNICALL Java_org_grammaticalframework_pgf_Expr_showExpr(JNIEnv* env, jclass clazz, jlong ref) { GuPool* tmp_pool = gu_local_pool(); GuExn* err = gu_exn(tmp_pool); GuStringBuf* sbuf = gu_string_buf(tmp_pool); GuOut* out = gu_string_buf_out(sbuf); pgf_print_expr(gu_variant_from_ptr(l2p(ref)), NULL, 0, out, err); GuString str = gu_string_buf_freeze(sbuf, tmp_pool); jstring jstr = gu2j_string(env, str); gu_pool_free(tmp_pool); return jstr; }
JNIEXPORT jobject JNICALL Java_org_grammaticalframework_pgf_ExprIterator_fetchExprProb (JNIEnv* env, jclass clazz, jlong enumRef, jobject pool, jobject gr) { GuEnum* res = (GuEnum*) l2p(enumRef); PgfExprProb* ep = gu_next(res, PgfExprProb*, NULL); if (ep == NULL) return NULL; jclass expprob_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ExprProb"); jmethodID methodId = (*env)->GetStaticMethodID(env, expprob_class, "mkExprProb", "(Lorg/grammaticalframework/pgf/Pool;Lorg/grammaticalframework/pgf/PGF;JD)Lorg/grammaticalframework/pgf/ExprProb;"); jobject jexpprob = (*env)->CallStaticObjectMethod(env, expprob_class, methodId, pool, gr, p2l(gu_variant_to_ptr(ep->expr)), (double) ep->prob); return jexpprob; }
JNIEXPORT jobject JNICALL Java_org_grammaticalframework_pgf_FullFormIterator_fetchFullFormEntry (JNIEnv* env, jobject clazz, jlong enumRef, jobject jpool, jobject jconcr) { GuEnum* res = (GuEnum*) l2p(enumRef); PgfFullFormEntry* entry = gu_next(res, PgfFullFormEntry*, get_ref(env, jpool)); if (entry == NULL) return NULL; GuString form = pgf_fullform_get_string(entry); jclass list_class = (*env)->FindClass(env, "java/util/ArrayList"); jmethodID list_constrId = (*env)->GetMethodID(env, list_class, "<init>", "()V"); jobject analyses = (*env)->NewObject(env, list_class, list_constrId); jmethodID addId = (*env)->GetMethodID(env, list_class, "add", "(Ljava/lang/Object;)Z"); jclass an_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/MorphoAnalysis"); jmethodID an_constrId = (*env)->GetMethodID(env, an_class, "<init>", "(Ljava/lang/String;Ljava/lang/String;D)V"); GuPool* tmp_pool = gu_local_pool(); GuExn* err = gu_exn(tmp_pool); JMorphoCallback callback = { { jpgf_collect_morpho }, analyses, 0, env, addId, an_class, an_constrId }; pgf_fullform_get_analyses(entry, &callback.fn, err); if (!gu_ok(err)) { if (gu_exn_caught(err, PgfExn)) { GuString msg = (GuString) gu_exn_caught_data(err); throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", msg); } else { throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The lookup failed"); } analyses = NULL; } gu_pool_free(tmp_pool); jclass entry_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/FullFormEntry"); jmethodID entry_constrId = (*env)->GetMethodID(env, entry_class, "<init>", "(Ljava/lang/String;DLjava/util/List;)V"); jobject jentry = (*env)->NewObject(env, entry_class, entry_constrId, gu2j_string(env,form), - log(callback.prob), analyses); return jentry; }
JNIEXPORT void JNICALL Java_org_grammaticalframework_pgf_Parser_addLiteralCallback (JNIEnv* env, jclass clazz, jobject jconcr, jlong callbacksRef, jstring jcat, jobject jcallback, jobject jpool) { PgfConcr* concr = get_ref(env, jconcr); GuPool* pool = get_ref(env, jpool); JPgfLiteralCallback* callback = gu_new(JPgfLiteralCallback, pool); callback->callback.match = jpgf_literal_callback_match; callback->callback.predict = jpgf_literal_callback_predict; callback->jcallback = (*env)->NewGlobalRef(env, jcallback); callback->fin.fn = jpgf_literal_callback_fin; jclass callback_class = (*env)->GetObjectClass(env, jcallback); callback->match_methodId = (*env)->GetMethodID(env, callback_class, "match", "(ILjava/lang/String;I)Lorg/grammaticalframework/pgf/LiteralCallback$CallbackResult;"); callback->predict_methodId = (*env)->GetMethodID(env, callback_class, "predict", "(ILjava/lang/String;)Ljava/util/Iterator;"); gu_pool_finally(pool, &callback->fin); pgf_callbacks_map_add_literal(concr, l2p(callbacksRef), j2gu_string(env, jcat, pool), &callback->callback); }
JNIEXPORT jlong JNICALL Java_org_grammaticalframework_pgf_Expr_initStringLit(JNIEnv* env, jclass clazz, jstring jstr, jlong jpool) { GuPool* pool = l2p(jpool); PgfExpr expr; PgfExprLit* e = gu_new_variant(PGF_EXPR_LIT, PgfExprLit, &expr, pool); GuString str = (*env)->GetStringUTFChars(env, jstr, 0); PgfLiteralStr* slit = gu_new_flex_variant(PGF_LITERAL_STR, PgfLiteralStr, val, strlen(str)+1, &e->lit, pool); strcpy(slit->val, str); (*env)->ReleaseStringUTFChars(env, jstr, str); return expr; }
JNIEXPORT jobject JNICALL Java_org_grammaticalframework_pgf_Parser_parseWithHeuristics (JNIEnv* env, jclass clazz, jobject jconcr, jstring jstartCat, jstring js, jdouble heuristics, jlong callbacksRef, jobject jpool) { GuPool* pool = get_ref(env, jpool); GuPool* out_pool = gu_new_pool(); GuString startCat = j2gu_string(env, jstartCat, pool); GuString s = j2gu_string(env, js, pool); GuExn* parse_err = gu_new_exn(pool); GuEnum* res = pgf_parse_with_heuristics(get_ref(env, jconcr), startCat, s, heuristics, l2p(callbacksRef), parse_err, pool, out_pool); if (!gu_ok(parse_err)) { if (gu_exn_caught(parse_err, PgfExn)) { GuString msg = (GuString) gu_exn_caught_data(parse_err); throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", msg); } else if (gu_exn_caught(parse_err, PgfParseError)) { GuString tok = (GuString) gu_exn_caught_data(parse_err); throw_string_exception(env, "org/grammaticalframework/pgf/ParseError", tok); } gu_pool_free(out_pool); return NULL; } jfieldID refId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, jconcr), "gr", "Lorg/grammaticalframework/pgf/PGF;"); jobject jpgf = (*env)->GetObjectField(env, jconcr, refId); jclass expiter_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ExprIterator"); jmethodID constrId = (*env)->GetMethodID(env, expiter_class, "<init>", "(Lorg/grammaticalframework/pgf/PGF;Lorg/grammaticalframework/pgf/Pool;JJ)V"); jobject jexpiter = (*env)->NewObject(env, expiter_class, constrId, jpgf, jpool, p2l(out_pool), p2l(res)); return jexpiter; }
static void* get_ref(JNIEnv *env, jobject self) { jfieldID refId = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, self), "ref", "J"); return l2p((*env)->GetLongField(env, self, refId)); }
JNIEXPORT void JNICALL Java_org_grammaticalframework_pgf_Pool_free(JNIEnv* env, jclass clazz, jlong ref) { gu_pool_free((GuPool*) l2p(ref)); }