Py::Object Transformation::seq_xy_tups(const Py::Tuple & args) { _VERBOSE("Transformation::seq_xy_tups"); args.verify_length(1); Py::SeqBase<Py::Object> xytups = args[0]; size_t Nx = xytups.length(); if (!_frozen) eval_scalars(); Py::Tuple ret(Nx); Py::SeqBase<Py::Object> xytup; for (size_t i=0; i< Nx; ++i) { xytup = Py::SeqBase<Py::Object>( xytups[i] ); double thisx = Py::Float(xytup[0]); double thisy = Py::Float(xytup[1]); this->operator()(thisx, thisy); Py::Tuple out(2); out[0] = Py::Float( xy.first ); out[1] = Py::Float( xy.second ); ret[i] = out; } return ret; }
Py::Object Transformation::seq_x_y(const Py::Tuple & args) { _VERBOSE("Transformation::seq_x_y"); args.verify_length(2); Py::SeqBase<Py::Object> x = args[0]; Py::SeqBase<Py::Object> y = args[1]; size_t Nx = x.length(); size_t Ny = y.length(); if (Nx!=Ny) throw Py::ValueError("x and y must be equal length sequences"); // evaluate the lazy objects if (!_frozen) eval_scalars(); Py::Tuple xo(Nx); Py::Tuple yo(Nx); for (size_t i=0; i< Nx; ++i) { double thisx = Py::Float(x[i]); double thisy = Py::Float(y[i]); this->operator()(thisx, thisy); xo[i] = Py::Float( xy.first ); yo[i] = Py::Float( xy.second ); } Py::Tuple ret(2); ret[0] = xo; ret[1] = yo; return ret; }
Py::Object Transformation::xy_tup(const Py::Tuple & args) { _VERBOSE("Transformation::xy_tup"); args.verify_length(1); try { if (!_frozen) eval_scalars(); } catch(...) { throw Py::ValueError("Domain error on nonlinear transform"); } Py::SeqBase<Py::Object> xytup = args[0]; double x = Py::Float(xytup[0]); double y = Py::Float(xytup[1]); Py::Tuple out(2); try { this->operator()(x, y); } catch(...) { throw Py::ValueError("Domain error on nTransformation::xy_tup operator()(x,y)"); } out[0] = Py::Float( xy.first ); out[1] = Py::Float( xy.second ); return out; }
Py::Object Affine::deepcopy(const Py::Tuple &args) { _VERBOSE("Affine::deepcopy"); args.verify_length(0); eval_scalars(); return Py::asObject( new Affine( new Value(_aval),new Value(_bval), new Value(_cval), new Value(_dval),new Value(_txval),new Value(_tyval) )); }
Py::Object Affine::deepcopy(const Py::Tuple &args) { _VERBOSE("Affine::deepcopy"); args.verify_length(0); try { eval_scalars(); } catch(...) { throw Py::ValueError("Domain error on Affine deepcopy"); } return Py::asObject( new Affine( new Value(_aval),new Value(_bval), new Value(_cval), new Value(_dval),new Value(_txval),new Value(_tyval) )); }
Py::Object Transformation::xy_tup(const Py::Tuple & args) { _VERBOSE("Transformation::xy_tup"); args.verify_length(1); if (!_frozen) eval_scalars(); Py::SeqBase<Py::Object> xytup = args[0]; double x = Py::Float(xytup[0]); double y = Py::Float(xytup[1]); Py::Tuple out(2); this->operator()(x, y); out[0] = Py::Float( xy.first ); out[1] = Py::Float( xy.second ); return out; }
Py::Object Transformation::inverse_xy_tup(const Py::Tuple & args) { _VERBOSE("Transformation::inverse_xy_tup"); args.verify_length(1); Py::Tuple tup = args[0]; double xin = Py::Float(tup[0]); double yin = Py::Float(tup[1]); if (!_frozen) eval_scalars(); inverse_api(xin, yin); Py::Tuple ret(2); ret[0] = Py::Float(xy.first); ret[1] = Py::Float(xy.second); return ret; }
void BBoxTransformation::affine_params_api(double* a, double* b, double* c, double* d, double* tx, double* ty) { //get the scale and translation factors of the separable transform //sx, sy, tx, ty if (!_frozen) eval_scalars(); *a = _sx; *b = 0.0; *c = 0.0; *d = _sy; *tx = _tx; *ty = _ty; if (_usingOffset) { *tx += _xot; *ty += _yot; } }
Py::Object Transformation::inverse_xy_tup(const Py::Tuple & args) { _VERBOSE("Transformation::inverse_xy_tup"); args.verify_length(1); Py::Tuple tup = args[0]; double xin = Py::Float(tup[0]); double yin = Py::Float(tup[1]); try { if (!_frozen) eval_scalars(); } catch(...) { throw Py::ValueError("Domain error on invser_xy_tup"); } inverse_api(xin, yin); Py::Tuple ret(2); ret[0] = Py::Float(xy.first); ret[1] = Py::Float(xy.second); return ret; }
Py::Object Transformation::numerix_x_y(const Py::Tuple & args) { _VERBOSE("Transformation::numerix_x_y"); args.verify_length(2); Py::Object xo = args[0]; Py::Object yo = args[1]; PyArrayObject *x = (PyArrayObject *) PyArray_ContiguousFromObject(xo.ptr(), PyArray_DOUBLE, 1, 1); if (x==NULL) throw Py::TypeError("Transformation::numerix_x_y expected numerix array"); PyArrayObject *y = (PyArrayObject *) PyArray_ContiguousFromObject(yo.ptr(), PyArray_DOUBLE, 1, 1); if (y==NULL) throw Py::TypeError("Transformation::numerix_x_y expected numerix array"); size_t Nx = x->dimensions[0]; size_t Ny = y->dimensions[0]; if (Nx!=Ny) throw Py::ValueError("x and y must be equal length sequences"); // evaluate the lazy objects if (!_frozen) eval_scalars(); int dimensions[1]; dimensions[0] = Nx; PyArrayObject *retx = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); if (retx==NULL) { Py_XDECREF(x); Py_XDECREF(y); throw Py::RuntimeError("Could not create return x array"); } PyArrayObject *rety = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); if (rety==NULL) { Py_XDECREF(x); Py_XDECREF(y); throw Py::RuntimeError("Could not create return x array"); } for (size_t i=0; i< Nx; ++i) { double thisx = *(double *)(x->data + i*x->strides[0]); double thisy = *(double *)(y->data + i*y->strides[0]); //std::cout << "calling operator " << thisx << " " << thisy << " " << std::endl; this->operator()(thisx, thisy); *(double *)(retx->data + i*retx->strides[0]) = xy.first; *(double *)(rety->data + i*rety->strides[0]) = xy.second; } Py_XDECREF(x); Py_XDECREF(y); Py::Tuple ret(2); ret[0] = Py::Object((PyObject*)retx); ret[1] = Py::Object((PyObject*)rety); Py_XDECREF(retx); Py_XDECREF(rety); return ret; }