Login  Register

Re: inheritance

Posted by ctrueden on Aug 08, 2006; 7:53pm
URL: http://imagej.273.s1.nabble.com/inheritance-tp3701842p3701846.html

Hi Tony,

Try:
    MyTypeOfImage myIP = (MyTypeOfImage) imp.getProcessor();

But I question why you need to subclass ImageProcessor at all. The
subclasses of ImageProcessor are mainly for different bit depths. Do you
need a new, crazy kind of bit depth?

-Curtis

On 8/8/06, Tony Shepherd <[hidden email]> wrote:

>
> When I create an image I can use one of the existing classes, creating one
> of the existing object types, for example
>
> ImagePlus imp = WindowManager.getCurrentImage();
>    Followed by
> ImageProcessor MyImage = imp.getProcessor();                   (1)
>
> Then MyImage is an object of type ImageProcessor.
>
> Say I want to write my own methods (like calculating stats from an ROI or
> what ever). I don't want to (have to) edit the ImageProcessor class. So I
> write methods in a new class, one that EXTENDS ImageProcessor. i.e.
>
> public abstract class MyTypeOfImage extents ImageProcessor{ …
>
> I can only expect to use my new methods if I create the image in the first
> place, as a 'MyTypeOfImage' object, i.e.:
>
> ImagePlus imp = WindowManager.getCurrentImage();
> MyTypeOfImage MyImage = imp.getProcessor();                    (2)
>
>
> Now, (1) and (2) above only differ in the type of object being
> declared/created
>
> I expect the class 'MyTypeOfImage' to inherit all the necessary
> constructors
> from 'ImageProcessor', for creating an image object,
>
> The compiler disagrees, complaining about incompatible types.
>