> From: Peter Vanroose [mailto:Peter.Vanroose@...]
> To: vxl-users@...
> Subject: [Vxl-users] vil2 question about creating new views
> Suppose a function takes a vil2_image_view_base argument.
It was not intended that (at least for code entering VXL core) that there
would be many functions taking vil2_image_view_base as arguments. The
purpose of this class is to provide a safe type where there is simply no way
to know the pixel type in advance.
> By querying the pixel type, that function can easily cast that
> argument to e.g. vil2_image_view<vxl_byte>.
This shows another reason why we are reluctant to encourage widespread use
of vil2_image_view_base. There is little to prevent the user for passing an
compound pixel image. Currently all of our uses of vil2_image_view_base
forbid by convention (i.e. by documentation) the use of compound pixels.
Otherwise we would have switch statements with a large and potentially
unbounded list of pixel types - vil2_rgb, vcl_complex, etc. Templating the
pixel type means we avoid having to explicitly code this list.
> Now the function wants to create a new view (of the same data),
> e.g. to only view the first plane of a 3-plane image, and return
> a vil2_image_view_base of that first plane.
It would seem to me that this is getting close to image manipulation and (at
the risk of repeating myself) we recommend you do that with a fully
> How should this be done? Do I have to use vil2_plane(im,0) ?
vil2_plane doesn't and should not cope with vil2_image_view_base for reasons
explained above. However, you can pass it the cast vil2_image_view<T>
reference, and cast the returned type back to the base class. To avoid
destruction of the result before it can be assigned to a variable, you need
to return a smart pointer to the view base.
vil2_image_view_base_sptr my_plane(const vil2_image_view_base &im)
const vil2_image_view<vxl_byte> &view = static_cast<const
return new vil2_image_view<vxl_byte>(vil2_plane(view));
There may be some unresolved constness issues in the above code.