Implementation of computeCavity