[vtkusers] Create a custom valueType vtkArray

Allie Vacanti allison.vacanti at kitware.com
Thu Oct 4 09:36:46 EDT 2018


While it might be tempting to hook into the templated vtkDataArray
subclasses 'vtkAOSDataArrayTemplate' or 'vtkSOADataArrayTemplate', this
will likely cause headaches as these ValueTypes expect to be implicitly
convertible to/from double.

Your best option here would be to write your own subclass of
vtkAbstractArray (the superclass of vtkDataArray), since that has much less
stringent requirements and is already used for things like strings, etc.
See vtkStringArray for an example subclass that doesn't just hold a trivial
numeric type.

HTH,
Allie

On Sun, Sep 30, 2018 at 5:12 AM Ruben Di Battista <rubendibattista at gmail.com>
wrote:

> Hello,
>
> At the moment I have some code that reads like this:
>
>         m_H->SetNumberOfValues(nPoints);
>         m_G->SetNumberOfValues(nPoints);
>         m_C->SetNumberOfValues(nPoints);
>         m_SI->SetNumberOfValues(nPoints);
>
>         for ( auto p : this->IterateOver<Point>() ) {
>                 auto curvatures = p.HG();
>                 m_H->SetValue(p.Id(), curvatures.H);
>                 m_G->SetValue(p.Id(), curvatures.G);
>                 m_C->SetValue(p.Id(), curvatures.C);
>                 m_SI->SetValue(p.Id(), curvatures.SI);
>        }
>
>         m_polyPtr->GetPointData()->AddArray(m_H);
>         m_polyPtr->GetPointData()->AddArray(m_G);
>         m_polyPtr->GetPointData()->AddArray(m_C);
>         m_polyPtr->GetPointData()->AddArray(m_SI);
>
> Where m_polyPtr is a vtkPolyData* and the return type of p.HG() is:
>
>      struct Curvatures
>     {
>         double G; /**< Gauss Curvature */
>         double H; /**< Mean Curvature */
>         double C; /**< Curvedness */
>         double SI; /**< Shape Index */
>     };
>
> Now I’m facing a problem where I need to add fields to the structure
> “Curvatures” and so I need to change code in three different classes.
> Is there a way to create a vtkArray whose (templated?) valueType is
> `Curvatures` such that I can just modify that struct to allow more fields
> to be stored and set in a “more abstract way” and that can be appended to
> the `PointData` of the vtkPolyData in a transparent way?
>
> Any suggestion is appreciated!
>
> :)
>
>
>           _
> -.     .´  |∞∞∞∞
>   ',  ;    |∞∞∞∞∞∞
>     ˜˜     |∞∞∞∞∞∞∞∞∞ RdB
>     ,.,    |∞∞∞∞∞∞
>   .'   '.  |∞∞∞∞
> -'       `’
> https://rdb.is
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181004/489b4a3e/attachment.html>


More information about the vtkusers mailing list