Calculating density of objects