[Paraview-developers] good way to wrap different array types?

David Lonie david.lonie at kitware.com
Mon Apr 24 10:57:06 EDT 2017


On Sat, Apr 22, 2017 at 7:39 AM, Mark Olesen <Mark.Olesen at esi-group.com> wrote:
> I was considering some cleanup of the OpenFOAM reader - there are loads of special int32, int64 handling. For example near here:
> https://gitlab.kitware.com/vtk/vtk/blob/master/IO/Geometry/vtkOpenFOAMReader.cxx#L5716 ,
> which also uses a number of helper functions for retrieving back the correct value from the vtkDataArray.
>
> Since the decision of 32/64-bit input is run-time, I don't see any really elegant means of avoiding explicitly specifying and later checking 32 vs. 64-bit.
> What I would like is something along the lines of a wrapped vtkDataArray with additional flag (32/64).
> For example,
>
> struct someIntArray : public vtkDataArray
> {
> bool is64;
>
> // Construct with 32/64?
> someIntArray(bool use64Bit)
> : is64(use64Bit)
> {
>    if (use64Bit)
>    {
>     ... etc
>    }
>
> }
>
> The question is if this approach even makes sense. How the constructor should actually look. Should the constructor use a New, smartpointer, whatever?

Feel free to clean up the internals of that class as much as you like :-)

As for the data array class, I like the idea, but wouldn't try to make
a full-fledged subclass of vtkDataArray. VTK supports arbitrary
subclasses of vtkDataArray, but using the built-in versions gives much
better performance since performance-critical areas of code in VTK
have fast-paths implemented for them. Plus it's a giant pain to get
the APIs right for new vtkDataArrays :-)

Instead, I think an internal wrapper class that basically encapsulates
the helper functions and the use64bit boolean would simpler, e.g.

class vtkFOAMLabelArray
{
  vtkNew<vtkTypeInt32Array> Data32;
  vtkNew<vtkTypeInt64Array> Data64;
  bool Use64BitArray;

public:
  vtkFOAMLabelArray(bool use64BitArray) {...}

  vtkTypeInt64 GetValue(...) {...}
  void SetValue(..., vtkTypeInt64) {...}

  vtkDataArray *GetDataArray() {...}
};

You can interact with the arrays through the wrapper API, and then
call GetDataArray at the end when building up the final data set.

HTH,
Dave


More information about the Paraview-developers mailing list