An algorithm for kilovoltage x-ray dose calculations with applications in kV-CBCT scans and 2D planar projected radiographs