void TransformerFunc::execute() { ComValue objv(stack_arg(0)); ComValue transv(stack_arg(0)); reset_stack(); if (objv.object_compview()) { ComponentView* compview = (ComponentView*)objv.obj_val(); if (compview && compview->GetSubject()) { OverlayComp* comp = (OverlayComp*)compview->GetSubject(); Graphic* gr = comp->GetGraphic(); if (gr) { Transformer* trans = gr->GetTransformer(); if (transv.is_unknown() || !transv.is_array() || transv.array_val()->Number()!=6) { AttributeValueList* avl = new AttributeValueList(); float a00, a01, a10, a11, a20, a21; trans->matrix(a00, a01, a10, a11, a20, a21); avl->Append(new AttributeValue(a00)); avl->Append(new AttributeValue(a01)); avl->Append(new AttributeValue(a10)); avl->Append(new AttributeValue(a11)); avl->Append(new AttributeValue(a20)); avl->Append(new AttributeValue(a21)); ComValue retval(avl); push_stack(retval); } else { float a00, a01, a10, a11, a20, a21; AttributeValueList* avl = transv.array_val(); Iterator it; AttributeValue* av; avl->First(it); av = avl->GetAttrVal(it); a00 = av->float_val(); avl->Next(it); av = avl->GetAttrVal(it); a01 = av->float_val(); avl->Next(it); av = avl->GetAttrVal(it); a10 = av->float_val(); avl->Next(it); av = avl->GetAttrVal(it); a11 = av->float_val(); avl->Next(it); av = avl->GetAttrVal(it); a20 = av->float_val(); avl->Next(it); av = avl->GetAttrVal(it); a21 = av->float_val(); Transformer t(a00, a01, a10, a11, a20, a21); *gr->GetTransformer()=t; ComValue compval(new OverlayViewRef(comp), comp->class_symid()); push_stack(compval); } } } } }
inline inverse_transformer(Transformer const& input) { typedef boost::numeric::ublas::matrix<T> matrix_type; // create a working copy of the input matrix_type copy(input.matrix()); // create a permutation matrix for the LU-factorization typedef boost::numeric::ublas::permutation_matrix<> permutation_matrix; permutation_matrix pm(copy.size1()); // perform LU-factorization int res = boost::numeric::ublas::lu_factorize<matrix_type>(copy, pm); if( res == 0 ) { // create identity matrix this->m_matrix.assign(boost::numeric::ublas::identity_matrix<T>(copy.size1())); // backsubstitute to get the inverse boost::numeric::ublas::lu_substitute(copy, pm, this->m_matrix); } }
void print_t(const char* s, const Transformer& t) { float a00, a01, a10, a11, a20, a21; t.matrix(a00, a01, a10, a11, a20, a21); printf("%s transform %g %g %g %g %g %g\n", s, a00, a01, a10, a11, a20, a21); }