void SweepAndPrune::swapEndPoints(unsigned int axis, unsigned int a, unsigned int b) { auto axisvec = _axis[axis]; EndPoint temp = axisvec->at(a); axisvec->at(a) = axisvec->at(b); axisvec->at(b) = temp; EndPoint& aend = axisvec->at(b); EndPoint& bend = axisvec->at(a); auto amax = isMax(aend.box); auto bmax = isMax(bend.box); auto aidx = boxIndex(aend.box); auto bidx = boxIndex(bend.box); auto& abox = _objects[aidx]; auto& bbox = _objects[bidx]; if (amax) abox.max[axis] = b; else abox.min[axis] = b; if (bmax) bbox.max[axis] = a; else bbox.min[axis] = a; }
void SweepAndPrune::fixRefs(unsigned int axis, unsigned int start) { auto axisvec = _axis[axis]; for (unsigned int i = start; i < axisvec->size() - 1; ++i) { unsigned int boxIdx = boxIndex(axisvec->at(i).box); bool max = isMax(axisvec->at(i).box); if (max) _objects[boxIdx].max[axis] = i; else _objects[boxIdx].min[axis] = i; } }
void CState::fillBoxes() { cout << "CState::fillBoxes()" << endl; vec3 atomPosition; ivec3 boxIndex; CAtom* atomptr; for (int i = 0; i < nAtoms; i++) { atomptr = atoms[i]; atomPosition = atomptr->getPosition(); for (int j = 0; j < 3; j++) { boxIndex(j) = int(floor(atomPosition(j)/boxDimensions(j))); } boxes[calculate_box_number(boxIndex, NBoxes)]->addAtom(atomptr); } cout << "Exiting CState::fillBoxes()" << endl << endl; }
void SweepAndPrune::updateAxis(unsigned int axis, unsigned int pos, float newval) { auto axisvector = _axis[axis]; if (newval == _axis[axis]->at(pos).value) { //the value has not actually changed, do nothing return; } float oldval = axisvector->at(pos).value; axisvector->at(pos).value = newval; if (newval <= axisvector->at(pos + 1).value && newval >= axisvector->at(pos - 1).value) { //we have changed but we are still in the correct place, //if there are other boxes in our axis we should check against those //to make sure we never skip the last axis checkAndAdd(boxIndex(axisvector->at(pos).box), boxIndex(axisvector->at(pos - 1).box)); checkAndAdd(boxIndex(axisvector->at(pos).box), boxIndex(axisvector->at(pos + 1).box)); return; } if (newval < oldval) { //going down while (newval < axisvector->at(pos-1).value) { swapEndPoints(axis, pos-1, pos); checkAndAdd(boxIndex(axisvector->at(pos).box), boxIndex(axisvector->at(pos-1).box)); pos -= 1; } } else { //going up while (newval > axisvector->at(pos+1).value) { swapEndPoints(axis, pos+1, pos); checkAndAdd(boxIndex(axisvector->at(pos).box), boxIndex(axisvector->at(pos+1).box)); pos += 1; } } }