Optical characterization of polystyrene direct opals and of inverse-opal hydrogels