static ParamSpec *paramp(PCStr(param),int nameonly){ int pi; if( pi = paramX(param,nameonly) ){ return ¶ms[pi]; } return 0; }
GridIterator GridRay::begin() { GridIterator result(*this); double t; // determine the value of t for which the ray enters the image if (direction.x == 0) { // special case //std::cout << "vertical case" << std::endl; if (!grid.contains(point(0))) { throw std::runtime_error("outside grid"); } result.t = -(double)(grid.height / 2); result.x = trunc(point(0).x); result.y = 0; result.pos = GridIterator::BOTTOM; try { result.next(); if (!result.valid()) { goto end; } return result; } catch (std::exception& x) { } return end(); } if (direction.y == 0) { //std::cout << "horizontal case" << std::endl; if (!grid.contains(point(0))) { throw std::runtime_error("outside grid"); } result.t = -(double)(grid.width / 2); result.x = 0; result.y = trunc(point(0).y); result.pos = (direction.x > 0) ? GridIterator::LEFT : GridIterator::RIGHT; try { result.next(); if (!result.valid()) { goto end; } //std::cout << "initialized horizontal iterator: " << *this << std::endl << result << std::endl; return result; } catch (std::exception& x) { //std::cout << "no next point" << std::endl; } return end(); } // normal case t = paramX(0); //std::cout << "paramX(0) = " << t << std::endl; // left border is only possible if the direction points to the right if ((direction.x > 0) && (t < 0)) { GridPoint p = point(t); if (p.y >= 0) { result.t = t; result.x = 0; result.y = trunc(p.y); result.pos = GridIterator::LEFT; result.next(); if (!result.valid()) { goto end; } return result; } } // right boundary t = paramX(grid.width); //std::cout << "paramX(grid.width) = " << t << std::endl; // right border is only possible if the direction points to the left if ((direction.x < 0) && (t < 0)) { GridPoint p = point(t); if (p.y >= 0) { result.t = t; result.x = grid.width - 1; result.y = trunc(p.y); result.pos = GridIterator::RIGHT; result.next(); if (!result.valid()) { goto end; } return result; } } // if we get to this point, the line we study must intersect // the lower border t = paramY(0); //std::cout << "paramY(0) = " << t << std::endl; if (t < 0) { GridPoint p = point(t); //std::cout << "Boundary point: " << p << std::endl; if ((0 <= p.x + epsilon) && (p.x - epsilon< grid.width)) { result.t = t; result.x = trunc(p.x); result.y = 0; result.pos = GridIterator::BOTTOM; //std::cout << "trying to get next from here: " << result << std::endl; result.next(); if (!result.valid()) { goto end; } return result; } } t = paramX(grid.width); //std::cout << "paramX(grid.width - 1) = " << t << std::endl; if (t < 0) { GridPoint p = point(t); if (p.y >= 0) { result.t = t; result.x = grid.width - 1; result.y = round(p.y); result.pos = GridIterator::RIGHT; result.next(); if (!result.valid()) { goto end; } return result; } } end: result.x = -1; result.y = -1; return result; }