Solution-adaptive Cartesian cell approach for viscous and inviscid flows