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

Elvis Stansvik elvis.stansvik at orexplore.com
Tue Jul 5 03:32:40 EDT 2016


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.

  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/ff49a28f/attachment.html>


More information about the vtkusers mailing list