[vtkusers] Best practice to subclass vtkImageReader2, or vtkImageAlgorithm okay?

Elvis Stansvik elvis.stansvik at orexplore.com
Tue Jul 5 03:34:59 EDT 2016


2016-07-05 9:32 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:

> Hi all,
>
> I've implemented a basic image reader to read a volume from a data set in
> a HDF5 file. I subclassed vtkImageAlgorithm and reimplemented
> RequestInformation and RequestData.
>
> I realize now that to be a good "VTK citizen", I should probably have
> subclassed vtkImageReader2 instead.
>
> But looking at the vtkImageReader2.h header, much of the additional API /
> protected member variables it imposes don't make sense for my use case. E.g:
>
>   virtual void SetFileNames(vtkStringArray *);
>   vtkGetObjectMacro(FileNames, vtkStringArray);
>
> My reader will not support multiple files.
>
>   virtual void SetFilePrefix(const char *);
>   vtkGetStringMacro(FilePrefix);
>
>   virtual void SetFilePattern(const char *);
>   vtkGetStringMacro(FilePattern);
>
> I have no pressing need for this.
>
>   virtual void SetMemoryBuffer(void *);
>   virtual void *GetMemoryBuffer() { return this->MemoryBuffer; }
>
>   virtual void SetMemoryBufferLength(vtkIdType buflen);
>   vtkIdType GetMemoryBufferLength() { return this->MemoryBufferLength; }
>
> I'll support loading from files on disk only.
>
>   virtual void SetDataScalarType(int type);
>   ...
>   vtkGetMacro(DataScalarType, int);
>
> In my reader, the scalar datatype is always deduced from looking at the
> file. It doesn't make sense to let the user set it. (I guess this API is
> meant more for "raw" format readers?). I could implement the getter.
>
>   vtkSetMacro(NumberOfScalarComponents,int);
>   vtkGetMacro(NumberOfScalarComponents,int);
>
> This I could obviously implement.
>

Sorry, here I meant just the getter. This is again a case where the setter
doesn't make sense for me, since the number of scalar components is always
1 in my format (or possibly some other number in the future, but always
derived from what's in the file automatically, not to be set by the user).

Elvis


>
>   vtkSetVector6Macro(DataExtent,int);
>   vtkGetVector6Macro(DataExtent,int);
>
> Again, the setter doesn't make sense for my format, but I could of course
> implement the getter.
>
> The same is true for other setters/getters like spacing, origin, byte
> order et.c.
>
> But before I go on, let me get to my questions:
>
> * What will I "lose" by basing my reader on vtkImageAlgorithm instead of
> vtkImageReader2. Will my reader be unusable with some parts of VTK? Which?
>
> * Is it frowned upon to make an image reader that derives directly from
> vtkImageAlgorithm instead of vtkImageReader2 or vtkImageReader?
>
> Thanks,
> Elvis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160705/f38e4b78/attachment.html>


More information about the vtkusers mailing list