It can be simplified with 3 lines: ;) 
 HyperRectDomain<SpaceND<3,int> > aDomain(p0, p1);
 viewer << SetMode3D(aDomain.className(), "BoundingBox");
 viewer << aDomain;

but since you it deals also with color and different mode we can let it as it it.