bool Bounds::inside(const Bounds& bounds) const { tgtAssert( isDefined(), "This Box ist not defined."); tgtAssert(bounds.isDefined(), "Box b ist not defined."); vec3 llfb = bounds.getLLF(); vec3 urbb = bounds.getURB(); float r0x = min(llf_[0], urb_[0]); float r1x = max(llf_[0], urb_[0]); float r0y = min(llf_[1], urb_[1]); float r1y = max(llf_[1], urb_[1]); float r0z = min(llf_[2], urb_[2]); float r1z = max(llf_[2], urb_[2]); float r2x = min(llfb[0], urbb[0]); float r3x = max(llfb[0], urbb[0]); float r2y = min(llfb[1], urbb[1]); float r3y = max(llfb[1], urbb[1]); float r2z = min(llfb[2], urbb[2]); float r3z = max(llfb[2], urbb[2]); return (r0x >= r2x) && (r1x <= r3x) && (r0y >= r2y) && (r1y <= r3y) && (r0z >= r2z) && (r1z <= r3z); }
void Image<T>::resize(const Bounds<int>& new_bounds) { if (!new_bounds.isDefined()) { // Then this is really a deallocation. Clear out the existing memory. this->_owner.reset(); this->_data = 0; this->_stride = 0; } else if (this->_bounds.isDefined() && this->_bounds.area() <= new_bounds.area() && this->_owner.unique()) { // Then safe to keep existing memory allocation. // Just redefine the bounds and stride. this->_stride = new_bounds.getXMax() - new_bounds.getXMin() + 1; } else { // Then we want to do the reallocation. this->_bounds = new_bounds; this->allocateMem(); } }
double PhotonArray::addTo(ImageView<T> target) const { Bounds<int> b = target.getBounds(); if (!b.isDefined()) throw std::runtime_error("Attempting to PhotonArray::addTo an Image with" " undefined Bounds"); // Factor to turn flux into surface brightness in an Image pixel dbg<<"In PhotonArray::addTo\n"; dbg<<"bounds = "<<b<<std::endl; double addedFlux = 0.; #ifdef DEBUGLOGGING double totalFlux = 0.; double lostFlux = 0.; int nx = target.getXMax()-target.getXMin()+1; int ny = target.getYMax()-target.getYMin()+1; std::vector<std::vector<double> > posFlux(nx,std::vector<double>(ny,0.)); std::vector<std::vector<double> > negFlux(nx,std::vector<double>(ny,0.)); #endif for (int i=0; i<int(size()); i++) { int ix = int(floor(_x[i] + 0.5)); int iy = int(floor(_y[i] + 0.5)); #ifdef DEBUGLOGGING totalFlux += _flux[i]; xdbg<<" photon: ("<<_x[i]<<','<<_y[i]<<") f = "<<_flux[i]<<std::endl; #endif if (b.includes(ix,iy)) { #ifdef DEBUGLOGGING if (_flux[i] > 0.) posFlux[ix-target.getXMin()][iy-target.getXMin()] += _flux[i]; else negFlux[ix-target.getXMin()][iy-target.getXMin()] -= _flux[i]; #endif target(ix,iy) += _flux[i]; addedFlux += _flux[i]; } else { #ifdef DEBUGLOGGING xdbg<<"lost flux at ix = "<<ix<<", iy = "<<iy<<" with flux = "<<_flux[i]<<std::endl; lostFlux += _flux[i]; #endif } } #ifdef DEBUGLOGGING dbg<<"totalFlux = "<<totalFlux<<std::endl; dbg<<"addedlFlux = "<<addedFlux<<std::endl; dbg<<"lostFlux = "<<lostFlux<<std::endl; for(int ix=0;ix<nx;++ix) { for(int iy=0;iy<ny;++iy) { double pos = posFlux[ix][iy]; double neg = negFlux[ix][iy]; double tot = pos + neg; if (tot > 0.) { xdbg<<"eta("<<ix+target.getXMin()<<','<<iy+target.getXMin()<<") = "<< neg<<" / "<<tot<<" = "<<neg/tot<<std::endl; } } } #endif return addedFlux; }