[vtkusers] Cast vtkTypedDataArrayIterator to vtkArrayIterator?

Lars Bilke lars.bilke at ufz.de
Wed Oct 29 03:14:39 EDT 2014


Hi David,

thanks a lot for your explanation! I already assumed that this would not be an easy task ...

But I found an easy workaround:

If I write ascii files then I deep copy the mapped grid to a regular vtkUnstructuredGrid and  write out this temporary. This fits our needs because ascii files will just be written out for debugging purposes and if the grid is relatively small.

Best,
Lars

> Am 28.10.2014 um 15:30 schrieb David Lonie <david.lonie at kitware.com>:
> 
> Hi Lars,
> 
> The vtkArrayIterator class is very different from the vtkTypedDataArrayIterator. See the APIs in vtkTypedDataArrayIterator.h and vtkArrayIteratorTemplate.h. The former is an STL style iterator, while the latter uses a custom API for retrieving data.
> 
> At this point, you'd need to write a new iterator implementation that matches the vtkArrayIterator API and somehow shoehorn some extra logic into vtkArrayIteratorTemplateMacro in vtkSetGet.h. This would be hacky, and to properly fix this the writer would likely need to be rewritten, since the vtkArrayIterator plumbing seems intrinsically tied to the vtkArrayIteratorTemplate class, which relies heavily on the horrible vtkDataArray::GetVoidPointer method.
> 
> Is ascii mode required for your use case? If not, it would likely be much simpler to just use binary mode.
> 
> Hope this helps,
> Dave
> 
> On Tue, Oct 28, 2014 at 4:20 AM, Lars Bilke <lars.bilke at ufz.de> wrote:
> I have a similar implementation of a vtkMappedDataArray as in
> 
> vtkCPExodusIIResultsArrayTemplate (https://github.com/Kitware/VTK/blob/master/IO/Exodus/vtkCPExodusIIResultsArrayTemplate.txx).
> 
> The mapped data array is part of a vtkMappedUnstructuredGrid as in
> 
> https://github.com/gahansen/Albany/blob/master/src/disc/catalyst/Albany_Catalyst_Grid.hpp
> 
> and so on. It works fine. Now I try to write the unstructured grid to a file which also works fine in binary mode. But when I switch the vtkXMLUnstructuredGridWriter to ascii mode the member vtkArrayIterator* NewIterator() of my vtkMappedDataArray needs to be implemented. I did not found an example of such an implementation. For now I came up with this:
> 
> template <class Scalar> vtkArrayIterator*
> VtkMappedElementDataArrayTemplate<Scalar>::NewIterator()
> {
>         vtkTypedDataArrayIterator<Scalar> tdaBegin = vtkTypedDataArray<Scalar>::FastDownCast(this)->Begin();
>         return tdaBegin;
> }
> 
> But compilation fails with
> 
> error: no viable conversion from 'vtkTypedDataArrayIterator<unsigned int>' to 'vtkArrayIterator *‘
> 
> If you want to have a look at my code:
> 
> https://github.com/ufz/ogs/tree/master/InSituLib
> 
> Thanks,
> Lars
> _______________________________________________
> 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
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
> 



More information about the vtkusers mailing list